Add state-aware random program scaffolding

This commit is contained in:
Huang
2026-09-29 21:29:06 -04:00
committed by Benzi
parent e1ff376357
commit 2bb9ccd45e
5 changed files with 131 additions and 18 deletions
+32 -6
View File
@@ -100,7 +100,7 @@ scoreboard must not assume that driver intent became DUT behavior.
| `src/verilog/tb/cpu_if.sv` | Groups chip signals and supplies a clocking block that prevents testbench/RTL races. | Provided |
| `src/verilog/tb/cpu_seq_item.svh` | Represents one randomized instruction and encodes it into a program word. | Complete constraints |
| `src/verilog/tb/cpu_xbar_item.svh` | Represents external accesses and monitor observations. | Complete constraints |
| `src/verilog/tb/cpu_sequencer.svh` | Generates programs/accesses and sends them to the driver through a mailbox. | Provided |
| `src/verilog/tb/cpu_sequencer.svh` | Generates programs/accesses, tracks the reachable generation state, and sends requests through a mailbox. | Provided |
| `src/verilog/tb/cpu_driver.svh` | Converts high-level requests into cycle-accurate chip pin activity. | Complete protocol tasks |
| `src/verilog/tb/cpu_monitor.svh` | Samples the interface and turns observed behavior into transactions. | Complete delayed-read and CPU-memory reconstruction |
| `src/verilog/tb/cpu_ref_model.svh` | Executes the supported architecture without modeling pipeline timing. | Provided; may be extended |
@@ -108,7 +108,7 @@ scoreboard must not assume that driver intent became DUT behavior.
| `src/verilog/tb/cpu_tb_pkg.sv` | Holds shared types, constants, helpers, and class includes. | Provided |
| `src/verilog/tb/cpu_tb_top.sv` | Instantiates the DUT and components, runs tests, and contains assertions. | Add tests and assertions |
| `Fall-26-Onboarding-TestPlan-Template.md` | Plan organized like the testbench: functional, chip-level, random, assertion, coverage, and bug-hunt sections. | Copy into initial and final plans |
| `sim/behav/Include/member.include` | Lists the your CPU and testbench sources compiled by Xcelium. | Update only if filenames differ |
| `sim/behav/Include/member.include` | Lists your CPU and testbench sources compiled by Xcelium. | Update only if filenames differ |
| `sim/behav/Makefile` | Provides the simulation, waveform, coverage, and bug-hunt commands. | Provided |
### How the components cooperate
@@ -116,6 +116,12 @@ scoreboard must not assume that driver intent became DUT behavior.
The **sequencer** decides what operation should be attempted. It sends transaction objects through
a mailbox to the **driver**, which is the only class allowed to drive DUT inputs.
Some instruction constraints depend on architectural state produced by earlier generated
instructions. For that purpose, the supplied sequencer advances a private reference model along
the program's reachable path and places the current register values in each instruction item
before randomization. This model supplies generation context only: it never observes the DUT and
never decides whether a test passed.
The **monitor** independently samples signals at the chip boundary. It converts observed requests,
responses, CPU memory operations, reset, start, and halt into transactions for the **scoreboard**.
The monitor never asks the driver what it intended to do.
@@ -157,7 +163,8 @@ rewrite the original reasoning when results contradict it; the revision history
When planning constrained-random tests, look through `src/verilog/tb/cpu_seq_item.svh` for the
instruction constraints, and `src/verilog/tb/cpu_xbar_item.svh` for the external-port constraints.
Use those constraint blocks to guide the plan for what stimulus is already covered and
what still needs to be completed.
what still needs to be completed. In particular, distinguish a field that is encoded in an
instruction from a value that depends on the state in which that instruction executes.
Do not make a checklist containing only one friendly example per operation. Think about value
classes, limits, state transitions, dependencies between adjacent operations, ownership changes,
@@ -269,6 +276,22 @@ unproductive combinations. The constraint exercises intentionally use three leve
For each constraint you complete, document the invalid state it removes, the useful distribution
or dependency it encourages, and any legal behavior it makes unreachable.
#### State-aware memory constraints
For `lw` and `sw`, the immediate is only one input to the effective byte address. Earlier
instructions may leave the selected base register aligned or unaligned, so constraining the
immediate alone cannot guarantee a legal access. Before each instruction is randomized, the
provided sequencer fills `reg_snapshot` with the register state at that instruction's reachable
execution point. Use that context to express both requirements in the `c_mem_align` TODO:
- the effective byte address is word-aligned, and
- the entire word lies inside data SRAM.
Keep `rs1` genuinely random. Forcing it to `x0`, reserving one address register, or requiring base
register values themselves to be aligned removes legal combinations and hides dependencies between
instructions. The sequencer includes a diagnostic check that stops at the first illegal generated
memory operation; it is feedback for completing the constraint, not a substitute for it.
Random stimulus is valuable only when it is reproducible and checked. Generated instructions are
printed by default. The Makefile also controls Xcelium's seed:
@@ -277,9 +300,12 @@ make xrun SEED=1 # repeat a known run
make xrun SEED=random # ask Xcelium to choose a new seed
```
For a random run, record the numeric `SVSEED` printed by Xcelium and rerun with that number. Reset
between random programs, label each iteration, and ensure the monitor/scoreboard path checks every
relevant result. A seed without the generated program and failing iteration is weak evidence.
For a random run, record the numeric `SVSEED` printed by Xcelium and rerun with that number. Label
each iteration, reset the CPU, and call `init_memories()` before generating each new program. That
reinitialization gives the DUT, scoreboard, and sequencer's generation model the same starting
memory image; it also prevents a timed-out or store-heavy program from contaminating the next
iteration. Run the CPU with a bounded timeout, then queue the register and relevant memory reads
needed for checking. A seed without the generated program and failing iteration is weak evidence.
### 7. Report DUT code coverage and revise the plan