Skip to content

Commit

Permalink
sim/riscv: PR29595, Fix multiply instructions
Browse files Browse the repository at this point in the history
Because of recent 'Zmmul' support, the simulator is now broken.  This is
caused by instruction classification changes:

[Before]
-   INSN_CLASS_M     : multiply / divide
[After Zmmul]
-   INSN_CLASS_M     : divide
-   INSN_CLASS_ZMMUL : multiply

The simulator checks the instruction class to execute an instruction:

-   INSN_CLASS_I  : 'I'
-   INSN_CLASS_M  : 'M' (multiply / divide)
-   INSN_CLASS_A  : 'A'

'Zmmul' moved multiply instructions to INSN_CLASS_ZMMUL and that instruction
class is not handled by the simulator.

This commit handles INSN_CLASS_ZMMUL for all 'M' instructions and adds a
testcase to test all RV32M instructions run without any faults.
  • Loading branch information
a4lg committed Oct 9, 2022
1 parent c10a862 commit 36cbb38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions sim/riscv/sim-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ execute_one (SIM_CPU *cpu, unsigned_word iw, const struct riscv_opcode *op)
case INSN_CLASS_I:
return execute_i (cpu, iw, op);
case INSN_CLASS_M:
case INSN_CLASS_ZMMUL:
return execute_m (cpu, iw, op);
default:
TRACE_INSN (cpu, "UNHANDLED EXTENSION: %d", op->insn_class);
Expand Down
18 changes: 18 additions & 0 deletions sim/testsuite/riscv/m-ext.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# check that the RV32M instructions run without any fault.
# mach: riscv

.include "testutils.inc"

start

.option arch, +m
mul x0, x1, x2
mulh x0, x1, x2
mulhu x0, x1, x2
mulhsu x0, x1, x2
div x0, x1, x2
divu x0, x1, x2
rem x0, x1, x2
remu x0, x1, x2

pass

0 comments on commit 36cbb38

Please sign in to comment.