instructor: Mark Jeffrey
lec: T 3PM-5PM MC254, W 9AM-10AM BA1170
lec2: M11AM-1PM BA1180, W10AM-11AM BA1160
tut: W 4PM-5PM GB120
pra: F 9AM-12PM BA3155
Zoom: https://utoronto.zoom.us/j/82657136791 (Passcode: 552552)
breakdown
the role of a computer architect:
important differences:
design goals:
About security:
technology push
performance growth:
technology trends:
the microprocessor revolution:
how are growing transistor counts utilized?
application pull
application specific designs
layers of abstraction
+------+ +-------+ +--------+
| app | | app | |compiler|
+------+ +-------+ +--------+
+---------------------------+
| OS, device drivers | us
+---------------------------+ <-----+
+------+ +-------+ +--------+ <-----+
| IO | |memory | |processr|
+------+ +-------+ +--------+
+---------------------------+
|circuits, devices, material|
+---------------------------+
instruction set architecture (ch 3.2)
microarhichitecture
empirical evaluation
performance
eg. d=10 miles, car has cap= 5, speed = 60 mi/hr. then latency = 10 mi / 60 mi/hr = 10 min. throughput = 15 people/hr (3 round trips / hr).
bus has cap=60, speed=20 mi/hr. then latency=30 mins, throughput=60 people/hr.
performance improvement
eg. for latency, car is 3 times (200%) faster than bus; for throughput, bus is 4 times (300%) faster than car.
what is 'P':
adding/averaging perf numbers
iron law of performance
cycles per instruction
eg. a program executes equal int, FP, and mem operations. int is 1 cycle, FP is 3 cycles, mem is 2 cycles. then CPI = (1 + 3 + 2) / 3 = 2.
caveat: this sort of calculation ignores dependency.
measuring CPI
improving CPI
eg. given processor with instr frequencies and costs
CPI is 50% * 1 + 20% * 5 + 10% * 1 + 20% * 2 = 0.5 + 1 + 0.1 + 0.4 = 2.
which change would improve perf more?
speedup = old time / new time = =2/1.6=1.25 (25%).
eg. given processor
suppose we reduce store 1 cycle, but slow down clock by 20%.
this is example of Amdahl's law - do not want to speed up small fraction at cost of the rest.
^
|
n |
|
|
|
|
1 +---------+--------+
| f | 1-f |
+---------+--------+---------->
time
^
|
n |----+
| |
| |
| |
| f |
1 + +--------+
| | 1-f |
+----+----+---+----+---------->
time
the sequential model
processor logically executes loop
fetch PC <---+
decode |
read inputs |
execute |
write output |
next PC ---+
alternatives have been proposed: e.g. dataflow [dennis, 1974/75].
single cycle datapath
breaking instruction into steps
multi-cycle
single vs. multi-cycle
eg. single cycle has clock speed = 50ns, CPI=1. then performance is 50ns/instr.
multiple-cycle has 20% branch (3 cycles), 20% load (5 cycles), 60% ALU (4 cycles). let us say clock period = 11ns. CPI = 0.2*3 + 0.2*5 + 0.6*4 = 4. perf = 44 ns / instr.
(why not 50/5=10ns? not every stage is executed, and not every stage has same required clock period.)
can we have both low CPI and short clock period? not if datapath executes only one instruction at a time.
latency vs throughput:
use pipelining
MULTI-CYCLE:
instr0: [fetch] [decode] [exec]
instr1: [fetch] [decode] [exec]
PIPELINED:
instr0: [fetch] [decode] [exec]
instr1: [fetch] [decode] [exec]
instr2: [fetch] [decode] [exec]
5-stage pipelined datapath
there is one single-cycle controller, but pipeline the control signals:
terminology and foreshadowing:
eg. given three instrs
1 2 3 4 5 6 7 8 9
ADD r1,r2->r3 F D X M W
LW #0(r5)->r4 F D X M W (load)
SW r6->#4(r7) F D X M W (store)
ADD is noop at M stage, and SW is noop at W stage to help instrs are executed in order.
pipelining
eg. given 20% branch, 20% load, 60% ALU. suppose clock period is 12ns (50/5 stages + overhead). CPI = 1 (each instr takes 5 cycles, but 1 instr completes every cycle). perf = 12 ns / instr.
actually CPI = 1 + some penalty for pipelining. say CPI = 1.5, then perf = 18ns/instr.
why is pipeline clock period longer?
why is pipeline CPI > 1?
make common case fast (MCCF)
managing a pipeline
dependence and hazards
read-after-write (RAW)
ADD r2,r3->r1
SUB r1,r4->r2
eg. internal forwarding
1 2 3 4 5 6 7 8
ADD r1, r2 -> r3 F D X M |W
LW #0(r3) -> r4 F D X M W
ADDI r3, #1 -> r6 F D X M W
SW r3 -> #0(r7) F |D X M W
RAW: detect and stall
(F/D.rs1 && (F/D.rs1 == D/x.rd || F/D.rs1 == X/M.rd))|| (F/D.rs2 && (F/D.rs2 == D/x.rd || F/D.rs2 == X/M.rd))eg. D and W share regfile
1 2 3 4 5 6 7 8 9 10
ADD r1,r2 -> r3 F D X M W
LW #0(r3) -> r4 F d# d* D X M W
ADDI r3,1 -> r6 p# p* F D X M W
SW r3, #0(r7) F D X M W
reducing RAW stalls with bypassing
suppose LW #4(r3) -> r1 is in X stage, ADD r1, r2 -> r3 is in M stage, then LW can get r3 from the output of ADD.
logic:
(X/M.rd == D/X.rs1) -> 1(M/W.rd == D/X.rs1) -> 1else -> 2eg. full bypassing using MX bypass
1 2 3 4 5 6 7 8 9 10
ADD r2,r3->r1 F D X |M W
SUB r1,r4->r2 F D |X M W
eg. full bypassing using WX bypass
1 2 3 4 5 6 7 8 9 10
ADD r2,r3->r1 F D X M |W
LW #0(r7)->r5 F D X M W
SUB r1,r4->r2 F D |X M W
eg. WM bypass
1 2 3 4 5 6 7 8 9 10
LW #0(r2)->r1 F D X M |W
SW r1->#0(r4) F D X |M W
stalling-on-load:
1 2 3 4 5 6 7 8 9 10
LW #0(r2)->r1 F D X M |W
SUB r1,r4->r2 F d* D |X M W
stall = (D/X.op == LW) && ((F/D.rs1 == D/X.rd) || (F/D.rs2 == D/X.rd && F/D.op != SW))performance impact of load/use penalty
write-after-write (WAW)
ADD r2,r3->r1* -+
SUB r1,r4->r2 |
OR r3,r6->r1* <+
write-after-read (WAR)
ADD r3,r2*->r1
SUB r4,r5->r2*
OR r1,r3->r6
remarks:
some instructions take more execution cycles
+--+ +--+
|X | |M |
+--+ +--+
+---+ +---+ +--+ +--+ +--+ +--+ +--+ +--+ +---+
| F +--> D +----> |M1| |M2| |M3| |M4| |M5| |M6+---->+ W |
+---+ +---+ +--+ +--+ +--+ +--+ +--+ +--+ +---+
+--+ +--+ +--+
|A1| |A2| |A3|
+--+ +--+ +--+
+---------------------------+
|||||||||||||||||||||||||||||
+---------------------------+
div
eg.
1 2 3 4 5 6 7 8 9 10
DIV.S f0,f1->f2 F D X X X X X |W
S.S f2->#0(r1) F d* d* d* D X |M W (!!)
ADD.S f0,f1->f2 F D X X W
...
ADD.S f2,f3->f4 F D X
wanted f2 overwritten ^
structural hazards: resource needed twice in 1 cycle
1 2 3 4 5 6 7 8 9
LW #0(r1)->r2 F D X M W
ADD r4,r3->r1 F D X M W
SUB r5,r3->r1 F D X M W
AND r3,r4->r6 s* F D X M W
to fix: proper ISA/pipeline design
steps needed for branch: br (Rj op Rk) displ
option 1: always stall
1 2 3 4 5 6 7 8 9
ADDI r1,#1->r3 F D X M W
BNEZ r3,targ F D X |M W
SW r6,#4(r7) c* c*|F D X M W
option 2: assume not-taken. branch 20%, other 80%, 75% of branches are taken.
1 2 3 4 5 6 7 8 9
ADDI r1,#1->r3 F D X M W
BNEZ r3,targ F D X M W
SW r6->#4(r7) f' d' X M W
ADD r2,r1->r4 f' D X M W
targ: ADD r4,r->r4 F D X M W
if branch is taken:
1 2 3 4 5 6 7 8 9
ADDI r1,#1->r3 F D X M W
BNEZ r3,targ F D X M W
SW r6->#4(r7) F D - - -
ADD r2,r1->r4 F - - - -
targ: ADD r4,r->r4 F D X M W
note 2 instrs cancelled - did not reach stage where they update reg or mem.
branch prediction:
speculation
control speculation
eg. assume not-taken. branch 20%, other 80%, 75% of branches are taken. branch predicted with 95% accuracy. then CPI = 1 + 2*0.2*(1-0.95) = 1.02.
dynamic branch prediction
anatomy
all instrs or PC and/or
only branches? global/local
history
+----------+ +------------+ +------------+
|program |------->| event |------>| prediction |
|execution | | selection | | index |
+----------+ +------------+ +------------+
^ ^ |
. . |
. . |
. . |
recovery?. . v
. +------------+ +-----------+
.| feedback |<----------|prediction | saturating counters,
| |---------->|mechanism | markov,
+------------+ +-----------+ perceptrons, etc.
using branch outcome,
update pred. mechanism,
update history
branch direction prediction
eg. consider the inner loop only. assume path taken last time.
for (i = 0; i < 100; i++)
for (j = 0; j < 3; j++)
predict N T T T N T T T N T T T
outcome T T T N T T T N T T T N
^ ^ ^ ^ ^ ^
there are 2 built-in mispredictions per loop.
two-bit saturating counters (2bc):
T
+-----------------+ T +-----------------+
+--| predict taken |<--------| predict taken |
T| | 11 | | 10 |
+->| TT |-------->| TN |
+-----------------+ N +-----------------+
| ^
N | | T
v |
+-----------------+ N +-----------------+
+--|predict not taken|<--------|predict not taken|
N| | 00 | | 01 |
+->| NN |-------->| NT |
+-----------------+ T +-----------------+
store and accessing predictions
eg. with k = 10 PC bits, then the table size is 2^10*2=2048 bits. tag = 32 - 10 (index) - 2 (lower bits) = 20 bits. size is 2^10*(2+20)=22 kbits.
+------+----+-+ +---+ 2^k rows
| tag | idx| | |---| PBT
+------+----+-+ |---|
| |---|
+----------->|---|
+---+
eg. using 2bc
for (i = 0; i < 100; i++)
for (j = 0; j < 3; j++)
predict N n t T t T T T t T T T
outcome T T T N T T T N T T T N
^ ^ ^ ^
correlated branch prediction
eg. using corrs:
state/prediction BHR=NN N- T T T T T T T T T T T
BHR=NT N N- T T T T+ T T T T+ T T
BHR=TN N N N N N- T T T T+ T T T
BHR=TT N N N- T- N N N- N- N N N- T-
outcome N N T T T N T T T N T T T N
it does not get better. BHR is not long enough to capture patterns.
eg. using 3 bits of history:
v
state/prediction BHR=NNN N- T T T T T T T T T T T
BHR=NNT N N- T T T T T T T T T T
BHR=NTN N N N N N N N N N N N N
BHR=NTT N N N- T T T T+ T T T T+ T <<
BHR=TNN N N N N N N N N N N N N
BHR=TNT N N N N N N- T T T T+ T T <<
BHR=TTN N N N N N- T T T T+ T T T <<
BHR=TTT N N N N+ N N N N+ N N N N+ <<
outcome T T T N T T T N T T T N
note prediction reaches a steady state of perfect accuracy. only 4 patterns are active.
correlated predictor design choices:
two-level predictors
eg. global history register (G) and global prediction table (g):
+---+ +-------+
8bits | | | | 2^8 rows
| G |----8---> | g |
| | | |
+---+ +-------+
2-bit counters
size = 8 + 2^8*2 = 520 bits.
eg. global history register (G) and per-address prediction table (p):
choose k=2 bits
+----+--+--+
branch PC | | | |
+----+--+--+
| 2
v
+---+ +---------------+
8bits | | |+-+ +-+ +-+ +-+| 2^8 rows
| G |----8---> || | | | | | | ||
| | |+-+ +-+ +-+ +-+|
+---+ +---------------+
2^k=4 tables
private predictor tables
size = 8 + 2^8 * 2^2 * 2 = 2056 bits
eg. per-address history register (P) and global prediction table (g):
branch PC
+----+--+--+
| | | | choose 6 bits
+----+--+--+
| +----------+ +---------+
+--6--------> | | | |
+----------+ | |
+----------+---8---->| g |
2^6 | | | | 2^8 rows
rows +----------+ +---------+
8 bits 2 bits
private history table
size = 2^6 * 8 + 2^8 * 2 = 1024 bits
eg. per-address history register (P) and per-address prediction table (p):
branch PC
+----+--+--++
| | | ||
+----+--+--++
| |
| +--2-----------------------------v
| +----------+ +---------------+
+------6----> | | |+-+ +-+ +-+ +-+| 2^8
+----------+ || | | | | | | || rows
+----------+---8---->|| | | | | | | || (2bits)
2^6 | | |+-+ +-+ +-+ +-+|
rows +----------+ +---------------+
8 bits 4 tables
private history table private prediction tables
size = 2^6 * 8 + 2^8 * 2 * 4 = 2560 bits
hybrid (tournament) predictor [McFarling'93]:
+--+
|PC|-----+-------------+-------+
+--+ | v v
+---+ v +---+ +---+ +-------+
|GHR|-> xor ->|BPB| |BPB| |chooser|
+---+ +---+ +---+ +-------+
| | |
v v |
.----------. |
| mux |<-----+
'----+-----'
v
many direction prediction stretegies
branch target buffer (BTB)
zen4 BTB: 1.5K(L1) to 7K(L2) entries
why does BTB work:
switch)return address stack (RAS)
RAS[TOS]branch prediction summary
handling interrupts/exceptions:
eg. handling exceptions
1 2 3 4 5 6
DIV r1,r0->r2 F D X* M W <- handle here
ADD r3,r4->r5 F* D X M W
X*: div/0
F* page fault
eg. out of order
1 2 3 4 5 6 7 8 9 10
DIV.S f0,f1->f2 F D E/ E/ E/ E/ E/ W
S.S f2->[r1] F D d* d* d* X M^ W
ADD.S f0,f1->f0 F D E+ E+ W
M^: page fault
eg. two simultaneous in-flight exceptions
1 2 3 4 5 6 7 8 9 10
DIV.S f0,f1->f2 F D E/ E/ E/ E/ E/ W
S.S f2->[r1] F D d* d* d* X M^ W
DIV.S f0,f4->f2 F D E\ E/ E/ E/ E/ W
M^: page fault
E\: div/0
problem wih in-order pipelines:
1 2 3 4 5 6 7 8 9 10 11
ADD.S f0,f1->f2 F D X X X |M X
MUL.S f2,f3->f2 F d* d* D |X X X M W
SUB.S f0,f1->f4 p* p* F D X X X M W
static instruction scheduling:
dynamic scheduling:
instruction buffer
tomasulu's algorithm:
true/data dependence (RAW)
name dependencies
register renaming:
eg.
map table free list
r1 r2 r3 r4
--------------
p1 p2 p3 p4 p5,p6,p7,p8
p5 p2 p3 p4 p6,p7,p8
p5 p6 p3 p4 p7,p8
p5 p7 p3 p4 p8
p8 p7 p3 p4
div r2,r3->r1 div p2,p3->p5
add r2,r1->r3 add p2,p5->p6
subi r4,4->r2 subi p4,4->p7
add r4,r2->r1 add p4,p7->p8
tomasulo organization
new pipeline (FDSXW):
remark. stalls propagate to later instrs but waits do not.
value/copy-based regiseter renaming (/tomasulo-style):
eg.
L.S [r1+0]->f1 (allotted RS#2)
maptable[r1]==0 => RS[2].vk=regfile[r1]
maptable[f1]=RS#2
MUL.S f0,f1->f2 (alloted RS#4)
maptable[f0]==0 => RS[4].vj=regfile[f0]
maptable[f1]==RS#2 => RS[4].vk=RS#2
ADD.S f7,f8->f0
can write regfile[f0] before MUL.S execs
L.S[r1+4]->f1
can write regfile[f1] before MUL.S execs
can write regfile[f1] before 1st L.S execs
reservation stations
RS# | FU | Busy | Op | Vj | Vk | Qj | Qk
2 | LD | YES |L.S.| | | 0 |[r1]
4 |FP1 | YES |MULS| |RS#2|[f0]|
eg.
cycle 1:
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |yes |34+[R2] |Reg|T
LD.S 34(r2)->f6 |c1| | | |load2 |no | |f0 |
LD.S 45(r3)->f2 | | | | |load3 |no | |f2 |
MUL.S f2,f4->f0 | | | | +------+----+--------+f4 |
SUB.S f6,f2->f8 | | | | |CDB |f6 |load1
DIV.S f0,f6->f10 | | | | |T |V |f8 |
ADD.S f8,f2->f6 | | | | | | |f10|
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj|Vk |r3 |
add1 |no | | | | | +---+--------
add2 |no | | | | | |ex latencies
add3 |no | | | | | |op |cycles
mult1|no | | | | | |ADD|2
mult2|no | | | | | |L.S|2
|MUL|10
|DIV|40
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |yes |34+[R2] |Reg|T
LD.S 34(r2)->f6 |c1|c2| | |load2 |yes |45+[R3] |f0 |
LD.S 45(r3)->f2 |c2| | | |load3 |no | |f2 |load2
MUL.S f2,f4->f0 | | | | +------+----+--------+f4 |
SUB.S f6,f2->f8 | | | | |CDB |f6 |load1
DIV.S f0,f6->f10 | | | | |T |V |f8 |
ADD.S f8,f2->f6 | | | | | | |f10|
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj|Vk |r3 |
add1 |no | | | | | +---+
add2 |no | | | | |
add3 |no | | | | |
mult1|no | | | | |
mult2|no | | | | |
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |yes |34+[R2] |Reg|T
LD.S 34(r2)->f6 |c1|c2| | |load2 |yes |45+[R3] |f0 |mult1
LD.S 45(r3)->f2 |c2|c3| | |load3 |no | |f2 |load2
MUL.S f2,f4->f0 |c3| | | +------+----+--------+f4 |
SUB.S f6,f2->f8 | | | | |CDB |f6 |load1
DIV.S f0,f6->f10 | | | | |T |V |f8 |
ADD.S f8,f2->f6 | | | | | | |f10|
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj|Vk |r3 |
add1 |no | | | | | +---+
add2 |no | | | | |
add3 |no | | | | |
mult1|yes |MUL.S|load2| |- |[f4]
mult2|no | | | | |
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |yes |34+[R2] |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4| |load2 |yes |45+[R3] |f0 |mult1
LD.S 45(r3)->f2 |c2|c3| | |load3 |no | |f2 |load2
MUL.S f2,f4->f0 |c3| | | +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4| | | |CDB |f6 |load1
DIV.S f0,f6->f10 | | | | |T |V |f8 |add1
ADD.S f8,f2->f6 | | | | | | |f10|
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj|Vk |r3 |
add1 |yes |SUB.S|load1|load2|- |- +---+
add2 |no | | | | |
add3 |no | | | | |
mult1|yes |MUL.S|load2| | |[f4]
mult2|no | | | | |
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |yes |45+[R3] |f0 |mult1
LD.S 45(r3)->f2 |c2|c3|c5| |load3 |no | |f2 |load2
MUL.S f2,f4->f0 |c3| | | +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4| | | |CDB |f6 |
DIV.S f0,f6->f10 |c5| | | |T |V |f8 |add1
ADD.S f8,f2->f6 | | | | |load1 |mem(1) |f10|mult2
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |yes |SUB.S| |load2|mem(1)|- +---+--------
add2 |no | | | | |
add3 |no | | | | |
mult1|yes |MUL.S|load2| | |[f4]
mult2|yes |DIV.S|mult1| | |[f6]
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |no | |f0 |mult1
LD.S 45(r3)->f2 |c2|c3|c5|c6 |load3 |no | |f2 |
MUL.S f2,f4->f0 |c3|c6| | +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4|c6| | |CDB |f6 |add2
DIV.S f0,f6->f10 |c5| | | |T |V |f8 |add1
ADD.S f8,f2->f6 |c6| | | |load2 |mem(2) |f10|mult2
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |yes |SUB.S| | |mem(1) |mem(2)
add2 |yes |ADD.S|add1 | | |[f2]
add3 |no | | | | |
mult1|yes |MUL.S| | |mem(2) |[f4]
mult2|yes |DIV.S|mult1| | |[f6]
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |no | |f0 |mult1
LD.S 45(r3)->f2 |c2|c3|c5|c6 |load3 |no | |f2 |
MUL.S f2,f4->f0 |c3|c6| | +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4|c6|c8|c9 |CDB |f6 |add2
DIV.S f0,f6->f10 |c5| | | |T |V |f8 |
ADD.S f8,f2->f6 |c6|c9| | |add1 |m-m |f10|mult2
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |no | | | | |
add2 |yes |ADD.S| | |m-m |[f2]
add3 |no | | | | |
mult1|yes |MUL.S| | |mem(2) |[f4]
mult2|yes |DIV.S|mult1| | |[f6]
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |no | |f0 |mult1
LD.S 45(r3)->f2 |c2|c3|c5|c6 |load3 |no | |f2 |
MUL.S f2,f4->f0 |c3|c6| | +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4|c6|c8|c9 |CDB |f6 |
DIV.S f0,f6->f10 |c5| | | |T |V |f8 |
ADD.S f8,f2->f6 |c6|c9|11|12 |add2 |(m-m)+f2 |f10|mult2
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |no | | | | |
add2 |no | | | | |
add3 |no | | | | |
mult1|yes |MUL.S| | |mem(2) |[f4]
mult2|yes |DIV.S|mult1| | |[f6]
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |no | |f0 |
LD.S 45(r3)->f2 |c2|c3|c5|c6 |load3 |no | |f2 |
MUL.S f2,f4->f0 |c3|c6|16|17 +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4|c6|c8|c9 |CDB |f6 |
DIV.S f0,f6->f10 |c5|17| | |T |V |f8 |
ADD.S f8,f2->f6 |c6|c9|11|12 |mult1 |M*f4 |f10|mult2
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |no | | | | |
add2 |no | | | | |
add3 |no | | | | |
mult1|no | | | | |
mult2|yes |DIV.S| | |M*f4 |[f6]
instr status | |Busy|Address |Map Table
instr |D |S |X |W |load1 |no | |Reg|T
LD.S 34(r2)->f6 |c1|c2|c4|c5 |load2 |no | |f0 |
LD.S 45(r3)->f2 |c2|c3|c5|c6 |load3 |no | |f2 |
MUL.S f2,f4->f0 |c3|c6|16|17 +------+----+--------+f4 |
SUB.S f6,f2->f8 |c4|c6|c8|c9 |CDB |f6 |
DIV.S f0,f6->f10 |c5|17|57|58 |T |V |f8 |
ADD.S f8,f2->f6 |c6|c9|11|12 |mult2 |M*f4/f6 |f10|
-----------------+--+--+--+-----------+------+-------------+...|
reservation stations |r2 |
FU |busy|op |Qj |Qk |Vj |Vk |r3 |
add1 |no | | | | |
add2 |no | | | | |
add3 |no | | | | |
mult1|no | | | | |
mult2|no | | | | |
summary
| hazard type | tomasulo |
|---|---|
| instr buffer/RS | stall in D - structural |
| FU | wait in S - structural |
| RAW | wait in S |
| WAR | none - renaming |
| WAW | none - renaming |
dyanamic scheduling as loop unrolling:
eg. single-precision AX (SAX):
for (i = N; i>0; i--)
Z[i] = A * X[i];
0: L.S X(r1),f0 // Loop
1: MUL.S f0,f2,f4 // A in f2
2: S.S f4,Z(r1)
3: SUBI r1,4,r1 // i in r1
4: BNEZ r1,Loop
consider two iterations: L.S, MUL.S, S.S, SUBI, L.S, MUL.S, S.S
assume mul takes 4 cycles; 1st load takes 8 cycles (cache miss), 2nd load 1 cycle (hit, after 1st load executes); R1 has 80; &Z[0] == &X[0].
cycle 1:
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 | | | |ld2|no | | |f0 |ld1
MUL.S f0,f2->f4 | | | | |ld3|no | | |f2 |
S.S f4->#0(r1) | | | | |st1|no | | |f4 |
SUBI r1,4->r1 | | | | |st2|no | | |f6 |
BNEZ r1,Loop | | | | |st3|no | | |f8 |
L.S #0(r1)->f0 | | | | |---+----+----+------|f10| WAW
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|no |
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|no | | |f0 |ld1
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) | | | | |st1|no | | |f4 |mult1
SUBI r1,4->r1 | | | | |st2|no | | |f6 |
BNEZ r1,Loop | | | | |st3|no | | |f8 |
L.S #0(r1)->f0 | | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|no | | |f0 |ld1
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult1
SUBI r1,4->r1 | | | | |st2|no | | |f6 |
BNEZ r1,Loop | | | | |st3|no | | |f8 |
L.S #0(r1)->f0 | | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|no | | |f0 |ld1
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult1
SUBI r1,4->r1 |c4 | | | |st2|no | | |f6 |
BNEZ r1,Loop | | | | |st3|no | | |f8 |
L.S #0(r1)->f0 | | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |add1
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |[r1] |4
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|no | | |f0 |ld1
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult1
SUBI r1,4->r1 |c4 |c5 | | |st2|no | | |f6 |
BNEZ r1,Loop |c5 | | | |st3|no | | |f8 |
L.S #0(r1)->f0 | | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |add1
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |[r1] |4
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|yes | |add1 |f0 |ld2
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult1
SUBI r1,4->r1 |c4 |c5 |c6 | |st2|no | | |f6 |
BNEZ r1,Loop |c5 | | | |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 | | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |add1
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |[r1] |4
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|yes |76 | |f0 |ld2
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|no | | |f6 |
BNEZ r1,Loop |c5 |c7 | | |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 | | | |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 | | | |CDB |...|
S.S f4->#0(r1) | | | | |T |V |r1 |
|add1 |76 | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|yes |MUL.S|ld2 | | |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|yes |76 | |f0 |ld2
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 | |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 | | |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 | | | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|yes |MUL.S|ld2 | | |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 | | |ld2|yes |76 | |f0 |ld2
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 | | |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 | | | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |add1
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |76 |4
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|yes |MUL.S|ld2 | | |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|yes |80 | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10| |ld2|yes |76 | |f0 |ld2
MUL.S f0,f2->f4 |c2 | | | |ld3|no | | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 | | |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 | | | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |add1
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |76 |4
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld1 | | |[f2]
mult2|yes |MUL.S|ld2 | | |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|yes |76 | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11| | |ld3|yes | |add1 |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11| |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 | | | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |add1
|ld1 |Mem[80] | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |76 |4
add2 |no |
add3 |no |
mult1|yes |MUL.S| | |M[80] |[f2]
mult2|yes |MUL.S|ld2 | | |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11| | |ld3|yes | |add1 |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12| | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |add1
|ld2 |M[76] | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |yes |SUBI | | |76 |4
add2 |no |
add3 |no |
mult1|yes |MUL.S| | |M[80] |[f2]
mult2|yes |MUL.S| | |M[76] |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11| | |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12| | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |
|add1 |72 | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S| | |M[80] |[f2]
mult2|yes |MUL.S| | |M[76] |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11|c15| |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 | | | |st1|yes |80 |mult1 |f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12| | |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S| | |M[80] |[f2]
mult2|yes |MUL.S| | |M[76] |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11|c15|c16 |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 |c16| | |st1|yes |80 |[80]*F|f4 |mult2
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |mult2 |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12|c16| |CDB |...|
S.S f4->#0(r1) |c8 | | | |T |V |r1 |
|mult1 |M[80]*f2 | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|no |
mult2|yes |MUL.S| | |M[76] |[f2]
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11|c15|c16 |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 |c16|c17| |st1|yes |80 |[80]*F|f4 |mult1
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |[76]*F|f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|no | | |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12|c16|c17 |CDB |...|
S.S f4->#0(r1) |c8 |c17| | |T |V |r1 |
|mult2 |M[76]*f2 | |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld3 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11|c15|c16 |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 |c16|c17|c18 |st1|no | | |f4 |mult1
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|yes |76 |[76]*F|f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|yes |72 |mult1 |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12|c16|c17 |CDB |...|
S.S f4->#0(r1) |c8 |c17|c18| |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld3 | | |[f2]
mult2|no |
instr status | |Busy|Addr|T |Map Table
instr |D |S |X |W |ld1|no | | |Reg|T
L.S #0(r1)->f0 |c1 |c2 |c10|c11 |ld2|no | | |f0 |ld3
MUL.S f0,f2->f4 |c2 |c11|c15|c16 |ld3|yes |72 | |f2 |
S.S f4->#0(r1) |c3 |c16|c17|c18 |st1|no | | |f4 |mult1
SUBI r1,4->r1 |c4 |c5 |c6 |c7 |st2|no | | |f6 |
BNEZ r1,Loop |c5 |c7 |c8 |c9 |st3|yes |72 |mult1 |f8 |
L.S #0(r1)->f0 |c6 |c8 |c11|c12 |---+----+----+------|f10|
MUL.S f0,f2->f4 |c7 |c12|c16|c17 |CDB |...|
S.S f4->#0(r1) |c8 |c17|c18|c19 |T |V |r1 |
----------------------------------+--------------------+---+------
reservation stations
FU |busy|op |Qj |Qk |Vj |Vk
add1 |no |
add2 |no |
add3 |no |
mult1|yes |MUL.S|ld3 | | |[f2]
mult2|no |
why can tomasulo overlap loop iterations:
two major advantages:
drawback: if 1st store has page fault, younger instrs can have already updated values. we do not have info to restore the states.
dynamic scheduling summary:
true register renaming + reorder buffer (ROB) = MIPSR10K design
sequential (vN) semantics for interrupts:
precise state:
instr buffer becomes reorder buffer (ROB):
load/store queue (LSQ):
register renaming in R10K:
R10K data structures:
R10K pipeline (FDSXCR):
eg.
Loop: L.S #0(r1)->f0
MUL.S f0,f2->f4
S.S f4->#0(r1)
SUBI r1,4->r1
BNEZ r1,Loop
cycle 1:
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
ht|1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 | | | |f0 |PR#5 |
| | | | | | | | |f2 |PR#2+ |
| | | | | | | | |f4 |PR#3+ |
| | | | | | | | |r1 |PR#4+ |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#6,PR#7,PR#8
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 | | |f0 |PR#5 |
t |2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
| | | | | | | | |f4 |PR#6 |
| | | | | | | | |r1 |PR#4+ |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#7,PR#8
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#5 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
t |3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
| | | | | | | | |r1 |PR#4+ |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#7,PR#8
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#5 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
t |4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 | | | |r1 |PR#7 |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#8
1|add1 |yes |SUBI |PR#7 |PR#4+|
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#5 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 | | |r1 |PR#7 |
t |5 |BNEZ r1,Loop | | |c5 | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#8
1|add1 |yes |SUBI |PR#7 |PR#4+|
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#8 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 | |r1 |PR#7 |
|5 |BNEZ r1,Loop | | |c5 | | | |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |yes |L.S |PR#8 |PR#7 |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#8 |PR#7
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 | | |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 | | | |
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |yes |L.S |PR#8 |PR#7+|
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#8 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 | |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 | | |
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |yes |L.S |PR#8 |PR#7+|
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3+ | |f0 |PR#8 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 |c9+ | |
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |yes |L.S |PR#5 |PR#4+|
6|ld2 |yes |L.S |PR#8 |PR#7+|
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3-10 | |f0 |PR#8 |
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 | | | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 |c9+ | |
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5 |PR#2+|
4|mult2|no |
5|ld1 |no |
6|ld2 |yes |L.S |PR#8 |PR#7+|
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
h |1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3-10 |c11|f0 |PR#8 |PR#5
|2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 |c11| | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 |c9-11 | |
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5+|PR#2+|
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
|1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3-10 |c11|f0 |PR#8+ |PR#8
h |2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 |c11|c12+ | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#6 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
t |6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
|7 |MUL.S f0,f2->f4 | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#1
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5+|PR#2+|
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
|1 |L.S #0(r1)->f0 |PR#5 |PR#1 |c1 |c2 |c3-10 |c11|f0 |PR#8+ |
h |2 |MUL.S f0,f2->f4 |PR#6 |PR#3 |c2 |c11|c12+ | |f2 |PR#2+ |
|3 |S.S f4->#0(r1) | | |c3 | | | |f4 |PR#1 |
|4 |SUBI r1,4->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |BNEZ r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
|6 |L.S #0(r1)->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
t |7 |MUL.S f0,f2->f4 |PR#1 |PR#6 |c13| | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |no |
2|add2 |no |
3|mult1|yes |MUL.S|PR#6 |PR#5+|PR#2+|
4|mult2|yes |MUL.S|PR#1 |PR#8+|PR#2+|
5|ld1 |no |
6|ld2 |no |
7|st1 |yes |S.S | |PR#4+|PR#6 |
8|st2 |no |
observations:
precise state in r10k:
restoring precise state in R10K
eg. serial rollback
Loop: ldf [r1+0]->f0
mulf f0,f2->f4
stf f4->[r1+0]
subi r1,8->r1
bnez r1,Loop
page fault:
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
|8 |stf f4->[r1+0] | | |c14| | | |f0 |PR#8+ |
t |9 |subi r1,8->r1 |PR#3 |PR#7 |c18| | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#1 |
|4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#3 |
|5 |bnez r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
|6 |ldf [r1+0]->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
|7 |mulf f0,f2->f4 |PR#1 |PR#6 |c13|c14|c15-18| |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |
1|add1 |yes |subi |PR#3 |PR#7+|
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |yes |stf | |PR#7+|PR#1 |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
|8 |stf f4->[r1+0] | | |c14| | | |f0 |PR#8+ |
t |9 |subi r1,8->r1 |PR#3 |PR#7 |c18| | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#1 |
|4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |bnez r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
|6 |ldf [r1+0]->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
|7 |mulf f0,f2->f4 |PR#1 |PR#6 |c13|c14|c15-18| |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |yes |stf | |PR#7+|PR#1 |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
t |8 |stf f4->[r1+0] | | |c14| | | |f0 |PR#8+ |
| | | | | | | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#1 |
|4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |bnez r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
|6 |ldf [r1+0]->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
|7 |mulf f0,f2->f4 |PR#1 |PR#6 |c13|c14|c15-18| |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
| | | | | | | | |f0 |PR#8+ |
| | | | | | | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#6+ |
|4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |bnez r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
|6 |ldf [r1+0]->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
t |7 |mulf f0,f2->f4 |PR#1 |PR#6 |c13|c14|c15-18| |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3,PR#1
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
| | | | | | | | |f0 |PR#5+ |
| | | | | | | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#6+ |
|4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#7+ |
|5 |bnez r1,Loop | | |c5 |c7 |c8 |c9 |----------+------
t |6 |ldf [r1+0]->f0 |PR#8 |PR#5 |c6 |c8 |c11 |c12|
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3,PR#1,PR#8
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
| | | | | | | | |f0 |PR#5+ |
| | | | | | | | |f2 |PR#2+ |
h |3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#6+ |
t |4 |subi r1,8->r1 |PR#7 |PR#4 |c4 |c5 |c6 |c7 |r1 |PR#4+ |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3,PR#1,PR#8,PR#7
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |no |
ROB |map table |CDB
ht|# |instr |T |Told |D |S |X |C |reg|T+ |T
| | | | | | | | |f0 |PR#5+ |
| | | | | | | | |f2 |PR#2+ |
ht|3 |stf f4->[r1+0] | | |c3 |c16|c17 |c18|f4 |PR#6+ |
| | | | | | | | |r1 |PR#4+ |
| | | | | | | | |----------+------
| | | | | | | | |
| | | | | | | | |
--+--+----------------+-----+-----+---+---+------+---+
reservation stations |free list
#|FU |busy|op |T |S1 |S2 |PR#3,PR#1,PR#8,PR#7
1|add1 |no |
2|add2 |no |
3|mult1|no |
4|mult2|no |
5|ld1 |no |
6|ld2 |no |
7|st1 |no |
8|st2 |no |
MIPS R10K summary
three great tastes
motivation:
locality
memory hierarchy:
+---+ +----+ +------+ +--------+
|CPU|<-->|M1|<-->| M2 |<-->| M3 |<-->| M4 |
+---+ +----+ +------+ +--------+
concrete memory hierarchy:
┌────────────────┐ ─┐
│ CPU Regs │ │ compiler
├───────┬────────┤ │ managed
│ I$ │ D$ │ ─┤
└───┬───┴───┬────┘ │
┌───┴───────┴────┐ │ hardware
│ L2$ │ │ managed
└───────┬────────┘ │
┌───────┴────────┐ │
│ main memory │ ─┤
└───────┬────────┘ │ software
┌───────┴────────┐ │ managed
│ disk │ │
└────────────────┘ ─┘
basic mem array structure:
eg. finding data via indexing:
data tag v
╱┐ ┌──────┬───┬─┐ 1024*256 bits
│ ├─►│ 0 │ │ │ SRAM
│ ├─►│ 1 │ │ │
│w├─►│ 2 │ │ │
┌──────────►│o├─►│ 3 │ │ │
│ │r│ │ ┊ │ ┊ │┊│
│ │d├─►│ 1021 │ │ │
│ │s├─►│ 1022 │ │ │
│ │ ├─►│ 1023 │ │ │
│ ╲┘ └───┬──┴─┬─┴┬┘
│ │ │ │
┌───────┼────────────────────┼──►(=) │
│ │ │ │ │
│ │ ▼ ▼ ▼
┌────┴─────┬─┴─────────┬─────┐ ┌────┐┌────┐
│tag[31:15]│index[14:5]│[4:0]├─►│ << ││ & │
└──────────┴───────────┴─────┘ └─┬──┘└─┬──┘
▲ ▼ ▼
address data hit?
decode part of address
tags:
lookup algorithm:
calculating tag overhead:
handling cache miss:
cache performance equation
eg. calculating CPI:
then
for hierarchy:
t_avg = T_L1 + %miss_L1 * T_L1miss
= T_L1 + %miss_L1 * (T_L2 + %miss_L2 \* T_L2miss)
= ...
eg. performance calculation:
then without L2:
with L2:
eg. cache miss simulation:
observation: there are conflicting pairs like 0000/1000
set-associativity
2-way associative cache:
way 0 way 1
╱┐ ┌──────┬─┬──────┬─┐
│ ├─►│ 0 │ │ 512 │ │
│s├─►│ 1 │ │ 513 │ │
┌──────────►│e├─►│ 2 │ │ 514 │ │
│ │t│ │ ┊ │┊│ ┊ │┊│
│ │s├─►│ 510 │ │ 1022 │ │
│ │ ├─►│ 511 │ │ 1023 │ │
│ ╲┘ └──┬───┴┬┴──┬───┴┬┘
┌───────┼───────────────────┼──┬─┼───┼──┐ │
│ │ │ └(=) │ └(=)
│ │ │ └───┼────┼┐
│ │ ▼ ▼ ││
│18 │9 ┌──────────┐ ││
│ │ │ mux │◄──┤│
│ │ └─┬────────┘ ││
│ │ ▼ ▼▼
┌────┴─────┬─┴─────────┬─────┐5 ┌────┐ ┌────┐
│tag[31:14]│index[13:5]│[4:0]├─►│ << │ │ OR │
└──────────┴───────────┴─────┘ └─┬──┘ └─┬──┘
▲ ▼ ▼
address data hit?
eg. 8-bit cache, 2-bit blocks, 2-way set-associative:
observation:
replacement policies
2-way NMRU: add MRU field in each set, updated on each access
data from memory
│
┌───┴────┐
┌───────────────────────────────┼────┬───┼────┐
│ ▼ ▼ ▼ ▼
│ ╱┐ ┌───┬──────┬─┬──────┬─┐
│ │s├─►│ │ 0 │ │ 512 │ │
│ ┌──────────►│e├─►│ │ 1 │ │ 513 │ │
│ │ │t│ │ ┊ │ ┊ │┊│ ┊ │┊│
│ │ │s├─►│ │ 511 │ │ 1023 │ │
│ │ ╲┘ └┬─┬┴──┬───┴┬┴──┬───┴┬┘
├───────┼─────────────────┼─┼───┼──┬─┼───┼──┐ │
│ │ ▲ ▲ │ └(=) │ └(=)
│ │ │ │ │ └───┼────┼┐
│ │ │ │ ▼ ▼ ││
│ │ WE │ │ ┌──────────┐ ││
│ │ │ │ │ mux │◄──┤│
│ │ │ │ └─┬────────┘ ┌─┼┤
│ │ │ └────┼─────────mux┤│
│ │ │ ▼ ▼▼
┌────┴─────┬─┴─────────┬─────┐ │ ┌────┐ ┌────┐
│tag[31:15]│index[14:5]│[4:0]├─┼──►│ << │ │ OR │
└──────────┴───────────┴─────┘ │ └──┬─┘ └─┬──┘
▲ └──────┼────────────┤
address ▼ ▼
data hit?
eg. 4-bit addr, 8-bit cache, 4-way LRU
prefetching