Async FIFO Design with AI Assistance: An Engineering Practice Guide

    This article explains how to use AI coding tools to build a reliable asynchronous FIFO instead of just generating plausible-looking RTL. It covers writing a precise specification first (depth, width, accept conditions, read-data timing), splitting the design into reviewable modules, using Gray-coded pointers with proper synchronizers and physical constraints, deriving empty/full flags from next-state logic, handling dual-port memory and reset as part of the protocol, and closing the verification loop with a reference model, directed corner cases, assertions, static CDC checks and formal methods. It also proposes a staged, traceable iteration workflow for AI-assisted development.

    1. From “Generating Code” to “Building a Verifiable Design”

    In chip development, the asynchronous FIFO is a small module that tends to expose engineering details. It bridges two clock domains, decoupling traffic while preserving data order, and is commonly used in data acquisition, interface bridging, and rate matching between pipeline stages.

    AI coding tools can generate module structure, RTL, and a testbench from a text description. But complete code and clean naming do not mean the design is sound. The real difficulty of an asynchronous FIFO is not the read/write counters; it is passing information across clock domains, computing the empty/full boundaries correctly, and keeping reset and memory behavior consistent.

    So the effectiveness of AI-assisted design should not be judged by the subjective standard of “this looks like code an experienced engineer would write.” Instead, answer four questions:

    • Are the requirements clear and the interface semantics complete?
    • Does the structure follow established clock-domain-crossing (CDC) design principles?
    • Has the functionality been verified against boundary scenarios?
    • Do synthesis and physical implementation preserve the design assumptions?

    Only when all four questions have explicit answers does generated code have a chance of becoming a deliverable engineering asset.

    2. Write the Specification First, Then Let the Tool Generate the Implementation

    2.1 Define Capacity and Data Width

    The design inputs should include at least data width, storage depth, read and write clocks, and the reset strategy. For the common Gray-code pointer scheme, the storage depth is usually a power of two.

    Let the FIFO depth be:

    1. DEPTH = 2^A

    Then the storage address needs A bits, and the read and write pointers need A+1 bits. The extra bit distinguishes states that have “the same address but a different number of wraps,” which is what makes empty/full detection possible.

    This derivation applies to FIFOs with a depth of at least 2 that use the standard circular pointer structure. Supporting an arbitrary depth is not just a parameter change: the pointer wrap-around, encoding conversion, and full-detection algorithm all need to be re-examined.

    2.2 Define the Interface Accept Conditions

    The specification should define:

    1. Write accepted: write_enable AND NOT full
    2. Read accepted: read_enable AND NOT empty

    Pointer advancement and memory access must use the same accept condition. Otherwise you can end up with a pointer that has moved while the memory was never written, or data that has been read while the read pointer was not updated.

    For the cases of writing while full and reading while empty, state which policy applies. The common approach is to reject the request and leave the relevant pointer unchanged. If errors must be reported, provide separate overflow, underflow, or illegal-request status; do not leave the interface behavior to be guessed by the user.

    2.3 Define the Read Data Timing

    “Reading one entry” is not a complete interface definition. Also specify:

    • On which clock edge a read request is accepted;
    • Whether data is valid in the same cycle or a later cycle;
    • Whether a separate data-valid signal is provided;
    • Whether the output holds its previous value or shows some other defined behavior when no valid read occurs.

    Synchronous-read and combinational-read memories have different external timing. If the testbench assumes zero latency while the implementation uses a registered output, a correct design may be flagged as broken; conversely, sloppy comparison timing can hide data misalignment.

    3. Architecture Partitioning: Give Each Module a Clear Responsibility

    An asynchronous FIFO that is easy to review can be split into:

    1. Write-domain control module: maintains the write binary and Gray pointers, generates the full flag, and controls writes.
    2. Read-domain control module: maintains the read binary and Gray pointers, generates the empty flag, and controls reads.
    3. Read-pointer synchronizer: synchronizes the read Gray pointer into the write clock domain.
    4. Write-pointer synchronizer: synchronizes the write Gray pointer into the read clock domain.
    5. Dual-port memory module: stores and outputs data under independent read and write clock control.
    6. Top-level module: connects the interface, reset, pointers, and memory.

    The value of modularization is not more files; it is that responsibility boundaries become checkable. For example, the write-domain logic may decide available space only from the local write pointer and the synchronized read pointer, and must never use the other domain’s binary pointer directly.

    The architecture diagram should express these relationships rather than showing a few boxes. At minimum it should mark both clock domains, pointer widths, synchronization direction, the number of synchronizer stages, and the distinction between the data path and the status path. Only such a diagram genuinely serves design review and documentation maintenance.

    4. Gray-Code Pointers: Reducing Inconsistency Risk in Cross-Domain Sampling

    4.1 Why a Binary Counter Cannot Be Synchronized Directly

    When a binary counter increments, several bits may flip at once. Going from 0111 to 1000, for example, changes all four bits. Because path delays and sampling instants differ, the receiving clock domain may capture a combination that is neither the old value nor the new one.

    Adding a synchronizer register per bit does not automatically solve the consistency problem of a multi-bit binary bus.

    The property of Gray code is that only one bit changes between adjacent count values. The usual conversion is:

    1. gray = binary XOR (binary >> 1)

    Locally, the binary pointer is still used for incrementing and for memory addressing; only the registered Gray pointer crosses the clock domain.

    4.2 A Synchronizer Is Not a Device That “Eliminates Metastability”

    The receiving side typically uses two or more synchronizer stages to reduce the probability of metastability propagating into downstream logic. A synchronizer cannot guarantee that metastability never occurs; its reliability depends on clock frequency, how often the input changes, device characteristics, and the available resolution time.

    In the design, avoid driving functional logic from the first synchronizer stage’s output, and do not insert combinational logic into the synchronizer chain. The crossing pointer should be driven by a register in the source clock domain to reduce the extra risk from combinational glitches.

    Also, the receiving side does not need to observe every intermediate pointer value. When the two clocks differ in frequency, skipping some Gray states is normal. What matters is that the pointer state obtained by the receiver can be used for a safe, conservative capacity decision.

    4.3 Correct Encoding Still Needs Physical Constraints

    A single-bit change in Gray code at the logic level does not mean the post-layout implementation automatically satisfies all CDC assumptions. If the propagation delays of different bits differ too much, consecutive source-side changes can produce unwanted overlap at the receiver.

    Therefore, set appropriate maximum-delay or bit-to-bit skew constraints for the crossing Gray bus according to the implementation environment, and check them together with clock characteristics. Declaring the paths asynchronous is not enough to consider the CDC design closed.

    5. Empty/Full Detection: Next State and the Extra Pointer Bit

    5.1 Generating the Empty Flag

    In the read domain, the read pointer being equal to the synchronized write pointer means there is currently no data to read.

    If the empty flag is registered, a common implementation computes the next read pointer first and then compares:

    1. read_next = read_binary + accepted_read
    2. read_gray_next = gray(read_next)
    3. empty_next = (read_gray_next == synchronized_write_gray)

    This way, after the last accepted read, the empty flag updates with that same read clock edge, avoiding boundary offsets caused by using a stale state version.

    5.2 Generating the Full Flag

    For a standard power-of-two depth FIFO, the FIFO is full when the write pointer is one complete capacity ahead of the read pointer.

    In the common A+1-bit reflected Gray implementation, the full condition can be expressed as: the next write Gray code equals the synchronized read Gray code with its top two bits inverted and the remaining bits unchanged.

    1. write_next = write_binary + accepted_write
    2. write_gray_next = gray(write_next)
    3. full_next =
    4. write_gray_next == invert_top_two_bits(synchronized_read_gray)

    It cannot simply be written as “invert the most significant bit only,” because the change of the extra bit in the binary pointer affects the top two Gray bits. The implementation should also check the minimum parameter configuration to avoid empty or illegal bit-slice ranges.

    The code above is an algorithm sketch; it cannot be treated as a complete implementation without the bit widths, reset, and register-update rules.

    5.3 Synchronization Delay Usually Produces Conservative Behavior

    After a write has occurred but the write pointer has not yet reached the read domain, the read side may still appear empty for a while; after a read has freed space but the read pointer has not yet reached the write domain, the write side may still appear full.

    This delay usually means readable data or available space is estimated conservatively rather than data being lost immediately. The system design must accept the corresponding recovery latency; the empty/full flags of an asynchronous FIFO cannot reflect global occupancy in real time the way a single-clock counter does.

    6. Dual-Port Memory and Reset: Two Problems Easily Hidden by Code Appearance

    6.1 The Memory Model Must Match the Implementation Target

    The dual-port memory module must define independent-clock read and write, the read latency, and the behavior on same-address read/write collisions. Different implementation resources support same-address access and output semantics differently, so behavioral simulation results alone do not prove the hardware behaves the same way.

    Correct FIFO control prevents reading data that has not been validly written and prevents overwriting data that has not been read, but the specific memory model still needs review. In particular, during reset, boundary advancement, and output-register updates, the testbench should compare at the defined valid-data time.

    6.2 Reset Is Part of the Protocol

    A common strategy is to assert reset asynchronously and release it synchronously within each clock domain, while clearing the local pointers and the synchronizer chain and establishing the initial state “empty true, full false.”

    But locally synchronized release only solves the timing of reset release in that clock domain; it does not automatically solve the inconsistency between the two ends after a one-sided reset.

    If resetting only the read side or only the write side during operation is allowed, an additional recovery protocol must be defined, for example stopping transfers, coordinating a flush, and re-establishing a consistent starting state for both sides. Otherwise one end clears its pointers while the other still interprets memory contents with the old pointers, which can cause data to be re-read, lost, or misjudged in capacity.

    Whether reset is allowed to discard existing data should also be written into the specification.

    7. Closing the Verification Loop: A Testbench Is More Than a Clock Generator

    7.1 Build a Reference Model

    The testbench can maintain a software queue:

    • When a write request is actually accepted, push the write data into the queue;
    • When a read request is actually accepted, compare the output against the head of the queue according to the defined read latency;
    • Remove the entry after a successful comparison.

    The reference model must be driven by interface accept events, not merely by read/write enables. A write rejected while full must not enter the queue, and a read rejected while empty must not remove data.

    When two clock edges coincide in simulation, the reference model’s own scheduling race must be avoided so that comparison results do not depend on the execution order of the test code.

    7.2 Cover the Error-Prone Scenarios

    At minimum, include:

    • Write clock clearly faster than read clock; check the full state and rejected writes;
    • Read clock clearly faster than write clock; check the empty state and rejected reads;
    • Different clock period and initial phase combinations;
    • Pointers wrapping around repeatedly;
    • Long burst writes, burst reads, and alternating pauses;
    • Recovery from empty to non-empty and from full to non-full;
    • Reset release close to a clock edge;
    • Pausing one side’s clock within the range allowed by the protocol;
    • The minimum supported depth and multiple data widths.

    Random testing can explore a wider space of combinations but cannot replace directed tests that explicitly cover the key boundaries.

    7.3 Express Design Invariants as Assertions

    The following properties can be checked:

    • With no accepted write while full, the write pointer stays unchanged;
    • With no accepted read while empty, the read pointer stays unchanged;
    • The local pointer advances by at most one step per cycle, or stays unchanged;
    • The local Gray code changes by at most one bit between adjacent source-clock samples;
    • The initial empty/full state after reset matches the specification;
    • Output data stays in order, with no duplication and no loss.

    Note in particular that a synchronized Gray code may skip several source-side states, so the receiving domain cannot be required to observe only one-bit changes each time. The single-bit-change assertion belongs in the local clock domain that generates the Gray code.

    7.4 Waveforms, Static Checks, and Formal Methods Each Have a Role

    Waveforms are good for explaining a failure, but a few screenshots cannot prove a design correct. Conventional digital simulation also does not truly model metastability at the analog level, so CDC static checks, reset checks, and timing-constraint reviews are needed as well.

    Where resources allow, formal methods can verify properties such as pointer advancement, boundary protection, and data ordering, but the proof depends on environmental assumptions. Clock, reset, and interface constraints must be stated clearly, so that overly strong assumptions do not exclude potential bugs from the verification scope.

    8. Organizing the Iteration Flow of AI-Assisted Design

    AI coding tools are well suited to producing first drafts, tidying structure, and filling in checklists, but the work should be broken into reviewable stages rather than demanding the entire design in one shot.

    The first stage generates the specification and architecture, confirming parameter ranges, interface timing, reset behavior, and CDC paths. The second stage generates the core modules, checking bit widths, next-state computation, the synchronizer chain, and illegal-request handling item by item. The third stage completes the testbench, assertions, and coverage plan, then iterates on the design based on failure logs. Finally, run synthesis, static analysis, and implementation-constraint checks.

    Each round of changes should state “what problem was fixed, which logic was affected, and which regression cases were added.” Do not accept new code without understanding the diff, and do not treat a testbench generated by the same tool as an independent, correct judge: the design and the test may share the same wrong assumption.

    Design documentation also belongs in the deliverable. A module responsibility table, a signal timing table, the reset flow, and CDC constraint notes are usually more valuable than a decorative architecture diagram.

    9. Conclusion: Efficiency Gains Require Keeping Engineering Responsibility

    The asynchronous FIFO illustrates the typical boundary of AI-assisted chip design: tools can quickly assemble familiar structures, but they cannot replace the engineer’s judgment about clock domains, memory semantics, reset protocols, and verification adequacy.

    The reliable practice is not “generate code and use it directly,” but building a closed loop of “clear specification, reviewable structure, verifiable functionality, constrainable implementation, and traceable changes.” Once that flow matures, AI assistance can genuinely reduce repetitive work and let developers spend more effort on architecture decisions, boundary analysis, and delivery quality.