A synthesizable 5-stage pipelined RISC-V RV32I core, packaged as a reusable IP block with external memory ports, a memory-mapped peripheral bus, and a self-checking golden-model regression.
38/38 tests passing · zero assertion violations · lockstep-verified against a behavioural reference model.
TOTAL:38 PASS:38 EXPECTED_FAIL:0 UNEXPECTED_FAIL:0 RV32I_CHK:0
Implements the RISC-V RV32I base integer ISA. Despite the repository name, this is not a MIPS design.
| Core | 5-stage pipeline (IF/ID/EX/MEM/WB), single clock domain, no CDC |
| ISA | Full RV32I integer set — all R/I-type ALU ops, six branches, jal, jalr, lui, auipc, lw, sw |
| Hazards | Full forwarding (MEM→EX, WB→EX), write-first register file, 1-cycle load-use interlock |
| Control flow | EX-resolved branches with pipeline flush; 2-cycle taken penalty, 0 for not-taken |
| SoC | Address decoder + memory-mapped peripheral register block |
| Memories | External to the IP; combinational same-cycle read contract |
| Verification | Golden-model lockstep, 38 directed + randomised tests, two assertion tiers |
IF ID EX MEM WB
+--------+ +--------+ +--------+ +--------+ +--------+
| PC | | decode | | fwd mux| | dmem | | result |
| +4 |---->| regfile|---->| ALU |---->| access |---->| mux |
| imem | | immgen | | branch | | | | 3:1 |
+--------+ +--------+ +--------+ +--------+ +--------+
^ ^ ^ ^ | | | |
| | | | | +------------+--------------+--> forward
| | | | | MEM->EX
| | | | | WB ->EX
| | | | v
| | | | pc_src_e (taken branch / jal / jalr)
| +-----------+--+-----------+
| flush_d flush_e
|
stall_f / stall_d <-- load-use interlock
Hazard resolution
| Hazard | Mechanism | Cost |
|---|---|---|
| RAW, distance 1 | MEM→EX forward | 0 cycles |
| RAW, distance 2 | WB→EX forward | 0 cycles |
| RAW, distance 3 | Write-first register file (transparent read) | 0 cycles |
| Load-use | stall_f + stall_d + flush_e bubble |
1 cycle |
Taken branch / jal / jalr |
flush_d + flush_e squash both shadow instructions |
2 cycles |
| Not-taken branch | none | 0 cycles |
Ideal steady-state CPI is 1.0. Branches resolve in EX; there is no branch prediction.
| Module | Role |
|---|---|
rv32i_core |
Pipeline top — the synthesizable IP deliverable |
rv32i_stage_if/id/ex/mem/wb |
Pipeline stages, each owning its output pipeline register |
rv32i_control_unit |
Main decoder + ALU decoder |
rv32i_main_decoder |
Opcode → control signals, illegal-encoding detection |
rv32i_alu_decoder |
ALUOp/funct3/funct7 → 4-bit ALU control |
rv32i_alu |
10-operation ALU with status flags |
rv32i_branch_unit |
Six funct3-decoded branch conditions |
rv32i_imm_gen |
I / S / B / J / U immediate generation |
rv32i_regfile |
32×32, write-first bypass, hardwired x0 |
rv32i_hazard_unit |
Forwarding selects, stall and flush generation |
rv32i_pc, rv32i_adder, rv32i_mux |
PC register, adders, 2:1 / 3:1 muxes |
+-------------------------------------------------+
| rv32i_soc |
| |
imem <-+--+------------------+ |
rdata->| | rv32i_core | |
| +---------+--------+ |
| | dmem_* (one flat data port) |
| +---------v--------+ |
| | rv32i_bus_decode | addr[28]: 0=RAM 1=periph |
| +----+--------+----+ |
| | | |
ram <-+-------+ +----v-----------+ |
rdata->| | rv32i_ddc_regs | |
| +----------------+ |
+-------------------------------------------------+
Both memories are external to the IP, so the same SoC drives simulation models or inferred BRAM without modification. Both must honour the core's same-cycle combinational read contract — there is no ready/valid handshake and no stall-on-miss, so the decode and read-mux logic sits directly in the MEM-stage critical path.
Address decoding uses a single bit (dmem_addr[28]) rather than a wide compare, to keep that path
shallow. Write strobes are gated per target; read data is muxed combinationally.
| Offset | Name | Access | Description |
|---|---|---|---|
0x00 |
NCO_FREQ |
rw | NCO phase increment |
0x04 |
NCO_PHASE |
rw | NCO phase offset |
0x08 |
AGC_GAIN |
rw | Datapath gain, Q1.15 (reset 0x8000 = 1.0) |
0x0C |
PWR_ACC |
ro | Accumulated signal power |
0x10 |
STATUS |
ro | bit0 sample_ready, bit1 overflow, bit2 saturate |
0x14 |
CTRL |
rw | bit0 enable, bit1 clear_acc (self-clearing) |
0x18 |
ID |
ro | 0x0DDC_0001 |
| Group | Instructions |
|---|---|
| R-type ALU | add sub sll slt sltu xor srl sra or and |
| I-type ALU | addi slti sltiu xori ori andi slli srli srai |
| Memory | lw sw |
| Branch | beq bne blt bge bltu bgeu |
| Jump | jal jalr |
| Upper immediate | lui auipc |
Not supported — detected and flagged on dbg_illegal_instr, never silently mis-executed:
lb/lh/lbu/lhu/sb/sh, fence, ecall/ebreak, CSR instructions, traps and exceptions,
misaligned accesses, M/A/F/D/C extensions, branch prediction.
Every test runs the same program through the DUT and through an independent behavioural RV32I
reference model, then compares the architectural commit streams — register writes and stores,
in order, including total count. Observation is taken at the documented IP boundary
(dbg_commit_*, dmem_*), not from core internals.
- 38 tests, 0 expected failures. Directed coverage of every instruction group, all three forwarding paths, hazard gaps 1–4, stall/flush interaction, illegal-instruction inertness, memory boundaries, peripheral access, and two seeded pseudo-random stress streams.
- Two assertion tiers. Tier 1 (
RV32I_CHECK_ON) is plain procedural checks that run in every regression. Tier 2 (RV32I_ASSERT_ON) is concurrent SVA, guarded down to the`includeitself so an SVA-incapable simulator never opens the file. - Assertions are mutation-tested. Inverting two checks produces 2689 violations across the suite, confirming they are not passing vacuously.
- Programs are generated, not hand-maintained.
tb/gen/gen_programs.pyowns instruction encoding, a two-pass label assembler, per-test cycle-budget derivation via an architectural interpreter, and emission of the hex images, the manifest, and the SystemVerilog test registry — so they cannot drift apart.
rtl/ synthesizable RTL + simulation-only memory models
rv32i_core.v the IP top
rv32i_soc.v CPU + bus decode + peripherals
rv32i_bus_decode.v address decoder / read mux
rv32i_ddc_regs.v memory-mapped register block
rv32i_core.f filelist (sim-only files marked for exclusion)
tb/ class-based verification environment
gen/gen_programs.py single source of truth for test programs
scripts/ regression driver
docs/ IP datasheet, toolchain notes
Requires Icarus Verilog, PowerShell 7, and Python 3.
python tb/gen/gen_programs.py # regenerate programs + manifest
pwsh tb/scripts/run_regression.ps1 # compile once, run all testsAdd -StrictChecks to fail the run on any Tier-1 assertion violation (default is report-only, so a
faulty check can never mask a real regression result).
A Digital Down-Converter subsystem is in progress — NCO, complex mixer, CIC decimator, and compensation FIR — with the CPU running an automatic gain control loop in software against the register map above.
Synthesis and place-and-route are not yet part of this repository.
Developed by Christos Ntoumas. Detailed port lists, memory protocol timing, and the full
assertion table are in docs/rv32i_core_datasheet.md.