lecture8_predication.ppt
Download
Report
Transcript lecture8_predication.ppt
Chapter 4
Predication
CSE 820
• Go over midterm exam
Michigan State University
Computer Science and Engineering
Review
Predicated instructions have a predicate
which determines if the instruction will
complete execution or become a NOP
Michigan State University
Computer Science and Engineering
Example
if (A==0) A=B; else A= A+4;
LD
R1,0(R3)
BNEZ
R1,L1
LD
R1,0(R2)
J
L2
L1: DADDI R1,R1,#4
L2: SD
R1,0(R3)
;load A
;test A
;then clause
;skip else
;else clause
;store A
Michigan State University
Computer Science and Engineering
Hoist Load
if (A==0) A=B; else A= A+4;
L3:
LD
LD
BEQZ
DADDI
SD
R1,0(R3)
R14,0(R2)
R1,L3
R14,R1,#4
R14,0(R3)
;load A
;speculative load B
;other branch of if
;else clause
;store A
What if speculative load raises an exception?
Michigan State University
Computer Science and Engineering
Guard
if (A==0) A=B; else A= A+4;
LD
R1,0(R3)
sLD
R14,0(R2)
BNEZ
R1,L1
SPECCK 0(R2)
J
L2
L1: DADDI
R14,R1,#4
L2: SD
R14,0(R3)
;load A
;speculative load
;test A
;speculative check
;skip else
;else clause
;store A
sLD does not raise certain exceptions;
leaves them for SPECCK (IA-64).
Michigan State University
Computer Science and Engineering
Other exception techniques
• Poison bit:
– applied to destination register.
– set upon exception
– raise exception upon access to poisoned
register.
Michigan State University
Computer Science and Engineering
Hoist Load above Store
If memory addresses are known,
a load can be hoisted above a store.
If not, …
add a special instruction to check addresses
before the loaded value is used.
(It is similar to SPECCK shown earlier: IA-64)
Michigan State University
Computer Science and Engineering
Speculation: soft vs. hard
• must be able to disambiguate memory
(to hoist loads past stores), but at compile
time information is insufficient
• hardware works best when control flow is
unpredictable and when hardware branch
prediction is superior
• exception handling is easier in hardware
• trace techniques require compensation code
• compilers see further for better scheduling
Michigan State University
Computer Science and Engineering