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