@@ -184,12 +184,15 @@ where
184
184
/// # Safety
185
185
/// Reading `ptr` must be safe, as if by `<*const [T; N]>::read_unaligned`.
186
186
const unsafe fn load ( ptr : * const [ T ; N ] ) -> Self {
187
- let mut tmp = core:: mem:: MaybeUninit :: uninit ( ) ;
187
+ // There are potentially simpler ways to write this function, but this should result in
188
+ // LLVM `load <N x T>`
189
+
190
+ let mut tmp = core:: mem:: MaybeUninit :: < Self > :: uninit ( ) ;
188
191
// SAFETY: `Simd<T, N>` always contains `N` elements of type `T`. It may have padding
189
192
// which does not need to be initialized. The safety of reading `ptr` is ensured by the
190
193
// caller.
191
194
unsafe {
192
- core:: ptr:: copy_nonoverlapping ( ptr, tmp. as_mut_ptr ( ) as * mut _ , 1 ) ;
195
+ core:: ptr:: copy_nonoverlapping ( ptr, tmp. as_mut_ptr ( ) . cast ( ) , 1 ) ;
193
196
tmp. assume_init ( )
194
197
}
195
198
}
@@ -201,9 +204,14 @@ where
201
204
/// # Safety
202
205
/// Writing to `ptr` must be safe, as if by `<*mut [T; N]>::write_unaligned`.
203
206
const unsafe fn store ( self , ptr : * mut [ T ; N ] ) {
207
+ // There are potentially simpler ways to write this function, but this should result in
208
+ // LLVM `store <N x T>`
209
+
210
+ // Creating a temporary helps LLVM turn the memcpy into a store.
211
+ let tmp = self ;
204
212
// SAFETY: `Simd<T, N>` always contains `N` elements of type `T`. The safety of writing
205
213
// `ptr` is ensured by the caller.
206
- unsafe { core:: ptr:: copy_nonoverlapping ( self . as_array ( ) , ptr, 1 ) }
214
+ unsafe { core:: ptr:: copy_nonoverlapping ( tmp . as_array ( ) , ptr, 1 ) }
207
215
}
208
216
209
217
/// Converts an array to a SIMD vector.
0 commit comments