A multi-bit bus sampled directly across clock domains can arrive as an impossible hybrid value — bits from one clock edge mixed with bits from another. This is bus tearing. Single-bit synchronizers do not fix it. You need a protocol: Gray counters, handshake, or FIFO.
When a multi-bit signal changes while the receiver samples it, different bits may reflect different source cycles. The sampled value may never have existed on the source — corrupting pointers, status words, or configuration buses.
Lesson 9.6 taught synchronizer chains for single control bits. Stretching that to a 32-bit counter by placing 2-FF on every bit is a classic CDC failure — each bit settles at a different time.
Binary rollover flips all bits — maximum tearing risk. Gray code changes one bit per increment.
Never write assign count_b = count_a_sync; with per-bit 2-FF on a binary counter used as a pointer or level indicator. Lint tools flag this; silicon may pass sim then fail in corner silicon.
Gray encoding guarantees only one bit changes per increment. If the receiver samples during a transition, the value is either the old Gray word or the new one — both valid, never a third impossible state.
| Binary | Gray (4-bit) | Bits changed |
|---|---|---|
| 0000 | 0000 | — |
| 0001 | 0001 | 1 |
| 0010 | 0011 | 1 |
| 0011 | 0010 | 1 |
| 0100 | 0110 | 1 |
| 0111 | 0100 | 1 |
| 1000 | 1100 | 1 |
// Binary to Gray — one combinational xor tree function automatic [WIDTH-1:0] bin2gray(input [WIDTH-1:0] bin); bin2gray = bin ^ (bin >> 1); endfunction // Gray pointer in write domain, sync to read domain always @(posedge wr_clk) begin wr_ptr_gray <= bin2gray(wr_ptr_bin); end // Each bit through 2-FF in rd_clk — safe because only 1 bit changes/cycle
// Gray to binary on receive side
function automatic [WIDTH-1:0] gray2bin(input [WIDTH-1:0] gray);
integer i;
gray2bin[WIDTH-1] = gray[WIDTH-1];
for (i = WIDTH-2; i >= 0; i = i - 1)
gray2bin[i] = gray2bin[i+1] ^ gray[i];
endfunction
wire [PTR_W-1:0] rd_ptr_sync_gray /* 2-FF per bit */;
wire [PTR_W-1:0] rd_ptr_sync_bin = gray2bin(rd_ptr_sync_gray);
Gray is for monotonic counters/pointers — not arbitrary data buses. A 32-bit status register with random field updates still needs handshake or FIFO.
Gray does not eliminate metastability — you still need 2-FF per bit. It eliminates impossible data values.
| Scenario | Don't | Do |
|---|---|---|
| Single control pulse | Stretch pulse with combo logic in receiver | Toggle sync or pulse stretcher in source domain |
| FIFO read/write pointers | Sync binary pointers directly | Gray pointers + 2-FF + full/empty math in safe domain |
| 32-bit config register | Sample bus with 2-FF per bit | Handshake (req/ack) or shadow register + toggle |
| Streaming data | Wide bus + hope | Async FIFO (Lesson 9.5) or AXI CDC bridge |
| Level indicator (credit count) | Binary counter cross-domain | Gray if monotonic; else handshake |
// ANTI-PATTERN: binary status bus "synchronized" per bit reg [31:0] status_a; reg [31:0] status_b_meta, status_b; always @(posedge clk_b) begin status_b_meta <= status_a; // each bit from different clk_a cycle! status_b <= status_b_meta; end // Consumer may decode impossible mode bits → FSM escape
// Safe config update: latch in src, pulse toggle, ack in dst
always @(posedge clk_a) begin
if (cfg_wr) begin
cfg_shadow <= cfg_wdata; // stable before toggle
toggle_a <= ~toggle_a;
end
end
// toggle_a → 2-FF → toggle_b_sync
// Edge on toggle_b_sync means "sample cfg_shadow (held on bus or registered)"
Async FIFOs (Lesson 6.8 overview, CDC course) cross pointers, not data buses directly. Write pointer increments in wr_clk, converts to Gray, syncs to rd_clk, converts back to binary for full/empty math.
// Pointer sync — the pattern behind every async FIFO reg [PTR_W:0] wr_ptr_bin, wr_ptr_gray; // extra bit for full/empty always @(posedge wr_clk) wr_ptr_bin <= wr_ptr_bin + (wr_en && !full); always @(posedge wr_clk) wr_ptr_gray <= bin2gray(wr_ptr_bin); // wr_ptr_gray → 2FF per bit in rd_clk → gray2bin → rd_ptr_sync // Full when (wr_ptr_sync - rd_ptr) == DEPTH (Gray math in safe domain)
Gray pointers must be one step monotonic. Skipping values or decrementing by more than one per cycle reintroduces multi-bit transitions. Also: pointer width is ADDR_W+1 bits to distinguish full from empty.
// Full/empty uses Gray-synced pointers — compare in same domain wire [PTR_W:0] wr_ptr_gray_rd; // wr_ptr synced to rd_clk via 2FF each bit wire [PTR_W:0] rd_ptr_bin_rd = gray2bin(rd_ptr_gray); wire [PTR_W:0] wr_ptr_bin_rd = gray2bin(wr_ptr_gray_rd); assign empty = (rd_ptr_bin_rd == wr_ptr_bin_rd); // same clock domain now // Full computed symmetrically in wr_clk domain // MSB trick: (PTR_W+1)-bit pointers disambiguate full vs empty
| Anti-pattern | Why it fails | Replacement |
|---|---|---|
| XOR "balance" sync on bus | Still multi-bit, still tears | FIFO or handshake |
| Sample bus on slow clock without hold | Source may change mid-sample | Req/ack or registered shadow |
| Gray on non-monotonic counter | Multi-bit transitions return | Handshake only |
| Waive CDC_MULTI_BIT without protocol | Signoff debt | Fix RTL or document FIFO |