u64 with `trailing_zeros` returns incorrect values
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.4k
- Forks
- 125
- PR merge metrics
- No merged PRs in 30d
Description
Expected Behaviour
We expect the trailing_zeros() function on u64 values to match the behavior of Rust's standard library implementation, returning the count of trailing zero bits.
For example:
0x0000000000000001_u64.trailing_zeros()should return 00x0000000100000000_u64.trailing_zeros()should return 320x8000000000000000_u64.trailing_zeros()should return 63
Example & Steps To Reproduce
0x0000000000000001Expected: 0, Result: 320x0000000100000000Expected: 32, Result: 00x8000000000000000Expected: 63, Result: 31
Run a shader that calculates trailing zeros on a u64. I am creating a pull request that contains test to validate the function and a fix for this issue.
#![no_std]
use spirv_std::spirv;
#[spirv(compute(threads(1)))]
pub fn main_cs(
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut [u32],
) {
// Expected: 0, Actual: 32
output[0] = 0x0000000000000001_u64.trailing_zeros();
// Expected: 32, Actual: 0
output[1] = 0x0000000100000000_u64.trailing_zeros();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the u64 trailing_zeros() entry point used when compiling the shader, comparing its behavior with Rust's standard library implementation. Run the shader reproduction with the three listed u64 values and add or use tests covering results 0, 32, and 63. Done means all examples return the expected count of trailing zero bits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100