Skip to content

feat: Add CXXRTL-based simulation infrastructure#159

Closed
robtaylor wants to merge 6 commits intomainfrom
feat/cxxrtl-sim
Closed

feat: Add CXXRTL-based simulation infrastructure#159
robtaylor wants to merge 6 commits intomainfrom
feat/cxxrtl-sim

Conversation

@robtaylor
Copy link
Contributor

Summary

  • Adds Python ctypes bindings for CXXRTL C API (chipflow/sim/cxxrtl.py)
  • Adds build infrastructure to compile SystemVerilog/Verilog to CXXRTL shared libraries (chipflow/sim/build.py)
  • Validates the yosys-slang → CXXRTL pipeline for SystemVerilog simulation

Key Features

  • CxxrtlSimulator class: Python wrapper for CXXRTL compiled simulations

    • get(name) / set(name, value) for signal access
    • step() for simulation advancement
    • signals() / inputs() / outputs() iterators for introspection
  • build_cxxrtl(): Compiles HDL sources to shared library

    • Uses yowasp-yosys with slang frontend for SystemVerilog
    • Generates C API wrapper with correct CXXRTL naming conventions
    • Supports Verilog (.v) and SystemVerilog (.sv)
  • build_cxxrtl_from_amaranth(): Builds from Amaranth Elaboratable

    • Generates RTLIL from Amaranth design
    • Can combine with extra Verilog/SV sources

Test plan

  • All 6 tests pass locally using wb_timer SystemVerilog IP from chipflow-digital-ip
  • CI validation

Technical Notes

  • Uses cxxrtl_get_parts instead of cxxrtl_get (which is an inline function)
  • CXXRTL naming convention: module names get p_ prefix, underscores doubled (wb_timerp_wb__timer)
  • Signal names don't have backslash prefix in CXXRTL (unlike Amaranth simulator)

Add Python bindings and build tools for CXXRTL compiled simulation:

- chipflow.sim.build: Compile HDL (Verilog/SystemVerilog) to CXXRTL
  shared libraries using yowasp-yosys or native yosys with slang
- chipflow.sim.cxxrtl: Python ctypes bindings for CXXRTL C API
  supporting signal get/set, stepping, and enumeration

This enables fast compiled simulation of mixed Amaranth/Verilog/SystemVerilog
designs with Python testbenches, solving the limitation that Amaranth's
built-in Python simulator cannot simulate Instance() black boxes.

Validated with wb_timer SystemVerilog IP - all tests pass including
register read/write, timer counting, compare match, and IRQ generation.

Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
@github-actions
Copy link

github-actions bot commented Jan 14, 2026

Tests Skipped Failures Errors Time
74 10 💤 0 ❌ 0 🔥 24.298s ⏱️

Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
- Change _lib and _handle types to non-optional (always set after init)
- Add type: ignore for amaranth.back.rtlil import (missing from stubs)
- Fix sources list type annotation and extend call

Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
- Add :: for literal code blocks in Example sections
- Update signal name examples to match CXXRTL conventions (no backslash)

Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
@github-actions
Copy link

github-actions bot commented Jan 16, 2026

PR Preview Action v1.8.0
Preview removed because the pull request was closed.
2026-01-16 11:00 UTC

Co-developed-by: Claude Code v2.1.7 (claude-opus-4-5-20251101)
@robtaylor robtaylor closed this Jan 16, 2026
@robtaylor robtaylor deleted the feat/cxxrtl-sim branch January 16, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant