Skip to content

Commit c6cc332

Browse files
committed
u128 sdiv intrinsics
1 parent 5dfe588 commit c6cc332

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ These builtins are needed to support 128-bit integers, which are in the process
195195

196196
- [x] ashlti3.c
197197
- [x] ashrti3.c
198-
- [ ] divti3.c
198+
- [x] divti3.c
199199
- [ ] fixdfti.c
200200
- [ ] fixsfti.c
201201
- [ ] fixunsdfti.c
@@ -205,7 +205,7 @@ These builtins are needed to support 128-bit integers, which are in the process
205205
- [ ] floatuntidf.c
206206
- [ ] floatuntisf.c
207207
- [x] lshrti3.c
208-
- [ ] modti3.c
208+
- [x] modti3.c
209209
- [x] muloti4.c
210210
- [x] multi3.c
211211
- [x] udivmodti4.c

build.rs

-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ fn main() {
182182
"cmpti2.c",
183183
"ctzti2.c",
184184
"divtf3.c",
185-
"divti3.c",
186185
"ffsti2.c",
187186
"fixdfti.c",
188187
"fixsfti.c",
@@ -196,7 +195,6 @@ fn main() {
196195
"floatuntidf.c",
197196
"floatuntisf.c",
198197
"floatuntixf.c",
199-
"modti3.c",
200198
"multf3.c",
201199
"mulvti3.c",
202200
"negti2.c",

src/int/sdiv.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,39 @@ use int::Int;
22

33
macro_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

2023
macro_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")))]
6268
div!(__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"))))]
6579
mod_!(__modsi3: i32, u32);
6680

6781
#[cfg(not(all(feature = "c", target_arch = "x86")))]
6882
mod_!(__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"))))]
7193
divmod!(__divmodsi4, __divsi3: i32);
7294

src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ fn conv(i: u128) -> U64x2 {
111111
U64x2(i.low(), i.high())
112112
}
113113

114+
#[cfg(all(windows, target_pointer_width="64"))]
115+
fn sconv(i: i128) -> U64x2 {
116+
use int::LargeInt;
117+
let j = i as u128;
118+
U64x2(j.low(), j.high())
119+
}
120+
114121
#[cfg(test)]
115122
#[macro_use]
116123
extern crate quickcheck;

0 commit comments

Comments
 (0)