@@ -2,23 +2,30 @@ 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+ let t = ( r as $ty ^ s) - s;
19+ ( $conv) ( t as $ty)
1620 }
1721 }
1822}
1923
2024macro_rules! mod_ {
2125 ( $intrinsic: ident: $ty: ty, $uty: ty) => {
26+ mod_!( $intrinsic: $ty, $uty, $ty, |i| { i} ) ;
27+ } ;
28+ ( $intrinsic: ident: $ty: ty, $uty: ty, $tyret: ty, $conv: expr) => {
2229 /// Returns `a % b`
2330 #[ cfg_attr( not( test) , no_mangle) ]
2431 pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $ty {
@@ -28,7 +35,8 @@ macro_rules! mod_ {
2835 let a = ( a ^ s) - s;
2936
3037 let r = urem!( a as $uty, b as $uty) ;
31- ( r as $ty ^ s) - s
38+ let t = ( r as $ty ^ s) - s;
39+ ( $conv) ( t)
3240 }
3341 }
3442}
@@ -61,12 +69,28 @@ div!(__divsi3: i32, u32);
6169#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
6270div ! ( __divdi3: i64 , u64 ) ;
6371
72+ #[ cfg( not( stage0) ) ]
73+ #[ cfg( not( all( windows, target_pointer_width="64" ) ) ) ]
74+ div ! ( __divti3: u128 , u128 ) ;
75+
76+ #[ cfg( not( stage0) ) ]
77+ #[ cfg( all( windows, target_pointer_width="64" ) ) ]
78+ div ! ( __divti3: u128 , u128 , :: U64x2 , :: conv) ;
79+
6480#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
6581mod_ ! ( __modsi3: i32 , u32 ) ;
6682
6783#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
6884mod_ ! ( __moddi3: i64 , u64 ) ;
6985
86+ #[ cfg( not( stage0) ) ]
87+ #[ cfg( not( all( windows, target_pointer_width="64" ) ) ) ]
88+ mod_ ! ( __modti3: u128 , u128 ) ;
89+
90+ #[ cfg( not( stage0) ) ]
91+ #[ cfg( all( windows, target_pointer_width="64" ) ) ]
92+ mod_ ! ( __modti3: i128 , u128 , :: U64x2 , :: conv) ;
93+
7094#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
7195divmod ! ( __divmodsi4, __divsi3: i32 ) ;
7296
0 commit comments