Skip to content

Commit 1c3e1c8

Browse files
authored
Unrolled build for rust-lang#137828
Rollup merge of rust-lang#137828 - folkertdev:simd-intrinsic-doc-fixes, r=workingjubilee Fix inaccurate `std::intrinsics::simd` documentation This addresses two issues: - the docs on comparison operators (`simd_gt` etc.) said they only work for floating-point vectors, but they work for integer vectors too. - the docs on various functions that use a mask did not document that the mask must be a signed integer vector. Unsigned integer vectors would cause invalid behavior when the mask vector is widened (unsigned integers would use zero extension, producing incorrect results). r? ``@workingjubilee``
2 parents 351686b + 854e9f4 commit 1c3e1c8

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

library/core/src/intrinsics/simd.rs

+34-36
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ pub const unsafe fn simd_extract<T, U>(_x: T, _idx: u32) -> U;
2626

2727
/// Adds two simd vectors elementwise.
2828
///
29-
/// `T` must be a vector of integer or floating point primitive types.
29+
/// `T` must be a vector of integers or floats.
3030
#[rustc_intrinsic]
3131
#[rustc_nounwind]
3232
pub unsafe fn simd_add<T>(_x: T, _y: T) -> T;
3333

3434
/// Subtracts `rhs` from `lhs` elementwise.
3535
///
36-
/// `T` must be a vector of integer or floating point primitive types.
36+
/// `T` must be a vector of integers or floats.
3737
#[rustc_intrinsic]
3838
#[rustc_nounwind]
3939
pub unsafe fn simd_sub<T>(_lhs: T, _rhs: T) -> T;
4040

4141
/// Multiplies two simd vectors elementwise.
4242
///
43-
/// `T` must be a vector of integer or floating point primitive types.
43+
/// `T` must be a vector of integers or floats.
4444
#[rustc_intrinsic]
4545
#[rustc_nounwind]
4646
pub unsafe fn simd_mul<T>(_x: T, _y: T) -> T;
4747

4848
/// Divides `lhs` by `rhs` elementwise.
4949
///
50-
/// `T` must be a vector of integer or floating point primitive types.
50+
/// `T` must be a vector of integers or floats.
5151
///
5252
/// # Safety
5353
/// For integers, `rhs` must not contain any zero elements.
@@ -58,7 +58,7 @@ pub unsafe fn simd_div<T>(_lhs: T, _rhs: T) -> T;
5858

5959
/// Returns remainder of two vectors elementwise.
6060
///
61-
/// `T` must be a vector of integer or floating point primitive types.
61+
/// `T` must be a vector of integers or floats.
6262
///
6363
/// # Safety
6464
/// For integers, `rhs` must not contain any zero elements.
@@ -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,29 +95,28 @@ 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;
116116

117117
/// Numerically casts a vector, elementwise.
118118
///
119-
/// `T` and `U` must be vectors of integer or floating point primitive types, and must have the
120-
/// same length.
119+
/// `T` and `U` must be vectors of integers or floats, and must have the same length.
121120
///
122121
/// When casting floats to integers, the result is truncated. Out-of-bounds result lead to UB.
123122
/// When casting integers to floats, the result is rounded.
@@ -138,8 +137,7 @@ pub unsafe fn simd_cast<T, U>(_x: T) -> U;
138137

139138
/// Numerically casts a vector, elementwise.
140139
///
141-
/// `T` and `U` be a vectors of integer or floating point primitive types, and must have the
142-
/// same length.
140+
/// `T` and `U` be a vectors of integers or floats, and must have the same length.
143141
///
144142
/// Like `simd_cast`, but saturates float-to-integer conversions (NaN becomes 0).
145143
/// This matches regular `as` and is always safe.
@@ -153,7 +151,7 @@ pub unsafe fn simd_as<T, U>(_x: T) -> U;
153151

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

188186
/// Tests elementwise equality of two vectors.
189187
///
190-
/// `T` must be a vector of floating-point primitive types.
188+
/// `T` must be a vector of integers or floats.
191189
///
192190
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
193191
///
@@ -198,7 +196,7 @@ pub unsafe fn simd_eq<T, U>(_x: T, _y: T) -> U;
198196

199197
/// Tests elementwise inequality equality of two vectors.
200198
///
201-
/// `T` must be a vector of floating-point primitive types.
199+
/// `T` must be a vector of integers or floats.
202200
///
203201
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
204202
///
@@ -209,7 +207,7 @@ pub unsafe fn simd_ne<T, U>(_x: T, _y: T) -> U;
209207

210208
/// Tests if `x` is less than `y`, elementwise.
211209
///
212-
/// `T` must be a vector of floating-point primitive types.
210+
/// `T` must be a vector of integers or floats.
213211
///
214212
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
215213
///
@@ -220,7 +218,7 @@ pub unsafe fn simd_lt<T, U>(_x: T, _y: T) -> U;
220218

221219
/// Tests if `x` is less than or equal to `y`, elementwise.
222220
///
223-
/// `T` must be a vector of floating-point primitive types.
221+
/// `T` must be a vector of integers or floats.
224222
///
225223
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
226224
///
@@ -231,7 +229,7 @@ pub unsafe fn simd_le<T, U>(_x: T, _y: T) -> U;
231229

232230
/// Tests if `x` is greater than `y`, elementwise.
233231
///
234-
/// `T` must be a vector of floating-point primitive types.
232+
/// `T` must be a vector of integers or floats.
235233
///
236234
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
237235
///
@@ -242,7 +240,7 @@ pub unsafe fn simd_gt<T, U>(_x: T, _y: T) -> U;
242240

243241
/// Tests if `x` is greater than or equal to `y`, elementwise.
244242
///
245-
/// `T` must be a vector of floating-point primitive types.
243+
/// `T` must be a vector of integers or floats.
246244
///
247245
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
248246
///
@@ -273,7 +271,7 @@ pub unsafe fn simd_shuffle<T, U, V>(_x: T, _y: T, _idx: U) -> V;
273271
///
274272
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
275273
///
276-
/// `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).
277275
///
278276
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
279277
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
@@ -294,7 +292,7 @@ pub unsafe fn simd_gather<T, U, V>(_val: T, _ptr: U, _mask: V) -> T;
294292
///
295293
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
296294
///
297-
/// `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).
298296
///
299297
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
300298
/// corresponding value in `val` to the pointer.
@@ -318,7 +316,7 @@ pub unsafe fn simd_scatter<T, U, V>(_val: T, _ptr: U, _mask: V);
318316
///
319317
/// `U` must be a pointer to the element type of `T`
320318
///
321-
/// `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).
322320
///
323321
/// For each element, if the corresponding value in `mask` is `!0`, read the corresponding
324322
/// pointer offset from `ptr`.
@@ -341,7 +339,7 @@ pub unsafe fn simd_masked_load<V, U, T>(_mask: V, _ptr: U, _val: T) -> T;
341339
///
342340
/// `U` must be a pointer to the element type of `T`
343341
///
344-
/// `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).
345343
///
346344
/// For each element, if the corresponding value in `mask` is `!0`, write the corresponding
347345
/// value in `val` to the pointer offset from `ptr`.
@@ -375,7 +373,7 @@ pub unsafe fn simd_saturating_sub<T>(_lhs: T, _rhs: T) -> T;
375373

376374
/// Adds elements within a vector from left to right.
377375
///
378-
/// `T` must be a vector of integer or floating-point primitive types.
376+
/// `T` must be a vector of integers or floats.
379377
///
380378
/// `U` must be the element type of `T`.
381379
///
@@ -387,7 +385,7 @@ pub unsafe fn simd_reduce_add_ordered<T, U>(_x: T, _y: U) -> U;
387385
/// Adds elements within a vector in arbitrary order. May also be re-associated with
388386
/// unordered additions on the inputs/outputs.
389387
///
390-
/// `T` must be a vector of integer or floating-point primitive types.
388+
/// `T` must be a vector of integers or floats.
391389
///
392390
/// `U` must be the element type of `T`.
393391
#[rustc_intrinsic]
@@ -396,7 +394,7 @@ pub unsafe fn simd_reduce_add_unordered<T, U>(_x: T) -> U;
396394

397395
/// Multiplies elements within a vector from left to right.
398396
///
399-
/// `T` must be a vector of integer or floating-point primitive types.
397+
/// `T` must be a vector of integers or floats.
400398
///
401399
/// `U` must be the element type of `T`.
402400
///
@@ -408,7 +406,7 @@ pub unsafe fn simd_reduce_mul_ordered<T, U>(_x: T, _y: U) -> U;
408406
/// Multiplies elements within a vector in arbitrary order. May also be re-associated with
409407
/// unordered additions on the inputs/outputs.
410408
///
411-
/// `T` must be a vector of integer or floating-point primitive types.
409+
/// `T` must be a vector of integers or floats.
412410
///
413411
/// `U` must be the element type of `T`.
414412
#[rustc_intrinsic]
@@ -437,7 +435,7 @@ pub unsafe fn simd_reduce_any<T>(_x: T) -> bool;
437435

438436
/// Returns the maximum element of a vector.
439437
///
440-
/// `T` must be a vector of integer or floating-point primitive types.
438+
/// `T` must be a vector of integers or floats.
441439
///
442440
/// `U` must be the element type of `T`.
443441
///
@@ -448,7 +446,7 @@ pub unsafe fn simd_reduce_max<T, U>(_x: T) -> U;
448446

449447
/// Returns the minimum element of a vector.
450448
///
451-
/// `T` must be a vector of integer or floating-point primitive types.
449+
/// `T` must be a vector of integers or floats.
452450
///
453451
/// `U` must be the element type of `T`.
454452
///
@@ -459,7 +457,7 @@ pub unsafe fn simd_reduce_min<T, U>(_x: T) -> U;
459457

460458
/// Logical "ands" all elements together.
461459
///
462-
/// `T` must be a vector of integer or floating-point primitive types.
460+
/// `T` must be a vector of integers or floats.
463461
///
464462
/// `U` must be the element type of `T`.
465463
#[rustc_intrinsic]
@@ -468,7 +466,7 @@ pub unsafe fn simd_reduce_and<T, U>(_x: T) -> U;
468466

469467
/// Logical "ors" all elements together.
470468
///
471-
/// `T` must be a vector of integer or floating-point primitive types.
469+
/// `T` must be a vector of integers or floats.
472470
///
473471
/// `U` must be the element type of `T`.
474472
#[rustc_intrinsic]
@@ -477,7 +475,7 @@ pub unsafe fn simd_reduce_or<T, U>(_x: T) -> U;
477475

478476
/// Logical "exclusive ors" all elements together.
479477
///
480-
/// `T` must be a vector of integer or floating-point primitive types.
478+
/// `T` must be a vector of integers or floats.
481479
///
482480
/// `U` must be the element type of `T`.
483481
#[rustc_intrinsic]
@@ -523,9 +521,9 @@ pub unsafe fn simd_bitmask<T, U>(_x: T) -> U;
523521

524522
/// Selects elements from a mask.
525523
///
526-
/// `M` must be an integer vector.
524+
/// `T` must be a vector.
527525
///
528-
/// `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).
529527
///
530528
/// For each element, if the corresponding value in `mask` is `!0`, select the element from
531529
/// `if_true`. If the corresponding value in `mask` is `0`, select the element from

0 commit comments

Comments
 (0)