Skip to content

Commit

Permalink
Provide internal nop
Browse files Browse the repository at this point in the history
For the safe of return address, nop has to be part of IR, so that pc can
correctly advance. The internal nop can be used as the placeholder along
with super-instructions.
  • Loading branch information
jserv committed Dec 16, 2022
1 parent 96b8983 commit 5e94ea5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,10 @@ static inline bool op_op_imm(rv_insn_t *ir, const uint32_t insn)
decode_itype(ir, insn);

/* nop can be implemented as "addi x0, x0, 0" */
if (unlikely(ir->rd == rv_reg_zero))
if (unlikely(ir->rd == rv_reg_zero)) {
ir->opcode = rv_insn_nop;
return true;
}

/* dispatch from funct3 field */
switch (decode_funct3(insn)) {
Expand Down Expand Up @@ -566,8 +568,10 @@ static inline bool op_op(rv_insn_t *ir, const uint32_t insn)
decode_rtype(ir, insn);

/* nop can be implemented as "add x0, x1, x2" */
if (unlikely(ir->rd == rv_reg_zero))
if (unlikely(ir->rd == rv_reg_zero)) {
ir->opcode = rv_insn_nop;
return true;
}

uint8_t funct3 = decode_funct3(insn);

Expand Down
1 change: 1 addition & 0 deletions src/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* RISC-V instruction list */
/* clang-format off */
#define RISCV_INSN_LIST \
_(nop) \
/* RV32I Base Instruction Set */ \
_(lui) \
_(auipc) \
Expand Down
3 changes: 3 additions & 0 deletions src/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ static bool emulate(riscv_t *rv, const block_t *block)
/* main loop */
DISPATCH()

/* Internal */
_(nop, /* no operation */)

/* LUI (Load Upper Immediate) 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 register rd, filling in the lowest 12 bits with zeros. The
Expand Down

0 comments on commit 5e94ea5

Please sign in to comment.