How to do an interface between the PC counter and synchronous instruction cache in a 5-stage pipeline

2026-06-12

Stack Overflow: View Question

Tags: caching, vhdl, cpu-architecture, fpga

Score: -2 | Views: 107

The asker is building a classic 5-stage RISC pipeline (IF/ID/EX/MEM/WB) in VHDL, and it works when the instruction memory behaves as a combinational ROM — present an address, get the instruction back in the same cycle. The trouble starts when they swap in a real block RAM-backed instruction cache. On every FPGA fabric (Xilinx, Intel, Lattice, Gowin), BRAM is fundamentally synchronous: the address is latched on a clock edge, and the data appears on the output port one cycle later. That extra cycle of latency breaks the textbook fetch stage, where the PC and the instruction were assumed to update in lockstep.

What makes this interesting is that the fix isn't just "add a register" — it forces you to re-think where the IF/ID boundary actually lives and how stalls, branches, and resets propagate.

Why it's hard

A direction toward a solution

Treat the BRAM's internal output register as the IF/ID pipeline register itself, rather than adding another flip-flop after it. Then:

Gotchas

The challenge: Synchronous BRAM forces the fetch stage to span two clock edges, which means stalls, flushes, and resets have to be redesigned around the BRAM's own address and output registers rather than bolted on afterward.

All newsletters