Download Hardware/Software Interface: ISA, VLIW, EPIC, and Predication - Prof. Sudhakar Yalamanchil and more Papers Computer Architecture and Organization in PDF only on Docsity!
ECE 4100/
Advanced Computer Architecture
Lecture 14 Static Scheduling Machines
Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology With adaptations and additions by S. Yalamanchili for ECE 4100/6100 – Spring 2009
Required Reading
• Appendix G.4, G.5, G.
• Paper on IA 64 Architecture (check the
webpage)
3
Compiler - Hardware Interface
IF ID MEM WB
Lexical Analyzer (^) Parser SemanticAnalyzer Code GeneratorIntermediate
Optimizer Code Generator (^) OptimizerPostpass
tokens parse tree parse tree IR
low level IR machine code
.. .. L.D F2, 0(R1) ADD.D F4, F0, F MUL.D F6, F4, F S.D F6, 4(R2) … …
IR
Hardware/Software Interface: The ISA
A new approach ISA design and utilization!
Static Scheduling
- Compiler performs instruction scheduling
- VLIW Very Long Instruction Word
- An alternative to dynamic scheduling processors
- Pack multiple operations into one instruction
- Move scheduling to Compiler (Software Approach)
- Can simplify the complexity of a hardware-based instruction scheduler
- Cydrome, Multiflow, EPIC
7
Characteristics of EPIC
• Move the results of dependency analysis directly
into the ISA
• Emphasis on creating as much parallelism as
possible for scheduling at compile time
• Introduction of several compiler and architectural
innovations
- Explicit instruction independences exposed in the ISA
- Predication
- Control flow optimizations
- Parallel compare and multi-way branches
- Control and data speculation
- Register management
- Register stack engine and rotating registers
Predication
• How can we reduce the impact of branches?
– Consider the work for predicting one branch let
alone multiple branches
– Must be performed at compile time
• Provide a way for the compiler to reason
about control flow.
• Make the execution of instructions
conditional to reflect their execution
semantics
9
Computing Predicates
• Normal comparison operations set predicate
registers based on the result of the comparison
cmp.eqcmp.eq (^) p1, p2p1, p2 = r1, r2= r1, r
p1=1 and p2=0 if r1=r12, and p1=0 and p2=1 otherwise
• Compare instructions can themselves be predicated
like other instructions
- Normal compare instructions function as expected, affecting predicate registers if predicated on
- Unconditional comparisons function differently when predicated off - If the qualifying predicate is 1 then operate as normal - If the qualifying predicate is off, then write 0 to both predicate registers
Predicated Execution
- Convert control flow into dataflow
- not all branches can be eliminated in this way
- Example: cmp.gt p1, p2 = ra, rb
- Compare instructions can be predicated
- Use otherwise idle functional cycles
- Example
p p2 p
p
cmp op p1 p cmp else
branch
then
Single bitpredicate registers
13
Control Speculation (Hoist Uses)
- The uses of speculative data can be executed speculatively
- Distinguishes speculation from simple prefetch
- NaT bit propagates down to the dependent instruction chain
- Importance of load operations Æ start of a chain of operations
ld.sld.s instrinstr 1 1 instrinstr 2 2 brbr
chk.schk.s useuse
IA-IA-64 64
Control Speculation (Recovery)
- All computation instructions propagate NaTsNaTs to the consumers to reduce number of checks
- Cmp propagates “false” if NaT is set when writing predicates (“ 0 ” for both target predicates) - Cuts off execution of dependent instructions
chk.schk.s r5r5,, recvrecv sub r7 =sub r7 = r5r5,r2,r
ld8.s r3 = (r9)ld8.s r3 = (r9) ld8.sld8.s r4 = (r10)r4 = (r10) addaddr6 = r3, r4r6 = r3, r ld8.sld8.s r5r5 = (r6)= (r6) p1,p2 = cmp(...)p1,p2 = cmp(...)
Allows single chkAllows singlechk onon resultresult
ld8ld ld8ld addadd ld8ld br homebrhome
Recovery codeRecovery code
15
Miscellaneous Issues
• Instructions whose destination is not a
register cannot propagate NaT values
– For example store instructions
– Instructions that set branch target registers
• Decouple load and handling of exceptions
– Compiler responsible for scheduling the handling
of the exception
• Ensure speculative load can execute safely
Data Speculation (Advanced Loads)
- Compiler can hoist a load prior to a preceding, possibly-conflicting store
- ALAT (Advanced Load Address Table) is used for checking every store address in-between
- Can be done by superscalar machine using Store coloringStore coloring
instrinstr 1 1 instrinstr 2 2
.. .... st8st
ld8ld useuse
BarrierBarrier
Conventional ArchitecturesConventional Architectures
ld8.ald8.a instrinstr 1^1 instrinstr 2 2 st8st
ld.cld.c useuse
ItaniumItanium
19
Combining Control and Data Speculation
- Use of the LD.SA instruction: moving across branches and stores
- If an exception occurs do not write the ALAT
- Check instruction will be invoked
LD …
SD …
ADD … MULTD .. SUBD ..
BNE .. …
instructions^ Dependent
Aliased StorePossibly
LD.SA … ADD … MULTD .. SUBD .. … … SD … Check.a … Insert check foradvanced load
Optimization
BNE ..
Parallel Compare Types
- Three new types of compares:
- and: both target predicates set FALSE if compare is false
- or: both target predicates set TRUE if compare is true
- DeMorgan: if true, sets one TRUE, sets other FALSE
- Do not get confused with the “parallel compare” pcmp1/pcmp2/pcmp
Reduces Critical PathReduces Critical Path Reduces Critical Path
B B
AA
CC
DD
AA BB CC
DD
21
Eight Queen Example
Source: Crawford & Huck Source: Crawford & Huck
if ((b[j] == true) && (a[i+j] == true) && (c[i-j+7] == true))
R1=&b[j] R1=&b[j] R3=&a[i+j]R3=&a[i+j] R5=&c[i-R5=&c[i-j+7]j+7] ld R2=[R1]ld R2=[R1] ld.s R4=[R3]ld.sR4=[R3] ld.s R6=[R5]ld.sR6=[R5] P1,P2=cmp.unc(R2==true)P1,P2=cmp.unc(R2==true)
(p1) chk.s(p1)chk.s R4R (p1) P3,P4=cmp.unc(R4==true)(p1)P3,P4=cmp.unc(R4==true)
(p3) chk.s(p3)chk.s R6R (p3) P5,P6=cmp.unc(R5==true)(p3)P5,P6=cmp.unc(R5==true) (P5) br(P5)br thenthen elseelse
1 2 4 5 6 7
Then
Else
P
P
P
P3 P
P
8 queens control flow 8 queens control flow
Unconditional ComparesUnconditional Compares
Eight Queen Example
Source: Crawford & HuckSource: Crawford & Huck
if ((b[j] == true) && (a[i+j] == true) && (c[i-j+7] == true))
Then
Else
P
P
P
P3 P
P
Parallel Compares Parallel Compares R1=&b[j]R1=&b[j] R3=&a[i+j]R3=&a[i+j] R5=&c[i-R5=&c[i-j+7]j+7] p1 <-p1 <- truetrue ld R2=[R1]ld R2=[R1] ld R4=[R3]ld R4=[R3] ld R6=[R5]ld R6=[R5] p1,p2 <-p1,p2 <- cmp.and(R2==true)cmp.and(R2==true) p1,p2 <-p1,p2 <- cmp.and(R4==true)cmp.and(R4==true) p1,p2 <-p1,p2 <- cmp.and(R6==true)cmp.and(R6==true) (p1) br(p1)br thenthen elseelse
1
2
4 5
Reduced from 7 cycles to 5Reduced from 7 cycles to 5 Reduced from 7 cycles to 5
Then
Else
P1= true P1=False
25
Multiway Branches
3 branch cycles3 branch cycles 3 branch cycles^ 1 branch cycle1 branch cycle1 branch cycle
w/o Speculationw/o Speculation Hoisting LoadsHoisting Loads ld8 r6 = (ra) ld8 r6 = (ra) (p1) br(p1)br exit1exit
ld8 r7 = (rb)ld8 r7 = (rb) (p3)(p3) brbr exit2exit
ld8 r8 = (rc)ld8 r8 = (rc) (p5)(p5) brbr exit3exit
(p1)(p1) brbr exit1exit
chk r7, rec1chkr7, rec (p3) br(p3)br exit2exit
chkchk r8, rec2r8, rec (p5)(p5) brbr exit3exit
ld8ld8 r6 = (ra)r6 = (ra) ld8.s r7 = (rb)ld8.s r7 = (rb) ld8.s r8 = (rc)ld8.s r8 = (rc)
ld8 r6 = (ra)ld8 r6 = (ra) ld8.s r7 = (rb)ld8.s r7 = (rb) ld8.s r8 = (rc)ld8.s r8 = (rc)
(p2)(p2) chkchk r7, rec1r7, rec (p4)(p4) chkchk r8, rec2r8, rec (p1)(p1) brbr exit1exit (p3)(p3) brbr exit2exit (p5)(p5) brbr exit3exit
P1P
P6P
P5P
P2P
P4P
P3P
- • Multiway branches: more than 1 branch in a single cycleMultiwaybranches: more than 1 branch in a single cycle
- – Itanium allows multipleItanium allows multiple ““consecutiveconsecutive”” B instructions in the same inst groupB instructions in the same inst group
- – Allows n-Allows n-way branching (Itanium and Itanium 2 have 3 branch units)way branching (Itanium and Itanium 2 have 3 branch units) per cycleper cycle
- – Ordering matters if branch predicates are not mutually exclusiveOrdering matters if branch predicates are not mutually exclusive
- • E.g. BBB template enables 3 branches in one bundleE.g.BBB template enables 3 branches in one bundle
MultiMulti--way Branchesway Branches
Branch and Prefetch Hints
- Compiler provides hints for branch predictor by
- Completer in branch instructions, e.g. br.call.sptksptk
- 4 completer types for static and dynamic predictions: sptksptk,, spntspnt,, dptkdptk,, dpntdpnt
- Explicit brpbrp instructions
- Compiler provide hints for instructioninstruction sequentialsequential prefetchingprefetching
- Use completer in branch instructions, e.g. br.call.sptk.manymany
- 2 completer types: many, fewmany, few
- •^ Many and fewMany few are implementation-specific
- Compiler directs predictor allocation
- For managing branch predictor resources
- Use completer in branch instructions, e.g. br.call.sptk.many.nonenone
- 2 completer types: none,none, clrclr
- •^ none: donnone ’t deallocate; clrclr: deallocate branch info
27
The Register Files
Integer Registers FP Registers Branch Registers Predicate Registers
0
31
127
0
31
127 0
7
PR
PR
PR
NaT (^) 32 stacked and 96 rotating
32 stacked and 96 rotating
32 stacked and 96 rotating
16 stacked and 48 rotating
Itanium Register Files
Stacked (Rotating)
Static 0
General Purpose Registers
Stacked (Rotating)
Static 0
FP Registers
63 0 81 0
Stacked (Rotating)
Static 0
0
Predicate Registers
31
RSE: A Function Call
loc
out
sol sof CFM 14 21
PFS.pfm x x
out
sol sof 0 7
14 21
call
pfm: Previous frame marker
RSE: Alloc
loc
out
sol sof CFM 14 21
PFS.pfm x x
out
sol sof 0 7
14 21
call alloc r32=ar.pfs,7,9,3,
sol sof 16 19
14 21
loc
out
inputs
alloc copies PFM to GR (r32)
33
RSE: Return
loc
out
sol sof CFM 14 21
PFS.pfm x x
out
sol sof 0 7
14 21
call alloc
sol sof 16 19
14 21
loc
out
loc
out
sol sof 14 21
14 21
return
Register Rotation and Modulo Scheduling
• Hardware register naming mechanism
– Register window rotates modulo the number of
registers
• Base register points to the base of the
register window
– Physical register is the sum of the base register
and referenced register
– If ( i <32), physical register is GR[ i ]
– If ( i => 32), physical register is GR[ i + RRB]
37
Example: Simple Schedule
For (i=0; i<n; i++){ b++ = a++; / copy string/ }
// setup ra, rb, rc, LC, check n> .label loop { ld8 rt = [ra], } { st8 [rb] = rt, br.cloop #loop }
br.cloop
ld st
st br.cloop
ld
st br.cloop
ld
Schedule
Software Pipeline the Loop
st5 br.ctop
ldl5 st4 br.ctop
ld4 st3 br.ctop
ld3 st2 br.ctop
ld2 st1 br.ctop
ld1 (^) prologue
epilogue
kernel
• Assuming multiple load/store functional units
39
Initial State After Prologue
// setup ra, rb, rc, LC, check n> } ld 8 r33 = [ra], .label loop { ld8 r32 = [ra], st8 [rb] = r33, br.ctop #loop } { st8 [rb] = 33,
1 2 3 4 .. .. 1
RRB = 0
ra
rb
r
r
r r r
r
After First iteration
// setup ra, rb, rc, LC, check n> } ld 8 r33 = [ra], .label loop { ld8 r32 = [ra], st8 [rb] = r33, br.ctop #loop } { st8 [rb] = 33,
1 2 3 4 .. ..
1
1 2
RRB = -
ra
rb
r
r
r r r
r