Skip to content

Commit f97d616

Browse files
committed
u128 sdiv intrinsics
1 parent d2eae2e commit f97d616

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
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

src/int/sdiv.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@ 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+
let t = (r as $ty ^ s) - s;
19+
($conv)(t as $ty)
1620
}
1721
}
1822
}
1923

2024
macro_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")))]
6270
div!(__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"))))]
6581
mod_!(__modsi3: i32, u32);
6682

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

0 commit comments

Comments
 (0)