Skip to content

Commit

Permalink
Add FCLASS_MASK enum for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
feilongjiang committed Oct 25, 2023
1 parent f9795d0 commit 069bb87
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 {
FCLASS_MINF = 1 << 0, // negative infinite
FCLASS_MNORM = 1 << 1, // negative normal number
FCLASS_MSUBNORM = 1 << 2, // negative subnormal number
FCLASS_MZERO = 1 << 3, // negative zero
FCLASS_PZERO = 1 << 4, // positive zero
FCLASS_PSUBNORM = 1 << 5, // positive subnormal number
FCLASS_PNORM = 1 << 6, // positive normal number
FCLASS_PINF = 1 << 7, // positive infinite
FCLASS_SNAN = 1 << 8, // signaling NaN
FCLASS_QNAN = 1 << 9, // quiet NaN
FCLASS_ZERO = FCLASS_MZERO | FCLASS_PZERO,
FCLASS_SUBNORM = FCLASS_MSUBNORM | FCLASS_PSUBNORM,
FCLASS_NORM = FCLASS_MNORM | FCLASS_PNORM,
FCLASS_INF = FCLASS_MINF | FCLASS_PINF,
FCLASS_NAN = FCLASS_SNAN | FCLASS_QNAN,
FCLASS_FINITE = FCLASS_ZERO | FCLASS_SUBNORM | FCLASS_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, Assembler::FCLASS_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, Assembler::FCLASS_ZERO | Assembler::FCLASS_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 @@ -4228,7 +4228,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, Assembler::FCLASS_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 @@ -7292,7 +7292,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_INF);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7307,7 +7307,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_INF);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7322,7 +7322,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_FINITE);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand All @@ -7337,7 +7337,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_FINITE);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand Down

0 comments on commit 069bb87

Please sign in to comment.