allow force_eval! to produce a result and use that result to more explicitly force rounding on x87.
This commit is contained in:
parent
94b416e496
commit
f8c8c8b2fe
6 changed files with 17 additions and 11 deletions
|
|
@ -220,7 +220,8 @@ mod tests {
|
|||
|
||||
let result = fma(-0.992, -0.992, -0.992);
|
||||
//force rounding to storage format on x87 to prevent superious errors.
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(result);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let result = force_eval!(result);
|
||||
assert_eq!(result, -0.007936000000000007,);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
macro_rules! force_eval {
|
||||
($e:expr) => {
|
||||
unsafe {
|
||||
::core::ptr::read_volatile(&$e);
|
||||
::core::ptr::read_volatile(&$e)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -484,8 +484,10 @@ mod tests {
|
|||
let exp = expected(*val);
|
||||
let res = computed(*val);
|
||||
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(exp);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(res);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let exp = force_eval!(exp);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let res = force_eval!(res);
|
||||
assert!(
|
||||
if exp.is_nan() {
|
||||
res.is_nan()
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
|
|||
let tmp = x as f64 * INV_PIO2 + TO_INT;
|
||||
// force rounding of tmp to it's storage format on x87 to avoid
|
||||
// excess precision issues.
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(tmp);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let tmp = force_eval!(tmp);
|
||||
let f_n = tmp - TO_INT;
|
||||
let n = f_n as i32;
|
||||
let mut r = x - f_n * PIO2_1;
|
||||
|
|
@ -195,25 +196,25 @@ mod tests {
|
|||
#[test]
|
||||
fn test_near_pi() {
|
||||
let arg = 3.141592025756836;
|
||||
force_eval!(arg);
|
||||
let arg = force_eval!(arg);
|
||||
assert_eq!(
|
||||
rem_pio2(arg),
|
||||
(2, -6.278329573009626e-7, -2.1125998133974653e-23)
|
||||
);
|
||||
let arg = 3.141592033207416;
|
||||
force_eval!(arg);
|
||||
let arg = force_eval!(arg);
|
||||
assert_eq!(
|
||||
rem_pio2(arg),
|
||||
(2, -6.20382377148128e-7, -2.1125998133974653e-23)
|
||||
);
|
||||
let arg = 3.141592144966125;
|
||||
force_eval!(arg);
|
||||
let arg = force_eval!(arg);
|
||||
assert_eq!(
|
||||
rem_pio2(arg),
|
||||
(2, -5.086236681942706e-7, -2.1125998133974653e-23)
|
||||
);
|
||||
let arg = 3.141592979431152;
|
||||
force_eval!(arg);
|
||||
let arg = force_eval!(arg);
|
||||
assert_eq!(
|
||||
rem_pio2(arg),
|
||||
(2, 3.2584135866119817e-7, -2.1125998133974653e-23)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ pub(crate) fn rem_pio2f(x: f32) -> (i32, f64) {
|
|||
let tmp = x64 * INV_PIO2 + TOINT;
|
||||
// force rounding of tmp to it's storage format on x87 to avoid
|
||||
// excess precision issues.
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(tmp);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let tmp = force_eval!(tmp);
|
||||
let f_n = tmp - TOINT;
|
||||
return (f_n as i32, x64 - f_n * PIO2_1 - f_n * PIO2_1T);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ fn test_near_pi() {
|
|||
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
|
||||
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
|
||||
let result = sin(x);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(result);
|
||||
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
|
||||
let result = force_eval!(result);
|
||||
assert_eq!(result, sx);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue