Fix RISC-V vector mask logical and unary operations to respect tail-agnostic policy limits

This change fixes a bug introduced in an earlier change where vector mask logical operations (e.g., `vmnand`, `vmand`) and vector unary mask instructions (`vmsbf`, `vmsif`, `vmsof`) were extended to evaluate across the entire physical register block (`physical_bits`) rather than safely bounding execution at the dynamic vector length (`vlen`).

According to Section 3.4.3 of the RISC-V V-Extension specification:
- "Mask destination tail elements are always treated as tail-agnostic, regardless of the setting of vta."
- "When a set is marked agnostic, the corresponding set of destination elements in any vector destination operand can either retain the value they previously held, or are overwritten with 1s."

By running the active bitwise logical lambdas (such as `~` for NAND/NOR) over the tail zeroes, the ISS unconditionally modified tail elements. Worse, for operations lacking a bitwise NOT (such as `vmand`), this approach overwrote the tail elements with `0`s, which is an explicit violation of the specification (must be undisturbed or overwritten with `1`s).

This commit reverts the `BitwiseMaskBinaryOp` and unary mask instructions to bound processing up to `vlen`, aligning the ISS with the valid "undisturbed" implementation of the tail-agnostic policy. This resolves mismatches against Spike trace outputs and ensures `vmnand.elf_test` and related architectural tests pass successfully.

PiperOrigin-RevId: 978109338
3 files changed
tree: 551947d295ea329ca8c9b4b6b0a6fbfbd805fe9d
  1. .github/
  2. riscv/
  3. .bazeliskrc
  4. .bazelrc
  5. .bazelversion
  6. .gitignore
  7. BUILD
  8. CODE_OF_CONDUCT.md
  9. CONTRIBUTING.md
  10. LICENSE
  11. MODULE.bazel
  12. README.md
  13. SECURITY.md
README.md

MPACT-RiscV

MPACT-RiscV is an implementation of an instruction set simulator for the RiscV instruction set architecture created using the MPACT-Sim simulator tools and framework, for which there are tutorials at Google for Developers.

The instruction set is described in a set of .isa files, and the instruction encoding in a corresponding set of .bin_fmt files. The instruction semantics are implemented in a set of of functions distributed over a large set of C++ files *_instructions.{cc,h}.

The top level simulator control is implemented in riscv_top.{cc,h}, and the simulators are instantiated from main in rv{32,64}g_sim.cc.

Building

Bazel

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.

Java

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.

Build and Test

To build the mpact-sim libraries for x86 based processors, use the command bazel build ...:all from the top level directory. To run the tests, use the command bazel test ...:all.

For Apple computers with Arm64 M series chips, use bazel build --cpu=darwin_arm64 ...:all and bazel test --cpu=darwin_arm64 ...:all.

The build targets rv32g_sim and rv64g_sim provide RiscV simulators for the 32 bit and 64 bit variants of RiscV scalar architectures respectively. Decoding and execution support for vector instructions is included, but has not been built into these targets, though adding them to these simulators is not particularly daunting.