Skip to content

Commit bef4c41

Browse files
committed
Add test examples
1 parent fd53445 commit bef4c41

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

crates/core_simd/src/vector.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ where
373373
/// # Safety
374374
///
375375
/// Each read must satisfy the same conditions as [`core::ptr::read`].
376+
///
377+
/// # Example
378+
/// ```
379+
/// # #![feature(portable_simd)]
380+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
381+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
382+
/// # use simd::{Simd, SimdConstPtr};
383+
/// let values = [6, 2, 4, 9];
384+
/// let offsets = Simd::from_array([1, 0, 0, 3]);
385+
/// let source = Simd::splat(values.as_ptr()).wrapping_add(offsets);
386+
/// let gathered = unsafe { Simd::gather_ptr(source) };
387+
/// assert_eq!(gathered, Simd::from_array([2, 6, 6, 9]));
388+
/// ```
376389
#[must_use]
377390
#[inline]
378391
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -392,6 +405,20 @@ where
392405
/// # Safety
393406
///
394407
/// Enabled lanes must satisfy the same conditions as [`core::ptr::read`].
408+
///
409+
/// # Example
410+
/// ```
411+
/// # #![feature(portable_simd)]
412+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
413+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
414+
/// # use simd::{Mask, Simd, SimdConstPtr};
415+
/// let values = [6, 2, 4, 9];
416+
/// let enable = Mask::from_array([true, true, false, true]);
417+
/// let offsets = Simd::from_array([1, 0, 0, 3]);
418+
/// let source = Simd::splat(values.as_ptr()).wrapping_add(offsets);
419+
/// let gathered = unsafe { Simd::gather_select_ptr(source, enable, Simd::splat(0)) };
420+
/// assert_eq!(gathered, Simd::from_array([2, 6, 0, 9]));
421+
/// ```
395422
#[must_use]
396423
#[inline]
397424
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
@@ -519,6 +546,19 @@ where
519546
/// # Safety
520547
///
521548
/// Each write must satisfy the same conditions as [`core::ptr::write`].
549+
///
550+
/// # Example
551+
/// ```
552+
/// # #![feature(portable_simd)]
553+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
554+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
555+
/// # use simd::{Simd, SimdMutPtr};
556+
/// let mut values = [0; 4];
557+
/// let offset = Simd::from_array([3, 2, 1, 0]);
558+
/// let ptrs = Simd::splat(values.as_mut_ptr()).wrapping_add(offset);
559+
/// unsafe { Simd::from_array([6, 3, 5, 7]).scatter_ptr(ptrs); }
560+
/// assert_eq!(values, [7, 5, 3, 6]);
561+
/// ```
522562
#[inline]
523563
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
524564
pub unsafe fn scatter_ptr(self, dest: Simd<*mut T, LANES>) {
@@ -533,6 +573,20 @@ where
533573
/// # Safety
534574
///
535575
/// Enabled lanes must satisfy the same conditions as [`core::ptr::write`].
576+
///
577+
/// # Example
578+
/// ```
579+
/// # #![feature(portable_simd)]
580+
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
581+
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
582+
/// # use simd::{Mask, Simd, SimdMutPtr};
583+
/// let mut values = [0; 4];
584+
/// let offset = Simd::from_array([3, 2, 1, 0]);
585+
/// let ptrs = Simd::splat(values.as_mut_ptr()).wrapping_add(offset);
586+
/// let enable = Mask::from_array([true, true, false, false]);
587+
/// unsafe { Simd::from_array([6, 3, 5, 7]).scatter_select_ptr(ptrs, enable); }
588+
/// assert_eq!(values, [0, 0, 3, 6]);
589+
/// ```
536590
#[inline]
537591
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
538592
pub unsafe fn scatter_select_ptr(self, dest: Simd<*mut T, LANES>, enable: Mask<isize, LANES>) {

0 commit comments

Comments
 (0)