Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

In this section, we transform the single-cycle processor into our RISC-V five-stage pipelined processor. A pipelined processor “separates” the five steps to a RISC-V instruction into stages, where instructions execute in stages, and stages of different instructions execute in parallel during the same clock cycle.

2Pipelined Datapath

Toggle between the visualizations below to visualize the five-stage pipelined datapath. At each rising clock edge, pipeline registers carry data and control signals to the next stage. We discuss control below.

5-Stage Pipelined Datapath
Single-Cycle Datapath
"TODO"

Figure 1:Five-stage RISC-V datapath diagram. Pipeline registers are inserted between stages to hold signals until the next clock cycle.

Just like the single-cycle datapath, in the five-stage pipeline, data and control signals still generally move left to right. There are also still two loops. We extend our original quote from P&H 4.7:

Instructions and data move generally from left to right through the five stages as they complete execution. Returning to our laundry analogy, clothes get cleaner, drier, and more organized as they move through the line, and they never move backward.

There are, however, two exceptions to this left-to-right flow of instructions:

  • The write-back stage, which places the results back into the register file in the middle of the datapath

  • The selection of the next value of the PC, choosing between the incremental PC and the branch address from the MEM stage

Data flowing from right to left do not affect the current instruction; these reverse data movements influence only later instructions in the pipeline. Note that the first right-to-left flow of data can lead to data hazards and the second leads to control hazards.[1]

We define pipeline registers by the two stages they are inserted between, e.g., IF/ID pipeline registers refer to the registers between the IF and ID stages. From P&H 4.7:

Returning to our laundry analogy, we might have a basket between each pair of stages to hold the clothes for the next step.

3Five Stages of the RISC-V Pipelined Processor

We now revisit the five steps to a RISC-V instruction in the context of our new five-stage pipelined datapath in Figure 1. Here are the five steps.

And here are the stages of the five-stage RISC-V pipelined processor, one step per stage.

4Pipeline Registers in the 5-Stage Datapath

Below, we explain Figure 3 from the perspective of what is fed into each set of pipeline registers. For example, when discussing IF/ID registers, we describe the instruction currently executing in the IF stage.

Figure 3:Animation that steps through the enumerated text in this section. Access original Google Slides. A more complete picture is in Figure 6.

5Pipelined Control

Since pipelining the datapath leaves the meaning of the control lines unchanged, we can use the same control values but now group together the control signals by pipeline stage, as in Table 1 and Figure 4.

Table 1:Signals for control logic, grouped by pipeline stage.

NameStage
ImmSelID
BrUnEX
ASelEX
BSelEX
ALUSelEX
MemRWMEM
PCSelMEM
WBSelEX
RegWEnWB

We note there is nothing special to control in the IF stage, because the control signals to read instruction memory and to write the PC are always implicitly asserted. PCSel, the control signal to determine what to write to the PC, is determined in MEM.

"TODO"

Figure 4:Five-stage RISC-V processor diagram with control.

5.1Implementing Pipelined Control

Implementing control means setting these control lines to the correct values in each stage for each instruction. We discuss two approaches below.

One approach computes as many control signals as possible during instruction decode (ID) because all control signals but PCSel can be derived from the instruction. As shown in Figure 5, this extends the pipeline registers to include control information to pipeline control “words” between stages. This approach reuses much of the control circuitry from our single-cycle processor.

"TODO"

Figure 5:Diagram of additional pipelined register for control.

Figure 4 shows a second approach. Each stage now has a separate control unit that determines the control signals based on the instruction currently executing in that stage. This is illustrated in Figure 4 by the inputs to the different control signal groups: inst (ID), inst (EX), inst (M), and inst (WB).

6Summary

The full five-stage pipeline processor is shown in Figure 6; this is also on the course reference card.

"TODO"

Figure 6:Five-stage RISC-V processor diagram: datapath and control.

The 5-stage pipeline we have studied is commonplace in many devices: cars, appliances, etc.

Footnotes
  1. We discuss hazards in a later section of this chapter.