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

Fei Yang fyang at openjdk.org
Mon Apr 15 10:45:42 UTC 2024


On Mon, 15 Apr 2024 08:49:25 GMT, Ludovic Henry <luhenry at openjdk.org> wrote:

>> Hi,
>> Can you help to review this patch?
>> As discussed at https://github.com/openjdk/jdk/pull/17745#discussion_r1558783467, we should do the similar thing as [JDK-8319973](https://bugs.openjdk.org/browse/JDK-8319973) on aarch64.
>> Thanks!
>> 
>> Tests running ...
>
> 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.

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

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


More information about the hotspot-dev mailing list