Step Compare Against End-of-Test Memory Compare
There are two ways to check a core with a model. Compare every record as it retires, or run the model to the end and compare memory images. This page runs both on two recorded core bugs and measures what each one catches, when, and at what cost.
You Will Be Able To
- Describe the step compare and the end-of-test memory compare, and what each needs.
- Explain why an end-of-test compare can report late or never.
- Read the cost of each method from measured runs.
- Choose a method for a given bench, and say why.
- Lesson
- V5.5
- Time
- 26 min
- Runs on
- Your browser
- Check
- 5 questions
A kernel on this page runs 1,004,426 cycles on a faulty chip, and only its final memory is wrong. Which of its 697,213 instructions made the bad word? The image cannot say. A step compare stops at the first one.
- Processor
- Debug
- Memory
- Data
- Bug 1, step compare
The first wrong SLL differs from the model at cycle 34; the bench stops the run.
- Bug 1, memory compare
With the model off, the run goes on to its end at cycle 1,004,426. Then the image differs from the model's.
- Bug 2, step compare
The first SRL of a negative word differs at cycle 24.
- Bug 2, memory compare
The kernel keeps only bytes of each result: the wrong high bits never reach memory, and the images agree.
Read the diagram as text
- Bug 1: SLL shifts right: the shift kernel
- Bug 2: SRL fills from the sign: the byte kernel
- Step compare: cycle 34: pc and field
- Memory compare: cycle 1,004,426: a word differs
- Step compare: cycle 24: pc and field
- Memory compare: never: the images agree
- Bug 1: SLL shifts right → Step compare: at once
- Bug 1: SLL shifts right → Memory compare: 1,004,392 cycles later
- Bug 2: SRL fills from the sign → Step compare: at once
- Bug 2: SRL fills from the sign → Memory compare: masked
Recorded on ap_soc v1.5: two kernels of 1,200 rounds, each on a chip with one core fault of stage E9.
Before You Start
Read Lockstep With an Instruction-Level Model first.
| Question | |
|---|---|
| 1 | What does each method compare, and when? |
| 2 | Why can an end-of-test compare report a bug late, or not at all? |
| 3 | What does each method name when it reports? |
| 4 | What does the step compare cost in run time? |
| 5 | When is the end-of-test compare the right choice? |
The Idea: Every Step, or the Final Picture
The step compare runs the model in lockstep and checks every record, as on the lockstep page. It needs the trace and a model that can follow the core exactly. It reports at the first wrong instruction, and names it.
The end-of-test compare runs the model alone, on the same program, to its end. Then it compares the memory image the model left with the one the chip left. It needs no trace and no exact timing, only two images. It reports at the end, and names a word.
Between the bug and the end, two things can happen. The wrong value can spread and be overwritten, so the word you find is far from the cause. Or it can vanish: masked, overwritten or never stored. Then the images agree and nothing is reported.
New Words
| Word | Meaning |
|---|---|
| Step compare | Comparing the chip's retire record with the model's, on every record. |
| End-of-test compare | Comparing the final memory image of the chip with the model's, once, after the run. |
| Memory image | The contents of a memory at one moment, word by word. |
| Masked fault | A wrong value that never reaches anything the check looks at. |
| Detection latency | The cycles between a bug happening and a check reporting it. |
The Smallest Example: One Wrong Bit, Masked
Take one step of the byte kernel by hand. After the chip's faulty SRL by 8 the word is 0xffdaa674; the model's is 0x00daa674. The kernel keeps only byte 1 of it: andi t1, t1, 0xff.
| After srli by 8 | After andi 0xff | Stored | |
|---|---|---|---|
| Chip (faulty SRL) | ffdaa674 | 00000074 | byte 1 + byte 2 |
| Model | 00daa674 | 00000074 | byte 1 + byte 2 |
The first mismatch line of the recorded byte kernel: ISS mismatch cycle=24 pc=80000038 field=rd_wdata rtl=ffdaa674 model=daa674
The step compare reports the srli record. The andi removes every wrong bit, so the stored word is the same on both. At the end, the images agree.
The Rules
Rule 1: The step compare reports at the first wrong record.
Its latency is zero records; it names the pc and the field.
Rule 2: The end-of-test compare reports at the end, or never.
Its latency is the rest of the run; a masked fault is never reported.
Rule 3: An image names a word, not an instruction.
Finding the instruction means a search backwards through the run.
Rule 4: The step compare needs an exact model and a trace.
Every value the model cannot know must come from the chip.
Rule 5: Use both when you can.
Step compare for the core; images for what a model can only follow loosely.
Sources for These Rules
MEHTA-DV, chapter 18: a cache subsystem checked with instruction-set models of its processors. A random program image runs to the end; the model's expected image of external memory is compared with the simulated one. The book notes that a mismatch found this way is hard to trace back. It suggests also comparing the image of the cache nearer the activity, or assertions that stop the run at once.
Our step compare: soc_iss_dpi.c and soc_tb.sv; its cost of about 1 percent at stage E7 (plan 6.2). The memory compare of this page uses the bench's sram field (soc_tb README). It is a checksum of the first 4,096 words of SRAM at the end of the run.
Now Run It: Two Kernels, Both Methods
Both kernels run 1,200 rounds of 64 steps. On the good chip the shift kernel ends at cycle 1,004,426 and the byte kernel at 1,388,426. The model, run alone to the same end, leaves the chip's SRAM checksums: 01a59dfe and 984ac073.
ISS mismatch cycle=34 pc=8000002c field=rd_wdata rtl=1e3779b9 model=78dde6e4
shift kernel, model on: checker at cycle 43
ISS mismatch cycle=24 pc=80000038 field=rd_wdata rtl=ffdaa674 model=daa674
byte kernel, model on: checker at cycle 33shift kernel, model off: pass at cycle 1,004,426, sram 46e4cf93, model 01a59dfe: differs
byte kernel, model off: pass at cycle 1,388,426, sram 984ac073, model 984ac073: equalBug 1 was reported 1,004,392 cycles later than the step compare reported it. Bug 2 was never reported: its program passed, and so did its image. At 4 rounds the shift kernel's image differs in 64 of 64 words. The first is 80000400, last written at cycle 2,535 of 3,374: rule 3. The wrong SLL came at cycle 34.
And the price? On the laptop, the shift kernel of 1,200 rounds ran 5 times each way on the good chip. Every run took between 3.868 and 4.425 s, with the step compare or without. The two medians differ by less than the spread between runs: the compare's cost is lost in the noise.
add a0, a0, t5 # (keeps the high bit busy)
srli t1, a0, 8
andi t1, t1, 0xff # byte 1
srli t2, a0, 16
andi t2, t2, 0xff # byte 2Why It Is Built This Way
On this chip the step compare is nearly free. The core is in order and the model is fast C in the same process. Every value it cannot know is in the record. So our bench runs it on every test with the processor, and a mismatch ends the run.
The end-of-test compare earns its place where a model cannot follow the hardware step by step. The book's cache subsystem is one: two processors, caches and memory interleave their transfers in ways an instruction-level model does not time. A final image of memory still has one right answer, whatever the order in between.
This bench's sram field is a checksum, not an image. Two different images can share a checksum, though rarely. A real end-of-test compare dumps the words, as the practice problem does with the model's memory.
The Trap: The Bug That Washed Out
A team checks only final images. Its random programs pass, one after another. The bug in the byte kernel above is in their core too: every value it touched was masked before it was stored. Then a driver uses the full word, and the bug appears on silicon.
An image compare is a sample of the end, not a record of the run. Keep a step compare where you can afford one. Where you cannot, compare intermediate images, or add assertions that stop the run at once. The practice problem writes the end-of-test compare; the worksheet prices both.
At Scale
This section looks ahead. ap_soc has one core and no cache.
Caches and coherence
With caches, memory is right only after a flush; images are compared after it, and assertions watch the protocol on the way.
Long runs
Emulators run billions of cycles. A step compare there streams records off the box, and an image compare is often all there is.
Checkpoints
Comparing registers and memory at checkpoints splits the difference: latency of one interval, cost of a few compares.
Try It
Run the slice: for each bug and method, the cycle of the report and the last cycle of the run.
Which method reported bug 2, and at which cycle?
The predict question gives it the shorter runs.
shift left reversed, step compare: reported at cycle 34 of 43 shift left reversed, memory compare: reported at cycle 1004426 of 1004426 logical shift fills from the sign, step compare: reported at cycle 24 of 33 logical shift fills from the sign, memory compare: never reported (1388426 cycles run)Check Yourself
Common Mistakes
Wrong Compare only the final memory image.
A masked fault never reaches memory, and a late report hides its cause.
Fix Keep a step compare where the model can follow the core.
Wrong Debug from the first differing word.
The word may have been written long after the bug, many times.
Fix Find its last writer, then work back, or rerun with the step compare.
Wrong Skip the step compare to save time.
On this chip it costs about a hundredth of the run.
Fix Measure the cost before you drop a check.
Remember
- The step compare checks every record and reports the first wrong instruction at once.
- The end-of-test compare checks final images: it reports late, names a word, and misses masked faults.
- On this chip the step compare costs less than the spread between runs; it runs on every test with the processor.
- Use images where a model cannot follow the hardware step by step; keep step compares where it can.