[Paper Review] Designing a CPU model: from a pseudo-formal document to fast code
This paper presents a method to automatically generate a high-performance, optimized SystemC/TLM Instruction Set Simulator (ISS) for the ARMv6 architecture directly from the pseudo-formal sections of its official reference manual. By extracting instruction encodings, behavior in abstract syntax trees (ASTs), and assembly syntax, applying automated optimizations, and generating a dynamic-translation-enabled ISS, the approach achieves simulation speeds comparable to hand-written ISSes, with a 0.9% average performance gain over a hand-coded ARMv5 ISS.
For validating low level embedded software, engineers use simulators that take the real binary as input. Like the real hardware, these full-system simulators are organized as a set of components. The main component is the CPU simulator (ISS), because it is the usual bottleneck for the simulation speed, and its development is a long and repetitive task. Previous work showed that an ISS can be generated from an Architecture Description Language (ADL). In the work reported in this paper, we generate a CPU simulator directly from the pseudo-formal descriptions of the reference manual. For each instruction, we extract the information describing its behavior, its binary encoding, and its assembly syntax. Next, after automatically applying many optimizations on the extracted information, we generate a SystemC/TLM ISS. We also generate tests for the decoder and a formal specification in Coq. Experiments show that the generated ISS is as fast and stable as our previous hand-written ISS.
Motivation & Objective
- To reduce the long, error-prone development time of hand-written ISS implementations for embedded systems.
- To leverage pseudo-formal descriptions in processor reference manuals (e.g., ARMv6) for automatic code generation.
- To generate a high-performance ISS that matches or exceeds the speed of hand-optimized versions.
- To produce additional artifacts such as formal Coq specifications and decoder unit tests from the same source.
- To enable easier retargeting to other ISAs (e.g., MIPS, PowerPC) through reusable intermediate representations.
Proposed method
- Extract pseudo-formal instruction descriptions (encoding tables, pseudo-code, syntax) from the ARMv6 reference manual using a custom tool chain.
- Transform the extracted data into a standardized intermediate representation using abstract syntax trees (ASTs) for behavior and structured metadata for syntax and encoding.
- Apply multiple automated optimizations to the intermediate representation, including data flow analysis, parameter and variable tracking, and branch prediction modeling (e.g., may_branch function).
- Generate a SystemC/TLM-based ISS with dynamic translation—caching decoded instructions to avoid re-decoding on repeated execution.
- Generate formal Coq specifications and unit tests for the decoder from the same intermediate representation.
- Support extensibility by designing back-ends for LLVM-based dynamic translation and potential assembler generation.
Experimental results
Research questions
- RQ1Can a high-performance, optimized ISS be automatically generated from the pseudo-formal sections of a processor reference manual without manual code modification?
- RQ2Does the automatically generated ISS achieve simulation performance comparable to a hand-optimized, hand-written ISS?
- RQ3To what extent can automated analysis and transformation of intermediate representations improve both correctness and performance in ISS generation?
- RQ4Can the same intermediate representation support multiple outputs, such as formal specifications, tests, and optimized code?
- RQ5How does the approach scale or adapt to other instruction set architectures with similar documentation structures?
Key findings
- The generated ARMv6 ISS achieves a global average simulation speed of 92.47 Mi/s, which is 0.9% faster than the hand-written ARMv5 ISS (91.60 Mi/s), with results within measurement accuracy.
- On 64-bit systems, the generated ISS outperforms the hand-written version by up to 7.4% in some benchmarks, indicating better portability and performance on modern hardware.
- The ISS demonstrates consistent performance across multiple benchmarks (crypto, loop, sorting) and compilation settings (O0 and O3), with minimal performance degradation on 32-bit systems.
- The approach reduces development time significantly compared to hand-coding, while maintaining equivalent performance and stability.
- The intermediate representation enables the automatic generation of formal Coq specifications and unit tests for the decoder, enhancing verification and maintainability.
- The method is extensible to other ISAs such as MIPS and PowerPC, with potential for further optimization if documentation quality improves (e.g., ARMv7 manual).
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.