Skip to content

Commit 829c42e

Browse files
AaronKutchdmakarov
authored andcommitted
add remaining floating point tests
1 parent e3f7361 commit 829c42e

File tree

5 files changed

+160
-15
lines changed

5 files changed

+160
-15
lines changed

testcrate/tests/addsub.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_macros)]
2+
13
use testcrate::*;
24

35
macro_rules! sum {
@@ -107,3 +109,18 @@ fn float_addsub() {
107109
f64, __adddf3, __subdf3;
108110
);
109111
}
112+
113+
#[cfg(target_arch = "arm")]
114+
#[test]
115+
fn float_addsub_arm() {
116+
use compiler_builtins::float::{
117+
add::{__adddf3vfp, __addsf3vfp},
118+
sub::{__subdf3vfp, __subsf3vfp},
119+
Float,
120+
};
121+
122+
float_sum!(
123+
f32, __addsf3vfp, __subsf3vfp;
124+
f64, __adddf3vfp, __subdf3vfp;
125+
);
126+
}

testcrate/tests/cmp.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_macros)]
2+
13
use testcrate::*;
24

35
macro_rules! cmp {
@@ -50,3 +52,61 @@ fn float_comparisons() {
5052
);
5153
});
5254
}
55+
56+
macro_rules! cmp2 {
57+
($x:ident, $y:ident, $($unordered_val:expr, $fn_std:expr, $fn_builtins:ident);*;) => {
58+
$(
59+
let cmp0: i32 = if $x.is_nan() || $y.is_nan() {
60+
$unordered_val
61+
} else {
62+
$fn_std as i32
63+
};
64+
let cmp1: i32 = $fn_builtins($x, $y);
65+
if cmp0 != cmp1 {
66+
panic!("{}({}, {}): std: {}, builtins: {}", stringify!($fn_builtins), $x, $y, cmp0, cmp1);
67+
}
68+
)*
69+
};
70+
}
71+
72+
#[cfg(target_arch = "arm")]
73+
#[test]
74+
fn float_comparisons_arm() {
75+
use compiler_builtins::float::cmp::{
76+
__aeabi_dcmpeq, __aeabi_dcmpge, __aeabi_dcmpgt, __aeabi_dcmple, __aeabi_dcmplt,
77+
__aeabi_fcmpeq, __aeabi_fcmpge, __aeabi_fcmpgt, __aeabi_fcmple, __aeabi_fcmplt, __eqdf2vfp,
78+
__eqsf2vfp, __gedf2vfp, __gesf2vfp, __gtdf2vfp, __gtsf2vfp, __ledf2vfp, __lesf2vfp,
79+
__ltdf2vfp, __ltsf2vfp, __nedf2vfp, __nesf2vfp,
80+
};
81+
82+
fuzz_float_2(N, |x: f32, y: f32| {
83+
cmp2!(x, y,
84+
0, x < y, __aeabi_fcmplt;
85+
0, x <= y, __aeabi_fcmple;
86+
0, x == y, __aeabi_fcmpeq;
87+
0, x >= y, __aeabi_fcmpge;
88+
0, x > y, __aeabi_fcmpgt;
89+
0, x < y, __ltsf2vfp;
90+
0, x <= y, __lesf2vfp;
91+
0, x == y, __eqsf2vfp;
92+
0, x >= y, __gesf2vfp;
93+
0, x > y, __gtsf2vfp;
94+
1, x != y, __nesf2vfp;
95+
);
96+
});
97+
fuzz_float_2(N, |x: f64, y: f64| {
98+
cmp2!(x, y,
99+
0, x < y, __aeabi_dcmplt;
100+
0, x <= y, __aeabi_dcmple;
101+
0, x == y, __aeabi_dcmpeq;
102+
0, x >= y, __aeabi_dcmpge;
103+
0, x > y, __aeabi_dcmpgt;
104+
0, x < y, __ltdf2vfp;
105+
0, x <= y, __ledf2vfp;
106+
0, x == y, __eqdf2vfp;
107+
0, x >= y, __gedf2vfp;
108+
0, x > y, __gtdf2vfp;
109+
1, x != y, __nedf2vfp;
110+
);
111+
});
112+
}

testcrate/tests/div_rem.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_macros)]
2+
13
use compiler_builtins::int::sdiv::{__divmoddi4, __divmodsi4, __divmodti4};
24
use compiler_builtins::int::udiv::{__udivmoddi4, __udivmodsi4, __udivmodti4, u128_divide_sparc};
35
use testcrate::*;
@@ -134,3 +136,17 @@ fn float_div() {
134136
f64, __divdf3;
135137
);
136138
}
139+
140+
#[cfg(target_arch = "arm")]
141+
#[test]
142+
fn float_div_arm() {
143+
use compiler_builtins::float::{
144+
div::{__divdf3vfp, __divsf3vfp},
145+
Float,
146+
};
147+
148+
float!(
149+
f32, __divsf3vfp;
150+
f64, __divdf3vfp;
151+
);
152+
}

testcrate/tests/misc.rs

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// makes configuration easier
2+
#![allow(unused_macros)]
3+
4+
use compiler_builtins::float::Float;
15
use testcrate::*;
26

37
/// Make sure that the the edge case tester and randomized tester don't break, and list examples of
@@ -89,15 +93,37 @@ fn leading_zeros() {
8993
})
9094
}
9195

96+
macro_rules! extend {
97+
($fX:ident, $fD:ident, $fn:ident) => {
98+
fuzz_float(N, |x: $fX| {
99+
let tmp0 = x as $fD;
100+
let tmp1: $fD = $fn(x);
101+
if !Float::eq_repr(tmp0, tmp1) {
102+
panic!(
103+
"{}({}): std: {}, builtins: {}",
104+
stringify!($fn),
105+
x,
106+
tmp0,
107+
tmp1
108+
);
109+
}
110+
});
111+
};
112+
}
113+
92114
#[test]
93115
fn float_extend() {
94-
fuzz_float(N, |x: f32| {
95-
let tmp0 = x as f64;
96-
let tmp1: f64 = compiler_builtins::float::extend::__extendsfdf2(x);
97-
if !compiler_builtins::float::Float::eq_repr(tmp0, tmp1) {
98-
panic!("__extendsfdf2({}): std: {}, builtins: {}", x, tmp0, tmp1);
99-
}
100-
});
116+
use compiler_builtins::float::extend::__extendsfdf2;
117+
118+
extend!(f32, f64, __extendsfdf2);
119+
}
120+
121+
#[cfg(target_arch = "arm")]
122+
#[test]
123+
fn float_extend_arm() {
124+
use compiler_builtins::float::extend::__extendsfdf2vfp;
125+
126+
extend!(f32, f64, __extendsfdf2vfp);
101127
}
102128

103129
// This doesn't quite work because of issues related to
@@ -108,14 +134,16 @@ macro_rules! pow {
108134
($($f:ty, $fn:ident);*;) => {
109135
$(
110136
fuzz_float_2(N, |x: $f, y: $f| {
111-
let n = y as i32;
112-
let tmp0: $f = x.powi(n);
113-
let tmp1: $f = $fn(x, n);
114-
if tmp0 != tmp1 {
115-
panic!(
116-
"{}({}, {}): std: {}, builtins: {}",
117-
stringify!($fn), x, y, tmp0, tmp1
118-
);
137+
if !(Float::is_subnormal(x) || Float::is_subnormal(y) || x < 0. || y < 0.) {
138+
let n = y as i32;
139+
let tmp0: $f = x.powi(n);
140+
let tmp1: $f = $fn(x, n);
141+
if tmp0 != tmp1 {
142+
panic!(
143+
"{}({}, {}): std: {}, builtins: {}",
144+
stringify!($fn), x, y, tmp0, tmp1
145+
);
146+
}
119147
}
120148
});
121149
)*
@@ -132,3 +160,11 @@ fn float_pow() {
132160
);
133161
}
134162
*/
163+
164+
// placeholder test to make sure basic functionality works
165+
#[test]
166+
fn float_pow() {
167+
use compiler_builtins::float::pow::{__powidf2, __powisf2};
168+
assert_eq!(__powisf2(-3.0, 3), -27.0);
169+
assert_eq!(__powidf2(-3.0, 3), -27.0);
170+
}

testcrate/tests/mul.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_macros)]
2+
13
use testcrate::*;
24

35
macro_rules! mul {
@@ -112,3 +114,17 @@ fn float_mul() {
112114
f64, __muldf3;
113115
);
114116
}
117+
118+
#[cfg(target_arch = "arm")]
119+
#[test]
120+
fn float_mul_arm() {
121+
use compiler_builtins::float::{
122+
mul::{__muldf3vfp, __mulsf3vfp},
123+
Float,
124+
};
125+
126+
float_mul!(
127+
f32, __mulsf3vfp;
128+
f64, __muldf3vfp;
129+
);
130+
}

0 commit comments

Comments
 (0)