[PATCH] D144454: Add builtin for llvm set rounding
Serge Pavlov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 1 20:56:37 PST 2023
sepavloff added a comment.
C standard function `fesetround` accepts rounding mode in the form of target-specific values like `FE_TONEAREST`. They usually represent corresponding bits in control register, so are different for different targets. `llvm.set_rounding` in contrast accepts rounding mode as target-independent value, the encoding is same as used in `FLT_ROUNDS`.
The difference between `fesetround` and `llvm.set_rounding` is same as for `fegetround` and `FLT_ROUNDS`. They differ in how rounding mode is specified, - as target-specific or as target-independent values respectively.
The intrinsic `llvm.set_rounding` was introduced to facilitate work on IR, because IR is (mainly) target-agnostic and defines like `FE_TONEAREST` are not available there. It would be nice to have a C builtin counterpart for `FLT_ROUNDS`, I don't know why the standard does not define it.
Implementation of `fesetround` with `set_rounding` would be very useful, but it requires translation of target-specific values for rounding mode into universal values and also checking availability of FPU, as `fesetround` returns value if rounding mode cannot be set. Both these checks are likely to require separate builtins.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144454/new/
https://reviews.llvm.org/D144454
More information about the cfe-commits
mailing list