|
4 | 4 | // Test that floats (in particular signalling NaNs) are losslessly returned from functions.
|
5 | 5 |
|
6 | 6 | fn main() {
|
7 |
| - let bits_f32 = std::hint::black_box([ |
8 |
| - 4.2_f32.to_bits(), |
9 |
| - f32::INFINITY.to_bits(), |
10 |
| - f32::NEG_INFINITY.to_bits(), |
11 |
| - f32::NAN.to_bits(), |
12 |
| - // These two masks cover all the mantissa bits. One of them is a signalling NaN, the other |
13 |
| - // is quiet. |
14 |
| - // Similar to the masks in `test_float_bits_conv` in library/std/src/f32/tests.rs |
15 |
| - f32::NAN.to_bits() ^ 0x002A_AAAA, |
16 |
| - f32::NAN.to_bits() ^ 0x0055_5555, |
17 |
| - // Same as above but with the sign bit flipped. |
18 |
| - f32::NAN.to_bits() ^ 0x802A_AAAA, |
19 |
| - f32::NAN.to_bits() ^ 0x8055_5555, |
20 |
| - ]); |
21 |
| - for bits in bits_f32 { |
22 |
| - assert_eq!(identity(f32::from_bits(bits)).to_bits(), bits); |
23 |
| - // Test types that are returned as scalar pairs. |
24 |
| - assert_eq!(identity((f32::from_bits(bits), 42)).0.to_bits(), bits); |
25 |
| - assert_eq!(identity((42, f32::from_bits(bits))).1.to_bits(), bits); |
26 |
| - let (a, b) = identity((f32::from_bits(bits), f32::from_bits(bits))); |
27 |
| - assert_eq!((a.to_bits(), b.to_bits()), (bits, bits)); |
28 |
| - } |
| 7 | + // FIXME(#114479): LLVM miscompiles loading and storing `f32` and `f64` when SSE is disabled on |
| 8 | + // x86. |
| 9 | + if cfg!(not(all(target_arch = "x86", not(target_feature = "sse2")))) { |
| 10 | + let bits_f32 = std::hint::black_box([ |
| 11 | + 4.2_f32.to_bits(), |
| 12 | + f32::INFINITY.to_bits(), |
| 13 | + f32::NEG_INFINITY.to_bits(), |
| 14 | + f32::NAN.to_bits(), |
| 15 | + // These two masks cover all the mantissa bits. One of them is a signalling NaN, the |
| 16 | + // other is quiet. |
| 17 | + // Similar to the masks in `test_float_bits_conv` in library/std/src/f32/tests.rs |
| 18 | + f32::NAN.to_bits() ^ 0x002A_AAAA, |
| 19 | + f32::NAN.to_bits() ^ 0x0055_5555, |
| 20 | + // Same as above but with the sign bit flipped. |
| 21 | + f32::NAN.to_bits() ^ 0x802A_AAAA, |
| 22 | + f32::NAN.to_bits() ^ 0x8055_5555, |
| 23 | + ]); |
| 24 | + for bits in bits_f32 { |
| 25 | + assert_eq!(identity(f32::from_bits(bits)).to_bits(), bits); |
| 26 | + // Test types that are returned as scalar pairs. |
| 27 | + assert_eq!(identity((f32::from_bits(bits), 42)).0.to_bits(), bits); |
| 28 | + assert_eq!(identity((42, f32::from_bits(bits))).1.to_bits(), bits); |
| 29 | + let (a, b) = identity((f32::from_bits(bits), f32::from_bits(bits))); |
| 30 | + assert_eq!((a.to_bits(), b.to_bits()), (bits, bits)); |
| 31 | + } |
29 | 32 |
|
30 |
| - let bits_f64 = std::hint::black_box([ |
31 |
| - 4.2_f64.to_bits(), |
32 |
| - f64::INFINITY.to_bits(), |
33 |
| - f64::NEG_INFINITY.to_bits(), |
34 |
| - f64::NAN.to_bits(), |
35 |
| - // These two masks cover all the mantissa bits. One of them is a signalling NaN, the other |
36 |
| - // is quiet. |
37 |
| - // Similar to the masks in `test_float_bits_conv` in library/std/src/f64/tests.rs |
38 |
| - f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA, |
39 |
| - f64::NAN.to_bits() ^ 0x0005_5555_5555_5555, |
40 |
| - // Same as above but with the sign bit flipped. |
41 |
| - f64::NAN.to_bits() ^ 0x800A_AAAA_AAAA_AAAA, |
42 |
| - f64::NAN.to_bits() ^ 0x8005_5555_5555_5555, |
43 |
| - ]); |
44 |
| - for bits in bits_f64 { |
45 |
| - assert_eq!(identity(f64::from_bits(bits)).to_bits(), bits); |
46 |
| - // Test types that are returned as scalar pairs. |
47 |
| - assert_eq!(identity((f64::from_bits(bits), 42)).0.to_bits(), bits); |
48 |
| - assert_eq!(identity((42, f64::from_bits(bits))).1.to_bits(), bits); |
49 |
| - let (a, b) = identity((f64::from_bits(bits), f64::from_bits(bits))); |
50 |
| - assert_eq!((a.to_bits(), b.to_bits()), (bits, bits)); |
| 33 | + let bits_f64 = std::hint::black_box([ |
| 34 | + 4.2_f64.to_bits(), |
| 35 | + f64::INFINITY.to_bits(), |
| 36 | + f64::NEG_INFINITY.to_bits(), |
| 37 | + f64::NAN.to_bits(), |
| 38 | + // These two masks cover all the mantissa bits. One of them is a signalling NaN, the |
| 39 | + // other is quiet. |
| 40 | + // Similar to the masks in `test_float_bits_conv` in library/std/src/f64/tests.rs |
| 41 | + f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA, |
| 42 | + f64::NAN.to_bits() ^ 0x0005_5555_5555_5555, |
| 43 | + // Same as above but with the sign bit flipped. |
| 44 | + f64::NAN.to_bits() ^ 0x800A_AAAA_AAAA_AAAA, |
| 45 | + f64::NAN.to_bits() ^ 0x8005_5555_5555_5555, |
| 46 | + ]); |
| 47 | + for bits in bits_f64 { |
| 48 | + assert_eq!(identity(f64::from_bits(bits)).to_bits(), bits); |
| 49 | + // Test types that are returned as scalar pairs. |
| 50 | + assert_eq!(identity((f64::from_bits(bits), 42)).0.to_bits(), bits); |
| 51 | + assert_eq!(identity((42, f64::from_bits(bits))).1.to_bits(), bits); |
| 52 | + let (a, b) = identity((f64::from_bits(bits), f64::from_bits(bits))); |
| 53 | + assert_eq!((a.to_bits(), b.to_bits()), (bits, bits)); |
| 54 | + } |
51 | 55 | }
|
52 | 56 | }
|
53 | 57 |
|
|
0 commit comments