Async FIFO Verification Part 2: bugs that only show up across clocks, with the write and read clock domains, a one-flop synchronizer bug and a 5 by 4 catch grid
|

Async FIFO Verification, Part 2: Bugs That Only Show Up Across Clocks

In short: Cross-clock bugs in an async FIFO often pass a scoreboard, because RTL simulation checks logic, not timing. Catch them with flag assertions (never early, late by at most 3 cycles), a one-bit-per-clock check on what crosses, and at least four clock ratios. In our 14 VCS runs, 3 bug runs were green on the scoreboard, and one bug passed every check we had.

In this part (Part 2 of 3):

  • 2 flag rules, and the 3-cycle limit counted edge by edge
  • A Gray check placed on the right signal
  • 4 clock ratios and 5 planted bugs
  • 14 real VCS runs, and a flowchart to name the bug from the log

New here? Start with Part 1: the design, the plan and the starter UVM bench.

Why cross-clock bugs hide from a scoreboard

A scoreboard checks what came out. Cross-clock bugs are about when a flag was allowed to change, and what the other clock saw while a value was moving.

RTL simulation settles a flop at the clock edge to the old or new value, while on silicon the output can hang and settle late
Simulation settles every flop at the clock edge. Silicon does not.
QuestionScoreboardAssertionsStatic CDC tool
Right data, right order?YesNoNo
Flag never early, late by at most 3?NoYesNo
Only Gray values cross?NoYesYes
Synchronizer has 2 flops?NoNoYes

Why it matters: “only about 24 percent of today’s projects can achieve first silicon success” (Harry Foster, Siemens EDA, 2022 Wilson Research Group study). Bugs that pass every test are the ones that cost a respin.

Flag assertions: write the lateness down

A flag can be wrong in two directions. They get two different rules.

DirectionRuleCheckWhy
EarlyNever, not even 1 cycleap_no_overflow, ap_no_underflowEarly full loses data. Early empty invents data
LateAllowed, up to 3 cyclesap_full_late, ap_empty_lateLate only costs a few cycles. But a limit stops a stuck flag passing
Flag rules on a cycle line: wfull may stay high for 3 wclk edges after space opens, the 4th edge fails, and an early drop fails at once
Late is fine for 3 wclk edges. Early is never fine.

Where the 3 comes from

After a write, the read side needs three rclk edges before rempty can drop:

  1. Edge 1: rq1_wptr picks up the new Gray pointer.
  2. Edge 2: rq2_wptr copies it, and the empty compare sees the write.
  3. Edge 3: the rempty register drops.

wfull is the same, counted in wclk edges.

A write reaches rempty in three rclk edges: first synchronizer flop, second flop, then the rempty register
A write reaches rempty on the third rclk edge: two synchronizer flops, then the flag register.

Measured, not just counted: the bench prints the worst lateness it sees. On the clean design VCS printed 3 for both flags, at every clock ratio.

The assertions

They live in their own module, bound into the design with bind. From there they can read the internal binary pointers and work out the true fill level, which only simulation can do.

localparam int LATE = 3;   // 2 synchronizer flops + 1 flag register

logic [ASIZE:0] level;
assign level = wbin - rbin;  // true fill level, 0 to DEPTH

// Never early: strict, no window
ap_no_overflow: assert property (@(posedge wclk) disable iff (!wrst_n)
  (winc && !wfull) |-> (level != DEPTH));

ap_no_underflow: assert property (@(posedge rclk) disable iff (!rrst_n)
  (rinc && !rempty) |-> (level != 0));

// Late is allowed, by at most LATE cycles of the flag's own clock
ap_full_late: assert property (@(posedge wclk) disable iff (!wrst_n)
  (wfull && level != DEPTH) |-> ##[1:LATE] !wfull);

ap_empty_late: assert property (@(posedge rclk) disable iff (!rrst_n)
  (rempty && level != 0) |-> ##[1:LATE] !rempty);

bind tav_async_fifo tav_fifo_sva #(.ASIZE(ASIZE)) u_sva (.*);

Two tips from the runs:

  • The extra pointer bit makes wbin - rbin wrap cleanly, so the level is always 0 to 16.
  • Print only the first 3 failures of each check. VCS also prints its own line per failure, and a broken FIFO fails thousands of times.

The Gray check: watch what actually crosses

Only Gray pointers should cross, because a Gray count changes one bit per step. A late sample is then still a real value.

Counting 7 to 8 flips 4 bits in binary but only 1 bit in Gray code
Counting 7 to 8: binary flips 4 bits at once, Gray flips 1.

The check is one line per side:

// The value entering each synchronizer changes at most one bit per clock
ap_gray_w: assert property (@(posedge wclk) disable iff (!wrst_n)
  $onehot0(w_cross ^ $past(w_cross)));

ap_gray_r: assert property (@(posedge rclk) disable iff (!rrst_n)
  $onehot0(r_cross ^ $past(r_cross)));

Put it on the right signal:

  • w_cross = the exact wire into the first synchronizer flop.
  • Not wptr. If the binary pointer is wired in by mistake, wptr is still a perfect Gray count, so a check on it stays green.
  • Analogy: check the note in the tray, not the note on the writer’s desk.
Where each check looks: flag assertions on each side, Gray assertions on the synchronizer inputs, synchronizer depth only in a static CDC tool
Each check watches a different place. Synchronizer depth needs a static CDC tool.

The flag checks sit on each side, the Gray checks sit on the crossings, and the one thing no simulation check can see sits underneath all of them.

Four clock ratios, four different tests

Each ratio pushes the FIFO into a different corner. A bug that hides at one ratio shows up at another.

Ratiowclk / rclk (ns)What it stressesMax fill level (VCS)
R1 slow reader10 / 17Full is hit often16
R2 fast reader23 / 10Empty is hit often, full never6
R3 near-equal10 / 11Edges drift slowly past each other16
R4 very slow reader10 / 40Full nearly all the time, empty rarely16

Clocks are made in the top module, with periods from +WCLK_NS and +RCLK_NS. rclk starts at an odd offset, so the edges drift.

The five planted bugs

Numbering carries on from Part 1’s bugs 1 and 2. Four bugs are in the design and one is in the bench, because a wrong check costs you days too.

+BUGWhereWhat’s wrongWhy it’s easy to miss
3DesignThe binary pointers cross instead of Gray. The compares are changed to match, so the design is consistentData stays correct in simulation
4DesignThe full compare inverts only the top bit: the binary rule used on Gray pointersIt’s one character away from the right line
5Designrempty is computed from the current read pointer instead of the next oneIt looks like a harmless style choice
6BenchA check that demands wfull drop one wclk after space opensIt reads like a sensible spec
7DesignOne-flop synchronizers instead of twoIt makes the FIFO faster

Bug 4: one character from correct

In Gray code, “one lap ahead” means the top two bits are inverted. Inverting only the top bit is the binary rule.

Gray full compare: the correct rule inverts the top two bits, bug 4 inverts only the top bit
Bug 4 inverts only the top Gray bit, so the full compare matches the wrong write pointer.

Where the pointers are decides what bug 4 does: sometimes full comes early, sometimes far too late.

// Correct: Gray rule, top two bits inverted
wfull_val = (wgraynext == {~wq2_rptr[ASIZE:ASIZE-1], wq2_rptr[ASIZE-2:0]});

// Bug 4: binary rule on Gray pointers, top bit only
wfull_val = (wgraynext == {~wq2_rptr[ASIZE],         wq2_rptr[ASIZE-1:0]});

Bug 5: one read late

Bug 5 timing: rempty stays low one extra rclk after the last word leaves, so a read on that cycle underflows
Bug 5 leaves rempty low one rclk too long, and a read on that cycle underflows.

A fast reader asks on that cycle often. A slow reader almost never does, which is why R4 was clean.

rempty_val = (rgraynext == rq2_wptr);  // correct: the pointer after this read
rempty_val = (rptr      == rq2_wptr);  // bug 5: the pointer before this read

What VCS printed: 14 runs

VCS X-2025.06-SP1, UVM 1.2, same seed, 300 writes per run. Clean runs first, to prove the checks stay quiet on a correct design: 0 errors at every ratio.

RunBugRatioScoreboardWords stuckLateness w / rAssertion failures
1 to 4noneall 40 errors03 / 3 (0 / 3 at R2)none
53 binary crossingR10 errors03 / 3Gray w 150, Gray r 150
63 binary crossingR20 errors00 / 3Gray w 150, Gray r 150
74 wrong full compareR1201 mismatches9615 / 3overflow 6, underflow 4, full late 29
84 wrong full compareR20 errors06 / 3full late 12
94 wrong full compareR4139 mismatches16016 / 3overflow 6, underflow 1, full late 64
105 empty one read lateR2678 underflows, 136 mismatches03 / 3underflow 25, overflow 3
115 empty one read lateR40 errors03 / 3none
126 strict bench checkR10 errors03 / 3strict full 152
136 strict bench checkR20 errors00 / 3none
147 one-flop syncR10 errors02 / 2none

The headline: 3 of the 10 bug runs (5, 6 and 8) were green on the scoreboard. Only an assertion caught them. Run 14 was green everywhere.

Catch grid of 5 planted bugs against scoreboard, flag assertions, Gray assertion and measured lateness from 14 VCS runs
No single check caught every bug in the 14 VCS runs.

What each bug teaches

BugLoud atQuiet atThe lesson
3 binary crossingneverevery ratio (scoreboard)Gray check fired 150 times per side: one for every step where binary flips 2+ bits
4 wrong full compareR1, R4: 139 to 201 bad reads, 96 to 160 words stuckR2: only ap_full_late (6 cycles late)Scoreboard saw fill levels of 120 and 174 in a 16-deep FIFO. Impossible, so it’s the full logic
5 empty one read lateR2: 978 reads for 300 writesR4: completely cleanThe clock ratio decides whether you ever see it
6 strict checkR1: 152 false alarmsR2: silent (no full)The check was the bug. The design was correct
7 one-flop syncneverevery checkOnly lateness changed, 3 to 2. See below

Fix the first failure first. In run 10, overflow fired too. That was a knock-on effect: once the read pointer passed the write pointer, the true level wrapped.

Name the bug from the log

Try this on your own runs before you open the waveform.

Flowchart to name the async FIFO bug from the COV and SVA log lines
Read the [COV] and [SVA] lines, then follow the flowchart to the bug.

Bug 7: a green run that’s still unsafe

Run 14 by the numbers: 0 scoreboard errors, 0 assertion failures, full and empty both reached. Every dashboard says done.

On silicon it’s unsafe. With two flops, the first flop gets a whole clock cycle to settle before anything reads it. With one, a value that’s still settling goes straight into the flag compare.

Two-flop synchronizer versus one-flop: with one flop the compare can read a settling value
With one flop, the compare can read a value that is still settling.

Simulation can’t see it, because a simulated flop always settles at the clock edge. One flop just looks faster.

The only fingerprint: measured lateness was 2 / 2, not the 3 / 3 of every clean run. That’s why the bench prints lateness as a number. Try adding a cover on “lateness reached 3” as an exercise: it would show a hole for bug 7. (Not in the download yet, and not tested.)

What actually catches it

  • A static CDC tool. It reads the structure: which signals cross, and whether each crossing has a proper synchronizer. This is the right tool, and it’s row 9 of the Part 1 plan.
  • A design review. Counting flops on every crossing takes minutes, and a reviewer who knows to look will see it.
  • CDC-aware simulation, where your flow has it. Some CDC flows can add random extra delay at synchronizer outputs during simulation, so timing uncertainty becomes something a bench can see.

Say it in the review: “Simulation passed, lateness matches two flops, and CDC sign-off comes from the static tool.”

Run it yourself

  1. Download async_fifo_p2.sv (design, assertions, UVM bench and top in one file).
  2. On EDA Playground pick Synopsys VCS and UVM 1.2, and paste the file.
  3. Put each run’s options in Run Options, like this:
vcs -full64 -sverilog -ntb_opts uvm-1.2 async_fifo_p2.sv -R +BUG=0 +WCLK_NS=10 +RCLK_NS=17
  1. Run the 4 clean ratios first (+BUG=0), then each bug at R1 and R2.
  2. Read only the [COV] and [SVA] lines and name the bug with the flowchart above. Then check the table.

Check: every log starts with async_fifo_p2: planted bug = N, wclk = .. ns, rclk = .. ns. If N shows 0, add +define+BUG=N to the compile options. All user names use the tav_ prefix, the house style on this site.

Common mistakes

MistakeWhat happensFix
Gray check on wptr, not on what crossesBug 3 stays greenCheck the synchronizer input (w_cross)
One window for both directionsAn early flag passes for N cycles, and data is lostEarly: strict. Late: windowed
A guessed window“1 cycle” fails a correct design (bug 6). “10” misses bug 4 at R2 (6 late)Count your flops, then measure
One clock ratioBug 4 quiet at R2, bug 5 clean at R4Run at least 4 ratios
Fixing the second failure firstYou chase a knock-on effectStart from the earliest failure in time
Calling a green run CDC-cleanBug 7 shipsCDC sign-off comes from structure

How AI helps (and where it doesn’t)

AI helps withAI doesn’t help with
Boilerplate: the bind, counters, “print first 3” action blocksThe window. AI-written checks often demand an exact cycle: that’s bug 6, 152 false alarms
A second read of a compare line: “Gray rule or binary rule?” (check it against Cummings)Bug 7. Nothing that reads a passing log can see synchronizer depth

More in AI in ASIC verification and the AI-written vs hand-written UVM testbench experiment.

What’s next in the series

Part 3 (February): reset on one side at a time, covergroups that prove every fill level and every pointer wrap, and a sign-off checklist you can take into a review.

FAQ

How late can an async FIFO’s full or empty flag be? With two-flop synchronizers and a registered flag, 3 cycles of the flag’s own clock after the other side moves its pointer. In our VCS runs the measured worst case was exactly 3 at every clock ratio.

Can a flag ever be early? Not in a correct design. An early full flag lets a write overwrite unread data, and an early empty flag lets a read take data that isn’t there. Check that direction with no window.

Why check $onehot0 on the synchronizer input and not on the Gray pointer? Because the bug is in what crosses. If the binary pointer is wired in by mistake, the Gray pointer itself is still a perfect Gray count, and a check on it stays green.

Why did the scoreboard pass bug 3? In RTL simulation a flop never samples a value halfway through a change, so a binary pointer crosses cleanly every time. The danger only exists on silicon.

How many clock ratios should I run? At least four: a slow reader, a fast reader, near-equal clocks, and a very slow reader. In our runs, bug 4 was quiet at the fast-reader ratio and bug 5 was clean at the very slow one.

Can simulation prove a FIFO is CDC-safe? No. It proves the logic. Structure and synchronizer depth come from a static CDC tool and a design review.

References

Read next

Leave a Reply

Your email address will not be published. Required fields are marked *