@@ -88,14 +88,15 @@ where
88
88
89
89
/// SIMD scatter: write a SIMD vector's values into a slice, using potentially discontiguous indices.
90
90
/// Out-of-bounds indices are not written.
91
+ /// `scatter` writes "in order", so if an index receives two writes, only the last is guaranteed.
91
92
/// ```
92
93
/// # use core_simd::*;
93
94
/// let mut vec: Vec<i32> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
94
- /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 5 ]);
95
- /// let vals = SimdI32::from_array([-5, -4 , -3, -2 ]);
95
+ /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 0 ]);
96
+ /// let vals = SimdI32::from_array([-27, 82 , -41, 124 ]);
96
97
///
97
- /// vals.scatter(&mut vec, idxs);
98
- /// assert_eq!(vec, vec![-3 , 11, 12, -4 , 14, -2 , 16, 17, 18]);
98
+ /// vals.scatter(&mut vec, idxs); // index 0 receives two writes.
99
+ /// assert_eq!(vec, vec![124 , 11, 12, 82 , 14, 15 , 16, 17, 18]);
99
100
/// ```
100
101
#[ inline]
101
102
fn scatter ( self , slice : & mut [ Self :: Scalar ] , idxs : SimdUsize < LANES > ) {
@@ -104,15 +105,16 @@ where
104
105
105
106
/// SIMD scatter: write a SIMD vector's values into a slice, using potentially discontiguous indices.
106
107
/// Out-of-bounds or masked indices are not written.
108
+ /// `scatter_select` writes "in order", so if an index receives two writes, only the last is guaranteed.
107
109
/// ```
108
110
/// # use core_simd::*;
109
111
/// let mut vec: Vec<i32> = vec![10, 11, 12, 13, 14, 15, 16, 17, 18];
110
- /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 5 ]);
111
- /// let vals = SimdI32::from_array([-5, -4 , -3, -2 ]);
112
+ /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 0 ]);
113
+ /// let vals = SimdI32::from_array([-27, 82 , -41, 124 ]);
112
114
/// let mask = MaskSize::from_array([true, true, true, false]); // Note the mask of the last lane.
113
115
///
114
- /// vals.scatter_select(&mut vec, mask, idxs);
115
- /// assert_eq!(vec, vec![-3 , 11, 12, -4 , 14, 15, 16, 17, 18]);
116
+ /// vals.scatter_select(&mut vec, mask, idxs); // index 0's second write is masked, thus omitted.
117
+ /// assert_eq!(vec, vec![-41 , 11, 12, 82 , 14, 15, 16, 17, 18]);
116
118
/// ```
117
119
#[ inline]
118
120
fn scatter_select (
0 commit comments