Developer tools · Research feature

MHRC-Bench: A Multilingual Hardware Repository-Level Code Completion benchmark

Large language models (LLMs) have achieved strong performance on code completion in general-purpose programming languages, but existing repository-level benchmarks focus almost exclusively on software code and largely overlook hardware description languages (HDLs).

Adapted from research by Qingyun Zou, Jiahao Cui, Nuo Chen and colleagues.

arXiv preprint revision · 2026-11-15 · Attribution & reuse
In this article
Editorial illustration of stacked plates.

Authors’ overview

Large language models (LLMs) have achieved strong performance on code completion in general-purpose programming languages, but existing repository-level benchmarks focus almost exclusively on software code and largely overlook hardware description languages (HDLs). We present MHRC-Bench, consisting of MHRC-Bench-Train and MHRC-Bench-Eval, the first benchmark for multilingual hardware code completion at the repository level with functional evaluation. MHRC-Bench covers three major hardware design coding styles and annotates each completion target with code-structure-level and hardware-oriented semantic labels derived from concrete syntax tree (CST) analysis. Post-training billion-scale code LLMs on MHRC-Bench-Train enables smaller open-weight models to outperform much larger general-purpose models under matched context windows. Beyond aggregate accuracy, our analysis surfaces four findings that distinguish hardware from software code completion: (i)~performance varies sharply across HDLs, with high-level synthesis (HLS) easiest and VHDL hardest in most settings across functional pass rate, exact match (EM), and edit similarity (ES); (ii)~hardware accuracy is non-monotonic in code-structure depth, in contrast with the monotonic depth—accuracy curve known for software; (iii)~accuracy plateaus once the input context exceeds 2,048 tokens, while software completion continues to benefit from longer context; and (iv)~certain repository-level retrievers tuned on software underperform a no-retrieval baseline on HDL repositories because their structural and dependency assumptions are violated by hardware code.

Introduction

These models, trained on vast datasets encompassing both natural language and source code, have demonstrated remarkable proficiency in modeling programming languages as structured sequences and predicting logical code continuations. Consequently, LLM-based code completion has emerged as a valuable tool in real-world software development environments.

More recently, research efforts have shifted toward repository-level code completion, where models are required to leverage cross-file information such as imports, symbol definitions, and project structure. train a dedicated retriever to identify and retrieve relevant code fragments that can be incorporated into LLM-based code completion. In a complementary direction, equip LLMs with external tool APIs to more effectively utilize repository-level context during the code completion process. Despite their success in software code, LLM performance on hardware code remains unclear, as hardware differs fundamentally in execution semantics, structural parallelism, and cross-file dependency patterns. In particular, hardware code completion requires understanding static structure, signal connectivity, and design intent rather than purely sequential execution. We introduce MHRC-Bench, a multilingual repository-level benchmark with both MHRC-Bench-Train and MHRC-Bench-Eval, designed to expose structural and semantic failure modes of LLMs in hardware code completion.

Using MHRC-Bench-Train to fine-tune code LLMs, we observe substantial gains across complementary evaluation signals, including exact/edit similarity and functional pass rate. Billion-scale post-trained models such as Qwen2.5-Coder-7B and Qwen2.5-Coder-14B substantially improve over their pretrained counterparts, whose exact-match scores are near zero in preceding-context-only settings, and can outperform much larger general-purpose models under matched context windows. This demonstrates that MHRC-Bench-Train effectively enhances the hardware code completion capabilities of smaller-scale code LLMs.

Beyond the gains from post-training, our analysis surfaces four observations that distinguish hardware from software code completion. (i) Strong language dependence: In most settings, HLS is easiest and VHDL hardest across both functional pass rate and EM/ES; VHDL is the only language where full-context fill-in-the-middle (FIM) does not outperform preceding-context-only completion. (ii) Non-monotonic structural sensitivity: unlike software code, where deeper CST nodes monotonically correlate with higher LLM accuracy, hardware accuracy varies non-monotonically with structural depth. (iii) Context-length plateau: extending the input window from 2,048 to 4,096 tokens yields diminishing or negative returns on hardware code, whereas software code completion continues to benefit. (iv) Software-tuned retrieval breaks on hardware: repository-level retrievers designed for software (e.g., GraphCoder) underperform a no-retrieval baseline on HDL, because their structural and dependency assumptions are violated by hardware code (Section A.9).

Repository-level code completion has been studied extensively for software, with retrieval-augmented generation (RAG) methods such as RepoCoder, GraphCoder, and RLCoder, and structural-sensitivity analyses such as M2RC; however, this line of work has not transferred to hardware code, which differs fundamentally in execution semantics, structural parallelism, and cross-file dependency patterns.

Hardware code-generation benchmarks cover several tasks: VerilogEval and RTLLM evaluate module-level Verilog generation, while HDLEval covers multiple HDL dialects. HLS-Eval evaluates HLS generation, HLStrans provides paired C-to-HLS programs, and HLS-Seek optimizes HLS code generation for latency and resource usage. Reward-weighted on-policy distillation uses property-equivalence verification for natural-language-to-SystemVerilog-assertion generation. Phoenix-bench evaluates agents on repository-level hardware issue resolution. For repository-level completion, RTL-Repo remains limited to one HDL and primarily single-line targets, leaving multilingual completion and fine-grained performance analysis underexplored.

Data Collection

We collect publicly accessible hardware design repositories from GitHub, created after 2000 and with more than five GitHub stars. Source code retains its original license terms, including permissive and copyleft licenses; the released repository inventory records license notices and unresolved cases. To avoid data leakage, we remove files located in common vendor or dependency directories and deduplicate exact repository copies. The resulting corpus contains 47,200 source files written in Chisel, SystemVerilog, Verilog, HLS C/C++, and VHDL, drawn from 583 distinct repositories.

Experimental Analysis

Context format. As shown in Tables 3 and 4, the full-context outperforms the preceding-context-only in terms of EM and ES across all models and languages except VHDL. This suggests that bidirectional context is generally beneficial for code generation, while the rigid and highly structured nature of VHDL reduces the marginal benefit of right-context information. Hence, we focus on full-context in the following analysis.

Agentic Evaluation

We also evaluate the Aider code agent on MHRC-Bench-Eval. The detailed setup and results are in Appendix A.11. Although Aider was able to attain better performance than the strongest local LLMs fine-tuned on MHRC-Bench-Train, the improvement is 6.0 percentage points in EM. Furthermore, it costs ten times the token usage, suggesting that local, smaller models fine-tuned on our dataset are a more cost-efficient alternative for repository-level HDL code completion.

Key Observations

Performance varies significantly across hardware languages. In most settings, the four HDLs follow the same ordering across functional pass rate and EM/ES: HLS is easiest, reaching 48.0–71.9% pass rate across nine models; VHDL is hardest, staying below 23% even for the best post-trained model; and V/SV and Chisel fall between. We attribute this to three language-specific factors: HLS benefits from C/C++ pretraining priors, whereas VHDL has a smaller public-code footprint; VHDL’s verbosity and strict typing make small cast, width, or library-type errors fatal; and VHDL is the only language where full-context FIM does not beat preceding-context-only completion, suggesting preceding declarations are more informative than trailing context. Thus, HDL performance should be reported per language rather than only as an aggregate.

Similarities between hardware and software code. (1) Increasing the target length consistently degrades performance for both hardware and software code completion tasks. (2) LLMs perform well on identifier-level generation in both domains, indicating strong lexical and naming capabilities.

Differences between hardware and software code. (1) Structural sensitivity: For software code, deeper CST depths often correlate with improved LLM performance. However, for hardware code, increasing structural complexity can either improve or degrade performance. (2) Prompt length sensitivity. Increasing prompt length generally benefits software code completion, whereas for hardware code it yields limited or inconsistent gains (from 2048 to 4096 tokens), reflecting the greater difficulty of reasoning about hardware semantics.

Inappropriate retrieval can degrade performance. Retrieval-augmented methods are not always beneficial. We observe that retrieving irrelevant or noisy information can harm model performance, as shown by GraphCoder. The drop is not a critique of the GraphCoder algorithm itself; rather, it documents the cost of porting a software-tuned retriever to HDL, where its CST helpers and dependency-graph constructor (released for Python/Java) systematically miss function declarations and HLS-specific directives during retrieval (Appendix A.9). This highlights the importance of retrieval quality and motivates HDL-native retrievers as future work.

Conclusion and Limitations

We present MHRC-Bench, the first multilingual, repository-level benchmark for hardware code completion, covering RTL, HLS, and generator-based hardware languages across design and verification stages. Fine-grained structural and semantic annotations enable detailed analysis of LLM behavior in hardware-oriented settings, while repository-level functional checks complement EM/ES by measuring behavioral correctness. Post-training on MHRC-Bench-Train substantially improves performance, allowing smaller open-weight models to outperform strong general baselines under matched context windows. Limitations. MHRC-Bench is built from open-source repositories, which may not fully reflect proprietary HDL development practices. Its heuristic semantic labels may miss ambiguous or project-specific design intent, and the benchmark currently excludes analog/mixed-signal design and physical-design scripts. Although we strictly enforce repository-level train/test separation and try to avoid internet data leakage, we cannot fully rule out prior exposure of public test repositories in closed-source pretraining data.

Cross-file dependency

The target file often depends on functions, definitions, or modules defined in other files to be completed correctly. Since different hardware description languages follow distinct grammatical and structural rules, we adopt language-specific strategies to identify and extract cross-file dependencies.

For each task file, we compute cross-file dependencies as the number of distinct other files within the same repository that the file depends on, using deterministic, language-specific resolution rules. For HLS C/C++, dependencies are inferred from resolved include directives, macro references, and user-defined type usages. For VHDL, dependencies are determined by references to design units such as entities, packages, and contexts. For Chisel/Scala, dependencies are identified through resolved imports and statically resolvable symbol usages. For SystemVerilog/Verilog, dependencies are computed from includes, package references, module or interface instantiations, macro usage, and typedef references. In all cases, the final dependency count equals the number of uniquely resolved dependent files, excluding the file itself, and results are reported as averages across task items (or aggregated per file or repository, depending on the evaluation setting).

Statistical uncertainty

The reported EM, ES, and functional pass rates are point estimates. We do not report confidence intervals, significance tests, or means and standard deviations across independent fine-tuning seeds. The results therefore do not quantify sampling uncertainty or variation across fine-tuning runs.

Case Study of Pretrained-Model Responses

To illustrate the effect of fine-tuning on local models, we analyze the completions generated by Qwen2.5-Coder-7B on fill-in-the-middle tasks before and after fine-tuning. Specifically, we list for each tested language common errors made by the model that were significantly improved by fine-tuning.

A.8.1 Verilog/SystemVerilog

Structural Hallucination: The pre-trained model is prone to regurgitating file headers, copyright notices, or artificial file boundary markers in the middle of code blocks. In custom_uvm_report_server for instance, the pre-trained model suddenly outputs a full copyright header // Copyright 2007-2010 Mentor Graphics…inside the build_phase function instead of the expected super.build_phase(phase); call.

Pattern Oversight: The pre-trained model fails to follow obvious naming sequences or structural patterns established immediately before the target line. In SystemVerilog Assertions, for instance, the model failed to recognize the naming pattern of logic gnt1; logic gnt2; and even missed the comment //3 Requests to Arbiter logic req1;logic req2; logic req3;. Instead, it regurgitated earlier comments and produced irrelevant code.

Logical Confusion: The pre-trained model sometimes generates code that is syntactically valid SystemVerilog but logically disconnected from the immediate control flow (e.g., jumping to a different state in a Finite State Machine). In virtio, the code is strictly defining an always_ff block for reset logic. The pre-trained model attempts to insert FSM state logic _EVENT_IDX: begin… from a case statement that belongs elsewhere, ignoring the always_ff structure.

A.8.2 HLS

Structural Hallucination: Similar to other languages, the pre-trained model for HLS code often completely loses track of the file position and hallucinates the start of a new file. Instead of generating the next line of code, the model outputs copyright notices, include guards, or library imports. For example, in hls-spmv, the pre-trained model outputs #include “spmv.h” despite the cursor being positioned in the spmv_kernel function.

C++/HLS Confusion: HLS often requires specific syntax not included in standard C++ that are used for reporting and optimization directives. The pre-trained model often writes valid standard C++ but misses these hardware-description necessities. In hls_spmv, for instance, the ground truth required an L1: in the loop L1: for (int i = 0; i < NUM_ROWS; i++), which the pre-trained model neglected.

Syntax Hallucination: Similar to other languages, the pre-trained model fails to recognize the contextual logic and syntax. In libllsm, for instance, while the context explicitly requires a memory allocation (calloc), the pre-trained model instead attempts to define a new function FP_TYPE* llsm_envelope…

A.8.3 VHDL

Structural Confusion: Similar to other languages, the pre-trained model struggles to comprehend the context and has the tendency to hallucinate file headers, library declarations, or copyright notices in the middle of an active code block. For the FPGA-Speech-Recognition repository, for instance, the pre-trained model outputted library IEEE; use IEEE.STD_LOGIC_1164.ALL;… entity UART_PARITY… despite the target line being deep inside a generate block for odd parity. More severely, the model often confuses code segments with prompt structures and output strings used to mark file boundaries in prompts. In the cpu_for_nscscc2022_single repository, the model outputs --- FILE: dcache_tag.vhd (END) --- immediately, skipping the required generic map assignments C_MEM_TYPE => 1.

Syntax Confusion: VHDL distinguishes heavily between concurrent statements and sequential statements inside processes or subprograms. The pre-trained model often mixes these contexts. In FPGA-I2C-Minion, the pre-trained model hallucinates unrelated procedure calls i2c_wait_quarter_clock or definitions that belong in a testbench or architecture body, not the sequential spike generator logic that the target line is in.

A.8.4 Chisel

Language Confusion: The pre-trained model sometimes fails to generate valid Chisel syntax or uses generic tokens that don’t fit the Chisel hardware construction paradigm. For example, in rjrouter, the ground truth is c => new GCDUnitTester(c), but the pre-trained model outputs <|fim_middle|>, indicating a complete failure to generate content.

GraphCoder Modifications and Limitations

The original implementation of GraphCoder is designed for preceding context tasks. To evaluate its performance on full context tasks, we modified GraphCoder such that the right context is also preserved and included during prompt assembly. As the graph builder and the retriever operate independently of the left and right contexts, this has no other effect on the functionality of GraphCoder.

Furthermore, the original implementation of GraphCoder included helper functions in utils/ccg.py for traversing CSTs, but these functions only supported Java and Python. To extend support to hardware languages, we added helper functions for each language’s syntax and for identifying control-flow and data dependencies. We also made minor changes to include HDL languages during tree-sitter parser selection and code-file filtering.

Absence of function declarations. We found that 16.9% of snippets retrieved by RepoCoder contain HLS function definitions, while the number drops to 1.8% for GraphCoder. This arises from a design in the official GraphCoder implementation: line 79 of utils/slicing.py explicitly filters out nodes with definition in their type names, likely to focus on executable statements. However, this excludes many function signatures and affects HLS retrieval because key synthesis constraints (types, interfaces, and pragmas that shape parallelism) are often encoded in definitions and headers rather than in nearby data/control-flow statements.

Absence of HLS constructs. Because tree-sitter has no dedicated HLS grammar, we use tree-sitter-cpp to support HLS. However, the C++ grammar does not process HLS-specific constructs, causing them to be left out of retrieval. For instance, 4.2% of snippets retrieved by RepoCoder contain HLS-specific directives, while the rate for GraphCoder is only 0.7%. This causes many information-carrying synthesis constraints to be systematically omitted from GraphCoder’s retrieved context. In HLS, pragmas and vendor-specific types are not merely stylistic annotations: they encode parallelization, memory partitioning, and interface protocols that directly affect correctness and implementability.

Agentic Evaluation Results

To better demonstrate that MHRC-Bench is compatible with agentic systems, we additionally evaluate the Aider code agent. Although the strongest Aider configuration (Gemini-2.5-Pro) achieves better performance than the strongest fine-tuned Qwen2.5-Coder-14B baseline with RepoCoder, its advantage is modest, achieving an overall EM rate of 45.0% compared to Qwen-14B’s 38.9%, resulting in a gain of 6.0 percentage points. This comes at immense computational costs: the agentic runs consume 81.42M total tokens over 3,566 instances, or 22,833 tokens per instance on average, whereas the fine-tuned local models are evaluated with a 2,048-token input budget and a 64-token maximum generation length. It also suffers from longer latency compared with local inference on small models, suggesting that our fine-tuned model is perhaps a more practical solution in practical code completion scenarios that require fast, low-cost inference.