Paradigm-Based Automatic HDL Code Generation Using LLMs

Wenhao Sun, Bing Li, Grace Li Zhang, Xunzhao Yin, Cheng Zhuo, Ulf Schlichtmann

Abstract

Large Language Models (LLMs) have demonstrated remarkable proficiency in software engineering, yet they frequently falter when generating Hardware Description Languages (HDL) like Verilog. The primary obstacle is "hallucination," where models produce logically inconsistent circuits despite correct syntax. This paper presents a paradigm-based framework designed to mitigate these errors by decomposing complex design tasks into structured "paradigm blocks." By incorporating intermediate state formatting—such as state-transition tables and JSON-formatted truth tables—and integrating external symbolic tools like PyEDA, the framework anchors LLM reasoning and offloads complex logic simplification. Experimental results on the VerilogEval benchmark show that this method significantly outperforms naive generation and existing iterative feedback loops, raising the Pass@10 metric for GPT-4 from 62.2% to 76.9%.

Introduction

The automation of hardware design using LLMs holds the potential to significantly accelerate the development cycle of integrated circuits. However, unlike software, hardware design is inherently multi-step and requires a rigorous adherence to timing and state logic. Current LLMs often struggle with this "multi-hop" reasoning, attempting to generate complex modules in a single pass without an explicit internal state. This often leads to hallucinations where the model misinterprets technical specifications or fails to simplify boolean logic correctly.

While existing solutions like Retrieval-Augmented Generation (RAG) or fine-tuning offer some improvements, they are often constrained by the quality of the retrieval database or the scarcity of high-quality HDL training data. This research introduces a "training-free" alternative that structures the LLM’s reasoning process to mirror the workflow of a human hardware engineer.

Methodology: The Paradigm-Based Workflow

The proposed framework operates on a "divide and conquer" strategy, utilizing specialized pipelines called Paradigm Blocks. The workflow is divided into two main phases.

1. Classification and Information Extraction

The process begins with the LLM categorizing the design task into one of three paradigms: Sequential (SEQU), Combinational (COMB), or Behavioral (BEHAV). To ensure accuracy, the system uses a "naive" initial code generation step to help the LLM understand the circuit's intent, which improved classification accuracy from 94.9% to 98.3%. Once classified, the LLM extracts an "Information List" from the natural language specification, detailing input/output ports, timing requirements, and functional constraints.

2. Intermediate Formatting and Tool Integration

The core of the framework lies in its use of intermediate states as "external memory" to anchor the LLM's logic:

  • Sequential (SEQU): The LLM generates a state-transition table before writing code. The final Verilog is then produced using the standard "three-always-block" method, a best practice in human design.
  • Combinational (COMB): To avoid logical errors in boolean simplification, the LLM generates a JSON-formatted truth table. This table is passed to PyEDA, an external symbolic logic tool, which calculates the simplified Sum-of-Products (SoP) expression. The LLM then wraps this deterministic output into a Verilog module.
  • Behavioral (BEHAV): For designs that do not fit strictly into SEQU or COMB, the system decomposes the task into smaller, manageable behavioral components.

3. Two-Phase Execution and Fail-safes

The system employs a two-phase workflow. Phase I utilizes the specialized paradigm blocks. If the resulting code fails the testbench, the system enters Phase II. In this phase, it reuses the high-quality information lists from Phase I but applies the more flexible BEHAV paradigm. Additionally, the framework includes "Short-cut" logic to refine near-misses and "Fail-safe" mechanisms to switch paradigms if formatting errors occur.

Experimental Evaluation

The researchers evaluated the framework using the VerilogEval benchmark, consisting of 299 tasks split into human-written (VerilogEval-human) and machine-generated (VerilogEval-machine) specifications.

Performance Metrics

Using GPT-4 as the backbone, the paradigm-based method showed substantial gains across all Pass@k metrics on the VerilogEval-human subset:

  • Pass@1: Improved from 42.0% to 46.7%.
  • Pass@5: Improved from 58.6% to 69.6%.
  • Pass@10: Improved from 62.2% to 76.9%.

Comparison with AutoChip

In a head-to-head comparison on difficult combinational logic tasks, the paradigm-based method achieved a 70% success rate. In contrast, AutoChip—which relies on iterative feedback from a compiler—achieved 0%. This suggests that iterative feedback alone cannot correct the fundamental logical hallucinations that occur during the initial generation of complex combinational circuits; a structured, symbolic approach is required.

Discussion and Limitations

The study highlights that while the paradigm-based approach is highly effective for standard logic, it still faces challenges with the "hardest" tasks (those with baseline error rates > 0.8). Furthermore, the system is sensitive to the "Information Extraction" step; any detail missed during the initial parsing of the natural language specification propagates through the entire pipeline, leading to functional errors.

Conclusion

By forcing LLMs to generate intermediate structured formats and offloading logical reasoning to symbolic tools like PyEDA, the paradigm-based framework significantly reduces hallucinations in HDL generation. This approach demonstrates that the key to effective hardware generation lies not just in the size of the model, but in the structure of the design process. Future work will focus on integrating more sophisticated EDA tools and refining the extraction of information from complex, large-scale hardware specifications.

Summary updated

BibTeX
@inproceedings{sun2025paradigm,
  author = {Wenhao Sun and Bing Li and Grace Li Zhang and Xunzhao Yin and Cheng Zhuo and Ulf Schlichtmann},
  title = {{Paradigm-Based Automatic HDL Code Generation Using LLMs}},
  booktitle = {ISQED},
  year = {2025},
}
Figure