Skip to content

core: Improve the documentation for funnel shifts#154150

Open
tgross35 wants to merge 3 commits intorust-lang:mainfrom
tgross35:funnel-updates
Open

core: Improve the documentation for funnel shifts#154150
tgross35 wants to merge 3 commits intorust-lang:mainfrom
tgross35:funnel-updates

Conversation

@tgross35
Copy link
Contributor

Change the variable name to make things a bit more clear, then rework funnel shift documentation. Examples now cover shifting by zero and emulating rotates.

Tracking issue: #145686

`rhs` is confusing since for the `Shl` and `Shr` traits, that is the
name used for the value to shift by (i.e. `self >> rhs`).
It's a bit easier to understand the results of shifts and otherwise
bitwise operations when leading zeros are present.
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet, scottmcm

@tgross35 tgross35 force-pushed the funnel-updates branch 3 times, most recently from 8683922 to 5ae8d71 Compare March 20, 2026 18:13
@tgross35
Copy link
Contributor Author

Cc @clarfonthey since you requested some of this at #145686 (comment)

@tgross35
Copy link
Contributor Author

Output since it's impossible to read the macros:

image

Shorten the summary line, cover shifts by zeros, rotates, and panics in
examples, and turn the "Panics" section into a complete sentence.
@tgross35
Copy link
Contributor Author

Some ascii art I sketched for this but decided to exclude:

//   high    low   
// |0x1234  0x5678| <- shift left 12 bits
//  \            /
//   \--|       /
//      |0x4567|
//       result
// 
//   high    low   
// |0x1234  0x5678| -> shift right 12 bits
//  \            /
//   \       |--/
//    |0x2345|
//     result

without modifying the original"]
#[inline(always)]
pub const fn funnel_shr(self, rhs: Self, n: u32) -> Self {
pub const fn funnel_shr(self, low: Self, n: u32) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think "right" gives a better intuition here than "low". This is about the number as a bitstring after all, not about it's numeric value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants