Rust-GPU / Rust-GPU/rust-gpu

Implement `unbounded_shl`/`unbounded_shr`

Open
#403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
3.4k
Forks
126
PR merge metrics
No merged PRs in 30d

Description

These recent Rust integer methods semantically map cleanly onto OpShiftLeftLogical/OpShiftRightLogical.

This is in contrast to normal Rust shifts, whose semantic is such that shifting by the amount that is equal to or larger than number of bits in an integer is UB:

error: this arithmetic operation will overflow
 --> src/main.rs:3:20
  |
3 |     println!("{}", u32::MAX >> 32);
  |                    ^^^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow
  |
  = note: `#[deny(arithmetic_overflow)]` on by default

My understanding is that rust-gpu doesn't map these methods to those instructions yet, probably resulting in use of conditional logic from standard library, which is less efficient, at least without additional optimizations:

impl u32 {
    pub const fn unbounded_shr(self, rhs: u32) -> u32 {
        if rhs < Self::BITS {
            unsafe { self.unchecked_shr(rhs) }
        } else {
            0
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Rust integer method lowering and the code paths that emit OpShiftLeftLogical and OpShiftRightLogical. Verify that unbounded_shl and unbounded_shr use those instructions directly, including shift amounts at or above the integer width, and add or update coverage for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.