Re: [PATCH v2 1/6] host-utils: fix ssub32/64_saturate return type and clamp direction
Brian Cain <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu.stable,gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
On 8/5/2026 11:32 PM, Brian Cain wrote: > ssub32_saturate() and ssub64_saturate() were declared to return bool > instead of int32_t/int64_t, and clamped to the wrong bound on overflow. > > Reviewed-by: Philippe Mathieu-Daudé <[email protected]> > Cc: [email protected] > Fixes: 16495533131 ("host-utils: Introduce signed saturation primitives") > Reviewed-by: Pierrick Bouvier <[email protected]> > Signed-off-by: Brian Cain <[email protected]> > --- Michael, I think this patch is a good candidate fix for -stable. -Brian > include/qemu/host-utils.h | 24 ++++++++++++------------ > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h > index 2e8da7fb3d0..1db9dbb138e 100644 > --- a/include/qemu/host-utils.h > +++ b/include/qemu/host-utils.h > @@ -607,10 +607,10 @@ static inline bool umul64_overflow(uint64_t x, uint64_t y, uint64_t *ret) > } > > /** > - * sadd32_saturate - addition with saturation > + * sadd32_saturate - 32-bit signed addition with saturation > * @x, @y: addends > * > - * Computes @x + @y, and saturates rathern than truncating the result. > + * Computes @x + @y, and saturates rather than truncating the result. > */ > static inline int32_t sadd32_saturate(int32_t x, int32_t y) > { > @@ -622,10 +622,10 @@ static inline int32_t sadd32_saturate(int32_t x, int32_t y) > } > > /** > - * sadd64_saturate - addition with saturation > + * sadd64_saturate - 64-bit signed addition with saturation > * @x, @y: addends > * > - * Computes @x + @y, and saturates rathern than truncating the result. > + * Computes @x + @y, and saturates rather than truncating the result. > */ > static inline int64_t sadd64_saturate(int64_t x, int64_t y) > { > @@ -637,31 +637,31 @@ static inline int64_t sadd64_saturate(int64_t x, int64_t y) > } > > /** > - * ssub32_saturate - subtraction with saturation > + * ssub32_saturate - 32-bit signed subtraction with saturation > * @x, @y: addends > * > - * Computes @x + @y, and saturates rathern than truncating the result. > + * Computes @x - @y, and saturates rather than truncating the result. > */ > -static inline bool ssub32_saturate(int32_t x, int32_t y) > +static inline int32_t ssub32_saturate(int32_t x, int32_t y) > { > int32_t ret; > if (ssub32_overflow(x, y, &ret)) { > - ret = x < 0 ? INT32_MAX : INT32_MIN; > + ret = x < 0 ? INT32_MIN : INT32_MAX; > } > return ret; > } > > /** > - * ssub64_saturate - subtraction with saturation > + * ssub64_saturate - 64-bit signed subtraction with saturation > * @x, @y: addends > * > - * Computes @x + @y, and saturates rathern than truncating the result. > + * Computes @x - @y, and saturates rather than truncating the result. > */ > -static inline bool ssub64_saturate(int64_t x, int64_t y) > +static inline int64_t ssub64_saturate(int64_t x, int64_t y) > { > int64_t ret; > if (ssub64_overflow(x, y, &ret)) { > - ret = x < 0 ? INT64_MAX : INT64_MIN; > + ret = x < 0 ? INT64_MIN : INT64_MAX; > } > return ret; > }