You now have two working cores that run the same programs: a single-cycle core and a 3-stage pipeline. The pipeline needs more cycles for every program, because of the flushes, and it costs more hardware, because of the pipeline registers and the forwarding path. Is it faster? This article answers with measurements: the cycle counts of both cores on the seven programs, the clock period of both from a synthesized and placed design, the execution time and speed-up that follow, and the area each one costs. It also shows where the pipelined core's clock is limited and why pipelining into three stages gives far less than three times the speed.
9 min read | Intermediate
What You'll Learn
- Compare the cycle counts of the single-cycle and 3-stage cores and explain the difference
- Read the clock period of each core from its slowest path, and find the 3-stage core's critical path
- Compute execution time and speed-up with the performance equation
- Explain why three stages give much less than three times the clock speed, and what the pipeline costs in area
Before You Start
This article reads and interprets results; if you want to reproduce the synthesis yourself, you need a working Verilog core and the Verilog Tutorial basics. The Performance Equation explains why time is instructions times CPI times clock period, and Clocks, Cycles and Time explains what limits a clock period. Pass E12 and E16 to have both cores of your own.
How the Numbers Were Measured
Both reference cores, the single-cycle one of E12 and the pipeline of E16, were run on the seven programs on Icarus Verilog and Verilator, which give identical counts. For timing, both were synthesized and placed with the open-source OpenROAD flow on the SkyWater 130 nm library sky130_fd_sc_hd at the typical corner: synthesis, placement, buffering of high-fanout signals and resizing of gates on slow paths, all with the same timing target for both cores, and an ideal clock (no clock tree). The memories are outside the cores, so their read time cannot be measured; it is an assumption: 2 ns for each memory read, added to every path that goes through a memory. Results from a different library, memory or tool would be different; the comparison between the two cores is what matters.
Cycles
The pipeline needs more cycles, exactly instructions + redirects + 2, as A Control Hazard: Flushing After a Taken Branch showed. Relative to the single-cycle core:
| Program | Single-cycle cycles | 3-stage cycles | Ratio |
|---|---|---|---|
| hello | 205 | 234 | 1.1415 |
| sum | 8,205 | 10,255 | 1.2498 |
| memcpy | 21,522 | 24,595 | 1.1428 |
| bubble | 13,408 | 16,520 | 1.2321 |
| matmul | 90,514 | 111,083 | 1.2272 |
| list | 152,674 | 190,228 | 1.246 |
| crc | 71,695 | 80,913 | 1.1286 |
Every program runs 13 to 25 percent more cycles on the pipeline, and all of it is taken branches and jumps: forwarding means the data hazard costs nothing. The programs with the most taken branches per instruction, the array sum and the linked-list walk, lose most.
Clock Period
The clock period of a core is set by its slowest path from one register to the next (through the memory, where a path crosses it). In the single-cycle core that is the load: from the PC through the instruction memory, decode, register read and ALU to the data memory, and back through the load/store unit to the register file, crossing memory twice. It needs 14.373 ns; an ALU instruction's path needs 10.038 ns.
In the 3-stage core, each stage has its own longest path:
| Stage path | Delay |
|---|---|
| F: PC to instruction memory to the F/X register | 3.998 ns |
| X: F/X register through decode, ALU and branch logic to X/W and the PC | 5.839 ns |
| W to X: X/W register through data memory and the load/store unit, forwarded into X's ALU, to X/W | 8.96 ns |
The pipelined core's clock period is the largest, 8.96 ns, and it is not any single stage. It is the forwarding path of a load: the loaded value leaves the X/W register, crosses the data memory and the load/store unit, goes through the forwarding multiplexer into the ALU of the next instruction, and must be in the X/W register by the end of the same cycle. Forwarding made the data hazard free in cycles, but in time it joined W and X into one long path. That is exactly why real pipelines with synchronous memories stall after a load instead: A Data Hazard and Its Forwarding Path explains the trade-off.
Quick Check
Q: If the W-to-X forwarding path were removed by stalling one cycle after every load that is used immediately, which path would set the clock, and what would it be?
Show Answer
The next longest path, stage X at 5.839 ns, assuming W's own path through the data memory to the register file is shorter, which the table does not show. The clock period could then drop by about a third, paid for with one stall cycle per load-use pair, 2,016 of them in the bubble sort.
Time and Speed-Up
Time is cycles times clock period. For the matrix multiply: 90,514 x 14.373 ns, about 1,300.96 µs on the single-cycle core, and 111,083 x 8.96 ns, about 995.3 µs on the pipeline, so the pipeline is 1.307 times faster. For every program:
The pipeline wins on every program, by between 1.283 and 1.421 times. The speed-up is the ratio of the clock periods, 14.373 / 8.96, about 1.604, divided by the cycle ratio from the first table: programs with fewer taken branches, such as the CRC, keep more of the clock gain. That is the performance equation at work: a design change that improves one factor and worsens another is judged by the product.
Why Not Three Times Faster
Three stages could in principle divide the single-cycle path by three. The measured gain in clock period is about 1.6 times. Three reasons:
- The forwarding path spans the data memory and the ALU in one cycle, so the slowest "stage" is really a stage and a half.
- The stages are unbalanced. F is much shorter than X; a third of the work is not a third of the delay, and the clock is set by the slowest.
- Pipeline registers cost time. Every stage adds a flip-flop's clock-to-output delay and setup time to its path, a fixed overhead that does not shrink when the logic does. Pipeline Depth vs Frequency shows how this limits deep pipelines.
What It Costs
In the placed designs, the single-cycle core occupies 78,741 µm² and the 3-stage core 84,296 µm², about 7.05 percent more. The difference is the two pipeline registers, the forwarding multiplexers and their select logic, and the flush gating. A synthesis of both with Yosys on the sky130_fd_sc_ms library counts 1,024 flip-flops in the single-cycle core and 1,199 in the pipeline: the 175 extra flip-flops are the F/X and X/W registers. For a 1.283 to 1.421 times speed-up, 7 percent more area is a good trade, which is why almost every processor is pipelined.
Where Does This Matter?
This is the everyday work of computer architects: a design change is proposed, it is measured on a set of programs, and it is judged by performance, power and area together, the PPA trade-off described in PPA Trade-offs and Amdahl's Law. Your comparison, two cores, seven programs, a placed design and a stated assumption, is the same method on a small scale.
Quick Check
Q: With a faster memory, read time 1 ns instead of 2 ns, the single-cycle load path loses 2 ns (two memory reads) and the pipeline's forwarding path 1 ns. Assuming the other paths stay below them, what are the new periods and the new clock ratio?
Show Answer
14.373 - 2 = 12.373 ns and 8.96 - 1 = 7.96 ns, a ratio of about 1.554. A faster memory helps the single-cycle core more, because its critical path crosses memory twice, so the pipeline's advantage shrinks slightly. The answer depends on the memory assumption, which is why results like these always state it.
Common Mistakes
Mistake #1: Comparing cycle counts alone
The pipeline needs more cycles for every program and is faster on all of them. Cycles, instructions and clock period only mean something together.
Mistake #2: Expecting a stage count to divide the clock period
Unbalanced stages, register overhead and paths that span stages, such as forwarding, keep the gain well below the number of stages.
Mistake #3: Quoting timing without its assumptions
A clock period depends on the library, the corner, the flow and here the memory read time. A number without them cannot be compared with anything.
Your Turn in the Lab
Exercise E17 synthesizes your pipelined core, the one that passed E16, on the sky130 high-density library and checks two things in the netlist: that it contains no latches, and that it has at least 150 ordinary flip-flops, which only a core with real pipeline registers has. The flip-flop count leaves out the register file, which maps to flip-flops with an enable input: the reference single-cycle core counts 32 (its PC) and the reference 3-stage core 206.
Then compare your own two cores in your project:
- Run the Synthesis panel on your single-cycle core (E12) and on your pipelined core (E16), with the same sky130 library, and compare the cell counts and areas in the two reports.
- With a Pro account, run static timing analysis on both and look at the critical path of the pipeline. An unplaced netlist without buffering gives longer, less realistic delays than the placed numbers above, but the slowest path should end in the same place.
Summary
- The 3-stage core needs 13 to 25 percent more cycles than the single-cycle core, all of it from taken branches and jumps.
- Its clock period is 8.96 ns against 14.373 ns, in placed sky130hd designs with a 2 ns memory read assumed; its critical path is the load result forwarded from W into X.
- Time is cycles times period: the pipeline runs every program 1.283 to 1.421 times faster.
- Three stages give a clock about 1.6 times faster, not three, because of the forwarding path, unbalanced stages and register overhead.
- The pipeline costs about 7 percent more area: 175 more flip-flops for the pipeline registers, plus the forwarding and flush logic.