@@ -2,33 +2,39 @@ use int::Int;
22
33macro_rules! div {
44 ( $intrinsic: ident: $ty: ty, $uty: ty) => {
5+ div!( $intrinsic: $ty, $uty, $ty, |i| { i} ) ;
6+ } ;
7+ ( $intrinsic: ident: $ty: ty, $uty: ty, $tyret: ty, $conv: expr) => {
58 /// Returns `a / b`
69 #[ cfg_attr( not( test) , no_mangle) ]
7- pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $ty {
10+ pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $tyret {
811 let s_a = a >> ( <$ty>:: bits( ) - 1 ) ;
912 let s_b = b >> ( <$ty>:: bits( ) - 1 ) ;
1013 let a = ( a ^ s_a) - s_a;
1114 let b = ( b ^ s_b) - s_b;
1215 let s = s_a ^ s_b;
1316
1417 let r = udiv!( a as $uty, b as $uty) ;
15- ( r as $ty ^ s) - s
18+ ( $conv ) ( ( r as $ty ^ s) - s)
1619 }
1720 }
1821}
1922
2023macro_rules! mod_ {
2124 ( $intrinsic: ident: $ty: ty, $uty: ty) => {
25+ mod_!( $intrinsic: $ty, $uty, $ty, |i| { i} ) ;
26+ } ;
27+ ( $intrinsic: ident: $ty: ty, $uty: ty, $tyret: ty, $conv: expr) => {
2228 /// Returns `a % b`
2329 #[ cfg_attr( not( test) , no_mangle) ]
24- pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $ty {
30+ pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $tyret {
2531 let s = b >> ( <$ty>:: bits( ) - 1 ) ;
2632 let b = ( b ^ s) - s;
2733 let s = a >> ( <$ty>:: bits( ) - 1 ) ;
2834 let a = ( a ^ s) - s;
2935
3036 let r = urem!( a as $uty, b as $uty) ;
31- ( r as $ty ^ s) - s
37+ ( $conv ) ( ( r as $ty ^ s) - s)
3238 }
3339 }
3440}
@@ -61,12 +67,28 @@ div!(__divsi3: i32, u32);
6167#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
6268div ! ( __divdi3: i64 , u64 ) ;
6369
70+ #[ cfg( not( stage0) ) ]
71+ #[ cfg( not( all( windows, target_pointer_width="64" ) ) ) ]
72+ div ! ( __divti3: i128 , u128 ) ;
73+
74+ #[ cfg( not( stage0) ) ]
75+ #[ cfg( all( windows, target_pointer_width="64" ) ) ]
76+ div ! ( __divti3: i128 , u128 , :: U64x2 , :: sconv) ;
77+
6478#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
6579mod_ ! ( __modsi3: i32 , u32 ) ;
6680
6781#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
6882mod_ ! ( __moddi3: i64 , u64 ) ;
6983
84+ #[ cfg( not( stage0) ) ]
85+ #[ cfg( not( all( windows, target_pointer_width="64" ) ) ) ]
86+ mod_ ! ( __modti3: i128 , u128 ) ;
87+
88+ #[ cfg( not( stage0) ) ]
89+ #[ cfg( all( windows, target_pointer_width="64" ) ) ]
90+ mod_ ! ( __modti3: i128 , u128 , :: U64x2 , :: sconv) ;
91+
7092#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
7193divmod ! ( __divmodsi4, __divsi3: i32 ) ;
7294
0 commit comments