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_v is ignored on this clock. With no open run, nothing is emitted.
  • data (in_v = 1): if a run is open, in_d equals 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: random v, d, flush and gap (idle clocks before the item). Every item does something: v or flush (or both) is set. Make data-only items by far the most common, then flush-only, with both together rare. Make d mostly 8'h00, often 8'h80, rarely 8'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. Make gap mostly 0, sometimes 1 to 3, rarely up to 12.
  • rl_seq: sends count random items.
  • rl_driver: waits out reset, then for each item waits gap clocks with in_v and flush at 0, drives in_v, in_d and flush for exactly one clock, and returns both to 0. With gap 0, the next item follows on the very next clock.
  • rl_scoreboard: write is 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 compare t.o_v (and t.o_d, t.o_n when o_v is set) with the expectation first, then apply t.flush / t.v to the model. Count every call in checked, every call with v or flush set in ops, and mismatches in errors; report the first few with uvm_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.