@@ -2,33 +2,39 @@ 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
+ ( $conv ) ( ( r as $ty ^ s) - s)
16
19
}
17
20
}
18
21
}
19
22
20
23
macro_rules! mod_ {
21
24
( $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) => {
22
28
/// Returns `a % b`
23
29
#[ 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 {
25
31
let s = b >> ( <$ty>:: bits( ) - 1 ) ;
26
32
let b = ( b ^ s) - s;
27
33
let s = a >> ( <$ty>:: bits( ) - 1 ) ;
28
34
let a = ( a ^ s) - s;
29
35
30
36
let r = urem!( a as $uty, b as $uty) ;
31
- ( r as $ty ^ s) - s
37
+ ( $conv ) ( ( r as $ty ^ s) - s)
32
38
}
33
39
}
34
40
}
@@ -61,12 +67,28 @@ div!(__divsi3: i32, u32);
61
67
#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
62
68
div ! ( __divdi3: i64 , u64 ) ;
63
69
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
+
64
78
#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
65
79
mod_ ! ( __modsi3: i32 , u32 ) ;
66
80
67
81
#[ cfg( not( all( feature = "c" , target_arch = "x86" ) ) ) ]
68
82
mod_ ! ( __moddi3: i64 , u64 ) ;
69
83
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
+
70
92
#[ cfg( not( all( feature = "c" , target_arch = "arm" , not( target_os = "ios" ) ) ) ) ]
71
93
divmod ! ( __divmodsi4, __divsi3: i32 ) ;
72
94
0 commit comments