Manuscript Offprint

arXiv:2608.22938

Execution-Anchored Hallucination Calibration Reranking for Verilog Code Generation

Guang Yang, Xing Hu, Xiang Chen, Terry Yue Zhuo, Xin Xia

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Guang Yang, Xing Hu ∗^{*}, Xiang Chen, Terry Yue Zhuo, and Xin Xia

Abstract—Large Language Models (LLMs) have demonstrated remarkable capabilities in code generation, yet their performance degrades significantly on low-resource Hardware Description Languages such as Verilog. While multi-candidate sampling improves the likelihood of generating correct solutions, automatically selecting the optimal candidate remains an open challenge. Through a systematic empirical study across nine models and two benchmarks, we identify two critical limitations: (1) existing execution-based reranking methods, which rely on testbench pass/fail outcomes, exhibit poor domain transferability due to low-quality generated testbenches; and (2) LLM-as-a-Judge suffers from reasoning hallucination, producing inconsistent judgments for execution-equivalent code. These findings reveal two signal types with orthogonal errors: execution signals (deterministic but testbench coverage limited) and reasoning signals (semantically rich but hallucination-prone). Their orthogonality suggests combining the two signals, yet in our experiments letting the reasoner directly observe execution results merely anchors its judgments on test outcomes; we therefore acquire the two signals independently and fuse them only at the decision stage. Based on these insights, we propose EAHC, an Execution-Anchored Hallucination Calibration reranking framework that anchors reasoning judgments to execution behavior so that execution-equivalent candidates receive consistent scores, which implements a dual-channel architecture: EAHC-R, a 4B reasoning discriminator fine-tuned on 47K compiler-verified judgment traces via multi-teacher distillation; and EAHC-T, a testbench generator leveraging RAG over a 53K corpus for execution verification. Experiments show that EAHC ranks first in 15 of 18 configurations and attains the best average on both benchmarks, elevating average Pass@1 from 53.99% to 65.10% on VerilogEval-v2 and from 53.18% to 68.25% on ResBench, recovering over 60% of the gap to Pass@10 oracle.

Index Terms—Large Language Models, Verilog Code Generation, Code Reranking, LLM-as-a-Judge, Hardware Description Languages

I. INTRODUCTION

Hardware Description Languages (HDLs), including Verilog, VHDL, and SystemVerilog, form the foundation of modern digital circuit design [1]. Among these, Verilog stands out for its widespread industry adoption, serving as the standard in both ASIC and FPGA design workflows. As integrated circuit complexity continues to grow, automated Verilog code generation has become increasingly critical to reduce development costs and alleviate engineering workload [2]. With the rapid advancement of Large Language Models (LLMs), remarkable progress has been achieved in code generation for high-resource programming languages, with state-of-the-art LLMs now surpassing 90% Pass@1 on Python benchmarks like HumanEval [3], [4]. Inspired by this success, researchers have attempted to transfer LLM capabilities to Verilog generation [5]. However, these efforts reveal a significant performance gap: even the most capable LLMs achieve only 30–50% Pass@1 on Verilog benchmarks, far below their performance on general-purpose languages [6], [7].

The performance gap stems from fundamental challenges: (1) data scarcity, as available Verilog corpora are orders of magnitude smaller than those for general-purpose languages and (2) domain complexity, since hardware design involves temporal logic, parallel execution, and signal propagation that diverge fundamentally from sequential software paradigms. A straightforward solution is to build large-scale, high-quality Verilog corpora. However, it is limited by the escalating labeling cost and the high computational expense of retraining large models for this domain.

An alternative strategy leverages the characteristics of LLM decoding: by sampling k candidates at non-zero temperature, the probability that at least one is correct (Pass@k) far exceeds that of a single greedy attempt (Pass@1). Table I reveals a striking disparity: while Pass@10 reaches 71.30% on VerilogEval-v2 [6] and 77.78% on ResBench [8], Pass@1 lags significantly at 53.99% and 53.18%, respectively. This 17–25 percentage-point gap reveals considerable latent capability that existing approaches fail to fully leverage in practice. In real-world development scenarios, developers typically expect definitive code suggestions rather than k uncertain alternatives, which require additional manual effort to evaluate and select. This gap motivates the code reranking problem: given k candidates Yk={y^1,…,y^k}\mathcal{Y}_k = \{\hat{y}_1, \ldots, \hat{y}_k\} for requirement x, design a scoring function to select the most likely correct implementation, effectively converting sampling diversity into deployment-ready accuracy.

Corresponding author: Xing Hu.

To better understand the limitations of existing approaches, we conduct a systematic empirical study (Section III) across nine code generation models and two benchmarks, evaluating state-of-the-art reranking methods including generation probability [9], semantic matching [10], execution verification [11], and LLM-as-a-Judge [12]. Our study reveals two critical findings:

Guang Yang is with the State Key Laboratory of Blockchain and Data Security, Zhejiang University, Hangzhou, China, and also with the Hangzhou High-Tech Zone (Binjiang) Institute of Blockchain and Data Security, Hangzhou, China. Xing Hu and Xin Xia are with the State Key Laboratory of Blockchain and Data Security, Zhejiang University, Hangzhou, China. Xiang Chen is with the School of Artificial Intelligence and Computer Science, Nantong University, Nantong, China. Terry Yue Zhuo is with the Department of Computer Science, Monash University and CSIRO's Data61, Australia. E-mail: noveltyg@outlook.com, xinghu@zju.edu.cn, xchencs@ntu.edu.cn, terry.zhuo@monash.edu, xin.xia@acm.org.

Manuscript received April 19, 2020; revised August xx, xxxx.

☆Finding 1: Poor Domain Transferability. Existing reranking methods for general-purpose languages generalize poorly to Verilog. Probability-based approaches suffer from distributional shift between training corpora and HDL syntax, while semantic matching methods fail to capture hardware-specific constructs such as always blocks and non-blocking assignments. Execution-based methods like CodeT [11] harness execution signals for candidate selection, but their reliance on self-generated testbenches limits effectiveness: the underlying code models lack hardware domain expertise to produce high-quality test cases.

☆Finding 2: Reasoning Hallucination in LLM-as-a-Judge. In contrast to execution-based methods, LLM-as-a-Judge leverages reasoning signals and emerges as the most competitive baseline, yet it exhibits a critical flaw: reasoning hallucination, where it may produce inconsistent correctness judgments for execution-equivalent code, i.e., candidates with identical input–output behavior on a finite test suite (Section III). Specifically, for candidates y^i\hat{y}_i and y^j\hat{y}_j with the same execution behavior, the LLMs may give different judgments. This inconsistency stems from the fact that LLMs reason at the token level without grounding in execution semantics [13].

These findings reveal two signal types with distinct strengths and limitations. Execution-based methods (Finding 1) leverage execution signals, i.e., deterministic pass/fail outcomes where execution-equivalent code must produce identical results. Their strength lies in consistency: identical behavior guarantees identical scores. However, they suffer from coverage gaps, as limited testbenches cannot detect all bugs. LLM-as-a-Judge (Finding 2) relies on reasoning signals, i.e., semantic correctness judgments derived from analyzing code logic. Their strength lies in semantic coverage: reasoning can identify errors beyond what tests exercise. However, they suffer from reasoning hallucination, producing inconsistent judgments for execution-equivalent code.

Crucially, the two limitations differ in character: execution errors are systematic, missing the same behaviors whenever the tests fail to exercise them, whereas reasoning errors are stochastic, varying across implementations that behave identically. This asymmetry is what makes the signals worth combining: execution outcomes can stabilize fluctuating judgments, while reasoning can cover what the tests leave untested.

How to combine them is less obvious. The intuitive option is interactive: let the reasoner observe execution results before judging. Information theory bounds what this can gain, but only when the resulting verdict is a revision of the judgment the reasoner would have produced anyway (Section IV-B); the bound does not rule out every interactive design. Empirically, however, exposing execution feedback anchors the reasoner on test outcomes and costs accuracy (Section V). We therefore keep the channels apart, a design we formalize as a dual-channel information model (Section IV-B): the execution channel generates testbenches solely from requirement x, the reasoning channel judges correctness from (x,y^)(x, \hat{y}) pairs without observing execution results, and the two signals meet only when the final choice is made. Our ablations support the premise behind this design: reasoning does carry information that execution misses (Section V).

We realize this design as EAHC (Execution-Anchored Hallucination Calibration), a reranking framework with one component per channel. EAHC-R implements the reasoning channel: we curate a 47K dataset via multi-teacher distillation with compiler-in-the-loop verification and fine-tune Qwen3-4B to acquire Verilog-specific judgment capabilities; at inference, majority voting across multiple samples yields aggregated reasoning signals. EAHC-T implements the execution channel: we construct a 53K dataset using the same distillation pipeline and employ RAG techniques to produce high-quality execution signals. The two signals meet only in hierarchical selection, the decision stage anticipated above: candidates sharing identical execution vectors are grouped into execution-equivalence clusters and assigned uniform reasoning scores, then ranked by fusing execution pass rates with cluster-level reasoning confidence. Since equivalent implementations share a single score, the winning cluster no longer depends on which candidate the judge happens to favor. This is how execution anchors reasoning, and what we mean by calibration: consistency of judgments, not conversion of scores into probabilities.

We evaluate EAHC on VerilogEval-v2 and ResBench across nine code generation models, including commercial (GPT-5, DeepSeek-V3, and GLM-4.6), general-purpose (Qwen2.5-Coder, Open-Coder, and Seed-Coder), and Verilog-specialized (HaVen, VeriPrefer, and CodeV-R1) models. Results demonstrate that: (1) EAHC improves average Pass@1 from 53.99% to 65.10% on VerilogEval-v2 and from 53.18% to 68.25% on ResBench, outperforming the strongest baseline by +5.91% and +4.96% respectively, and ranking first in 15 of 18 configurations; (2) ablation studies confirm both components are essential, with EAHC-R contributing +7.12% and EAHC-T contributing +5.75% on average; (3) the fusion weight α=0.6\alpha=0.6 performs best in our sweep, reflecting the higher reliability of execution signals; (4) EAHC is orthogonal to training-based approaches, providing gains of 8.93% to 19.64% across base, SFT, and RL-optimized models; and (5) independent fusion outperforms interactive fusion across all evaluated configurations.

In summary, this paper makes the following contributions:

• Problem Formulation and Empirical Findings. We formalize the Verilog code reranking problem and conduct the first systematic empirical study across nine code generation models and two benchmarks.

• Dual-Channel Framework and Domain Resources. We propose EAHC, a dual-channel reranking framework that acquires execution and reasoning signals independently and fuses them only at the decision stage, a choice supported by our information-theoretic analysis (Theorem 1) and by a direct comparison against interactive fusion. It also yields two reusable resources, VeriJudge-47K and VeriTest-53K, curated by multi-teacher distillation with compiler-in-the-loop verification, along with the 4B judge and testbench generator trained on them.

• State-of-the-Art Performance. EAHC attains the best average Pass@1 on both benchmarks and the best reranking accuracy in 15 of the 18 configurations (9 models × 2 benchmarks), recovering over 60% of the gap between Pass@1 and Pass@10.

To support future research, we open-source our trained models and code 1^{1} to facilitate reproducibility and future research in Verilog code generation.

References (40)