From 0da3a665af799cc0afe662f636bc096593816f82 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sun, 22 Feb 2026 12:58:49 +0000 Subject: [PATCH 1/4] Update exhaustive tests to roundtrip precise conversions on all values; out-of-range values are intentionally implementation-defined in the non-precise variants --- fearless_simd_tests/tests/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fearless_simd_tests/tests/mod.rs b/fearless_simd_tests/tests/mod.rs index c6575e800..9f81ef42f 100644 --- a/fearless_simd_tests/tests/mod.rs +++ b/fearless_simd_tests/tests/mod.rs @@ -74,11 +74,11 @@ fn test_f32_to_i32_exhaustive(simd: S) { || { for i in (0..u32::MAX).step_by(4) { let floats = f32x4::from_fn(simd, |n| f32::from_bits(n as u32 + i)); - let ints = floats.to_int::>(); + let ints = floats.to_int_precise::>(); let ints_ref = (*floats).map(|f| f as i32); assert_eq!( *ints, ints_ref, - "f32x4::to_int::>() returns the same results as Rust's `as i32`" + "f32x4::to_int_precise::>() returns the same results as Rust's `as i32`" ); } }, @@ -98,11 +98,11 @@ fn test_f32_to_u32_exhaustive(simd: S) { || { for i in (0..u32::MAX).step_by(4) { let floats = f32x4::from_fn(simd, |n| f32::from_bits(n as u32 + i)); - let ints = floats.to_int::>(); + let ints = floats.to_int_precise::>(); let ints_ref = (*floats).map(|f| f as u32); assert_eq!( *ints, ints_ref, - "f32x4::to_int::>() returns the same results as Rust's `as u32`" + "f32x4::to_int_precise::>() returns the same results as Rust's `as u32`" ); } }, From a171c9c38e4305e41b35176f7441e994a56ab121 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sun, 22 Feb 2026 13:22:07 +0000 Subject: [PATCH 2/4] add a roundtrip test for the non-precise f32 to u32 conversion --- fearless_simd_tests/tests/mod.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fearless_simd_tests/tests/mod.rs b/fearless_simd_tests/tests/mod.rs index 9f81ef42f..2444d5dfb 100644 --- a/fearless_simd_tests/tests/mod.rs +++ b/fearless_simd_tests/tests/mod.rs @@ -87,7 +87,7 @@ fn test_f32_to_i32_exhaustive(simd: S) { #[simd_test] #[ignore] -fn test_f32_to_u32_exhaustive(simd: S) { +fn test_f32_to_u32_precise_exhaustive(simd: S) { // The vectorize call doesn't affect the outcome of the test, but does make it complete far more quickly #[expect( clippy::cast_possible_truncation, @@ -109,6 +109,35 @@ fn test_f32_to_u32_exhaustive(simd: S) { ); } +#[simd_test] +#[ignore] +fn test_f32_to_u32_exhaustive(simd: S) { + // The vectorize call doesn't affect the outcome of the test, but does make it complete far more quickly + #[expect( + clippy::cast_possible_truncation, + reason = "that's the exact behavior we're testing" + )] + simd.vectorize( + #[inline(always)] + || { + for i in (0..u32::MAX).step_by(4) { + let floats = f32x4::from_fn(simd, |n| f32::from_bits(n as u32 + i)); + // If the value is out of range of u32 because f32 cannot represent it exactly, skip the value + // The out-of-range semantics are explicitly implementation-defined in the non-precise version. + if ! (*floats).iter().all(|val| !val.is_nan() && *val > u32::MIN as f32 && *val < u32::MAX as f32) { + continue; + } + let ints = floats.to_int::>(); + let ints_ref = (*floats).map(|f| f as u32); + assert_eq!( + *ints, ints_ref, + "f32x4::to_int::>() returns the same results as Rust's `as u32` (input: {:?})", floats.as_slice() + ); + } + }, + ); +} + #[simd_test] #[ignore] fn test_i32_to_f32_exhaustive(simd: S) { From 5a3e9273c9da5e0f5ae8b02e9ce44683c252f2f8 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sun, 22 Feb 2026 13:23:59 +0000 Subject: [PATCH 3/4] Add i32 non-precise roundtrip test --- fearless_simd_tests/tests/mod.rs | 35 +++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/fearless_simd_tests/tests/mod.rs b/fearless_simd_tests/tests/mod.rs index 2444d5dfb..63f47a3e0 100644 --- a/fearless_simd_tests/tests/mod.rs +++ b/fearless_simd_tests/tests/mod.rs @@ -63,7 +63,7 @@ fn supports_highest_level() { #[simd_test] #[ignore] -fn test_f32_to_i32_exhaustive(simd: S) { +fn test_f32_to_i32_precise_exhaustive(simd: S) { // The vectorize call doesn't affect the outcome of the test, but does make it complete far more quickly #[expect( clippy::cast_possible_truncation, @@ -138,6 +138,39 @@ fn test_f32_to_u32_exhaustive(simd: S) { ); } +#[simd_test] +#[ignore] +fn test_f32_to_i32(simd: S) { + // The vectorize call doesn't affect the outcome of the test, but does make it complete far more quickly + #[expect( + clippy::cast_possible_truncation, + reason = "that's the exact behavior we're testing" + )] + simd.vectorize( + #[inline(always)] + || { + for i in (0..u32::MAX).step_by(4) { + let floats = f32x4::from_fn(simd, |n| f32::from_bits(n as u32 + i)); + // If the value is out of range of i32 because f32 cannot represent it exactly, skip the value + // The out-of-range semantics are explicitly implementation-defined in the non-precise version. + if !(*floats) + .iter() + .all(|val| !val.is_nan() && *val > i32::MIN as f32 && *val < i32::MAX as f32) + { + continue; + } + let ints = floats.to_int::>(); + let ints_ref = (*floats).map(|f| f as i32); + assert_eq!( + *ints, ints_ref, + "f32x4::to_int::>() returns the same results as Rust's `as i32` (input: {:?})", + floats.as_slice() + ); + } + }, + ); +} + #[simd_test] #[ignore] fn test_i32_to_f32_exhaustive(simd: S) { From add7d2463429c4c8895a4233d7a20493934f9104 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Sun, 22 Feb 2026 14:31:30 +0000 Subject: [PATCH 4/4] Update fearless_simd_tests/tests/mod.rs Co-authored-by: Tom Churchman --- fearless_simd_tests/tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fearless_simd_tests/tests/mod.rs b/fearless_simd_tests/tests/mod.rs index 63f47a3e0..24c76c095 100644 --- a/fearless_simd_tests/tests/mod.rs +++ b/fearless_simd_tests/tests/mod.rs @@ -140,7 +140,7 @@ fn test_f32_to_u32_exhaustive(simd: S) { #[simd_test] #[ignore] -fn test_f32_to_i32(simd: S) { +fn test_f32_to_i32_exhaustive(simd: S) { // The vectorize call doesn't affect the outcome of the test, but does make it complete far more quickly #[expect( clippy::cast_possible_truncation,