about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSean Stangl <sean.stangl@gmail.com>2022-04-11 00:05:14 -0600
committerGitHub <noreply@github.com>2022-04-10 23:05:14 -0700
commit7136841cbd22ba66dbd49331f276bdb16401ec11 (patch)
tree64b1a32fb6b52bda2f29c8e60b0d2666ca0668f6
parent1ec010db2abd34bfc6c33b5df75fa80b238f3b58 (diff)
downloadrust-7136841cbd22ba66dbd49331f276bdb16401ec11.tar.gz
rust-7136841cbd22ba66dbd49331f276bdb16401ec11.zip
rust-lang/portable-simd#274: Use SIMD equality for PartialEq on SIMD vectors
-rw-r--r--crates/core_simd/src/vector.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs
index 13e35ecfa49..d032f5459fd 100644
--- a/crates/core_simd/src/vector.rs
+++ b/crates/core_simd/src/vector.rs
@@ -429,8 +429,26 @@ where
 {
     #[inline]
     fn eq(&self, other: &Self) -> bool {
-        // TODO use SIMD equality
-        self.to_array() == other.to_array()
+        // Safety: All SIMD vectors are SimdPartialEq, and the comparison produces a valid mask.
+        let mask = unsafe {
+            let tfvec: Simd<<T as SimdElement>::Mask, LANES> = intrinsics::simd_eq(*self, *other);
+            Mask::from_int_unchecked(tfvec)
+        };
+
+        // Two vectors are equal if all lanes tested true for vertical equality.
+        mask.all()
+    }
+
+    #[inline]
+    fn ne(&self, other: &Self) -> bool {
+        // Safety: All SIMD vectors are SimdPartialEq, and the comparison produces a valid mask.
+        let mask = unsafe {
+            let tfvec: Simd<<T as SimdElement>::Mask, LANES> = intrinsics::simd_ne(*self, *other);
+            Mask::from_int_unchecked(tfvec)
+        };
+
+        // Two vectors are non-equal if any lane tested true for vertical non-equality.
+        mask.any()
     }
 }