util: fix UBSan error with _mesa_bfloat16_bits_to_float

runtime error: left shift of 65535 by 16 places cannot be represented in type 'int'

This fixes nir_opt_algebraic_pattern_test.bf2f.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Fixes: ecd2d2cf46 ("util: Add functions to convert float to/from bfloat16")
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
(cherry picked from commit 72f2b8a034)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40979>
This commit is contained in:
Rhys Perry 2026-04-07 09:46:27 +01:00 committed by Eric Engestrom
parent 92bfcb208f
commit eb4618b1b5
2 changed files with 2 additions and 2 deletions

View file

@ -3324,7 +3324,7 @@
"description": "util: fix UBSan error with _mesa_bfloat16_bits_to_float",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "ecd2d2cf46dfc3305a6dc1497815b7b54eef513e",
"notes": null

View file

@ -63,7 +63,7 @@ static inline float
_mesa_bfloat16_bits_to_float(uint16_t bf)
{
union fi x;
x.ui = bf << 16;
x.ui = (uint32_t)bf << 16;
return x.f;
}