Pipelined CPU Design

XKCD comic

We’ve now seen how to design a simple single cycle CPU. Next, we’re going to start talking about how to improve its performance and look at a more realistic design.

As discussed, there are two fundamental ways for computer architects to improve performance and overcome the fundamental physical constraints of electrical systems: Parallelism and locality. The pipelined processor leverages parallelism, specifically “pipelined” parallelism to improve performance and overlap instruction execution.

In the next section on Instruction-level parallelism, we will see another type of parallelism and how it can further increase performance.

Reading

Computer Organization and Design

Sections 4.5-4.9

Basic pipeline design

What is pipelining?

Reading

Computer Organization and Design

Sections 4.5

This is a video introducing the concept of pipelining through the metaphor of laundry. I’m sure you don’t love doing laundry, but it’s a pretty universal chore. I tried using a different metaphor once… I used one of my hobbies, brewing beer, but since most people didn’t know the beer brewing process, it was a bit less effective. So, you’re stuck with me talking about laundry.

Pipelined design for the DINO CPU

Reading

Computer Organization and Design

Section 4.6

The videos in this section use the DINO CPU design from Spring Quarter 2020 which is slightly different than the design for this quarter. The main difference is this quarter we have a NextPC unit which outputs the address of the next instruction and also whether a branch is “taken”. This is equivalent to the two muxes at the “top” of the execute stage in the previous design.

Discussion

There is one other difference between these two designs: the extra adder in the fetch stage.

This extra adder will be needed in the design for this quarter as well. Think about why we need to have two places where we calculate the next PC value

Discuss in the Discord app!
Or, on the web

The next video explains how to modify the single-cycle DINO CPU to be pipelined and goes through an example of how a few instructions may be executed.

Example execution in pipelined DINO CPU

This video shows an example of how a program will execute in a pipelined CPU.

Pipelined CPU performance

This video discusses the performance of a pipelined CPU.

QUIZ Basic pipelining

Use Canvas to complete the quiz

Pipeline hazards

Now that we understand the basics of pipelining, let’s look at some of the limitations and requirements to implement real system.

Discussion

Before the next section, think about if three are any combinations of instructions that might cause problems for the pipelined implementation.

Can you think of a metaphor with the laundry example above? Or maybe some other example of pipelining in ‘real life’?

Discuss in the Discord app!
Or, on the web

Note: these lectures will be useful when completing Part II of assignment 3.

Limits of our basic pipelined design and data hazards

Reading

Computer Organization and Design

Section 4.7

Through the following videos we will be understanding data hazards and the way the affect the pipeline performance and implementation. These videos are bit more detailed than some of the others. I suggest you give yourself enough time to go through the videos a couple of times to make sure you understand these concepts.

Detailed examples of data hazards and dependencies

First, let’s look at a very detailed example of how an example application uses this pipelined design. This video is very detailed. You may want to watch the next video first which goes over the example at a higher level and then come back to this video.

This video introduces data hazards and goes over a very detailed example.

Next, let’s bring things up a level and look at a different way to represent the same example.

This video introduces data hazards in a slightly different way than the previous video. After this video, you may want to watch the first video again to make sure you understand the details.

“Solving” data hazards with stalling

Now that we see how data hazards can cause a problem, let’s look at a naive way to “solve” this problem by stalling some instructions.

This video discusses how to “fix” the data hazard problem by stalling instructions that cause the hazard.

Note that in a “statically” scheduled design, the compiler can actually detect/predict which instructions are going to cause hazards and insert nop instructions in the right places. These designs are not common since you would have to recompile your program for every different hardware design. This is a good example of why you don’t want you microarchitecture leaking into your architecture.

How to handle data hazards (forwarding)

This video introduces forwarding to handle data hazards.

Load to use hazards

This video talks about a special kind of data hazard: load to use hazards.

Discussion

So, we don’t want to have to make the compiler insert nops and instead we rely on the hardware to detect and handle data hazards. However, do you think that if the compiler knew about the microarchitecture it could emit better code?

Discuss in the Discord app!
Or, on the web

QUIZ Data hazards

Use Canvas to complete the quiz

Control hazards and branch prediction

Reading

Computer Organization and Design

Section 4.8

This video introduces control hazards with an example.

This video introduces the idea of branch prediction.

This video discusses the requirements of a branch predictor and some more advanced branch predictions schemes.

Other kinds of hazards: Structural hazards

This video talks about structural hazards.

Exceptions in a pipelined processor

Reading

Computer Organization and Design

Section 4.9

This video talks about how to handle exceptions/interrupts/errors in a pipelined processor design.

Putting it all together: examples of pipelined execution

This video goes over an end-to-end example of the pipelined DINO CPU. This video should be helpful on Assignment 3.2

QUIZ Pipelining review

Use Canvas to complete the quiz

Discussion

General discussion

Discuss in the Discord app!
Or, on the web