On 23/06/2022 23.29, Richard Henderson wrote:
On 6/23/22 12:30, Peter Maydell wrote:
-static inline bool sadd32_overflow(int32_t x, int32_t y, int32_t *ret)
-{
-#if __has_builtin(__builtin_add_overflow) || __GNUC__ >= 5
- return __builtin_add_overflow(x, y, ret);
-#else
- *ret = x + y;
- return ((*ret ^ x) & ~(x ^ y)) < 0;
-#endif
-}
I think I'd prefer to keep the wrapper functions and just delete
the fallback ifdeffery, but I guess I don't feel really strongly
about it. Richard, do you have an opinion?
Likewise I don't feel strongly, but lean toward keeping the names. I will
point out that without these names, one has to track down the type of each
argument to figure out what is, or is not, overflowing.
Yes, I checked the calling sites, and some do use different types indeed,
but as far as I understood the __builtin_add_overflow(), it should be ok in
our cases. Anyway, it's maybe less error prone to keep the wrapper with the
fixed parameter types, so I'll send a v2 that just removes the #ifs instead.
Thomas