RISC-V round_away () handling of non canonical rounding modes
Vineet Gupta
vineetg@rivosinc.com
Thu Jan 16 18:21:17 GMT 2025
Hi,
On RISC-V we are running into an obscure issue where glibc FP print call stack
is hitting abort.
__snprintf
__vsnprintf_internal
__printf_buffer
__printf_fp_l_buffer
__printf_fp_buffer_1
*round_away* + get_rounding_mode
abort
The reason is round_away () only handles the 4 canonical rounding modes (Up,
Down, Towards zero, Nearest- ties to even), while RISC-V ISA supports an
additional *Nearest - ties to Max magnitude* [1]. The last one being set
implicitly by various FP instructions.
With unrelated gcc changes, SPEC 2017 cam4 benchmark runs are hitting the abort
because printf_dp_buffer_1 () just reads the last set rounding mode which
happens to be the fifth one set by some FP insn.
Granted RISC-V fenv.h doesn't describe this rounding mode, but even if it were,
the common code still needs to handle it.
My question is what's the best approach to do this. Should we define this in
RISC-V fenv.h and then add conditional ifdef in common round_away () . Or should
we have arch specific over-ride of round_away () itself with fallback to common
version. The latter might be cleaner but seems like an over kill for something
which is only used sparingly in glibc codebase.
Suggestions ?
Thx,
-Vineet
[1] https://github.com/riscv/riscv-isa-manual
More information about the Libc-alpha
mailing list