Skip to main content

High-performance RISC-V cycle-accurate system simulator

Project description

RISC-V 64-bit System Simulator

WARNING: This project is currently broken due to ongoing refactors from version 0.9.0. Version 1.0.0 will be released once these refactors are complete and stable.

A cycle-accurate system simulator for the RISC-V 64-bit architecture (RV64IMAFD). Features a 5-stage pipelined CPU, comprehensive memory hierarchy, and can boot Linux (experimental).

Technologies Used

  • Languages: Rust (Simulator), C (Libc/Software), RISC-V Assembly, Python (Analysis)
  • Concepts: Pipelining, Virtual Memory (SV39), Cache Coherence, Branch Prediction, OS Development
  • Tools: Make, GCC Cross-Compiler, Cargo

Key Implementation Details

CPU Core (Rust)

  • 5-Stage Pipeline: Implements Fetch, Decode, Execute, Memory, and Writeback stages with full data forwarding and hazard detection.
  • Branch Prediction: Multiple swappable predictors including Static, GShare, Tournament, Perceptron, and TAGE (Tagged Geometric History).
  • Floating Point: Support for single and double-precision floating-point arithmetic (F/D extensions).

Memory System

  • Memory Management Unit (MMU): Implements SV39 virtual addressing with translation lookaside buffers (iTLB and dTLB).
  • Cache Hierarchy: Configurable L1, L2, and L3 caches supporting LRU, PLRU, and Random replacement policies.
  • DRAM Controller: Simulates timing constraints including row-buffer conflicts, CAS/RAS latency, and precharge penalties.

Example Programs (C & Assembly)

  • Custom Libc: A minimal standard library written from scratch (includes printf, malloc, string manipulation).
  • Benchmarks: Complete programs including chess engine, raytracer, quicksort, and performance microbenchmarks.
  • User Programs: Various test applications (Game of Life, Mandelbrot, 2048, etc.).

Performance Analysis

  • Automated Benchmarking: Python scripts to sweep hardware parameters (e.g., cache size vs. IPC) and visualize bottlenecks.
  • Design Space Exploration: Hardware configuration comparison and performance analysis tools.

Project Structure

rvsim/
├── crates/              # Rust workspace
│   ├── hardware/        # CPU simulator core
│   └── bindings/        # Python bindings (PyO3)
├── rvsim/               # Python package for scripting
├── software/            # System software
│   ├── libc/            # Custom C standard library
│   └── linux/           # Linux boot configuration
├── examples/            # Example programs
│   ├── benchmarks/      # Performance benchmarks
│   └── programs/        # User applications
├── scripts/             # Analysis and utilities
│   ├── benchmarks/      # Performance analysis scripts
│   └── setup/           # Installation helpers
└── docs/                # Documentation

Installation

Python bindings (via pip):

pip install rvsim

Build from Source

Requirements:

  • Rust toolchain (1.70+)
  • riscv64-unknown-elf-gcc cross-compiler
  • Python 3.10+ with maturin (for Python bindings)

Quick Start

Build everything:

make build

Run a benchmark:

rvsim -f software/bin/benchmarks/qsort.bin

Run a Python script:

rvsim --script scripts/benchmarks/tests/smoke_test.py

Available Make Targets

make help           # Show all available targets
make python         # Build and install Python bindings (editable)
make software       # Build libc and example programs
make test           # Run Rust tests
make lint           # Format check + clippy
make run-example    # Quick test (quicksort benchmark)
make clean          # Remove all build artifacts

Python Scripting

The simulator supports Python scripting for hardware configuration and performance analysis:

from rvsim import SimConfig, Simulator

# Configure a machine model
config = SimConfig.default()
config.pipeline.width = 4
config.pipeline.branch_predictor = "TAGE"
config.cache.l1_i.enabled = True
config.cache.l1_i.size_bytes = 65536

# Run a binary
Simulator().with_config(config).binary("software/bin/benchmarks/qsort.bin").run()

See docs/ for full API documentation and architecture details.

Documentation

Linux Boot (Experimental)

⚠️ Experimental Feature — The simulator can boot Linux, though full boot is still in progress:

make linux          # Download and build Linux (takes time)
make run-linux      # Attempt to boot Linux

License

Licensed under either of the following, at your option:

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project shall be dual-licensed as above, without any additional terms or conditions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rvsim-0.10.0.tar.gz (275.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rvsim-0.10.0-cp310-abi3-win_amd64.whl (331.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

rvsim-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (466.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

rvsim-0.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (452.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

rvsim-0.10.0-cp310-abi3-macosx_11_0_arm64.whl (414.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rvsim-0.10.0-cp310-abi3-macosx_10_12_x86_64.whl (438.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file rvsim-0.10.0.tar.gz.

File metadata

  • Download URL: rvsim-0.10.0.tar.gz
  • Upload date:
  • Size: 275.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rvsim-0.10.0.tar.gz
Algorithm Hash digest
SHA256 54e21c2941be11c925cf0f7a88afdb2320cd380abf2770d7719e917a64497cde
MD5 fa76ae39ef3d22e647fb67460576a99a
BLAKE2b-256 40252360415c1d53ea4a046a834f9be81ce58aa3955755321feb826467e3e849

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0.tar.gz:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rvsim-0.10.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 331.2 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rvsim-0.10.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 964ea7c444d7c37c204e745f2ccc646acd40bed80d52ce72d69f1c188b4d7f62
MD5 3e4c801cd62126d4b4e5cacfd7d4a837
BLAKE2b-256 457b5a9aecc73d8978cccb9159c3a34996e792b060ee4e02e43ee200d807c56c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec52a2f271446e69716a04113eacacf47b32e3765685f9014efd8e50d9e37d16
MD5 73c36343ca75b3ce267c3c2e16c0ee98
BLAKE2b-256 e00b6a04aa76be2297f6e3282a2e3a16a37c530d50773a946fcd5fadac067363

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2150981282248243eafb4130bcb875142800c3f561d3c2edce14a5281018641d
MD5 9eade39acbc76bdcda59b4fb27bbc65a
BLAKE2b-256 b51288b1b7759990094c60cdc9c83cb41a771b0d6481a767e13415a035f1009d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc12ee44e43afc660582e5d3bc5ee4e6c92dafbba76fff5e013eee4f8034bf35
MD5 07114809acf7a229942a363320da8794
BLAKE2b-256 d2c1fd52a1d8938f0ecd325a1908a6eac131f2c9a5e41361b240564012e8b506

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ef2d4c971a08cbc72cc0de2b061577bda124e010e1f3cc243dcc383340273660
MD5 d9744821234db7dfc19017300ee1487f
BLAKE2b-256 5b8435737ab86d7a9a7f163953dc24b6ee579d0fea932f114d660a45731ec05e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page