@@ -2,23 +2,30 @@ use int::Int;
2
2
3
3
macro_rules! div {
4
4
( $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) => {
5
8
/// Returns `a / b`
6
9
#[ 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 {
8
11
let s_a = a >> ( <$ty>:: bits( ) - 1 ) ;
9
12
let s_b = b >> ( <$ty>:: bits( ) - 1 ) ;
10
13
let a = ( a ^ s_a) - s_a;
11
14
let b = ( b ^ s_b) - s_b;
12
15
let s = s_a ^ s_b;
13
16
14
17
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)
16
20
}
17
21
}
18
22
}
19
23
20
24
macro_rules! mod_ {
21
25
( $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) => {
22
29
/// Returns `a % b`
23
30
#[ cfg_attr( not( test) , no_mangle) ]
24
31
pub extern "C" fn $intrinsic( a: $ty, b: $ty) -> $ty {
@@ -28,7 +35,8 @@ macro_rules! mod_ {
28
35
let a = ( a ^ s) - s;
29
36
30
37
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)
32
40
}
33
41
}
34
42
}
@@ -61,12 +69,28 @@ div!(__divsi3: i32, u32);
61
69
#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
62
70
div ! ( __divdi3: i64 , u64 ) ;
63
71
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
+
64
80
#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
65
81
mod_ ! ( __modsi3: i32 , u32 ) ;
66
82
67
83
#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
68
84
mod_ ! ( __moddi3: i64 , u64 ) ;
69
85
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
+
70
94
#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
71
95
divmod ! ( __divmodsi4, __divsi3: i32 ) ;
72
96
0 commit comments