Jason NikasLive FPGA Lab

Microprocessor Design

Making a small RISC-V processor run at a faster clock on an FPGA, by taking one shortcut out of its pipeline.

10Course grade

CV32E40P timing

Faster RISC-V core clock

SystemVerilogRISC-VVivado/VitisTclCPythonJason NikasDimitrios TsiantosPanagiotis Nikolaos Tsogkas

What it is

CV32E40P is a small open-source RISC-V processor for embedded chips. We put it on an FPGA, a ZedBoard, and asked how much faster its clock could run if we took one shortcut out of its pipeline.

That shortcut is forwarding: a result goes straight to the next instruction that needs it, before it is written back. It saves waiting cycles, but its wires and selectors take room on the chip, and on an FPGA long, crowded wiring is what limits the clock. We built four versions of the core, the original and three with forwarding removed, and put each through the same tests, the same Vivado build and the same benchmarks.

Where the clock was lost

The slowest path in the original core ran through the operand selection in front of the register file, and most of its 14.87 ns was wiring delay, not logic. That region carries the results the ALU, the multiplier and the control registers forward to the next instruction.

We took the 1,000 slowest paths from Vivado’s reports. In the original core they spread all the way out to 14.9 ns, the shape of a crowded routing region. Without forwarding the slow tail was gone.

The CV32E40P core's block diagram, with its critical path through the multiplier marked in red

Cutting out the multiplier

The version without multiplier forwarding keeps the ALU’s shortcut but stores a multiplication’s result for one cycle and hands it over from the writeback stage instead. An instruction that needs that result straight away now waits one cycle: the controller adds a stall, so every program still gets the same answers.

It met a 14 ns clock instead of 15 ns, with its critical path down from 14.87 ns to 13.44 ns. The cost was small: 4,171 to 4,314 lookup tables (3.4% more), the same multipliers and memory, and an estimated 120 to 121 mW.

Checking it still works

Every version ran the same assembly tests in simulation, and a Python model of the processor worked out what memory and registers should hold at the end. Then bare-metal C benchmarks measured each version’s cycle count, multiplied by its own clock period.

When it pays off

A faster clock helps only while the extra stalls stay rare. Programs that never use a multiplication’s result straight away ran 8.7% faster: Dhrystone, sorting, SHA-256 hashing, IPv4 packet checks and a control state machine. A multiplication test where 7.7% of instructions waited came out 2.0% faster. Matrix multiplication, at 10.4%, was 0.4% slower.

The break-even point is about 9.6% of instructions waiting on the multiplier, so for most embedded code the trade pays.

Results

Estimated top clock speed of each version after place and route on the ZedBoard's Zynq-7020, from Vivado's timing reports. The version without multiplier forwarding met a 14 ns clock; the others were built for 15 ns.

Original core66.8 MHz
No ALU forwarding67.2 MHz
Neither forwarded69.6 MHz
No multiplier forwarding73.2 MHz

Code

The controller's new stall: an instruction that needs a multiplication's result waits one cycle for it. Lines 1366–1375 on GitHub
// Stall one cycle for consumers of a MUL result. MUL results are registered
// into the EX/WB stage and are only available for forwarding from WB.
if ((mult_en_ex_i == 1'b1) && (regfile_alu_we_ex_i == 1'b1) &&
    ((reg_d_alu_is_reg_a_i == 1'b1) ||
     (reg_d_alu_is_reg_b_i == 1'b1) ||
     (reg_d_alu_is_reg_c_i == 1'b1)))
begin
  deassert_we_o   = 1'b1;
  load_stall_o    = 1'b1;
end

Report, presentation and repository

Tools

What this course's projects were built with. Pick one to see where else I used it.

Tap the picture to see it at full size