-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Implement Integer funnel shifts #145690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Implement Integer funnel shifts #145690
Changes from all commits
915048c
273d7fb
16220b2
23601d2
4e5a6d1
3cabdab
3e9b6bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2102,6 +2102,48 @@ pub const fn saturating_add<T: Copy>(a: T, b: T) -> T; | |
#[rustc_intrinsic] | ||
pub const fn saturating_sub<T: Copy>(a: T, b: T) -> T; | ||
|
||
/// Funnel Shift left. | ||
/// | ||
/// Concatenates `a` and `b` (with `a` in the most significant half), | ||
/// creating an integer twice as wide. Then shift this inetegr left | ||
/// by `shift` (taken modulo the bit size of `T`), and extract the | ||
/// most significant half. If `a` and `b` are the same, this is equivalent | ||
/// to a rotate left operation. | ||
/// | ||
/// Note that, unlike most intrinsics, this is safe to call; | ||
/// it does not require an `unsafe` block. | ||
/// Therefore, implementations must not require the user to uphold | ||
/// any safety invariants. | ||
/// | ||
/// Safer versions of this intrinsic are available on the integer primitives | ||
/// via the `funnel_shl` method. For example, [`u32::funnel_shl`]. | ||
#[rustc_intrinsic] | ||
#[rustc_nounwind] | ||
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] | ||
folkertdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[unstable(feature = "funnel_shifts", issue = "145686")] | ||
pub const fn funnel_shl<T: Copy>(a: T, b: T, shift: u32) -> T; | ||
|
||
/// Funnel Shift right. | ||
/// | ||
/// Concatenates `a` and `b` (with `a` in the most significant half), | ||
/// creating an integer twice as wide. Then shift this integer right | ||
/// by `shift` (taken modulo the bit size of `T`), and extract the | ||
/// least significant half. If `a` and `b` are the same, this is equivalent | ||
/// to a rotate right operation. | ||
/// | ||
/// Note that, unlike most intrinsics, this is safe to call; | ||
/// it does not require an `unsafe` block. | ||
/// Therefore, implementations must not require the user to uphold | ||
/// any safety invariants. | ||
Comment on lines
+2134
to
+2137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you update the comment/signature of the simd versions of this intrinsic to also reflect that it is safe to call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to do that? There are other backends where making such guarantees might require more effort. For scalars, it's quite easy, so we can make the guarantee |
||
/// | ||
/// Safer versions of this intrinsic are available on the integer primitives | ||
/// via the `funnel_shr` method. For example, [`u32::funnel_shr`] | ||
#[rustc_intrinsic] | ||
#[rustc_nounwind] | ||
#[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] | ||
#[unstable(feature = "funnel_shifts", issue = "145686")] | ||
pub const fn funnel_shr<T: Copy>(a: T, b: T, shift: u32) -> T; | ||
|
||
/// This is an implementation detail of [`crate::ptr::read`] and should | ||
/// not be used anywhere else. See its comments for why this exists. | ||
/// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
urem_imm
to avoid thewidth_bits = iconst(...)
. Also maybe preferband_imm
withwidth_bits - 1
as mask?