-
Notifications
You must be signed in to change notification settings - Fork 1
/
notes.tex
2214 lines (1767 loc) · 36.5 KB
/
notes.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[letter,12pt]{article}
\usepackage{graphicx}
\usepackage{amsmath, amssymb}
\usepackage[hidelinks]{hyperref}
\usepackage[titles]{tocloft}
\usepackage{placeins}
\usepackage{courier}
\usepackage{multirow, multicol}
\usepackage{soul}
\renewcommand*{\cftdot}{}
\cftpagenumbersoff{subsection}
\cftpagenumbersoff{subsubsection}
\newcommand{\sect}[1]{
\pagebreak
\FloatBarrier
\section*{#1}
\addcontentsline{toc}{section}{\protect\numberline{}#1}%
}
\newcommand{\subsect}[1]{
\FloatBarrier
\subsection*{#1}
\addcontentsline{toc}{subsection}{\protect\numberline{}#1}%
}
\newcommand{\subsubsect}[1]{
\FloatBarrier
\subsubsection*{#1}
\addcontentsline{toc}{subsubsection}{\protect\numberline{}#1}%
}
\newcommand{\eq}[1]{
\begin{equation}
\begin{aligned}
#1
\end{aligned}
\end{equation}
}
\newcommand{\img}[1]{
\begin{figure}[h!]
\begin{center}
\includegraphics[width=0.5\linewidth]{#1}
\end{center}
\end{figure}
}
\newcommand{\bullets}[1]{
\begin{itemize}
#1
\end{itemize}
}
\newcommand{\enum}[1]{
\begin{enumerate}
#1
\end{enumerate}
}
\newcommand{\cols}[2]{
\begin{multicols}{2}
#1
\columnbreak
#2
\end{multicols}
}
\newcommand{\tabl}[2]{
\begin{center}
\begin{tabular}{ | #1 | }
\hline
#2
\hline
\end{tabular}
\end{center}
}
\begin{document}
\title{High Performance Computer Architecture}
\author{Madison Hanberry}
\maketitle
\pagebreak
\tableofcontents
\sect{Lesson 2: Introduction}
\subsect{(12) Active Power}
\eq{
P = \frac{1}{2} \times v^2 \times f \times \alpha
}
$C$: Capacitance ($\sim$ Chip area)
$v^2$: Power supply voltage
$f$: Frequency
$\alpha$: Activity factor (\% of transistors active in any given clock cycle)
\subsect{(13) Static Power}
Decreasing \emph{dynamic} power ($v \downarrow$) increases \emph{static} power (increases power leakage).
\img{figures/lesson2_13.png}
\subsect{(14) Quiz: Active Power}
\eq{
P &= 30 W\ at\ 1.0 v, 2\ GHz \\
30 &= \frac{1}{2} C \times (1.0)^2 \times 2 \alpha \\
30 &= C \alpha
}
\subsubsect{(i) $0.9 v, 1.8\ GHz$}
\eq{
P &= \frac{1}{2} (30) (0.9)^2 \times 1.8 \\
P &= 21.87
}
\subsubsect{(ii) $1.5v, 3\ GHz$}
\eq{
P &= \frac{1}{2} (30) (1.5)^2 \times 3 \\
P &= 101.25
}
\subsect{(16) Fabrication Yield}
\eq{
Yield = \frac{Working\ Chips}{Chips\ on\ Wafer}
}
Yield decreases as Chip size decreases relative to the wafer size.
\subsect{(17) Fabrication Cost 2}
\eq{
Chip\ Cost = \frac{Wafer\ Cost}{\#\ of\ Good\ Chips/Wafer}
}
\sect{Lesson 3: Metrics and Evaluation}
\subsect{(2) Performance}
\bullets{
\item
Latency (start $\rightarrow$ Done)
\item
Throughput (\# / second)
}
\eq{
Throughput = \frac{1}{Latency}
}
\subsect{(3) Quiz: Latency and Throughput}
\bullets{
\item
2 servers
\item
A server takes 1 msec to process an order
}
\eq{
Throughput &= 2000\ orders/sec \\
Latency &= 1\ msec
}
\subsect{(4) Comparing Performance}
\eq{
Speedup &= N \\
N &= \frac{Speed(x)}{Speed(y)} = \frac{Latency(y)}{Latency(x)} = \frac{Throughput(x)}{Throughput(y)}
}
\subsect{(5) Quiz: Performance Comparison 1}
\bullets{
\item
Laptop takes 4 hours to compress video
\item
New laptop takes 10 minutes
}
\eq{
Speedup = \frac{(4 \times 60)}{10} = 24
}
\subsect{(6) Quiz: Performance Comparison 2}
The new laptop broke, so you have to go back to using the slower laptop.
\eq{
Speedup = \frac{10}{(4 \times 60)} = 0.042
}
\subsect{(7) Speedup}
\eq{
Speedup > 1 &\Rightarrow Improved\ Performance \\
Speedup < 1 &\Rightarrow Worse\ Performance \\
Performance &\sim Throughput \\
Performance &\sim \frac{1}{Latency}
}
\subsect{(13) Summarizing Performance}
Use the \emph{geometric mean} instead of the \emph{arithmetic mean} for comparing speedups.
\img{figures/lesson3_13.png}
\subsect{(14) Quiz: Speedup Averaging}
\bullets{
\item
Speedup of 2
\item
Speedup of 8
}
\eq{
Overall\ Speedup = \sqrt{2 \times 8} = 4
}
\subsect{(15) Iron Law of Performance}
\eq{
CPU\ Time &= \#\ of\ Instructions \\
&\times Cycles\ per\ Instruction \times Clock\ Cycle\ Time
}
\subsect{(16) Quiz: Iron Law 1}
\bullets{
\item
3 Billion Instructions
\item
2 Cycles / Instruction
\item
Processor Clock is 3 GHz
}
\eq{
Execution\ Time = 3\ billion \times 2 \times \frac{1}{3\ billion} = 2\ sec
}
\subsect{(17) Iron Law for Unequal Instruction Times}
\eq{
CPU\ Time = \left(\sum_{i} = IC_i \times CPI_i\right) \times frequency
}
\subsect{Quiz: Iron Law 2}
\bullets{
\item
10 billion branches (CPI = 4)
\item
15 billion loads (CPI = 2)
5 billion stores (CPI = 3)
\item
20 billion integer adds (CPI = 1)
\item
Clock at 4 GHz
}
\eq{
Execution\ Time = \frac{10b \times 4 + 15b \times 2 + 5b \times 3 + 20b \times 1}{4b} = 26.25\ sec
}
\subsect{(19) Amdahl's Law}
Calculates the overall speedup when a portion of a program is enhanced.
\eq{
Frac_{ENH} &= \%\ of\ original\ execution\ time\ that\ is\ af\!fected\ by\ the\ enhancement \\
Speedup &= \frac{1}{(1 - Frac_{ENH}) + \frac{Frac_{ENH}}{Speedup_{ENH}}}
}
\subsect{(20) Quiz: Amdahl's Law}
\bullets{
\item
50 billion instructions
\item
2 GHz
\item
Improve branch from 4 to 2 CPI
}
\img{figures/lesson3_20.png}
\eq{
Frac_{ENH} &= \frac{0.2 \times 4}{0.4 \times 1 + 0.2 \times 4 + 0.3 \times 2 + 0.1 \times 3} \approx 0.381 \\
Speedup &= \frac{1}{(1 - 0.381) + \frac{0.381}{\frac{4}{2}}} \approx 1.24
}
\pagebreak
\subsect{(22) Quiz: Amdahl's Law 2}
\img{figures/lesson3_22.png}
\subsubsect{(i) Branch CPI 4 $\rightarrow$ 3}
\eq{
Speedup = \frac{1}{0.8 + \frac{0.2}{4/3}} = 1.05
}
\subsubsect{(ii) Increase Clock Frequency 2 $\rightarrow$ 2.3 GHz}
\eq{
Speedup = \frac{1}{0 + \frac{1}{2.3/2}} = 1.15
}
\subsubsect{(iii) Store CPI 3 $\rightarrow$ 2}
\eq{
Speedup = \frac{1}{0.9 + \frac{0.1}{3/2}} = 1.034
}
\pagebreak
\subsect{Lhamda's Law}
\bullets{
\item
Amdahl: Make common case fast
\item
Lhamda: Do not mess up uncommon case too badly
}
Example
\eq{
Speedup = \frac{1}{\frac{0.1}{0.1} + \frac{0.9}{2}} = 0.7
}
\subsect{(27 - 37) Problem Set}
\sect{Lesson 4: Pipelining}
\subsect{(3) Pipelining in a Processor}
\img{figures/lesson4_3.png}
\subsect{(4) Quiz: Laundry Pipelining}
\bullets{
\item
Wash (1 hour) $\rightarrow$ Dry (1 hour) $\rightarrow$ Fold (1 hour)
\item
10 loads of laundry
}
\eq{
No\ Pipelining &\Rightarrow 3 \times 10\ hours = 30\ hours \\
With\ Pipelining &\Rightarrow 1 \times 3\ hours + 9 \times 1\ hour = 12\ hours
}
\subsect{(5) Instruction Pipelining}
\bullets{
\item
5-stage pipeline (1 cycle/stage)
\item
10 instructions
}
\eq{
No\ Pipelining \Rightarrow 10 \times 5\ cycles = 50\ cycles \\
With\ Pipelining \Rightarrow 1 \times 5\ cycles + 9 \times 1\ cycle = 14\ cycles
}
\pagebreak
\subsect{(8) Processor Pipeline Stalls and Flushes}
\img{figures/lesson4_8.png}
\subsect{(10) Quiz: Control Dependencies}
\bullets{
\item
25\% of all instructions are taken branches with jumps
\item
10-stage pipeline
\item
Correct target for branch/jump computed in $6^{th}$ stage
}
\eq{
Actual\ CPI = 0.75 + 0.25 \times 6 = 2.25
}
subsect{(11) Data Dependencies}
\bullets{
\item
Read after write $\rightarrow$ True Dependency
\item
Write after write and write after read $\rightarrow$ False Dependency
}
\subsect{(12) Quiz: Data Dependencies}
I1: MUL R1,R2,R3 \\
I2: ADD R4,R4,R1 \\
I3: MUL R1,R5,R6 \\
I4: SUB R4,R4,R1
\tabl{c | c | c | c}{
& RAW & WAR & WAW \\ \hline
I1 $\rightarrow$ I2 & $\checkmark$ & - & - \\ \hline
I1 $\rightarrow$ I3 & - & - & $\checkmark$ \\ \hline
I1 $\rightarrow$ I4 & - & - & - \\ \hline
I2 $\rightarrow$ I3 & - & $\checkmark$ & - \\
}
\subsect{(13) Dependencies and Hazards}
\bullets{
\item
Dependencies - Instructions in a program that share the same registers.
\item
Hazards - Dependencies that can result in incorrect execution.
}
\subsect{(14) Quiz: Dependencies and Hazards}
\tabl{l | c | c}{
ADD R1,R2,R3 & Dependency? & Hazard? \\ \hline
SUB R5,R1,R4 & $\checkmark$ & $\checkmark$ \\ \hline
DIV R6,R1,R7 & $\checkmark$ & - \\ \hline
MUL R7,R1,R8 & $\checkmark$ & - \\
}
\subsect{(15) Handling Hazards}
\bullets{
\item
Detect hazardous situations
\bullets{
\item
Flush dependent instructions
\item
Stall dependent instructions
\item
Fix values read by dependent instructions
}
}
\subsect{(16) Quiz: Flushes, Stalls, and Forwarding}
\eq{
Fetch \rightarrow Read \rightarrow ALU/BR \rightarrow Mem \rightarrow Wr
}
\tabl{c l | c | c | c}{
& BNE R1,R0,Label & Flush & Stall & Forward \\ \hline
& ADD R4,R5,R6 & \multirow{2}{*}{$\checkmark$} & \multirow{2}{*}{-} & \multirow{2}{*}{-} \\
& SUB R5,R4,R3 & & & \\ \hline
& MUL R1,R2,R3 & \multirow{2}{*}{-} & \multirow{2}{*}{-} & \multirow{2}{*}{$\checkmark$} \\
Label: & LW R1,0(R1) & & & \\ \hline
& ADD R1,R1,R1 & - & $\checkmark$ & $\checkmark$ \\
}
\pagebreak
\subsect{(17) How Many Stages?}
\bullets{
\item
Ideal CPI = 9
\item
More stages means:
\bullets{
\item
$More\ Hazards \Rightarrow CPI \uparrow$
\item
$Less\ Work/Stage \Rightarrow Cycle Time \downarrow$
}
}
\eq{
Exe\ Time &= \#Inst \times Cycle\ Time \\
\#\ Stages &\Rightarrow Balance\ CPI\ \&\ Cycle\ Time \\
Performance &\Rightarrow 30 - 40\ stages \\
Performance + Power &\Rightarrow 10 - 15\ stages
}
\img{figures/lesson4_17.png}
\subsect{(20 - 30) Problem Set}
\sect{Lesson 5: Branches}
\subsect{(3) Branch Prediction Requirements}
\bullets{
\item
Know only PC of instruction
\bullets{
\item
What is the PC of the next instruction to fetch
}
\item
Must Correctly Guess:
\bullets{
\item
Is this a taken branch?
\item
If taken, what is the target PC?
}
}
\subsect{(4) Branch Prediction Accuracy}
\eq{
CPI = 1 + \frac{mispreds}{inst} \times \frac{penalty}{mispred}
}
\bullets{
\item
20\% of all instructions are branches
}
\tabl{c | c | c}{
Accuracy $\downarrow$ & Resolve BR in 3$^{rd}$ Stage & Resolve BR in 10$^{th}$ Stage \\ \hline
50\% for BR & $1 + 0.5 \times 0. \times 2$ & $1 + 0.5 + 0.2 \times 9$ \\
100\% for other & 1.2 & 1.9 \\ \hline
90\% for BR & $1 + 0.1 \times 0.2 \times 2$ & $1 + 0.1 \times 0.2 \times 9$ \\
100\% for all other & 1.04 & 1.18 \\ \hline
Speedup & 1.15 & 1.61 \\
}
\pagebreak
\subsect{(5) Quiz: Branch Prediction Benefit}
\bullets{
\item
5 stage pipeline
\item
Branch resolved in 3$^{rd}$ stage
\item
Fetch nothing until sure what to frtch
\item
Execute many iterations of:
}
\tabl{l | c | c}{
LOOP: & Cost No Pred & Perfect Pred \\ \hline
ADD R1,R1,-1 & 2 & 1 \\ \hline
ADD R2,R2,R2 & 2 & 1 \\ \hline
BNEZ R1,LOOP & 3 & 1 \\ \hline
Total & 7 & 3 \\
}
\eq{
Speedup = \frac{7}{3} \approx 2.33
}
\subsect{(6) Performance with Not-taken Prediction}
\bullets{
\item
Refuse to predict
\bullets{
\item
Branch: 3 cycles
\item
Non-branch: 2 cycles
}
\item
Predict not-taken:
\bullets{
\item
Branch: 1 or 3 cycles
\item
Non-branch: 1 cycle
}
}
\pagebreak
\subsect{Quiz: Multiple Predictions}
\eq{
Fetch \rightarrow Decode \rightarrow ALU\ (BR\ Resolved) \rightarrow Mem \rightarrow WR
}
\bullets{
\item
Using not-taken predictor
}
\noindent
BNE R1,R2,LABEL A \quad (Taken) \\
BNE R1,R3,LABEL B \quad (Taken) \\
A \\
B \\
C \\
LABEL A: \\
X \\
Y \\
LABEL B: \\
Z
\eq{
Cycles\ Wasted\ on\ Mispredictions = 2
}
\subsect{(8) Predict Not-Taken}
\bullets{
\item
Increment PPC
\item
20\% of instructions are branches
\item
60\% of branches are taken
\item
Correct: 80\% + 8\%, \quad Incorrect: 12\%
}
\eq{
CPI = 1 + 0.12 \times Penalty
}
\subsect{(9) Why We Need Better Prediction}
\tabl{c | c | c | c}{
& Not Taken (88\%) & Better (99\%) & Speedup \\ \hline
5-stage pipe & $1 + 0.12 \times 2$ & $1 + 0.01 \times 2$ & \multirow{2}{*}{1.22} \\
(3$^{rd}$ stage) & 1.24 & 1.02 & \\ \hline
14-stage & $1 + 0.12 \times 10$ & $1 + 0.01 \times 10$ & \multirow{2}{*}{2} \\
(11$^{th}$ stage) & 2.2 & 1.1 & \\ \hline
11$^{th}$ stage & $0.25 + 0.12 \times 10$ & $0.25 + 0.01 \times 10$ & \multirow{2}{*}{4.14} \\
4 inst/cycle & 1.45 & 0.35 & \\
}
\subsect{(10) Quiz: Predictor Impact}
\bullets{
\item
Pentium 4 "Prescott":
\bullets{
\item
FETCH, ... 29 stages ... , Resolve branches
\item
Branch prediction
\item
Multiple instruction/cycle
}
\item
Program:
\bullets{
\item
20\% of instructions are branches
\item
1\% if branches are mispredicted
\item
CPI = 0.5
}
}
Perfect branch predictor:
\eq{
CPI = 0.5 - 0.2 \times 0.01 \times 30 = 0.44
}
If 2\% of branches are mispredicted:
\eq{
CPI = 0.44 + 0.2 \times 0.02 \times 30 = 0.56
}
\subsect{(12) Better Prediction -- How?}
\eq{
PC_{next} = f(PC_{now}, History[PC_{now}])
}
\subsect{(13) BTB -- Branch Target Buffer}
\img{figures/lesson5_13.png}
\subsect{(14) Realistic BTB}
\bullets{
\item
Map least significant bits in $PC_{now}$ to an index in the BTB
}
\subsect{(15) Quiz: BTB}
\bullets{
\item
BTB has 1024 entries
\item
Fixed-size 4-byte instructions, word-aligned
\item
32-bit address
\item
$PC = 0x0000AB0C$
}
\eq{
BTB\ Index = 10leastSigUniqBits(PC) = 0b1011000011 = 0x2C3
}
\subsect{(16) Direction Predictor}
\img{figures/lesson5_16.png}
\pagebreak
\subsect{(17 - 21) Quiz: BTB and BHT}
\bullets{
\item
BHT: 16 entries, perfect prediction
\item
BTB: 4 entries, perfect prediction
}
\scriptsize
\tabl{l r l | c | c | c | c | c}{
& & & & & & & Missed \\
& & & Times & & Times & BTB & Preds. \\
& & & BHT & BHT & BTB & Entry & if 1-bit \\
0xC000 & & MOV R2,100 & Accessed & Entry & Accessed & Used & BHT \\ \hline
0xC004 & & MOV R1,0 & 1 & 0 & 0 & & \\ \hline
0xC008 & LOOP: & BEQ R1,R2,DONE & 101 & 2 & 1 & 2 & 1 \\ \hline
0xC00C & & ADD R4,R3,R1 & 100 & 3 & 0 & & \\ \hline
0xC010 & & LW R4,0(R4) & 100 & 4 & 0 & & \\ \hline
0xC014 & & ADD R5,R5,R4 & 100 & 5 & 0 & & \\ \hline
0xC018 & & ADDR1,R1,1 & 100 & 6 & 0 & & \\ \hline
0xC01C & & MOV R1,0 & 100 & 7 & 100 & 3 & 1 \\ \hline
0xC020 & DONE: & & & & & & \\
}
\normalsize
\subsect{(22) Problems with 1-Bit Prediction}
\bullets{
\item
Predicts well:
\bullets{
\item
Always taken
\item
Always not taken
\item
$Taken >>> Not\ Taken$
\item
$Taken <<< Not\ Taken$
}
\item
Not so well:
\bullets{
\item
$Taken > Not\ Taken$
\item
$Not\ Taken > Taken$
\item
Short loop
}
\item
Pretty bad:
\bullets{
\item
$Taken \approx Not\ Taken$
}
}
\eq{
Each\ Anomoly \Rightarrow Two\ Mispredictions
}
\subsect{(23) 2-Bit Predictor}
\bullets{
\item
00: Strong Not Taken
\item
01: Weak Not Taken
\item
10: Weak Taken
\item
11: Strong Taken
}
\img{figures/lesson5_23.png}
\subsect{(25) Quiz: 2BP}
\bullets{
\item
2-bit predictor
\item
Start in strong not-taken state
\item
A sequence always resulting in incorrect prediction:
\center{
T T N T N ...
}
}
\subsect{(26) 1BP,2BP}
\bullets{
\item
$1BP \rightarrow 2BP$ \quad 3BP? \quad 4BP?
\bullets{
\item
Bad: Cost $\uparrow$
\item
Good: When "anomalous" outcomes come in streaks
\bullets{
\item
How often does this happen?
}
}
\item
Stay with 2BP, maybe 3BP
}
\subsect{(28) 1-Bit History with 2-Bit Counters}
\tabl{c | c | c | c}{
State & Pred & Outcome & Correct? \\ \hline
(0, SN, SN) & N & T & $\times$ \\ \hline
(1, WN, SN) & N & N & $\checkmark$ \\ \hline
(0, WN, SN) & N & T & $\times$ \\ \hline
(1, WT, SN) & N & N & $\checkmark$ \\ \hline
(0, WT, SN) & T & T & $\checkmark$ \\ \hline
(1, ST, SN) & N & N & $\checkmark$ \\ \hline
(0, ST, SN) & T & T & $\checkmark$ \\
}
\subsect{(29) Quiz: 1-Bit History}
\bullets{
\item
1-Bit history (Start 0)
\item
2-BC/history (Start SN)
\item
(NNT)*
\item
Continues for 100 repitions
}
\eq{
\#\ Mispredictions = 100
}
\subsect{(30 - 31) N-Bit History Predictors}
\bullets{
\item
Works for all patterns of $length \leq N + 1$
\item
Costs $N + 2 \times 2^{N}$ per entry
\item
Most BCs are wasted
}
\pagebreak
\subsect{(32) Quiz: N-Bit History Predictor}
\bullets{
\item
N-Bit history, 2BCs/History
\item
Need 1024 entries
}
\tabl{c | c | c | c}{
& & & \# of 2BCs \\
& & & used for \\
& cost(bits) & (NNNT)* & (NT)* \\ \hline
N = 1 & $5 \times 1024$ & bad & 2 \\ \hline
N = 4 & $(4 + 2 \times 2^4) \times 1024$ & good & 2 \\ \hline
N = 8 & 532,480 & good & 2 \\ \hline
N = 16 & 134,234,112 & good & 2 \\
}
\subsect{(33) Quiz: History Predictor}
for(int i = 0; i != 8; i++) \\
\indent for(int j = 0; j != 8; j++) \\
\indent \indent doSomething();
\bullets{
\item
The history predictor needs at least 4 entries
\item
Each entry needs at least an 8-bit history (246 2-bit counters)
}
\subsect{(34 - 36) History with Shared Counters}
\img{figures/lesson5_34.png}
\eq{
TTTT &\Rightarrow 1111 \Rightarrow 1\ counter \\
NNNN &\Rightarrow 0000 \Rightarrow 1\ counter \\
NTNT &\Rightarrow 010101\ or\ 101010 \Rightarrow 2\ counters \\
NNNNT &\Rightarrow 16 \times H \Rightarrow 16\ counters
}
\subsect{(37) PShare}
PShare
\bullets{
\item
Private history
\item
Shared counters
\item
Good for:
\bullets{
\item
Even-odd
\item
8-iteration loop
}
}
\noindent
GShare
\bullets{
\item
Global history
\item
Shared counters
\item
Good for:
\bullets{
\item
Correlated branches
}
}
\subsect{(38) Quiz: PShare vs. GShare}
for(int i = 1000; i != 0; i--) \\
\indent if(i \% 2) \\
\indent \indent n += i; \\
\indent \indent \indent $\Downarrow$
\noindent
LOOP: \\
BEQ R1,0,EXIT \\
AND R2,R1,1 \\
BEQ R2,0,EVEN \\
ADD R3,R3,R1 \\
ADD R1,R1,-1 \\
B LOOP \\
EXIT:
\eq{
History\ for\ PShare &= 1 \\
History\ for\ GShare &= 3
}
\subsect{(40) Tournament Predictor}
\bullets{
\item
Two Predictors
\bullets{
\item
One better for branches x, y, z
\item
Other better for branches a, b, c
}
}
\img{figures/lesson5_40.png}
\subsect{(41) Hierarchical Predictor}
\bullets{
\item
Tournament
\bullets{
\item
2 good predictors
\item
update both on each dicision
}