nir: Fix ifind_msb_rev constant folding.
For example if src0 is 0x80000000 we should return 1, not 0.
Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Fixes: a5747f8ab3
("nir: add opcodes for *find_msb_rev and lowering")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18951>
This commit is contained in:
@@ -500,16 +500,12 @@ for (int bit = bit_size - 1; bit >= 0; bit--) {
|
||||
|
||||
unop_convert("ifind_msb_rev", tint32, tint, """
|
||||
dst = -1;
|
||||
if (src0 != 0 && src0 != -1) {
|
||||
for (int bit = 0; bit < 31; bit++) {
|
||||
/* If src0 < 0, we're looking for the first 0 bit.
|
||||
* if src0 >= 0, we're looking for the first 1 bit.
|
||||
*/
|
||||
if ((((src0 << bit) & 0x40000000) && (src0 >= 0)) ||
|
||||
((!((src0 << bit) & 0x40000000)) && (src0 < 0))) {
|
||||
dst = bit;
|
||||
break;
|
||||
}
|
||||
/* We are looking for the highest bit that's not the same as the sign bit. */
|
||||
uint32_t sign = src0 & 0x80000000u;
|
||||
for (int bit = 0; bit < 32; bit++) {
|
||||
if (((src0 << bit) & 0x80000000u) != sign) {
|
||||
dst = bit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
Reference in New Issue
Block a user