Debian Codegraph @

debian/missing-sources/wide/tests/all_tests/t_i16x8.rs

raw
1 use wide::*;
2
3 #[test]
4 fn size_align() {
5 assert_eq!(core::mem::size_of::<i16x8>(), 16);
6 assert_eq!(core::mem::align_of::<i16x8>(), 16);
7 }
8
9 #[test]
10 fn basic_traits() {
11 crate::test_basic_traits::<i16x8, _, 8>();
12 }
13
14 #[test]
15 fn impl_add_for_i16x8() {
16 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MAX - 1, i16::MAX - 1]);
17 let b = i16x8::from([17, 18, 19, 20, 21, 22, 1, 2]);
18 let expected = i16x8::from([18, 20, 22, 24, 26, 28, i16::MAX, i16::MIN]);
19 let actual = a + b;
20 assert_eq!(expected, actual);
21 }
22
23 #[test]
24 fn impl_sub_for_i16x8() {
25 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
26 let b = i16x8::from([17, -18, 190, -20, 21, -22, 1, 1]);
27 let expected = i16x8::from([-16, 20, -187, 24, -16, 28, i16::MIN, i16::MAX]);
28 let actual = a - b;
29 assert_eq!(expected, actual);
30 }
31
32 #[test]
33 fn impl_add_saturating_for_i16x8() {
34 let a = i16x8::from([i16::MAX, i16::MIN, 3, 4, -1, -2, -3, -4]);
35 let b = i16x8::from([i16::MAX, i16::MIN, 7, 8, -15, -26, -37, 48]);
36 let expected = i16x8::from([i16::MAX, i16::MIN, 10, 12, -16, -28, -40, 44]);
37 let actual = a.saturating_add(b);
38 assert_eq!(expected, actual);
39 }
40
41 #[test]
42 fn impl_mul_scale_i16x8() {
43 let a = i16x8::from([100, 200, 300, 400, 500, -600, 700, -800]);
44 let b = i16x8::from([900, 1000, 1100, 1200, 1300, -1400, -1500, 1600]);
45 let actual = a.mul_scale_round(b);
46 let expected = i16x8::from([3, 6, 10, 15, 20, 26, -32, -39]);
47 assert_eq!(expected, actual);
48 }
49
50 #[test]
51 fn impl_mul_scale_n_i16x8() {
52 let a = i16x8::from([100, 200, 300, 400, 500, -600, 700, -800]);
53 let actual = a.mul_scale_round_n(0x4000);
54 let expected = i16x8::from([50, 100, 150, 200, 250, -300, 350, -400]);
55 assert_eq!(expected, actual);
56 }
57
58 #[test]
59 fn impl_sub_saturating_for_i16x8() {
60 let a = i16x8::from([1, 2, 3, 4, 5, i16::MIN, i16::MIN + 1, i16::MAX]);
61 let b = i16x8::from([17, -18, 190, -20, 21, -1, 1, -1]);
62 let expected =
63 i16x8::from([-16, 20, -187, 24, -16, i16::MIN + 1, i16::MIN, i16::MAX]);
64 let actual = a.saturating_sub(b);
65 assert_eq!(expected, actual);
66 }
67
68 #[test]
69 fn impl_mul_for_i16x8() {
70 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
71 let b = i16x8::from([17, -18, 190, -20, 21, -22, 1, 1]);
72 let expected =
73 i16x8::from([17, -36, 570, -80, 105, -132, i16::MIN + 1, i16::MIN]);
74 let actual = a * b;
75 assert_eq!(expected, actual);
76 }
77
78 #[test]
79 fn impl_transpose_for_i16x8() {
80 let a = [
81 i16x8::new([0, 1, 2, 3, 4, 5, 6, 7]),
82 i16x8::new([8, 9, 10, 11, 12, 13, 14, 15]),
83 i16x8::new([16, 17, 18, 19, 20, 21, 22, 23]),
84 i16x8::new([24, 25, 26, 27, 28, 29, 30, 31]),
85 i16x8::new([32, 33, 34, 35, 36, 37, 38, 39]),
86 i16x8::new([40, 41, 42, 43, 44, 45, 46, 47]),
87 i16x8::new([48, 49, 50, 51, 52, 53, 54, 55]),
88 i16x8::new([5600, 5700, 5800, 5900, 6000, 6100, 6200, 6300]),
89 ];
90
91 let result = i16x8::transpose(a);
92
93 let expected = [
94 i16x8::new([0, 8, 16, 24, 32, 40, 48, 5600]),
95 i16x8::new([1, 9, 17, 25, 33, 41, 49, 5700]),
96 i16x8::new([2, 10, 18, 26, 34, 42, 50, 5800]),
97 i16x8::new([3, 11, 19, 27, 35, 43, 51, 5900]),
98 i16x8::new([4, 12, 20, 28, 36, 44, 52, 6000]),
99 i16x8::new([5, 13, 21, 29, 37, 45, 53, 6100]),
100 i16x8::new([6, 14, 22, 30, 38, 46, 54, 6200]),
101 i16x8::new([7, 15, 23, 31, 39, 47, 55, 6300]),
102 ];
103
104 assert_eq!(result, expected);
105 }
106
107 #[test]
108 fn impl_bitand_for_i16x8() {
109 let a = i16x8::from([0, 0, 1, 1, 0, 0, 1, 1]);
110 let b = i16x8::from([0, 1, 0, 1, 0, 1, 0, 1]);
111 let expected = i16x8::from([0, 0, 0, 1, 0, 0, 0, 1]);
112 let actual = a & b;
113 assert_eq!(expected, actual);
114 }
115
116 #[test]
117 fn impl_bitor_for_i16x8() {
118 let a = i16x8::from([0, 0, 1, 1, 0, 0, 1, 1]);
119 let b = i16x8::from([0, 1, 0, 1, 0, 1, 0, 1]);
120 let expected = i16x8::from([0, 1, 1, 1, 0, 1, 1, 1]);
121 let actual = a | b;
122 assert_eq!(expected, actual);
123 }
124
125 #[test]
126 fn impl_bitxor_for_i16x8() {
127 let a = i16x8::from([0, 0, 1, 1, 0, 0, 1, 1]);
128 let b = i16x8::from([0, 1, 0, 1, 0, 1, 0, 1]);
129 let expected = i16x8::from([0, 1, 1, 0, 0, 1, 1, 0]);
130 let actual = a ^ b;
131 assert_eq!(expected, actual);
132 }
133
134 #[test]
135 fn impl_shl_for_i16x8() {
136 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
137 let b = 2;
138 let expected = i16x8::from([
139 1 << 2,
140 2 << 2,
141 3 << 2,
142 4 << 2,
143 5 << 2,
144 6 << 2,
145 (i16::MIN + 1) << 2,
146 i16::MIN << 2,
147 ]);
148 let actual = a << b;
149 assert_eq!(expected, actual);
150 }
151
152 #[test]
153 fn impl_shr_for_i16x8() {
154 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
155 let b = 2;
156 let expected = i16x8::from([
157 1 >> 2,
158 2 >> 2,
159 3 >> 2,
160 4 >> 2,
161 5 >> 2,
162 6 >> 2,
163 (i16::MIN + 1) >> 2,
164 i16::MIN >> 2,
165 ]);
166 let actual = a >> b;
167 assert_eq!(expected, actual);
168 }
169
170 #[test]
171 fn impl_i16x8_cmp_eq() {
172 let a = i16x8::from([1, 2, 3, 4, 1, 2, 3, 4]);
173 let b = i16x8::from([2_i16; 8]);
174 let expected = i16x8::from([0, -1, 0, 0, 0, -1, 0, 0]);
175 let actual = a.cmp_eq(b);
176 assert_eq!(expected, actual);
177 }
178
179 #[test]
180 fn impl_i16x8_cmp_gt() {
181 let a = i16x8::from([1, 2, 3, 4, 1, 2, 3, 4]);
182 let b = i16x8::from([2_i16; 8]);
183 let expected = i16x8::from([0, 0, -1, -1, 0, 0, -1, -1]);
184 let actual = a.cmp_gt(b);
185 assert_eq!(expected, actual);
186 }
187
188 #[test]
189 fn impl_i16x8_cmp_lt() {
190 let a = i16x8::from([1, 2, 3, 4, 1, 2, 3, 4]);
191 let b = i16x8::from([2_i16; 8]);
192 let expected = i16x8::from([-1, 0, 0, 0, -1, 0, 0, 0]);
193 let actual = a.cmp_lt(b);
194 assert_eq!(expected, actual);
195
196 let expected = i16x8::from([0, 0, 0, 0, 0, 0, 0, 0]);
197 let actual = a.cmp_lt(a);
198 assert_eq!(expected, actual);
199 }
200
201 #[test]
202 fn impl_i16x8_blend() {
203 let use_t: i16 = -1;
204 let t = i16x8::from([1, 2, 3, 4, 5, 6, 7, 8]);
205 let f = i16x8::from([17, 18, 19, 20, 21, 22, 23, 24]);
206 let mask = i16x8::from([use_t, 0, use_t, 0, use_t, 0, use_t, 0]);
207 let expected = i16x8::from([1, 18, 3, 20, 5, 22, 7, 24]);
208 let actual = mask.blend(t, f);
209 assert_eq!(expected, actual);
210 }
211
212 #[test]
213 fn impl_i16x8_abs() {
214 let a = i16x8::from([1, -2, 3, -4, 5, -6, -7, i16::MIN]);
215 let expected = i16x8::from([1, 2, 3, 4, 5, 6, 7, i16::MIN]);
216 let actual = a.abs();
217 assert_eq!(expected, actual);
218 }
219
220 #[test]
221 fn impl_i16x8_unsigned_abs() {
222 let a = i16x8::from([1, -2, 3, -4, 5, -6, -7, i16::MIN]);
223 let expected = u16x8::from([1, 2, 3, 4, 5, 6, 7, i16::MIN as u16]);
224 let actual = a.unsigned_abs();
225 assert_eq!(expected, actual);
226 }
227
228 #[test]
229 fn impl_i16x8_max() {
230 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
231 let b = i16x8::from([17, -18, 190, -20, 21, -22, 1, 1]);
232 let expected = i16x8::from([17, 2, 190, 4, 21, 6, 1, 1]);
233 let actual = a.max(b);
234 assert_eq!(expected, actual);
235
236 crate::test_random_vector_vs_scalar(|a: i16x8, b| a.max(b), |a, b| a.max(b));
237 }
238
239 #[test]
240 fn impl_i16x8_min() {
241 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
242 let b = i16x8::from([17, -18, 190, -20, 21, -22, 1, 1]);
243 let expected = i16x8::from([1, -18, 3, -20, 5, -22, i16::MIN + 1, i16::MIN]);
244 let actual = a.min(b);
245 assert_eq!(expected, actual);
246
247 crate::test_random_vector_vs_scalar(|a: i16x8, b| a.min(b), |a, b| a.min(b));
248 }
249
250 #[test]
251 fn test_from_u8x16_low() {
252 let bytes =
253 u8x16::from([1, 2, 3, 4, 5, 6, 7, u8::MAX, 9, 10, 11, 12, 13, 14, 15, 16]);
254 let expected = i16x8::from([1, 2, 3, 4, 5, 6, 7, u8::MAX as i16]);
255 let actual = i16x8::from_u8x16_low(bytes);
256 assert_eq!(expected, actual);
257 }
258
259 #[test]
260 fn test_from_u8x16_high() {
261 let a =
262 u8x16::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255, 128]);
263 let expected = i16x8::from([9, 10, 11, 12, 13, 14, 255, 128]);
264 let actual = i16x8::from_u8x16_high(a);
265 assert_eq!(expected, actual);
266 }
267
268 #[test]
269 fn impl_from_i32x8_truncate() {
270 let src = i32x8::new([10000, 1001, 2, 3, 4, 5, -65536, 65536]);
271
272 let expected = i16x8::new([10000, 1001, 2, 3, 4, 5, 0, 0]);
273
274 let result = i16x8::from_i32x8_truncate(src);
275
276 assert_eq!(result, expected);
277 }
278
279 #[test]
280 fn impl_from_i32x8_saturate() {
281 let src = i32x8::new([10000, 1001, 2, 3, 4, 5, -65535, 65536]);
282
283 let expected = i16x8::new([10000, 1001, 2, 3, 4, 5, -32768, 32767]);
284
285 let result = i16x8::from_i32x8_saturate(src);
286
287 assert_eq!(result, expected);
288 }
289
290 #[test]
291 fn impl_from_i16_slice() {
292 let src = [0, 1_i16, 2, 3, 4, 5, 6, 7, 8];
293
294 let result = i16x8::from_slice_unaligned(&src[1..9]);
295
296 let expected = i16x8::new([1_i16, 2, 3, 4, 5, 6, 7, 8]);
297 assert_eq!(result, expected);
298 }
299
300 #[test]
301 fn test_i16x8_move_mask() {
302 let a = i16x8::from([-1, 0, -2, -3, -1, 0, -2, -3]);
303 let expected = 0b11011101;
304 let actual = a.move_mask();
305 assert_eq!(expected, actual);
306 //
307 let a = i16x8::from([1, 0, 2, -3, 1, 0, 2, -3]);
308 let expected = 0b10001000;
309 let actual = a.move_mask();
310 assert_eq!(expected, actual);
311 }
312
313 #[test]
314 fn test_i16x8_any() {
315 let a = i16x8::from([0, 0, 0, -1, 0, 0, 0, 0]);
316 assert!(a.any());
317 //
318 let a = i16x8::from([0, 0, 0, 0, 0, 0, 0, 0]);
319 assert!(!a.any());
320 }
321
322 #[test]
323 fn test_i16x8_all() {
324 let a = i16x8::from([0, 0, 0, -1, 0, 0, 0, 0]);
325 assert!(!a.all());
326 //
327 let a = i16x8::from([-1; 8]);
328 assert!(a.all());
329 }
330
331 #[test]
332 fn test_i16x8_none() {
333 let a = i16x8::from([0, 0, 0, -1, 0, 0, 0, 0]);
334 assert!(!a.none());
335 //
336 let a = i16x8::from([0; 8]);
337 assert!(a.none());
338 }
339
340 #[test]
341 fn impl_i16x8_reduce_add() {
342 let p = i16x8::from([1, 2, 3, 4, 5, 6, 7, 9]);
343 assert_eq!(p.reduce_add(), 37);
344 }
345
346 #[test]
347 fn impl_dot_for_i16x8() {
348 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN + 1, i16::MIN]);
349 let b = i16x8::from([17, -18, 190, -20, 21, -22, 3, 2]);
350 let expected = i32x4::from([-19, 490, -27, -163837]);
351 let actual = a.dot(b);
352 assert_eq!(expected, actual);
353 }
354
355 #[test]
356 fn impl_i16x8_reduce_min() {
357 for i in 0..8 {
358 let mut v = [i16::MAX; 8];
359 v[i] = i16::MIN;
360 let p = i16x8::from(v);
361 assert_eq!(p.reduce_min(), i16::MIN);
362 }
363 }
364
365 #[test]
366 fn impl_i16x8_reduce_max() {
367 for i in 0..8 {
368 let mut v = [i16::MIN; 8];
369 v[i] = i16::MAX;
370 let p = i16x8::from(v);
371 assert_eq!(p.reduce_min(), i16::MIN);
372 }
373 }
374
375 #[test]
376 fn impl_mul_keep_high() {
377 let a = i16x8::from([i16::MAX, 200, 300, 4568, -1, -2, -3, -4]);
378 let b = i16x8::from([i16::MIN, 600, 700, 8910, -15, -26, -37, 48]);
379 let c: [i16; 8] = i16x8::mul_keep_high(a, b).into();
380 assert_eq!(
381 c,
382 [
383 (i32::from(i16::MAX) * i32::from(i16::MIN) >> 16) as i16,
384 1,
385 3,
386 621,
387 0,
388 0,
389 0,
390 -1
391 ]
392 );
393
394 crate::test_random_vector_vs_scalar(
395 |a: i16x8, b| i16x8::mul_keep_high(a, b),
396 |a, b| ((i32::from(a) * i32::from(b)) >> 16) as i16,
397 );
398 }
399
400 #[test]
401 fn impl_i16x8_mul_widen() {
402 let a = i16x8::from([1, 2, 3, 4, 5, 6, i16::MIN, i16::MAX]);
403 let b = i16x8::from([17, -18, 190, -20, 21, -22, i16::MAX, i16::MAX]);
404 let expected = i32x8::from([
405 17,
406 -36,
407 570,
408 -80,
409 105,
410 -132,
411 (i16::MIN as i32) * (i16::MAX as i32),
412 (i16::MAX as i32) * (i16::MAX as i32),
413 ]);
414 let actual = a.mul_widen(b);
415 assert_eq!(expected, actual);
416
417 crate::test_random_vector_vs_scalar(
418 |a: i16x8, b| a.mul_widen(b),
419 |a, b| i32::from(a) * i32::from(b),
420 );
421 }
422
423 #[cfg(feature = "serde")]
424 #[test]
425 fn impl_i16x8_ser_de_roundtrip() {
426 let serialized =
427 bincode::serialize(&i16x8::ZERO).expect("serialization failed");
428 let deserialized =
429 bincode::deserialize(&serialized).expect("deserializaion failed");
430 assert_eq!(i16x8::ZERO, deserialized);
431 }