From b2aa92b52374066e9830672ef07bc4f6100a3508 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Wed, 29 Apr 2026 01:39:41 +0200 Subject: [PATCH] softfloat: make sign bit an unsigned int According to ubsan shifting an int32_t by 31 bits to the left is undefined behavior. So just declare it as uint32_t. Backport-to: 26.1 Reviewed-by: Adam Jackson Reviewed-by: Emma Anholt Part-of: --- src/util/softfloat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/softfloat.c b/src/util/softfloat.c index eb191a4ac1e..435fadd16e6 100644 --- a/src/util/softfloat.c +++ b/src/util/softfloat.c @@ -153,7 +153,7 @@ double _mesa_roundtozero_f64(int64_t s, int64_t e, int64_t m) * \brief Extracted from softfloat_roundPackToF32() */ static inline -float _mesa_round_f32(int32_t s, int32_t e, int32_t m, bool rtz) +float _mesa_round_f32(uint32_t s, int32_t e, int32_t m, bool rtz) { fi_type result; uint8_t round_increment = rtz ? 0 : 0x40; @@ -1192,7 +1192,8 @@ _mesa_float_fma_rtz(float a, float b, float c) uint32_t c_flt_m = c_fi.u & 0x07fffff; uint32_t c_flt_e = (c_fi.u >> 23) & 0xff; uint32_t c_flt_s = (c_fi.u >> 31) & 0x1; - int32_t s, e, m = 0; + uint32_t s; + int32_t e, m = 0; c_flt_s ^= 0; s = a_flt_s ^ b_flt_s ^ 0; @@ -1371,7 +1372,8 @@ _mesa_double_to_f32(double val, bool rtz) uint64_t flt_m = di.u & 0x0fffffffffffff; uint64_t flt_e = (di.u >> 52) & 0x7ff; uint64_t flt_s = (di.u >> 63) & 0x1; - int32_t s, e, m = 0; + uint32_t s; + int32_t e, m = 0; s = flt_s;