Verification #56 · 2026-11-18 · Stateful scoreboard · Medium · about 30 min
Build the testbench for a saturating accumulator
sat_acc.sv is a registered saturating accumulator. One operation is accepted on any clock edge where in_valid is 1, and one clock later out_valid is 1 for a clock with the accumulator's new value on acc (10 bits, signed, range -512 to 511). The operand val is signed 8-bit.
op |
operation |
|---|---|
| 0 | ADD: acc = clamp(acc + val) |
| 1 | SUB: acc = clamp(acc - val) |
| 2 | CLR: acc = 0 |
clamp saturates at -512 and 511 instead of wrapping. op 3 is reserved and must never be sent. The accumulator is 0 after reset.
Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name:
acc_item: randomop,valandgap(idle clocks before the item). Only ops 0, 1 and 2 may be generated. Constraingapto 0 to 3. Shapeopandvalso a run actually saturates the accumulator in both directions (CLR resets the running total, so it has to be rare) and sovalhits its extremes (-128 and 127) often.acc_seq: sendscountrandom items.acc_driver: waits out reset, waitsgapclocks, then presents one item for exactly one clock. Withgap0, items go back to back.acc_scoreboard: the DUT has state, so keep a model of the accumulator. For each item the monitor reports, in order, update the model fromopandval, then compare it withresult. Count items incheckedand mismatches inerrors; report the first few withuvm_error. The monitor'sresultis the 10-bit accumulator value after the operation (all X if the DUT never answered).
Run uses tb.sv: 50 random items into the correct accumulator. Submit runs your testbench against the correct accumulator and four faulty ones. Your scoreboard must stay quiet on the first and catch each of the others.
Write and run your answer in the browser. The hidden tests check it, and it’s free.