Skip to content

Commit 99d3840

Browse files
author
Vladimir Kempik
committedNov 26, 2022
8297359: RISC-V: improve performance of floating Max Min intrinsics
Reviewed-by: fyang
1 parent 6c05771 commit 99d3840

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed
 

‎src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -1329,27 +1329,28 @@ void C2_MacroAssembler::minmax_FD(FloatRegister dst, FloatRegister src1, FloatRe
13291329
bool is_double, bool is_min) {
13301330
assert_different_registers(dst, src1, src2);
13311331

1332-
Label Done;
1333-
fsflags(zr);
1332+
Label Done, Compare;
1333+
1334+
is_double ? fclass_d(t0, src1)
1335+
: fclass_s(t0, src1);
1336+
is_double ? fclass_d(t1, src2)
1337+
: fclass_s(t1, src2);
1338+
orr(t0, t0, t1);
1339+
andi(t0, t0, 0b1100000000); //if src1 or src2 is quiet or signaling NaN then return NaN
1340+
beqz(t0, Compare);
1341+
is_double ? fadd_d(dst, src1, src2)
1342+
: fadd_s(dst, src1, src2);
1343+
j(Done);
1344+
1345+
bind(Compare);
13341346
if (is_double) {
13351347
is_min ? fmin_d(dst, src1, src2)
13361348
: fmax_d(dst, src1, src2);
1337-
// Checking NaNs
1338-
flt_d(zr, src1, src2);
13391349
} else {
13401350
is_min ? fmin_s(dst, src1, src2)
13411351
: fmax_s(dst, src1, src2);
1342-
// Checking NaNs
1343-
flt_s(zr, src1, src2);
13441352
}
13451353

1346-
frflags(t0);
1347-
beqz(t0, Done);
1348-
1349-
// In case of NaNs
1350-
is_double ? fadd_d(dst, src1, src2)
1351-
: fadd_s(dst, src1, src2);
1352-
13531354
bind(Done);
13541355
}
13551356

‎src/hotspot/cpu/riscv/riscv.ad

+8-8
Original file line numberDiff line numberDiff line change
@@ -7226,9 +7226,9 @@ instruct nmaddD_reg_reg(fRegD dst, fRegD src1, fRegD src2, fRegD src3) %{
72267226
%}
72277227

72287228
// Math.max(FF)F
7229-
instruct maxF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
7229+
instruct maxF_reg_reg(fRegF dst, fRegF src1, fRegF src2, rFlagsReg cr) %{
72307230
match(Set dst (MaxF src1 src2));
7231-
effect(TEMP_DEF dst);
7231+
effect(TEMP_DEF dst, KILL cr);
72327232

72337233
format %{ "maxF $dst, $src1, $src2" %}
72347234

@@ -7242,9 +7242,9 @@ instruct maxF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
72427242
%}
72437243

72447244
// Math.min(FF)F
7245-
instruct minF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
7245+
instruct minF_reg_reg(fRegF dst, fRegF src1, fRegF src2, rFlagsReg cr) %{
72467246
match(Set dst (MinF src1 src2));
7247-
effect(TEMP_DEF dst);
7247+
effect(TEMP_DEF dst, KILL cr);
72487248

72497249
format %{ "minF $dst, $src1, $src2" %}
72507250

@@ -7258,9 +7258,9 @@ instruct minF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
72587258
%}
72597259

72607260
// Math.max(DD)D
7261-
instruct maxD_reg_reg(fRegD dst, fRegD src1, fRegD src2) %{
7261+
instruct maxD_reg_reg(fRegD dst, fRegD src1, fRegD src2, rFlagsReg cr) %{
72627262
match(Set dst (MaxD src1 src2));
7263-
effect(TEMP_DEF dst);
7263+
effect(TEMP_DEF dst, KILL cr);
72647264

72657265
format %{ "maxD $dst, $src1, $src2" %}
72667266

@@ -7274,9 +7274,9 @@ instruct maxD_reg_reg(fRegD dst, fRegD src1, fRegD src2) %{
72747274
%}
72757275

72767276
// Math.min(DD)D
7277-
instruct minD_reg_reg(fRegD dst, fRegD src1, fRegD src2) %{
7277+
instruct minD_reg_reg(fRegD dst, fRegD src1, fRegD src2, rFlagsReg cr) %{
72787278
match(Set dst (MinD src1 src2));
7279-
effect(TEMP_DEF dst);
7279+
effect(TEMP_DEF dst, KILL cr);
72807280

72817281
format %{ "minD $dst, $src1, $src2" %}
72827282

0 commit comments

Comments
 (0)
Please sign in to comment.