@@ -140,111 +140,66 @@ pub mod scalar;
140
140
pub mod sse2;
141
141
pub mod sse41;
142
142
143
+ /// Grouping all the constraints shared by associated types in
144
+ /// the Simd trait into this marker trait drastically reduces
145
+ /// compile time.
146
+ pub trait SimdBase < T , U > :
147
+ Copy
148
+ + Debug
149
+ + IndexMut < usize >
150
+ + Add < T , Output = T >
151
+ + Sub < T , Output = T >
152
+ + AddAssign < T >
153
+ + SubAssign < T >
154
+ + BitAnd < T , Output = T >
155
+ + BitOr < T , Output = T >
156
+ + BitXor < T , Output = T >
157
+ + BitAndAssign < T >
158
+ + BitOrAssign < T >
159
+ + BitXorAssign < T >
160
+ + Index < usize , Output = U > { }
161
+
162
+ pub trait SimdSmallInt < T , U > : SimdBase < T , U >
163
+ + Mul < T , Output = T >
164
+ + MulAssign < T >
165
+ + Not < Output = T >
166
+ + Shl < i32 , Output = T >
167
+ + ShlAssign < i32 >
168
+ + Shr < i32 , Output = T >
169
+ + ShrAssign < i32 > { }
170
+
171
+ pub trait SimdFloat < T , U > : SimdBase < T , U >
172
+ + Mul < T , Output = T >
173
+ + Div < T , Output = T >
174
+ + MulAssign < T >
175
+ + DivAssign < T > { }
176
+
143
177
pub trait Simd {
144
- type Vi16 : Copy
145
- + Debug
146
- + Add < Self :: Vi16 , Output = Self :: Vi16 >
147
- + Sub < Self :: Vi16 , Output = Self :: Vi16 >
148
- + Mul < Self :: Vi16 , Output = Self :: Vi16 >
149
- + AddAssign < Self :: Vi16 >
150
- + SubAssign < Self :: Vi16 >
151
- + MulAssign < Self :: Vi16 >
152
- + BitAnd < Self :: Vi16 , Output = Self :: Vi16 >
153
- + BitOr < Self :: Vi16 , Output = Self :: Vi16 >
154
- + BitXor < Self :: Vi16 , Output = Self :: Vi16 >
155
- + BitAndAssign < Self :: Vi16 >
156
- + BitOrAssign < Self :: Vi16 >
157
- + BitXorAssign < Self :: Vi16 >
158
- + Index < usize , Output = i16 >
159
- + IndexMut < usize >
160
- + Not < Output = Self :: Vi16 >
161
- + Shl < i32 , Output = Self :: Vi16 >
162
- + ShlAssign < i32 >
163
- + Shr < i32 , Output = Self :: Vi16 >
164
- + ShrAssign < i32 > ;
165
- /// Vi32 stands for Vector of i32s. Corresponds to __m128i when used
178
+
179
+ type Vi16 : SimdSmallInt < Self :: Vi16 , i16 > ;
180
+
181
+ /// Vector of i32s. Corresponds to __m128i when used
166
182
/// with the Sse impl, __m256i when used with Avx2, or a single i32
167
183
/// when used with Scalar.
168
- type Vi32 : Copy
169
- + Debug
170
- + Add < Self :: Vi32 , Output = Self :: Vi32 >
171
- + Sub < Self :: Vi32 , Output = Self :: Vi32 >
172
- + Mul < Self :: Vi32 , Output = Self :: Vi32 >
173
- + AddAssign < Self :: Vi32 >
174
- + SubAssign < Self :: Vi32 >
175
- + MulAssign < Self :: Vi32 >
176
- + BitAnd < Self :: Vi32 , Output = Self :: Vi32 >
177
- + BitOr < Self :: Vi32 , Output = Self :: Vi32 >
178
- + BitXor < Self :: Vi32 , Output = Self :: Vi32 >
179
- + BitAndAssign < Self :: Vi32 >
180
- + BitOrAssign < Self :: Vi32 >
181
- + BitXorAssign < Self :: Vi32 >
182
- + Index < usize , Output = i32 >
183
- + IndexMut < usize >
184
- + Not < Output = Self :: Vi32 >
185
- + Shl < i32 , Output = Self :: Vi32 >
186
- + ShlAssign < i32 >
187
- + Shr < i32 , Output = Self :: Vi32 >
188
- + ShrAssign < i32 > ;
189
- /// Vf32 stands for Vector of f32s. Corresponds to __m128 when used
184
+ type Vi32 : SimdSmallInt < Self :: Vi32 , i32 > ;
185
+
186
+ /// Vector of i64s. Corresponds to __m128i when used
187
+ /// with the Sse impl, __m256i when used with Avx2, or a single i64
188
+ /// when used with Scalar.
189
+ type Vi64 : SimdBase < Self :: Vi64 , i64 >
190
+ + Not < Output = Self :: Vi64 > ;
191
+
192
+ /// Vector of f32s. Corresponds to __m128 when used
190
193
/// with the Sse impl, __m256 when used with Avx2, or a single f32
191
194
/// when used with Scalar.
192
- type Vf32 : Copy
193
- + Debug
194
- + Add < Self :: Vf32 , Output = Self :: Vf32 >
195
- + Sub < Self :: Vf32 , Output = Self :: Vf32 >
196
- + Mul < Self :: Vf32 , Output = Self :: Vf32 >
197
- + Div < Self :: Vf32 , Output = Self :: Vf32 >
198
- + AddAssign < Self :: Vf32 >
199
- + SubAssign < Self :: Vf32 >
200
- + MulAssign < Self :: Vf32 >
201
- + DivAssign < Self :: Vf32 >
202
- + BitAnd < Self :: Vf32 , Output = Self :: Vf32 >
203
- + BitOr < Self :: Vf32 , Output = Self :: Vf32 >
204
- + BitXor < Self :: Vf32 , Output = Self :: Vf32 >
205
- + BitAndAssign < Self :: Vf32 >
206
- + BitOrAssign < Self :: Vf32 >
207
- + BitXorAssign < Self :: Vf32 >
208
- + Index < usize , Output = f32 >
209
- + IndexMut < usize > ;
195
+ type Vf32 : SimdFloat < Self :: Vf32 , f32 > ;
210
196
211
- /// Vi64 stands for Vector of f64s. Corresponds to __m128 when used
212
- /// with the Sse impl, __m256 when used with Avx2, or a single f64
197
+ /// Vector of f64s. Corresponds to __m128d when used
198
+ /// with the Sse impl, __m256d when used with Avx2, or a single f64
213
199
/// when used with Scalar.
214
- type Vf64 : Copy
215
- + Debug
216
- + Index < usize , Output = f64 >
217
- + IndexMut < usize >
218
- + Add < Self :: Vf64 , Output = Self :: Vf64 >
219
- + Sub < Self :: Vf64 , Output = Self :: Vf64 >
220
- + Mul < Self :: Vf64 , Output = Self :: Vf64 >
221
- + Div < Self :: Vf64 , Output = Self :: Vf64 >
222
- + AddAssign < Self :: Vf64 >
223
- + SubAssign < Self :: Vf64 >
224
- + MulAssign < Self :: Vf64 >
225
- + DivAssign < Self :: Vf64 >
226
- + BitAnd < Self :: Vf64 , Output = Self :: Vf64 >
227
- + BitOr < Self :: Vf64 , Output = Self :: Vf64 >
228
- + BitXor < Self :: Vf64 , Output = Self :: Vf64 >
229
- + BitAndAssign < Self :: Vf64 >
230
- + BitOrAssign < Self :: Vf64 >
231
- + BitXorAssign < Self :: Vf64 > ;
232
-
233
- type Vi64 : Copy
234
- + Debug
235
- + Index < usize , Output = i64 >
236
- + IndexMut < usize >
237
- + Add < Self :: Vi64 , Output = Self :: Vi64 >
238
- + Sub < Self :: Vi64 , Output = Self :: Vi64 >
239
- + AddAssign < Self :: Vi64 >
240
- + SubAssign < Self :: Vi64 >
241
- + BitAnd < Self :: Vi64 , Output = Self :: Vi64 >
242
- + BitOr < Self :: Vi64 , Output = Self :: Vi64 >
243
- + BitXor < Self :: Vi64 , Output = Self :: Vi64 >
244
- + BitAndAssign < Self :: Vi64 >
245
- + BitOrAssign < Self :: Vi64 >
246
- + BitXorAssign < Self :: Vi64 >
247
- + Not < Output = Self :: Vi64 > ;
200
+ type Vf64 : SimdFloat < Self :: Vf64 , f64 > ;
201
+
202
+
248
203
/// The width of the vector lane. Necessary for creating
249
204
/// lane width agnostic code.
250
205
const VF32_WIDTH : usize ;
0 commit comments