This adds the ability to specify an instruction encoding as specializing that of another. In some cases, there is a desire to specialize some instructions with specific operand values to different mnemonics, even though the decoding of that instruction would match the "general" instruction. For instance, in RiscV the 'rdcycle t5' instruction is the same as 'csrrs t5, zero, cycle', or even 'csrrs t5, cycle'. The new capability allows this to be expressed in the bin_fmt file as: rdcycle : specializes csrrs_nw : u_imm12 == 0xc00; Which means that rdcycle has the same encoding as csrrs_nw, with one added constraint. The generated decoder will now contain code to check for rdcycle whenever a csrrs_nw instruction is matched, and prefer to return that opcode as opposed to the more generic csrrs_nw opcode. Multiple such specializations can be added for an opcode. There is no order in which they are considered, except that the base opcode will be considered last. PiperOrigin-RevId: 706018484 Change-Id: I2a5393a33d96ab3023b04defef24dd83111f527c
MPACT-Sim is a toolkit that reduces the effort to create instruction set simulators, and make the resulting simulators easy to change and extend.
This repository contains the C++ code for MPACT-Sim, tools and library support for making it simple to create easily retargetable simulators for a wide range of instruction set architectures.
The toolkit consists of three major components. The first is the isa and binary decoder generators, that take in descriptors of the isa and the binary encoding of instructions and produce C++ code used in writing a decoder. The second is the generic classes that implement the instruction objects, registers, and other simulated state objects, and the code necessary to manipulate them, as well as supporting writing the semantics of the instructions. Lastly, there are utility classes that make it easier to put together a finished simulator, including memory classes and an ELF loader.
MPACT-Sim utilizes the Bazel build system. The easiest way to install bazel is to use Bazelisk, a wrapper for Bazel that automates selecting and downloading the right version of bazel. Use brew install bazelisk on macOS, choco install bazelisk on Windows, and on linux, download the Bazelisk binary, add it to your PATH, then alias bazel to the bazelisk binary.
You need to use bazel version >= 7.0 to build this project.
MPACT-Sim depends on Java, so a reasonable JRE has to be installed. For macOS, run brew install java, on linux sudo apt install default-jre, and on Windows follow the appropriate instructions at java.com.
To build the mpact-sim libraries, use the command bazel build ...:all from the top level directory. To run the tests, use the command bazel test ...:all
mpact/sim/decoder
This directory contains the code that implements the tools that parse .isa and .bin_fmt files, which define the instructions and instruction encodings of an ISA, and generate C++ code for the instruction decoder for an MPACT-Sim simulator.
The tools are built automatically and the process is largely invisible when using bazel with the appropriate build targets - see the tests in mpact/sim/decoder/test for examples.
mpact/sim/decoder/vscode
This directory contains files necessary to build syntax highlighting extensions for VS Code for .isa and .bin_fmt files. Look in the mpact/sim/decoder/vscode/README.md file for directions.
mpact/sim/generic
This directory contains all the generic classes provided for use in writing MPACT-Sim instruction set simulators.
mpact/sim/util
This directory contains code for a generic ELF program loader, and for a set of classes that can be used to implement memories used in an instruction set simulator.