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