H8.2 Local-Domain Flag Model

MediumFixIcarus · browser samples / server checksReview the topic

Fix a FIFO flag model that drops the pointer wrap bit, so a full FIFO does not look full.

Hardware context: Gray-pointer asynchronous FIFO with a declared reset and synchronization model. Model local full/empty flags using delayed remote pointer information.

Each side of an asynchronous FIFO computes its own flag. The write side computes full, and the read side computes empty. Each uses its own binary pointer and the other side's Gray pointer, caught through two flops.

The function domain_flags models one side. It decodes remote_gray to binary and returns that value with a blocked flag. blocked means full on the write side and empty on the read side. A side whose reset guard is still closed is always blocked.

With the write side a whole lap ahead, the model said not full. It had dropped the extra wrap bit, so full and empty looked alike. The tests try every pointer pair on both sides, at depth 4 and depth 8.

Find the bug and fix it.

Signals in the Timeline

SignalWidthRole
local_binary4input of each check
remote_gray4input of each check
address_bits3input of each check
write_domain1input of each check
armed1input of each check
Full specification
The function (keep its signature)
function automatic logic [79:0] domain_flags(input logic [3:0] local_binary, remote_gray,
                                             input logic [2:0] address_bits,
                                             input logic write_domain, armed);
Bits of the resultHolds
79:5Always 0.
4:1remote_binary: the decoded value of remote_gray.
0blocked: full on the write side, empty on the read side.
RuleMeaning
Depthdepth = 2^address_bits, so 4 or 8. Pointers have one more bit and run from 0 to 2 × depth − 1.
DecodeUse the low address_bits + 1 bits of remote_gray. Bit i of the binary value is the XOR of those Gray bits from the top down to bit i.
Write sideWith write_domain = 1, blocked = 1 when (local_binary − remote_binary) modulo 2 × depth equals depth. The writer is then a whole lap ahead.
Read sideWith write_domain = 0, blocked = 1 when local_binary equals remote_binary within the pointer bits.
Guardarmed = 0 means this side's reset guard is still closed. Then blocked = 1 on either side.

remote_binary is reported even when armed = 0.

The remote pointer can be up to two edges old. So full may stay 1 after the reader frees a slot, and empty may stay 1 after a write. Both errors are safe. They delay traffic but never lose or invent a byte.

Examples

Example 1

Write Side, a Whole Lap Ahead
Input
local_binary = 4, remote_gray = 0, address_bits = 2, write_domain = 1, armed = 1
Output
remote_binary = 0, blocked = yes

Depth is 4. The read pointer decodes to 0, and the write pointer is 4 ahead. That is a whole lap, so the write side is full and blocked.

Example 2

Read Side, Equal Pointers
Input
local_binary = 0, remote_gray = 0, address_bits = 2, write_domain = 0, armed = 1
Output
remote_binary = 0, blocked = yes

The write pointer decodes to 0, the same as the read pointer. Nothing is stored, so the read side is empty and blocked.

Example 3

The Guard Is Still Closed
Input
local_binary = 0, remote_gray = 1, address_bits = 2, write_domain = 0, armed = 0
Output
remote_binary = 1, blocked = yes

The write pointer decodes to 1, so one byte is waiting. The read side has not finished its reset release, so it stays blocked anyway.

Constraints and Contract

  • address_bits is 2 or 3. remote_gray is the copy after the two flops, not the live pointer of the other side.
  • Keep the function name, the argument names and their widths.

Hints

Hint 1

A pointer runs from 0 to 2 × depth − 1. Why does it need one bit more than the address?

Hint 2

Trace the first example. Depth is 4, so the pointers need 3 bits. Which bits does mask keep, and what is left of local_binary = 4?

Hint 3

Look at the line that sets mask. It keeps only the address bits. It must keep the wrap bit too: 2 × depth − 1.

What the grader checks: The tests try every pointer pair on both sides, with the guard open and closed, at depth 4 and depth 8. Some pairs never occur in real traffic. Passing shows the arithmetic of one side, not the timing between the two clocks.

1283 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Write Side, a Whole Lap Ahead

Input
local_binary = 4, remote_gray = 0, address_bits = 2, write_domain = 1, armed = 1
Expected output
remote_binary = 0, blocked = yes

Depth is 4. The read pointer decodes to 0, and the write pointer is 4 ahead. That is a whole lap, so the write side is full and blocked.

Run samples executes all 3 public checks. Check all tests runs 1283 checks on the server.

Icarus · browser samples / server checks