Skip to content

Commit 22576bb

Browse files
committed
Implement additional functions
1 parent 27e9442 commit 22576bb

15 files changed

+40
-40
lines changed

crates/core_simd/src/macros.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,27 @@ macro_rules! call_counting_args {
139139
macro_rules! impl_vector {
140140
{ $name:ident, $type:ty } => {
141141
impl<const LANES: usize> $name<LANES> {
142-
/// Construct a vector by setting all lanes to the given value.
142+
/// Construct a SIMD vector by setting all lanes to the given value.
143143
pub const fn splat(value: $type) -> Self {
144144
Self([value; LANES])
145145
}
146146

147+
/// Returns a slice containing the entire SIMD vector.
147148
pub const fn as_slice(&self) -> &[$type] {
148149
&self.0
149150
}
150151

152+
/// Returns a mutable slice containing the entire SIMD vector.
151153
pub fn as_mut_slice(&mut self) -> &mut [$type] {
152154
&mut self.0
153155
}
154156

155-
pub const fn as_ptr(&self) -> *const $type {
156-
self.0.as_ptr()
157-
}
158-
159-
pub fn as_mut_ptr(&mut self) -> *mut $type {
160-
self.0.as_mut_ptr()
161-
}
162-
157+
/// Converts an array to a SIMD vector.
163158
pub const fn from_array(array: [$type; LANES]) -> Self {
164159
Self(array)
165160
}
166161

162+
/// Converts a SIMD vector to an array.
167163
pub const fn to_array(self) -> [$type; LANES] {
168164
self.0
169165
}
@@ -250,7 +246,7 @@ macro_rules! impl_vector {
250246

251247
/// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`.
252248
macro_rules! impl_integer_vector {
253-
{ $name:path, $type:ty } => {
249+
{ $name:ident, $type:ty } => {
254250
impl_vector! { $name, $type }
255251

256252
impl<const LANES: usize> Eq for $name<LANES> {}
@@ -279,22 +275,26 @@ macro_rules! impl_integer_vector {
279275
/// `$lanes` of float `$type`, which uses `$bits_ty` as its binary
280276
/// representation. Called from `define_float_vector!`.
281277
macro_rules! impl_float_vector {
282-
{ $name:path => [$type:ty; $lanes:literal]; bits $bits_ty:ty; } => {
283-
impl $name {
284-
// /// Raw transmutation to an unsigned integer vector type with the
285-
// /// same size and number of lanes.
286-
// #[inline]
287-
// pub fn to_bits(self) -> $bits_ty {
288-
// unsafe { core::mem::transmute(self) }
289-
// }
290-
//
291-
// /// Raw transmutation from an unsigned integer vector type with the
292-
// /// same size and number of lanes.
293-
// #[inline]
294-
// pub fn from_bits(bits: $bits_ty) -> Self {
295-
// unsafe { core::mem::transmute(bits) }
296-
// }
297-
//
278+
{ $name:ident, $type:ty, $bits_ty:ident } => {
279+
impl_vector! { $name, $type }
280+
281+
impl<const LANES: usize> $name<LANES> {
282+
/// Raw transmutation to an unsigned integer vector type with the
283+
/// same size and number of lanes.
284+
#[inline]
285+
pub fn to_bits(self) -> crate::$bits_ty<LANES> {
286+
assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<crate::$bits_ty<LANES>>());
287+
unsafe { core::mem::transmute_copy(&self) }
288+
}
289+
290+
/// Raw transmutation from an unsigned integer vector type with the
291+
/// same size and number of lanes.
292+
#[inline]
293+
pub fn from_bits(bits: crate::$bits_ty<LANES>) -> Self {
294+
assert_eq!(core::mem::size_of::<Self>(), core::mem::size_of::<crate::$bits_ty<LANES>>());
295+
unsafe { core::mem::transmute_copy(&bits) }
296+
}
297+
298298
// /// Produces a vector where every lane has the absolute value of the
299299
// /// equivalently-indexed lane in `self`.
300300
// #[inline]

crates/core_simd/src/vectors_f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdF32<const LANES: usize>([f32; LANES]);
66

7-
impl_vector! { SimdF32, f32 }
7+
impl_float_vector! { SimdF32, f32, SimdU32 }
88

99
pub type f32x2 = SimdF32<2>;
1010
pub type f32x4 = SimdF32<4>;

crates/core_simd/src/vectors_f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdF64<const LANES: usize>([f64; LANES]);
66

7-
impl_vector! { SimdF64, f64 }
7+
impl_float_vector! { SimdF64, f64, SimdU64 }
88

99
pub type f64x2 = SimdF64<2>;
1010
pub type f64x4 = SimdF64<4>;

crates/core_simd/src/vectors_i128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdI128<const LANES: usize>([i128; LANES]);
66

7-
impl_vector! { SimdI128, i128 }
7+
impl_integer_vector! { SimdI128, i128 }
88

99
pub type i128x2 = SimdI128<2>;
1010
pub type i128x4 = SimdI128<4>;

crates/core_simd/src/vectors_i16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdI16<const LANES: usize>([i16; LANES]);
66

7-
impl_vector! { SimdI16, i16 }
7+
impl_integer_vector! { SimdI16, i16 }
88

99
pub type i16x4 = SimdI16<4>;
1010
pub type i16x8 = SimdI16<8>;

crates/core_simd/src/vectors_i32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdI32<const LANES: usize>([i32; LANES]);
66

7-
impl_vector! { SimdI32, i32 }
7+
impl_integer_vector! { SimdI32, i32 }
88

99
pub type i32x2 = SimdI32<2>;
1010
pub type i32x4 = SimdI32<4>;

crates/core_simd/src/vectors_i64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdI64<const LANES: usize>([i64; LANES]);
66

7-
impl_vector! { SimdI64, i64 }
7+
impl_integer_vector! { SimdI64, i64 }
88

99
pub type i64x2 = SimdI64<2>;
1010
pub type i64x4 = SimdI64<4>;

crates/core_simd/src/vectors_i8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdI8<const LANES: usize>([i8; LANES]);
66

7-
impl_vector! { SimdI8, i8 }
7+
impl_integer_vector! { SimdI8, i8 }
88

99
pub type i8x8 = SimdI8<8>;
1010
pub type i8x16 = SimdI8<16>;

crates/core_simd/src/vectors_isize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdIsize<const LANES: usize>([isize; LANES]);
66

7-
impl_vector! { SimdIsize, isize }
7+
impl_integer_vector! { SimdIsize, isize }
88

99
pub type isizex2 = SimdIsize<2>;
1010
pub type isizex4 = SimdIsize<4>;

crates/core_simd/src/vectors_u128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdU128<const LANES: usize>([u128; LANES]);
66

7-
impl_vector! { SimdU128, u128 }
7+
impl_integer_vector! { SimdU128, u128 }
88

99
pub type u128x2 = SimdU128<2>;
1010
pub type u128x4 = SimdU128<4>;

crates/core_simd/src/vectors_u16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdU16<const LANES: usize>([u16; LANES]);
66

7-
impl_vector! { SimdU16, u16 }
7+
impl_integer_vector! { SimdU16, u16 }
88

99
pub type u16x4 = SimdU16<4>;
1010
pub type u16x8 = SimdU16<8>;

crates/core_simd/src/vectors_u32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdU32<const LANES: usize>([u32; LANES]);
66

7-
impl_vector! { SimdU32, u32 }
7+
impl_integer_vector! { SimdU32, u32 }
88

99
pub type u32x2 = SimdU32<2>;
1010
pub type u32x4 = SimdU32<4>;

crates/core_simd/src/vectors_u64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdU64<const LANES: usize>([u64; LANES]);
66

7-
impl_vector! { SimdU64, u64 }
7+
impl_integer_vector! { SimdU64, u64 }
88

99
pub type u64x2 = SimdU64<2>;
1010
pub type u64x4 = SimdU64<4>;

crates/core_simd/src/vectors_u8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdU8<const LANES: usize>([u8; LANES]);
66

7-
impl_vector! { SimdU8, u8 }
7+
impl_integer_vector! { SimdU8, u8 }
88

99
pub type u8x8 = SimdU8<8>;
1010
pub type u8x16 = SimdU8<16>;

crates/core_simd/src/vectors_usize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[repr(simd)]
55
pub struct SimdUsize<const LANES: usize>([usize; LANES]);
66

7-
impl_vector! { SimdUsize, usize }
7+
impl_integer_vector! { SimdUsize, usize }
88

99
pub type usizex2 = SimdUsize<2>;
1010
pub type usizex4 = SimdUsize<4>;

0 commit comments

Comments
 (0)