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: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34678>
This commit is contained in:
Faith Ekstrand 2025-04-23 10:16:03 -05:00 committed by Marge Bot
parent fa58199166
commit d3e917ea03
2 changed files with 8 additions and 7 deletions

View file

@ -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()
}

View file

@ -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)
}
};