Many math functions need to check for floating point rounding modes to
return correct values. Currently most of them use the internal implementation
of fegetround, which is platform-dependent and blocking math functions to be
enabled on platforms with unimplemented fegetround. In this change, we add
platform independent rounding mode checks and switching math functions to use
them instead. https://github.com/llvm/llvm-project/issues/63016
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | I like the idea, but I'd like to have a flag to use the old method as well for targets where we're using -ffastmath or other optimizations that might precompute this value unexpectedly. |
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | For math functions, I think it is ok be not correctly rounded in all rounding modes with -ffastmath, but ideally, string functions should not be affected by it. On the other hand, -ffast-math flags break the floating point standards in many ways, such as flush denormal numbers to 0, so maybe losing the last bit of accuracy in some rounding modes with -ffast-math is acceptable? |
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | What do you think of this:
|
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | I that would be great, but unfortunately I think fegetround still have to return the correct one from fesetround, even with -ffast-math and fno-rounding-math: https://godbolt.org/z/8ca6djYvh So we still need the current get_round somewhere. Only the internal functions that are not expected to be correctly rounded with -ffast-math or -fno-rounding-mode should use this function. |
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | I do not know enough about -ffast-math and friends that I can agree or disagree with this. But, I think moving this to a separate header file is still good for distinction of what this FEnvImpl.h is for (it an implementation of a uniform interface to observe and manipulate the hardware FP env). |
libc/src/__support/FPUtil/FEnvImpl.h | ||
---|---|---|
130 ↗ | (On Diff #528892) | I've moved these functions to rounding_mode.h |