RISC-V round_away () handling of non canonical rounding modes

Florian Weimer fweimer@redhat.com
Thu Jan 16 19:21:43 GMT 2025


* Vineet Gupta:

> 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.

Is it really correct if the rounding mode changes spontaneously?  Or
is this an -ffast-math thing?

Thanks,
Florian



More information about the Libc-alpha mailing list