Skip to content

Commit

Permalink
Ensure tests don't fail on i586 in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
beetrees committed Jul 1, 2024
1 parent 0e1c832 commit 0f643c4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
5 changes: 5 additions & 0 deletions tests/assembly/x86-return-float.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,10 @@
//@ assembly-output: emit-asm
//@ only-x86
// FIXME(#114479): LLVM miscompiles loading and storing `f32` and `f64` when SSE is disabled.
// There's no compiletest directive to ignore a test on i586 only, so just always explicitly enable
// SSE2.
// Use the same target CPU as `i686` so that LLVM orders the instructions in the same order.
//@ compile-flags: -Ctarget-feature= sse2 -Ctarget-cpu=pentium4
// Force frame pointers to make ASM more consistent between targets
//@ compile-flags: -O -C force-frame-pointers
//@ filecheck-flags: --implicit-check-not fld --implicit-check-not fst
Expand Down
90 changes: 47 additions & 43 deletions tests/ui/abi/numbers-arithmetic/return-float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 4,54 @@
// Test that floats (in particular signalling NaNs) are losslessly returned from functions.

fn main() {
let bits_f32 = std::hint::black_box([
4.2_f32.to_bits(),
f32::INFINITY.to_bits(),
f32::NEG_INFINITY.to_bits(),
f32::NAN.to_bits(),
// These two masks cover all the mantissa bits. One of them is a signalling NaN, the other
// is quiet.
// Similar to the masks in `test_float_bits_conv` in library/std/src/f32/tests.rs
f32::NAN.to_bits() ^ 0x002A_AAAA,
f32::NAN.to_bits() ^ 0x0055_5555,
// Same as above but with the sign bit flipped.
f32::NAN.to_bits() ^ 0x802A_AAAA,
f32::NAN.to_bits() ^ 0x8055_5555,
]);
for bits in bits_f32 {
assert_eq!(identity(f32::from_bits(bits)).to_bits(), bits);
// Test types that are returned as scalar pairs.
assert_eq!(identity((f32::from_bits(bits), 42)).0.to_bits(), bits);
assert_eq!(identity((42, f32::from_bits(bits))).1.to_bits(), bits);
let (a, b) = identity((f32::from_bits(bits), f32::from_bits(bits)));
assert_eq!((a.to_bits(), b.to_bits()), (bits, bits));
}
// FIXME(#114479): LLVM miscompiles loading and storing `f32` and `f64` when SSE is disabled on
// x86.
if cfg!(not(all(target_arch = "x86", not(target_feature = "sse2")))) {
let bits_f32 = std::hint::black_box([
4.2_f32.to_bits(),
f32::INFINITY.to_bits(),
f32::NEG_INFINITY.to_bits(),
f32::NAN.to_bits(),
// These two masks cover all the mantissa bits. One of them is a signalling NaN, the
// other is quiet.
// Similar to the masks in `test_float_bits_conv` in library/std/src/f32/tests.rs
f32::NAN.to_bits() ^ 0x002A_AAAA,
f32::NAN.to_bits() ^ 0x0055_5555,
// Same as above but with the sign bit flipped.
f32::NAN.to_bits() ^ 0x802A_AAAA,
f32::NAN.to_bits() ^ 0x8055_5555,
]);
for bits in bits_f32 {
assert_eq!(identity(f32::from_bits(bits)).to_bits(), bits);
// Test types that are returned as scalar pairs.
assert_eq!(identity((f32::from_bits(bits), 42)).0.to_bits(), bits);
assert_eq!(identity((42, f32::from_bits(bits))).1.to_bits(), bits);
let (a, b) = identity((f32::from_bits(bits), f32::from_bits(bits)));
assert_eq!((a.to_bits(), b.to_bits()), (bits, bits));
}

let bits_f64 = std::hint::black_box([
4.2_f64.to_bits(),
f64::INFINITY.to_bits(),
f64::NEG_INFINITY.to_bits(),
f64::NAN.to_bits(),
// These two masks cover all the mantissa bits. One of them is a signalling NaN, the other
// is quiet.
// Similar to the masks in `test_float_bits_conv` in library/std/src/f64/tests.rs
f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA,
f64::NAN.to_bits() ^ 0x0005_5555_5555_5555,
// Same as above but with the sign bit flipped.
f64::NAN.to_bits() ^ 0x800A_AAAA_AAAA_AAAA,
f64::NAN.to_bits() ^ 0x8005_5555_5555_5555,
]);
for bits in bits_f64 {
assert_eq!(identity(f64::from_bits(bits)).to_bits(), bits);
// Test types that are returned as scalar pairs.
assert_eq!(identity((f64::from_bits(bits), 42)).0.to_bits(), bits);
assert_eq!(identity((42, f64::from_bits(bits))).1.to_bits(), bits);
let (a, b) = identity((f64::from_bits(bits), f64::from_bits(bits)));
assert_eq!((a.to_bits(), b.to_bits()), (bits, bits));
let bits_f64 = std::hint::black_box([
4.2_f64.to_bits(),
f64::INFINITY.to_bits(),
f64::NEG_INFINITY.to_bits(),
f64::NAN.to_bits(),
// These two masks cover all the mantissa bits. One of them is a signalling NaN, the
// other is quiet.
// Similar to the masks in `test_float_bits_conv` in library/std/src/f64/tests.rs
f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA,
f64::NAN.to_bits() ^ 0x0005_5555_5555_5555,
// Same as above but with the sign bit flipped.
f64::NAN.to_bits() ^ 0x800A_AAAA_AAAA_AAAA,
f64::NAN.to_bits() ^ 0x8005_5555_5555_5555,
]);
for bits in bits_f64 {
assert_eq!(identity(f64::from_bits(bits)).to_bits(), bits);
// Test types that are returned as scalar pairs.
assert_eq!(identity((f64::from_bits(bits), 42)).0.to_bits(), bits);
assert_eq!(identity((42, f64::from_bits(bits))).1.to_bits(), bits);
let (a, b) = identity((f64::from_bits(bits), f64::from_bits(bits)));
assert_eq!((a.to_bits(), b.to_bits()), (bits, bits));
}
}
}

Expand Down

0 comments on commit 0f643c4

Please sign in to comment.