Overview
The co-simulation testbench is the verification setup described for cross-level testing of a pipelined 32-bit RISC-V core. Its purpose is to run an RTL core and an instruction set simulator (ISS) against an effectively endless, unrestricted instruction stream while detecting mismatches between the two models.
Main components
Core adapter
The testbench uses a core adapter to hide implementation-specific details of the RTL core and present a clean testing interface. The adapter observes internal signal changes, especially pipeline behavior, and notifies the test controller whenever the RTL core completes an instruction. It also preserves the correct order in the presence of illegal instructions and exposes RTL register values so that they can be compared with the ISS.
This adapter is needed because completion detection in a pipelined RTL core can require knowledge of pipeline timing, delays, and gaps caused by multi-cycle operations.
Instruction stream matching
The testbench cannot simply assume that the RTL core and ISS fetch in lockstep. The RTL core may prefetch multiple instructions, and prefetched instructions may later be discarded because of jumps or traps. Short jumps and traps can also make the RTL core fetch new instructions before the ISS has reached the same fetch point.
To handle this, the setup matches ISS fetches against a queue of pending instructions delivered to the RTL core. If a matching instruction is found, it is returned to the ISS; otherwise, the testbench reports a mismatch because the ISS attempted to fetch an instruction that had not been delivered to the RTL core. The approach deliberately avoids feeding the RTL core's completed instruction sequence directly into the ISS, because doing so would rely on correct instruction propagation inside the RTL core, which is the design under test.
Instruction stream generator
The instruction stream generator provides the testbench with unrestricted instruction input. Its baseline behavior is to fully randomize generated instructions. The paper then describes several guidance mechanisms:
- injecting a random valid opcode into an otherwise randomized 32-bit word, to create a legal instruction while leaving fields randomized;
- applying field-mutation rules derived from RISC-V instruction formats;
- injecting special immediate values such as
MIN,-1,0,1, andMAX; - mutating register fields, for example setting
RDto zero, makingRDequal toRS1and/orRS2, or makingRS1matchRS2; - mutating a CSR selector field to a supported CSR;
- occasionally generating fixed-length instruction sequences rather than only independent instructions.
The algorithm shown in the paper starts a new instruction sequence with 1% probability, injects a random valid opcode with 98% probability, and applies a random field mutation with 20% probability.
Role in the verification flow
Together, the core adapter, instruction-stream matching, and guided instruction generation allow the co-simulation setup to compare RTL behavior against the ISS without constraining the generated program stream to simple lockstep execution. This is central to the cross-level testing approach introduced in the RISC-V processor verification case study.