Professional Documents
Culture Documents
369W17 Slideset07
369W17 Slideset07
369W17 Slideset07
February 2017
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 2/86
Contents
The multicycle processor (textbook Section 7.4)
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 3/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 4/86
ENCM 369 will not cover Section 7.4 in detail, because terms
at Canadian universities are short!
That’s too bad, because the multicycle design has some
interesting aspects . . .
I It shows how a computer can use a single memory
array for both instructions and data.
I It makes very efficient use of the ALU—the ALU gets
used to compute three different results for every
instruction.
I The control unit is sequential—it’s a really nice and
practical example of a finite state machine (FSM).
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 5/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 6/86
Introduction to Pipelining
Before we start to learn about pipelining, let’s review a model
we will call the one-instruction-at-a-time model:
I a dryer
(In real life not very many students would ask their roommates
to put away laundry for them, but let’s just follow Patterson
and Hennessy here.)
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 10/86
Load
1st W D F PA
2nd W D F PA
3rd W D F PA
4th W D F PA
6:00pm 8:00pm 10:00pm midnight 2:00am
Time
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 13/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 16/86
ADD IF ID EX MEM WB
LW IF ID EX MEM WB
SW IF ID EX MEM WB
SUB IF ID EX MEM WB
0 ns 1 ns 2 ns 3 ns 4 ns 5 ns 6 ns 7 ns 8 ns
time
The single-cycle processor starts one instruction per clock cycle.
A pipelined processor also starts one instruction per clock cycle.
Why will a pipelined design allow much greater instruction
throughput? (The diagram below provides a hint at the answer!)
CLK
PC output
Instruction
R-File outputs
ALU result
D-Mem RD output
$s1 contents
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 20/86
The sequence is . . .
lw $t0, 20($t1)
or $t2, $t3, $t4
sw $t5, 40($t6)
Let’s use the “Pipeline Basics” handout to track all the steps
in processing these instructions.
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 21/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 22/86
Pipeline Hazards
Structural Hazards
Example:
add $t0, $t1, $t2
sub $t4, $t3, $t0
The destination of ADD is a source for SUB.
The Writeback step of ADD will happen later than the
Decode step of SUB, so there is a risk that SUB will use old,
wrong data from $t0.
Remember, the processor must produce results as if one
instruction completes before the next instruction starts!
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 26/86
Example . . .
1
system clock
0
Example:
add $t0, $t1, $t2
sub $t4, $t3, $t0
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 31/86
Example B:
lw $t0, ($t1)
add $t2, $t2, $t3
slt $t6, $t0, $t5
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 32/86
Example:
lw $t0, ($t1)
add $t3, $t0, $t2
BEQ F D E M W
next instruction F D E M W
1. Stall: Delay the Fetch step for the next instruction until
the address of the next instruction is known.
2. Predict: Guess what the address of the next instruction
will be, and act on the guess without delay. Check that
the guess was correct; if not, cancel instructions that
have incorrectly entered the pipeline.
3. Delayed branch and jump rules
4. Conditional instructions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 36/86
do {
if (*p < 0)
count++;
p++;
} while (p != past_last);
Let’s suppose that there are a lot of array elements, and most
of them are negative . . .
slt operands
beq $t0, $zero, L1
add operands
lw operands
L1: or operands
sub operands
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 42/86
Conditional instructions
Suppose that a, b, and c are ints in $s0, $s1, $s2. Let’s see
how this can be coded with MIPS “move conditional”
instructions movn and movz.
By the way, ARM instruction sets have very rich collections of
conditional instructions.
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 44/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 45/86
Pipeline registers
<<2
+ +
4 SignExt
F D E M W
stage stage stage stage stage
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 50/86
1
system clock
0
0 PCF
1
+
4
PCPlus4F
R-File
What gets into the
20:16 D/E register at the
15:11 end of the Decode
clock cycle?
15:0
SignExt
What is going on
PCPlus4D
with WriteRegW and
WriteRegW
ResultW?
ResultW
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 54/86
ALU
instruction, what useful
0 SrcBE information gets
1
WriteDataE written into the E/M
RtE
register at the end of
0 WriteRegE the Execute clock
1
RdE cycle?
<<2 What useful
SignImmE
+
PCPlus4E information gets
written into the E/M
register in the cases of
LW, SW and BEQ?
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 55/86
ALUOutW
0
happens in the Writeback
ReadDataW
1 stage? Let’s draw part of a
schematic to help explain it.
WriteRegW What would be the same and
what would be different for an
LW instruction in the
W stage?
ResultW
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 57/86
RegWriteW
CLK CLK PCSrcM CLK
MemtoRegW
M/W pipeline register
E/M pipeline register
D/E pipeline register
MemWriteD MemWriteE MemWriteM
BranchD BranchE BranchM
31:26
opcode
ALUControlD ALUControlE
.. .. ..
Instr
. . .
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 61/86
first ADD F D E M W
second ADD F D E M W
SUB F D E M W
ALUSrcE
CLK
GPR
00
01 A
ID/EX pipeline register
10
ALU
GPR
00 0
01 B
10 1
LW/SW
WriteDataE
offset
2 2
ALUOutM
ResultW
ForwardAE ForwardBE
Hazard Unit
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 63/86
WriteRegW
RegWriteW
WriteRegM
RegWriteM
ForwardAE
ForwardBE
5 5 2 2 5 5
RsE
RtE
Hazard Unit
What are RsE and RtE, and how are they used by the Hazard
Unit?
A complete description of the logic in this version of the
Hazard Unit can be found on pages 416 and 418 in the
textbook.
Note: The computer of Figure 7.50 properly handles data
hazards that can be solved using forwarding only. It is not
capable of solving data hazards that require stalls.
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 65/86
PC
EN EN
MemtoRegE
FlushE
StallD
StallF
5 5 5
RsD
RtD
RtE
extension to Hazard Unit
For clarity, the schematic above only shows Hazard Unit inputs and
outputs that are used to effect the stall for LW instructions. See
textbook Figure 7.53 for a complete schematic.
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 68/86
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 70/86
ENCM 369 will NOT cover this material in depth, and there
will be NO lab exercises or midterm or final exam questions on
it!
The Figure 7.53 processor is excellent regarding data hazards,
but handles BEQ instructions poorly—three instructions follow
a BEQ into the pipeline before the branch decision gets made.
Why does that happen? The Figure 7.53 processor makes the
branch decision in the Memory stage. (Check the location of
the AND gate . . . )
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 71/86
LW $17, 0($4)
BEQ $17, $0, some_other_label
ADD $2, $5, $6
Introduction to Pipelining
Pipeline Hazards
Exceptions
ENCM 369 Winter 2017 Slide Set 7 for Lecture Section 01 slide 75/86
Examples of Interrupts