Skip to content

Commit 854e9f4

Browse files
committed
intrinsics::simd: document that masks must be signed integer vectors
this is because they may be widened, and that only works when sign extension is used: zero extension would produce invalid results
1 parent 4549266 commit 854e9f4

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Diff for: library/core/src/intrinsics/simd.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub unsafe fn simd_rem<T>(_lhs: T, _rhs: T) -> T;
7171
///
7272
/// Shifts `lhs` left by `rhs`, shifting in sign bits for signed types.
7373
///
74-
/// `T` must be a vector of integer primitive types.
74+
/// `T` must be a vector of integers.
7575
///
7676
/// # Safety
7777
///
@@ -82,7 +82,7 @@ pub unsafe fn simd_shl<T>(_lhs: T, _rhs: T) -> T;
8282

8383
/// Shifts vector right elementwise, with UB on overflow.
8484
///
85-
/// `T` must be a vector of integer primitive types.
85+
/// `T` must be a vector of integers.
8686
///
8787
/// Shifts `lhs` right by `rhs`, shifting in sign bits for signed types.
8888
///
@@ -95,21 +95,21 @@ pub unsafe fn simd_shr<T>(_lhs: T, _rhs: T) -> T;
9595

9696
/// "Ands" vectors elementwise.
9797
///
98-
/// `T` must be a vector of integer primitive types.
98+
/// `T` must be a vector of integers.
9999
#[rustc_intrinsic]
100100
#[rustc_nounwind]
101101
pub unsafe fn simd_and<T>(_x: T, _y: T) -> T;
102102

103103
/// "Ors" vectors elementwise.
104104
///
105-
/// `T` must be a vector of integer primitive types.
105+
/// `T` must be a vector of integers.
106106
#[rustc_intrinsic]
107107
#[rustc_nounwind]
108108
pub unsafe fn simd_or<T>(_x: T, _y: T) -> T;
109109

110110
/// "Exclusive ors" vectors elementwise.
111111
///
112-
/// `T` must be a vector of integer primitive types.
112+
/// `T` must be a vector of integers.
113113
#[rustc_intrinsic]
114114
#[rustc_nounwind]
115115
pub unsafe fn simd_xor<T>(_x: T, _y: T) -> T;
@@ -151,7 +151,7 @@ pub unsafe fn simd_as<T, U>(_x: T) -> U;
151151

152152
/// Negates a vector elementwise.
153153
///
154-
/// `T` must be a vector of integer or floating-point primitive types.
154+
/// `T` must be a vector of integers or floats.
155155
///
156156
/// Rust panics for `-<int>::Min` due to overflow, but it is not UB with this intrinsic.
157157
#[rustc_intrinsic]
@@ -185,7 +185,7 @@ pub unsafe fn simd_fmax<T>(_x: T, _y: T) -> T;
185185

186186
/// Tests elementwise equality of two vectors.
187187
///
188-
/// `T` must be a vector of integer or floating-point primitive types.
188+
/// `T` must be a vector of integers or floats.
189189
///
190190
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
191191
///
@@ -196,7 +196,7 @@ pub unsafe fn simd_eq<T, U>(_x: T, _y: T) -> U;
196196

197197
/// Tests elementwise inequality equality of two vectors.
198198
///
199-
/// `T` must be a vector of integer or floating-point primitive types.
199+
/// `T` must be a vector of integers or floats.
200200
///
201201
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
202202
///
@@ -207,7 +207,7 @@ pub unsafe fn simd_ne<T, U>(_x: T, _y: T) -> U;
207207

208208
/// Tests if `x` is less than `y`, elementwise.
209209
///
210-
/// `T` must be a vector of integer or floating-point primitive types.
210+
/// `T` must be a vector of integers or floats.
211211
///
212212
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
213213
///
@@ -218,7 +218,7 @@ pub unsafe fn simd_lt<T, U>(_x: T, _y: T) -> U;
218218

219219
/// Tests if `x` is less than or equal to `y`, elementwise.
220220
///
221-
/// `T` must be a vector of integer or floating-point primitive types.
221+
/// `T` must be a vector of integers or floats.
222222
///
223223
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
224224
///
@@ -229,7 +229,7 @@ pub unsafe fn simd_le<T, U>(_x: T, _y: T) -> U;
229229

230230
/// Tests if `x` is greater than `y`, elementwise.
231231
///
232-
/// `T` must be a vector of integer or floating-point primitive types.
232+
/// `T` must be a vector of integers or floats.
233233
///
234234
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
235235
///
@@ -240,7 +240,7 @@ pub unsafe fn simd_gt<T, U>(_x: T, _y: T) -> U;
240240

241241
/// Tests if `x` is greater than or equal to `y`, elementwise.
242242
///
243-
/// `T` must be a vector of integer or floating-point primitive types.
243+
/// `T` must be a vector of integers or floats.
244244
///
245245
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
246246
///
@@ -271,7 +271,7 @@ pub unsafe fn simd_shuffle<T, U, V>(_x: T, _y: T, _idx: U) -> V;
271271
///
272272
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
273273
///
274-
/// `V` must be a vector of integers with the same length as `T` (but any element size).
274+
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
275275
///
276276
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
277277
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
@@ -292,7 +292,7 @@ pub unsafe fn simd_gather<T, U, V>(_val: T, _ptr: U, _mask: V) -> T;
292292
///
293293
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
294294
///
295-
/// `V` must be a vector of integers with the same length as `T` (but any element size).
295+
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
296296
///
297297
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
298298
/// corresponding value in `val` to the pointer.
@@ -316,7 +316,7 @@ pub unsafe fn simd_scatter<T, U, V>(_val: T, _ptr: U, _mask: V);
316316
///
317317
/// `U` must be a pointer to the element type of `T`
318318
///
319-
/// `V` must be a vector of integers with the same length as `T` (but any element size).
319+
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
320320
///
321321
/// For each element, if the corresponding value in `mask` is `!0`, read the corresponding
322322
/// pointer offset from `ptr`.
@@ -339,7 +339,7 @@ pub unsafe fn simd_masked_load<V, U, T>(_mask: V, _ptr: U, _val: T) -> T;
339339
///
340340
/// `U` must be a pointer to the element type of `T`
341341
///
342-
/// `V` must be a vector of integers with the same length as `T` (but any element size).
342+
/// `V` must be a vector of signed integers with the same length as `T` (but any element size).
343343
///
344344
/// For each element, if the corresponding value in `mask` is `!0`, write the corresponding
345345
/// value in `val` to the pointer offset from `ptr`.
@@ -373,7 +373,7 @@ pub unsafe fn simd_saturating_sub<T>(_lhs: T, _rhs: T) -> T;
373373

374374
/// Adds elements within a vector from left to right.
375375
///
376-
/// `T` must be a vector of integer or floating-point primitive types.
376+
/// `T` must be a vector of integers or floats.
377377
///
378378
/// `U` must be the element type of `T`.
379379
///
@@ -385,7 +385,7 @@ pub unsafe fn simd_reduce_add_ordered<T, U>(_x: T, _y: U) -> U;
385385
/// Adds elements within a vector in arbitrary order. May also be re-associated with
386386
/// unordered additions on the inputs/outputs.
387387
///
388-
/// `T` must be a vector of integer or floating-point primitive types.
388+
/// `T` must be a vector of integers or floats.
389389
///
390390
/// `U` must be the element type of `T`.
391391
#[rustc_intrinsic]
@@ -394,7 +394,7 @@ pub unsafe fn simd_reduce_add_unordered<T, U>(_x: T) -> U;
394394

395395
/// Multiplies elements within a vector from left to right.
396396
///
397-
/// `T` must be a vector of integer or floating-point primitive types.
397+
/// `T` must be a vector of integers or floats.
398398
///
399399
/// `U` must be the element type of `T`.
400400
///
@@ -406,7 +406,7 @@ pub unsafe fn simd_reduce_mul_ordered<T, U>(_x: T, _y: U) -> U;
406406
/// Multiplies elements within a vector in arbitrary order. May also be re-associated with
407407
/// unordered additions on the inputs/outputs.
408408
///
409-
/// `T` must be a vector of integer or floating-point primitive types.
409+
/// `T` must be a vector of integers or floats.
410410
///
411411
/// `U` must be the element type of `T`.
412412
#[rustc_intrinsic]
@@ -435,7 +435,7 @@ pub unsafe fn simd_reduce_any<T>(_x: T) -> bool;
435435

436436
/// Returns the maximum element of a vector.
437437
///
438-
/// `T` must be a vector of integer or floating-point primitive types.
438+
/// `T` must be a vector of integers or floats.
439439
///
440440
/// `U` must be the element type of `T`.
441441
///
@@ -446,7 +446,7 @@ pub unsafe fn simd_reduce_max<T, U>(_x: T) -> U;
446446

447447
/// Returns the minimum element of a vector.
448448
///
449-
/// `T` must be a vector of integer or floating-point primitive types.
449+
/// `T` must be a vector of integers or floats.
450450
///
451451
/// `U` must be the element type of `T`.
452452
///
@@ -457,7 +457,7 @@ pub unsafe fn simd_reduce_min<T, U>(_x: T) -> U;
457457

458458
/// Logical "ands" all elements together.
459459
///
460-
/// `T` must be a vector of integer or floating-point primitive types.
460+
/// `T` must be a vector of integers or floats.
461461
///
462462
/// `U` must be the element type of `T`.
463463
#[rustc_intrinsic]
@@ -466,7 +466,7 @@ pub unsafe fn simd_reduce_and<T, U>(_x: T) -> U;
466466

467467
/// Logical "ors" all elements together.
468468
///
469-
/// `T` must be a vector of integer or floating-point primitive types.
469+
/// `T` must be a vector of integers or floats.
470470
///
471471
/// `U` must be the element type of `T`.
472472
#[rustc_intrinsic]
@@ -475,7 +475,7 @@ pub unsafe fn simd_reduce_or<T, U>(_x: T) -> U;
475475

476476
/// Logical "exclusive ors" all elements together.
477477
///
478-
/// `T` must be a vector of integer or floating-point primitive types.
478+
/// `T` must be a vector of integers or floats.
479479
///
480480
/// `U` must be the element type of `T`.
481481
#[rustc_intrinsic]
@@ -521,9 +521,9 @@ pub unsafe fn simd_bitmask<T, U>(_x: T) -> U;
521521

522522
/// Selects elements from a mask.
523523
///
524-
/// `M` must be an integer vector.
524+
/// `T` must be a vector.
525525
///
526-
/// `T` must be a vector with the same number of elements as `M`.
526+
/// `M` must be a signed integer vector with the same length as `T` (but any element size).
527527
///
528528
/// For each element, if the corresponding value in `mask` is `!0`, select the element from
529529
/// `if_true`. If the corresponding value in `mask` is `0`, select the element from

0 commit comments

Comments
 (0)