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 24, 2023
1 parent f9795d0 commit 62f9f97
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
19 changes: 18 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,24 @@ enum operand_size { int8, int16, int32, uint32, int64 };

#undef INSN

// Float and Double Conversion Instruction
enum FCLASS_MASK {
NEG_INFINITE = 1 << 0,
NEG_NORMAL = 1 << 1,
NEG_SUBNORMAL = 1 << 2,
NEG_ZERO = 1 << 3,
POS_ZERO = 1 << 4,
POS_SUBNORMAL = 1 << 5,
POS_NORMAL = 1 << 6,
POS_INFINITE = 1 << 7,
SIGNALING_NAN = 1 << 8,
QUIET_NAN = 1 << 9,
RV_NAN = SIGNALING_NAN | QUIET_NAN,
RV_INFINITE = NEG_INFINITE | POS_INFINITE,
RV_FINITE = NEG_NORMAL | NEG_SUBNORMAL | NEG_ZERO |
POS_ZERO | POS_SUBNORMAL | POS_NORMAL,
};

// 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::RV_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::NEG_ZERO | Assembler::POS_ZERO | Assembler::RV_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::RV_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::RV_INFINITE);
__ 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::RV_INFINITE);
__ 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::RV_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::RV_FINITE);
__ slt(as_Register($dst$$reg), zr, as_Register($dst$$reg));
%}

Expand Down

0 comments on commit 62f9f97

Please sign in to comment.