Skip to content

Commit

Permalink
8297359: RISC-V: improve performance of floating Max Min intrinsics
Browse files Browse the repository at this point in the history
Reviewed-by: fyang
  • Loading branch information
Vladimir Kempik committed Nov 26, 2022
1 parent 6c05771 commit 99d3840
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
27 changes: 14 additions & 13 deletions src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,27 +1329,28 @@ void C2_MacroAssembler::minmax_FD(FloatRegister dst, FloatRegister src1, FloatRe
bool is_double, bool is_min) {
assert_different_registers(dst, src1, src2);

Label Done;
fsflags(zr);
Label Done, Compare;

is_double ? fclass_d(t0, src1)
: fclass_s(t0, src1);
is_double ? fclass_d(t1, src2)
: fclass_s(t1, src2);
orr(t0, t0, t1);
andi(t0, t0, 0b1100000000); //if src1 or src2 is quiet or signaling NaN then return NaN
beqz(t0, Compare);
is_double ? fadd_d(dst, src1, src2)
: fadd_s(dst, src1, src2);
j(Done);

bind(Compare);
if (is_double) {
is_min ? fmin_d(dst, src1, src2)
: fmax_d(dst, src1, src2);
// Checking NaNs
flt_d(zr, src1, src2);
} else {
is_min ? fmin_s(dst, src1, src2)
: fmax_s(dst, src1, src2);
// Checking NaNs
flt_s(zr, src1, src2);
}

frflags(t0);
beqz(t0, Done);

// In case of NaNs
is_double ? fadd_d(dst, src1, src2)
: fadd_s(dst, src1, src2);

bind(Done);
}

Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -7226,9 +7226,9 @@ instruct nmaddD_reg_reg(fRegD dst, fRegD src1, fRegD src2, fRegD src3) %{
%}

// Math.max(FF)F
instruct maxF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
instruct maxF_reg_reg(fRegF dst, fRegF src1, fRegF src2, rFlagsReg cr) %{
match(Set dst (MaxF src1 src2));
effect(TEMP_DEF dst);
effect(TEMP_DEF dst, KILL cr);

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

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

// Math.min(FF)F
instruct minF_reg_reg(fRegF dst, fRegF src1, fRegF src2) %{
instruct minF_reg_reg(fRegF dst, fRegF src1, fRegF src2, rFlagsReg cr) %{
match(Set dst (MinF src1 src2));
effect(TEMP_DEF dst);
effect(TEMP_DEF dst, KILL cr);

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

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

// Math.max(DD)D
instruct maxD_reg_reg(fRegD dst, fRegD src1, fRegD src2) %{
instruct maxD_reg_reg(fRegD dst, fRegD src1, fRegD src2, rFlagsReg cr) %{
match(Set dst (MaxD src1 src2));
effect(TEMP_DEF dst);
effect(TEMP_DEF dst, KILL cr);

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

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

// Math.min(DD)D
instruct minD_reg_reg(fRegD dst, fRegD src1, fRegD src2) %{
instruct minD_reg_reg(fRegD dst, fRegD src1, fRegD src2, rFlagsReg cr) %{
match(Set dst (MinD src1 src2));
effect(TEMP_DEF dst);
effect(TEMP_DEF dst, KILL cr);

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

Expand Down

1 comment on commit 99d3840

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.