HDLCoRe: A Training-Free Framework for Mitigating Hallucinations in LLM-Generated HDL

Heng Ping, Shixuan Li, Peiyu Zhang, Anzhe Cheng, Shukai Duan, Nikos Kanakaris, Xiongye Xiao, Wei Yang, Shahin Nazarian, Andrei Irimia, Paul BogdanarXiv 2025 · DOI

Abstract

Large Language Models (LLMs) have demonstrated remarkable proficiency in software programming but continue to struggle with Hardware Description Languages (HDL) like Verilog. These models often produce "hallucinations"—syntactically plausible but functionally incorrect code—due to the concurrent nature of hardware logic and the scarcity of HDL training data. We present HDLCoRe, a training-free framework designed to enhance the reliability of off-the-shelf LLMs in hardware design. By integrating complexity-aware Chain-of-Thought (CoT) reasoning with a heterogeneous Retrieval-Augmented Generation (RAG) system and a novel self-simulation mechanism, HDLCoRe achieves up to a 28% improvement in functional correctness on the RTLLM 2.0 benchmark. This approach allows open-source models to achieve performance levels previously reserved for much larger or fine-tuned counterparts.

Introduction: The Challenge of HDL Generation

Generating HDL code is fundamentally different from writing software. While software is largely procedural, hardware design is concurrent and timing-dependent. LLMs frequently stumble in this domain because HDL data is significantly scarcer in their training sets compared to general-purpose languages like Python or C++.

Furthermore, the semiconductor industry faces unique challenges regarding intellectual property. Using closed-source models like GPT-4 raises significant privacy concerns, yet open-source alternatives often exhibit higher hallucination rates. Existing solutions typically rely on computationally expensive fine-tuning or complex human-in-the-loop iterations. HDLCoRe addresses these issues by making open-source models smarter through optimized prompting and context retrieval, rather than additional training.

The HDLCoRe Framework

HDLCoRe is built upon two primary pillars designed to guide the LLM through the intricacies of hardware logic without requiring model weights to be updated.

1. HDL-aware Chain-of-Thought (CoT) and Self-Verification

Instead of utilizing a generic prompt, HDLCoRe categorizes tasks by complexity (e.g., Simple vs. Complex, Combinational vs. Sequential). Simple tasks receive lightweight prompts to prevent "over-thinking" errors, while complex designs are supported by deep domain-specific guidance.

A standout feature is Self-Simulation. The LLM is prompted to generate a testbench and then emulates the simulation process step-by-step. By "mentalizing" signal transitions over time, the model can identify its own logic errors and refine the code autonomously before final output.

2. Two-Stage Heterogeneous RAG System

To provide the model with relevant context, the system employs a specialized RAG pipeline. It breaks down hardware descriptions into high-level overviews, low-level implementation details, and module headers. A lightweight embedding model first identifies potential matches from a high-quality HDL database, which are then re-ranked by a powerful cross-encoder to ensure maximum semantic relevance.

The HDLCoRe framework architecture, featuring (a) the HDL-aware Chain-of-Thought pipeline and (b) the two-stage heterogeneous RAG system.

Experimental Evaluation

The researchers evaluated HDLCoRe using the RTLLM 2.0 benchmark, which includes 50 Verilog design tasks ranging from basic adders to complex MIPS-ISA CPUs. Testing spanned the Qwen2.5 and Qwen2.5-Coder series, from 7B to 72B parameters.

Key Results

  • Functional Correctness: HDLCoRe achieved up to a 28% increase in functional pass@1 rates compared to baseline models.
  • Model Scaling Efficiency: The Qwen2.5-32B model, when equipped with HDLCoRe, achieved a 60% functional success rate, significantly outperforming the much larger 72B baseline model.
  • Ablation Insights: Every component of the pipeline contributed to the success. The Self-Verification (SV) step alone consistently improved performance by 2–6% across all model sizes.
Comparison of Pass@1 rates across various Qwen2.5 model sizes, demonstrating the cumulative performance gains from CoT, RAG, and Self-Verification (SV).

Conclusion and Future Directions

HDLCoRe demonstrates that sophisticated retrieval and reasoning frameworks can effectively compensate for a lack of specialized pre-training in hardware design. By tailoring prompts to task complexity and enabling models to act as their own debuggers through self-simulation, the framework narrows the gap between general-purpose LLMs and specialized hardware engineers.

Future work will focus on integrating these autonomous loops with physical synthesis tools to address Power, Performance, and Area (PPA) constraints, ensuring that generated code is not only functionally correct but also optimized for real-world silicon implementation.

Summary updated

BibTeX
@misc{ping2025hdlcore,
  author = {Heng Ping and Shixuan Li and Peiyu Zhang and Anzhe Cheng and Shukai Duan and Nikos Kanakaris and Xiongye Xiao and Wei Yang and Shahin Nazarian and Andrei Irimia and Paul Bogdan},
  title = {{HDLCoRe: A Training-Free Framework for Mitigating Hallucinations in LLM-Generated HDL}},
  year = {2025},
  eprint = {2503.16528},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.16528},
}
Figure