Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ features = ["c"]
- [ ] arm/unordsf2vfp.S
- [x] ashldi3.c
- [x] ashrdi3.c
- [ ] divdf3.c
- [x] divdf3.c
- [x] divdi3.c
- [x] divmoddi4.c
- [x] divmodsi4.c
- [ ] divsf3.c
- [x] divsf3.c
- [x] divsi3.c
- [ ] extendhfsf2.c
- [ ] extendsfdf2.c
Expand Down
185 changes: 185 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ mod tests {
Mulsf3,
Muldf3,

// float/div.rs
Divsf3,
Divdf3,

// int/mul.rs
Muldi3,
Mulodi4,
Expand Down Expand Up @@ -3399,6 +3403,187 @@ fn muldf3() {
}
}

#[derive(Eq, Hash, PartialEq)]
pub struct Divsf3 {
a: u32, // f32
b: u32, // f32
c: u32, // f32
}

impl TestCase for Divsf3 {
fn name() -> &'static str {
"divsf3"
}

fn generate<R>(rng: &mut R) -> Option<Self>
where
R: Rng,
Self: Sized,
{
let a = gen_large_f32(rng);
let b = gen_large_f32(rng);
if b == 0.0 {
return None;
}
let c = a / b;
// TODO accept NaNs. We don't do that right now because we can't check
// for NaN-ness on the thumb targets (due to missing intrinsics)
if a.is_nan() || b.is_nan() || c.is_nan()|| c.abs() <= unsafe { mem::transmute(16777215u32) } {
return None;
}

Some(
Divsf3 {
a: to_u32(a),
b: to_u32(b),
c: to_u32(c),
},
)
}

fn to_string(&self, buffer: &mut String) {
writeln!(
buffer,
"(({a}, {b}), {c}),",
a = self.a,
b = self.b,
c = self.c
)
.unwrap();
}

fn prologue() -> &'static str {
r#"
#[cfg(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test))]
use core::mem;
#[cfg(not(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test)))]
use std::mem;
use compiler_builtins::float::div::__divsf3;

fn mk_f32(x: u32) -> f32 {
unsafe { mem::transmute(x) }
}

fn to_u32(x: f32) -> u32 {
unsafe { mem::transmute(x) }
}

static TEST_CASES: &[((u32, u32), u32)] = &[
"#
}

fn epilogue() -> &'static str {
"
];

#[test]
fn divsf3() {
for &((a, b), c) in TEST_CASES {
let c_ = __divsf3(mk_f32(a), mk_f32(b));
assert_eq!(((a, b), c), ((a, b), to_u32(c_)));
}
}
"
}
}

#[derive(Eq, Hash, PartialEq)]
pub struct Divdf3 {
a: u64, // f64
b: u64, // f64
c: u64, // f64
}

impl TestCase for Divdf3 {
fn name() -> &'static str {
"divdf3"
}

fn generate<R>(rng: &mut R) -> Option<Self>
where
R: Rng,
Self: Sized,
{
let a = gen_large_f64(rng);
let b = gen_large_f64(rng);
if b == 0.0 {
return None;
}
let c = a / b;
// TODO accept NaNs. We don't do that right now because we can't check
// for NaN-ness on the thumb targets (due to missing intrinsics)
if a.is_nan() || b.is_nan() || c.is_nan()
|| c.abs() <= unsafe { mem::transmute(4503599627370495u64) } {
return None;
}

Some(
Divdf3 {
a: to_u64(a),
b: to_u64(b),
c: to_u64(c),
},
)
}

fn to_string(&self, buffer: &mut String) {
writeln!(
buffer,
"(({a}, {b}), {c}),",
a = self.a,
b = self.b,
c = self.c
)
.unwrap();
}

fn prologue() -> &'static str {
r#"
#[cfg(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test))]
use core::mem;
#[cfg(not(all(target_arch = "arm",
not(any(target_env = "gnu", target_env = "musl")),
target_os = "linux",
test)))]
use std::mem;
use compiler_builtins::float::div::__divdf3;

fn mk_f64(x: u64) -> f64 {
unsafe { mem::transmute(x) }
}

fn to_u64(x: f64) -> u64 {
unsafe { mem::transmute(x) }
}

static TEST_CASES: &[((u64, u64), u64)] = &[
"#
}

fn epilogue() -> &'static str {
"
];

#[test]
fn divdf3() {
for &((a, b), c) in TEST_CASES {
let c_ = __divdf3(mk_f64(a), mk_f64(b));
assert_eq!(((a, b), c), ((a, b), to_u64(c_)));
}
}
"
}
}


#[derive(Eq, Hash, PartialEq)]
pub struct Udivdi3 {
Expand Down
Loading