EmbarkStudios / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧

Home Page:https://shader.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Integer bitwise rotate miscompilation

averyanalex opened this issue · comments

Expected Behaviour

Bitwise rotating works correctly.

Example & Steps To Reproduce

I was porting SHA512 and this function worked differently on CPU and GPU:

fn big_sigma0(x: u64) -> u64 {
    x.rotate_right(28) ^ x.rotate_right(34) ^ x.rotate_right(39)
}

System Info

  • Rust: rustc 1.69.0-nightly (44cfafe2f 2023-03-03)
  • OS: NixOS Linux 5.15.110
  • GPU: AMD Radeon RX 6800 XT
  • GPU Driver: amdvlk
  • SPIR-V: v2023.2 unknown hash, 1980-01-01T00:00:00 (incorrect time because of NixOS)

Just FYI the same thing happens with u32.

I think @chrisliebaer just ran into the same issue, and AFAICT it's just this being flipped:

let mask_is_zero = self
.emit()
.i_not_equal(bool, None, mask_shift.def(self), zero.def(self))
.unwrap()
.with_type(bool);

(based on the name it should clearly be == not !=)