about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-08-06 02:31:24 +0000
committerCaleb Zulawski <caleb.zulawski@gmail.com>2021-08-06 02:31:24 +0000
commit054f25f2b0212ada7caae70a4470e32f503a3eea (patch)
tree17ba7eebb21db3471a9210fdb93ad93b20dbffae
parentc36d17de4d87f5baba95b13d2b1ec70e652f0fe4 (diff)
downloadrust-054f25f2b0212ada7caae70a4470e32f503a3eea.tar.gz
rust-054f25f2b0212ada7caae70a4470e32f503a3eea.zip
Convert all vectors to a single type
-rw-r--r--crates/core_simd/src/vector.rs76
-rw-r--r--crates/core_simd/src/vector/float.rs13
-rw-r--r--crates/core_simd/src/vector/int.rs41
-rw-r--r--crates/core_simd/src/vector/uint.rs41
4 files changed, 101 insertions, 70 deletions
diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs
index 1f6df533767..ea1a732f203 100644
--- a/crates/core_simd/src/vector.rs
+++ b/crates/core_simd/src/vector.rs
@@ -12,9 +12,85 @@ pub use uint::*;
 // Vectors of pointers are not for public use at the current time.
 pub(crate) mod ptr;
 
+use crate::{LaneCount, SupportedLaneCount};
+
+/// A SIMD vector of `LANES` elements of type `Element`.
+#[repr(simd)]
+pub struct Simd<Element, const LANES: usize>([Element; LANES])
+where
+    Element: SimdElement,
+    LaneCount<LANES>: SupportedLaneCount;
+
 mod sealed {
     pub trait Sealed {}
 }
+use sealed::Sealed;
+
+/// Marker trait for types that may be used as SIMD vector elements.
+pub unsafe trait SimdElement: Sealed {
+    /// The mask element type corresponding to this element type.
+    type Mask: SimdElement;
+}
+
+impl Sealed for u8 {}
+unsafe impl SimdElement for u8 {
+    type Mask = u8;
+}
+
+impl Sealed for u16 {}
+unsafe impl SimdElement for u16 {
+    type Mask = u16;
+}
+
+impl Sealed for u32 {}
+unsafe impl SimdElement for u32 {
+    type Mask = u32;
+}
+
+impl Sealed for u64 {}
+unsafe impl SimdElement for u64 {
+    type Mask = u64;
+}
+
+impl Sealed for usize {}
+unsafe impl SimdElement for usize {
+    type Mask = usize;
+}
+
+impl Sealed for i8 {}
+unsafe impl SimdElement for i8 {
+    type Mask = i8;
+}
+
+impl Sealed for i16 {}
+unsafe impl SimdElement for i16 {
+    type Mask = i16;
+}
+
+impl Sealed for i32 {}
+unsafe impl SimdElement for i32 {
+    type Mask = i32;
+}
+
+impl Sealed for i64 {}
+unsafe impl SimdElement for i64 {
+    type Mask = i64;
+}
+
+impl Sealed for isize {}
+unsafe impl SimdElement for isize {
+    type Mask = isize;
+}
+
+impl Sealed for f32 {}
+unsafe impl SimdElement for f32 {
+    type Mask = i32;
+}
+
+impl Sealed for f64 {}
+unsafe impl SimdElement for f64 {
+    type Mask = i64;
+}
 
 /// A representation of a vector as an "array" with indices, implementing
 /// operations applicable to any vector type based solely on "having lanes",
diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs
index bdeccd037a8..231fe590ada 100644
--- a/crates/core_simd/src/vector/float.rs
+++ b/crates/core_simd/src/vector/float.rs
@@ -187,19 +187,12 @@ macro_rules! impl_float_vector {
 }
 
 /// A SIMD vector of containing `LANES` `f32` values.
-#[repr(simd)]
-pub struct SimdF32<const LANES: usize>([f32; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 }
+pub type SimdF32<const LANES: usize> = crate::Simd<f32, LANES>;
 
 /// A SIMD vector of containing `LANES` `f64` values.
-#[repr(simd)]
-pub struct SimdF64<const LANES: usize>([f64; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
+pub type SimdF64<const LANES: usize> = crate::Simd<f64, LANES>;
 
+impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 }
 impl_float_vector! { SimdF64, f64, SimdU64, Mask64, SimdI64 }
 
 /// Vector of two `f32` values
diff --git a/crates/core_simd/src/vector/int.rs b/crates/core_simd/src/vector/int.rs
index 73c737762fb..88a17daa2f4 100644
--- a/crates/core_simd/src/vector/int.rs
+++ b/crates/core_simd/src/vector/int.rs
@@ -62,44 +62,25 @@ macro_rules! impl_integer_vector {
     }
 }
 
-/// A SIMD vector of containing `LANES` `isize` values.
-#[repr(simd)]
-pub struct SimdIsize<const LANES: usize>([isize; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_integer_vector! { SimdIsize, isize, MaskSize, SimdIsize }
+/// A SIMD vector of containing `LANES` `i8` values.
+pub type SimdI8<const LANES: usize> = crate::Simd<i8, LANES>;
 
 /// A SIMD vector of containing `LANES` `i16` values.
-#[repr(simd)]
-pub struct SimdI16<const LANES: usize>([i16; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_integer_vector! { SimdI16, i16, Mask16, SimdI16 }
+pub type SimdI16<const LANES: usize> = crate::Simd<i16, LANES>;
 
 /// A SIMD vector of containing `LANES` `i32` values.
-#[repr(simd)]
-pub struct SimdI32<const LANES: usize>([i32; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_integer_vector! { SimdI32, i32, Mask32, SimdI32 }
+pub type SimdI32<const LANES: usize> = crate::Simd<i32, LANES>;
 
 /// A SIMD vector of containing `LANES` `i64` values.
-#[repr(simd)]
-pub struct SimdI64<const LANES: usize>([i64; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
+pub type SimdI64<const LANES: usize> = crate::Simd<i64, LANES>;
 
-impl_integer_vector! { SimdI64, i64, Mask64, SimdI64 }
-
-/// A SIMD vector of containing `LANES` `i8` values.
-#[repr(simd)]
-pub struct SimdI8<const LANES: usize>([i8; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
+/// A SIMD vector of containing `LANES` `isize` values.
+pub type SimdIsize<const LANES: usize> = crate::Simd<isize, LANES>;
 
+impl_integer_vector! { SimdIsize, isize, MaskSize, SimdIsize }
+impl_integer_vector! { SimdI16, i16, Mask16, SimdI16 }
+impl_integer_vector! { SimdI32, i32, Mask32, SimdI32 }
+impl_integer_vector! { SimdI64, i64, Mask64, SimdI64 }
 impl_integer_vector! { SimdI8, i8, Mask8, SimdI8 }
 
 /// Vector of two `isize` values
diff --git a/crates/core_simd/src/vector/uint.rs b/crates/core_simd/src/vector/uint.rs
index b19f694872a..5bd1a7fd67f 100644
--- a/crates/core_simd/src/vector/uint.rs
+++ b/crates/core_simd/src/vector/uint.rs
@@ -33,44 +33,25 @@ macro_rules! impl_unsigned_vector {
     }
 }
 
-/// A SIMD vector of containing `LANES` `usize` values.
-#[repr(simd)]
-pub struct SimdUsize<const LANES: usize>([usize; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_unsigned_vector! { SimdUsize, usize }
+/// A SIMD vector of containing `LANES` `u8` values.
+pub type SimdU8<const LANES: usize> = crate::Simd<u8, LANES>;
 
 /// A SIMD vector of containing `LANES` `u16` values.
-#[repr(simd)]
-pub struct SimdU16<const LANES: usize>([u16; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_unsigned_vector! { SimdU16, u16 }
+pub type SimdU16<const LANES: usize> = crate::Simd<u16, LANES>;
 
 /// A SIMD vector of containing `LANES` `u32` values.
-#[repr(simd)]
-pub struct SimdU32<const LANES: usize>([u32; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
-
-impl_unsigned_vector! { SimdU32, u32 }
+pub type SimdU32<const LANES: usize> = crate::Simd<u32, LANES>;
 
 /// A SIMD vector of containing `LANES` `u64` values.
-#[repr(simd)]
-pub struct SimdU64<const LANES: usize>([u64; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
+pub type SimdU64<const LANES: usize> = crate::Simd<u64, LANES>;
 
-impl_unsigned_vector! { SimdU64, u64 }
-
-/// A SIMD vector of containing `LANES` `u8` values.
-#[repr(simd)]
-pub struct SimdU8<const LANES: usize>([u8; LANES])
-where
-    LaneCount<LANES>: SupportedLaneCount;
+/// A SIMD vector of containing `LANES` `usize` values.
+pub type SimdUsize<const LANES: usize> = crate::Simd<usize, LANES>;
 
+impl_unsigned_vector! { SimdUsize, usize }
+impl_unsigned_vector! { SimdU16, u16 }
+impl_unsigned_vector! { SimdU32, u32 }
+impl_unsigned_vector! { SimdU64, u64 }
 impl_unsigned_vector! { SimdU8, u8 }
 
 /// Vector of two `usize` values