Skip to content

Commit 22f684c

Browse files
Rollup merge of rust-lang#142078 - sayantn:more-intrinsics, r=workingjubilee
Add SIMD funnel shift and round-to-even intrinsics This PR adds 3 new SIMD intrinsics - `simd_funnel_shl` - funnel shift left - `simd_funnel_shr` - funnel shift right - `simd_round_ties_even` (vector version of `round_ties_even_fN`) TODO (future PR): implement `simd_fsh{l,r}` in miri, cg_gcc and cg_clif (it is surprisingly hard to implement without branches, the common tricks that rotate uses doesn't work because we have 2 elements now. e.g, the `-n&31` trick used by cg_gcc to implement rotate doesn't work with this because then `fshl(a, b, 0)` will be `a | b`) [#t-compiler > More SIMD intrinsics](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/More.20SIMD.20intrinsics/with/522130286) `@rustbot` label T-compiler T-libs A-intrinsics F-core_intrinsics r? `@workingjubilee`
2 parents 93fbfe3 + e14b4ef commit 22f684c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

core/src/intrinsics/simd.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,40 @@ pub unsafe fn simd_shl<T>(lhs: T, rhs: T) -> T;
126126
#[rustc_nounwind]
127127
pub unsafe fn simd_shr<T>(lhs: T, rhs: T) -> T;
128128

129+
/// Funnel Shifts vector left elementwise, with UB on overflow.
130+
///
131+
/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
132+
/// creating a vector of the same length, but with each element being twice as
133+
/// wide. Then shift this vector left elementwise by `shift`, shifting in zeros,
134+
/// and extract the most significant half of each of the elements. If `a` and `b`
135+
/// are the same, this is equivalent to an elementwise rotate left operation.
136+
///
137+
/// `T` must be a vector of integers.
138+
///
139+
/// # Safety
140+
///
141+
/// Each element of `shift` must be less than `<int>::BITS`.
142+
#[rustc_intrinsic]
143+
#[rustc_nounwind]
144+
pub unsafe fn simd_funnel_shl<T>(a: T, b: T, shift: T) -> T;
145+
146+
/// Funnel Shifts vector right elementwise, with UB on overflow.
147+
///
148+
/// Concatenates `a` and `b` elementwise (with `a` in the most significant half),
149+
/// creating a vector of the same length, but with each element being twice as
150+
/// wide. Then shift this vector right elementwise by `shift`, shifting in zeros,
151+
/// and extract the least significant half of each of the elements. If `a` and `b`
152+
/// are the same, this is equivalent to an elementwise rotate right operation.
153+
///
154+
/// `T` must be a vector of integers.
155+
///
156+
/// # Safety
157+
///
158+
/// Each element of `shift` must be less than `<int>::BITS`.
159+
#[rustc_intrinsic]
160+
#[rustc_nounwind]
161+
pub unsafe fn simd_funnel_shr<T>(a: T, b: T, shift: T) -> T;
162+
129163
/// "Ands" vectors elementwise.
130164
///
131165
/// `T` must be a vector of integers.
@@ -678,6 +712,14 @@ pub unsafe fn simd_floor<T>(x: T) -> T;
678712
#[rustc_nounwind]
679713
pub unsafe fn simd_round<T>(x: T) -> T;
680714

715+
/// Rounds each element to the closest integer-valued float.
716+
/// Ties are resolved by rounding to the number with an even least significant digit
717+
///
718+
/// `T` must be a vector of floats.
719+
#[rustc_intrinsic]
720+
#[rustc_nounwind]
721+
pub unsafe fn simd_round_ties_even<T>(x: T) -> T;
722+
681723
/// Returns the integer part of each element as an integer-valued float.
682724
/// In other words, non-integer values are truncated towards zero.
683725
///

0 commit comments

Comments
 (0)