Fix an asynchronous FIFO scoreboard that counts every byte but never checks its value.
Hardware context: Gray-pointer asynchronous FIFO with a declared reset and synchronization model. Check accepted data order under independent clocks and clock pauses.
A checker watched an asynchronous FIFO through a whole regression and reported no errors. Later, a corrupted byte turned up in the output. The checker had counted every byte, but it never compared one.
The function verify_cdc reads 128 sampled events from the FIFO pins. It returns one report entry per event: an error mask and four counts. The counts are bytes written, bytes read, bytes thrown away by reset and bytes still waiting.
The tests replay a real FIFO at several clock ratios, with pauses and resets. Some tests then plant one fault in the samples, such as a changed read byte. The checker must stay silent on clean samples and flag each planted fault on the right event.
In this problem check_visibility is 0, so flag timing is not checked. Find the bug and fix it.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
address_bits | 3 | input of each check |
reset_events | 3 | input of each check |
observation_fault | 3 | input of each check |
Full specification
function automatic string verify_cdc(input logic [4095:0] samples, input int aw, input bit check_visibility);
| Part | How this FIFO works |
|---|---|
| Size | Depth 4 (AW = 2) or depth 8 (AW = 3). Each entry is one byte. |
| Pointers | Each side counts in binary with one extra wrap bit. A pointer runs from 0 to 2 × depth − 1. |
| Crossing | Each side sends a Gray copy of its pointer. The other side catches it in two flops of its own clock. |
| Flags | full compares the write pointer with the read pointer after both flops. empty compares the read pointer with the write pointer after both flops. |
| Admission | A request is accepted on an edge only when the flag before that edge allows it. There is no look-ahead. |
| Edges together | When both clocks rise in one event, each side samples the other side's pointer from before the event. |
| Simulation | The flops have no metastability here. Each flop simply delays a value by one edge of its clock. |
| Reset rule | Meaning |
|---|---|
| Assert | One shared reset clears both sides at once, even while a clock is stopped. It does not wait for an edge. |
| Release guard | Each side has a guard. After reset falls, the guard opens after two rising edges of that side's own clock. |
| Before release | While its guard is closed, the write side shows full = 1 and the read side shows empty = 1. |
| Traffic | The tests offer no new requests until both guards are open. |
| Flush | Reset throws away every unread byte. A thrown-away byte must never come out later. |
| Bits of a sample | Holds |
|---|---|
| 0 | pre_full: full just before the edges of this event. |
| 1 | pre_empty: empty just before the edges. |
| 2 | write_edge: wclk rises in this event. |
| 3 | read_edge: rclk rises in this event. |
| 4 | reset: reset is high in this event. |
| 5 | write_en: the write request. |
| 6 | read_en: the read request. |
| 7 | write_accepted after the event. |
| 8 | read_valid after the event. |
| 16:9 | write_data: the byte offered for writing. |
| 24:17 | read_data after the event. |
| 25 | warmed: the write guard after the event. |
| 26 | rarmed: the read guard after the event. |
| 31:27 | Always 0. |
Event t sits in bits 32t + 31 down to 32t, so event 0 is in the lowest bits. There are always 128 events. aw is 2 for depth 4 or 3 for depth 8.
| Step | Rule for each event |
|---|---|
| Reset event | Add the waiting bytes to canceled and empty the queue. Clear both counts, both histories and both edge counters. Skip the edge rules; only the reset checks and the balance check apply. |
| Reset checks | Set bit 5 if write_accepted, read_valid, warmed or rarmed is 1. With check_visibility = 1, set bit 3 unless pre_full and pre_empty are both 1. |
| Flags | With check_visibility = 1, predict full and empty as in the next table. Set bit 3 if either pin differs. |
| Write receipt | On a write edge, write_accepted must equal write_en and not pre_full and an open write guard. Otherwise set bit 0. |
| Read receipt | On a read edge, read_valid must equal read_en and not pre_empty and an open read guard. Otherwise set bit 1. |
| Read | On a read edge with read_valid = 1, count the read. Pop the oldest waiting byte and set bit 2 if it differs from read_data. If nothing is waiting, set bit 4 and pop nothing. |
| Write | On a write edge with write_accepted = 1, count the write and push write_data. If depth bytes were already waiting, set bit 4 but still push. |
| Order | Retire the read before you add the write. A receipt counts only on its own edge, because it holds its value between edges. |
| Guards | After the edges, warmed must be 1 exactly when the write side has had two or more edges since reset. The same holds for rarmed. Otherwise set bit 5. |
| Balance | Writes must equal reads + canceled + waiting. Otherwise set bit 6. |
A guard is open when its side has had two or more edges since the last reset, counted before this event.
In this problem check_visibility is always 0. The visibility rules below apply only when it is 1, so bit 3 stays 0 here.
| Visibility rule | Meaning |
|---|---|
| Counts | wcount and rcount count the accepted writes and reads since the last reset. |
| Histories | The write side keeps two history stages of rcount. The read side keeps two stages of wcount. |
| Shift | On a write edge, the second stage takes the first stage, and the first stage takes rcount from before this event. The read side does the same with wcount. |
| Edges together | When both clocks rise in one event, each side samples the other side's count from before the event. |
| full | full = 1 when the write side has had fewer than two edges since reset. It is also 1 when (wcount − second stage) modulo 2 × depth equals depth. |
| empty | empty = 1 when the read side has had fewer than two edges since reset. It is also 1 when rcount equals the second stage, modulo 2 × depth. |
Each event adds one entry to the report. It is the error mask as two hex digits, a colon, four decimal counts and a semicolon. The counts are writes, reads, canceled and waiting, separated by commas. For example, 04:4,1,0,3; is a data error after 4 writes and 1 read, with 3 bytes waiting. Writes, reads and canceled keep counting across resets.
| Planted fault | What changes in the samples |
|---|---|
| 0 | Nothing. The samples are clean. |
| 1 | Bit 7 of read_data is flipped on the first accepted read. |
| 2 | write_accepted is cleared on the first accepted write. |
| 3 | pre_full is flipped at event 7. |
| 4 | warmed is flipped at event 4. |
| 5 | read_valid is set on the first reset event. |
The checker sees only the pins. It never sees the FIFO's pointers or memory, so it keeps its own queue of waiting bytes.
The whole report string is compared with the expected one. The result shows its length, the expected length and whether the two match.
Simulation checks logic only. A real design also needs a CDC review of both synchronizer chains and reset recovery and removal checks. It also needs skew limits on the Gray buses and an MTBF target.
Examples
Example 1
A Clean Run with a Fast Writer- Input
aw = 2, planted fault 0. The write clock rises every event, the read clock every third event. No reset after the start.
- Output
report_length = 1571, expected_length = 1571, match = yes
The first read is accepted at event 21. In all, 25 bytes go in and come out in order. Every entry has error mask 00, and the last one is 00:25,25,0,0.
Example 2
Reset While the Read Clock Is Stopped- Input
aw = 2, planted fault 0. Write clock every event, read clock every third. The read clock stops for events 20 to 34 and the write clock for 40 to 59. Reset at event 21.
- Output
report_length = 1493, expected_length = 1493, match = yes
Four bytes are waiting at the reset, so the entry for event 21 is 00:4,0,4,0. Those bytes count as canceled and never come out. The last entry is 00:14,10,4,0.
Example 3
A Changed Read Byte- Input
The clean run of the first example, with planted fault 1.
- Output
report_length = 1571, expected_length = 1571, match = yes
The first read returns 0x36 instead of 0xb6. The counts do not change, so only the value check sees it. The entry for event 21 is 04:4,1,0,3, and every other entry stays clean.
Constraints and Contract
- Each test gives all 128 samples and one planted fault at most. Clean samples must give error mask 00 on every event.
- Keep the waiting bytes in a queue of your own, apart from the FIFO's circular addresses.
- Keep the function name and its arguments.
Hints
Hint 1
Start from the queue. When a read is accepted, which byte should come out? Where does the checker look at it?
Hint 2
Planted fault 1 changes one bit of the first read byte. The counts stay the same, so only a value check can catch it.
Hint 3
Look at the read branch, where the checker pops the oldest byte. It never compares read_data with queue_data[0] before the pop. Set bit 2 when they differ.
What the grader checks: The samples come from a real two-clock FIFO at several clock ratios, with pauses and resets. Planted faults test both false alarms and missed errors. Logic checks cannot replace CDC, reset and timing review.
54 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 8 steps and the final capstone