From 853171782706c3b9342045ff06e9ff0ccf5faa9e Mon Sep 17 00:00:00 2001 From: Christian Vallentin Date: Sun, 7 Jul 2024 06:05:58 +0200 Subject: [PATCH] Added bvec constructors (#528) --- codegen/templates/vec_mask.rs.tera | 13 ++++++++- src/bool.rs | 42 ++++++++++++++++-------------- src/bool/bvec2.rs | 7 +++++ src/bool/bvec3.rs | 7 +++++ src/bool/bvec4.rs | 7 +++++ src/bool/coresimd/bvec3a.rs | 7 +++++ src/bool/coresimd/bvec4a.rs | 7 +++++ src/bool/neon/bvec3a.rs | 7 +++++ src/bool/neon/bvec4a.rs | 7 +++++ src/bool/scalar/bvec3a.rs | 7 +++++ src/bool/scalar/bvec4a.rs | 7 +++++ src/bool/sse2/bvec3a.rs | 7 +++++ src/bool/sse2/bvec4a.rs | 7 +++++ src/bool/wasm32/bvec3a.rs | 7 +++++ src/bool/wasm32/bvec4a.rs | 7 +++++ 15 files changed, 125 insertions(+), 21 deletions(-) diff --git a/codegen/templates/vec_mask.rs.tera b/codegen/templates/vec_mask.rs.tera index 41e0e16f..53f7135e 100644 --- a/codegen/templates/vec_mask.rs.tera +++ b/codegen/templates/vec_mask.rs.tera @@ -51,7 +51,18 @@ union UnionCast { } {% endif %} -{%- if is_scalar and is_bool %} +/// Creates a {{ dim }}-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn {{ self_t | lower }}( + {% for c in components %} + {{ c }}: bool, + {% endfor %} +) -> {{ self_t }} { + {{ self_t }}::new({{ components | join(sep=",") }}) +} + +{% if is_scalar and is_bool %} /// A {{ dim }}-dimensional `bool` vector mask. {%- elif is_scalar and is_u32 %} /// A {{ dim }}-dimensional `u32` vector mask. diff --git a/src/bool.rs b/src/bool.rs index 091cf0c7..c920e0b5 100644 --- a/src/bool.rs +++ b/src/bool.rs @@ -34,47 +34,47 @@ mod wasm32; ))] mod scalar; -pub use bvec2::BVec2; -pub use bvec3::BVec3; -pub use bvec4::BVec4; +pub use bvec2::{bvec2, BVec2}; +pub use bvec3::{bvec3, BVec3}; +pub use bvec4::{bvec4, BVec4}; #[cfg(all( target_arch = "aarch64", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use neon::bvec3a::BVec3A; +pub use neon::bvec3a::{bvec3a, BVec3A}; #[cfg(all( target_arch = "aarch64", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use neon::bvec4a::BVec4A; +pub use neon::bvec4a::{bvec4a, BVec4A}; #[cfg(all( target_feature = "sse2", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use sse2::bvec3a::BVec3A; +pub use sse2::bvec3a::{bvec3a, BVec3A}; #[cfg(all( target_feature = "sse2", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use sse2::bvec4a::BVec4A; +pub use sse2::bvec4a::{bvec4a, BVec4A}; #[cfg(all( target_feature = "simd128", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use wasm32::bvec3a::BVec3A; +pub use wasm32::bvec3a::{bvec3a, BVec3A}; #[cfg(all( target_feature = "simd128", not(any(feature = "core-simd", feature = "scalar-math")) ))] -pub use wasm32::bvec4a::BVec4A; +pub use wasm32::bvec4a::{bvec4a, BVec4A}; #[cfg(all(feature = "core-simd", not(feature = "scalar-math")))] -pub use coresimd::bvec3a::BVec3A; +pub use coresimd::bvec3a::{bvec3a, BVec3A}; #[cfg(all(feature = "core-simd", not(feature = "scalar-math")))] -pub use coresimd::bvec4a::BVec4A; +pub use coresimd::bvec4a::{bvec4a, BVec4A}; #[cfg(any( not(any( @@ -85,16 +85,18 @@ pub use coresimd::bvec4a::BVec4A; )), feature = "scalar-math" ))] -pub use scalar::bvec3a::BVec3A; +pub use scalar::bvec3a::{bvec3a, BVec3A}; -#[cfg(not(any( - feature = "scalar-math", - feature = "core-simd", - target_arch = "aarch64", - target_feature = "sse2", - target_feature = "simd128" -),))] -pub use scalar::bvec4a::BVec4A; +#[cfg(any( + not(any( + feature = "core-simd", + target_arch = "aarch64", + target_feature = "sse2", + target_feature = "simd128" + )), + feature = "scalar-math" +))] +pub use scalar::bvec4a::{bvec4a, BVec4A}; mod const_test_bvec2 { const_assert_eq!(1, core::mem::align_of::()); diff --git a/src/bool/bvec2.rs b/src/bool/bvec2.rs index 3fc13b19..5ac62cb8 100644 --- a/src/bool/bvec2.rs +++ b/src/bool/bvec2.rs @@ -4,6 +4,13 @@ use core::fmt; use core::ops::*; +/// Creates a 2-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec2(x: bool, y: bool) -> BVec2 { + BVec2::new(x, y) +} + /// A 2-dimensional `bool` vector mask. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C, align(1))] diff --git a/src/bool/bvec3.rs b/src/bool/bvec3.rs index 2f33cd19..94fd2b91 100644 --- a/src/bool/bvec3.rs +++ b/src/bool/bvec3.rs @@ -4,6 +4,13 @@ use core::fmt; use core::ops::*; +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3(x: bool, y: bool, z: bool) -> BVec3 { + BVec3::new(x, y, z) +} + /// A 3-dimensional `bool` vector mask. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C, align(1))] diff --git a/src/bool/bvec4.rs b/src/bool/bvec4.rs index 2300a4a9..c1f49313 100644 --- a/src/bool/bvec4.rs +++ b/src/bool/bvec4.rs @@ -4,6 +4,13 @@ use core::fmt; use core::ops::*; +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4(x: bool, y: bool, z: bool, w: bool) -> BVec4 { + BVec4::new(x, y, z, w) +} + /// A 4-dimensional `bool` vector mask. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C, align(1))] diff --git a/src/bool/coresimd/bvec3a.rs b/src/bool/coresimd/bvec3a.rs index 080f3bde..4615fb48 100644 --- a/src/bool/coresimd/bvec3a.rs +++ b/src/bool/coresimd/bvec3a.rs @@ -12,6 +12,13 @@ union UnionCast { v: BVec3A, } +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3a(x: bool, y: bool, z: bool) -> BVec3A { + BVec3A::new(x, y, z) +} + /// A 3-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/coresimd/bvec4a.rs b/src/bool/coresimd/bvec4a.rs index a1213b01..dc65730f 100644 --- a/src/bool/coresimd/bvec4a.rs +++ b/src/bool/coresimd/bvec4a.rs @@ -12,6 +12,13 @@ union UnionCast { v: BVec4A, } +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A { + BVec4A::new(x, y, z, w) +} + /// A 4-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/neon/bvec3a.rs b/src/bool/neon/bvec3a.rs index 3e26c2cd..7672a187 100644 --- a/src/bool/neon/bvec3a.rs +++ b/src/bool/neon/bvec3a.rs @@ -12,6 +12,13 @@ union UnionCast { v: BVec3A, } +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3a(x: bool, y: bool, z: bool) -> BVec3A { + BVec3A::new(x, y, z) +} + /// A 3-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/neon/bvec4a.rs b/src/bool/neon/bvec4a.rs index 27a188fa..c8a1700e 100644 --- a/src/bool/neon/bvec4a.rs +++ b/src/bool/neon/bvec4a.rs @@ -12,6 +12,13 @@ union UnionCast { v: BVec4A, } +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A { + BVec4A::new(x, y, z, w) +} + /// A 4-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/scalar/bvec3a.rs b/src/bool/scalar/bvec3a.rs index 28c9f45b..bd687af6 100644 --- a/src/bool/scalar/bvec3a.rs +++ b/src/bool/scalar/bvec3a.rs @@ -4,6 +4,13 @@ use core::fmt; use core::ops::*; +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3a(x: bool, y: bool, z: bool) -> BVec3A { + BVec3A::new(x, y, z) +} + /// A 3-dimensional `u32` vector mask. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C, align(16))] diff --git a/src/bool/scalar/bvec4a.rs b/src/bool/scalar/bvec4a.rs index eaf6572f..82b46401 100644 --- a/src/bool/scalar/bvec4a.rs +++ b/src/bool/scalar/bvec4a.rs @@ -4,6 +4,13 @@ use core::fmt; use core::ops::*; +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A { + BVec4A::new(x, y, z, w) +} + /// A 4-dimensional `u32` vector mask. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(C, align(16))] diff --git a/src/bool/sse2/bvec3a.rs b/src/bool/sse2/bvec3a.rs index 89b36c3f..5c1943d3 100644 --- a/src/bool/sse2/bvec3a.rs +++ b/src/bool/sse2/bvec3a.rs @@ -15,6 +15,13 @@ union UnionCast { v: BVec3A, } +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3a(x: bool, y: bool, z: bool) -> BVec3A { + BVec3A::new(x, y, z) +} + /// A 3-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/sse2/bvec4a.rs b/src/bool/sse2/bvec4a.rs index 344892d1..9ea076d9 100644 --- a/src/bool/sse2/bvec4a.rs +++ b/src/bool/sse2/bvec4a.rs @@ -15,6 +15,13 @@ union UnionCast { v: BVec4A, } +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A { + BVec4A::new(x, y, z, w) +} + /// A 4-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/wasm32/bvec3a.rs b/src/bool/wasm32/bvec3a.rs index 19302906..5e889a23 100644 --- a/src/bool/wasm32/bvec3a.rs +++ b/src/bool/wasm32/bvec3a.rs @@ -6,6 +6,13 @@ use core::ops::*; use core::arch::wasm32::*; +/// Creates a 3-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec3a(x: bool, y: bool, z: bool) -> BVec3A { + BVec3A::new(x, y, z) +} + /// A 3-dimensional SIMD vector mask. /// /// This type is 16 byte aligned. diff --git a/src/bool/wasm32/bvec4a.rs b/src/bool/wasm32/bvec4a.rs index 4bb5afa0..65438a12 100644 --- a/src/bool/wasm32/bvec4a.rs +++ b/src/bool/wasm32/bvec4a.rs @@ -6,6 +6,13 @@ use core::ops::*; use core::arch::wasm32::*; +/// Creates a 4-dimensional `bool` vector mask. +#[inline(always)] +#[must_use] +pub const fn bvec4a(x: bool, y: bool, z: bool, w: bool) -> BVec4A { + BVec4A::new(x, y, z, w) +} + /// A 4-dimensional SIMD vector mask. /// /// This type is 16 byte aligned.