6-stage RISC-V out-of-order-commit CPU with cache
A pipelined RISC-V processor with instruction and data caches, designed in Verilog and taken through synthesis and place-and-route in the SkyWater 130nm process. It was the first fully functional 6-stage out-of-order-commit CPU in the course, and it won the Apple New Silicon Initiative design contest.
- Clock
- 96.3 MHz after place-and-route
- Area
- 1.25 mm²
- Figure of merit
- 45.07
- Branch prediction
- 99.80% accurate
- Recognition
- Apple New Silicon Initiative winner, presented at Apple Park
The challenge
The course design challenge asked each team to build the fastest correct RISC-V CPU they could, with credit for creativity. Designs were scored on a figure of merit that combines the cycle count on a benchmark suite, the clock frequency reached after place-and-route, and the chip area, so every optimization had to pay for itself in both speed and silicon.
A six-stage pipeline
I split the classic five-stage pipeline further so each stage does less work and the clock can run faster. Fetch is split into a request and a response stage around the instruction cache, and memory access is split the same way around the data cache.
Fetch request sends the next PC to the instruction cache and redirects on a branch misprediction. Fetch response receives the instruction and precomputes jump and branch targets, buffering on stalls. Decode reads the register file. Execute runs the ALU, computes memory addresses, and detects hazards and mispredictions. Memory request sends the data-cache request, which can be skipped when a value is forwarded from execute, and memory response commits the result.
Getting more done per cycle
The core commits out of order: ALU instructions are allowed to finish ahead of slower memory instructions, so a cache access no longer holds up independent arithmetic behind it. Forwarding resolves data hazards without stalls in the common case, and the register file is double-pumped, writing and then reading in the same stage.
Jumps and branches are resolved early by precomputing their targets in the fetch-response stage. A branch predictor reached 99.80% accuracy on the benchmarks, which keeps the deeper pipeline from paying for mispredictions.
Caches
Both caches hit in a single cycle. I designed the cache controller as a state machine that handles hits, evictions, and refills from memory.
As groundwork for a superscalar version, I built an instruction cache that prefetches four instructions per request. It worked, but it did not improve the figure of merit enough to justify its area, so I left it out of the final scored design.
Saving area
Because area counts against the score, the control logic only keeps the bits it actually needs, for example a 16-bit PC, a 26-bit instruction in execute, and a 14-bit instruction in memory.
Physical design and verification
The design passed every RTL simulation test with and without caches, every post-synthesis test, and the extra tests I wrote myself. After place-and-route the floorplan had fewer than 20 DRC violations.