Skip to content

Commit

Permalink
8318827: RISC-V: Improve readability of fclass result testing
Browse files Browse the repository at this point in the history
Reviewed-by: vkempik, luhenry, fyang
  • Loading branch information
feilongjiang committed Oct 29, 2023
1 parent 1ec0d02 commit db34025
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
21 changes: 20 additions & 1 deletion src/hotspot/cpu/riscv/assembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,26 @@ enum operand_size { int8, int16, int32, uint32, int64 };

#undef INSN

// Float and Double Conversion Instruction
enum fclass_mask {
minf = 1 << 0, // negative infinite
mnorm = 1 << 1, // negative normal number
msubnorm = 1 << 2, // negative subnormal number
mzero = 1 << 3, // negative zero
pzero = 1 << 4, // positive zero
psubnorm = 1 << 5, // positive subnormal number
pnorm = 1 << 6, // positive normal number
pinf = 1 << 7, // positive infinite
snan = 1 << 8, // signaling NaN
qnan = 1 << 9, // quiet NaN
zero = mzero | pzero,
subnorm = msubnorm | psubnorm,
norm = mnorm | pnorm,
inf = minf | pinf,
nan = snan | qnan,
finite = zero | subnorm | norm,
};

// Float and Double Conversion/Classify Instruction
#define INSN(NAME, op, funct3, funct5, funct7) \
void NAME(Register Rd, FloatRegister Rs1) { \
unsigned insn = 0; \
Expand Down
10 changes: 3 additions & 7 deletions src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ void C2_MacroAssembler::minmax_fp(FloatRegister dst, FloatRegister src1, FloatRe
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
andi(t0, t0, fclass_mask::nan); // 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);
Expand Down Expand Up @@ -1669,12 +1669,8 @@ void C2_MacroAssembler::signum_fp(FloatRegister dst, FloatRegister src, FloatReg
is_double ? fmv_d(dst, src)
: fmv_s(dst, src);

//bitmask 0b1100011000 specifies this bits:
// 3 - src is -0
// 4 - src is +0
// 8 - src is signaling NaN
// 9 - src is a quiet NaN
andi(tmp1, tmp1, 0b1100011000);
// check if input is -0, +0, signaling NaN or quiet NaN
andi(tmp1, tmp1, fclass_mask::zero | fclass_mask::nan);

bnez(tmp1, done);

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4246,7 +4246,7 @@ void MacroAssembler::FLOATCVT##_safe(Register dst, FloatRegister src, Register t
fclass_##FLOATSIG(tmp, src); \
mv(dst, zr); \
/* check if src is NaN */ \
andi(tmp, tmp, 0b1100000000); \
andi(tmp, tmp, fclass_mask::nan); \
bnez(tmp, done); \
FLOATCVT(dst, src); \
bind(done); \
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -7361,7 +7361,7 @@ instruct isInfiniteF_reg_reg(iRegINoSp dst, fRegF src)
format %{ "isInfinite $dst, $src" %}
ins_encode %{
__ fclass_s(as_Register($dst$$reg), as_FloatRegister($src$$reg));
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), 0b0010000001);
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), Assembler::fclass_mask::inf);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7376,7 +7376,7 @@ instruct isInfiniteD_reg_reg(iRegINoSp dst, fRegD src)
format %{ "isInfinite $dst, $src" %}
ins_encode %{
__ fclass_d(as_Register($dst$$reg), as_FloatRegister($src$$reg));
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), 0b0010000001);
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), Assembler::fclass_mask::inf);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7391,7 +7391,7 @@ instruct isFiniteF_reg_reg(iRegINoSp dst, fRegF src)
format %{ "isFinite $dst, $src" %}
ins_encode %{
__ fclass_s(as_Register($dst$$reg), as_FloatRegister($src$$reg));
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), 0b0001111110);
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), Assembler::fclass_mask::finite);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7406,7 +7406,7 @@ instruct isFiniteD_reg_reg(iRegINoSp dst, fRegD src)
format %{ "isFinite $dst, $src" %}
ins_encode %{
__ fclass_d(as_Register($dst$$reg), as_FloatRegister($src$$reg));
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), 0b0001111110);
__ andi(as_Register($dst$$reg), as_Register($dst$$reg), Assembler::fclass_mask::finite);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand Down

0 comments on commit db34025

Please sign in to comment.