Skip to content

Commit

Permalink
riscv(asm): fix float to int type conversion rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
infiWang committed Jun 24, 2023
1 parent a51de7a commit 4ceacb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lj_asm_riscv64.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ static void asm_conv(ASMState *as, IRIns *ir)
(st == IRT_NUM ?
(irt_isint(ir->t) ? RISCVI_FCVT_W_D : RISCVI_FCVT_WU_D) :
(irt_isint(ir->t) ? RISCVI_FCVT_W_S : RISCVI_FCVT_WU_S));
emit_ds(as, riscvi, dest, left);
emit_ds(as, riscvi|RISCVF_RM(RISCVRM_RTZ), dest, left);
}
} else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
Reg dest = ra_dest(as, ir, RSET_GPR);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ static void asm_sload(ASMState *as, IRIns *ir)
emit_dsshamt(as, RISCVI_SLLI, dest, dest, 17);
} else if (ir->op2 & IRSLOAD_CONVERT) {
if (irt_isint(t)) {
emit_ds(as, RISCVI_FCVT_W_D, dest, tmp);
emit_ds(as, RISCVI_FCVT_W_D|RISCVF_RM(RISCVRM_RTZ), dest, tmp);
/* If value is already loaded for type check, move it to FPR. */
if ((ir->op2 & IRSLOAD_TYPECHECK))
emit_ds(as, RISCVI_FMV_D_X, tmp, dest);
Expand Down
9 changes: 9 additions & 0 deletions src/lj_target_riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,13 @@ typedef enum RISCVIns {
/* TBD: RVV?, RVP?, RVJ? */
} RISCVIns;

typedef enum RISCVRM {
RISCVRM_RNE = 0,
RISCVRM_RTZ = 1,
RISCVRM_RDN = 2,
RISCVRM_RUP = 3,
RISCVRM_RMM = 4,
RISCVRM_DYN = 7,
} RISCVRM;

#endif

0 comments on commit 4ceacb3

Please sign in to comment.