Skip to content

BUG-005: Wrong expected value for remu check in cpu_peak_tests.asm

Field Value
Severity LOW
Component Testbench
File(s) tb/cpu_peak_tests.asm
Status Fixed
Date 2026-07-19

Symptom

After fixing BUG-004, run_riscv_program ran to completion but failed a genuine register assertion:

t4 [x29]  actual=0x00000000  expected=0x00000037  [FAIL ✗]
1 register assertion(s) FAILED

Root Cause

The test's own comment miscalculated the expected value:

# remu t4, s5, s1  →  88560 % 205 = 55  (88560 = 205×431 + 55)
remu t4, s5, s1             | 0x029AFEB3 | cpu | t4==55

205 × 431 + 55 = 88410, not 88560. The correct factorization is 205 × 432 = 88560 exactly, so 88560 % 205 = 0. The RTL (ALU_REMU in rtl/alu.sv) computed the correct answer (0); the test's hand-derived expected value was simply arithmetically wrong.

Confirmed independently outside the design: iverilog evaluating 32'd88560 % 32'd205 in isolation also returns 0.

Fix

- # remu t4, s5, s1  →  88560 % 205 = 55  (88560 = 205×431 + 55)
- remu t4, s5, s1             | 0x029AFEB3 | cpu | t4==55
+ # remu t4, s5, s1  →  88560 % 205 = 0  (88560 = 205×432, exact)
+ remu t4, s5, s1             | 0x029AFEB3 | cpu | t4==0

Notes

s5 = 88560 is itself the product of a mul chain in the same program (29520 × 3), so it's worth double-checking hand-derived expected values in .asm fixtures with a calculator rather than mental arithmetic — this one went unnoticed because BUG-004 masked it behind a SimFailure for an unknown amount of time.