LLM-Assisted Asynchronous FIFO Design: An End-to-End Workflow
A practical workflow for using a large language model to design and verify an asynchronous FIFO. The article covers specification writing, modular RTL architecture, Gray-coded pointers, clock-domain crossing, conservative full and empty detection, and simulation-based verification, while identifying the engineering reviews that still require human judgment.
1. Why an Asynchronous FIFO Tests AI Design Capabilities
AI coding assistants already handle much of the boilerplate in everyday digital front-end development. But syntax completion alone does not demonstrate design competence. A meaningful test must involve architectural decisions, clock-domain crossing (CDC) risks, and boundary conditions.
An asynchronous FIFO fits that requirement. Its implementation is relatively compact, yet a few hundred lines must address two clock domains, pointer encoding, metastability mitigation, and conservative full and empty detection. A mistake in any of these areas can cause data loss or duplication that is difficult to reproduce in production.
This article follows an end-to-end human–AI workflow for designing an asynchronous FIFO and extracts practices that can be applied to other RTL projects.
2. Turn Natural-Language Requirements into a Verifiable Specification
The first step is not asking the model to write code. It is making the requirements explicit. A useful specification should include at least the following:
- Data width and depth: For example, 8-bit data and a depth of 16, requiring a 4-bit address.
- Pointer encoding: Both read and write pointers use Gray code for CDC; binary pointers are used internally for incrementing.
- Interface signals:
wclk,wr_en,wdata, andfullin the write domain;rclk,rd_en,rdata, andemptyin the read domain. - Full and empty policy: Flags must be conservative, prioritizing safety over immediate availability.
- Optional enhancements:
almost_fullandalmost_emptythresholds, reset synchronization, and first-word fall-through (FWFT) operation.
More specific requirements improve the likelihood of a usable first implementation. Clarifying the specification usually delivers more value than repeatedly tweaking the prompt.
3. Break the Architecture into Clear Modules
When reviewing the initial response, check whether the assistant has produced a meaningful modular structure rather than placing everything in one file.
A reasonable hierarchy is:
async_fifo_top├── fifo_mem // Dual-port RAM: write-side writes, read-side reads├── wptr_ctrl // Write pointer, Gray-code conversion, and full flag├── rptr_ctrl // Read pointer, Gray-code conversion, and empty flag└── sync_2ff // Two-stage synchronizer; stage count can be parameterized
This separation concentrates CDC logic in dedicated synchronization modules, making constraints and checks easier to review independently. It also decouples pointer and flag logic from storage, so replacing a register array with an SRAM macro does not require redesigning the control logic.
4. Key Implementation Details and Code Skeletons
Dual-Port Storage
always @(posedge wclk) if (wr_en && !full) mem[wbin[ADDR-1:0]] <= wdata;assign rdata = mem[rbin[ADDR-1:0]];
The example uses an asynchronous read with combinational output. This can provide a compact implementation, but the read path may be long. If timing is tight, the read address can be registered for one cycle. That changes read timing and requires corresponding adjustments to empty-flag handling—a typical area-versus-timing trade-off.
Gray Code: Reducing Pointer Transitions to One Bit
assign wgray_next = (wbin_next >> 1) ^ wbin_next;
Adjacent Gray-code values differ by only one bit. This avoids the multi-bit transitions of a binary counter, which can otherwise produce an incoherent pointer when sampled across clock domains.
Gray coding helps constrain the uncertainty associated with sampling a pointer transition. It does not eliminate metastability; synchronization and appropriate CDC implementation remain essential.
Two-Stage Synchronizers and Metastability
module sync_2ff #(parameter W = 1)(input clk, input rst_n, input [W-1:0] d, output [W-1:0] q);reg [W-1:0] s1, s2;always @(posedge clk or negedge rst_n)if (!rst_n) begin s1 <= 0; s2 <= 0; endelse begin s1 <= d; s2 <= s1; endassign q = s2;endmodule
Synchronizer depth affects mean time between failures (MTBF). More stages improve metastability tolerance but add latency. Two stages are common, while higher-reliability designs may use three.
Timing constraints must identify the asynchronous crossing into the synchronizer appropriately, rather than treating it as an ordinary synchronous path.
Conservative Full and Empty Detection
// Read domain: compare against the synchronized write Gray pointerassign empty = (rgray_next == rg_wgray_sync);// Write domain: compare against the synchronized read Gray pointer,// with the two most significant bits invertedassign full = (wgray_next == {~wg_rgray_sync[ADDR:ADDR-1],wg_rgray_sync[ADDR-2:0]});
These expressions illustrate the next-pointer comparisons used in flag generation. The full comparison inverts the two most significant Gray-code bits to distinguish the full condition from an equal-position condition after pointer wraparound.
Synchronization means each domain sees a delayed version of the opposite pointer. The resulting flags are conservative: space freed by a read, or data added by a write, may not become visible immediately to the other domain. Correct flag handling prevents that delay from allowing unsafe accesses.
5. Close the Verification Loop with a Testbench and Local Simulation
Even a polished RTL implementation needs verification. Ask the assistant to generate the following:
- Independent clock stimulus: Use different clock frequencies, such as 100 MHz and 37 MHz, to exercise changing relative clock phases.
- Randomized reads and writes: Randomize enables with weighted probabilities, and periodically create write-heavy and read-heavy conditions to drive the FIFO toward full and empty.
- A reference model and scoreboard: Store accepted writes in a SystemVerilog queue and compare each accepted read against the expected value, checking for loss, duplication, and reordering.
- Assertions and coverage: Check that no write is accepted while full and no read is accepted while empty, along with pointer-range properties. Track read/write activity and full/empty transitions.
- Waveforms and logs: Compile, elaborate, and run the testbench with a local simulator, producing waveform files for manual inspection.
A simple simulation-control skeleton is:
initial begin$dumpfile("fifo.vcd"); $dumpvars(0, tb.dut);repeat (2000) @(posedge rclk);if (err_cnt == 0) $display("PASS"); else $display("FAIL, err=%0d", err_cnt);$finish;end
The assistant’s role should extend beyond generating RTL to producing the verification scaffolding and supporting the local simulation workflow. Generated code alone is not a verification result.
6. Evaluate the Output and Improve the Documentation
Assess the result across six dimensions:
- Functional correctness
- CDC implementation quality
- Synthesizability: No unintended latches or combinational loops, and a consistent reset strategy
- Maintainability: Clear naming and module hierarchy
- Documentation and diagram quality
- Verification completeness
One of the weakest areas in this workflow is often the architecture diagram. AI-generated block diagrams can be decorative rather than accurate, with module names or ports that do not match the RTL.
In real projects, design documentation, timing descriptions, and interface tables can take as much effort as the code itself. A practical improvement is to make documentation part of the required output:
- A module port table
- A clock-domain ownership table
- A list of signals crossing clock domains
Use those structured descriptions as the basis for the block diagram. This makes consistency between the diagram and implementation easier to check.
7. A Practical Adoption Checklist
- Start with requirements: Specify width, depth, pointer encoding, full/empty policy, and reset behavior before requesting RTL.
- Require structured output: Ask for the hierarchy and port tables before the implementation.
- Review CDC separately: Check synchronizer depth, asynchronous-path constraints, and whether crossing signals pass through the intended synchronization structures.
- Do not skip verification: Combine randomized stimulus, a reference model, assertions, and coverage.
- Keep engineers responsible for the final review: Post-synthesis simulation, timing closure, and structural CDC checks still require engineering judgment.
In this type of RTL-generation task, current coding assistants can produce work resembling that of a well-trained engineer with several years of experience: implementations are often substantially complete and account for many boundary conditions. However, precise documentation and diagrams remain weaker areas, and the assistant does not independently complete timing or reliability sign-off.
The most effective division of labor is to use the model for the path from specification to RTL and verification scaffolding, while reserving human attention for architectural trade-offs and sign-off decisions.
