Skip to content

Commit 3a66737

Browse files
Yadong WangRealFYang
authored andcommitted
8299525: RISC-V: Add backend support for half float conversion intrinsics
Reviewed-by: fyang, fjiang
1 parent b7eb4e2 commit 3a66737

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/hotspot/cpu/riscv/assembler_riscv.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ enum operand_size { int8, int16, int32, uint32, int64 };
798798
INSN(fsqrt_d, 0b1010011, 0b00000, 0b0101101);
799799
INSN(fcvt_s_d, 0b1010011, 0b00001, 0b0100000);
800800
INSN(fcvt_d_s, 0b1010011, 0b00000, 0b0100001);
801+
INSN(fcvt_s_h, 0b1010011, 0b00010, 0b0100000);
802+
INSN(fcvt_h_s, 0b1010011, 0b00000, 0b0100010);
801803
#undef INSN
802804

803805
// Immediate Instruction
@@ -1054,6 +1056,7 @@ enum operand_size { int8, int16, int32, uint32, int64 };
10541056

10551057
INSN(fmv_w_x, 0b1010011, 0b000, 0b00000, 0b1111000);
10561058
INSN(fmv_d_x, 0b1010011, 0b000, 0b00000, 0b1111001);
1059+
INSN(fmv_h_x, 0b1010011, 0b000, 0b00000, 0b1111010);
10571060

10581061
#undef INSN
10591062

@@ -1074,6 +1077,7 @@ enum operand_size { int8, int16, int32, uint32, int64 };
10741077
INSN(fclass_d, 0b1010011, 0b001, 0b00000, 0b1110001);
10751078
INSN(fmv_x_w, 0b1010011, 0b000, 0b00000, 0b1110000);
10761079
INSN(fmv_x_d, 0b1010011, 0b000, 0b00000, 0b1110001);
1080+
INSN(fmv_x_h, 0b1010011, 0b000, 0b00000, 0b1110010);
10771081

10781082
#undef INSN
10791083

src/hotspot/cpu/riscv/globals_riscv.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ define_pd_global(intx, InlineSmallCode, 1000);
103103
product(bool, UseZba, false, EXPERIMENTAL, "Use Zba instructions") \
104104
product(bool, UseZbb, false, EXPERIMENTAL, "Use Zbb instructions") \
105105
product(bool, UseZbs, false, EXPERIMENTAL, "Use Zbs instructions") \
106+
product(bool, UseZfhmin, false, EXPERIMENTAL, "Use Zfhmin instructions") \
106107
product(bool, UseZic64b, false, EXPERIMENTAL, "Use Zic64b instructions") \
107108
product(bool, UseZicbom, false, EXPERIMENTAL, "Use Zicbom instructions") \
108109
product(bool, UseZicbop, false, EXPERIMENTAL, "Use Zicbop instructions") \

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,10 @@ const bool Matcher::match_rule_supported(int opcode) {
18421842
case Op_CountTrailingZerosI:
18431843
case Op_CountTrailingZerosL:
18441844
return UseZbb;
1845+
1846+
case Op_ConvF2HF:
1847+
case Op_ConvHF2F:
1848+
return UseZfhmin;
18451849
}
18461850

18471851
return true; // Per default match rules are supported.
@@ -8135,6 +8139,44 @@ instruct convL2F_reg_reg(fRegF dst, iRegL src) %{
81358139
ins_pipe(fp_l2f);
81368140
%}
81378141

8142+
// float <-> half float
8143+
8144+
instruct convHF2F_reg_reg(fRegF dst, iRegINoSp src, fRegF tmp) %{
8145+
predicate(UseZfhmin);
8146+
match(Set dst (ConvHF2F src));
8147+
effect(TEMP tmp);
8148+
8149+
ins_cost(XFER_COST);
8150+
format %{ "fmv.h.x $tmp, $src\t#@convHF2F_reg_reg\n\t"
8151+
"fcvt.s.h $dst, $tmp\t#@convHF2F_reg_reg"
8152+
%}
8153+
8154+
ins_encode %{
8155+
__ fmv_h_x($tmp$$FloatRegister, $src$$Register);
8156+
__ fcvt_s_h($dst$$FloatRegister, $tmp$$FloatRegister);
8157+
%}
8158+
8159+
ins_pipe(fp_i2f);
8160+
%}
8161+
8162+
instruct convF2HF_reg_reg(iRegINoSp dst, fRegF src, fRegF tmp) %{
8163+
predicate(UseZfhmin);
8164+
match(Set dst (ConvF2HF src));
8165+
effect(TEMP tmp);
8166+
8167+
ins_cost(XFER_COST);
8168+
format %{ "fcvt.h.s $tmp, $src\t#@convF2HF_reg_reg\n\t"
8169+
"fmv.x.h $dst, $tmp\t#@convF2HF_reg_reg"
8170+
%}
8171+
8172+
ins_encode %{
8173+
__ fcvt_h_s($tmp$$FloatRegister, $src$$FloatRegister);
8174+
__ fmv_x_h($dst$$Register, $tmp$$FloatRegister);
8175+
%}
8176+
8177+
ins_pipe(fp_f2i);
8178+
%}
8179+
81388180
// double <-> int
81398181

81408182
instruct convD2I_reg_reg(iRegINoSp dst, fRegD src) %{

src/hotspot/cpu/riscv/vm_version_riscv.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void VM_Version::initialize() {
5959
if (FLAG_IS_DEFAULT(UseZbb)) {
6060
FLAG_SET_DEFAULT(UseZbb, true);
6161
}
62+
if (FLAG_IS_DEFAULT(UseZbs)) {
63+
FLAG_SET_DEFAULT(UseZbs, true);
64+
}
6265
if (FLAG_IS_DEFAULT(UseZic64b)) {
6366
FLAG_SET_DEFAULT(UseZic64b, true);
6467
}
@@ -71,6 +74,9 @@ void VM_Version::initialize() {
7174
if (FLAG_IS_DEFAULT(UseZicboz)) {
7275
FLAG_SET_DEFAULT(UseZicboz, true);
7376
}
77+
if (FLAG_IS_DEFAULT(UseZfhmin)) {
78+
FLAG_SET_DEFAULT(UseZfhmin, true);
79+
}
7480
}
7581

7682
if (UseZic64b) {

0 commit comments

Comments
 (0)