1//! Internal `#[repr(simd)]` types
2
3#![allow(non_camel_case_types)]
4
5macro_rules! simd_ty {
6 ($id:ident [$ety:ident]: $($elem_ty:ident),* | $($elem_name:ident),*) => {
7 #[repr(simd)]
8 #[derive(Copy, Clone, Debug, PartialEq)]
9 pub(crate) struct $id($(pub $elem_ty),*);
10
11 #[allow(clippy::use_self)]
12 impl $id {
13 #[inline(always)]
14 pub(crate) const fn new($($elem_name: $elem_ty),*) -> Self {
15 $id($($elem_name),*)
16 }
17 // FIXME: Workaround rust@60637
18 #[inline(always)]
19 pub(crate) const fn splat(value: $ety) -> Self {
20 $id($({
21 #[allow(non_camel_case_types, dead_code)]
22 struct $elem_name;
23 value
24 }),*)
25 }
26
27 // FIXME: Workaround rust@60637
28 #[inline(always)]
29 pub(crate) fn extract(self, index: usize) -> $ety {
30 unsafe {
31 crate::core_arch::simd_llvm::simd_extract(self, index as u32)
32 }
33 }
34 }
35 }
36}
37
38macro_rules! simd_m_ty {
39 ($id:ident [$ety:ident]: $($elem_ty:ident),* | $($elem_name:ident),*) => {
40 #[repr(simd)]
41 #[derive(Copy, Clone, Debug, PartialEq)]
42 pub(crate) struct $id($(pub $elem_ty),*);
43
44 #[allow(clippy::use_self)]
45 impl $id {
46 #[inline(always)]
47 const fn bool_to_internal(x: bool) -> $ety {
48 [0 as $ety, !(0 as $ety)][x as usize]
49 }
50
51 #[inline(always)]
52 pub(crate) const fn new($($elem_name: bool),*) -> Self {
53 $id($(Self::bool_to_internal($elem_name)),*)
54 }
55
56 // FIXME: Workaround rust@60637
57 #[inline(always)]
58 pub(crate) const fn splat(value: bool) -> Self {
59 $id($({
60 #[allow(non_camel_case_types, dead_code)]
61 struct $elem_name;
62 Self::bool_to_internal(value)
63 }),*)
64 }
65
66 // FIXME: Workaround rust@60637
67 #[inline(always)]
68 pub(crate) fn extract(self, index: usize) -> bool {
69 let r: $ety = unsafe {
70 crate::core_arch::simd_llvm::simd_extract(self, index as u32)
71 };
72 r != 0
73 }
74 }
75 }
76}
77
78// 16-bit wide types:
79
80simd_ty!(u8x2[u8]: u8, u8 | x0, x1);
81simd_ty!(i8x2[i8]: i8, i8 | x0, x1);
82
83// 32-bit wide types:
84
85simd_ty!(u8x4[u8]: u8, u8, u8, u8 | x0, x1, x2, x3);
86simd_ty!(u16x2[u16]: u16, u16 | x0, x1);
87
88simd_ty!(i8x4[i8]: i8, i8, i8, i8 | x0, x1, x2, x3);
89simd_ty!(i16x2[i16]: i16, i16 | x0, x1);
90
91// 64-bit wide types:
92
93simd_ty!(
94 u8x8[u8]: u8,
95 u8,
96 u8,
97 u8,
98 u8,
99 u8,
100 u8,
101 u8 | x0,
102 x1,
103 x2,
104 x3,
105 x4,
106 x5,
107 x6,
108 x7
109);
110simd_ty!(u16x4[u16]: u16, u16, u16, u16 | x0, x1, x2, x3);
111simd_ty!(u32x2[u32]: u32, u32 | x0, x1);
112simd_ty!(u64x1[u64]: u64 | x1);
113
114simd_ty!(
115 i8x8[i8]: i8,
116 i8,
117 i8,
118 i8,
119 i8,
120 i8,
121 i8,
122 i8 | x0,
123 x1,
124 x2,
125 x3,
126 x4,
127 x5,
128 x6,
129 x7
130);
131simd_ty!(i16x4[i16]: i16, i16, i16, i16 | x0, x1, x2, x3);
132simd_ty!(i32x2[i32]: i32, i32 | x0, x1);
133simd_ty!(i64x1[i64]: i64 | x1);
134
135simd_ty!(f32x2[f32]: f32, f32 | x0, x1);
136simd_ty!(f64x1[f64]: f64 | x1);
137
138// 128-bit wide types:
139
140simd_ty!(
141 u8x16[u8]: u8,
142 u8,
143 u8,
144 u8,
145 u8,
146 u8,
147 u8,
148 u8,
149 u8,
150 u8,
151 u8,
152 u8,
153 u8,
154 u8,
155 u8,
156 u8 | x0,
157 x1,
158 x2,
159 x3,
160 x4,
161 x5,
162 x6,
163 x7,
164 x8,
165 x9,
166 x10,
167 x11,
168 x12,
169 x13,
170 x14,
171 x15
172);
173simd_ty!(
174 u16x8[u16]: u16,
175 u16,
176 u16,
177 u16,
178 u16,
179 u16,
180 u16,
181 u16 | x0,
182 x1,
183 x2,
184 x3,
185 x4,
186 x5,
187 x6,
188 x7
189);
190simd_ty!(u32x4[u32]: u32, u32, u32, u32 | x0, x1, x2, x3);
191simd_ty!(u64x2[u64]: u64, u64 | x0, x1);
192
193simd_ty!(
194 i8x16[i8]: i8,
195 i8,
196 i8,
197 i8,
198 i8,
199 i8,
200 i8,
201 i8,
202 i8,
203 i8,
204 i8,
205 i8,
206 i8,
207 i8,
208 i8,
209 i8 | x0,
210 x1,
211 x2,
212 x3,
213 x4,
214 x5,
215 x6,
216 x7,
217 x8,
218 x9,
219 x10,
220 x11,
221 x12,
222 x13,
223 x14,
224 x15
225);
226simd_ty!(
227 i16x8[i16]: i16,
228 i16,
229 i16,
230 i16,
231 i16,
232 i16,
233 i16,
234 i16 | x0,
235 x1,
236 x2,
237 x3,
238 x4,
239 x5,
240 x6,
241 x7
242);
243simd_ty!(i32x4[i32]: i32, i32, i32, i32 | x0, x1, x2, x3);
244simd_ty!(i64x2[i64]: i64, i64 | x0, x1);
245
246simd_ty!(f32x4[f32]: f32, f32, f32, f32 | x0, x1, x2, x3);
247simd_ty!(f64x2[f64]: f64, f64 | x0, x1);
248simd_ty!(f64x4[f64]: f64, f64, f64, f64 | x0, x1, x2, x3);
249
250simd_m_ty!(
251 m8x16[i8]: i8,
252 i8,
253 i8,
254 i8,
255 i8,
256 i8,
257 i8,
258 i8,
259 i8,
260 i8,
261 i8,
262 i8,
263 i8,
264 i8,
265 i8,
266 i8 | x0,
267 x1,
268 x2,
269 x3,
270 x4,
271 x5,
272 x6,
273 x7,
274 x8,
275 x9,
276 x10,
277 x11,
278 x12,
279 x13,
280 x14,
281 x15
282);
283simd_m_ty!(
284 m16x8[i16]: i16,
285 i16,
286 i16,
287 i16,
288 i16,
289 i16,
290 i16,
291 i16 | x0,
292 x1,
293 x2,
294 x3,
295 x4,
296 x5,
297 x6,
298 x7
299);
300simd_m_ty!(m32x4[i32]: i32, i32, i32, i32 | x0, x1, x2, x3);
301simd_m_ty!(m64x2[i64]: i64, i64 | x0, x1);
302
303// 256-bit wide types:
304
305simd_ty!(
306 u8x32[u8]: u8,
307 u8,
308 u8,
309 u8,
310 u8,
311 u8,
312 u8,
313 u8,
314 u8,
315 u8,
316 u8,
317 u8,
318 u8,
319 u8,
320 u8,
321 u8,
322 u8,
323 u8,
324 u8,
325 u8,
326 u8,
327 u8,
328 u8,
329 u8,
330 u8,
331 u8,
332 u8,
333 u8,
334 u8,
335 u8,
336 u8,
337 u8 | x0,
338 x1,
339 x2,
340 x3,
341 x4,
342 x5,
343 x6,
344 x7,
345 x8,
346 x9,
347 x10,
348 x11,
349 x12,
350 x13,
351 x14,
352 x15,
353 x16,
354 x17,
355 x18,
356 x19,
357 x20,
358 x21,
359 x22,
360 x23,
361 x24,
362 x25,
363 x26,
364 x27,
365 x28,
366 x29,
367 x30,
368 x31
369);
370simd_ty!(
371 u16x16[u16]: u16,
372 u16,
373 u16,
374 u16,
375 u16,
376 u16,
377 u16,
378 u16,
379 u16,
380 u16,
381 u16,
382 u16,
383 u16,
384 u16,
385 u16,
386 u16 | x0,
387 x1,
388 x2,
389 x3,
390 x4,
391 x5,
392 x6,
393 x7,
394 x8,
395 x9,
396 x10,
397 x11,
398 x12,
399 x13,
400 x14,
401 x15
402);
403simd_ty!(
404 u32x8[u32]: u32,
405 u32,
406 u32,
407 u32,
408 u32,
409 u32,
410 u32,
411 u32 | x0,
412 x1,
413 x2,
414 x3,
415 x4,
416 x5,
417 x6,
418 x7
419);
420simd_ty!(u64x4[u64]: u64, u64, u64, u64 | x0, x1, x2, x3);
421
422simd_ty!(
423 i8x32[i8]: i8,
424 i8,
425 i8,
426 i8,
427 i8,
428 i8,
429 i8,
430 i8,
431 i8,
432 i8,
433 i8,
434 i8,
435 i8,
436 i8,
437 i8,
438 i8,
439 i8,
440 i8,
441 i8,
442 i8,
443 i8,
444 i8,
445 i8,
446 i8,
447 i8,
448 i8,
449 i8,
450 i8,
451 i8,
452 i8,
453 i8,
454 i8 | x0,
455 x1,
456 x2,
457 x3,
458 x4,
459 x5,
460 x6,
461 x7,
462 x8,
463 x9,
464 x10,
465 x11,
466 x12,
467 x13,
468 x14,
469 x15,
470 x16,
471 x17,
472 x18,
473 x19,
474 x20,
475 x21,
476 x22,
477 x23,
478 x24,
479 x25,
480 x26,
481 x27,
482 x28,
483 x29,
484 x30,
485 x31
486);
487simd_ty!(
488 i16x16[i16]: i16,
489 i16,
490 i16,
491 i16,
492 i16,
493 i16,
494 i16,
495 i16,
496 i16,
497 i16,
498 i16,
499 i16,
500 i16,
501 i16,
502 i16,
503 i16 | x0,
504 x1,
505 x2,
506 x3,
507 x4,
508 x5,
509 x6,
510 x7,
511 x8,
512 x9,
513 x10,
514 x11,
515 x12,
516 x13,
517 x14,
518 x15
519);
520simd_ty!(
521 i32x8[i32]: i32,
522 i32,
523 i32,
524 i32,
525 i32,
526 i32,
527 i32,
528 i32 | x0,
529 x1,
530 x2,
531 x3,
532 x4,
533 x5,
534 x6,
535 x7
536);
537simd_ty!(i64x4[i64]: i64, i64, i64, i64 | x0, x1, x2, x3);
538
539simd_ty!(
540 f32x8[f32]: f32,
541 f32,
542 f32,
543 f32,
544 f32,
545 f32,
546 f32,
547 f32 | x0,
548 x1,
549 x2,
550 x3,
551 x4,
552 x5,
553 x6,
554 x7
555);
556
557// 512-bit wide types:
558
559simd_ty!(
560 i8x64[i8]: i8,
561 i8,
562 i8,
563 i8,
564 i8,
565 i8,
566 i8,
567 i8,
568 i8,
569 i8,
570 i8,
571 i8,
572 i8,
573 i8,
574 i8,
575 i8,
576 i8,
577 i8,
578 i8,
579 i8,
580 i8,
581 i8,
582 i8,
583 i8,
584 i8,
585 i8,
586 i8,
587 i8,
588 i8,
589 i8,
590 i8,
591 i8,
592 i8,
593 i8,
594 i8,
595 i8,
596 i8,
597 i8,
598 i8,
599 i8,
600 i8,
601 i8,
602 i8,
603 i8,
604 i8,
605 i8,
606 i8,
607 i8,
608 i8,
609 i8,
610 i8,
611 i8,
612 i8,
613 i8,
614 i8,
615 i8,
616 i8,
617 i8,
618 i8,
619 i8,
620 i8,
621 i8,
622 i8,
623 i8 | x0,
624 x1,
625 x2,
626 x3,
627 x4,
628 x5,
629 x6,
630 x7,
631 x8,
632 x9,
633 x10,
634 x11,
635 x12,
636 x13,
637 x14,
638 x15,
639 x16,
640 x17,
641 x18,
642 x19,
643 x20,
644 x21,
645 x22,
646 x23,
647 x24,
648 x25,
649 x26,
650 x27,
651 x28,
652 x29,
653 x30,
654 x31,
655 x32,
656 x33,
657 x34,
658 x35,
659 x36,
660 x37,
661 x38,
662 x39,
663 x40,
664 x41,
665 x42,
666 x43,
667 x44,
668 x45,
669 x46,
670 x47,
671 x48,
672 x49,
673 x50,
674 x51,
675 x52,
676 x53,
677 x54,
678 x55,
679 x56,
680 x57,
681 x58,
682 x59,
683 x60,
684 x61,
685 x62,
686 x63
687);
688
689simd_ty!(
690 u8x64[u8]: u8,
691 u8,
692 u8,
693 u8,
694 u8,
695 u8,
696 u8,
697 u8,
698 u8,
699 u8,
700 u8,
701 u8,
702 u8,
703 u8,
704 u8,
705 u8,
706 u8,
707 u8,
708 u8,
709 u8,
710 u8,
711 u8,
712 u8,
713 u8,
714 u8,
715 u8,
716 u8,
717 u8,
718 u8,
719 u8,
720 u8,
721 u8,
722 u8,
723 u8,
724 u8,
725 u8,
726 u8,
727 u8,
728 u8,
729 u8,
730 u8,
731 u8,
732 u8,
733 u8,
734 u8,
735 u8,
736 u8,
737 u8,
738 u8,
739 u8,
740 u8,
741 u8,
742 u8,
743 u8,
744 u8,
745 u8,
746 u8,
747 u8,
748 u8,
749 u8,
750 u8,
751 u8,
752 u8,
753 u8 | x0,
754 x1,
755 x2,
756 x3,
757 x4,
758 x5,
759 x6,
760 x7,
761 x8,
762 x9,
763 x10,
764 x11,
765 x12,
766 x13,
767 x14,
768 x15,
769 x16,
770 x17,
771 x18,
772 x19,
773 x20,
774 x21,
775 x22,
776 x23,
777 x24,
778 x25,
779 x26,
780 x27,
781 x28,
782 x29,
783 x30,
784 x31,
785 x32,
786 x33,
787 x34,
788 x35,
789 x36,
790 x37,
791 x38,
792 x39,
793 x40,
794 x41,
795 x42,
796 x43,
797 x44,
798 x45,
799 x46,
800 x47,
801 x48,
802 x49,
803 x50,
804 x51,
805 x52,
806 x53,
807 x54,
808 x55,
809 x56,
810 x57,
811 x58,
812 x59,
813 x60,
814 x61,
815 x62,
816 x63
817);
818
819simd_ty!(
820 i16x32[i16]: i16,
821 i16,
822 i16,
823 i16,
824 i16,
825 i16,
826 i16,
827 i16,
828 i16,
829 i16,
830 i16,
831 i16,
832 i16,
833 i16,
834 i16,
835 i16,
836 i16,
837 i16,
838 i16,
839 i16,
840 i16,
841 i16,
842 i16,
843 i16,
844 i16,
845 i16,
846 i16,
847 i16,
848 i16,
849 i16,
850 i16,
851 i16 | x0,
852 x1,
853 x2,
854 x3,
855 x4,
856 x5,
857 x6,
858 x7,
859 x8,
860 x9,
861 x10,
862 x11,
863 x12,
864 x13,
865 x14,
866 x15,
867 x16,
868 x17,
869 x18,
870 x19,
871 x20,
872 x21,
873 x22,
874 x23,
875 x24,
876 x25,
877 x26,
878 x27,
879 x28,
880 x29,
881 x30,
882 x31
883);
884
885simd_ty!(
886 u16x32[u16]: u16,
887 u16,
888 u16,
889 u16,
890 u16,
891 u16,
892 u16,
893 u16,
894 u16,
895 u16,
896 u16,
897 u16,
898 u16,
899 u16,
900 u16,
901 u16,
902 u16,
903 u16,
904 u16,
905 u16,
906 u16,
907 u16,
908 u16,
909 u16,
910 u16,
911 u16,
912 u16,
913 u16,
914 u16,
915 u16,
916 u16,
917 u16 | x0,
918 x1,
919 x2,
920 x3,
921 x4,
922 x5,
923 x6,
924 x7,
925 x8,
926 x9,
927 x10,
928 x11,
929 x12,
930 x13,
931 x14,
932 x15,
933 x16,
934 x17,
935 x18,
936 x19,
937 x20,
938 x21,
939 x22,
940 x23,
941 x24,
942 x25,
943 x26,
944 x27,
945 x28,
946 x29,
947 x30,
948 x31
949);
950
951simd_ty!(
952 i32x16[i32]: i32,
953 i32,
954 i32,
955 i32,
956 i32,
957 i32,
958 i32,
959 i32,
960 i32,
961 i32,
962 i32,
963 i32,
964 i32,
965 i32,
966 i32,
967 i32 | x0,
968 x1,
969 x2,
970 x3,
971 x4,
972 x5,
973 x6,
974 x7,
975 x8,
976 x9,
977 x10,
978 x11,
979 x12,
980 x13,
981 x14,
982 x15
983);
984
985simd_ty!(
986 u32x16[u32]: u32,
987 u32,
988 u32,
989 u32,
990 u32,
991 u32,
992 u32,
993 u32,
994 u32,
995 u32,
996 u32,
997 u32,
998 u32,
999 u32,
1000 u32,
1001 u32 | x0,
1002 x1,
1003 x2,
1004 x3,
1005 x4,
1006 x5,
1007 x6,
1008 x7,
1009 x8,
1010 x9,
1011 x10,
1012 x11,
1013 x12,
1014 x13,
1015 x14,
1016 x15
1017);
1018
1019simd_ty!(
1020 f32x16[f32]: f32,
1021 f32,
1022 f32,
1023 f32,
1024 f32,
1025 f32,
1026 f32,
1027 f32,
1028 f32,
1029 f32,
1030 f32,
1031 f32,
1032 f32,
1033 f32,
1034 f32,
1035 f32 | x0,
1036 x1,
1037 x2,
1038 x3,
1039 x4,
1040 x5,
1041 x6,
1042 x7,
1043 x8,
1044 x9,
1045 x10,
1046 x11,
1047 x12,
1048 x13,
1049 x14,
1050 x15
1051);
1052
1053simd_ty!(
1054 i64x8[i64]: i64,
1055 i64,
1056 i64,
1057 i64,
1058 i64,
1059 i64,
1060 i64,
1061 i64 | x0,
1062 x1,
1063 x2,
1064 x3,
1065 x4,
1066 x5,
1067 x6,
1068 x7
1069);
1070
1071simd_ty!(
1072 u64x8[u64]: u64,
1073 u64,
1074 u64,
1075 u64,
1076 u64,
1077 u64,
1078 u64,
1079 u64 | x0,
1080 x1,
1081 x2,
1082 x3,
1083 x4,
1084 x5,
1085 x6,
1086 x7
1087);
1088
1089simd_ty!(
1090 f64x8[f64]: f64,
1091 f64,
1092 f64,
1093 f64,
1094 f64,
1095 f64,
1096 f64,
1097 f64 | x0,
1098 x1,
1099 x2,
1100 x3,
1101 x4,
1102 x5,
1103 x6,
1104 x7
1105);
1106