A Novel HDL Code Generator for Effectively Testing FPGA Logic Synthesis Compilers

Zhihao Xu, Shikai Guo, Guilin Zhao, Peiyu Zou, Xiaochen Li, He Jiang

TL;DR

LegoHDL is a new automated "fuzzer" designed to find bugs in FPGA logic synthesis compilers (like Vivado and Quartus) by generating complex, functionally valid hardware descriptions. By treating hardware design like building with LEGO blocks—specifically using Cyber-Physical System (CPS) models—it successfully uncovered 20 new defects in major industry compilers that previous state-of-the-art tools missed.

What Problem Does This Paper Address?

Field Programmable Gate Arrays (FPGAs) are the backbone of modern hardware prototyping and specialized computing. To turn high-level code (HDL) into actual circuitry, engineers rely on logic synthesis compilers. However, these compilers are incredibly complex; they perform aggressive optimizations for power and timing that can inadvertently introduce "logic defects"—meaning the final hardware doesn't actually do what the code specified.

Existing tools for testing these compilers, such as Verismith, often generate code that is too simple or repetitive. They struggle with two main challenges:

  1. Lack of Diversity: They don't produce complex enough control-flow or data-flow patterns to trigger "deep" bugs.
  2. Language Limitations: Most existing generators only support Verilog, leaving VHDL and SystemVerilog compilers under-tested.

Methods

The authors introduce LegoHDL, which shifts the strategy from generating random text to generating functional Cyber-Physical System (CPS) models.

The system consists of two interacting components:

  • Function Generation Component: This acts like the "builder." It randomly selects functional blocks (like mathematical operators, filters, or logic gates) from a library and connects them to create a valid system model.
  • Syntax Guidance Component: This acts like the "architect." It uses a tool called HDL Coder to translate the CPS model into HDL code (Verilog, VHDL, or SystemVerilog). It then analyzes the Abstract Syntax Tree (AST) of that code to identify valid "insertion points" where the builder can add more blocks, ensuring the code remains syntactically correct and functionally meaningful.

LegoHDL uses Differential Testing to find bugs: it feeds the same generated code into multiple different compilers (Vivado, Iverilog, Yosys, and Quartus). If the compilers produce different outputs for the same input, a bug has been found.

Datasets

While not a traditional machine learning paper, LegoHDL utilizes:

  • CPS Function Block Libraries: Extensive libraries of functional blocks (Sources/Sinks, Math Operations, HDL-specific operations, and Control Flow) derived from the Simulink ecosystem.
  • Evaluation Targets: The tool was tested against four major FPGA synthesis suites: Xilinx Vivado, Iverilog, Yosys, and Intel Quartus.

Key Insights and Ideas

  • Model-Based Fuzzing: Instead of trying to guess the complex grammar of HDLs, LegoHDL leverages existing high-level modeling tools (CPS) that are already designed to be translated into hardware. This ensures the generated code is "deep" and functionally rich.
  • The "Lego" Analogy: By piecing together small, discrete functional components into a large project, the tool mimics how human engineers actually build hardware, making the test cases more realistic.
  • Cross-Language Support: Because it starts at the model level, LegoHDL can export to Verilog, VHDL, or SystemVerilog with ease, allowing it to test a much wider range of compiler features than previous tools.
  • Constraint Feedback: The tool doesn't just build randomly; it collects "constraint information" (like data types and sampling rates) from the existing code to ensure that new blocks added to the design are compatible, preventing the fuzzer from generating "garbage" code that compilers would immediately reject.

Key Results

  • Bug Discovery: In just three months, LegoHDL identified 20 new defects across Vivado, Iverilog, Yosys, and Quartus.
  • Confirmation: 16 of these defects have already been confirmed by the respective technical support teams.
  • Complexity: Compared to the previous state-of-the-art (Verismith), LegoHDL generated code with 31% more nodes and 25.1% more connections on average, indicating significantly higher structural complexity.
  • Efficiency: While translation time increases with model size, the tool can generate a complex 100-model design in about 50-200 seconds, making it practical for continuous integration testing.

Limitations and Future Work

  • Scalability: As the number of models/blocks increases, the time required for the "Syntax Guidance" component to analyze the AST and translate the code grows significantly.
  • Tool Dependency: The current implementation relies on the MATLAB/Simulink ecosystem (specifically HDL Coder) for the model-to-code translation, which may limit its accessibility for some researchers.
  • Future Directions: The authors plan to improve generation efficiency and conduct a broader empirical study comparing different testing methods across even more FPGA development tools.

Summary updated

BibTeX
@article{xu2025novel,
  author = {Zhihao Xu and Shikai Guo and Guilin Zhao and Peiyu Zou and Xiaochen Li and He Jiang},
  title = {{A Novel HDL Code Generator for Effectively Testing FPGA Logic Synthesis Compilers}},
  journal = {IEEE Trans. Comput. Aided Des. Integr. Circuits Syst.},
  year = {2025},
  doi = {10.1109/tcad.2025.3565488},
}
Figure