Skip to main content

rvsim

PyPI crates.io ISA Tests ISA Boots Linux License

Cycle-level RISC-V 64-bit system simulator with a composable Python API for architecture research and design-space exploration.

Documentation · PyPI · Rust Core (crates.io) · Changelog


rvsim models a complete superscalar processor cycle by cycle. It implements two pluggable microarchitectural backends — out-of-order and in-order — sharing a common frontend, memory hierarchy, and SoC device layer. It boots Linux 6.6 through OpenSBI to a BusyBox shell and passes all 188 riscv-tests. The chipsalliance riscv-vector-tests suite is cross-checked against spike.

Accuracy. rvsim simulates every cycle, but it is not cycle-accurate to any one machine yet. It models how real cores behave and measures itself two ways: against gem5's O3 CPU, where compute- and branch-bound kernels are within a few percent and memory- and vector-bound ones are still 10 to 60% apart (Error against gem5), and against hardware, where configurations calibrated to the SiFive P550 and the Cortex-A72 reproduce their measured cache and memory latencies and the A72 one runs CoreMark within 6% of a Raspberry Pi 4 (Linux Benchmarks). We are working to close the remaining gaps.

Install

pip install rvsim

Requires Python 3.11+. Ships pre-built wheels for Linux x86_64.

Quick Start

from rvsim import Config, BranchPredictor, Cache, Environment

config = Config(
    width=4,
    branch_predictor=BranchPredictor.Tage(),
    l1d=Cache("32KB", ways=8, latency=1, mshr_count=8),
    l2=Cache("256KB", ways=8, latency=10),
)

result = Environment(binary="software/bin/programs/qsort.elf", config=config).run()
print(result.stats.query(r"^ipc$|bp\.committed\.(accuracy|mispredicts)|(l1d|l2)\.miss_rate"))
core0.bp.committed.accuracy      0.8750
core0.bp.committed.mispredicts  386,904
core0.cache.l1d.miss_rate        0.0914
core0.cache.l2.miss_rate         0.5149
ipc                              1.1588

Stats are keyed by path (core0.cache.l1d.misses, hart0.retired_insts); see Stats & Observability.

Features

Two Pipeline Backends

Out-of-order superscalar — Physical register files with speculative and committed rename maps and branch checkpoints, CAM-style issue queue with wakeup/select and oldest-first priority, stores that issue their address and data separately, reorder buffer for in-order commit with precise exceptions, load queue with store-set memory-dependence prediction, store buffer with forwarding, and a configurable functional unit pool (per-type counts and latencies).

In-order — Configurable width, scoreboard-based operand tracking, program-order issue onto the same functional unit pool, backpressure gating. Shares the same frontend and commit/memory/writeback stages as the O3 backend, making both modes directly comparable on identical workloads.

Both backends enforce identical serialization semantics: system/CSR instructions wait for all older completions, FENCE respects predecessor/successor ordering bits, loads wait for older store address resolution.

Memory Hierarchy

  • SV39 / SV48 / SV57 virtual memory — separate iTLB/dTLB, an optional shared L2 TLB, a hardware page table walker whose PTE reads go through the L1D, and Svade or Svadu A/D handling
  • L1i / L1d / L2 / L3 caches — independently configurable size, associativity, latency, and replacement policy (LRU, PLRU, FIFO, Random, MRU)
  • Non-blocking caches at every level via MSHRs with request coalescing and writeback buffers; caches hold tags only and every access takes effect where it is served
  • Hardware prefetchers per cache level: next-line, stride, stream, tagged
  • Inclusion policies: non-inclusive, inclusive (back-invalidation), exclusive (L1-L2 swap)
  • Memory controllers — fixed latency, a row-buffer DRAM model, or a JEDEC DDR5 controller with command timing, refresh and power-down

Branch Prediction

Seven pluggable predictors with shared BTB, RAS, and global history register:

Predictor Description
Static Always not-taken (baseline)
GShare PC XOR global history, 2-bit counters
BHT Rocket's branch history table: counters indexed by the PC, with hashed global history above the PC bits
Tournament Local + global two-level adaptive with meta-predictor
Perceptron Neural predictor with weight vectors
TAGE Tagged geometric history lengths
ScLTage TAGE-SC-L (TAGE, loop predictor, statistical corrector) with ITTAGE for indirect targets; defaults to Seznec's 64KB CBP-5 configuration

RAS recognizes both x1 and x5 as link registers per RISC-V spec Table 2.1, including coroutine swap detection.

ISA & Privileged Architecture

RV64IMAFDC + V — base integer, multiply/divide, atomics (LR/SC + AMO), single/double float with IEEE 754 NaN-boxing, compressed instructions, and the V vector extension (RVV 1.0), with Zba, Zbb, Zbc, Zbs, Zbkb, Zbkx and Zfh. M/S/U privilege modes, trap delegation, MRET/SRET, WFI, SFENCE.VMA, FENCE/FENCE.I, PMP (16 regions), Sstc, Svadu and Sdtrig triggers. Cache management ops via Zicbom and Zicboz.

Multi-core systems (Config(hart_count=N)) give every hart its own core and private caches behind a MESI coherence fabric: a broadcast or snoop-filter home agent at the LLC and a crossbar, ring, mesh, torus or hypercube interconnect, with per-hart CLINT and PLIC contexts and a device tree that enumerates every hart.

The vector extension supports configurable VLEN (default 256) and ELEN=64. Implemented sub-extensions: Zvfh (half-precision FP), Zvbb / Zvbc (bit-manip and carryless multiply), Zvkn (AES, SHA-256 and SHA-512), Zvks (SM4 and SM3), Zvkg (GHASH). Vector ops are cross-checked against spike.

Passes all 188/188 tests in riscv-software-src/riscv-tests and the chipsalliance riscv-vector-tests suite.

SoC Devices

CLINT timer, PLIC interrupt controller, 16550A UART, VirtIO MMIO block device, Goldfish RTC, SYSCON (poweroff/reboot), HTIF. Auto-generated device tree blob.

Python API

Comparing Configurations

from rvsim import BranchPredictor, Config, Environment, Stats

rows = {}
for name, bp in [("GShare", BranchPredictor.GShare()), ("Tage", BranchPredictor.Tage())]:
    r = Environment("program.elf", Config(branch_predictor=bp)).run()
    rows[name] = r.stats

print(Stats.tabulate(rows, title="Branch Predictor Comparison"))

Parallel Sweeps

Sweep distributes all (binary, config) combinations across CPU cores:

from rvsim import Sweep, Config, Cache

results = Sweep(
    binaries=["qsort.elf", "mandelbrot.elf", "maze.elf"],
    configs={
        f"L1={s}": Config(l1d=Cache(s, ways=8, mshr_count=8), console="Quiet")
        for s in ["8KB", "16KB", "32KB", "64KB"]
    },
).run(parallel=True)

results.compare(metrics=["ipc", "core0.cache.l1d.misses"], baseline="L1=8KB")

Low-Level Control

from rvsim import Simulator, Config, reg, csr

cpu = Simulator(Config(width=4), binary="program.elf")

for _ in range(1000):
    cpu.tick()
    cpu.pipeline_snapshot().visualize()

cpu.run_until(pc=0x80001234)
cpu.run_until(privilege="U")

print(hex(cpu.regs[reg.A0]))
print(hex(cpu.csrs[csr.MSTATUS]))
print(cpu.mem64[0x80001000])

cpu.save("checkpoint.bin")

Analysis Scripts

Ready-to-run design-space exploration in examples/analysis/:

Script Description
branch_predict.py Accuracy comparison across all seven predictors
cache_sweep.py L1D size vs miss rate and IPC impact
design_space.py Multi-dimensional width x cache size sweep
o3_inorder.py Out-of-order vs in-order backend comparison
width_scaling.py IPC vs superscalar width
stall_breakdown.py Stall cycles by cause
top_down.py Top-down microarchitecture analysis
inst_mix.py Instruction class breakdown
rvsim examples/analysis/branch_predict.py
rvsim examples/analysis/cache_sweep.py --sizes 4KB 8KB 16KB 32KB 64KB
rvsim examples/analysis/o3_inorder.py --widths 1 2 4

Building from Source

Requires Rust (the version in rust-toolchain.toml), Python 3.11+, and two RISC-V GCCs for the bundled programs: a Linux one (riscv64-linux-gnu-gcc; SE_TARGET= overrides the prefix) and a bare-metal one (riscv64-elf-gcc; TARGET=). nix develop provides all of them.

git clone https://github.com/willmccallion/rvsim
cd rvsim
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt
maturin develop --release
make -C software

Linux Boot

Boots Linux 6.6 through OpenSBI to a BusyBox shell on both backends. The default boot is eight out-of-order cores from the fast preset (64KB TAGE-SC-L) with coherent private caches over a mesh and four channels of DDR5-5600.

make -C software linux              # Build kernel + rootfs via Buildroot
make run-linux                      # Boot 8 SMP cores (login: root, no password)
rvsim tools/boot_linux.py --harts 1   # Single core

Documentation

Full documentation including architecture deep-dives, API reference, and examples:

willmccallion.github.io/rvsim

Contributing

See CONTRIBUTING.md for the repository layout, the checks a change must pass, and the policy on AI-assisted contributions.

License

Licensed under either of MIT or Apache-2.0, at your option.

Metadata

Release files for rvsim 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rvsim 3.0.0
File Size Uploaded Provenance Actions
rvsim-3.0.0.tar.gz 1.1 MB With provenance Details for rvsim-3.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rvsim 3.0.0
File Actions
rvsim-3.0.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for rvsim-3.0.0-cp311-abi3-win_amd64.whl
rvsim-3.0.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for rvsim-3.0.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
rvsim-3.0.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for rvsim-3.0.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
rvsim-3.0.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for rvsim-3.0.0-cp311-abi3-macosx_11_0_arm64.whl
rvsim-3.0.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for rvsim-3.0.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 10.6 MB

Release files / rvsim-3.0.0.tar.gz

Download URL rvsim-3.0.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
7f67e76a285ef36afce2d0f5bf9434183171baff42ebf97a3d592671739fc0de
BLAKE2b-256 checksum
How to use checksums
5a1cc1a1f0d2813545b51da55ec0aebbbd74cfc585efab5fee4b72dd79fa7a17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / rvsim-3.0.0-cp311-abi3-win_amd64.whl

Download URL rvsim-3.0.0-cp311-abi3-win_amd64.whl
Size 1.9 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fc10cdbf247e52a072f472c84241f3bba893b664bcb781ddbf5ca925ca2748da
BLAKE2b-256 checksum
How to use checksums
e85a5bc3b231b3cda44c96754ce5c5b395ca5cb4846c29c958dc51b399f5c248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / rvsim-3.0.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL rvsim-3.0.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 2.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
afae121f2273f7eaf16ea7458b5b244f28f35b396165efbbc99903d78c2441bc
BLAKE2b-256 checksum
How to use checksums
846905d486895355e3b478490f84d2ed216b4ee6586a8fa746dd801ba6de1e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / rvsim-3.0.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL rvsim-3.0.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
3f46cddb9abe24be4675feaf90136a5cf7fcde0b929f3a66b259399bdc24d3f1
BLAKE2b-256 checksum
How to use checksums
6b4f3dcf80490196a8020154c86574c9eaeab5bd1ec00959418d7d1c807a11b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / rvsim-3.0.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL rvsim-3.0.0-cp311-abi3-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0b94315d8ea0ec557e98bd6ce460af7f6286bb8383c7e81e7d60f96c2942a7fd
BLAKE2b-256 checksum
How to use checksums
6c0a31c5ece449c80e86f234f796ba138cb3f3a3244cca1fe33357ab973dc47e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / rvsim-3.0.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL rvsim-3.0.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b2a84eb663b01d48c9d52103357a3bc49960c0925cd5ef32c57b608182f066fc
BLAKE2b-256 checksum
How to use checksums
a4c5f6f0a4011718d953bd53cea6efc1d9b2af558f35def537a78f0401bc344d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for rvsim 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for rvsim-3.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page