RFR: 8318158: RISC-V: implement roundD/roundF intrinsics [v2]
Hamlin Li
mli at openjdk.org
Wed Nov 15 13:49:32 UTC 2023
On Mon, 13 Nov 2023 23:01:30 GMT, Olga Mikhaltsova <omikhaltcova at openjdk.org> wrote:
>>> I have consulted with our h/w team and they told me next: multi-issue FP Unit can process few (data-independent) fp instructions at a time, even if they have different rounding mode. The only issue is when the rounding mode is set to dynamic rounding (aka get it from csr), but it's not our case here
>>
>> OK. Do what you will, but you're coding for an architecture not an implementation, and this code may stand for many years.
>
> First I've tried to implement rounding on riscv similar to aarch64, separated negative and positive numbers but branching is too expensive and I got not much performance improvement against the current java implementation.
>
> I like Vladimir's idea, the algorithm gives significant performance improvement and why not to take this advantage. But the above mentioned fix, related to fadd_s(), should be made. Not all numbers are processed correctly without it. Having changed rounding mode of fadd_s() we've got two sequential instructions with the same rounding mode - rdn.
>
> The performance improvement with the last fix on the T-Head RVB-ICE board is as follow:
>
> Benchmark (TESTSIZE) Mode Cnt Score Error Units
> FpRoundingBenchmark.test_round_double 2048 thrpt 15 111.278 0.349 ops/ms
> FpRoundingBenchmark.test_round_float 2048 thrpt 15 115.776 0.323 ops/ms
>
> @theRealAph As you suggested I've also tested this algorithm on the full 32-bit range [0; 0xFFFFFFFF] using Float.intBitsToFloat(x) and all the numbers were processed correctly. The output of this algorithm is equal to the current java Math.round() implementation output.
In typical implementations, writes to the dynamic rounding mode CSR state will serialize
the pipeline.
Static rounding modes are used to implement specialized arithmetic operations that often
have to switch frequently between different rounding modes.
-- from `“F” Standard Extension`
Seems to me, the static rounding is fine in riscv arch?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16382#discussion_r1394222656
More information about the hotspot-dev
mailing list