Cover: RISC-V verification with an ISS golden model, showing lock-step compare, three test phases, and a blind spot shared by core and ISS

RISC-V Verification: Check Every Instruction Against an ISS Golden Model

In short: To verify a RISC-V core, run the same program on the core and on an instruction set simulator (ISS) written from the spec, and compare every instruction the core retires: pc, instruction, register write, memory write and next pc. The first difference points at the bug. I built a small RV32I core and a UVM bench that does this, planted four bugs, and found that each of my three test phases caught bugs the others missed. The bigger lesson came from an AI-written ISS: it stopped on encodings that my core and my own ISS both ran, a blind spot the lock-step compare could not see because the two shared it. On VCS, the hand-written test missed three of the four bugs, the random programs missed two, and the random encodings missed one, so only the three phases together caught everything.

A core is only one block in a chip. Once it sits inside an SoC, the bugs move to how the blocks are wired together. SoC verification: the key areas shows a UVM bench that checks that glue.

Why is verifying a RISC-V design hard?

RISC-V is an open instruction set. Anyone can build a core for it, add custom instructions, and put it in an SoC with other cores, peripherals and accelerators. That freedom moves the work onto verification. Two questions have to be answered:

  • Is the core right? Every instruction must do exactly what the ISA spec says, for every operand.
  • Is the system right? The core must work with everything around it, and the software must run on the whole thing.

The first question has a standard answer that every serious RISC-V team uses: compare the core against a golden model of the ISA, instruction by instruction. The second question needs the same idea at a much bigger scale, which is where emulation comes in.

In this post I build the first part for real: a tiny RV32I core, an ISS written from the spec, and a UVM bench that compares them in lock-step. I run it on VCS with four planted bugs. Then I show how the same check scales to emulation and hardware-software co-verification, and what changes on the way.

The picture: marking homework with an answer key

A teacher checks homework against an answer key, question by question. The first wrong answer tells her exactly where the student went off track. That is lock-step checking: the core is the student, the ISS is the answer key.

Now suppose the answer key was written by the same student, the night before. Every mistake the student makes, the key makes too. Every answer matches, and every answer can still be wrong.

That is the trap with a golden model. It only catches what it disagrees with. If the person who wrote the core also writes the model, from the same understanding, they can share a blind spot. Mine did, and an independent model found it.

What will you learn?

By the end of this post you will be able to:

  • Explain the two halves of RISC-V verification: the core against the ISA, and the system around it.
  • Build a lock-step check that compares every retired instruction against an ISS golden model.
  • Design a commit (retirement) port that gives the testbench everything it needs to compare.
  • Use directed, random and random-encoding tests together, and say which bugs each one finds.
  • Spot when a golden model shares the core’s blind spot, and keep it independent.
  • Explain how the same check scales to emulation and hardware-software co-verification.

How do you prove a RISC-V core runs the ISA correctly?

The RISC-V spec says what every instruction must do to the registers, the memory and the program counter. An instruction set simulator (ISS) is a program that does exactly that, one instruction at a time, with no clocks or pipelines. Well-known ISS models for RISC-V include Spike, the reference simulator from the RISC-V project, and Sail, the formal model RISC-V International adopted as its golden reference.

To check a core, you run the same program on the core and on the ISS, and compare them after every instruction the core finishes (retires). This is called lock-step comparison. You need two things from the core:

  • A retirement trace. Each time an instruction retires, the core reports its pc, the instruction, which register it wrote and with what, any memory write, and the next pc. RISC-V cores often expose this as a standard trace port; the RISC-V Formal Interface (RVFI) is a common one.
  • Matching start state. Core and ISS must start from the same registers, the same memory and the same program.
Lock-step checking: the same program runs on the RTL core and on an ISS golden model, and every retired instruction is compared; the first difference is the bug
Lock-step checking: compare every retired instruction, and the first difference is the bug.

Why compare every instruction instead of only the final result? Because a wrong value can be overwritten before the program ends, and because the first difference tells you the exact instruction to debug. A final-state check tells you something went wrong somewhere in thousands of instructions.

Where does ISA compliance fit?

ISA compliance tests are fixed programs that check each instruction against expected signatures. They are a good start and every core should pass them. But they are a fixed set. A random program generator plus lock-step comparison finds the combinations a fixed suite never tried. Real teams use both: compliance tests to prove the basics, and random programs against an ISS to find the rest.

What does the testbench look like?

Everything is in one file, tav_riscv_iss_uvm.sv. The design is tav_rv_core, a single-cycle core for a subset of RV32I: ADD, SUB, SLL, SLT, SLTU, XOR, SRL, SRA, OR, AND, their immediate forms, LUI, LW, SW, BEQ, BNE, BLT, BGE and ECALL. ECALL, or any encoding outside the subset, stops the core. It has 256 words of program memory, 64 words of data memory, and a commit port that reports what it retires every cycle.

Testbench architecture: three stimulus phases feed a driver that loads programs into the RV32I core; a monitor sends each commit to a scoreboard that steps the ISS and compares every field
Three kinds of stimulus, one core, one ISS, every instruction compared.

The parts:

  • Phase 1, directed (tav_directed_seq): one hand-written program. It sums 1 to 10 in a loop that branches backward, stores the result, loads it back. This is the kind of test you write first.
  • Phase 2, random (tav_random_seq): 20 programs of 200 random instructions. Registers come from x0 to x7, so results get reused; LUI loads big and negative values; loads and stores use x0 as the base so every address is valid. Branches only go forward, so every program ends.
  • Phase 3, random encodings (tav_outside_seq): 200 programs of one instruction each, with a supported opcode and random bits in every other field. About half of these land outside the subset, and the core must stop on them.
  • Driver (tav_rv_driver): holds reset, writes the program into program memory, tells the scoreboard which program is starting, releases reset and waits for the core to stop.
  • Monitor (tav_rv_monitor): turns each retired instruction into a commit record.
  • Scoreboard (tav_rv_scoreboard): loads the same program into the ISS, steps the ISS once per commit and compares every field. After the first difference in a program it stops comparing that program, because the two states no longer match. It also checks that the core and the ISS stop together.
  • ISS (tav_rv_iss): written from the spec, in a different style from the RTL. It also counts what it saw, for the REACH lines: SLT with a negative operand, results aimed at x0, branches taken forward and backward, and encodings outside the subset.

The planted bugs, one per run:

OptionBug
(none)the clean core
+BUG=1SLT and SLTI compare as unsigned, so -1 < 1 comes out false
+BUG=2a write to x0 is not ignored
+BUG=3the branch offset is not sign-extended, so a backward branch jumps forward
+BUG=4loose decode: encodings outside the subset run instead of stopping the core

How do you build a lock-step RISC-V bench in UVM?

Here is the whole bench. To run it on EDA Playground, pick Synopsys VCS and UVM 1.2, paste the file into testbench.sv, leave design.sv empty, and set the top module to tav_top. Add +BUG=1 to +BUG=4 in the run options to plant a bug. The same file is in the tav-verification-basics repo on GitHub.

Four parts carry the lesson. The core’s commit port (c_valid to c_next_pc) is what makes lock-step possible. tav_rv_iss::step() is the golden model, and it checks the encoding before it executes anything. write_commit() in the scoreboard compares every field and stops comparing a program after its first difference. And the three sequences decide what the bench can find at all.

// tav_riscv_iss_uvm.sv : a tiny RV32I core checked instruction by instruction against an ISS (UVM 1.2)
// Run on Synopsys VCS X-2025.06-SP1 with UVM 1.2 (EDA Playground), 25 Nov 2026.
// The Art of Verification | theartofverification.com
//
// EDA Playground: Synopsys VCS, UVM 1.2, top module "tav_top".
// Paste this whole file into testbench.sv and leave design.sv empty.
//
// The design is a single-cycle core for a subset of RV32I:
//   ADD SUB SLL SLT SLTU XOR SRL SRA OR AND, ADDI SLTI SLTIU XORI ORI ANDI SLLI SRLI SRAI,
//   LUI, LW, SW, BEQ BNE BLT BGE, and ECALL. ECALL, and any encoding outside this
//   subset, stops the core.
// Every cycle it reports what it retired (pc, instruction, register write, memory write,
// next pc). The scoreboard runs an instruction set simulator (ISS) written from the RISC-V
// spec on the same program and compares every retired instruction. This is lock-step
// comparison, the same idea real RISC-V teams use with a golden model.
//
// Phase 1 runs one hand-written program: sum 1 to 10 in a loop, store it, load it back.
// Phase 2 runs 20 random programs of 200 instructions each. The random generator only
// makes forward branches, so every program ends.
// Phase 3 runs 200 one-instruction programs with random bits in every field except the
// opcode, to check that anything outside the subset stops the core.
//
// Run options (one per run):
//   (none)    the clean design
//   +BUG=1    SLT and SLTI compare as unsigned, so -1 < 1 comes out false
//   +BUG=2    a write to x0 is not ignored, so x0 stops reading as zero
//   +BUG=3    the branch offset is not sign-extended, so a backward branch jumps forward
//   +BUG=4    loose decode: encodings outside the subset (LB, SH, a bad funct7 ...) run instead
//             of stopping the core
//
// Memory: 256 instruction words from address 0, 64 data words (loads and stores use x0 as
// the base, so addresses are 0 to 252). Registers and data memory start at zero.

`timescale 1ns/1ns
`include "uvm_macros.svh"
import uvm_pkg::*;

// ---------------------------------------------------------------------------
// The design: a single-cycle RV32I subset core with a retirement (commit) port
// ---------------------------------------------------------------------------
module tav_rv_core (input logic clk, rst_n,
                    input logic iw_en, input logic [7:0] iw_addr, input logic [31:0] iw_data,
                    output logic c_valid, output logic [31:0] c_pc, c_insn,
                    output logic c_rd_we, output logic [4:0] c_rd, output logic [31:0] c_rd_wdata,
                    output logic c_mem_we, output logic [31:0] c_mem_addr, c_mem_wdata,
                    output logic [31:0] c_next_pc, output logic halted, input int bug);
  logic [31:0] imem [256];
  logic [31:0] dmem [64];
  logic [31:0] x [32];
  logic [31:0] pc, insn, a, b, imm_i, imm_s, imm_b, imm_u, wdata, maddr, npc;
  logic [6:0]  opcode, f7;
  logic [4:0]  rd, rs1, rs2;
  logic [2:0]  f3;
  logic        we, mwe, taken, stop, legal;

  always_ff @(posedge clk) if (iw_en) imem[iw_addr] <= iw_data;   // program load port

  always_comb begin
    insn   = imem[pc[9:2]];
    opcode = insn[6:0];  rd = insn[11:7];  f3 = insn[14:12];
    rs1    = insn[19:15]; rs2 = insn[24:20]; f7 = insn[31:25];
    a      = x[rs1];  b = x[rs2];
    imm_i  = {{20{insn[31]}}, insn[31:20]};
    imm_s  = {{20{insn[31]}}, insn[31:25], insn[11:7]};
    imm_b  = {{19{insn[31]}}, insn[31], insn[7], insn[30:25], insn[11:8], 1'b0};
    if (bug == 3) imm_b[31:13] = '0;                    // BUG=3: no sign extension
    imm_u  = {insn[31:12], 12'b0};
    we = 0; wdata = 0; mwe = 0; maddr = 0; taken = 0; stop = 0;
    npc = pc + 4;
    case (opcode)
      7'b0110011: begin                                  // register-register
        we = 1;
        case (f3)
          3'd0: wdata = f7[5] ? a - b : a + b;
          3'd1: wdata = a << b[4:0];
          3'd2: wdata = (bug == 1) ? 32'(a < b) : 32'($signed(a) < $signed(b));   // BUG=1
          3'd3: wdata = 32'(a < b);
          3'd4: wdata = a ^ b;
          3'd5: if (f7[5]) wdata = $signed(a) >>> b[4:0]; else wdata = a >> b[4:0];
          3'd6: wdata = a | b;
          3'd7: wdata = a & b;
        endcase
      end
      7'b0010011: begin                                  // register-immediate
        we = 1;
        case (f3)
          3'd0: wdata = a + imm_i;
          3'd1: wdata = a << insn[24:20];
          3'd2: wdata = (bug == 1) ? 32'(a < imm_i) : 32'($signed(a) < $signed(imm_i));   // BUG=1
          3'd3: wdata = 32'(a < imm_i);
          3'd4: wdata = a ^ imm_i;
          3'd5: if (insn[30]) wdata = $signed(a) >>> insn[24:20]; else wdata = a >> insn[24:20];
          3'd6: wdata = a | imm_i;
          3'd7: wdata = a & imm_i;
        endcase
      end
      7'b0110111: begin we = 1; wdata = imm_u; end      // LUI
      7'b0000011: begin we = 1; maddr = a + imm_i; wdata = dmem[maddr[7:2]]; end   // LW
      7'b0100011: begin mwe = 1; maddr = a + imm_s; end  // SW
      7'b1100011: begin                                  // branches
        case (f3)
          3'd0: taken = (a == b);
          3'd1: taken = (a != b);
          3'd4: taken = ($signed(a) < $signed(b));
          3'd5: taken = ($signed(a) >= $signed(b));
          default: stop = 1;
        endcase
        if (taken) npc = pc + imm_b;
      end
      default: stop = 1;                                 // ECALL, or anything not supported
    endcase
    // only the encodings in the subset may run; any other funct3 or funct7 stops the core
    case (opcode)
      7'b0110011:             legal = (f7 == 7'h00) || (f7 == 7'h20 && (f3 == 3'd0 || f3 == 3'd5));
      7'b0010011:             legal = (f3 == 3'd1) ? (f7 == 7'h00) :
                                      (f3 == 3'd5) ? (f7 == 7'h00 || f7 == 7'h20) : 1'b1;
      7'b0000011, 7'b0100011: legal = (f3 == 3'd2);
      default:                legal = 1'b1;
    endcase
    if (!legal && bug != 4) begin                        // BUG=4: loose decode
      we = 0; mwe = 0; npc = pc + 4; stop = 1;
    end
  end

  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      pc <= 0; halted <= 0;
      foreach (x[i])    x[i]    <= 0;
      foreach (dmem[i]) dmem[i] <= 0;
    end else if (!halted) begin
      if (we && (rd != 0 || bug == 2)) x[rd] <= wdata;  // BUG=2: x0 gets written
      if (mwe) dmem[maddr[7:2]] <= b;
      pc <= npc;
      if (stop) halted <= 1;
    end

  // what this cycle retires
  assign c_valid     = rst_n && !halted;
  assign c_pc        = pc;
  assign c_insn      = insn;
  assign c_rd_we     = we && (rd != 0 || bug == 2);
  assign c_rd        = rd;
  assign c_rd_wdata  = wdata;
  assign c_mem_we    = mwe;
  assign c_mem_addr  = maddr;
  assign c_mem_wdata = b;
  assign c_next_pc   = npc;
endmodule

// ---------------------------------------------------------------------------
// Interface
// ---------------------------------------------------------------------------
interface tav_rv_if (input logic clk);
  logic        rst_n, iw_en;
  logic [7:0]  iw_addr;
  logic [31:0] iw_data;
  logic        c_valid, c_rd_we, c_mem_we, halted;
  logic [4:0]  c_rd;
  logic [31:0] c_pc, c_insn, c_rd_wdata, c_mem_addr, c_mem_wdata, c_next_pc;
  clocking mon_cb @(posedge clk);
    default input #1step;
    input c_valid, c_pc, c_insn, c_rd_we, c_rd, c_rd_wdata, c_mem_we, c_mem_addr, c_mem_wdata, c_next_pc;
  endclocking
endinterface

// ---------------------------------------------------------------------------
// Encoders: turn an instruction into its 32-bit RV32I encoding
// ---------------------------------------------------------------------------
class tav_rv_asm;
  static function bit [31:0] r(bit [6:0] f7, bit [4:0] rs2, rs1, bit [2:0] f3, bit [4:0] rd);
    return {f7, rs2, rs1, f3, rd, 7'b0110011};
  endfunction
  static function bit [31:0] i(bit [6:0] op, int imm, bit [4:0] rs1, bit [2:0] f3, bit [4:0] rd);
    bit [11:0] im = imm;
    return {im, rs1, f3, rd, op};
  endfunction
  static function bit [31:0] s(int imm, bit [4:0] rs2, rs1);
    bit [11:0] im = imm;
    return {im[11:5], rs2, rs1, 3'b010, im[4:0], 7'b0100011};
  endfunction
  static function bit [31:0] br(bit [2:0] f3, bit [4:0] rs1, rs2, int off);
    bit [12:0] im = off;
    return {im[12], im[10:5], rs2, rs1, f3, im[4:1], im[11], 7'b1100011};
  endfunction
  static function bit [31:0] lui(bit [4:0] rd, bit [19:0] imm);
    return {imm, rd, 7'b0110111};
  endfunction
  static function bit [31:0] ecall();
    return 32'h0000_0073;
  endfunction
endclass

// ---------------------------------------------------------------------------
// Transactions
// ---------------------------------------------------------------------------
class tav_rv_prog extends uvm_sequence_item;          // one program to run
  bit [31:0] code[$];
  string     name;
  int        phase;
  bit        is_end, timed_out;                        // set by the driver when it finishes
  `uvm_object_utils(tav_rv_prog)
  function new(string name = "tav_rv_prog");
    super.new(name);
  endfunction
endclass

class tav_rv_commit extends uvm_object;               // one retired instruction
  bit [31:0] pc, insn, rd_wdata, mem_addr, mem_wdata, next_pc;
  bit [4:0]  rd;
  bit        rd_we, mem_we;
  `uvm_object_utils(tav_rv_commit)
  function new(string name = "tav_rv_commit");
    super.new(name);
  endfunction
  function string show();
    string s = $sformatf("pc=%08h insn=%08h", pc, insn);
    if (rd_we)  s = {s, $sformatf(" x%0d<=%08h", rd, rd_wdata)};
    if (mem_we) s = {s, $sformatf(" mem[%08h]<=%08h", mem_addr, mem_wdata)};
    return {s, $sformatf(" next_pc=%08h", next_pc)};
  endfunction
endclass

// ---------------------------------------------------------------------------
// The ISS: the golden model, written from the RISC-V spec, one instruction at a time
// ---------------------------------------------------------------------------
class tav_rv_iss;
  bit [31:0] x[32], mem[64], prog[$], pc;
  bit        halted;
  // what it saw, for the REACH report
  int n_slt_neg, n_x0_dest, n_back_taken, n_fwd_taken, n_outside;

  function void load(bit [31:0] code[$]);
    prog = code; pc = 0; halted = 0;
    foreach (x[k])   x[k]   = 0;
    foreach (mem[k]) mem[k] = 0;
  endfunction

  function int sx(bit [31:0] v, int bits);             // sign-extend the low "bits" bits
    return int'(v << (32 - bits)) >>> (32 - bits);
  endfunction

  function tav_rv_commit step();
    tav_rv_commit c = new("exp");
    bit [31:0] in = (pc[31:2] < prog.size()) ? prog[pc[31:2]] : 32'h0;
    bit [6:0] op = in[6:0];
    bit [4:0] rd = in[11:7], rs1 = in[19:15], rs2 = in[24:20];
    bit [2:0] f3 = in[14:12];
    int  sa = x[rs1], sb = x[rs2];                     // signed views
    bit [31:0] ua = x[rs1], ub = x[rs2];               // unsigned views
    int  imm;
    bit [31:0] res, uimm;
    bit  wr = 0, ok = 1;
    c.pc = pc; c.insn = in; c.next_pc = pc + 4;
    // the subset: any other funct3 or funct7 is outside it and stops the model
    case (op)
      7'h33:        ok = (in[31:25] == 0) || (in[31:25] == 7'h20 && (f3 == 0 || f3 == 5));
      7'h13:        if (f3 == 1) ok = (in[31:25] == 0);
                    else if (f3 == 5) ok = (in[31:25] == 0 || in[31:25] == 7'h20);
      7'h03, 7'h23: ok = (f3 == 2);
    endcase
    if (!ok) begin halted = 1; n_outside++; return c; end
    case (op)
      7'h33: begin
        wr = 1;
        case (f3)
          0: res = in[30] ? ua - ub : ua + ub;
          1: res = ua << ub[4:0];
          2: begin res = (sa < sb); if (sa < 0 || sb < 0) n_slt_neg++; end
          3: res = (ua < ub);
          4: res = ua ^ ub;
          5: if (in[30]) res = sa >>> ub[4:0]; else res = ua >> ub[4:0];
          6: res = ua | ub;
          7: res = ua & ub;
        endcase
      end
      7'h13: begin
        wr = 1; imm = sx(in[31:20], 12);
        case (f3)
          0: res = sa + imm;
          1: res = ua << in[24:20];
          2: begin res = (sa < imm); if (sa < 0 || imm < 0) n_slt_neg++; end
          3: begin uimm = imm; res = (ua < uimm); end
          4: res = ua ^ imm;
          5: if (in[30]) res = sa >>> in[24:20]; else res = ua >> in[24:20];
          6: res = ua | imm;
          7: res = ua & imm;
        endcase
      end
      7'h37: begin wr = 1; res = {in[31:12], 12'b0}; end
      7'h03: begin wr = 1; imm = sx(in[31:20], 12); res = mem[((sa + imm) >> 2) & 63]; end
      7'h23: begin
        imm = sx({in[31:25], in[11:7]}, 12);
        c.mem_we = 1; c.mem_addr = sa + imm; c.mem_wdata = ub;
        mem[(c.mem_addr >> 2) & 63] = ub;
      end
      7'h63: begin
        bit t;
        imm = sx({in[31], in[7], in[30:25], in[11:8], 1'b0}, 13);
        case (f3)
          0: t = (ua == ub);
          1: t = (ua != ub);
          4: t = (sa < sb);
          5: t = (sa >= sb);
          default: halted = 1;
        endcase
        if (t) begin
          c.next_pc = pc + imm;
          if (imm < 0) n_back_taken++; else n_fwd_taken++;
        end
      end
      default: halted = 1;                              // ECALL ends the program
    endcase
    if (wr && rd == 0) n_x0_dest++;
    if (wr && rd != 0) begin x[rd] = res; c.rd_we = 1; c.rd = rd; c.rd_wdata = res; end
    if (!halted) pc = c.next_pc;
    return c;
  endfunction
endclass

// ---------------------------------------------------------------------------
// Sequences: one hand-written program, then random programs
// ---------------------------------------------------------------------------
class tav_directed_seq extends uvm_sequence #(tav_rv_prog);
  `uvm_object_utils(tav_directed_seq)
  function new(string name = "tav_directed_seq");
    super.new(name);
  endfunction
  task body();
    req = tav_rv_prog::type_id::create("req");
    start_item(req);
    req.name = "sum 1 to 10"; req.phase = 1;
    req.code = '{ tav_rv_asm::i(7'h13, 10, 0, 0, 1),     //  0: addi x1, x0, 10
                  tav_rv_asm::i(7'h13, 0, 0, 0, 2),      //  4: addi x2, x0, 0
                  tav_rv_asm::r(0, 1, 2, 0, 2),          //  8: add  x2, x2, x1
                  tav_rv_asm::i(7'h13, -1, 1, 0, 1),     // 12: addi x1, x1, -1
                  tav_rv_asm::br(1, 1, 0, -8),           // 16: bne  x1, x0, 8 (back)
                  tav_rv_asm::s(0, 2, 0),                // 20: sw   x2, 0(x0)
                  tav_rv_asm::i(7'h03, 0, 0, 2, 3),      // 24: lw   x3, 0(x0)
                  tav_rv_asm::i(7'h13, -55, 3, 0, 4),    // 28: addi x4, x3, -55
                  tav_rv_asm::ecall() };                 // 32: ecall
    finish_item(req);
  endtask
endclass

class tav_random_seq extends uvm_sequence #(tav_rv_prog);
  `uvm_object_utils(tav_random_seq)
  int n_progs = 20, n_insns = 200;
  function new(string name = "tav_random_seq");
    super.new(name);
  endfunction

  // one random instruction at position k of n; registers x0 to x7 so results get reused
  function bit [31:0] one(int k, int n);
    bit [4:0] rd = $urandom_range(7), rs1 = $urandom_range(7), rs2 = $urandom_range(7);
    int pick = $urandom_range(99);
    if (pick < 30) begin                                 // register-register
      bit [2:0] f3 = $urandom_range(7);
      bit [6:0] f7 = ((f3 == 0 || f3 == 5) && $urandom_range(1)) ? 7'h20 : 7'h00;
      return tav_rv_asm::r(f7, rs2, rs1, f3, rd);
    end else if (pick < 55) begin                        // register-immediate
      bit [2:0] f3 = $urandom_range(7);
      int imm = $urandom_range(4095) - 2048;
      if (f3 == 1 || f3 == 5) imm = $urandom_range(31) | (($urandom_range(1) && f3 == 5) ? 32'h400 : 0);
      return tav_rv_asm::i(7'h13, imm, rs1, f3, rd);
    end else if (pick < 65) begin                        // LUI: big and negative values
      return tav_rv_asm::lui(rd, $urandom());
    end else if (pick < 75) begin                        // LW, base x0
      return tav_rv_asm::i(7'h03, 4 * $urandom_range(63), 0, 2, rd);
    end else if (pick < 85) begin                        // SW, base x0
      return tav_rv_asm::s(4 * $urandom_range(63), rs2, 0);
    end else begin                                       // forward branch, stays inside the program
      bit [2:0] f3s[4] = '{0, 1, 4, 5};
      int room = n - k;                                  // instructions left, counting the ecall
      int skip = $urandom_range((room < 8) ? room : 8, 1);
      return tav_rv_asm::br(f3s[$urandom_range(3)], rs1, rs2, 4 * skip);
    end
  endfunction

  task body();
    for (int p = 0; p < n_progs; p++) begin
      req = tav_rv_prog::type_id::create("req");
      start_item(req);
      req.name = $sformatf("random %0d", p + 1); req.phase = 2;
      for (int k = 0; k < n_insns; k++) req.code.push_back(one(k, n_insns));
      req.code.push_back(tav_rv_asm::ecall());
      finish_item(req);
    end
  endtask
endclass

class tav_outside_seq extends uvm_sequence #(tav_rv_prog);
  `uvm_object_utils(tav_outside_seq)
  int n_progs = 200;
  function new(string name = "tav_outside_seq");
    super.new(name);
  endfunction
  task body();
    bit [6:0] ops[6] = '{7'h33, 7'h13, 7'h37, 7'h03, 7'h23, 7'h73};   // branches left out
    for (int p = 0; p < n_progs; p++) begin
      bit [31:0] w = $urandom();
      w[6:0] = ops[$urandom_range(5)];
      req = tav_rv_prog::type_id::create("req");
      start_item(req);
      req.name = $sformatf("one-instruction %0d (%08h)", p + 1, w); req.phase = 3;
      req.code = '{ tav_rv_asm::i(7'h13, 1, 0, 0, 1),     // addi x1, x0, 1
                    tav_rv_asm::i(7'h13, -1, 0, 0, 2),    // addi x2, x0, -1
                    w,
                    tav_rv_asm::ecall() };
      finish_item(req);
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Driver: reset, load the program, release reset, wait for the core to stop
// ---------------------------------------------------------------------------
class tav_rv_driver extends uvm_driver #(tav_rv_prog);
  `uvm_component_utils(tav_rv_driver)
  virtual tav_rv_if vif;
  uvm_analysis_port #(tav_rv_prog) ap;                 // tells the scoreboard: start, end
  function new(string name, uvm_component parent);
    super.new(name, parent);
    ap = new("ap", this);
  endfunction
  function void build_phase(uvm_phase phase);
    if (!uvm_config_db#(virtual tav_rv_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "no virtual interface")
  endfunction
  task run_phase(uvm_phase phase);
    vif.rst_n <= 0; vif.iw_en <= 0;
    forever begin
      tav_rv_prog done;
      int cycles = 0, limit;
      seq_item_port.get_next_item(req);
      @(negedge vif.clk);
      vif.rst_n <= 0;
      for (int k = 0; k < 256; k++) begin
        @(negedge vif.clk);
        vif.iw_en <= 1; vif.iw_addr <= k; vif.iw_data <= (k < req.code.size()) ? req.code[k] : 32'h0;
      end
      @(negedge vif.clk);
      vif.iw_en <= 0;
      ap.write(req);                                     // start
      @(negedge vif.clk);
      vif.rst_n <= 1;
      limit = 4 * req.code.size() + 50;
      while (!vif.halted && cycles < limit) begin @(negedge vif.clk); cycles++; end
      done = tav_rv_prog::type_id::create("done");
      done.name = req.name; done.phase = req.phase; done.is_end = 1; done.timed_out = !vif.halted;
      ap.write(done);                                    // end
      seq_item_port.item_done();
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Monitor: one commit per retired instruction
// ---------------------------------------------------------------------------
class tav_rv_monitor extends uvm_monitor;
  `uvm_component_utils(tav_rv_monitor)
  virtual tav_rv_if vif;
  uvm_analysis_port #(tav_rv_commit) ap;
  function new(string name, uvm_component parent);
    super.new(name, parent);
    ap = new("ap", this);
  endfunction
  function void build_phase(uvm_phase phase);
    if (!uvm_config_db#(virtual tav_rv_if)::get(this, "", "vif", vif))
      `uvm_fatal("NOVIF", "no virtual interface")
  endfunction
  task run_phase(uvm_phase phase);
    forever begin
      @(vif.mon_cb);
      if (vif.mon_cb.c_valid === 1'b1) begin
        tav_rv_commit c = tav_rv_commit::type_id::create("c");
        c.pc = vif.mon_cb.c_pc; c.insn = vif.mon_cb.c_insn; c.next_pc = vif.mon_cb.c_next_pc;
        c.rd_we = vif.mon_cb.c_rd_we;
        if (c.rd_we) begin c.rd = vif.mon_cb.c_rd; c.rd_wdata = vif.mon_cb.c_rd_wdata; end
        c.mem_we = vif.mon_cb.c_mem_we;
        if (c.mem_we) begin c.mem_addr = vif.mon_cb.c_mem_addr; c.mem_wdata = vif.mon_cb.c_mem_wdata; end
        ap.write(c);
      end
    end
  endtask
endclass

// ---------------------------------------------------------------------------
// Scoreboard: lock-step compare of every retired instruction against the ISS
// ---------------------------------------------------------------------------
`uvm_analysis_imp_decl(_prog)
`uvm_analysis_imp_decl(_commit)
class tav_rv_scoreboard extends uvm_scoreboard;
  `uvm_component_utils(tav_rv_scoreboard)
  uvm_analysis_imp_prog   #(tav_rv_prog,   tav_rv_scoreboard) prog_imp;
  uvm_analysis_imp_commit #(tav_rv_commit, tav_rv_scoreboard) commit_imp;
  tav_rv_iss iss = new();
  string cur;
  int    cur_phase, retired, shown;
  bit    failed;
  int    progs[4], fails[4], compared[4];
  int    p1[4];                                       // REACH counts at the end of phase 1

  function new(string name, uvm_component parent);
    super.new(name, parent);
    prog_imp = new("prog_imp", this);
    commit_imp = new("commit_imp", this);
  endfunction

  function void fail(string why);
    failed = 1;
    if (shown < 3) begin
      shown++;
      `uvm_error("MISMATCH", $sformatf("%s, instruction %0d: %s", cur, retired, why))
    end
  endfunction

  function void write_prog(tav_rv_prog p);
    if (!p.is_end) begin
      iss.load(p.code); cur = p.name; cur_phase = p.phase; retired = 0; failed = 0;
      return;
    end
    progs[p.phase]++;
    if (!failed && p.timed_out) fail("core did not stop");
    else if (!failed && !iss.halted) fail("core stopped before the ISS did");
    if (failed) fails[p.phase]++;
    if (p.phase == 1) p1 = '{iss.n_slt_neg, iss.n_x0_dest, iss.n_fwd_taken, iss.n_back_taken};
  endfunction

  function void write_commit(tav_rv_commit got);
    tav_rv_commit exp;
    if (failed) return;                                 // after the first mismatch the states differ
    if (iss.halted) begin fail({"core kept going after the ISS stopped: ", got.show()}); return; end
    exp = iss.step();
    retired++; compared[cur_phase]++;
    if (got.pc !== exp.pc || got.insn !== exp.insn || got.next_pc !== exp.next_pc ||
        got.rd_we !== exp.rd_we || got.rd !== exp.rd || got.rd_wdata !== exp.rd_wdata ||
        got.mem_we !== exp.mem_we || got.mem_addr !== exp.mem_addr || got.mem_wdata !== exp.mem_wdata)
      fail($sformatf("core %s | ISS %s", got.show(), exp.show()));
  endfunction

  function void tav_print_results();
    `uvm_info("RESULT", $sformatf("Phase 1 directed: programs=%0d failed=%0d instructions compared=%0d -> %s",
              progs[1], fails[1], compared[1], fails[1] == 0 ? "PASS" : "FAIL"), UVM_NONE)
    `uvm_info("RESULT", $sformatf("Phase 2 random:   programs=%0d failed=%0d instructions compared=%0d -> %s",
              progs[2], fails[2], compared[2], fails[2] == 0 ? "PASS" : "FAIL"), UVM_NONE)
    `uvm_info("RESULT", $sformatf("Phase 3 encodings: programs=%0d failed=%0d instructions compared=%0d -> %s",
              progs[3], fails[3], compared[3], fails[3] == 0 ? "PASS" : "FAIL"), UVM_NONE)
    `uvm_info("REACH", $sformatf("Phase 1: SLT/SLTI with a negative operand=%0d, results aimed at x0=%0d, branches taken forward=%0d, backward=%0d",
              p1[0], p1[1], p1[2], p1[3]), UVM_NONE)
    `uvm_info("REACH", $sformatf("Phase 2: SLT/SLTI with a negative operand=%0d, results aimed at x0=%0d, branches taken forward=%0d, backward=%0d",
              iss.n_slt_neg - p1[0], iss.n_x0_dest - p1[1], iss.n_fwd_taken - p1[2], iss.n_back_taken - p1[3]), UVM_NONE)
    `uvm_info("REACH", $sformatf("Phase 3: encodings outside the subset=%0d of %0d", iss.n_outside, progs[3]), UVM_NONE)
  endfunction
endclass

// ---------------------------------------------------------------------------
// Agent, environment, test
// ---------------------------------------------------------------------------
class tav_rv_env extends uvm_env;
  `uvm_component_utils(tav_rv_env)
  uvm_sequencer #(tav_rv_prog) sqr;
  tav_rv_driver     drv;
  tav_rv_monitor    mon;
  tav_rv_scoreboard scb;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    sqr = uvm_sequencer#(tav_rv_prog)::type_id::create("sqr", this);
    drv = tav_rv_driver::type_id::create("drv", this);
    mon = tav_rv_monitor::type_id::create("mon", this);
    scb = tav_rv_scoreboard::type_id::create("scb", this);
  endfunction
  function void connect_phase(uvm_phase phase);
    drv.seq_item_port.connect(sqr.seq_item_export);
    drv.ap.connect(scb.prog_imp);
    mon.ap.connect(scb.commit_imp);
  endfunction
endclass

class tav_riscv_test extends uvm_test;
  `uvm_component_utils(tav_riscv_test)
  tav_rv_env env;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    env = tav_rv_env::type_id::create("env", this);
  endfunction
  task run_phase(uvm_phase phase);
    tav_directed_seq d = tav_directed_seq::type_id::create("d");
    tav_random_seq   r = tav_random_seq::type_id::create("r");
    tav_outside_seq  o = tav_outside_seq::type_id::create("o");
    phase.raise_objection(this);
    d.start(env.sqr);
    r.start(env.sqr);
    o.start(env.sqr);
    env.scb.tav_print_results();
    phase.drop_objection(this);
  endtask
endclass

// ---------------------------------------------------------------------------
// Top
// ---------------------------------------------------------------------------
module tav_top;
  logic clk = 0;
  int   BUG = 0;
  always #5 clk = ~clk;

  tav_rv_if vif (clk);
  tav_rv_core u_core (.clk(clk), .rst_n(vif.rst_n),
                      .iw_en(vif.iw_en), .iw_addr(vif.iw_addr), .iw_data(vif.iw_data),
                      .c_valid(vif.c_valid), .c_pc(vif.c_pc), .c_insn(vif.c_insn),
                      .c_rd_we(vif.c_rd_we), .c_rd(vif.c_rd), .c_rd_wdata(vif.c_rd_wdata),
                      .c_mem_we(vif.c_mem_we), .c_mem_addr(vif.c_mem_addr), .c_mem_wdata(vif.c_mem_wdata),
                      .c_next_pc(vif.c_next_pc), .halted(vif.halted), .bug(BUG));

  initial begin
    void'($value$plusargs("BUG=%d", BUG));
    `uvm_info("TOP", $sformatf("Running with BUG=%0d", BUG), UVM_NONE)
    uvm_config_db#(virtual tav_rv_if)::set(null, "uvm_test_top.env.*", "vif", vif);
    run_test("tav_riscv_test");
  end
endmodule

What does the output show?

I ran the bench five times on Synopsys VCS X-2025.06-SP1 with UVM 1.2 on EDA Playground. The clean run:

UVM_INFO testbench.sv(541) @ 610410: uvm_test_top.env.scb [RESULT] Phase 1 directed: programs=1 failed=0 instructions compared=36 -> PASS
UVM_INFO testbench.sv(543) @ 610410: uvm_test_top.env.scb [RESULT] Phase 2 random:   programs=20 failed=0 instructions compared=3091 -> PASS
UVM_INFO testbench.sv(545) @ 610410: uvm_test_top.env.scb [RESULT] Phase 3 encodings: programs=200 failed=0 instructions compared=675 -> PASS
UVM_INFO testbench.sv(547) @ 610410: uvm_test_top.env.scb [REACH] Phase 1: SLT/SLTI with a negative operand=0, results aimed at x0=0, branches taken forward=0, backward=9
UVM_INFO testbench.sv(549) @ 610410: uvm_test_top.env.scb [REACH] Phase 2: SLT/SLTI with a negative operand=85, results aimed at x0=259, branches taken forward=263, backward=0
UVM_INFO testbench.sv(551) @ 610410: uvm_test_top.env.scb [REACH] Phase 3: encodings outside the subset=95 of 200

3,802 instructions compared, no differences. Read the REACH lines before you trust that. Phase 1 took a backward branch 9 times but never ran SLT with a negative operand or aimed a result at x0. Phase 2 did both, hundreds of times, but took a backward branch 0 times. Phase 3 tried 95 encodings outside the subset. Each phase reaches places the others never go, and that decides what each one can catch.

Results grid of five VCS runs: clean core passes all three phases; BUG=1 and BUG=2 are missed by the directed program and caught by random programs; BUG=3 is caught only by the directed program; BUG=4 is caught only by random encodings
Five runs, four bugs, and which phase caught each one.

+BUG=1, SLT compares unsigned. The directed program passed: it has no SLT. Phase 2 failed 19 of 20 programs, and phase 3 caught it once too:

UVM_ERROR testbench.sv(512) @ 6525: uvm_test_top.env.scb [MISMATCH] random 1, instruction 99: core pc=0000020c insn=f530a093 x1<=00000001 next_pc=00000210 | ISS pc=0000020c insn=f530a093 x1<=00000000 next_pc=00000210

That is slti x1, x1, -173. The core says x1 < -173 is true, because it compared the bits as unsigned and -173 is a huge unsigned number. One random program in 20 never ran an SLT where signed and unsigned gave different answers. Random tests find bugs by volume; a smaller run could have passed.

+BUG=2, x0 written. Directed passed again: it never targets x0. Phase 2 failed all 20 programs, often within a few instructions:

UVM_ERROR testbench.sv(512) @ 6085: uvm_test_top.env.scb [MISMATCH] random 1, instruction 55: core pc=00000144 insn=a6c9e037 x0<=a6c9e000 next_pc=00000148 | ISS pc=00000144 insn=a6c9e037 next_pc=00000148

+BUG=3, branch offset not sign-extended. This time the hand-written program was the one that caught it, at its fifth instruction, the backward branch at the end of the loop:

UVM_ERROR testbench.sv(512) @ 2635: uvm_test_top.env.scb [MISMATCH] sum 1 to 10, instruction 5: core pc=00000010 insn=fe009ce3 next_pc=00002008 | ISS pc=00000010 insn=fe009ce3 next_pc=00000008

The core jumped to 0x2008 instead of back to 0x8. All 20 random programs and all 200 encodings passed, because my generator only makes forward branches. The REACH line said so before any bug was planted: backward=0.

+BUG=4, loose decode. Phases 1 and 2 passed, because they only ever use legal encodings. Phase 3 failed exactly the 95 programs whose encoding was outside the subset, and none of the others:

UVM_ERROR testbench.sv(512) @ 98785: uvm_test_top.env.scb [MISMATCH] one-instruction 5 (e6955403), instruction 3: core pc=00000008 insn=e6955403 x8<=00000000 next_pc=0000000c | ISS pc=00000008 insn=e6955403 next_pc=0000000c

e6955403 has the LOAD opcode with funct3 = 5, which is LHU, not in the subset. The ISS stops; the loose core loads a word into x8.

No single phase caught all four bugs, and each bug was missed by at least one phase. If I had stopped at the directed test I would have shipped three of them. If I had stopped at random programs I would have shipped two.

How does this scale to a full RISC-V SoC?

My bench runs a few thousand instructions in RTL simulation. A real core needs billions: long random programs, operating system boots, real software. Simulation gets too slow for that, and the system around the core adds more RTL to simulate. This is where hardware emulation and FPGA prototyping come in. I did not run either for this post; this section explains how the same lock-step idea carries over.

Scaling up: RTL simulation, then hardware emulation, then hardware-software co-emulation, then FPGA prototyping, with typical speeds and what each is used for
The lock-step check stays the same; the speed and the size of the program grow. Speeds are typical ranges, not measured here.

Emulation. The RTL is mapped onto a hardware emulator that runs at MHz speeds and stays cycle accurate. The testbench stays on the host computer and talks to the design through transactions, not individual pins. The Accellera SCE-MI standard defines that link, so a testbench built on it can move between emulators from different vendors. The ISS comparison still works: the core streams its retirement trace out of the emulator and the host compares it against the ISS. The catch is that the testbench must be emulation ready from the start: transaction-level interfaces, no pin-level delays in the driver, and as little time-consuming code on the host side as possible.

System and software. Once the core is trusted, the same approach extends to the rest of the SoC: peripherals, custom hardware, other cores. Software teams usually start on a virtual platform, a fast software model of the chip. In hybrid co-emulation, the virtual platform connects to the RTL running in the emulator, so software runs against real RTL long before silicon, and both teams debug the same revision.

FPGA prototyping. A prototype runs faster still, but it needs the whole design to be ready and synthesizable for the FPGA, so it comes late. It is useful for fast final testing and software bring-up, but it gives less visibility for debug and costs more per developer.

RTL simulationEmulationFPGA prototyping
When it is availablefrom day oneonce RTL blocks existlate, needs synthesizable RTL for everything
Debug visibilityfullhighlower
Best forblock and core checks, early bring-uplong programs, OS boot, HW-SW co-verificationfast final testing
Testbench reusethe UVM testbenchthe same testbench, if emulation readylimited

What are the common mistakes in RISC-V core verification?

Writing the golden model from the RTL instead of the spec. If you read your own RTL to write the ISS, it inherits the RTL’s mistakes, and the compare passes. Write it from the spec, in a different style, ideally by a different person, or use an existing model like Spike or Sail.

Comparing only the final result. A wrong register can be overwritten long before the program ends. Compare every retired instruction, every field.

Trusting one kind of test. In this bench, the directed program and the random programs found different bugs, and neither found the decode bug. Each phase covers a space the others never enter.

Letting the generator decide what you test without checking. My random generator only makes forward branches, so it can never test a backward branch. The REACH line shows that as a zero. Read the coverage of your generator, not just its pass count.

Only feeding the core legal instructions. A random program generator that only makes valid instructions never asks what the core does with everything else. The spec says what happens to encodings outside what you support; test it.

Comparing after the first difference. Once core and ISS disagree, their states differ and every later compare is noise. Report the first difference per program and move to the next program.

Forgetting x0. Register x0 always reads zero. A core that lets x0 be written passes any test that never targets it.

Mixing signed and unsigned in SystemVerilog. In a conditional expression, if one side is unsigned the whole thing is unsigned, so cond ? (sa >>> n) : (ua >> n) quietly turns the arithmetic shift into a logical one. I wrote exactly that in my first ISS draft and caught it in review. Use if and else for signed shifts.

Declaring a variable with a value inside a loop in a module’s initial block. In tav_riscv_ai_check.sv I first wrote tav_rv_commit cf = f.step(); inside a while loop in the module’s initial block. Variables there are static, so SystemVerilog runs that initial value once, at time 0, and never again. step() was never called in the loop, the loop never ended, and the VCS run stopped at EDA Playground’s time limit. My sandbox simulator treated the variable as automatic and hid the problem. Declare the variable once, then assign it inside the loop. Class methods are automatic by default, which is why the same pattern is safe in the UVM bench.

How do you debug a lock-step mismatch?

  1. Read the first MISMATCH line: the program, the instruction number, and both versions of what retired.
  2. Decode the instruction word. Which instruction is it, and which operands?
  3. Compare field by field. A wrong next_pc points at branch or jump logic; a wrong register value points at the ALU or a load; a write the ISS did not expect points at decode or the x0 rule.
  4. Check the operands. If the inputs were already wrong, the bug is earlier: look at the instruction that last wrote that register.
  5. If you are not sure which side is wrong, go back to the spec. The golden model can be wrong too.

Can AI write the golden model?

Task: write the ISS for the same RV32I subset, from the spec, with the same class interface as mine, so it could drop into the scoreboard.

Tool: Claude, in a fresh session with no files and no tools, so it saw only the prompt.

Prompt (in full):

Write a SystemVerilog class that is an instruction set simulator (ISS) golden model for a
subset of RV32I, to use in a UVM scoreboard. Supported instructions: ADD SUB SLL SLT SLTU XOR
SRL SRA OR AND, ADDI SLTI SLTIU XORI ORI ANDI SLLI SRLI SRAI, LUI, LW, SW, BEQ BNE BLT BGE,
and ECALL. ECALL, or any other encoding, stops the model (set halted = 1) and retires with no
register write.

Use exactly this interface:

class tav_rv_commit;
  bit [31:0] pc, insn, rd_wdata, mem_addr, mem_wdata, next_pc;
  bit [4:0]  rd;
  bit        rd_we, mem_we;
endclass

class tav_rv_iss;
  bit [31:0] x[32], mem[64], prog[$], pc;
  bit        halted;
  function void load(bit [31:0] code[$]);   // program at address 0, pc = 0, registers and memory cleared
  function tav_rv_commit step();            // execute the instruction at pc, return what it retired
endclass

Rules for step(): fetch prog[pc/4] (0 if past the end). rd_we = 1 only when the instruction
writes a register other than x0; then rd and rd_wdata are set. For SW set mem_we, mem_addr (the
full byte address) and mem_wdata. Data memory is 64 words: word index = (address >> 2) & 63.
next_pc is pc+4, or the branch target if taken. Leave fields not used by the instruction at 0.
After step(), pc = next_pc unless halted.

Write the full code for both classes.

What came back: a 168-line model with clean decode, $signed() on every signed compare and shift, and one detail mine did not have: it decoded strictly. It matched on the full {funct7, funct3} pair for register instructions, checked funct7 on the shifts, and checked funct3 on LW and SW. Anything else halted, exactly as the prompt said.

How I validated it: I did not change a line. At that point my own bench was already passing, with my first ISS. So I put three models side by side in tav_riscv_ai_check.sv: my first ISS, the AI’s ISS, and my ISS after the fix below. The file runs them on the same 20 random programs as the UVM bench, then on 20,000 single instructions with a supported opcode and random bits everywhere else.

What happened: on VCS:

Test A, 20 random programs: instructions=3290  first vs AI differences=0  fixed vs AI differences=0
Test B, random encodings: instructions=20000  first vs AI differences=9973 (first ran it, AI stopped=9973, other=0)  fixed vs AI differences=0

On the random programs, all three models agreed on all 3,290 instructions. On the random encodings, my first ISS and the AI’s disagreed on 9,973 of 20,000, and every single difference was the same kind: my ISS ran the instruction, the AI’s stopped.

Who was right: the AI. Take 0x00000183. Its opcode is LOAD, but funct3 is 0, which makes it LB x3, 0(x0), not LW. LB is not in my subset, so the spec I wrote says the core must stop. My first core read it as LW and carried on, and so did my first ISS, because I wrote both with the same habit: look at the opcode, assume the rest. The lock-step bench passed because the core and its golden model shared the blind spot. That is the answer-key problem from the start of this post.

What I changed: I made both my core and my ISS check every field, added phase 3 to the bench to feed it random encodings, and kept the old loose decode as +BUG=4 so you can see phase 3 catch it. After the fix my ISS and the AI’s agreed on all 20,000 encodings, 0 differences.

Where AI still needs you: it got the model right because the prompt said “any other encoding stops”. It cannot know what your core should do with those encodings in real life: a real RISC-V core raises an illegal-instruction exception, and that is a design decision written in your spec. It also did not write the test that exposed the difference. The value came from running two independent models against each other on stimulus neither had seen.

Lesson: an AI-written golden model is worth having precisely because it did not come from your head. Do not use it to replace your model. Use it to cross-check it.

Interview questions on RISC-V verification

  1. What is lock-step comparison? Running the same program on the core and on a golden model, and comparing what each instruction did as it retires. The first difference points at the bug.
  2. What does a commit (retirement) trace need to contain? At least the pc, the instruction, the register written and its value, any memory write with address and data, and the next pc. Interrupts, exceptions and CSR writes come next on a real core.
  3. Why compare every instruction instead of the final register state? A wrong value can be overwritten before the end, and the final state tells you nothing about where the program first went wrong.
  4. How would a pipelined, out-of-order core change this? The commit port reports instructions in program order as they retire, not as they execute, so the ISS comparison still works. The trace gets more fields, and the bench must handle cycles with no retirement or several at once.
  5. What can make a lock-step bench pass a broken core? A golden model with the same blind spot, a generator that never reaches the bug, or a comparison that skips a field.
  6. Why is x0 a classic RISC-V bug? x0 must always read zero, even after an instruction writes it. If the core stores the write, every later use of x0 is wrong, but only tests that target x0 will show it.
  7. Why not just use FPGA prototyping for everything? It needs the whole design to be ready and synthesizable, so it arrives late, gives less debug visibility, and costs more per developer. Simulation and emulation come first.

Practice challenge

Take tav_riscv_iss_uvm.sv and try these, in order:

  1. Let the random generator make backward branches without risking an endless loop, for example a short loop with a counter. Rerun +BUG=3 and confirm phase 2 now catches it.
  2. Add JAL and JALR to the core and the ISS. Write the ISS part from the spec first, then the RTL.
  3. Add a coverage group on the instruction type and operand signs, and use it to decide when phase 2 has run long enough.
  4. Change the core so an encoding outside the subset raises an illegal-instruction flag on the commit port instead of stopping, and update the ISS and the compare to match.

Frequently asked questions

What is an ISS in RISC-V verification?

An instruction set simulator is a software model of the ISA. It executes one instruction at a time and updates registers, memory and the program counter exactly as the spec says. In verification it is the golden model the core is compared against.

What is lock-step comparison?

Running the same program on the core and the ISS and comparing each instruction as it retires: pc, instruction, register write, memory write and next pc. The first difference is where to start debugging.

Is ISA compliance testing enough to verify a RISC-V core?

No. Compliance tests are a fixed set of programs that prove the basics. Random programs compared against an ISS find the combinations a fixed suite never tried, and system-level tests check the core with everything around it.

Why did the lock-step bench miss the decode bug at first?

Because my core and my ISS were written with the same assumption, so they made the same mistake and agreed. A golden model has to be independent of the design it checks, and the stimulus has to include encodings outside what you support.

When should you move from simulation to emulation?

When the programs you need to run, like long random tests or an operating system boot, would take days in simulation. Emulation runs at MHz speeds and stays cycle accurate. Build the testbench to be emulation ready from the start so you can move without rewriting it.

What is hybrid co-emulation?

Connecting a software team’s virtual platform to RTL running in a hardware emulator, so software runs against the real hardware design early and both teams debug the same revision.

References

Related lessons