-
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
Conversation
This comment has been minimized.
This comment has been minimized.
/// 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. |
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.
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 comment
The 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
library/core/src/intrinsics/mod.rs
Outdated
/// creating an integer twice as wide. Then shift this vector left | ||
/// by `shift`, shifting in zeros, and extract the most significant | ||
/// half. If `a` and `b` are the same, this is equivalent to a rotate | ||
/// left operation. |
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.
Please explicitly specify what happens when the shift is larger than the size of a / larger than the size of the concatenation. As written, it seems to imply that the return value is 0 in the latter case.
Looking at the docs, the shift amount seems to be modulo the size. That then makes me wonder why you talk about shifting in zeroes since those zeroes can never be visible?
Maybe that's what you mean with "wrapping on overflow" but that is not clear enough. (What gets wrapped how, and how do you define overflow? There's multiple definitions of what it means for a shift to overflow.)
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.
yeah, the
with wrapping on overflow
bit isn't clear enough I think. For funnel shifts the shift amount is modulo'd by the total number of bits in the type. so, a funnel shift on a u8
by 12
is equivalent to one by 12 % u8::BITS
.
Probably a good idea to just have an example of that in the doc comment as well.
I see there is a tracking issue, but not an ACP for this. Could you create one? It's an issue template at https://github.com/rust-lang/libs-team/issues. |
81da1f2
to
b91850b
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
b91850b
to
400a29d
Compare
This comment has been minimized.
This comment has been minimized.
400a29d
to
23601d2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Parent: #145686
ACP: rust-lang/libs-team#642
This implements funnel shifts on primitive integer types. Adds support in cg_llvm and Miri
Thanks @folkertdev for the fixes, and the cg_gcc and cg_clif implementation
cc @rust-lang/libs-api