Download Lecture 6: Pipelining & Exception Handling in MIPS - Prof. Alan L. Sussman and more Assignments Computer Science in PDF only on Docsity!
CMSC 411Computer Systems Architecturey Lecture 6Basic Pipelining (cont )Basic Pipelining (cont.)Alan [email protected] s@cs u^ d edu
Administrivia^ •^ Answers to HW #1 posted^ –^ password protected, with instructions sent via emailpassword protected, with instructions sent via email^ •^ Homework problems for Unit 3 posted, dueThursday, Feb. 26
CMSC 411 - 6 (from Patterson)^
Review: Exceptions •^ Ideally, pipeline can be interrupted so thatinstructions before the fault complete. Then wantt^ t^ t^
ti^ j^ t^ ft^ th^
f^ lti
to restart execution just after the faultinginstruction -^ precise exception handling
CMSC 411 - 6 (from Patterson)^
3
When do MIPS exceptions occur?^ •^ IF^ –^ page fault on instruction fetch^ –^ misaligned memory access^ –^ memory protection violation^ •^ ID^ –^ undefined or illegal opcode^ •^ EX^ –^ arithmetic exception^ •^ MEM^ –^ page fault on data fetch/store^ –^ misaligned memory accesst^ ti
i^ l ti– memory protection violation • WB: None!CMSC 411 - 6 (from Patterson)^
Examples of exception handlingLD^ IF^ ID^
EX^ MEM^ WB
ADD^ IF^
ID^ EX^ MEM
WB
• Handle the MEM fault first, then restart LD^ IF^ ID^
EX^ MEM^ WB
LD^ IF^ ID^
EX^ MEM^ WB
ADD^ IF^
ID^ EX^ MEM
WB
• IF fault occurs first, even though LD will fault later
CMSC 411 - 6 (from Patterson)^
5
• But for precise exceptions, must handle LD fault first
How is this done? • Answer: Don't handle exceptions until the WBstagestage^ –^ each instruction has an associated status vector that keepstrack of faultsany bit set in the status vector turns off register writes and–^ any bit set in the status vector turns off register writes andmemory writes^ –^ in WB stage, the status vector is checked and any fault ishandled^ –^ So, since instructions reach WB in proper order, faults forearlier instructions are handled
before^ faults for later instructions^ »^ Unfortunately will need to violate this later (for»^ Unfortunately, will need to violate this later (forinstructions that don’t reach WB in proper order)CMSC 411 - 6 (from Patterson)
Commitment •^ When an instruction is guaranteed to complete, it is
g^ p^
committed • Life is easier if no instruction changes the permanentmachine state before it is committed • In MIPS, commitment occurs at the end of the MEM stage -that’s why register update occurs in the stage after that • Some machines muddy the state before commitment, andthe exception handler must do its best to restore the statethe exception handler must do its best to restore the statethat existed before the instruction started
CMSC 411 - 6 (from Patterson)^
7
Complications with long instructions •^ So far, all MIPS instructions take 5 cycles
y
•^ But haven't talked yet about the floating pointi^ t^ tiinstructions •^ Take it on faith that floating point instructions are•^ Take it on faith that floating point instructions areinherently slower than integer arithmeticinstructionsdoubters may consult Appendix H in H&P online–^ doubters may consult Appendix H in H&P online
CMSC 411 - 6 (from Patterson)^
Examples (cont.) - Fig. A.32MUL.D^ IF^ ID^ M1^ M
M3^ M4^ M^
M6^ M7^ MEM^ WB ADD.D^ IF^ ID^
A1^ A2^ A3^ A^
MEM^ WB L.D^ IF^
ID^ EX^ MEM^ WB S.D^
IF^ ID^ EX^ MEM
WB
Italics^ shows where data is needed, blue where a result is available
CMSC 411 - 6 (from Patterson)^
13
Hazards caused by long instructions
y^ g
•^ The floating point adder and multiplier arepipelined, but the divider is not - that is why thei^ iti ti^ i^ t^
l f^ di id^ i^25 initiation interval for divide is 25 – A program will run^ very^ slowly if it does too many of these!
•^ It will also run slowly if the results of the divide
y
are needed too soon
CMSC 411 - 6 (from Patterson)^
FP stalls from RAW hazards – Fig. A.33Inst.^1
3 4 5
6 7 8
9
L.D F4,0(R2)^ IF^ ID^
EX^ MEM^ WB MUL.D F0,F4,F6^ IF^
ID^ stall^ M^
M2^ M3^ M^
M
ADD.D F2,F0,F^
IF^ stall^ ID^
stall^ stall^ stall^
stall
ADD.D F2,F0,F^
IF^ stall^ ID^
stall^ stall^ stall^
stall
S.D F2,0(R2)^
stall^ IF^ stall^
stall^ stall^ stall Inst.^10
12 13 14
15 16 17 L.DMUL.D^ M6^ M^
MEM^ WB ADD.D^ stall^ stall^
A1^ A2^ A^
A4^ MEM^ WB S D^ t ll^ t ll^
ID^ EX^ t ll^
t ll^ t ll^ MEM CMSC 411 - 6 (from Patterson)
15
S.D^ stall^ stall^
ID^ EX^ stall^
stall^ stall^ MEM
Long instructions (cont.) •^ It is possible that two instructions enter the WB stage at thesame timesame timeADD.D^ IF^ ID^ A
A2^ A3^ A
MEM^ WB
LD^ IF^
ID^ ALU^ MEM^
WB
DADD^
IF^ ID^ ALU^
MEM^ WB
DADD^
IF^ ID^ ALU
MEM^ WB
DADD^
IF^ ID^ ALU
MEM^ WB
-^ A structural hazard
CMSC 411 - 6 (from Patterson)^ A^ structural hazard
Long instructions (cont.) •^ Instructions can finish in the wrong order •^ This can cause WAW hazards •^ This violation of WB ordering
1)^ stop fetching2)^ turn off writes defeats the 3)^ l^ i^
li^ d^ i
This^ violation of WB ordering defeats theprevious strategy for precise exception handling^ –^ problem is^ out-of-order completion
3)^ let pipeline drain4)^ handle problem^ is^ out^ of^ order
completion DIV.D^ F0, F2, F^
What happens if sub faults? ADD^ R1, R1, R2SUB.D^ F10, F12, F
And then div?What about R1? CMSC 411 - 6 (from Patterson)
17
WAW structural hazard^1 2
4 5 6 7
8 9 10 11 MUL.D F0,F4,F6^ IF^ ID^ M
M2^ M3^ M4^ M
M6^ M7^ MEM
WB IF^ ID^ EX^ MEM^ WB… IF^ ID^ EX^ MEM^ WB … IF^ ID^ EX^ MEM
WB ADD.D F2,F4,F^
IF^ ID^ A1^ A^
A3^ A4^ MEM^
WB
…^
IF^ ID^ EX^ MEM
WB …^
IF^ ID^ EX^ MEM
WB CMSC 411 - 6 (from Patterson)^
18
L.D F2,0(R2)^
IF^ ID^ EX^ MEM
WB
Possible fixes •^ Give up and just do
imprecise exception handlingGive up and just do imprecise^ exception handling– tempting, but very annoying to users
-^ Delay WB^ until all previous instructions completey^ p
p
-^ since so many instructions can be active, this is expensive - requires alot of supporting hardwareW it^ t^ hi t
fil^ f^ i t^
d
-^ Write, to memory, a
history file^ of register and memorychanges so can undo instructions if necessary – or keep a future file of computed results that are waiting for MEM or WBCMSC 411 - 6 (from Patterson)^
19
Possible fixes (cont.) •^ Let the^ exception handler
finish the instructions in
the pipeline and then restart the pipe at the nexti^ t^ tiinstruction • Have the floating point units
diagnose exceptionsg p g^ p
in their first or second stages
, so can handle them
by methods that work well for handling integerexceptionsexceptions
CMSC 411 - 6 (from Patterson)^
20