Skip to content

Commit 560ac23

Browse files
committed
State type requirements first
1 parent 1fd7de0 commit 560ac23

File tree

1 file changed

+62
-61
lines changed

1 file changed

+62
-61
lines changed

library/core/src/intrinsics/simd.rs

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ extern "platform-intrinsic" {
4949

5050
/// Elementwise vector right shift, with UB on overflow.
5151
///
52-
/// Shift `lhs` right by `rhs`, shifting in sign bits for signed types.
53-
///
5452
/// `T` must be a vector of integer primitive types.
5553
///
54+
/// Shift `lhs` right by `rhs`, shifting in sign bits for signed types.
55+
///
5656
/// # Safety
5757
///
5858
/// Each element of `rhs` must be less than `<int>::BITS`.
@@ -75,35 +75,35 @@ extern "platform-intrinsic" {
7575

7676
/// Numerically cast a vector, elementwise.
7777
///
78+
/// `T` and `U` must be vectors of integer or floating point primitive types, and must have the
79+
/// same length.
80+
///
7881
/// When casting floats to integers, the result is truncated. Out-of-bounds result lead to UB.
7982
/// When casting integers to floats, the result is rounded.
8083
/// Otherwise, truncates or extends the value, maintaining the sign for signed integers.
8184
///
82-
/// `T` and `U` must be vectors of integer or floating point primitive types, and must have the
83-
/// same length.
84-
///
8585
/// # Safety
8686
/// Casting floats to integers truncates, but the truncated value must fit in the target type.
8787
pub fn simd_cast<T, U>(x: T) -> U;
8888

8989
/// Numerically cast a vector, elementwise.
9090
///
91+
/// `T` and `U` be a vectors of integer or floating point primitive types, and must have the
92+
/// same length.
93+
///
9194
/// Like `simd_cast`, but saturates float-to-integer conversions.
9295
/// This matches regular `as` and is always safe.
9396
///
9497
/// When casting floats to integers, the result is truncated.
9598
/// When casting integers to floats, the result is rounded.
9699
/// Otherwise, truncates or extends the value, maintaining the sign for signed integers.
97-
///
98-
/// `T` and `U` be a vectors of integer or floating point primitive types, and must have the
99-
/// same length.
100100
pub fn simd_as<T, U>(x: T) -> U;
101101

102102
/// Elementwise negation of a vector.
103103
///
104-
/// Rust panics for `-<int>::Min` due to overflow, but it is not UB with this intrinsic.
105-
///
106104
/// `T` must be a vector of integer or floating-point primitive types.
105+
///
106+
/// Rust panics for `-<int>::Min` due to overflow, but it is not UB with this intrinsic.
107107
pub fn simd_neg<T>(x: T) -> T;
108108

109109
/// Elementwise absolute value of a vector.
@@ -113,95 +113,96 @@ extern "platform-intrinsic" {
113113

114114
/// Elementwise minimum of a vector.
115115
///
116-
/// Follows IEEE-754 `minNum` semantics.
117-
///
118116
/// `T` must be a vector of floating-point primitive types.
117+
///
118+
/// Follows IEEE-754 `minNum` semantics.
119119
pub fn simd_fmin<T>(x: T, y: T) -> T;
120120

121121
/// Elementwise maximum of a vector.
122122
///
123-
/// Follows IEEE-754 `maxNum` semantics.
124-
///
125123
/// `T` must be a vector of floating-point primitive types.
124+
///
125+
/// Follows IEEE-754 `maxNum` semantics.
126126
pub fn simd_fmax<T>(x: T, y: T) -> T;
127127

128128
/// Tests elementwise equality of two vectors.
129129
///
130-
/// Returns `0` for false and `!0` for true.
131-
///
132130
/// `T` must be a vector of floating-point primitive types.
131+
///
133132
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
133+
///
134+
/// Returns `0` for false and `!0` for true.
134135
pub fn simd_eq<T, U>(x: T, y: T) -> U;
135136

136137
/// Tests elementwise inequality equality of two vectors.
137138
///
138-
/// Returns `0` for false and `!0` for true.
139-
///
140139
/// `T` must be a vector of floating-point primitive types.
141140
///
142141
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
142+
///
143+
/// Returns `0` for false and `!0` for true.
143144
pub fn simd_ne<T, U>(x: T, y: T) -> U;
144145

145146
/// Tests if `x` is less than `y`, elementwise.
146147
///
147-
/// Returns `0` for false and `!0` for true.
148-
///
149148
/// `T` must be a vector of floating-point primitive types.
150149
///
151150
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
151+
///
152+
/// Returns `0` for false and `!0` for true.
152153
pub fn simd_lt<T, U>(x: T, y: T) -> U;
153154

154155
/// Tests if `x` is less than or equal to `y`, elementwise.
155156
///
156-
/// Returns `0` for false and `!0` for true.
157-
///
158157
/// `T` must be a vector of floating-point primitive types.
159158
///
160159
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
160+
///
161+
/// Returns `0` for false and `!0` for true.
161162
pub fn simd_le<T, U>(x: T, y: T) -> U;
162163

163164
/// Tests if `x` is greater than `y`, elementwise.
164165
///
165-
/// Returns `0` for false and `!0` for true.
166-
///
167166
/// `T` must be a vector of floating-point primitive types.
168167
///
169168
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
169+
///
170+
/// Returns `0` for false and `!0` for true.
170171
pub fn simd_gt<T, U>(x: T, y: T) -> U;
171172

172173
/// Tests if `x` is greater than or equal to `y`, elementwise.
173174
///
174-
/// Returns `0` for false and `!0` for true.
175-
///
176175
/// `T` must be a vector of floating-point primitive types.
177176
///
178177
/// `U` must be a vector of integers with the same number of elements and element size as `T`.
178+
///
179+
/// Returns `0` for false and `!0` for true.
179180
pub fn simd_ge<T, U>(x: T, y: T) -> U;
180181

181182
/// Shuffle two vectors by const indices.
182183
///
183-
/// Concatenates `x` and `y`, then returns a new vector such that each element is selected from
184-
/// the concatenation by the matching index in `idx`.
185-
///
186184
/// `T` must be a vector.
187185
///
188186
/// `U` must be a const array of `i32`s.
189187
///
190188
/// `V` must be a vector with the same element type as `T` and the same length as `U`.
189+
///
190+
/// Concatenates `x` and `y`, then returns a new vector such that each element is selected from
191+
/// the concatenation by the matching index in `idx`.
191192
pub fn simd_shuffle<T, U, V>(x: T, y: T, idx: U) -> V;
192193

193194
/// Read a vector of pointers.
194195
///
195-
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
196-
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
197-
/// `val`.
198-
///
199196
/// `T` must be a vector.
200197
///
201198
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
202199
///
203200
/// `V` must be a vector of integers with the same length as `T` (but any element size).
204201
///
202+
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
203+
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
204+
/// `val`.
205+
///
205206
/// # Safety
206207
/// Unmasked values in `T` must be readable as if by `<ptr>::read` (e.g. aligned to the element
207208
/// type).
@@ -211,16 +212,16 @@ extern "platform-intrinsic" {
211212

212213
/// Write to a vector of pointers.
213214
///
214-
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
215-
/// corresponding value in `val` to the pointer.
216-
/// Otherwise if the corresponding value in `mask` is `0`, do nothing.
217-
///
218215
/// `T` must be a vector.
219216
///
220217
/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
221218
///
222219
/// `V` must be a vector of integers with the same length as `T` (but any element size).
223220
///
221+
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
222+
/// corresponding value in `val` to the pointer.
223+
/// Otherwise if the corresponding value in `mask` is `0`, do nothing.
224+
///
224225
/// # Safety
225226
/// Unmasked values in `T` must be writeable as if by `<ptr>::write` (e.g. aligned to the element
226227
/// type).
@@ -235,27 +236,27 @@ extern "platform-intrinsic" {
235236

236237
/// Subtract two simd vectors elementwise, with saturation.
237238
///
238-
/// Subtract `rhs` from `lhs`.
239-
///
240239
/// `T` must be a vector of integer primitive types.
240+
///
241+
/// Subtract `rhs` from `lhs`.
241242
pub fn simd_saturating_sub<T>(lhs: T, rhs: T) -> T;
242243

243244
/// Add elements within a vector from left to right.
244245
///
245-
/// Starting with the value `y`, add the elements of `x` and accumulate.
246-
///
247246
/// `T` must be a vector of integer or floating-point primitive types.
248247
///
249248
/// `U` must be the element type of `T`.
249+
///
250+
/// Starting with the value `y`, add the elements of `x` and accumulate.
250251
pub fn simd_reduce_add_ordered<T, U>(x: T, y: U) -> U;
251252

252253
/// Multiply elements within a vector from left to right.
253254
///
254-
/// Starting with the value `y`, multiply the elements of `x` and accumulate.
255-
///
256255
/// `T` must be a vector of integer or floating-point primitive types.
257256
///
258257
/// `U` must be the element type of `T`.
258+
///
259+
/// Starting with the value `y`, multiply the elements of `x` and accumulate.
259260
pub fn simd_reduce_mul_ordered<T, U>(x: T, y: U) -> U;
260261

261262
/// Check if all mask values are true.
@@ -276,20 +277,20 @@ extern "platform-intrinsic" {
276277

277278
/// Return the maximum element of a vector.
278279
///
279-
/// For floating-point values, uses IEEE-754 `maxNum`.
280-
///
281280
/// `T` must be a vector of integer or floating-point primitive types.
282281
///
283282
/// `U` must be the element type of `T`.
283+
///
284+
/// For floating-point values, uses IEEE-754 `maxNum`.
284285
pub fn simd_reduce_max<T, U>(x: T) -> U;
285286

286287
/// Return the minimum element of a vector.
287288
///
288-
/// For floating-point values, uses IEEE-754 `minNum`.
289-
///
290289
/// `T` must be a vector of integer or floating-point primitive types.
291290
///
292291
/// `U` must be the element type of `T`.
292+
///
293+
/// For floating-point values, uses IEEE-754 `minNum`.
293294
pub fn simd_reduce_min<T, U>(x: T) -> U;
294295

295296
/// Logical "and" all elements together.
@@ -315,17 +316,17 @@ extern "platform-intrinsic" {
315316

316317
/// Truncate an integer vector to a bitmask.
317318
///
319+
/// `T` must be an integer vector.
320+
///
321+
/// `U` must be either the smallest unsigned integer with at least as many bits as the length
322+
///
318323
/// Each element is truncated to a single bit and packed into the result.
319324
///
320325
/// The bit order depends on the byte endianness.
321326
/// The bitmask is always packed into the smallest/first bits, but the order is LSB-first for
322327
/// little endian and MSB-first for big endian.
323328
/// In other words, the LSB corresponds to the first vector element for little endian,
324329
/// and the last vector element for big endian.
325-
///
326-
/// `T` must be an integer vector.
327-
///
328-
/// `U` must be either the smallest unsigned integer with at least as many bits as the length
329330
/// of `T`, or the smallest array of `u8` with as many bits as the length of `T`.
330331
///
331332
/// # Safety
@@ -334,41 +335,41 @@ extern "platform-intrinsic" {
334335

335336
/// Select elements from a mask.
336337
///
337-
/// For each element, if the corresponding value in `mask` is `!0`, select the element from
338-
/// `if_true`. If the corresponding value in `mask` is `0`, select the element from
339-
/// `if_false`.
340-
///
341338
/// `M` must be an integer vector.
342339
///
343340
/// `T` must be a vector with the same number of elements as `M`.
344341
///
342+
/// For each element, if the corresponding value in `mask` is `!0`, select the element from
343+
/// `if_true`. If the corresponding value in `mask` is `0`, select the element from
344+
/// `if_false`.
345+
///
345346
/// # Safety
346347
/// `mask` must only contain `0` and `!0`.
347348
pub fn simd_select<M, T>(mask: M, if_true: T, if_false: T) -> T;
348349

349350
/// Select elements from a bitmask.
350351
///
352+
/// `M` must be an unsigned integer of type matching `simd_bitmask`.
353+
///
354+
/// `T` must be a vector.
355+
///
351356
/// For each element, if the bit in `mask` is `1`, select the element from
352357
/// `if_true`. If the corresponding bit in `mask` is `0`, select the element from
353358
/// `if_false`.
354359
///
355360
/// The bitmask bit order matches `simd_bitmask`.
356361
///
357-
/// `M` must be an unsigned integer of type matching `simd_bitmask`.
358-
///
359-
/// `T` must be a vector.
360-
///
361362
/// # Safety
362363
/// `mask` must only contain `0` and `!0`.
363364
pub fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T;
364365

365366
/// Elementwise calculates the offset from a pointer vector, potentially wrapping.
366367
///
367-
/// Operates as if by `<ptr>::wrapping_offset`.
368-
///
369368
/// `T` must be a vector of pointers.
370369
///
371370
/// `U` must be a vector of `isize` or `usize` with the same number of elements as `T`.
371+
///
372+
/// Operates as if by `<ptr>::wrapping_offset`.
372373
pub fn simd_arith_offset<T, U>(ptr: T, offset: U) -> T;
373374

374375
/// Cast a vector of pointers.

0 commit comments

Comments
 (0)