[PATCH] Ensure calculations happen with desired rounding mode in y1lf128
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Fri Aug 12 12:28:42 GMT 2022
Hi Michael,
> I don't know if this patch should be committed as is, although it does
> fix an observed failure for me.
The patch looks good to me, but this is a more general issue...
> My read of the discussion in the gcc bug I filed about this
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106574 is that every single
> use of a SET_RESTORE_ROUND macro is vulnerable to this. I can't think of
> a generic way to fix this -- I guess you could have a macro to call an
> always_inline function with a rounding mode set? But that would uglify
> the control flow in the code quite a bit.
Indeed, there is no general way to block optimizations across a boundary in
GCC if they do not involve memory accesses. As a result it is never safe to
change the rounding mode inside a function...
All math functions using the SET_RESTORE_ROUND macros will need similar
barriers. Note that it is feasible to remove these macros altogether and fix
any issues (a slightly larger ULP is acceptable for non-nearest rounding).
Given rounding mode changes are generally expensive, this also improves
performance (though that may not be important for 128-bit floats).
Cheers,
Wilco
More information about the Libc-alpha
mailing list