RHDL has one frontend (the Ruby DSL) and multiple backends for simulation, synthesis, and export. This page provides an overview of each backend and when to use it.

Frontend: Ruby DSL

All hardware descriptions enter through the Ruby DSL. The DSL modules (Behavior, Sequential, Structure, Memory, StateMachine, Vec, Bundle) produce an in-memory RTL model that feeds all backends.

Simulation Backends

RHDL provides four simulation backends at two abstraction levels:

BackendLevelLanguageRelative SpeedUse Case
Ruby behavioralRTLRuby1x (baseline)Rapid prototyping, debugging
Ruby gate-levelGateRuby~2xVerification against netlist
SIMD gate-levelGateRuby~5–10xBatch testing (64 vectors)
Rust nativeRTL/GateRust~50–100xPerformance-critical simulation
WASMRTLRust→WASM~10–20xBrowser-based demos

Ruby Behavioral

The default backend. Components propagate signals through Ruby method calls:

component = MyDesign.new('test')
component.set_input(:a, 42)
component.propagate
result = component.get_output(:y)

Best for: development, debugging, interactive exploration with IRB.

Ruby Gate-Level

Evaluates the gate-level netlist using a CPU interpreter:

sim = RHDL::Codegen.gate_level([component], backend: :interpreter)
sim.poke('a', 42)
sim.evaluate
result = sim.peek('y')

Best for: verifying behavioral model matches gate-level implementation.

SIMD Gate-Level

Evaluates 64 test vectors simultaneously using bit-parallel operations:

sim = RHDL::Codegen.gate_level([component], backend: :gpu, lanes: 64)
sim.poke('a', 0xFFFFFFFFFFFFFFFF)  # All 1s across 64 lanes
sim.evaluate
result = sim.peek('y')

Each net is a 64-bit integer where bit i = value in lane i. Gate operations (AND, OR, XOR, NOT) operate on full 64-bit words in a single instruction.

Best for: exhaustive testing of small components, batch verification.

Rust Native

Compiled simulation for maximum performance:

sim = RHDL::Codegen.gate_level([component], backend: :native_interpreter)
# or JIT-compiled
sim = RHDL::Codegen.gate_level([component], backend: :jit)

Best for: long-running simulations, CPU emulation, performance benchmarks.

WASM (Browser)

The Rust backend can target WebAssembly for browser-based simulation. See Browser Simulation for details.

Export Backends

BackendOutputCommand
Verilog.v filesrhdl export --all
Gate JSON.json netlistsrhdl gates --export
FIRRTLFIRRTL textMyComponent.to_firrtl
DiagramsSVG/PNG/DOTrhdl diagram --all

Verilog Export

Generates synthesizable Verilog from the RTL model. Supports full component hierarchies.

rhdl export --all --scope lib

See Verilog Export for details.

Gate-Level JSON

Exports the gate-level netlist as machine-readable JSON for external tools:

rhdl gates --export
rhdl gates --stats

See Gate Synthesis for details.

Circuit Diagrams

Generates visual diagrams at three levels of detail:

ModeDescription
componentBlock diagram with inputs/outputs
hierarchicalInternal sub-components and connections
gatePrimitive gate-level netlist
rhdl diagram --all --mode component   # Simple block diagrams
rhdl diagram --all --mode gate        # Gate-level schematics
rhdl diagram RHDL::HDL::ALU --level hierarchy --depth all

Backend Selection Guide

ScenarioRecommended Backend
Writing and debugging a new componentRuby behavioral
Running RSpec test suiteRuby behavioral
Verifying gate-level correctnessRuby gate-level interpreter
Exhaustive testing (all input combinations)SIMD gate-level (64 lanes)
Long simulation (>1M cycles)Rust native
Interactive web demoWASM
FPGA/ASIC implementationVerilog export
Estimating chip areaGate-level stats
DocumentationDiagram export

Next Steps