Skip to content

Tracking Issue for unbounded_shifts #129375

Open
@chorman0773

Description

@chorman0773

Feature gate: #![feature(unbounded_shifts)]

This is a tracking issue for ACP 428.

This adds shifts functions to the integer types that ignore type bounds when shifting, with out of range values for the rhs yielding the result of shifting the entire value out (0 for left shifts, and unsigned right shifts, and either 0 or -1 for signed right shifts).

Public API

impl uN{
     pub const fn unbounded_shl(self, rhs: u32) -> Self;
     pub const fn unbounded_shr(self, rhs: u32) -> Self;
}

impl iN{
    pub const fn unbounded_shl(self, rhs: u32) -> Self;
    pub const fn unbounded_shr(self, rhs: u32) -> Self;
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Activity

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Aug 21, 2024
added a commit that references this issue on Aug 26, 2024

Rollup merge of rust-lang#129377 - chorman0773:unbounded-shifts-impl,…

68aff29
added a commit that references this issue on Aug 26, 2024
joshtriplett

joshtriplett commented on Nov 12, 2024

@joshtriplett
Member

This seems ready to stabilize.

@rfcbot merge

rfcbot

rfcbot commented on Nov 12, 2024

@rfcbot
Collaborator

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

added
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
on Nov 12, 2024
chorman0773

chorman0773 commented on Nov 12, 2024

@chorman0773
ContributorAuthor

I was going to do a stabilization report.

Just to be clear, my intention was to stabilize it both as a function and as a const fn in one shot, so team should keep that in mind during the pFCP.

chorman0773

chorman0773 commented on Dec 5, 2024

@chorman0773
ContributorAuthor

Stabilization Report

(Retroactive to pFCP)

Implementation History

Api Summary

impl uN{
     pub const fn unbounded_shl(self, rhs: u32) -> Self;
     pub const fn unbounded_shr(self, rhs: u32) -> Self;
}

impl iN{
    pub const fn unbounded_shl(self, rhs: u32) -> Self;
    pub const fn unbounded_shr(self, rhs: u32) -> Self;
}

unbounded_shl and unbounded_shr shifts self left or right by rhs as though with unbounded range. If rhs exceeds the bounds of the type, the result is:

  • For unbounded_shl, 0 always
  • For unbounded_shr, 0 for unsigned integers and either 0 or -1 (depending on the sign bit)

Experience Report

The Clever-ISA Project Emulator uses the nightly version of these functions to implement same-named functions in a primitive type wrapper. The wrapper functions (particularily unbounded_shr) are then used throughout the emulator to compute a number of different bitmasks.

scottmcm

scottmcm commented on Jan 7, 2025

@scottmcm
Member

Big fan of stabilizing a canonical way to write "shift that actually works" 👍

(These are the only shifts where shifting by one N times is the same as shifting by N one time.)

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
and removed
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
on Feb 11, 2025
rfcbot

rfcbot commented on Feb 11, 2025

@rfcbot
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

13 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.to-announceAnnounce this issue on triage meeting

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cuviper@joshtriplett@chorman0773@scottmcm@rfcbot

        Issue actions

          Tracking Issue for unbounded_shifts · Issue #129375 · rust-lang/rust