[PATCH] Ensure calculations happen with desired rounding mode in y1lf128

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Aug 17 11:53:43 GMT 2022


Hi Michael,

> It does seem likely that an algorithm that does not require setting a rounding mode
> would in general be better than one that does but also that this is not very realistic.

Rewriting this function would not be trivial, but the math functions that are already
rewritten (like exp, pow, log) prove you can get fast and accurate results without
ever needing rounding mode changes.

When you design a polynomial to be very accurate, it actually works in all rounding
modes without extra effort. For this function it seems like whoever wrote it didn't
understand how to accurately evaluate polynomials - the input range of neval/deval
is (0.0, 4.0] so the repeated multiplies actually multiply the rounding errors...

> But I guess my point is that SET_RESTORE_ROUND without barriers is a footgun. 
> I guess I should commit my patch and perhaps see about writing some more for other
> uses of the macro?

The patch LGTM. Yes more patches would be welcome. It's a good idea to check
what happens if you remove the SET_RESTORE_ROUND - there will be cases where
the ULP is good enough.

Cheers,
Wilco


More information about the Libc-alpha mailing list