Conversation
|
Commenting here to avoid cluttering the closed ACP or the tracking issue.
If we're naming the methods after |
There was a problem hiding this comment.
Sorry for the delay here. A few requests:
- "bits disagreeing with the resulting sign bit" isn't the most clear. Maybe something based on "if the sign bit would be flipped"?
- The
exact_sh[lr]_uncheckedmethods seem to be missing examples - The signed example should demonstrate both positive and negative
- In the examples, use a value based on
$Self::BITSrather than 129. It would also be good to assert that one value below this returnsSome, for demonstrating the boundary - The edge cases are tricky here and should get some tests in
library/coretests/tests/num/uint_macros.rs(and the int version). - Can these be made
const?min/maxwill need to be replaced withrhs < ... && rhs < ..., but I feel like that's more clear anyway
@Qelxiros could you do the last one here? That one is pretty straightforward for naming consistency. For the other two, they sound right to me but we do have the |
629f3e1 to
525f2aa
Compare
This comment has been minimized.
This comment has been minimized.
525f2aa to
f2e8807
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. |
|
@rustbot ready |
|
@bors r+ |
|
Approved since this looks good to me (thank you for the changes) and has been sitting. One request if you get to it before bors does: the tracking issue mentions
which seems like a nice way to make this intuitive. I think it would be helpful to change the doc summary sentence to say something like that, then put the more specific detail (sign bit / shifting out / (can also be done as a followup at some point) |
|
Just realized that LLVM does have this behavior, and it was requested in the ACP rust-lang/libs-team#570 (comment). Not going to r- since the implementation here is still valid, but we'll need a followup PR adding new intrinsics at some point (I'll make a note in the tracking issue) |
f2e8807 to
f62b86b
Compare
|
Update looks good, thanks. Could you squash please? Didn't realize there were two commits here. |
f62b86b to
cefa74f
Compare
|
@bors r+ |
add exact bitshifts Tracking issue: rust-lang#144336 cc `@lolbinarycat`
add exact bitshifts Tracking issue: rust-lang#144336 cc ``@lolbinarycat``
Rollup of 6 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146186 (Update cc-rs to 1.2.33, and switch rustc_codegen_ssa to use find-msvc-tools) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 5 pull requests Successful merges: - #144342 (add exact bitshifts) - #145709 (Fix LoongArch C function ABI when passing/returning structs containing floats) - #146152 (Unify and deduplicate algebraic float tests) - #146207 (std: Implement WASIp2-specific stdio routines) - #146217 (fix ICE when suggesting `::new`) r? `@ghost` `@rustbot` modify labels: rollup
|
Hey bors this has already merged. @bors r- retry |
add exact bitshifts Tracking issue: rust-lang#144336 cc ```@lolbinarycat```
| assert_unsafe_precondition!( | ||
| check_language_ub, | ||
| concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out non-zero bits"), | ||
| ( | ||
| zeros: u32 = self.leading_zeros(), | ||
| ones: u32 = self.leading_ones(), | ||
| rhs: u32 = rhs, | ||
| ) => rhs < zeros || rhs < ones, | ||
| ); | ||
|
|
||
| // SAFETY: this is guaranteed to be safe by the caller | ||
| unsafe { self.unchecked_shl(rhs) } |
There was a problem hiding this comment.
The use of check_language_ub here seems wrong. The following code has language UB if rhs >= BITS, but the condition you are checking is stronger than that. check_language_ub should only be used if a violation of the precondition will always lead to language UB, and that is not the case here.
There was a problem hiding this comment.
@Qelxiros are you interested in putting up a PR adding the intrinsics mentioned at #144342 (comment)? The comment here could be fixed at the same time.
There was a problem hiding this comment.
I am interested, but I'm not sure exactly how to do it. Do I need to add implementations to all the rustc_codegen_* crates, or just llvm? How exactly are intrinsics added? It looks like I need a combination of LLVMBuildShl/LLVMBuildShr and LLVMSetNUW/LLVMSetNSW/LLVMSetExact (although LLVMSetExact currently only exists in C++ code). However, I'm not sure where that goes or how to associate it with the appropriate symbol.
There was a problem hiding this comment.
Ralf got these already in #146878, thanks for the interest though
Tracking issue: #144336
cc @lolbinarycat