Skip to content

Commit

Permalink
Add __divmodti4
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Aug 29, 2020
1 parent bc06465 commit 26fe6ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/int/sdiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ intrinsics! {
i128_div_rem(a, b).1
}

// LLVM does not currently have a `__divmodti4` function
// LLVM does not currently have a `__divmodti4` function, but GCC does
#[maybe_use_optimized_c_shim]
/// Returns `n / d` and sets `*rem = n % d`
pub extern "C" fn __divmodti4(a: i128, b: i128, rem: &mut i128) -> i128 {
let quo_rem = i128_div_rem(a, b);
*rem = quo_rem.1;
quo_rem.0
}
}
13 changes: 13 additions & 0 deletions testcrate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,19 @@ fn main() {
(builtins::int::sdiv::__divmodsi4(a, b, &mut r), r)
}",
);
gen(
|(a, b): (MyI128, MyI128)| {
if b.0 == 0 {
None
} else {
Some((a.0 / b.0, a.0 % b.0))
}
},
"{
let mut r = 0;
(builtins::int::sdiv::__divmodti4(a, b, &mut r), r)
}",
);
gen(
|(a, b): (MyI32, MyI32)| {
if b.0 == 0 {
Expand Down
8 changes: 1 addition & 7 deletions testcrate/tests/div_rem.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
use rand_xoshiro::rand_core::{RngCore, SeedableRng};
use rand_xoshiro::Xoshiro128StarStar;

use compiler_builtins::int::sdiv::{__divmoddi4, __divmodsi4, __divti3, __modti3};
use compiler_builtins::int::sdiv::{__divmoddi4, __divmodsi4, __divmodti4};
use compiler_builtins::int::udiv::{__udivmoddi4, __udivmodsi4, __udivmodti4};

// because `__divmodti4` does not exist, we synthesize it
fn __divmodti4(a: i128, b: i128, rem: &mut i128) -> i128 {
*rem = __modti3(a, b);
__divti3(a, b)
}

/// Creates intensive test functions for division functions of a certain size
macro_rules! test {
(
Expand Down

0 comments on commit 26fe6ff

Please sign in to comment.