3-stage RISC-V superscalar CPU with branch predictor
A 3-stage pipelined RISC-V CPU written in Verilog for the Xilinx PYNQ-Z1 FPGA, extended into a dual-issue superscalar core. It reached a CPI of 0.975, making it the first and only fully functional superscalar CPU in the lab’s history, and it won the Apple New Silicon Initiative design contest.
- Clock
- 100 MHz
- Superscalar CPI
- 0.975
- Base CPI
- 1.245
- Branch prediction
- Up to 99.8% accurate
- Recognition
- Apple New Silicon Initiative winner, presented at Apple Park
The base pipeline
I started with a three-stage pipeline that runs real RISC-V programs over UART and can synthesize audio. A few design choices kept it fast without many stalls.
Jumps need no stall, because the immediate is computed directly and passed to the first stage’s PC input; only a load followed by JALR costs one cycle. The register file is double-pumped so simultaneous writes and reads work, and nearly all forwarding goes through the write-back value. The control logic takes in all three stages and computes only the signals each one needs.
To close timing at 100 MHz, I moved UART handling from the second stage to the third and computed the ALU operand and operation selects one stage early. The finished core ran the challenge benchmark at a CPI of 1.245, about 0.16 seconds per run.
A configurable branch predictor
The first creative feature was a fully functional N-way set-associative cache for the branch predictor, parameterized by address width, data width, number of lines, and number of ways, with LRU replacement. Testing different sizes showed that four ways gave the best trade-off.
| Benchmark | Without predictor | With predictor | Extra correct predictions |
|---|---|---|---|
| Matrix multiply | 50.3% | 79.9% | 52,615 |
| Bubble sort | 50.2% | 99.8% | 124,746 |
To keep the predictor small, I merged the LRU bits into the cache itself and synthesized with Vivado’s area-focused optimization.
| Resource | Before | After |
|---|---|---|
| Slice LUTs | 6,273 | 4,470 |
| Flip-flops and latches | 6,964 | 4,323 |
| LUT6 | 4,784 | 3,007 |
| MUXF7 | 1,663 | 782 |
Going superscalar
The second creative feature was a superscalar core that issues two instructions per cycle. A prefetcher reads three instructions per cycle so a dispatch unit can check dependencies before sending instructions down two parallel paths.
R-, I-, U-, and S-type instructions all issue two at a time when there are no hazards. Jumps resolve in the first stage using precomputed immediates, and branches resolve there too through the four-way predictor. The register file, immediate generator, partial load and store logic, and ALU are all duplicated for two instructions, and I wrote my own testbench to check it.