Skip to main content

core/intrinsics/simd/
mod.rs

1//! SIMD compiler intrinsics.
2//!
3//! In this module, a "vector" is any `repr(simd)` type.
4
5pub mod scalable;
6
7use crate::marker::ConstParamTy;
8
9/// Inserts an element into a vector, returning the updated vector.
10///
11/// `T` must be a vector with element type `U`, and `idx` must be `const`.
12///
13/// # Safety
14///
15/// `idx` must be in-bounds of the vector.
16#[rustc_intrinsic]
17#[rustc_nounwind]
18pub const unsafe fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T;
19
20/// Extracts an element from a vector.
21///
22/// `T` must be a vector with element type `U`, and `idx` must be `const`.
23///
24/// # Safety
25///
26/// `idx` must be const and in-bounds of the vector.
27#[rustc_intrinsic]
28#[rustc_nounwind]
29pub const unsafe fn simd_extract<T, U>(x: T, idx: u32) -> U;
30
31/// Inserts an element into a vector, returning the updated vector.
32///
33/// `T` must be a vector with element type `U`.
34///
35/// If the index is `const`, [`simd_insert`] may emit better assembly.
36///
37/// # Safety
38///
39/// `idx` must be in-bounds of the vector.
40#[rustc_nounwind]
41#[rustc_intrinsic]
42pub const unsafe fn simd_insert_dyn<T, U>(x: T, idx: u32, val: U) -> T;
43
44/// Extracts an element from a vector.
45///
46/// `T` must be a vector with element type `U`.
47///
48/// If the index is `const`, [`simd_extract`] may emit better assembly.
49///
50/// # Safety
51///
52/// `idx` must be in-bounds of the vector.
53#[rustc_nounwind]
54#[rustc_intrinsic]
55pub const unsafe fn simd_extract_dyn<T, U>(x: T, idx: u32) -> U;
56
57/// Creates a vector where every lane has the provided value.
58///
59/// `T` must be a vector with element type `U`.
60#[rustc_nounwind]
61#[rustc_intrinsic]
62pub const unsafe fn simd_splat<T, U>(value: U) -> T;
63
64/// Adds two simd vectors elementwise.
65///
66/// `T` must be a vector of integers or floats.
67/// For integers, wrapping arithmetic is used.
68#[rustc_intrinsic]
69#[rustc_nounwind]
70pub const unsafe fn simd_add<T>(x: T, y: T) -> T;
71
72/// Subtracts `rhs` from `lhs` elementwise.
73///
74/// `T` must be a vector of integers or floats.
75/// For integers, wrapping arithmetic is used.
76#[rustc_intrinsic]
77#[rustc_nounwind]
78pub const unsafe fn simd_sub<T>(lhs: T, rhs: T) -> T;
79
80/// Multiplies two simd vectors elementwise.
81///
82/// `T` must be a vector of integers or floats.
83/// For integers, wrapping arithmetic is used.
84#[rustc_intrinsic]
85#[rustc_nounwind]
86pub const unsafe fn simd_mul<T>(x: T, y: T) -> T;
87
88/// Divides `lhs` by `rhs` elementwise.
89///
90/// `T` must be a vector of integers or floats.
91///
92/// # Safety
93/// For integers, `rhs` must not contain any zero elements.
94/// Additionally for signed integers, `<int>::MIN / -1` is undefined behavior.
95#[rustc_intrinsic]
96#[rustc_nounwind]
97pub const unsafe fn simd_div<T>(lhs: T, rhs: T) -> T;
98
99/// Returns remainder of two vectors elementwise.
100///
101/// `T` must be a vector of integers or floats.
102///
103/// # Safety
104/// For integers, `rhs` must not contain any zero elements.
105/// Additionally for signed integers, `<int>::MIN / -1` is undefined behavior.
106#[rustc_intrinsic]
107#[rustc_nounwind]
108pub const unsafe fn simd_rem<T>(lhs: T, rhs: T) -> T;
109
110/// Shifts vector left elementwise, with UB on overflow.
111///
112/// Shifts `lhs` left by `rhs`, shifting in sign bits for signed types.
113///
114/// `T` must be a vector of integers.
115///
116/// # Safety
117///
118/// Each element of `rhs` must be less than `<int>::BITS`.
119#[rustc_intrinsic]
120#[rustc_nounwind]
121pub const unsafe fn simd_shl<T>(lhs: T, rhs: T) -> T;
122
123/// Shifts vector right elementwise, with UB on overflow.
124///
125/// `T` must be a vector of integers.
126///
127/// Shifts `lhs` right by `rhs`, shifting in sign bits for signed types.
128///
129/// # Safety
130///
131/// Each element of `rhs` must be less than `<int>::BITS`.
132#[rustc_intrinsic]
133#[rustc_nounwind]
134pub const unsafe fn simd_shr<T>(lhs: T, rhs: T) -> T;
135
136/// Funnel Shifts vector left elementwise, with UB on overflow.
137///
138/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
139/// creating a vector of the same length, but with each element being twice as
140/// wide. Then shift this vector left elementwise by `shift`, shifting in zeros,
141/// and extract the most significant half of each of the elements. If `a` and `b`
142/// are the same, this is equivalent to an elementwise rotate left operation.
143///
144/// `T` must be a vector of integers.
145///
146/// # Safety
147///
148/// Each element of `shift` must be less than `<int>::BITS`.
149#[rustc_intrinsic]
150#[rustc_nounwind]
151pub const unsafe fn simd_funnel_shl<T>(a: T, b: T, shift: T) -> T;
152
153/// Funnel Shifts vector right elementwise, with UB on overflow.
154///
155/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
156/// creating a vector of the same length, but with each element being twice as
157/// wide. Then shift this vector right elementwise by `shift`, shifting in zeros,
158/// and extract the least significant half of each of the elements. If `a` and `b`
159/// are the same, this is equivalent to an elementwise rotate right operation.
160///
161/// `T` must be a vector of integers.
162///
163/// # Safety
164///
165/// Each element of `shift` must be less than `<int>::BITS`.
166#[rustc_intrinsic]
167#[rustc_nounwind]
168pub const unsafe fn simd_funnel_shr<T>(a: T, b: T, shift: T) -> T;
169
170/// Compute the carry-less product.
171///
172/// This is similar to long multiplication except that the carry is discarded.
173///
174/// This operation can be used to model multiplication in `GF(2)[X]`, the polynomial
175/// ring over `GF(2)`.
176///
177/// `T` must be a vector of integers.
178#[rustc_intrinsic]
179#[rustc_nounwind]
180pub unsafe fn simd_carryless_mul<T>(a: T, b: T) -> T;
181
182/// "And"s vectors elementwise.
183///
184/// `T` must be a vector of integers.
185#[rustc_intrinsic]
186#[rustc_nounwind]
187pub const unsafe fn simd_and<T>(x: T, y: T) -> T;
188
189/// "Ors" vectors elementwise.
190///
191/// `T` must be a vector of integers.
192#[rustc_intrinsic]
193#[rustc_nounwind]
194pub const unsafe fn simd_or<T>(x: T, y: T) -> T;
195
196/// "Exclusive ors" vectors elementwise.
197///
198/// `T` must be a vector of integers.
199#[rustc_intrinsic]
200#[rustc_nounwind]
201pub const unsafe fn simd_xor<T>(x: T, y: T) -> T;
202
203/// Numerically casts a vector, elementwise.
204///
205/// `T` and `U` must be vectors of integers or floats, and must have the same length.
206///
207/// When casting floats to integers, the result is truncated. Out-of-bounds result lead to UB.
208/// When casting integers to floats, the result is rounded.
209/// Otherwise, truncates or extends the value, maintaining the sign for signed integers.
210///
211/// # Safety
212/// Casting from integer types is always safe.
213/// Casting between two float types is also always safe.
214///
215/// Casting floats to integers truncates, following the same rules as `to_int_unchecked`.
216/// Specifically, each element must:
217/// * Not be `NaN`
218/// * Not be infinite
219/// * Be representable in the return type, after truncating off its fractional part
220#[rustc_intrinsic]
221#[rustc_nounwind]
222pub const unsafe fn simd_cast<T, U>(x: T) -> U;
223
224/// Numerically casts a vector, elementwise.
225///
226/// `T` and `U` be a vectors of integers or floats, and must have the same length.
227///
228/// Like `simd_cast`, but saturates float-to-integer conversions (NaN becomes 0).
229/// This matches regular `as` and is always safe.
230///
231/// When casting floats to integers, the result is truncated.
232/// When casting integers to floats, the result is rounded.
233/// Otherwise, truncates or extends the value, maintaining the sign for signed integers.
234#[rustc_intrinsic]
235#[rustc_nounwind]
236pub const unsafe fn simd_as<T, U>(x: T) -> U;
237
238/// Negates a vector elementwise.
239///
240/// `T` must be a vector of integers or floats.
241/// For integers, wrapping arithmetic is used.
242#[rustc_intrinsic]
243#[rustc_nounwind]
244pub const unsafe fn simd_neg<T>(x: T) -> T;
245
246/// Returns absolute value of a vector, elementwise.
247///
248/// `T` must be a vector of floating-point primitive types.
249#[rustc_intrinsic]
250#[rustc_nounwind]
251pub const unsafe fn simd_fabs<T>(x: T) -> T;
252
253/// Returns the minimum of two vectors, elementwise.
254///
255/// `T` must be a vector of floating-point primitive types.
256///
257/// This behaves like IEEE 754-2019 minimumNumber, *except* that it does not order signed
258/// zeros deterministically. In particular, for each vector lane:
259/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
260/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
261/// and `-0.0`), either input may be returned non-deterministically.
262#[rustc_intrinsic]
263#[rustc_nounwind]
264pub const unsafe fn simd_minimum_number_nsz<T>(x: T, y: T) -> T;
265
266/// Returns the maximum of two vectors, elementwise.
267///
268/// `T` must be a vector of floating-point primitive types.
269///
270/// This behaves like IEEE 754-2019 maximumNumber, *except* that it does not order signed
271/// zeros deterministically. In particular, for each vector lane:
272/// If one of the arguments is NaN (quiet or signaling), then the other argument is returned. If
273/// both arguments are NaN, returns NaN. If the inputs compare equal (such as for the case of `+0.0`
274/// and `-0.0`), either input may be returned non-deterministically.
275#[rustc_intrinsic]
276#[rustc_nounwind]
277pub const unsafe fn simd_maximum_number_nsz<T>(x: T, y: T) -> T;
278
279/// Tests elementwise equality of two vectors.
280///
281/// `T` must be a vector of integers or floats.
282///
283/// `U` must be a vector of integers with the same number of elements and element size as `T`.
284///
285/// Returns `0` for false and `!0` for true.
286#[rustc_intrinsic]
287#[rustc_nounwind]
288pub const unsafe fn simd_eq<T, U>(x: T, y: T) -> U;
289
290/// Tests elementwise inequality equality of two vectors.
291///
292/// `T` must be a vector of integers or floats.
293///
294/// `U` must be a vector of integers with the same number of elements and element size as `T`.
295///
296/// Returns `0` for false and `!0` for true.
297#[rustc_intrinsic]
298#[rustc_nounwind]
299pub const unsafe fn simd_ne<T, U>(x: T, y: T) -> U;
300
301/// Tests if `x` is less than `y`, elementwise.
302///
303/// `T` must be a vector of integers or floats.
304///
305/// `U` must be a vector of integers with the same number of elements and element size as `T`.
306///
307/// Returns `0` for false and `!0` for true.
308#[rustc_intrinsic]
309#[rustc_nounwind]
310pub const unsafe fn simd_lt<T, U>(x: T, y: T) -> U;
311
312/// Tests if `x` is less than or equal to `y`, elementwise.
313///
314/// `T` must be a vector of integers or floats.
315///
316/// `U` must be a vector of integers with the same number of elements and element size as `T`.
317///
318/// Returns `0` for false and `!0` for true.
319#[rustc_intrinsic]
320#[rustc_nounwind]
321pub const unsafe fn simd_le<T, U>(x: T, y: T) -> U;
322
323/// Tests if `x` is greater than `y`, elementwise.
324///
325/// `T` must be a vector of integers or floats.
326///
327/// `U` must be a vector of integers with the same number of elements and element size as `T`.
328///
329/// Returns `0` for false and `!0` for true.
330#[rustc_intrinsic]
331#[rustc_nounwind]
332pub const unsafe fn simd_gt<T, U>(x: T, y: T) -> U;
333
334/// Tests if `x` is greater than or equal to `y`, elementwise.
335///
336/// `T` must be a vector of integers or floats.
337///
338/// `U` must be a vector of integers with the same number of elements and element size as `T`.
339///
340/// Returns `0` for false and `!0` for true.
341#[rustc_intrinsic]
342#[rustc_nounwind]
343pub const unsafe fn simd_ge<T, U>(x: T, y: T) -> U;
344
345/// Shuffles two vectors by const indices.
346///
347/// `T` must be a vector.
348///
349/// `U` must be a **const** vector of `u32`s. This means it must either refer to a named
350/// const or be given as an inline const expression (`const { ... }`).
351///
352/// `V` must be a vector with the same element type as `T` and the same length as `U`.
353///
354/// Returns a new vector such that element `i` is selected from `xy[idx[i]]`, where `xy`
355/// is the concatenation of `x` and `y`. It is a compile-time error if `idx[i]` is out-of-bounds
356/// of `xy`.
357#[rustc_intrinsic]
358#[rustc_nounwind]
359pub const unsafe fn simd_shuffle<T, U, V>(x: T, y: T, idx: U) -> V;
360
361/// Reads a vector of pointers.
362///
363/// `T` must be a vector.
364///
365/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
366///
367/// `V` must be a vector of integers with the same length as `T` (but any element size).
368///
369/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
370/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
371/// `val`.
372///
373/// # Safety
374/// Unmasked values in `T` must be readable as if by `<ptr>::read` (e.g. aligned to the element
375/// type).
376///
377/// `mask` must only contain `0` or `!0` values.
378#[rustc_intrinsic]
379#[rustc_nounwind]
380pub const unsafe fn simd_gather<T, U, V>(val: T, ptr: U, mask: V) -> T;
381
382/// Writes to a vector of pointers.
383///
384/// `T` must be a vector.
385///
386/// `U` must be a vector of pointers to the element type of `T`, with the same length as `T`.
387///
388/// `V` must be a vector of integers with the same length as `T` (but any element size).
389///
390/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, write the
391/// corresponding value in `val` to the pointer.
392/// Otherwise if the corresponding value in `mask` is `0`, do nothing.
393///
394/// The stores happen in left-to-right order.
395/// (This is relevant in case two of the stores overlap.)
396///
397/// # Safety
398/// Unmasked values in `T` must be writeable as if by `<ptr>::write` (e.g. aligned to the element
399/// type).
400///
401/// `mask` must only contain `0` or `!0` values.
402#[rustc_intrinsic]
403#[rustc_nounwind]
404pub const unsafe fn simd_scatter<T, U, V>(val: T, ptr: U, mask: V);
405
406/// A type for alignment options for SIMD masked load/store intrinsics.
407#[derive(Debug, ConstParamTy, PartialEq, Eq)]
408pub enum SimdAlign {
409    // These values must match the compiler's `SimdAlign` defined in
410    // `rustc_middle/src/ty/consts/int.rs`!
411    /// No alignment requirements on the pointer
412    Unaligned = 0,
413    /// The pointer must be aligned to the element type of the SIMD vector
414    Element = 1,
415    /// The pointer must be aligned to the SIMD vector type
416    Vector = 2,
417}
418
419/// Reads a vector of pointers.
420///
421/// `T` must be a vector.
422///
423/// `U` must be a pointer to the element type of `T`
424///
425/// `V` must be a vector of integers with the same length as `T` (but any element size).
426///
427/// For each element, if the corresponding value in `mask` is `!0`, read the corresponding
428/// pointer offset from `ptr`.
429/// The first element is loaded from `ptr`, the second from `ptr.wrapping_offset(1)` and so on.
430/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
431/// `val`.
432///
433/// # Safety
434/// `ptr` must be aligned according to the `ALIGN` parameter, see [`SimdAlign`] for details.
435///
436/// `mask` must only contain `0` or `!0` values.
437#[rustc_intrinsic]
438#[rustc_nounwind]
439pub const unsafe fn simd_masked_load<V, U, T, const ALIGN: SimdAlign>(mask: V, ptr: U, val: T)
440-> T;
441
442/// Writes to a vector of pointers.
443///
444/// `T` must be a vector.
445///
446/// `U` must be a pointer to the element type of `T`
447///
448/// `V` must be a vector of integers with the same length as `T` (but any element size).
449///
450/// For each element, if the corresponding value in `mask` is `!0`, write the corresponding
451/// value in `val` to the pointer offset from `ptr`.
452/// The first element is written to `ptr`, the second to `ptr.wrapping_offset(1)` and so on.
453/// Otherwise if the corresponding value in `mask` is `0`, do nothing.
454///
455/// # Safety
456/// `ptr` must be aligned according to the `ALIGN` parameter, see [`SimdAlign`] for details.
457///
458/// `mask` must only contain `0` or `!0` values.
459#[rustc_intrinsic]
460#[rustc_nounwind]
461pub const unsafe fn simd_masked_store<V, U, T, const ALIGN: SimdAlign>(mask: V, ptr: U, val: T);
462
463/// Adds two simd vectors elementwise, with saturation.
464///
465/// `T` must be a vector of integer primitive types.
466#[rustc_intrinsic]
467#[rustc_nounwind]
468pub const unsafe fn simd_saturating_add<T>(x: T, y: T) -> T;
469
470/// Subtracts two simd vectors elementwise, with saturation.
471///
472/// `T` must be a vector of integer primitive types.
473///
474/// Subtract `rhs` from `lhs`.
475#[rustc_intrinsic]
476#[rustc_nounwind]
477pub const unsafe fn simd_saturating_sub<T>(lhs: T, rhs: T) -> T;
478
479/// Adds elements within a vector from left to right.
480///
481/// `T` must be a vector of integers or floats.
482///
483/// `U` must be the element type of `T`.
484///
485/// Starting with the value `y`, add the elements of `x` and accumulate.
486#[rustc_intrinsic]
487#[rustc_nounwind]
488pub const unsafe fn simd_reduce_add_ordered<T, U>(x: T, y: U) -> U;
489
490/// Adds elements within a vector in arbitrary order. May also be re-associated with
491/// unordered additions on the inputs/outputs.
492///
493/// `T` must be a vector of integers or floats.
494///
495/// `U` must be the element type of `T`.
496#[rustc_intrinsic]
497#[rustc_nounwind]
498pub unsafe fn simd_reduce_add_unordered<T, U>(x: T) -> U;
499
500/// Multiplies elements within a vector from left to right.
501///
502/// `T` must be a vector of integers or floats.
503///
504/// `U` must be the element type of `T`.
505///
506/// Starting with the value `y`, multiply the elements of `x` and accumulate.
507#[rustc_intrinsic]
508#[rustc_nounwind]
509pub const unsafe fn simd_reduce_mul_ordered<T, U>(x: T, y: U) -> U;
510
511/// Multiplies elements within a vector in arbitrary order. May also be re-associated with
512/// unordered additions on the inputs/outputs.
513///
514/// `T` must be a vector of integers or floats.
515///
516/// `U` must be the element type of `T`.
517#[rustc_intrinsic]
518#[rustc_nounwind]
519pub unsafe fn simd_reduce_mul_unordered<T, U>(x: T) -> U;
520
521/// Checks if all mask values are true.
522///
523/// `T` must be a vector of integer primitive types.
524///
525/// # Safety
526/// `x` must contain only `0` or `!0`.
527#[rustc_intrinsic]
528#[rustc_nounwind]
529pub const unsafe fn simd_reduce_all<T>(x: T) -> bool;
530
531/// Checks if any mask value is true.
532///
533/// `T` must be a vector of integer primitive types.
534///
535/// # Safety
536/// `x` must contain only `0` or `!0`.
537#[rustc_intrinsic]
538#[rustc_nounwind]
539pub const unsafe fn simd_reduce_any<T>(x: T) -> bool;
540
541/// Returns the maximum element of a vector.
542///
543/// `T` must be a vector of integers or floats.
544///
545/// `U` must be the element type of `T`.
546///
547/// For floating-point values, uses IEEE-754 `maxNum`.
548#[rustc_intrinsic]
549#[rustc_nounwind]
550pub const unsafe fn simd_reduce_max<T, U>(x: T) -> U;
551
552/// Returns the minimum element of a vector.
553///
554/// `T` must be a vector of integers or floats.
555///
556/// `U` must be the element type of `T`.
557///
558/// For floating-point values, uses IEEE-754 `minNum`.
559#[rustc_intrinsic]
560#[rustc_nounwind]
561pub const unsafe fn simd_reduce_min<T, U>(x: T) -> U;
562
563/// Logical "and"s all elements together.
564///
565/// `T` must be a vector of integers or floats.
566///
567/// `U` must be the element type of `T`.
568#[rustc_intrinsic]
569#[rustc_nounwind]
570pub const unsafe fn simd_reduce_and<T, U>(x: T) -> U;
571
572/// Logical "ors" all elements together.
573///
574/// `T` must be a vector of integers or floats.
575///
576/// `U` must be the element type of `T`.
577#[rustc_intrinsic]
578#[rustc_nounwind]
579pub const unsafe fn simd_reduce_or<T, U>(x: T) -> U;
580
581/// Logical "exclusive ors" all elements together.
582///
583/// `T` must be a vector of integers or floats.
584///
585/// `U` must be the element type of `T`.
586#[rustc_intrinsic]
587#[rustc_nounwind]
588pub const unsafe fn simd_reduce_xor<T, U>(x: T) -> U;
589
590/// Truncates an integer vector to a bitmask.
591///
592/// `T` must be an integer vector.
593///
594/// `U` must be either the smallest unsigned integer with at least as many bits as the length
595/// of `T`, or the smallest array of `u8` with at least as many bits as the length of `T`.
596///
597/// Each element is truncated to a single bit and packed into the result.
598///
599/// No matter whether the output is an array or an unsigned integer, it is treated as a single
600/// contiguous list of bits. The bitmask is always packed on the least-significant side of the
601/// output, and padded with 0s in the most-significant bits. The order of the bits depends on
602/// endianness:
603///
604/// * On little endian, the least significant bit corresponds to the first vector element.
605/// * On big endian, the least significant bit corresponds to the last vector element.
606///
607/// For example, `[!0, 0, !0, !0]` packs to
608/// - `0b1101u8` or `[0b1101]` on little endian, and
609/// - `0b1011u8` or `[0b1011]` on big endian.
610///
611/// To consider a larger example,
612/// `[!0, 0, 0, 0, 0, 0, 0, 0, !0, !0, 0, 0, 0, 0, !0, 0]` packs to
613/// - `0b0100001100000001u16` or `[0b00000001, 0b01000011]` on little endian, and
614/// - `0b1000000011000010u16` or `[0b10000000, 0b11000010]` on big endian.
615///
616/// And finally, a non-power-of-2 example with multiple bytes:
617/// `[!0, !0, 0, !0, 0, 0, !0, 0, !0, 0]` packs to
618/// - `0b0101001011u16` or `[0b01001011, 0b01]` on little endian, and
619/// - `0b1101001010u16` or `[0b11, 0b01001010]` on big endian.
620///
621/// # Safety
622/// `x` must contain only `0` and `!0`.
623#[rustc_intrinsic]
624#[rustc_nounwind]
625pub const unsafe fn simd_bitmask<T, U>(x: T) -> U;
626
627/// Selects elements from a mask.
628///
629/// `T` must be a vector.
630///
631/// `M` must be an integer vector with the same length as `T` (but any element size).
632///
633/// For each element, if the corresponding value in `mask` is `!0`, select the element from
634/// `if_true`.  If the corresponding value in `mask` is `0`, select the element from
635/// `if_false`.
636///
637/// # Safety
638/// `mask` must only contain `0` and `!0`.
639#[rustc_intrinsic]
640#[rustc_nounwind]
641pub const unsafe fn simd_select<M, T>(mask: M, if_true: T, if_false: T) -> T;
642
643/// Selects elements from a bitmask.
644///
645/// `M` must be an unsigned integer or array of `u8`, matching `simd_bitmask`.
646///
647/// `T` must be a vector.
648///
649/// For each element, if the bit in `mask` is `1`, select the element from
650/// `if_true`.  If the corresponding bit in `mask` is `0`, select the element from
651/// `if_false`.
652/// The remaining bits of the mask are ignored.
653///
654/// The bitmask bit order matches `simd_bitmask`.
655#[rustc_intrinsic]
656#[rustc_nounwind]
657pub const unsafe fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T;
658
659/// Calculates the offset from a pointer vector elementwise, potentially
660/// wrapping.
661///
662/// `T` must be a vector of pointers.
663///
664/// `U` must be a vector of `isize` or `usize` with the same number of elements as `T`.
665///
666/// Operates as if by `<ptr>::wrapping_offset`.
667#[rustc_intrinsic]
668#[rustc_nounwind]
669pub const unsafe fn simd_arith_offset<T, U>(ptr: T, offset: U) -> T;
670
671/// Casts a vector of pointers.
672///
673/// `T` and `U` must be vectors of pointers with the same number of elements.
674#[rustc_intrinsic]
675#[rustc_nounwind]
676pub const unsafe fn simd_cast_ptr<T, U>(ptr: T) -> U;
677
678/// Exposes a vector of pointers as a vector of addresses.
679///
680/// `T` must be a vector of pointers.
681///
682/// `U` must be a vector of `usize` with the same length as `T`.
683#[rustc_intrinsic]
684#[rustc_nounwind]
685pub unsafe fn simd_expose_provenance<T, U>(ptr: T) -> U;
686
687/// Creates a vector of pointers from a vector of addresses.
688///
689/// `T` must be a vector of `usize`.
690///
691/// `U` must be a vector of pointers, with the same length as `T`.
692#[rustc_intrinsic]
693#[rustc_nounwind]
694pub const unsafe fn simd_with_exposed_provenance<T, U>(addr: T) -> U;
695
696/// Swaps bytes of each element.
697///
698/// `T` must be a vector of integers.
699#[rustc_intrinsic]
700#[rustc_nounwind]
701pub const unsafe fn simd_bswap<T>(x: T) -> T;
702
703/// Reverses bits of each element.
704///
705/// `T` must be a vector of integers.
706#[rustc_intrinsic]
707#[rustc_nounwind]
708pub const unsafe fn simd_bitreverse<T>(x: T) -> T;
709
710/// Counts the leading zeros of each element.
711///
712/// `T` must be a vector of integers.
713#[rustc_intrinsic]
714#[rustc_nounwind]
715pub const unsafe fn simd_ctlz<T>(x: T) -> T;
716
717/// Counts the number of ones in each element.
718///
719/// `T` must be a vector of integers.
720#[rustc_intrinsic]
721#[rustc_nounwind]
722pub const unsafe fn simd_ctpop<T>(x: T) -> T;
723
724/// Counts the trailing zeros of each element.
725///
726/// `T` must be a vector of integers.
727#[rustc_intrinsic]
728#[rustc_nounwind]
729pub const unsafe fn simd_cttz<T>(x: T) -> T;
730
731/// Rounds up each element to the next highest integer-valued float.
732///
733/// `T` must be a vector of floats.
734#[rustc_intrinsic]
735#[rustc_nounwind]
736pub const unsafe fn simd_ceil<T>(x: T) -> T;
737
738/// Rounds down each element to the next lowest integer-valued float.
739///
740/// `T` must be a vector of floats.
741#[rustc_intrinsic]
742#[rustc_nounwind]
743pub const unsafe fn simd_floor<T>(x: T) -> T;
744
745/// Rounds each element to the closest integer-valued float.
746/// Ties are resolved by rounding away from 0.
747///
748/// `T` must be a vector of floats.
749#[rustc_intrinsic]
750#[rustc_nounwind]
751pub const unsafe fn simd_round<T>(x: T) -> T;
752
753/// Rounds each element to the closest integer-valued float.
754/// Ties are resolved by rounding to the number with an even least significant digit
755///
756/// `T` must be a vector of floats.
757#[rustc_intrinsic]
758#[rustc_nounwind]
759pub const unsafe fn simd_round_ties_even<T>(x: T) -> T;
760
761/// Returns the integer part of each element as an integer-valued float.
762/// In other words, non-integer values are truncated towards zero.
763///
764/// `T` must be a vector of floats.
765#[rustc_intrinsic]
766#[rustc_nounwind]
767pub const unsafe fn simd_trunc<T>(x: T) -> T;
768
769/// Takes the square root of each element.
770///
771/// `T` must be a vector of floats.
772#[rustc_intrinsic]
773#[rustc_nounwind]
774pub unsafe fn simd_fsqrt<T>(x: T) -> T;
775
776/// Computes `(x*y) + z` for each element, but without any intermediate rounding.
777///
778/// `T` must be a vector of floats.
779#[rustc_intrinsic]
780#[rustc_nounwind]
781pub const unsafe fn simd_fma<T>(x: T, y: T, z: T) -> T;
782
783/// Computes `(x*y) + z` for each element, non-deterministically executing either
784/// a fused multiply-add or two operations with rounding of the intermediate result.
785///
786/// The operation is fused if the code generator determines that target instruction
787/// set has support for a fused operation, and that the fused operation is more efficient
788/// than the equivalent, separate pair of mul and add instructions. It is unspecified
789/// whether or not a fused operation is selected, and that may depend on optimization
790/// level and context, for example. It may even be the case that some SIMD lanes get fused
791/// and others do not.
792///
793/// `T` must be a vector of floats.
794#[rustc_intrinsic]
795#[rustc_nounwind]
796pub const unsafe fn simd_relaxed_fma<T>(x: T, y: T, z: T) -> T;
797
798// Computes the sine of each element.
799///
800/// `T` must be a vector of floats.
801#[rustc_intrinsic]
802#[rustc_nounwind]
803pub unsafe fn simd_fsin<T>(a: T) -> T;
804
805// Computes the cosine of each element.
806///
807/// `T` must be a vector of floats.
808#[rustc_intrinsic]
809#[rustc_nounwind]
810pub unsafe fn simd_fcos<T>(a: T) -> T;
811
812// Computes the exponential function of each element.
813///
814/// `T` must be a vector of floats.
815#[rustc_intrinsic]
816#[rustc_nounwind]
817pub unsafe fn simd_fexp<T>(a: T) -> T;
818
819// Computes 2 raised to the power of each element.
820///
821/// `T` must be a vector of floats.
822#[rustc_intrinsic]
823#[rustc_nounwind]
824pub unsafe fn simd_fexp2<T>(a: T) -> T;
825
826// Computes the base 10 logarithm of each element.
827///
828/// `T` must be a vector of floats.
829#[rustc_intrinsic]
830#[rustc_nounwind]
831pub unsafe fn simd_flog10<T>(a: T) -> T;
832
833// Computes the base 2 logarithm of each element.
834///
835/// `T` must be a vector of floats.
836#[rustc_intrinsic]
837#[rustc_nounwind]
838pub unsafe fn simd_flog2<T>(a: T) -> T;
839
840// Computes the natural logarithm of each element.
841///
842/// `T` must be a vector of floats.
843#[rustc_intrinsic]
844#[rustc_nounwind]
845pub unsafe fn simd_flog<T>(a: T) -> T;