22Implementation
Grant the lowest request
Problem
Intended behavior. LowestRequest serves four requesters. Bit i of
req is requester i, and data(i) is that requester's 8-bit value. When
one or more requests are high, out carries the data of the lowest-numbered
requester. When no request is high, out is 0.
Current behavior. The starter drives out with a constant 0, so every
request pattern prints 0.
Task. Replace the constant with a selection that implements both rules.
Keep the module name and ports; the req Bools already split from io.req
are there for you to use.
Choose the selector shape
Before writing code, describe the selectors you have. Several requests can be high at once, so the conditions overlap. Some order must decide between them, and the case where no condition is true has its own required output. Go through the utilities in the Learn chapter's contract table and ask, for each one, what it does with overlapping selectors and what it returns when none is true.
Predict before running
The public run sets data to 11, 22, 33, 44 and prints req with the most
significant bit first. Predict out for 0100, 0110, 1010, 1000,
and 0000 before running your change. Choose one row with overlapping requests
and the idle row to distinguish a correct design from two tempting wrong ones.
Run and explain
Replace the constant, run, and compare all five rows with your prediction. For the two rows you marked, state what a selector that ORs overlapping data would print, and what a selector that falls through to its last value would print. Those differences are the reason your choice is correct, not luck on the sample.
Completion check
- Each of the 16 request patterns selects the lowest set bit's data.
- With no request,
outis 0, never one of the data inputs. - The selection follows
datafor any values, not only the four printed ones. - Two simultaneous requests return one requester's data, never a mixture.
Progressive hints
Hint 1
The idle row rules out one utility, and the rows with two requests rule out another. Which utilities remain?
Hint 2
PriorityMux has the right priority but no default argument. A utility with
an explicit default and first-listed-wins priority needs no extra logic.
Hint 3
The condition list can be built during elaboration with Seq.tabulate, pairing
req(i) with io.data(i). The list order decides who wins.
Concept
Selection utilities differ in their assumptions, not in their values on easy
inputs. Mux1H requires exactly one true selector; other cases have unspecified
results. Its current multi-input UInt implementation ORs the selected data,
which does not implement priority. PriorityMux resolves overlaps but falls through to its last value when
nothing is selected. MuxCase resolves overlaps by list order and returns an
explicit default, which matches both rules here.
Extension experiment
Change the rule so the highest-numbered requester wins. Predict the five public rows, and identify which part of your code is the only part that has to change.