A UVM scoreboard is good at checking a transaction against an expected value, but a CPU core doesn't produce transactions in that sense - it executes an instruction stream and quietly updates its own internal state, most of which never appears on any bus. Proving that internal execution is correct, instruction by instruction, across millions of instructions of real software, needs a different kind of reference model entirely: one that runs the same program the RTL is running and can be checked against it in lockstep.

9 min read | Intermediate Level

What You'll Learn

  • What an instruction set simulator (ISS) is, and why it makes a better CPU reference model than a scoreboard
  • Why lockstep comparison happens at instruction retirement, not every clock cycle
  • What architectural state actually gets compared, and how that depth scales with verification maturity
  • Why keeping interrupts and other asynchronous events synchronized between RTL and ISS is the hardest part of the whole setup

What an ISS Actually Is

An instruction set simulator is a software model of the processor's architecture - not its microarchitecture. It fetches, decodes, and executes the same binary the RTL runs, updating its own copy of the architectural state: the program counter, general-purpose registers, control and status registers, and memory. It has no pipeline, no branch predictor, no cache hierarchy - none of the microarchitectural machinery the RTL actually implements to run fast. That's exactly what makes it useful as a reference: it is far simpler to get correct than the RTL, and its job is only to say what the architecturally visible result of each instruction should be, not how the RTL should get there.

Lockstep co-simulation runs this ISS alongside the RTL, instruction for instruction, and compares their architectural state as they go. Where a directed test checks whether one specific scenario produced the right answer, lockstep checks every single instruction the core ever executes - directed tests, random instruction streams, and real boot software alike - against an independent model of what should have happened.

Comparing at Retirement, Not Every Cycle

The RTL's pipeline holds several instructions in different stages of execution at once, and most of that in-flight state isn't architecturally visible yet - it can still be flushed by a mispredicted branch or an exception before it ever commits. Comparing the ISS against raw pipeline state cycle by cycle would produce constant false mismatches for exactly that reason.

Lockstep environments instead compare at retirement: the point where an instruction's results are actually committed to architectural state and can no longer be undone. Each time the RTL retires an instruction, the ISS is stepped forward by exactly one instruction, and the two are compared at that single, well-defined point. This sidesteps the entire question of how the RTL's pipeline got there - only the committed result has to match.

ISS lockstep: each time the RTL CPU retires an instruction, pending interrupts are copied into the ISS, the ISS steps one instruction, and the PC, register writes and memory effects are compared

task lockstep_compare(int hart_id);
  rtl_retire_t rtl_result;
  iss_result_t iss_result;

  wait_for_retire(hart_id, rtl_result);

  // Synchronize any asynchronous events into the ISS BEFORE stepping it,
  // so it sees the same interrupt/exception environment the RTL just did
  iss_set_pending_interrupts(hart_id, rtl_get_pending_interrupts(hart_id));

  iss_step(hart_id, iss_result);

  if (iss_result.pc !== rtl_result.pc)
    `uvm_error("LOCKSTEP", $sformatf("Hart %0d PC mismatch: ISS=0x%0h RTL=0x%0h",
               hart_id, iss_result.pc, rtl_result.pc))

  if (iss_result.gpr_wdata !== rtl_result.gpr_wdata)
    `uvm_error("LOCKSTEP", $sformatf("Hart %0d register mismatch at retire index %0d",
               hart_id, rtl_result.retire_index))
endtask

What Actually Gets Compared

How much architectural state gets checked at each retirement is a deliberate, tunable choice, and teams typically widen it as verification matures. Early bring-up often checks only the program counter - proof that control flow is even roughly sane. Once that's stable, general-purpose register writes get added, which catches most data-path and ALU bugs. Privilege and exception-handling verification adds control and status registers on top of that. Full sign-off confidence extends the comparison to memory - at least the regions the current test actually touches, since comparing every byte of memory on every retirement is far more expensive than the check is worth.

Some lockstep setups compare using a standardized handshake rather than a custom one - for RISC-V cores, interfaces like RVFI (on the RTL side) and RVVI (for the verification environment) define exactly what retirement data gets exposed and how asynchronous events get injected, so the same lockstep infrastructure can be reused across different cores and different reference models.

The Real Challenge: Keeping Two Independent Models in Sync

The hardest part of lockstep isn't the comparison itself - it's making sure the ISS sees exactly the same external inputs the RTL saw, at exactly the same point in the instruction stream. An interrupt is the clearest example: if the RTL takes an interrupt on instruction 4,812 but the ISS is told about that same interrupt one instruction too early or too late, the two models legitimately diverge from that point onward, even though neither one has an actual bug. That's a false mismatch, and chasing it wastes exactly the debug time lockstep is supposed to save.

The fix is to treat interrupt and exception delivery as an explicit synchronization step, not something either model decides on its own. Before the ISS steps forward, the environment reads whatever pending-interrupt state the RTL is currently exposing and forces that same state into the ISS first - the task example above does exactly this with a dedicated synchronization call before iss_step(). The same discipline applies to anything else non-deterministic from the ISS's point of view: memory-mapped I/O reads, debug-mode entry, or timer values, whose actual value needs to come from the RTL side rather than the ISS's own free-running model of the world.

Multi-Core Lockstep

Lockstep scales to a multi-core cluster by running one ISS instance per hart, each compared independently against its own core's retirement stream. This is where cache coherency work discussed in this chapter connects directly to lockstep: an ISS models memory as a flat, always-consistent array, so a write from one hart's RTL that another hart's cache has not yet observed still needs to show up in every ISS instance immediately. The lockstep environment typically updates all ISS memory models the moment any hart's write retires, sidestepping the coherency timing question entirely rather than trying to model it - lockstep checks that each core executed the right instructions on the right data, not that the coherency fabric delivered that data with the right timing, which is exactly what the cache-coherency-specific checking exists to verify separately.

Common Mistakes

Comparing RTL and ISS state on every clock cycle instead of at retirement.

Cycle-by-cycle comparison exposes pipeline state that hasn't committed yet and can still be flushed, producing false mismatches on perfectly correct RTL. Compare only at the well-defined retirement point.

Letting the ISS decide for itself when an interrupt occurs instead of synchronizing it from the RTL.

Two independently-timed interrupt sources will diverge eventually even with correct RTL. Interrupt and exception delivery has to be driven into the ISS from the RTL's actual state, not generated independently.

Comparing full memory contents on every single retirement.

This is usually not a correctness problem so much as a performance one - checking every byte of memory at every instruction can slow a lockstep run enough that it stops being practical to run the volume of software needed to find real bugs. Scope memory comparison to what the current test actually exercises.

Summary

In this article, you learned:

  • An instruction set simulator models a processor's architecture, not its microarchitecture, making it a simpler and independently-correct reference for what each instruction's result should be
  • Lockstep compares RTL against the ISS at instruction retirement, not every cycle, to avoid false mismatches from in-flight pipeline state
  • The depth of comparison - PC only, plus GPRs, plus CSRs, plus memory - is a tunable choice that typically widens as verification matures
  • Keeping interrupts and other asynchronous events synchronized between the two independent models is the hardest and most bug-prone part of a lockstep setup
  • Multi-core lockstep runs one ISS per hart and generally updates all ISS memory models immediately on any retired write, leaving coherency timing itself to be verified separately
Did you find what you were looking for?

Quiz

Test Your Knowledge

1 of 5 Score: 0 / 5
Cron Job Starts