Cycle-accurate RV32I Single-Cycle (SS) and 5-Stage Pipelined (FS: IF -> ID -> EX -> MEM -> WB) RISC-V microarchitecture simulator in Python.
- RV32I Instruction Decoder & Assembler Helpers (
isa_rv32i.py):- Encodes and decodes 32-bit R, I, S, B, and J-format instructions (
ADD,SUB,XOR,OR,AND,SLL,SRL,SRA,SLT,SLTU,ADDI,XORI,ORI,ANDI,LW,SW,BEQ,BNE,BLT,BGE,JAL,HALT) with exact sign-extension and two's-complement 32-bit arithmetic.
- Encodes and decodes 32-bit R, I, S, B, and J-format instructions (
- Single-Cycle Core (
cores.py::SingleCycleCore):- Reference architectural execution engine retiring one instruction per clock edge (
x0hardwired to0).
- Reference architectural execution engine retiring one instruction per clock edge (
- 5-Stage Pipelined Core (
cores.py::FiveStagePipelinedCore):- Data Forwarding Unit: Bypasses
EX/MEMandMEM/WBALU results directly intoEXoperand multiplexers. - Load-Use Hazard Unit: Detects
LWinEXwhose destinationrdmatchesrs1orrs2inID, stallsPCandIF/IDfor one cycle, and injects aNOPbubble intoID/EX. - Control Hazard Handling: Flushes the speculative
IF/IDslot on taken branches/jumps and records cycle-by-cycleCPI,IPC, forwarding counts, and stall statistics.
- Data Forwarding Unit: Bypasses