From d3e917ea031bc3c50644cd20c601d7005c57793e Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 23 Apr 2025 10:16:03 -0500 Subject: [PATCH] nak: Fix OpShf folding for shift >= 64 The checked_shr wasn't returning the correct value if .wrap was not set. We also weren't checking this case in the unit tests so we missed it. While we're here, get rid of a bunch of pointhess `as u64` as well. Part-of: --- src/nouveau/compiler/nak/hw_tests.rs | 2 +- src/nouveau/compiler/nak/ir.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/nouveau/compiler/nak/hw_tests.rs b/src/nouveau/compiler/nak/hw_tests.rs index 27290cde016..ac71816329e 100644 --- a/src/nouveau/compiler/nak/hw_tests.rs +++ b/src/nouveau/compiler/nak/hw_tests.rs @@ -950,7 +950,7 @@ fn test_op_shf() { let mut a = Acorn::new(); test_foldable_op_with(op, &mut |i| { if i == shift_idx { - a.get_uint(6) as u32 + a.get_uint(7) as u32 } else { a.get_u32() } diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index c1c59fac37f..a90303440fc 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -4007,21 +4007,22 @@ impl Foldable for OpShf { && self.data_type != IntType::I64 { if self.right { - x.checked_shr(shift).unwrap_or(0) as u64 + x.checked_shr(shift).unwrap_or(0) } else { - x.checked_shl(shift).unwrap_or(0) as u64 + x.checked_shl(shift).unwrap_or(0) } } else if self.data_type.is_signed() { if self.right { - (x as i64).checked_shr(shift).unwrap_or(0) as u64 + let x = x as i64; + x.checked_shr(shift).unwrap_or(x >> 63) as u64 } else { - (x as i64).checked_shl(shift).unwrap_or(0) as u64 + x.checked_shl(shift).unwrap_or(0) } } else { if self.right { - x.checked_shr(shift).unwrap_or(0) as u64 + x.checked_shr(shift).unwrap_or(0) } else { - x.checked_shl(shift).unwrap_or(0) as u64 + x.checked_shl(shift).unwrap_or(0) } };