Skip to content

Commit fbe215a

Browse files
orlpUrgau
authored andcommitted
Conditionally do not compile NaN roundtrip tests on x87 fp.
1 parent 712bf2a commit fbe215a

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

library/std/src/f32/tests.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,18 @@ fn test_next_up() {
308308
let smallest_normal = f32::from_bits(0x0080_0000);
309309

310310
// Check that NaNs roundtrip.
311-
// Because x87 can lose NaN bits when passed through a function, ensure the reference value
312-
// also passes through a function boundary.
313-
#[inline(never)]
314-
fn identity(x: f32) -> f32 {
315-
crate::hint::black_box(x)
311+
// Ignore test on x87 floating point, the code is still correct but these
312+
// platforms do not guarantee NaN payloads are preserved, which caused these
313+
// tests to fail.
314+
#[cfg(not(all(target_arch = "x86", not(target_feature = "fxsr"))))]
315+
{
316+
let nan0 = f32::NAN;
317+
let nan1 = f32::from_bits(f32::NAN.to_bits() ^ 0x002a_aaaa);
318+
let nan2 = f32::from_bits(f32::NAN.to_bits() ^ 0x0055_5555);
319+
assert_eq!(nan0.next_up().to_bits(), nan0.to_bits());
320+
assert_eq!(nan1.next_up().to_bits(), nan1.to_bits());
321+
assert_eq!(nan2.next_up().to_bits(), nan2.to_bits());
316322
}
317-
let nan0 = f32::NAN;
318-
let nan1 = f32::from_bits(f32::NAN.to_bits() ^ 0x002a_aaaa);
319-
let nan2 = f32::from_bits(f32::NAN.to_bits() ^ 0x0055_5555);
320-
assert_eq!(nan0.next_up().to_bits(), identity(nan0).to_bits());
321-
assert_eq!(nan1.next_up().to_bits(), identity(nan1).to_bits());
322-
assert_eq!(nan2.next_up().to_bits(), identity(nan2).to_bits());
323323

324324
assert_eq!(f32::NEG_INFINITY.next_up(), f32::MIN);
325325
assert_eq!(f32::MIN.next_up(), -max_down);
@@ -345,18 +345,18 @@ fn test_next_down() {
345345
let smallest_normal = f32::from_bits(0x0080_0000);
346346

347347
// Check that NaNs roundtrip.
348-
// Because x87 can lose NaN bits when passed through a function, ensure the reference value
349-
// also passes through a function boundary.
350-
#[inline(never)]
351-
fn identity(x: f32) -> f32 {
352-
crate::hint::black_box(x)
348+
// Ignore test on x87 floating point, the code is still correct but these
349+
// platforms do not guarantee NaN payloads are preserved, which caused these
350+
// tests to fail.
351+
#[cfg(not(all(target_arch = "x86", not(target_feature = "fxsr"))))]
352+
{
353+
let nan0 = f32::NAN;
354+
let nan1 = f32::from_bits(f32::NAN.to_bits() ^ 0x002a_aaaa);
355+
let nan2 = f32::from_bits(f32::NAN.to_bits() ^ 0x0055_5555);
356+
assert_eq!(nan0.next_down().to_bits(), nan0.to_bits());
357+
assert_eq!(nan1.next_down().to_bits(), nan1.to_bits());
358+
assert_eq!(nan2.next_down().to_bits(), nan2.to_bits());
353359
}
354-
let nan0 = f32::NAN;
355-
let nan1 = f32::from_bits(f32::NAN.to_bits() ^ 0x002a_aaaa);
356-
let nan2 = f32::from_bits(f32::NAN.to_bits() ^ 0x0055_5555);
357-
assert_eq!(nan0.next_down().to_bits(), identity(nan0).to_bits());
358-
assert_eq!(nan1.next_down().to_bits(), identity(nan1).to_bits());
359-
assert_eq!(nan2.next_down().to_bits(), identity(nan2).to_bits());
360360

361361
assert_eq!(f32::NEG_INFINITY.next_down(), f32::NEG_INFINITY);
362362
assert_eq!(f32::MIN.next_down(), f32::NEG_INFINITY);

library/std/src/f64/tests.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,18 @@ fn test_next_up() {
298298
let smallest_normal = f64::from_bits(0x0010_0000_0000_0000);
299299

300300
// Check that NaNs roundtrip.
301-
// Because x87 can lose NaN bits when passed through a function, ensure the reference value
302-
// also passes through a function boundary.
303-
#[inline(never)]
304-
fn identity(x: f64) -> f64 {
305-
crate::hint::black_box(x)
301+
// Ignore test on x87 floating point, the code is still correct but these
302+
// platforms do not guarantee NaN payloads are preserved, which caused these
303+
// tests to fail.
304+
#[cfg(not(all(target_arch = "x86", not(target_feature = "fxsr"))))]
305+
{
306+
let nan0 = f64::NAN;
307+
let nan1 = f64::from_bits(f64::NAN.to_bits() ^ 0x000a_aaaa_aaaa_aaaa);
308+
let nan2 = f64::from_bits(f64::NAN.to_bits() ^ 0x0005_5555_5555_5555);
309+
assert_eq!(nan0.next_up().to_bits(), nan0.to_bits());
310+
assert_eq!(nan1.next_up().to_bits(), nan1.to_bits());
311+
assert_eq!(nan2.next_up().to_bits(), nan2.to_bits());
306312
}
307-
let nan0 = f64::NAN;
308-
let nan1 = f64::from_bits(f64::NAN.to_bits() ^ 0x000a_aaaa_aaaa_aaaa);
309-
let nan2 = f64::from_bits(f64::NAN.to_bits() ^ 0x0005_5555_5555_5555);
310-
assert_eq!(nan0.next_up().to_bits(), identity(nan0).to_bits());
311-
assert_eq!(nan1.next_up().to_bits(), identity(nan1).to_bits());
312-
assert_eq!(nan2.next_up().to_bits(), identity(nan2).to_bits());
313313

314314
assert_eq!(f64::NEG_INFINITY.next_up(), f64::MIN);
315315
assert_eq!(f64::MIN.next_up(), -max_down);
@@ -335,18 +335,18 @@ fn test_next_down() {
335335
let smallest_normal = f64::from_bits(0x0010_0000_0000_0000);
336336

337337
// Check that NaNs roundtrip.
338-
// Because x87 can lose NaN bits when passed through a function, ensure the reference value
339-
// also passes through a function boundary.
340-
#[inline(never)]
341-
fn identity(x: f64) -> f64 {
342-
crate::hint::black_box(x)
338+
// Ignore test on x87 floating point, the code is still correct but these
339+
// platforms do not guarantee NaN payloads are preserved, which caused these
340+
// tests to fail.
341+
#[cfg(not(all(target_arch = "x86", not(target_feature = "fxsr"))))]
342+
{
343+
let nan0 = f64::NAN;
344+
let nan1 = f64::from_bits(f64::NAN.to_bits() ^ 0x000a_aaaa_aaaa_aaaa);
345+
let nan2 = f64::from_bits(f64::NAN.to_bits() ^ 0x0005_5555_5555_5555);
346+
assert_eq!(nan0.next_down().to_bits(), nan0.to_bits());
347+
assert_eq!(nan1.next_down().to_bits(), nan1.to_bits());
348+
assert_eq!(nan2.next_down().to_bits(), nan2.to_bits());
343349
}
344-
let nan0 = f64::NAN;
345-
let nan1 = f64::from_bits(f64::NAN.to_bits() ^ 0x000a_aaaa_aaaa_aaaa);
346-
let nan2 = f64::from_bits(f64::NAN.to_bits() ^ 0x0005_5555_5555_5555);
347-
assert_eq!(nan0.next_down().to_bits(), identity(nan0).to_bits());
348-
assert_eq!(nan1.next_down().to_bits(), identity(nan1).to_bits());
349-
assert_eq!(nan2.next_down().to_bits(), identity(nan2).to_bits());
350350

351351
assert_eq!(f64::NEG_INFINITY.next_down(), f64::NEG_INFINITY);
352352
assert_eq!(f64::MIN.next_down(), f64::NEG_INFINITY);

0 commit comments

Comments
 (0)