Skip to content

Commit 1692bcc

Browse files
committed
Conditionally do not compile NaN roundtrip tests on x87 fp.
1 parent f020ba4 commit 1692bcc

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
@@ -296,18 +296,18 @@ fn test_next_up() {
296296
let smallest_normal = f32::from_bits(0x0080_0000);
297297

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

312312
assert_eq!(f32::NEG_INFINITY.next_up(), f32::MIN);
313313
assert_eq!(f32::MIN.next_up(), -max_down);
@@ -333,18 +333,18 @@ fn test_next_down() {
333333
let smallest_normal = f32::from_bits(0x0080_0000);
334334

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

349349
assert_eq!(f32::NEG_INFINITY.next_down(), f32::NEG_INFINITY);
350350
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)