Skip to content

Commit 1562d7b

Browse files
committed
Fix simd renames (Fixes #584)
1 parent 3d0b936 commit 1562d7b

2 files changed

Lines changed: 58 additions & 7 deletions

File tree

simd/src/arm/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
// pattern: Functional Core
1011

1112
use std::arch::aarch64::{self, float32x2_t, float32x4_t, int32x2_t, int32x4_t};
1213
use std::arch::aarch64::{uint32x2_t, uint32x4_t};
@@ -79,12 +80,12 @@ impl F32x2 {
7980

8081
#[inline]
8182
pub fn min(self, other: F32x2) -> F32x2 {
82-
unsafe { F32x2(simd_fmin(self.0, other.0)) }
83+
unsafe { F32x2(simd_minimum_number_nsz(self.0, other.0)) }
8384
}
8485

8586
#[inline]
8687
pub fn max(self, other: F32x2) -> F32x2 {
87-
unsafe { F32x2(simd_fmax(self.0, other.0)) }
88+
unsafe { F32x2(simd_maximum_number_nsz(self.0, other.0)) }
8889
}
8990

9091
#[inline]
@@ -268,12 +269,12 @@ impl F32x4 {
268269

269270
#[inline]
270271
pub fn min(self, other: F32x4) -> F32x4 {
271-
unsafe { F32x4(simd_fmin(self.0, other.0)) }
272+
unsafe { F32x4(simd_minimum_number_nsz(self.0, other.0)) }
272273
}
273274

274275
#[inline]
275276
pub fn max(self, other: F32x4) -> F32x4 {
276-
unsafe { F32x4(simd_fmax(self.0, other.0)) }
277+
unsafe { F32x4(simd_maximum_number_nsz(self.0, other.0)) }
277278
}
278279

279280
#[inline]
@@ -604,12 +605,12 @@ impl I32x4 {
604605

605606
#[inline]
606607
pub fn max(self, other: I32x4) -> I32x4 {
607-
unsafe { I32x4(simd_cast(simd_fmax(self.to_f32x4().0, other.to_f32x4().0))) }
608+
unsafe { I32x4(simd_select(self.packed_lt(other).0, other.0, self.0)) }
608609
}
609610

610611
#[inline]
611612
pub fn min(self, other: I32x4) -> I32x4 {
612-
unsafe { I32x4(simd_cast(simd_fmin(self.to_f32x4().0, other.to_f32x4().0))) }
613+
unsafe { I32x4(simd_select(self.packed_lt(other).0, self.0, other.0)) }
613614
}
614615

615616
// Packed comparisons

simd/src/test.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
// pattern: Functional Core
1011

1112
use crate::default::{F32x4, I32x4, U32x4};
13+
#[cfg(all(pf_rustc_nightly, target_arch = "aarch64"))]
14+
use crate::arm::{F32x2 as ArmF32x2, F32x4 as ArmF32x4};
1215
use crate::scalar::F32x4 as F32x4S;
1316

1417
// F32x4
@@ -37,7 +40,14 @@ fn test_f32x4_accessors_and_mutators() {
3740
fn test_f32x4_basic_ops() {
3841
let a = F32x4::new(1.0, 3.0, 5.0, 7.0);
3942
let b = F32x4::new(2.0, 2.0, 6.0, 6.0);
40-
assert_eq!(a.approx_recip(), F32x4::new(0.99975586, 0.333313, 0.19995117, 0.14282227));
43+
let approx_recip = a.approx_recip();
44+
for (lane, expected) in IntoIterator::into_iter([1.0, 1.0 / 3.0, 1.0 / 5.0, 1.0 / 7.0]).enumerate() {
45+
assert!(
46+
(approx_recip[lane] - expected).abs() <= 0.002,
47+
"lane {lane} reciprocal estimate {got} exceeded tolerance for {expected}",
48+
got = approx_recip[lane],
49+
);
50+
}
4151
assert_eq!(a.min(b), F32x4::new(1.0, 2.0, 5.0, 6.0));
4252
assert_eq!(a.max(b), F32x4::new(2.0, 3.0, 6.0, 7.0));
4353
let c = F32x4::new(-1.0, 1.3, -20.0, 3.6);
@@ -393,6 +403,46 @@ fn test_i32x4_basic_ops() {
393403
let a = I32x4::new(6, 29, -40, 2);
394404
let b = I32x4::new(10, -5, 10, 46);
395405
assert_eq!(a.min(b), I32x4::new(6, -5, -40, 2));
406+
assert_eq!(a.max(b), I32x4::new(10, 29, 10, 46));
407+
}
408+
409+
#[test]
410+
fn test_i32x4_min_max_large_values() {
411+
let a = I32x4::new(16_777_217, -16_777_219, 2_000_000_001, -2_000_000_001);
412+
let b = I32x4::new(16_777_218, -16_777_218, 2_000_000_000, -1_999_999_999);
413+
assert_eq!(a.min(b), I32x4::new(16_777_217, -16_777_219, 2_000_000_000, -2_000_000_001));
414+
assert_eq!(a.max(b), I32x4::new(16_777_218, -16_777_218, 2_000_000_001, -1_999_999_999));
415+
}
416+
417+
#[cfg(all(pf_rustc_nightly, target_arch = "aarch64"))]
418+
#[test]
419+
fn test_arm_float_min_max_nan_behavior() {
420+
let a2 = ArmF32x2::new(std::f32::NAN, 3.0);
421+
let b2 = ArmF32x2::new(2.0, std::f32::NAN);
422+
let min2 = a2.min(b2);
423+
let max2 = a2.max(b2);
424+
assert_eq!(min2[0], 2.0);
425+
assert_eq!(min2[1], 3.0);
426+
assert_eq!(max2[0], 2.0);
427+
assert_eq!(max2[1], 3.0);
428+
429+
let c2 = ArmF32x2::new(std::f32::NAN, std::f32::NAN);
430+
let both_nan2 = c2.min(c2);
431+
assert!(both_nan2[0].is_nan());
432+
assert!(both_nan2[1].is_nan());
433+
434+
let a4 = ArmF32x4::new(std::f32::NAN, 3.0, 5.0, std::f32::NAN);
435+
let b4 = ArmF32x4::new(2.0, std::f32::NAN, 6.0, std::f32::NAN);
436+
let min4 = a4.min(b4);
437+
let max4 = a4.max(b4);
438+
assert_eq!(min4[0], 2.0);
439+
assert_eq!(min4[1], 3.0);
440+
assert_eq!(min4[2], 5.0);
441+
assert!(min4[3].is_nan());
442+
assert_eq!(max4[0], 2.0);
443+
assert_eq!(max4[1], 3.0);
444+
assert_eq!(max4[2], 6.0);
445+
assert!(max4[3].is_nan());
396446
}
397447

398448
#[test]

0 commit comments

Comments
 (0)