20Verification
Repair the burst-length table
Problem
Intended behavior. BurstBeats decodes a 3-bit burst code into a beat
count. Codes 0, 1, 2, 3, and 4 mean 1, 2, 4, 8, and 16 beats. Codes 5, 6, and
7 are reserved and must produce 0.
Observed behavior. The starter compiles and prints a line for every code, but two of the lines do not match the table.
Task. Find the defect in the lookup and correct it. Keep the module name,
its ports, and the use of MuxLookup with 0 as the default.
Run and compare
Run the starter and compare each printed line with the specification. Write down the two wrong codes and what each one returned. The two symptoms have a single cause; one of them does not even look like the same bug at first.
Diagnose
For each wrong code, ask how many entries of the mapping have a key equal to
that code. If none does, which value does MuxLookup fall back to? If more
than one does, which entry ends up in charge? The Learn chapter's
variations describe how a lookup built from a list resolves two entries with
the same key.
Fix, run, and explain
Correct the mapping and run again. All eight lines must match the table. Explain how one wrong key produced both symptoms: which code lost its entry, and which code received a value that belonged to it.
Completion check
- All eight codes return the beat count from the specification.
- Each legal code appears as a key exactly once.
- Reserved codes still reach the default; none of them is listed explicitly.
- Removing an entry alone is not a repair: a code without its own key returns the default.
Progressive hints
Hint 1
One wrong line returns the default. That code has no key of its own in the mapping.
Hint 2
The other wrong line returns a value that belongs to its neighbour. Look for a key that is listed twice.
Concept
MuxLookup turns its list into a chain of comparisons. Keys are expected to be
distinct, and Chisel does not check that they are. In this implementation, the
last-listed entry for a duplicated key overrides the earlier one silently, and the
code that should have owned that entry falls through to the default.
Extension experiment
Predict the output for all eight codes if the 16-beat entry were accidentally written with key 2 as well. Then explain how a reviewer could spot this kind of defect from the source alone, without running anything.