Verification #72 · 2026-12-04 · Scoreboard for a stateful encoder · Medium · about 30 min
Build the testbench for a run-length encoder
rle.sv is a run-length encoder. Bytes come in; (value, count) pairs come out, with runs of at most 4. On each clock after reset, with this priority:
- flush (
flush= 1): if a run is open, it is emitted and closed.in_vis ignored on this clock. With no open run, nothing is emitted. - data (
in_v= 1): if a run is open,in_dequals its value and its count is below 4, the count goes up by one. Otherwise the open run (if any) is emitted, and a new run(in_d, 1)opens. - neither: nothing happens.
The output is registered: o_v is 1 for exactly one clock per emitted pair, and o_d, o_n carry the pair. On any clock the pins show what the previous clock emitted.
Write the verification components in components.sv. The monitor and environment in env.sv are provided, and they use your four classes by name. The monitor reports every clock, idle ones too: for each clock it sends one rl_item with v, d and flush as the DUT is about to sample them, and o_v, o_d, o_n as they are on the pins at that same clock.
rl_item: randomv,d,flushandgap(idle clocks before the item). Every item does something:vorflush(or both) is set. Make data-only items by far the most common, then flush-only, with both together rare. Makedmostly8'h00, often8'h80, rarely8'h01, and otherwise any byte, so that long runs of equal bytes, and neighbors that differ only in the top bit, happen all the time. Makegapmostly 0, sometimes 1 to 3, rarely up to 12.rl_seq: sendscountrandom items.rl_driver: waits out reset, then for each item waitsgapclocks within_vandflushat 0, drivesin_v,in_dandflushfor exactly one clock, and returns both to 0. Withgap0, the next item follows on the very next clock.rl_scoreboard:writeis called once per clock. Keep a model of the encoder (open run, value, count) and of the pair it should emit on the next clock. On each call comparet.o_v(andt.o_d,t.o_nwheno_vis set) with the expectation first, then applyt.flush/t.vto the model. Count every call inchecked, every call withvorflushset inops, and mismatches inerrors; report the first few withuvm_error.
Run uses tb.sv: 50 random items into the correct encoder. Submit runs your testbench against the correct encoder and six 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.