RISC-V interpreter from the future
A future RISC-V interpreter has been developed, offering numerous enhancements and features. This interpreter is fully modular and generic, panics-free, adheres to the RISC-V specification, and is passable for blockchain purposes. The interpreter passes the RISC-V Architectural Certification Tests and executes at compile time. To achieve these advanced capabilities, the interpreter relies on ~30 nightly Rust features, including advanced const generics and guaranteed tail calls.
The RISC-V specification is modular, comprising various base ISAs and extensions. The interpreter implementation mirrors this modular structure, with each extension implemented separately and composed according to the specification. Memory, register file, and general-purpose register types are all generic, allowing for modular implementation of extension-specific environments, such as additional registers (floats, vectors, etc.).
Instruction definition and decoding are handled by a separate crate, enabling users to utilize the decoder independently if desired. The implementation follows the specification closely, with specific requirements for composability, such as using enum with Self:: and avoiding return statements. Dependencies between instructions are expressed using inheritance and conditional dependencies, allowing for the expression of predicated instructions.
The interpreter includes mechanisms to exclude unsupported instructions and reorder instructions using macros. Instruction execution adheres to specific requirements and is annotated with a macro. The API design has reasons for its structure, but the generated code is more interesting. The interpreter generates efficient implementations using nightly Rust features and a build script that processes macros, ultimately creating a fast and compact implementation.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.