2
2
3
3
#![ allow( non_camel_case_types) ]
4
4
5
+ trait SimdLookup < const N : usize > {
6
+ type Vector ;
7
+ }
8
+ macro_rules! as_signed {
9
+ ( i8 ) => { i8 } ;
10
+ ( i16 ) => { i16 } ;
11
+ ( i32 ) => { i32 } ;
12
+ ( i64 ) => { i64 } ;
13
+ ( i128 ) => { i128 } ;
14
+
15
+ ( u8 ) => { i8 } ;
16
+ ( u16 ) => { i16 } ;
17
+ ( u32 ) => { i32 } ;
18
+ ( u64 ) => { i64 } ;
19
+ ( u128 ) => { i128 } ;
20
+
21
+ ( f8) => { i8 } ;
22
+ ( f16) => { i16 } ;
23
+ ( f32 ) => { i32 } ;
24
+ ( f64 ) => { i64 } ;
25
+ ( f128) => { i128 } ;
26
+ }
27
+
5
28
macro_rules! simd_ty {
6
- ( $id: ident [ $elem_type: ty ; $len: literal] : $( $param_name: ident) ,* ) => {
29
+ ( $id: ident [ $elem_type: ident ; $len: literal] : $( $param_name: ident) ,* ) => {
7
30
#[ repr( simd) ]
8
31
#[ derive( Copy , Clone ) ]
9
32
pub ( crate ) struct $id( [ $elem_type; $len] ) ;
@@ -54,8 +77,13 @@ macro_rules! simd_ty {
54
77
}
55
78
56
79
impl core:: cmp:: PartialEq for $id {
80
+ #[ inline]
57
81
fn eq( & self , other: & Self ) -> bool {
58
- self . as_array( ) == other. as_array( )
82
+ type Mask = <as_signed!( $elem_type) as SimdLookup <$len>>:: Vector ;
83
+ unsafe {
84
+ let mask = core:: intrinsics:: simd:: simd_eq:: <Self , Mask >( * self , * other) ;
85
+ core:: intrinsics:: simd:: simd_reduce_all( mask)
86
+ }
59
87
}
60
88
}
61
89
@@ -65,6 +93,10 @@ macro_rules! simd_ty {
65
93
debug_simd_finish( f, stringify!( $id) , self . as_array( ) )
66
94
}
67
95
}
96
+
97
+ impl SimdLookup <$len> for $elem_type {
98
+ type Vector = $id;
99
+ }
68
100
}
69
101
}
70
102
@@ -110,8 +142,12 @@ macro_rules! simd_m_ty {
110
142
}
111
143
112
144
impl core:: cmp:: PartialEq for $id {
145
+ #[ inline]
113
146
fn eq( & self , other: & Self ) -> bool {
114
- self . as_array( ) == other. as_array( )
147
+ unsafe {
148
+ let mask = core:: intrinsics:: simd:: simd_eq:: <Self , Self >( * self , * other) ;
149
+ core:: intrinsics:: simd:: simd_reduce_all( mask)
150
+ }
115
151
}
116
152
}
117
153
@@ -865,6 +901,73 @@ simd_ty!(
865
901
) ;
866
902
867
903
// 1024-bit wide types:
904
+ simd_ty ! (
905
+ i16x64[ i16 ; 64 ] :
906
+ x0,
907
+ x1,
908
+ x2,
909
+ x3,
910
+ x4,
911
+ x5,
912
+ x6,
913
+ x7,
914
+ x8,
915
+ x9,
916
+ x10,
917
+ x11,
918
+ x12,
919
+ x13,
920
+ x14,
921
+ x15,
922
+ x16,
923
+ x17,
924
+ x18,
925
+ x19,
926
+ x20,
927
+ x21,
928
+ x22,
929
+ x23,
930
+ x24,
931
+ x25,
932
+ x26,
933
+ x27,
934
+ x28,
935
+ x29,
936
+ x30,
937
+ x31,
938
+ x32,
939
+ x33,
940
+ x34,
941
+ x35,
942
+ x36,
943
+ x37,
944
+ x38,
945
+ x39,
946
+ x40,
947
+ x41,
948
+ x42,
949
+ x43,
950
+ x44,
951
+ x45,
952
+ x46,
953
+ x47,
954
+ x48,
955
+ x49,
956
+ x50,
957
+ x51,
958
+ x52,
959
+ x53,
960
+ x54,
961
+ x55,
962
+ x56,
963
+ x57,
964
+ x58,
965
+ x59,
966
+ x60,
967
+ x61,
968
+ x62,
969
+ x63
970
+ ) ;
868
971
simd_ty ! (
869
972
u16x64[ u16 ; 64 ] :
870
973
x0,
0 commit comments