# Why is it said that 'The longer the pipeline, higher the processor clock rate' [duplicate]

I have been recently going through the hyper threading technology of Pentium 4. The number of pipeline stages is high in P4 and is said that it will increase the speed of clock rate. How is that possible?

My reference material

## marked as duplicate by Community♦Jun 30 '15 at 17:58

To answer this question we need to understand a few things about basic digital electronics.

Lets start by taking a look at a typical pipeline.

As we can see that each pipeline stage is followed by a storage register (the green rectangles) which holds the output of each stage. Now each stage of a pipeline consists of a combinational circuit. Combinational circuits are basically combination of various logic gates like NAND, NOR, etc. Each of these logic gates has some latency, i.e.- when you provide some input it takes some time to produce the output (few nanoseconds to picoseconds). So the maximum latency of each stage depends on the longest sequence of this logic gates present in that stage.

Now for a stage to produce a valid output on providing some input we need to provide it with sufficient clock period. So for a stage with large complex combinational circuit the latency is high and hence it will require a long clock period and hence slower clock rate. Similarly for a stage with short and simple combinational circuit the latency is low and hence it will require a shorter clock period and hence higher clock rate.

This is the reason behind, longer the pipeline, higher the processor clock rate. As in a longer pipeline, the stages are divided into more and hence smaller sub-stages, which makes each stage in the pipeline simpler and combinational circuit shorter hence reducing the latency of each stage. This in turn makes room for higher clock rate.

• but if I have the typical 5 stages which last several ps (let's say the highest of them is 300ps) and I divide this stages till the point each one last 1ps, why does the clock rate increase? Because I need more clock cycles to execute the same thing? – Angelixus Oct 28 '18 at 12:49

its little brief to write up about it ,To understand why different CPUs at different clock speeds perform in different ways, let me brief you how the CPU processes instructions.

From tech Website

A CPU processes instructions in an assembly-line manner, with different instructions existing in different stages of completion as they move down the line. For instance, each instruction on the original Pentium passes through the following, five-stage pipeline:

Prefetch/Fetch: Instructions are fetched from the instruction cache and aligned for decoding. Decode1: Instructions are decoded into the Pentium's internal instruction format. Branch prediction also takes place at this stage. Decode2: Same as above. Also, address computations take place at this stage. Execute: The integer hardware executes the instruction. Write-back: The results of the computation are written back to the register file. An instruction enters the pipeline at stage 1, and leaves it at stage 5. Since the instruction stream that flows into the CPU's front-end is an ordered sequence of instructions that are to be executed one after the other, it makes sense to feed them into the pipeline one after the other. When the pipeline is full, there is an instruction at each stage.

Each pipeline stage takes one clock cycle to complete, so the smaller the clock cycle, the more instructions per second the CPU can push through its pipeline. This is why, in general, a faster clockspeed means more instructions per second and therefore higher performance.

Most modern processors, however, divide their pipelines up into many more, smaller stages than the Pentium. The later iterations of the Pentium 4 had some 21 stages in their pipelines. This 21-stage pipeline accomplished the same basic steps (with some important additions for instruction reordering) as the Pentium pipeline above, but it sliced each stage into many small stages. Because each pipeline stage was smaller and took less time, the Pentium 4's clock cycles were much shorter and its clockspeed much higher.

In a nutshell, the Pentium 4 took many more clock cycles to do the same amount of work as the original Pentium, so its clockspeed was much higher for the equivalent amount of work. This is one core reason why there's little point in comparing clockspeeds across different processor architectures and families—the amount of work done per clock cycle is different for each architecture, so the relationship between clockspeed and performance (measured in instructions per second) is different.

An real world example from quantum thread:

Lets take A VERY simple processor. It is just a programmable calculator - instructions available are add a, b, c and subtract a, b, c. (a, b, c are numbers in memory. no way to load these numbers from constants ). One way to do it would be to do the following all in one clock cycle:

1. read the instruction and figure out what we're going to do
4. perform the add or subtract
5. write the result to location c

With this setup, the IPC is exactly 1, because one instruction takes one (VERY long) clock cycle. Now, let's improve this design. We're going to have 5 clock cycles per instruction, and each doing one of the 5 things above. So, on cycle 1, we decide what to do, on cycle 2, we read a, on cycle 3, we read b, and so on. Note that the IPC will be 1/5th. The thing you have to remember is, ideally each of those steps takes 1/5th of the time, so the end result is the SAME performance.