Skip to content

Commit

Permalink
Fix illegal instruction handling for SLLI, SRLI, and SRAI
Browse files Browse the repository at this point in the history
According to the RISC-V specification, specifically for RV32I,
instructions like SLLI, SRLI, and SRAI should generate an illegal
instruction exception if the imm[5] bit is not zero. However, the
current implementation does not handle this error condition.

Addresse the issue by adding proper handling for illegal instruction
exceptions in cases where imm[5] is non-zero for SLLI, SRLI, and SRAI
instructions.
  • Loading branch information
visitorckw committed Feb 7, 2024
1 parent 50b8a07 commit 52fe009
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ static inline bool op_op_imm(rv_insn_t *ir, const uint32_t insn)
break;
case 1: /* SLLI: Shift Left Logical */
ir->opcode = rv_insn_slli;
if (unlikely(ir->imm & (1 << 5)))
return false;
break;
case 2: /* SLTI: Set on Less Than Immediate */
ir->opcode = rv_insn_slti;
Expand All @@ -482,6 +484,8 @@ static inline bool op_op_imm(rv_insn_t *ir, const uint32_t insn)
ir->opcode = (ir->imm & ~0x1f)
? rv_insn_srai /* SRAI: Shift Right Arithmetic */
: rv_insn_srli; /* SRLI: Shift Right Logical */
if (unlikely(ir->imm & (1 << 5)))
return false;
break;
case 6: /* ORI: OR Immediate */
ir->opcode = rv_insn_ori;
Expand Down

1 comment on commit 52fe009

@jserv
Copy link
Contributor

@jserv jserv commented on 52fe009 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Benchmark suite Current: 52fe009 Previous: 50b8a07 Ratio
Dhrystone 1662.37 Average DMIPS over 10 runs 1599 Average DMIPS over 10 runs 0.96
Coremark 1527.967 Average iterations/sec over 10 runs 1506.684 Average iterations/sec over 10 runs 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.