How ssaadakhtar/rv32i-five-stage-pipeline works
Project type and purpose
• This is a hardware‐design and verification project built in Scala/Chisel, targeting a RISC-V CPU in both single‐cycle and 5-stage pipeline styles.
• It uses SBT to compile Chisel (Scala) sources into FIRRTL, then Verilog, then Verilator/C++ for cycle‐accurate simulation. Python test harnesses (RISCoF, sail_cSim) drive memory models and compare results.
File structure
• src/main/scala/SingleCycle – Chisel implementation of single-cycle CPU
• 5stagepipeline – YAML configurations and Python harness for 5-stage pipeline implementation
• sail_cSim – Python harness + SAIL-C based ISS simulator
• core.v, core.fir, core.cpp – generated FIRRTL/Verilog/C++ simulation artifacts
• obj_dir/Vcore* – Verilator‐generated C++ model and build artifacts
• test_run_dir, waveform.vcd – simulation outputs and waveforms
• build.sbt, build.sc, project/ – SBT build and configuration files
README insights
• Contains RISC-V assembly test cases loaded at specific addresses in data memory
Main components
a. Chisel/Scala Frontend
• Scala source files under src/main/scala (SingleCycle, Pipeline generator)
• SBT/Scala build tool (build.sbt)
b. FIRRTL Compiler
• Transforms Chisel AST → FIRRTL (core.fir)
c. Verilog Backend
• FIRRTL → Verilog (core.v, sram_top.v, etc.)
d. Verilator/C++ Simulation
• Verilator generates C++ model (obj_dir/Vcore*.cpp/.h)
• Build produces simulation executable (Vcore)
e. Memory & Test Harness
• Python RISCoF scripts (riscof_5stagepipeline.py, riscof_sail_cSim.py)
• Linker scripts (link.ld) and test headers (model_test.h)
• Assembly test binaries loaded into simulated memory (imem.txt, .anno.json)
f. SAIL-C ISS
• sail_cSim harness for comparison to the Verilator model
g. Outputs & Verification
• Waveform (.vcd) viewer, test logs, PASS/FAIL comparison
Relationships & interactions
• SBT invokes Chisel → FIRRTL → Verilog
• Verilog + Verilator → C++ model → compiled simulator
• Python harness drives simulator: loads test code into memory, steps clock, reads register outputs
• sail_cSim harness runs the same test in the SAIL-C ISS
• Results from Verilator model vs ISS compared and discrepancies logged
• VCD waveforms generated during simulation for manual inspection
Architectural patterns and design principles
• Modular pipeline stages (Fetch, Decode, Execute, MEM, Write-Back) implemented as independent Chisel modules
• Memory‐mapped imem / dmem abstractions
• Build pipeline follows source-to-artifact pattern (Chisel → FIRRTL → Verilog → C++)
• Test‐driven verification via external Python harness
• Clear component labels (e.g., “Fetch.scala,” “Execute.scala,” “Pipeline YAML Config”)
• Two distinct flows: Build Flow (Chisel → FIRRTL → Verilog → C++ model) vs Test Flow (Python harness → Simulator & ISS → Comparison)
• Arrowheads indicating data and control flow direction