Skip to content

Commit 16a1186

Browse files
Rollup merge of rust-lang#129835 - RalfJung:float-tests, r=workingjubilee
enable const-float-classify test, and test_next_up/down on 32bit x86 The test_next_up/down tests have been disabled on all 32bit x86 targets, which goes too far -- they should definitely work on our (tier 1) i686 target, it is only without SSE that we might run into trouble due to rust-lang#114479. However, I cannot reproduce that trouble any more -- maybe that got fixed by rust-lang#123351? The const-float-classify test relied on const traits "because we can", and got disabled when const traits got removed. That's an unfortunate reduction in test coverage of our float functionality, so let's restore the test in a way that does not rely on const traits. The const-float tests are actually testing runtime behavior as well, and I don't think that runtime behavior is covered anywhere else. Probably they shouldn't be called "const-float", but we don't have a `tests/ui/float` folder... should I create one and move them there? Are there any other ui tests that should be moved there? I also removed some FIXME referring to not use x87 for Rust-to-Rust-calls -- that has happened in rust-lang#123351 so this got fixed indeed. Does that mean we can simplify all that float code again? I am not sure how to test it. Is running the test suite with an i586 target enough? Cc `@tgross35` `@workingjubilee`
2 parents 4cda52d + e556c13 commit 16a1186

11 files changed

+254
-282
lines changed

library/core/src/num/f16.rs

+1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ impl f16 {
435435
// WASM, see llvm/llvm-project#96437). These are platforms bugs, and Rust will misbehave on
436436
// such platforms, but we can at least try to make things seem as sane as possible by being
437437
// careful here.
438+
// see also https://github.com/rust-lang/rust/issues/114479
438439
if self.is_infinite() {
439440
// Thus, a value may compare unequal to infinity, despite having a "full" exponent mask.
440441
FpCategory::Infinite

library/core/src/num/f32.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,7 @@ impl f32 {
662662
// hardware flushes subnormals to zero. These are platforms bugs, and Rust will misbehave on
663663
// such hardware, but we can at least try to make things seem as sane as possible by being
664664
// careful here.
665-
//
666-
// FIXME(jubilee): Using x87 operations is never necessary in order to function
667-
// on x86 processors for Rust-to-Rust calls, so this issue should not happen.
668-
// Code generation should be adjusted to use non-C calling conventions, avoiding this.
665+
// see also https://github.com/rust-lang/rust/issues/114479
669666
if self.is_infinite() {
670667
// A value may compare unequal to infinity, despite having a "full" exponent mask.
671668
FpCategory::Infinite

library/core/src/num/f64.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,7 @@ impl f64 {
660660
// float semantics Rust relies on: x87 uses a too-large exponent, and some hardware flushes
661661
// subnormals to zero. These are platforms bugs, and Rust will misbehave on such hardware,
662662
// but we can at least try to make things seem as sane as possible by being careful here.
663-
//
664-
// FIXME(jubilee): Using x87 operations is never necessary in order to function
665-
// on x86 processors for Rust-to-Rust calls, so this issue should not happen.
666-
// Code generation should be adjusted to use non-C calling conventions, avoiding this.
663+
// see also https://github.com/rust-lang/rust/issues/114479
667664
//
668665
// Thus, a value may compare unequal to infinity, despite having a "full" exponent mask.
669666
// And it may not be NaN, as it can simply be an "overextended" finite value.

library/std/src/f32/tests.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@ use crate::f32::consts;
22
use crate::num::{FpCategory as Fp, *};
33

44
/// Smallest number
5-
#[allow(dead_code)] // unused on x86
65
const TINY_BITS: u32 = 0x1;
76

87
/// Next smallest number
9-
#[allow(dead_code)] // unused on x86
108
const TINY_UP_BITS: u32 = 0x2;
119

1210
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
13-
#[allow(dead_code)] // unused on x86
1411
const MAX_DOWN_BITS: u32 = 0x7f7f_fffe;
1512

1613
/// Zeroed exponent, full significant
17-
#[allow(dead_code)] // unused on x86
1814
const LARGEST_SUBNORMAL_BITS: u32 = 0x007f_ffff;
1915

2016
/// Exponent = 0b1, zeroed significand
21-
#[allow(dead_code)] // unused on x86
2217
const SMALLEST_NORMAL_BITS: u32 = 0x0080_0000;
2318

2419
/// First pattern over the mantissa
25-
#[allow(dead_code)] // unused on x86
2620
const NAN_MASK1: u32 = 0x002a_aaaa;
2721

2822
/// Second pattern over the mantissa
29-
#[allow(dead_code)] // unused on x86
3023
const NAN_MASK2: u32 = 0x0055_5555;
3124

3225
#[allow(unused_macros)]
@@ -353,9 +346,6 @@ fn test_is_sign_negative() {
353346
assert!((-f32::NAN).is_sign_negative());
354347
}
355348

356-
// Ignore test on x87 floating point, these platforms do not guarantee NaN
357-
// payloads are preserved and flush denormals to zero, failing the tests.
358-
#[cfg(not(target_arch = "x86"))]
359349
#[test]
360350
fn test_next_up() {
361351
let tiny = f32::from_bits(TINY_BITS);
@@ -386,9 +376,6 @@ fn test_next_up() {
386376
assert_f32_biteq!(nan2.next_up(), nan2);
387377
}
388378

389-
// Ignore test on x87 floating point, these platforms do not guarantee NaN
390-
// payloads are preserved and flush denormals to zero, failing the tests.
391-
#[cfg(not(target_arch = "x86"))]
392379
#[test]
393380
fn test_next_down() {
394381
let tiny = f32::from_bits(TINY_BITS);

library/std/src/f64/tests.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@ use crate::f64::consts;
22
use crate::num::{FpCategory as Fp, *};
33

44
/// Smallest number
5-
#[allow(dead_code)] // unused on x86
65
const TINY_BITS: u64 = 0x1;
76

87
/// Next smallest number
9-
#[allow(dead_code)] // unused on x86
108
const TINY_UP_BITS: u64 = 0x2;
119

1210
/// Exponent = 0b11...10, Sifnificand 0b1111..10. Min val > 0
13-
#[allow(dead_code)] // unused on x86
1411
const MAX_DOWN_BITS: u64 = 0x7fef_ffff_ffff_fffe;
1512

1613
/// Zeroed exponent, full significant
17-
#[allow(dead_code)] // unused on x86
1814
const LARGEST_SUBNORMAL_BITS: u64 = 0x000f_ffff_ffff_ffff;
1915

2016
/// Exponent = 0b1, zeroed significand
21-
#[allow(dead_code)] // unused on x86
2217
const SMALLEST_NORMAL_BITS: u64 = 0x0010_0000_0000_0000;
2318

2419
/// First pattern over the mantissa
25-
#[allow(dead_code)] // unused on x86
2620
const NAN_MASK1: u64 = 0x000a_aaaa_aaaa_aaaa;
2721

2822
/// Second pattern over the mantissa
29-
#[allow(dead_code)] // unused on x86
3023
const NAN_MASK2: u64 = 0x0005_5555_5555_5555;
3124

3225
#[allow(unused_macros)]
@@ -343,9 +336,6 @@ fn test_is_sign_negative() {
343336
assert!((-f64::NAN).is_sign_negative());
344337
}
345338

346-
// Ignore test on x87 floating point, these platforms do not guarantee NaN
347-
// payloads are preserved and flush denormals to zero, failing the tests.
348-
#[cfg(not(target_arch = "x86"))]
349339
#[test]
350340
fn test_next_up() {
351341
let tiny = f64::from_bits(TINY_BITS);
@@ -375,9 +365,6 @@ fn test_next_up() {
375365
assert_f64_biteq!(nan2.next_up(), nan2);
376366
}
377367

378-
// Ignore test on x87 floating point, these platforms do not guarantee NaN
379-
// payloads are preserved and flush denormals to zero, failing the tests.
380-
#[cfg(not(target_arch = "x86"))]
381368
#[test]
382369
fn test_next_down() {
383370
let tiny = f64::from_bits(TINY_BITS);

tests/ui/consts/const-float-bits-conv.rs

-161
This file was deleted.

tests/ui/consts/const-float-classify.rs

-76
This file was deleted.

tests/ui/consts/const-float-classify.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)