Debian Codegraph @

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

raw
1 use wide::*;
2
3 #[test]
4 fn size_align() {
5 assert_eq!(core::mem::size_of::<i8x32>(), 32);
6 assert_eq!(core::mem::align_of::<i8x32>(), 32);
7 }
8
9 #[test]
10 fn basic_traits() {
11 crate::test_basic_traits::<i8x32, _, 32>();
12 }
13
14 #[test]
15 fn impl_add_for_i8x32() {
16 let a = i8x32::from([
17 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127, 1, 2, 3, 4, 5, 6,
18 7, 8, 9, 10, 11, 12, 13, 14, 126, 127,
19 ]);
20 let b = i8x32::from([
21 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1, 17, 18, 19,
22 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1,
23 ]);
24 let expected = i8x32::from([
25 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, -128, 18, 20,
26 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, -128,
27 ]);
28 let actual = a + b;
29 assert_eq!(expected, actual);
30 }
31
32 #[test]
33 fn impl_sub_for_i8x32() {
34 let a = i8x32::from([
35 1,
36 2,
37 3,
38 4,
39 5,
40 6,
41 7,
42 8,
43 9,
44 10,
45 11,
46 12,
47 13,
48 14,
49 i8::MIN + 1,
50 i8::MIN,
51 1,
52 2,
53 3,
54 4,
55 5,
56 6,
57 7,
58 8,
59 9,
60 10,
61 11,
62 12,
63 13,
64 14,
65 i8::MIN + 1,
66 i8::MIN,
67 ]);
68 let b = i8x32::from([
69 17, 27, -1, 20, 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1, 17, 27, -1, 20,
70 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1,
71 ]);
72 let expected = i8x32::from([
73 -16, -25, 4, -16, -16, 14, -16, 8, 8, 8, 20, -16, -51, -16, -128, 127, -16,
74 -25, 4, -16, -16, 14, -16, 8, 8, 8, 20, -16, -51, -16, -128, 127,
75 ]);
76 let actual = a - b;
77 assert_eq!(expected, actual);
78 }
79
80 #[test]
81 fn impl_saturating_add_for_i8x32() {
82 let a = i8x32::from([
83 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127, 1, 2, 3, 4, 5, 6,
84 7, 8, 9, 10, 11, 12, 13, 14, 126, 127,
85 ]);
86 let b = i8x32::from([
87 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1, 17, 18, 19,
88 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1,
89 ]);
90 let expected = i8x32::from([
91 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, 127, 18, 20,
92 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 127, 127,
93 ]);
94 let actual = a.saturating_add(b);
95 assert_eq!(expected, actual);
96 }
97
98 #[test]
99 fn impl_saturating_sub_for_i8x32() {
100 let a = i8x32::from([
101 1,
102 2,
103 3,
104 4,
105 5,
106 6,
107 7,
108 8,
109 9,
110 10,
111 11,
112 12,
113 13,
114 14,
115 i8::MIN + 1,
116 i8::MIN,
117 1,
118 2,
119 3,
120 4,
121 5,
122 6,
123 7,
124 8,
125 9,
126 10,
127 11,
128 12,
129 13,
130 14,
131 i8::MIN + 1,
132 i8::MIN,
133 ]);
134 let b = i8x32::from([
135 17, 27, -1, 20, 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1, 17, 27, -1, 20,
136 21, -8, 23, 0, 1, 2, -9, 28, 64, 30, 1, 1,
137 ]);
138 let expected = i8x32::from([
139 -16, -25, 4, -16, -16, 14, -16, 8, 8, 8, 20, -16, -51, -16, -128, -128,
140 -16, -25, 4, -16, -16, 14, -16, 8, 8, 8, 20, -16, -51, -16, -128, -128,
141 ]);
142 let actual = a.saturating_sub(b);
143 assert_eq!(expected, actual);
144 }
145
146 #[test]
147 fn impl_bitand_for_i8x32() {
148 let a = i8x32::from([
149 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
150 0, 1, 1, 0, 0, 1, 1,
151 ]);
152 let b = i8x32::from([
153 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
154 0, 1, 1, 0, 0, 1, 1,
155 ]);
156 let expected = i8x32::from([
157 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
158 0, 1, 1, 0, 0, 1, 1,
159 ]);
160 let actual = a & b;
161 assert_eq!(expected, actual);
162 }
163
164 #[test]
165 fn impl_bitor_for_i8x32() {
166 let a = i8x32::from([
167 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
168 0, 1, 1, 0, 0, 1, 1,
169 ]);
170 let b = i8x32::from([
171 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
172 1, 0, 1, 0, 1, 0, 1,
173 ]);
174 let expected = i8x32::from([
175 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0,
176 1, 1, 1, 0, 1, 1, 1,
177 ]);
178 let actual = a | b;
179 assert_eq!(expected, actual);
180 }
181
182 #[test]
183 fn impl_bitxor_for_i8x32() {
184 let a = i8x32::from([
185 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
186 0, 1, 1, 0, 0, 1, 1,
187 ]);
188 let b = i8x32::from([
189 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0,
190 0, 1, 1, 0, 0, 1, 1,
191 ]);
192 let expected = i8x32::from([
193 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194 0, 0, 0, 0, 0, 0, 0,
195 ]);
196 let actual = a ^ b;
197 assert_eq!(expected, actual);
198 }
199
200 #[test]
201 fn impl_i8x32_cmp_eq() {
202 let a = i8x32::from([
203 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1,
204 2, 3, 4, 1, 2, 3, 4,
205 ]);
206 let b = i8x32::from([2_i8; 32]);
207 let expected = i8x32::from([
208 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0,
209 0, 0, -1, 0, 0, 0, -1, 0, 0,
210 ]);
211 let actual = a.cmp_eq(b);
212 assert_eq!(expected, actual);
213 }
214
215 #[test]
216 fn impl_i8x32_cmp_gt() {
217 let a = i8x32::from([
218 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1,
219 2, 3, 4, 1, 2, 3, 4,
220 ]);
221 let b = i8x32::from([2_i8; 32]);
222 let expected = i8x32::from([
223 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0,
224 -1, -1, 0, 0, -1, -1, 0, 0, -1, -1,
225 ]);
226 let actual = a.cmp_gt(b);
227 assert_eq!(expected, actual);
228 }
229
230 #[test]
231 fn impl_i8x32_cmp_lt() {
232 let a = i8x32::from([
233 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1,
234 2, 3, 4, 1, 2, 3, 4,
235 ]);
236 let b = i8x32::from([2_i8; 32]);
237 let expected = i8x32::from([
238 -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0,
239 0, -1, 0, 0, 0, -1, 0, 0, 0,
240 ]);
241 let actual = a.cmp_lt(b);
242 assert_eq!(expected, actual);
243
244 let expected = i8x32::from([
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
246 0, 0, 0, 0, 0, 0, 0,
247 ]);
248 let actual = a.cmp_lt(a);
249 assert_eq!(expected, actual);
250 }
251
252 #[test]
253 fn impl_i8x32_blend() {
254 let use_t: i8 = -1;
255 let t = i8x32::from([
256 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 127, 1, 2, 3, 4, 5, 6,
257 7, 8, 9, 10, 11, 12, 13, 14, 126, 127,
258 ]);
259 let f = i8x32::from([
260 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1, 17, 18, 19,
261 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 1,
262 ]);
263 let mask = i8x32::from([
264 use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0,
265 use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0, use_t, 0,
266 use_t, 0, use_t, 0,
267 ]);
268 let expected = i8x32::from([
269 1, 18, 3, 20, 5, 22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1, 1, 18, 3, 20, 5,
270 22, 7, 24, 9, 26, 11, 28, 13, 30, 126, 1,
271 ]);
272 let actual = mask.blend(t, f);
273 assert_eq!(expected, actual);
274 }
275
276 #[test]
277 fn impl_i8x32_abs() {
278 let a = i8x32::from([
279 -1,
280 2,
281 -3,
282 4,
283 5,
284 -6,
285 7,
286 8,
287 9,
288 -10,
289 -11,
290 12,
291 13,
292 -14,
293 -126,
294 i8::MIN,
295 -1,
296 2,
297 -3,
298 4,
299 5,
300 -6,
301 7,
302 8,
303 9,
304 -10,
305 -11,
306 12,
307 13,
308 -14,
309 -126,
310 i8::MIN,
311 ]);
312 let expected = i8x32::from([
313 1,
314 2,
315 3,
316 4,
317 5,
318 6,
319 7,
320 8,
321 9,
322 10,
323 11,
324 12,
325 13,
326 14,
327 126,
328 i8::MIN,
329 1,
330 2,
331 3,
332 4,
333 5,
334 6,
335 7,
336 8,
337 9,
338 10,
339 11,
340 12,
341 13,
342 14,
343 126,
344 i8::MIN,
345 ]);
346 let actual = a.abs();
347 assert_eq!(expected, actual);
348 }
349
350 #[test]
351 fn impl_i8x32_unsigned_abs() {
352 let a = i8x32::from([
353 -1,
354 2,
355 -3,
356 4,
357 5,
358 -6,
359 7,
360 8,
361 9,
362 -10,
363 -11,
364 12,
365 13,
366 -14,
367 -126,
368 i8::MIN,
369 -1,
370 2,
371 -3,
372 4,
373 5,
374 -6,
375 7,
376 8,
377 9,
378 -10,
379 -11,
380 12,
381 13,
382 -14,
383 -126,
384 i8::MIN,
385 ]);
386 let expected = u8x32::from([
387 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 126, 128, 1, 2, 3, 4, 5, 6,
388 7, 8, 9, 10, 11, 12, 13, 14, 126, 128,
389 ]);
390 let actual = a.unsigned_abs();
391 assert_eq!(expected, actual);
392 }
393
394 #[test]
395 fn impl_i8x32_max() {
396 let a = i8x32::from([
397 10,
398 2,
399 -3,
400 4,
401 5,
402 -6,
403 7,
404 8,
405 9,
406 7,
407 -11,
408 12,
409 13,
410 6,
411 55,
412 i8::MIN,
413 10,
414 2,
415 -3,
416 4,
417 5,
418 -6,
419 7,
420 8,
421 9,
422 7,
423 -11,
424 12,
425 13,
426 6,
427 55,
428 i8::MIN,
429 ]);
430 let b = i8x32::from([
431 -1,
432 2,
433 -3,
434 4,
435 5,
436 -6,
437 7,
438 8,
439 9,
440 -10,
441 -11,
442 12,
443 13,
444 -14,
445 -126,
446 i8::MIN + 1,
447 -1,
448 2,
449 -3,
450 4,
451 5,
452 -6,
453 7,
454 8,
455 9,
456 -10,
457 -11,
458 12,
459 13,
460 -14,
461 -126,
462 i8::MIN + 1,
463 ]);
464 let expected = i8x32::from([
465 10, 2, -3, 4, 5, -6, 7, 8, 9, 7, -11, 12, 13, 6, 55, -127, 10, 2, -3, 4, 5,
466 -6, 7, 8, 9, 7, -11, 12, 13, 6, 55, -127,
467 ]);
468 let actual = a.max(b);
469 assert_eq!(expected, actual);
470
471 crate::test_random_vector_vs_scalar(|a: i8x32, b| a.max(b), |a, b| a.max(b));
472 }
473
474 #[test]
475 fn impl_i8x32_min() {
476 let a = i8x32::from([
477 10,
478 2,
479 -3,
480 4,
481 5,
482 -6,
483 7,
484 8,
485 9,
486 7,
487 -11,
488 12,
489 13,
490 6,
491 55,
492 i8::MIN,
493 10,
494 2,
495 -3,
496 4,
497 5,
498 -6,
499 7,
500 8,
501 9,
502 7,
503 -11,
504 12,
505 13,
506 6,
507 55,
508 i8::MIN,
509 ]);
510 let b = i8x32::from([
511 -1,
512 2,
513 -3,
514 4,
515 5,
516 -6,
517 7,
518 8,
519 9,
520 -10,
521 -11,
522 12,
523 13,
524 -14,
525 -126,
526 i8::MIN + 1,
527 -1,
528 2,
529 -3,
530 4,
531 5,
532 -6,
533 7,
534 8,
535 9,
536 -10,
537 -11,
538 12,
539 13,
540 -14,
541 -126,
542 i8::MIN + 1,
543 ]);
544 let expected = i8x32::from([
545 -1,
546 2,
547 -3,
548 4,
549 5,
550 -6,
551 7,
552 8,
553 9,
554 -10,
555 -11,
556 12,
557 13,
558 -14,
559 -126,
560 i8::MIN,
561 -1,
562 2,
563 -3,
564 4,
565 5,
566 -6,
567 7,
568 8,
569 9,
570 -10,
571 -11,
572 12,
573 13,
574 -14,
575 -126,
576 i8::MIN,
577 ]);
578 let actual = a.min(b);
579 assert_eq!(expected, actual);
580
581 crate::test_random_vector_vs_scalar(|a: i8x32, b| a.min(b), |a, b| a.min(b));
582 }
583
584 #[test]
585 fn test_i8x32_move_mask() {
586 let a = i8x32::from([
587 -1, 0, -2, -3, -1, 0, -2, -3, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1,
588 -1, -1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0,
589 ]);
590 let expected = 0b01010101011111110101010111011101;
591 let actual = a.move_mask();
592 assert_eq!(expected, actual);
593 }
594
595 #[test]
596 fn test_i8x32_any() {
597 let a = i8x32::from([
598 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
599 0, 0, 0, 0, 0, 0, 0,
600 ]);
601 assert!(a.any());
602
603 let a = i8x32::from([
604 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
605 0, 0, 0, -1, 0, 0, 0,
606 ]);
607 assert!(a.any());
608
609 //
610 let a = i8x32::from([0; 32]);
611 assert!(!a.any());
612 }
613
614 #[test]
615 fn test_i8x32_all() {
616 let a = i8x32::from([
617 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
618 0, 0, 0, 0, 0, 0, 0,
619 ]);
620 assert!(!a.all());
621 //
622 let a = i8x32::from([-1; 32]);
623 assert!(a.all());
624 }
625
626 #[test]
627 fn test_i8x32_none() {
628 let a = i8x32::from([
629 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
630 0, 0, 0, 0, 0, 0, 0,
631 ]);
632 assert!(!a.none());
633
634 let a = i8x32::from([
635 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
636 0, 0, 0, -1, 0, 0, 0,
637 ]);
638 assert!(!a.none());
639
640 //
641 let a = i8x32::from([0; 32]);
642 assert!(a.none());
643 }
644
645 #[test]
646 fn test_i8x32_swizzle_half() {
647 let a = i8x32::from([
648 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
649 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
650 ]);
651 let b = i8x32::from([
652 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11,
653 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
654 ]);
655 let expected = i8x32::from([
656 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 32, 31, 30, 29, 28,
657 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
658 ]);
659 let actual = a.swizzle_half(b);
660 assert_eq!(expected, actual);
661 }
662
663 #[cfg(feature = "serde")]
664 #[test]
665 fn impl_i8x32_ser_de_roundtrip() {
666 let serialized =
667 bincode::serialize(&i8x32::ZERO).expect("serialization failed");
668 let deserialized =
669 bincode::deserialize(&serialized).expect("deserializaion failed");
670 assert_eq!(i8x32::ZERO, deserialized);
671 }