RFR: 8324724: Add Stub routines for FP16 conversions on aarch64
Nick Gasson
ngasson at openjdk.org
Mon Feb 5 10:01:01 UTC 2024
On Mon, 5 Feb 2024 09:12:23 GMT, Bhavana Kilambi <bkilambi at openjdk.org> wrote:
> This commit - https://github.com/openjdk/jdk/commit/8cfd74f76afc9e5d50c52104fef9974784718dd4 adds stub routines for FP16 conversions for float/float16 constants on x86 to get an accurate compile time value of the nodes. This task adds similar stub routines for aarch64 as well.
>
> With this patch, if the inputs to the conversion functions are constants, the stub routines are executed to determine the compile time values of the ConvHF2F/ConvF2HF nodes (in their respective Value() functions) and the ConvHF2F/ConvF2HF nodes are replaced with ConI/ConF nodes. This might help in further compiler optimizations like constant folding.
>
> The following testcase was used to test the disassembly -
>
>
> public class FloatConv {
>
> private static final short sconst;
> private static final float fconst;
>
> static {
> sconst = Short.MAX_VALUE;
> fconst = Float.MIN_VALUE;
> }
>
> @Benchmark
> public float hf2f() {
> return Float.float16ToFloat(sconst);
> }
>
> @Benchmark
> public short f2hf() {
> return Float.floatToFloat16(fconst);
> }
> }
>
>
> **Disassembly without patch :**
>
> **FloatConv.f2hf() :-**
>
> ...
> ldr s17, 0x0000ffff918cec80
> fcvt h16, s17
> smov x0, v16.h[0]
> ...
> ret
>
>
> **FloatConv.hf2f() :-**
>
> ...
> orr w11, wzr, #0x7fff
> mov v16.h[0], w11
> fcvt s0, h16
> ...
> ret
>
>
> **Disassembly with patch :**
>
> **FloatConv.hf2f() :-**
>
> ...
> ldr s0, 0x0000ffffb58ce880
> ...
> ret
>
>
> **FloatConv.f2hf() :-**
>
> ...
> mov w0, wzr
> ...
> ret
>
>
> With this patch, the conversion computation is done well in advance and the ConvHF2F/ConvF2HF nodes are replaced with the ConI/ConF nodes and thus the constant values are just loaded into registers and returned.
>
> The tests in - "hotspot/jtreg/compiler/intrinsics/float16" pass on both aarch64 and x86.
Marked as reviewed by ngasson (Reviewer).
-------------
PR Review: https://git.openjdk.org/jdk/pull/17706#pullrequestreview-1862309920
More information about the hotspot-compiler-dev
mailing list