ECE 5755: Modern Computer Systems and Architecture
Lecture 6: Pipeline Processors
Douglas
Mcllroy
Seymour
Cray
Douglas Mcllroy invented the concept of pipelining in the Version 3 Unix pages. The concept was later implemented and commercialized in 1970’s supercomputer by Cray Research led by Seymour Cray
Logistics
Photos, illustrations, graphics here.
Today’s agenda
Photos, illustrations, graphics here.
Terminology for pipelined processor
PC
I$
Register
File
s1
s2
d
D$
+
4
PC
PC
A
B
IR
IR
IR
IR
B
O
O
D
Fetch
Decode
Execute
Memory
Write-
back
Photos, illustrations, graphics here.
Pipeline Hazards
Photos, illustrations, graphics here.
Pipeline Hazards
Photos, illustrations, graphics here.
Instruction level parallelism (ILP)
Photos, illustrations, graphics here.
Control Hazards
If (1 == a) {� b = 5;
…
} else {
b = func(x, y);
}
Photos, illustrations, graphics here.
Control Hazards
If (1 == a) {� b = 5;
…
} else {
b = func(x, y);
}
Photos, illustrations, graphics here.
Control hazards in pipelining
PC
Insn
Mem
Register
File
s1
s2
d
+
4
<<
2
F/D
D/X
X/M
PC
A
B
IR
O
B
IR
PC
IR
S
X
When are branches resolved?
Photos, illustrations, graphics here.
Control hazards in pipelining
PC
Insn
Mem
Register
File
s1
s2
d
+
4
<<
2
F/D
D/X
X/M
PC
A
B
IR
O
B
IR
PC
IR
S
X
Photos, illustrations, graphics here.
Branch recovery: Flushing
+ They haven’t written permanent state (regfile, DMEM)
- Two cycle penalty for taken branches
PC
Insn
Mem
Register
File
s1
s2
d
+
4
<<
2
F/D
D/X
X/M
nop
nop
PC
A
B
IR
O
B
IR
PC
IR
S
X
Photos, illustrations, graphics here.
Branch performance
Photos, illustrations, graphics here.
Why predict? Speculative Execution
Photos, illustrations, graphics here.
Why are branches predictable?
for (i=0; i<1000000; i++) { // Highly biased
if (i % 3 == 0) { // and this one?
// whatever
}
if (random() % 2 == 0) { // how about this one?
…
}
}
Photos, illustrations, graphics here.
Branch Prediction Performance
Photos, illustrations, graphics here.
Branch prediction
PC
Insn
Mem
Register
File
S
X
s1
s2
d
+
4
<<
2
TG
PC
IR
TG
PC
A
B
IR
O
B
IR
F/D
D/X
X/M
nop
nop
BP
<>
Hardware guesses outcome
Start fetching from guessed address
Photos, illustrations, graphics here.
Dynamic hardware branch prediction
Photos, illustrations, graphics here.
Branch direction prediction
Photos, illustrations, graphics here.
Branch direction prediction in fetch stage
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | | | | | | | | | | | | |
1-bit Mis-Predict? | Y | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | | | | | | | | | | | |
1-bit Mis-Predict? | Y | | | | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | | | | | | | | | |
1-bit Mis-Predict? | Y | | | Y | | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | | | | | | | | |
1-bit Mis-Predict? | Y | | | Y | Y | | | | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | | | | | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | | | | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | | |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | T | T | T | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | Y | ~50% |
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Two bit saturating counter
Predict Not Taken
Predict Taken
Predict Not Taken
Predict Taken
11
10
01
00
Taken
Taken
Taken
Taken
Not Taken
Not Taken
Not Taken
Not Taken
“strongly
taken”
“strongly
not taken”
Photos, illustrations, graphics here.
Example 2-bit vs. 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | T | T | T | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | Y | ~50% |
2-bit Prediction | n | | | | | | | | | | | | |
2-bit Mis-Predict? | Y | | | | | | | | | | | | |
Photos, illustrations, graphics here.
Example 2-bit vs. 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | T | T | T | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | Y | ~50% |
2-bit Prediction | n | T | T | t | | | | | | | | | |
2-bit Mis-Predict? | Y | | | Y | | | | | | | | | |
Photos, illustrations, graphics here.
Example 2-bit vs. 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | T | T | T | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | Y | ~50% |
2-bit Prediction | n | T | T | t | T | T | T | t | | | | | |
2-bit Mis-Predict? | Y | | | Y | | | | Y | | | | | |
Photos, illustrations, graphics here.
Example 2-bit vs. 1-bit branch prediction
Branch Outcome | T | T | T | N | T | T | T | N | T | T | T | N | % predict rate |
1-bit Prediction | N | T | T | T | N | T | T | T | N | T | T | T | |
1-bit Mis-Predict? | Y | | | Y | Y | | | Y | Y | | | Y | ~50% |
2-bit Prediction | n | T | T | t | T | T | T | t | T | T | T | t | |
2-bit Mis-Predict? | Y | | | Y | | | | Y | | | | Y | ~75% |
Photos, illustrations, graphics here.
Branch prediction buffer (branch history table, BHT)
PC
12-bits
212 = 4K Entries
Taken or
Not-taken?
Photos, illustrations, graphics here.
Correlating predictors
if (aa==2)aa=0;
if (bb==2)bb=0;
if (aa!=bb){..}
// Branch #1
// Branch #2
// Branch #3
Photos, illustrations, graphics here.
Two level global branch prediction
Photos, illustrations, graphics here.
Variations on the basics
PC
12-bits
BHR
XOR
Photos, illustrations, graphics here.
Review: 1-level branch predictor
Photos, illustrations, graphics here.
Review: 2-level Global History Branch Predictor
Photos, illustrations, graphics here.
Review: 2-level Gshare Branch Predictor
Photos, illustrations, graphics here.
Hybrid branch predictors
Local
Predictor
Global
Predictor
Chooser
Predictor
Taken or
Not-taken?
Could be
G-share
Could be
2-bit BHT
Photos, illustrations, graphics here.
Branch Target Prediction
Photos, illustrations, graphics here.
Branch Target Buffer
Photos, illustrations, graphics here.
Branch Target Buffer
Photos, illustrations, graphics here.
Real world: Using ML for Branch Prediction
Photos, illustrations, graphics here.
Laying the context for branch predictor vulnerabilities
?
Photos, illustrations, graphics here.
Laying the context for branch predictor vulnerabilities
$$
100/101/102
Addr: 100
Addr: 100/101/102
Photos, illustrations, graphics here.
Laying the context for branch predictor vulnerabilities
$$
100/101/102
Addr: 100
Addr: 100/101/102
Book: HP
Book:
HP 1-7
Photos, illustrations, graphics here.
Photos, illustrations, graphics here.
Example code for a (simple) Spectre Attack…
Photos, illustrations, graphics here.
Real world: Security vulnerabilities with speculation
“if the pattern of memory accesses performed by such speculative execution depends on private data, the resulting state of the data cache constitutes a side channel through which an attacker may be able to extract information about the private data using a timing attack”
Discovered in 2018 and
affects all processors before 2019
Photos, illustrations, graphics here.
Instruction Level Parallelism (ILP)
Photos, illustrations, graphics here.
Dynamic scheduling
Photos, illustrations, graphics here.
Dynamic Scheduling: The main idea
DIVD F0, F2, F4
ADDD F10, F0, F8
SUBD F12, F8, F14
Photos, illustrations, graphics here.
Problems with out-of-order execution
DIVD F0, F2, F4 DIVD F0, F2, F4
ADDD F10, F0, F8 ADDD F10,F0, F8
SUBD F8, F8, F14 SUBD F10, F8, F14
QUIZ #1: What kind of hazard does the code on the left have?
QUIZ #2: What kind of hazard does the code on the right have?
Photos, illustrations, graphics here.
How do we implement out-of-order execution?
Fetch PC
Decode
Execute
Write Output
Memory
Photos, illustrations, graphics here.
How do we implement out-of-order execution?
Fetch PC
Decode
Execute
Write Output
Memory
Photos, illustrations, graphics here.
Scoreboarding basics
IF
ID
EX
M
WB
IF
IS
EX
M
WB
Rd
Standard Pipeline
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Overview of score-boarding stages
IF
IS
EX
M
WB
Rd
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Scoreboarding stages: Issue (or dispatch)
IF
IS
EX
M
WB
Rd
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Scoreboarding stages: Read operands (or issue)
IF
IS
EX
M
WB
Rd
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Scoreboarding stages: Execution/Write Result
IF
IS
EX
M
WB
Rd
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Overview of score-boarding stages
IF
IS
EX
M
WB
Rd
New Pipeline
I-Buffer/Scoreboard
Photos, illustrations, graphics here.
Scoreboarding control hardware
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Issue 2nd LD?
Photos, illustrations, graphics here.
Scoreboard example
Issue MULT?
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Read multiply operands?
Photos, illustrations, graphics here.
Scoreboard example (first half of cycle)
Photos, illustrations, graphics here.
Scoreboard example (first half of cycle)
Photos, illustrations, graphics here.
Scoreboard example
Issue ADDD?
Note
Remaining
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Read operands for DIVD?
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
WAR Hazard!
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
WAR Hazard is now gone...
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Faster than light compute!!��… Skipping a bunch of cycles
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
Photos, illustrations, graphics here.
Scoreboard example
In-order issue; out-of-order execute & commit
Photos, illustrations, graphics here.
Scoreboarding review
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
LD F6, 34(R2) | Iss | Rd | Ex | Wb | | | | | | | | | |
LD F2, 45(R3) | | | | | Iss | Rd | Ex | Wb | | | | | |
MULTD F0, F2, F4 | | | | | | Iss | Iss | Iss | Rd | M1 | M2 | M3 | M4 |
SUBD F8, F6, F2 | | | | | | | Iss | Iss | Rd | A1 | A2 | Wb | |
DIVD F10, F0, F6 | | | | | | | | Iss | Iss | Iss | Iss | Iss | Iss |
ADDD F6, F8, F2 | | | | | | | | | | | | | Iss |
Photos, illustrations, graphics here.
Scoreboarding review
| 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 …. 62 | |
LD F6, 34(R2) | | | | | | | | | | | | | |
LD F2, 45(R3) | | | | | | | | | | | | | |
MULTD F0, F2, F4 | M2 | M3 | M4 | M5 | M6 | M7 | M8 | M9 | M10 | Wb | | | |
SUBD F8, F6, F2 | A2 | Wb | | | | | | | | | | | |
DIVD F10, F0, F6 | Iss | Iss | Iss | Iss | Iss | Iss | Iss | Iss | Iss | Iss | Rd | D1 | Wb |
ADDD F6, F8, F2 | | | Iss | Rd | A1 | A2 | A2 | A2 | A2 | A2 | A2 | Wb | |
Photos, illustrations, graphics here.
Scoreboarding limitations
Photos, illustrations, graphics here.
5 minute break!
Photos, illustrations, graphics here.
Another approach: Tomasulo’s algorithm
Photos, illustrations, graphics here.
What are Reservation Stations?
Photos, illustrations, graphics here.
Register renaming
Photos, illustrations, graphics here.
Register Renaming with Tomasulo
Photos, illustrations, graphics here.
The three main stages of Tomasulo Algorithm
1. Issue—get instruction from FP Op Queue
If reservation station free (no structural hazard), �control issues instr & sends operands (renames registers).
2. Execution—operate on operands (EX)
When both operands ready then execute;� if not ready, watch Common Data Bus for result
3. Write result—finish execution (WB)
Write on Common Data Bus to all awaiting units; �mark reservation station available
Photos, illustrations, graphics here.
Tomasulo Organization
Photos, illustrations, graphics here.
Reservation Station Components
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Note: Unlike scoreboarding hardware, this processor can have multiple loads
Photos, illustrations, graphics here.
Tomasulo Example
Note: registers names are removed (“renamed”) in Reservation Stations; MULT issued vs. scoreboard
Load1 completing; what is waiting for Load1?
Photos, illustrations, graphics here.
Tomasulo Example
Load2 completing; what is waiting for Load2?
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Issue ADDD here vs. scoreboard?
Photos, illustrations, graphics here.
Tomasulo Example
Add1 completing; what is waiting for it?
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Add2 completing; what is waiting for it?
Photos, illustrations, graphics here.
Tomasulo Example
Write result of ADDD here vs. scoreboard?
All quick instructions complete in this cycle!
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Photos, illustrations, graphics here.
Tomasulo Example
Once again: In-order issue, out-of-order execution and completion.
Photos, illustrations, graphics here.
Comparing Tomasulo and Scoreboard
Structural Hazards
Lack of forwarding
Photos, illustrations, graphics here.
Tomasulo summary
Photos, illustrations, graphics here.
Tomasulo vs. scoreboarding
Photos, illustrations, graphics here.