Skip to content
GG
All projects

Mar – May 2026

RISC-V 5-Stage Pipelined Processor

A 32-bit RV32I core in Verilog on an Artix-7 FPGA, taken from a single-cycle design to a 5-stage pipeline that closes timing 20% faster, at 15 ns instead of 18 ns.

Artix-7 FPGARV32IBlock RAMVerilogVivado
The Artix-7 (XC7A50T) FPGA development board the core runs on

Datapath

Five stages, IF, ID, EX, MEM, and WB, with every mux and control signal of the core.

Pipelined RV32I datapath with PC, instruction memory, register file, immediate generator, branch comparator, ALU, data memory, write-back mux, and control logic

Data forwarding

EX/MEM and MEM/WB results bypass the register file into the ALU, the branch comparator, and the store data. A store that depends on a load gets its data in MEM, so it skips the stall. Compared with stalling on every data hazard, this raised IPC by over 20%.

Forwarding paths: EX/MEM and MEM/WB results routed back to the operand muxes in EX, and MEM/WB routed to the store data in MEM

Hazards

A load-use dependency stalls one cycle. A taken branch resolves in EX and flushes the two instructions behind it.

Pipeline charts: back-to-back ALU instructions with zero stalls, a load-use case with one stall, and a taken branch flushing two instructions

The same cases in simulation, where dbg_stall and dbg_flush pulse on each hazard:

Vivado behavioural simulation of the hazard test program, showing PC, instructions, ALU results, and the stall and flush debug signals

Timing closure

Moving memory to Block RAM put the branch and flush logic on a 16-level path. Pipeline balancing broke up that chain: the core now meets a 15 ns clock with a 14.81 ns critical path (WNS = +0.186 ns).

Critical path from BRAM read through forwarding, branch compare, and flush, and the clock improving from 18 ns to 15 ns

Implementation results in Vivado on the XC7A50T:

Single-cycle5-stage pipeline
Clock constraint met18 ns (55.6 MHz)15 ns (66.7 MHz)
Worst negative slack+0.204 ns+0.186 ns
Slice LUTs2,0311,884
Slice registers1,0231,397
Memory512 LUTs as RAM2 Block RAM tiles

Vivado timing summary for the single-cycle core at an 18 ns clock, all constraints met Vivado timing summary for the pipelined core at a 15 ns clock, all constraints met

Vivado utilization for the single-cycle core, with memory in distributed LUT RAM Vivado utilization for the pipelined core, with memory in two Block RAM tiles

What I learned

  • Block RAM changes every stage. Its one-cycle read meant freezing the fetch output on a stall, flushing both wrong-path slots, and slicing load bytes in WB instead of MEM.
  • Directed tests are not enough. My hazard program passed, but the official riscv-tests found missing immediates for loads, JALR, and AUIPC.

Hazard test program

A directed program in instruction memory checks each case by its final register or memory value.

InstructionCaseExpect
add x5, x1, x2 → sub x6, x5, x4EX/MEM forwardx6 = -1
add x7, x6, x5Both operands forwardedx7 = 2
add x8, x7, x5 after a nopMEM/WB forwardx8 = 5
addi x0, x0, 5 → add x9, x0, x2x0 never forwardedx9 = 2
lw x10 → add x11, x2, x10Load-use stallx11 = 4
lw x12 → sw x12, 4(x0)Store data forwardedmem[4] = 2
beq x13, x14 (not taken)Falls throughx15 = 1
beq x13, x13, +12Taken, 2 flushedx16 = 2
jalr x18, 0(x17)Register jump to 132x19 = 1