From 7116d2fed062822bdfd96b8b385f7638eb4a0412 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 (cherry picked from commit b2aa92b52374066e9830672ef07bc4f6100a3508) Part-of: --- .pick_status.json | 2 +- src/util/softfloat.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 6368d50d358..fd05907fa0e 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3064,7 +3064,7 @@ "description": "softfloat: make sign bit an unsigned int", "nominated": true, "nomination_type": 4, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null 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;