Skip to content

u64 with trailing_zeros returns incorrect values #501

@voxelbee

Description

@voxelbee

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 0
  • 0x0000000100000000_u64.trailing_zeros() should return 32
  • 0x8000000000000000_u64.trailing_zeros() should return 63

Example & Steps To Reproduce

  • 0x0000000000000001 Expected: 0, Result: 32
  • 0x0000000100000000 Expected: 32, Result: 0
  • 0x8000000000000000 Expected: 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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions