Skip to content

Commit

Permalink
Get rid of rv->X[rv_reg_zero] = 0 completely
Browse files Browse the repository at this point in the history
Only updating zero register in instruction nop can pass the the
arch-test version 3.5.3.

Close sysprog21#208
  • Loading branch information
Yen-Fu Chen committed Sep 12, 2023
1 parent f272b5b commit 6262b31
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
8 changes: 0 additions & 8 deletions src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ static uint32_t last_pc = 0;
#define RVOP(inst, code) \
static bool do_##inst(riscv_t *rv, const rv_insn_t *ir) \
{ \
rv->X[rv_reg_zero] = 0; \
rv->csr_cycle++; \
code; \
nextop: \
Expand Down Expand Up @@ -339,7 +338,6 @@ enum {
/* AUIPC + ADDI */
static bool do_fuse1(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += 2;
rv->X[ir->rd] = rv->PC + ir->imm;
rv->X[ir->rs1] = rv->X[ir->rd] + ir->imm2;
Expand All @@ -353,7 +351,6 @@ static bool do_fuse1(riscv_t *rv, const rv_insn_t *ir)
/* AUIPC + ADD */
static bool do_fuse2(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += 2;
rv->X[ir->rd] = rv->PC + ir->imm;
rv->X[ir->rs2] = rv->X[ir->rd] + rv->X[ir->rs1];
Expand All @@ -367,7 +364,6 @@ static bool do_fuse2(riscv_t *rv, const rv_insn_t *ir)
/* multiple SW */
static bool do_fuse3(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += ir->imm2;
opcode_fuse_t *fuse = ir->fuse;
uint32_t addr = rv->X[fuse[0].rs1] + fuse[0].imm;
Expand All @@ -391,7 +387,6 @@ static bool do_fuse3(riscv_t *rv, const rv_insn_t *ir)
/* multiple LW */
static bool do_fuse4(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += ir->imm2;
opcode_fuse_t *fuse = ir->fuse;
uint32_t addr = rv->X[fuse[0].rs1] + fuse[0].imm;
Expand All @@ -415,7 +410,6 @@ static bool do_fuse4(riscv_t *rv, const rv_insn_t *ir)
/* LUI + ADDI */
static bool do_fuse5(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += 2;
rv->X[ir->rd] = ir->imm;
rv->X[ir->rs1] = ir->imm + ir->imm2;
Expand All @@ -429,7 +423,6 @@ static bool do_fuse5(riscv_t *rv, const rv_insn_t *ir)
/* memset */
static bool do_fuse6(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += 2;
memory_t *m = ((state_t *) rv->userdata)->mem;
memset((char *) m->mem_base + rv->X[rv_reg_a0], rv->X[rv_reg_a1],
Expand All @@ -444,7 +437,6 @@ static bool do_fuse6(riscv_t *rv, const rv_insn_t *ir)
/* memcpy */
static bool do_fuse7(riscv_t *rv, const rv_insn_t *ir)
{
rv->X[rv_reg_zero] = 0;
rv->csr_cycle += 2;
memory_t *m = ((state_t *) rv->userdata)->mem;
memcpy((char *) m->mem_base + rv->X[rv_reg_a0],
Expand Down
8 changes: 1 addition & 7 deletions src/rv32_template.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/* RV32I Base Instruction Set */

/* Internal */
static bool do_nop(riscv_t *rv, const rv_insn_t *ir)
{
rv->csr_cycle++;
rv->PC += ir->insn_len;
const rv_insn_t *next = ir + 1;
MUST_TAIL return next->impl(rv, next);
}
RVOP(nop, { rv->X[rv_reg_zero] = 0; })

/* LUI is used to build 32-bit constants and uses the U-type format. LUI
* places the U-immediate value in the top 20 bits of the destination
Expand Down

0 comments on commit 6262b31

Please sign in to comment.