@@ -159,7 +159,7 @@ where
159
159
///
160
160
/// Panics if the slice's length is less than the vector's `Simd::LANES`.
161
161
///
162
- /// # Examples
162
+ /// # Example
163
163
///
164
164
/// ```
165
165
/// # #![feature(portable_simd)]
@@ -174,12 +174,43 @@ where
174
174
slice. len( ) >= LANES ,
175
175
"slice length must be at least the number of lanes"
176
176
) ;
177
+ assert ! ( core:: mem:: size_of:: <Self >( ) == LANES * core:: mem:: size_of:: <T >( ) ) ;
177
178
// Safety:
178
179
// - We've checked the length is sufficient.
179
180
// - `T` and `Simd<T, N>` are Copy types.
180
181
unsafe { slice. as_ptr ( ) . cast :: < Self > ( ) . read_unaligned ( ) }
181
182
}
182
183
184
+ /// Writes a SIMD vector to the first `LANES` elements of a slice.
185
+ ///
186
+ /// # Panics
187
+ ///
188
+ /// Panics if the slice's length is less than the vector's `Simd::LANES`.
189
+ ///
190
+ /// # Example
191
+ ///
192
+ /// ```
193
+ /// # #![feature(portable_simd)]
194
+ /// # #[cfg(feature = "as_crate")] use core_simd::simd;
195
+ /// # #[cfg(not(feature = "as_crate"))] use core::simd;
196
+ /// # use simd::u32x4;
197
+ /// let mut dest = vec![0; 6];
198
+ /// let v = u32x4::from_array([1, 2, 3, 4]);
199
+ /// v.copy_to_slice(&mut dest);
200
+ /// assert_eq!(&dest, &[1, 2, 3, 4, 0, 0]);
201
+ /// ```
202
+ pub fn copy_to_slice ( self , slice : & mut [ T ] ) {
203
+ assert ! (
204
+ slice. len( ) >= LANES ,
205
+ "slice length must be at least the number of lanes"
206
+ ) ;
207
+ assert ! ( core:: mem:: size_of:: <Self >( ) == LANES * core:: mem:: size_of:: <T >( ) ) ;
208
+ // Safety:
209
+ // - We've checked the length is sufficient
210
+ // - `T` and `Simd<T, N>` are Copy types.
211
+ unsafe { slice. as_mut_ptr ( ) . cast :: < Self > ( ) . write_unaligned ( self ) }
212
+ }
213
+
183
214
/// Performs lanewise conversion of a SIMD vector's elements to another SIMD-valid type.
184
215
///
185
216
/// This follows the semantics of Rust's `as` conversion for casting
0 commit comments