Skip to content

Commit f93bef3

Browse files
committed
Move vector implementation
1 parent 529ffe0 commit f93bef3

File tree

3 files changed

+33
-100
lines changed

3 files changed

+33
-100
lines changed

crates/core_simd/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#![unstable(feature = "portable_simd", issue = "86656")]
1313
//! Portable SIMD module.
1414
15-
#[macro_use]
16-
mod first;
1715
#[macro_use]
1816
mod permute;
1917
#[macro_use]

crates/core_simd/src/vector.rs

Lines changed: 3 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[macro_use]
2+
mod vector_impl;
3+
14
mod float;
25
mod int;
36
mod uint;
@@ -31,101 +34,3 @@ pub trait Vector: sealed::Sealed {
3134
#[must_use]
3235
fn splat(val: Self::Scalar) -> Self;
3336
}
34-
35-
macro_rules! impl_vector_for {
36-
($simd:ident {type Scalar = $scalar:ident;}) => {
37-
impl_vector_for! { $simd<1> { type Scalar = $scalar; type BitMask = u8; } }
38-
impl_vector_for! { $simd<2> { type Scalar = $scalar; type BitMask = u8; } }
39-
impl_vector_for! { $simd<4> { type Scalar = $scalar; type BitMask = u8; } }
40-
impl_vector_for! { $simd<8> { type Scalar = $scalar; type BitMask = u8; } }
41-
impl_vector_for! { $simd<16> { type Scalar = $scalar; type BitMask = u16; } }
42-
impl_vector_for! { $simd<32> { type Scalar = $scalar; type BitMask = u32; } }
43-
};
44-
($simd:ident<$lanes:literal> {type Scalar = $scalar:ident; type BitMask = $bitmask:ident; }) => {
45-
impl sealed::Sealed for $simd<$lanes> {}
46-
47-
impl Vector for $simd<$lanes> {
48-
type Scalar = $scalar;
49-
const LANES: usize = $lanes;
50-
51-
type BitMask = $bitmask;
52-
53-
#[inline]
54-
fn splat(val: Self::Scalar) -> Self {
55-
Self::splat(val)
56-
}
57-
}
58-
};
59-
}
60-
61-
impl_vector_for! {
62-
SimdUsize {
63-
type Scalar = usize;
64-
}
65-
}
66-
67-
impl_vector_for! {
68-
SimdIsize {
69-
type Scalar = isize;
70-
}
71-
}
72-
73-
impl_vector_for! {
74-
SimdI8 {
75-
type Scalar = i8;
76-
}
77-
}
78-
79-
impl_vector_for! {
80-
SimdI16 {
81-
type Scalar = i16;
82-
}
83-
}
84-
85-
impl_vector_for! {
86-
SimdI32 {
87-
type Scalar = i32;
88-
}
89-
}
90-
91-
impl_vector_for! {
92-
SimdI64 {
93-
type Scalar = i64;
94-
}
95-
}
96-
97-
impl_vector_for! {
98-
SimdU8 {
99-
type Scalar = u8;
100-
}
101-
}
102-
103-
impl_vector_for! {
104-
SimdU16 {
105-
type Scalar = u16;
106-
}
107-
}
108-
109-
impl_vector_for! {
110-
SimdU32 {
111-
type Scalar = u32;
112-
}
113-
}
114-
115-
impl_vector_for! {
116-
SimdU64 {
117-
type Scalar = u64;
118-
}
119-
}
120-
121-
impl_vector_for! {
122-
SimdF32 {
123-
type Scalar = f32;
124-
}
125-
}
126-
127-
impl_vector_for! {
128-
SimdF64 {
129-
type Scalar = f64;
130-
}
131-
}

crates/core_simd/src/first.rs renamed to crates/core_simd/src/vector/vector_impl.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
macro_rules! impl_vector_trait {
2+
($simd:ident {type Scalar = $scalar:ty;}) => {
3+
impl_vector_trait! { $simd<1> { type Scalar = $scalar; type BitMask = u8; } }
4+
impl_vector_trait! { $simd<2> { type Scalar = $scalar; type BitMask = u8; } }
5+
impl_vector_trait! { $simd<4> { type Scalar = $scalar; type BitMask = u8; } }
6+
impl_vector_trait! { $simd<8> { type Scalar = $scalar; type BitMask = u8; } }
7+
impl_vector_trait! { $simd<16> { type Scalar = $scalar; type BitMask = u16; } }
8+
impl_vector_trait! { $simd<32> { type Scalar = $scalar; type BitMask = u32; } }
9+
};
10+
($simd:ident<$lanes:literal> {type Scalar = $scalar:ty; type BitMask = $bitmask:ident; }) => {
11+
impl crate::vector::sealed::Sealed for $simd<$lanes> {}
12+
13+
impl crate::vector::Vector for $simd<$lanes> {
14+
type Scalar = $scalar;
15+
const LANES: usize = $lanes;
16+
17+
type BitMask = $bitmask;
18+
19+
#[inline]
20+
fn splat(val: Self::Scalar) -> Self {
21+
Self::splat(val)
22+
}
23+
}
24+
};
25+
}
26+
127
/// Implements common traits on the specified vector `$name`, holding multiple `$lanes` of `$type`.
228
macro_rules! impl_vector {
329
{ $name:ident, $type:ty } => {
30+
impl_vector_trait! {
31+
$name { type Scalar = $type; }
32+
}
33+
434
impl<const LANES: usize> $name<LANES> where Self: crate::Vector {
535
/// Construct a SIMD vector by setting all lanes to the given value.
636
pub const fn splat(value: $type) -> Self {

0 commit comments

Comments
 (0)