1010
1111#![ allow( unused) ]
1212#![ allow( non_camel_case_types) ]
13+ #![ allow( unexpected_cfgs) ]
14+
15+ #[ cfg_attr( minisimd_const, path = "minisimd_const_impls.rs" ) ]
16+ #[ cfg_attr( not( minisimd_const) , path = "minisimd_impls.rs" ) ]
17+ mod impls;
1318
1419// The field is currently left `pub` for convenience in porting tests, many of
1520// which attempt to just construct it directly. That still works; it's just the
@@ -24,39 +29,32 @@ impl<T: Copy, const N: usize> Clone for Simd<T, N> {
2429 }
2530}
2631
27- impl < T : PartialEq , const N : usize > PartialEq for Simd < T , N > {
28- fn eq ( & self , other : & Self ) -> bool {
29- self . as_array ( ) == other. as_array ( )
30- }
31- }
32-
3332impl < T : core:: fmt:: Debug , const N : usize > core:: fmt:: Debug for Simd < T , N > {
3433 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> Result < ( ) , core:: fmt:: Error > {
3534 <[ T ; N ] as core:: fmt:: Debug >:: fmt ( self . as_array ( ) , f)
3635 }
3736}
3837
39- impl < T , const N : usize > core:: ops:: Index < usize > for Simd < T , N > {
40- type Output = T ;
41- fn index ( & self , i : usize ) -> & T {
42- & self . as_array ( ) [ i]
43- }
44- }
45-
4638impl < T , const N : usize > Simd < T , N > {
4739 pub const fn from_array ( a : [ T ; N ] ) -> Self {
4840 Simd ( a)
4941 }
50- pub fn as_array ( & self ) -> & [ T ; N ] {
42+ pub const fn as_array ( & self ) -> & [ T ; N ] {
5143 let p: * const Self = self ;
5244 unsafe { & * p. cast :: < [ T ; N ] > ( ) }
5345 }
54- pub fn into_array ( self ) -> [ T ; N ]
46+ pub const fn into_array ( self ) -> [ T ; N ]
5547 where
5648 T : Copy ,
5749 {
5850 * self . as_array ( )
5951 }
52+ pub const fn splat ( a : T ) -> Self
53+ where
54+ T : Copy ,
55+ {
56+ Self ( [ a; N ] )
57+ }
6058}
6159
6260pub type u8x2 = Simd < u8 , 2 > ;
@@ -109,6 +107,14 @@ pub type i64x8 = Simd<i64, 8>;
109107pub type i128x2 = Simd < i128 , 2 > ;
110108pub type i128x4 = Simd < i128 , 4 > ;
111109
110+ pub type usizex2 = Simd < usize , 2 > ;
111+ pub type usizex4 = Simd < usize , 4 > ;
112+ pub type usizex8 = Simd < usize , 8 > ;
113+
114+ pub type isizex2 = Simd < isize , 2 > ;
115+ pub type isizex4 = Simd < isize , 4 > ;
116+ pub type isizex8 = Simd < isize , 8 > ;
117+
112118pub type f32x2 = Simd < f32 , 2 > ;
113119pub type f32x4 = Simd < f32 , 4 > ;
114120pub type f32x8 = Simd < f32 , 8 > ;
@@ -122,7 +128,7 @@ pub type f64x8 = Simd<f64, 8>;
122128// which attempt to just construct it directly. That still works; it's just the
123129// `.0` projection that doesn't.
124130#[ repr( simd, packed) ]
125- #[ derive( Copy ) ]
131+ #[ derive( Copy , Eq ) ]
126132pub struct PackedSimd < T , const N : usize > ( pub [ T ; N ] ) ;
127133
128134impl < T : Copy , const N : usize > Clone for PackedSimd < T , N > {
@@ -131,12 +137,6 @@ impl<T: Copy, const N: usize> Clone for PackedSimd<T, N> {
131137 }
132138}
133139
134- impl < T : PartialEq , const N : usize > PartialEq for PackedSimd < T , N > {
135- fn eq ( & self , other : & Self ) -> bool {
136- self . as_array ( ) == other. as_array ( )
137- }
138- }
139-
140140impl < T : core:: fmt:: Debug , const N : usize > core:: fmt:: Debug for PackedSimd < T , N > {
141141 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> Result < ( ) , core:: fmt:: Error > {
142142 <[ T ; N ] as core:: fmt:: Debug >:: fmt ( self . as_array ( ) , f)
@@ -147,14 +147,46 @@ impl<T, const N: usize> PackedSimd<T, N> {
147147 pub const fn from_array ( a : [ T ; N ] ) -> Self {
148148 PackedSimd ( a)
149149 }
150- pub fn as_array ( & self ) -> & [ T ; N ] {
150+ pub const fn as_array ( & self ) -> & [ T ; N ] {
151151 let p: * const Self = self ;
152152 unsafe { & * p. cast :: < [ T ; N ] > ( ) }
153153 }
154- pub fn into_array ( self ) -> [ T ; N ]
154+ pub const fn into_array ( self ) -> [ T ; N ]
155155 where
156156 T : Copy ,
157157 {
158158 * self . as_array ( )
159159 }
160+ pub const fn splat ( a : T ) -> Self
161+ where
162+ T : Copy ,
163+ {
164+ Self ( [ a; N ] )
165+ }
160166}
167+
168+ /// Version of `assert_eq` that ignores fancy runtime printing in const context
169+ #[ cfg( minisimd_const) ]
170+ #[ macro_export]
171+ macro_rules! assert_eq_const_safe {
172+ ( $left: expr, $right: expr $( , ) ?) => {
173+ assert_eq_const_safe!(
174+ $left,
175+ $right,
176+ concat!( "`" , stringify!( $left) , "` == `" , stringify!( $right) , "`" )
177+ ) ;
178+ } ;
179+ ( $left: expr, $right: expr$( , $( $arg: tt) +) ?) => {
180+ {
181+ let left = $left;
182+ let right = $right;
183+ // type inference works better with the concrete type on the
184+ // left, but humans work better with the expected on the
185+ // right
186+ assert!( right == left, $( $( $arg) * ) ,* ) ;
187+ }
188+ } ;
189+ }
190+
191+ #[ cfg( minisimd_const) ]
192+ use assert_eq_const_safe;
0 commit comments