Repository: bitshifter/glam-rs
Pull request #365 (2022-12-03 20:46:59)

Vector mask type for scalar impl of `Vec3A` should be `BVec3A`.


Patch:
diff --git a/clippy.toml b/clippy.toml
index ddbdbc1..5ff4f79 100644
--- a/clippy.toml
+++ b/clippy.toml
@@ -1,1 +1,1 @@
-msrv = "1.58"
+msrv = "1.58.1"
diff --git a/codegen/templates/vec.rs.tera b/codegen/templates/vec.rs.tera
index 7a00ba3..511ce3d 100644
--- a/codegen/templates/vec.rs.tera
+++ b/codegen/templates/vec.rs.tera
@@ -22,6 +22,7 @@
     {% if scalar_t == "f32" %}
         {% if dim == 3 and is_simd or is_align %}
             {% set self_t = "Vec3A" %}
+            {% set mask_t = "BVec3A" %}
         {% else %}
             {% set self_t = "Vec" ~ dim %}
         {% endif %}
@@ -298,7 +299,11 @@ impl {{ self_t }} {
         {% if is_scalar %}
             Self {
                 {% for c in components %}
-                    {{ c  }}: if mask.{{ c }} { if_true.{{ c }} } else { if_false.{{ c }} },
+                    {%- if is_align %}
+                        {{ c  }}: if mask.{{ c }} != 0 { if_true.{{ c }} } else { if_false.{{ c }} },
+                    {%- else %}
+                        {{ c  }}: if mask.{{ c }} { if_true.{{ c }} } else { if_false.{{ c }} },
+                    {%- endif %}
                 {%- endfor %}
             }
         {% elif is_sse2 %}
diff --git a/codegen/templates/vec_mask.rs.tera b/codegen/templates/vec_mask.rs.tera
index c89d325..8e60515 100644
--- a/codegen/templates/vec_mask.rs.tera
+++ b/codegen/templates/vec_mask.rs.tera
@@ -51,7 +51,7 @@ union UnionCast {
 /// This type is {{ align }} byte aligned and is backed by a SIMD vector. If SIMD is not available
 /// `{{ self_t }}` will be a type alias for `BVec{{ dim }}`.
 {%- endif %}
-{%- if is_scalar and is_bool %}
+{%- if is_scalar or is_bool %}
 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
 {%- else %}
 #[derive(Clone, Copy)]
diff --git a/src/bool.rs b/src/bool.rs
index 889a0ed..c3cbb9f 100644
--- a/src/bool.rs
+++ b/src/bool.rs
@@ -17,12 +17,14 @@ mod sse2;
 ))]
 mod wasm32;
 
-#[cfg(not(any(
-    feature = "scalar-math",
-    feature = "core-simd",
-    target_feature = "sse2",
-    target_feature = "simd128"
-),))]
+#[cfg(any(
+    not(any(
+        feature = "core-simd",
+        target_feature = "sse2",
+        target_feature = "simd128"
+    )),
+    feature = "scalar-math"
+))]
 mod scalar;
 
 pub use bvec2::BVec2;
@@ -56,12 +58,14 @@ pub use coresimd::bvec3a::BVec3A;
 #[cfg(all(feature = "core-simd", not(feature = "scalar-math")))]
 pub use coresimd::bvec4a::BVec4A;
 
-#[cfg(not(any(
-    feature = "scalar-math",
-    feature = "core-simd",
-    target_feature = "sse2",
-    target_feature = "simd128"
-),))]
+#[cfg(any(
+    not(any(
+        feature = "core-simd",
+        target_feature = "sse2",
+        target_feature = "simd128"
+    )),
+    feature = "scalar-math"
+))]
 pub use scalar::bvec3a::BVec3A;
 
 #[cfg(not(any(
diff --git a/src/bool/scalar/bvec3a.rs b/src/bool/scalar/bvec3a.rs
index dbae395..f35908c 100644
--- a/src/bool/scalar/bvec3a.rs
+++ b/src/bool/scalar/bvec3a.rs
@@ -5,7 +5,7 @@ use core::fmt;
 use core::ops::*;
 
 /// A 3-dimensional `u32` vector mask.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, PartialEq, Eq, Hash)]
 #[repr(C, align(16))]
 pub struct BVec3A {
     pub x: u32,
diff --git a/src/bool/scalar/bvec4a.rs b/src/bool/scalar/bvec4a.rs
index c12d127..28b0066 100644
--- a/src/bool/scalar/bvec4a.rs
+++ b/src/bool/scalar/bvec4a.rs
@@ -5,7 +5,7 @@ use core::fmt;
 use core::ops::*;
 
 /// A 4-dimensional `u32` vector mask.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, PartialEq, Eq, Hash)]
 #[repr(C, align(16))]
 pub struct BVec4A {
     pub x: u32,
diff --git a/src/f32/scalar/vec3a.rs b/src/f32/scalar/vec3a.rs
index 88a3c13..808e480 100644
--- a/src/f32/scalar/vec3a.rs
+++ b/src/f32/scalar/vec3a.rs
@@ -1,6 +1,6 @@
 // Generated from vec.rs.tera template. Edit the template, not the generated file.
 
-use crate::{BVec3, Vec2, Vec3, Vec4};
+use crate::{BVec3A, Vec2, Vec3, Vec4};
 
 #[cfg(not(target_arch = "spirv"))]
 use core::fmt;
@@ -85,11 +85,11 @@ impl Vec3A {
     /// A true element in the mask uses the corresponding element from `if_true`, and false
     /// uses the element from `if_false`.
     #[inline]
-    pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
+    pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
         Self {
-            x: if mask.x { if_true.x } else { if_false.x },
-            y: if mask.y { if_true.y } else { if_false.y },
-            z: if mask.z { if_true.z } else { if_false.z },
+            x: if mask.x != 0 { if_true.x } else { if_false.x },
+            y: if mask.y != 0 { if_true.y } else { if_false.y },
+            z: if mask.z != 0 { if_true.z } else { if_false.z },
         }
     }
 
@@ -234,8 +234,8 @@ impl Vec3A {
     /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmpeq(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
+    pub fn cmpeq(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
     }
 
     /// Returns a vector mask containing the result of a `!=` comparison for each element of
@@ -244,8 +244,8 @@ impl Vec3A {
     /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmpne(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
+    pub fn cmpne(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
     }
 
     /// Returns a vector mask containing the result of a `>=` comparison for each element of
@@ -254,8 +254,8 @@ impl Vec3A {
     /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmpge(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
+    pub fn cmpge(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
     }
 
     /// Returns a vector mask containing the result of a `>` comparison for each element of
@@ -264,8 +264,8 @@ impl Vec3A {
     /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmpgt(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
+    pub fn cmpgt(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
     }
 
     /// Returns a vector mask containing the result of a `<=` comparison for each element of
@@ -274,8 +274,8 @@ impl Vec3A {
     /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmple(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
+    pub fn cmple(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
     }
 
     /// Returns a vector mask containing the result of a `<` comparison for each element of
@@ -284,8 +284,8 @@ impl Vec3A {
     /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
     /// elements.
     #[inline]
-    pub fn cmplt(self, rhs: Self) -> BVec3 {
-        BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
+    pub fn cmplt(self, rhs: Self) -> BVec3A {
+        BVec3A::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
     }
 
     /// Returns a vector containing the absolute value of each element of `self`.
@@ -340,8 +340,8 @@ impl Vec3A {
     ///
     /// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`.
     #[inline]
-    pub fn is_nan_mask(self) -> BVec3 {
-        BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
+    pub fn is_nan_mask(self) -> BVec3A {
+        BVec3A::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
     }
 
     /// Computes the length of `self`.


Test patch:
diff --git a/tests/vec3.rs b/tests/vec3.rs
index fae8858..e144e3d 100644
--- a/tests/vec3.rs
+++ b/tests/vec3.rs
@@ -1082,12 +1082,6 @@ mod vec3 {
 }
 
 mod vec3a {
-    #[cfg(any(
-        not(any(target_feature = "sse2", target_feature = "simd128")),
-        feature = "scalar-math"
-    ))]
-    use glam::BVec3;
-    #[cfg(not(feature = "scalar-math"))]
     use glam::BVec3A;
     use glam::{vec3a, Vec3A, Vec4};
 
@@ -1095,16 +1089,8 @@ mod vec3a {
         use std::mem;
         assert_eq!(16, mem::size_of::<Vec3A>());
         assert_eq!(16, mem::align_of::<Vec3A>());
-        #[cfg(not(feature = "scalar-math"))]
-        {
-            assert_eq!(16, mem::size_of::<BVec3A>());
-            assert_eq!(16, mem::align_of::<BVec3A>());
-        }
-        #[cfg(feature = "scalar-math")]
-        {
-            assert_eq!(3, mem::size_of::<BVec3>());
-            assert_eq!(1, mem::align_of::<BVec3>());
-        }
+        assert_eq!(16, mem::size_of::<BVec3A>());
+        assert_eq!(16, mem::align_of::<BVec3A>());
     });
 
     glam_test!(test_mask_align16, {
@@ -1162,17 +1148,7 @@ mod vec3a {
         assert_eq!(v2.min_element(), 2.0);
     });
 
-    #[cfg(all(
-        any(target_feature = "sse2", target_feature = "simd128"),
-        not(feature = "scalar-math")
-    ))]
     impl_vec3_float_tests!(f32, vec3a, Vec3A, BVec3A);
-
-    #[cfg(any(
-        not(any(target_feature = "sse2", target_feature = "simd128")),
-        feature = "scalar-math"
-    ))]
-    impl_vec3_float_tests!(f32, vec3a, Vec3A, BVec3);
 }
 
 mod dvec3 {