RFR: 8330094: RISC-V: Save and restore FCSR in the call stub

Ludovic Henry luhenry at openjdk.org
Mon Apr 15 10:52:40 UTC 2024


On Mon, 15 Apr 2024 10:43:34 GMT, Fei Yang <fyang at openjdk.org> wrote:

>> src/hotspot/cpu/riscv/stubGenerator_riscv.cpp line 429:
>> 
>>> 427:     // restore fcsr
>>> 428:     __ ld(t1, fcsr_save);
>>> 429:     __ csrw(CSR_FCSR, t1);
>> 
>> It would be better to avoid the `csrw` in case the CSR is already set to `RoundingMode::rne` on some hardware. You can have avoid it with a simple check on the current value of FCSR.
>> 
>> Something along the line of:
>> 
>> __ ld(t1, fcsr_save);
>> __ csrr(t0, CSR_FCSR);
>> __ beq(t1, t0, skip_csrw);
>> __ csrw(CSR_FCSR, t1);
>> __ bind(skip_csrw);
>> 
>> 
>> Some doc about it: https://riscv-optimization-guide.riseproject.dev/#_controlling_rounding_behavior_scalar
>
> Interesting. So is it safe to claim that `csrr` is faster than `csrw`? I didn't measure the difference.

It's fair to claim that `csrw` has side effects which may be more detrimental to performance, side effects that `csrr` that doesn't have (and can't as it's only reading).

> I didn't measure the difference.

I don't know how that affects current hardware, but remember that current hardware are in-order CPUs which may not be impacted by many of these performance problems.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18758#discussion_r1565583331


More information about the hotspot-dev mailing list