-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtage_sc_l.h
1739 lines (1383 loc) · 37.5 KB
/
tage_sc_l.h
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
#ifndef _TAGE_SC_L_H_
#define _TAGE_SC_L_H_
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <inttypes.h>
#include <math.h>
/*
enum OpType { OPTYPE_RET_UNCOND,
OPTYPE_JMP_INDIRECT_UNCOND,
OPTYPE_JMP_INDIRECT_COND,
OPTYPE_CALL_INDIRECT_UNCOND,
OPTYPE_CALL_INDIRECT_COND,
OPTYPE_RET_COND,
OPTYPE_JMP_DIRECT_COND,
OPTYPE_CALL_DIRECT_COND,
OPTYPE_JMP_DIRECT_UNCOND,
OPTYPE_CALL_DIRECT_UNCOND,
};
*/
// branch types
//#define NOT_BRANCH 0
//#define BRANCH_DIRECT_JUMP 1
//#define BRANCH_INDIRECT 2
//#define BRANCH_CONDITIONAL 3
//#define BRANCH_DIRECT_CALL 4
//#define BRANCH_INDIRECT_CALL 5
//#define BRANCH_RETURN 6
//#define BRANCH_OTHER 7
enum branch_type {
BRANCH_DIRECT_JUMP = 0,
BRANCH_INDIRECT,
BRANCH_CONDITIONAL,
BRANCH_DIRECT_CALL,
BRANCH_INDIRECT_CALL,
BRANCH_RETURN,
BRANCH_OTHER,
NOT_BRANCH
};
#define BORNTICK 1024
//To get the predictor storage budget on stderr uncomment the next line
#define PRINTSIZE
#include <vector>
long long IMLIcount; // use to monitor the iteration number
#define SC // 8.2 % if TAGE alone
#define IMLI // 0.2 %
#define LOCALH
#ifdef LOCALH // 2.7 %
#define LOOPPREDICTOR //loop predictor enable
#define LOCALS //enable the 2nd local history
#define LOCALT //enables the 3rd local history
#endif
//The statistical corrector components
#define PERCWIDTH 6 //Statistical corrector counter width 5 -> 6 : 0.6 %
//The three BIAS tables in the SC component
//We play with the TAGE confidence here, with the number of the hitting bank
#define LOGBIAS 8
int8_t Bias[(1 << LOGBIAS)];
#define INDBIAS (((((PC ^(PC >>2))<<1) ^ (LowConf &(LongestMatchPred!=alttaken))) <<1) + pred_inter) & ((1<<LOGBIAS) -1)
int8_t BiasSK[(1 << LOGBIAS)];
#define INDBIASSK (((((PC^(PC>>(LOGBIAS-2)))<<1) ^ (HighConf))<<1) + pred_inter) & ((1<<LOGBIAS) -1)
int8_t BiasBank[(1 << LOGBIAS)];
#define INDBIASBANK (pred_inter + (((HitBank+1)/4)<<4) + (HighConf<<1) + (LowConf <<2) +((AltBank!=0)<<3)+ ((PC^(PC>>2))<<7)) & ((1<<LOGBIAS) -1)
//In all th GEHL components, the two tables with the shortest history lengths have only half of the entries.
// IMLI-SIC -> Micro 2015 paper: a big disappointment on CBP2016 traces
#ifdef IMLI
#define LOGINB 8 // 128-entry
#define INB 1
int Im[INB] = { 8 };
int8_t IGEHLA[INB][(1 << LOGINB)] = { {0} };
int8_t *IGEHL[INB];
#define LOGIMNB 9 // 2* 256 -entry
#define IMNB 2
int IMm[IMNB] = { 10, 4 };
int8_t IMGEHLA[IMNB][(1 << LOGIMNB)] = { {0} };
int8_t *IMGEHL[IMNB];
long long IMHIST[256];
#endif
//global branch GEHL
#define LOGGNB 10 // 1 1K + 2 * 512-entry tables
#define GNB 3
int Gm[GNB] = { 40, 24, 10 };
int8_t GGEHLA[GNB][(1 << LOGGNB)] = { {0} };
int8_t *GGEHL[GNB];
//variation on global branch history
#define PNB 3
#define LOGPNB 9 // 1 1K + 2 * 512-entry tables
int Pm[PNB] = { 25, 16, 9 };
int8_t PGEHLA[PNB][(1 << LOGPNB)] = { {0} };
int8_t *PGEHL[PNB];
//first local history
#define LOGLNB 10 // 1 1K + 2 * 512-entry tables
#define LNB 3
int Lm[LNB] = { 11, 6, 3 };
int8_t LGEHLA[LNB][(1 << LOGLNB)] = { {0} };
int8_t *LGEHL[LNB];
#define LOGLOCAL 8
#define NLOCAL (1<<LOGLOCAL)
#define INDLOCAL ((PC ^ (PC >>2)) & (NLOCAL-1))
long long L_shist[NLOCAL]; //local histories
// second local history
#define LOGSNB 9 // 1 1K + 2 * 512-entry tables
#define SNB 3
int Sm[SNB] = { 16, 11, 6 };
int8_t SGEHLA[SNB][(1 << LOGSNB)] = { {0} };
int8_t *SGEHL[SNB];
#define LOGSECLOCAL 4
#define NSECLOCAL (1<<LOGSECLOCAL) //Number of second local histories
#define INDSLOCAL (((PC ^ (PC >>5))) & (NSECLOCAL-1))
long long S_slhist[NSECLOCAL];
//third local history
#define LOGTNB 10 // 2 * 512-entry tables
#define TNB 2
int Tm[TNB] = { 9, 4 };
int8_t TGEHLA[TNB][(1 << LOGTNB)] = { {0} };
int8_t *TGEHL[TNB];
#define NTLOCAL 16
#define INDTLOCAL (((PC ^ (PC >>(LOGTNB)))) & (NTLOCAL-1)) // different hash for the history
long long T_slhist[NTLOCAL];
// playing with putting more weights (x2) on some of the SC components
// playing on using different update thresholds on SC
//update threshold for the statistical corrector
#define VARTHRES
#define WIDTHRES 12
#define WIDTHRESP 8
#ifdef VARTHRES
#define LOGSIZEUP 6 //not worth increasing
#else
#define LOGSIZEUP 0
#endif
#define LOGSIZEUPS (LOGSIZEUP/2)
int updatethreshold;
int Pupdatethreshold[(1 << LOGSIZEUP)]; //size is fixed by LOGSIZEUP
#define INDUPD (PC ^ (PC >>2)) & ((1 << LOGSIZEUP) - 1)
#define INDUPDS ((PC ^ (PC >>2)) & ((1 << (LOGSIZEUPS)) - 1))
int8_t WG[(1 << LOGSIZEUPS)];
int8_t WL[(1 << LOGSIZEUPS)];
int8_t WS[(1 << LOGSIZEUPS)];
int8_t WT[(1 << LOGSIZEUPS)];
int8_t WP[(1 << LOGSIZEUPS)];
int8_t WI[(1 << LOGSIZEUPS)];
int8_t WIM[(1 << LOGSIZEUPS)];
int8_t WB[(1 << LOGSIZEUPS)];
#define EWIDTH 6
int LSUM;
// The two counters used to choose between TAGE and SC on Low Conf SC
int8_t FirstH, SecondH;
bool MedConf; // is the TAGE prediction medium confidence
#define CONFWIDTH 7 //for the counters in the choser
#define HISTBUFFERLENGTH 4096 // we use a 4K entries history buffer to store the branch history (this allows us to explore using history length up to 4K)
// utility class for index computation
// this is the cyclic shift register for folding
// a long global history into a smaller number of bits; see P. Michaud's PPM-like predictor at CBP-1
class folded_history
{
public:
unsigned comp;
int CLENGTH;
int OLENGTH;
int OUTPOINT;
folded_history ()
{
}
void init (int original_length, int compressed_length)
{
comp = 0;
OLENGTH = original_length;
CLENGTH = compressed_length;
OUTPOINT = OLENGTH % CLENGTH;
}
void update (uint8_t * h, int PT)
{
comp = (comp << 1) ^ h[PT & (HISTBUFFERLENGTH - 1)];
comp ^= h[(PT + OLENGTH) & (HISTBUFFERLENGTH - 1)] << OUTPOINT;
comp ^= (comp >> CLENGTH);
comp = (comp) & ((1 << CLENGTH) - 1);
}
};
class bentry // TAGE bimodal table entry
{
public:
int8_t hyst;
int8_t pred;
bentry ()
{
pred = 0;
hyst = 1;
}
};
class gentry // TAGE global table entry
{
public:
int8_t ctr;
uint tag;
int8_t u;
gentry ()
{
ctr = 0;
u = 0;
tag = 0;
}
};
#define POWER
//use geometric history length
#define NHIST 36 // twice the number of different histories
#define NBANKLOW 10 // number of banks in the shared bank-interleaved for the low history lengths
#define NBANKHIGH 20 // number of banks in the shared bank-interleaved for the history lengths
int SizeTable[NHIST + 1];
#define BORN 13 // below BORN in the table for low history lengths, >= BORN in the table for high history lengths,
// we use 2-way associativity for the medium history lengths
#define BORNINFASSOC 9 //2 -way assoc for those banks 0.4 %
#define BORNSUPASSOC 23
/*in practice 2 bits or 3 bits par branch: around 1200 cond. branchs*/
#define MINHIST 6 //not optimized so far
#define MAXHIST 3000
#define LOGG 10 /* logsize of the banks in the tagged TAGE tables */
#define TBITS 8 //minimum width of the tags (low history lengths), +4 for high history lengths
bool NOSKIP[NHIST + 1]; // to manage the associativity for different history lengths
bool LowConf;
bool HighConf;
#define NNN 1 // number of extra entries allocated on a TAGE misprediction (1+NNN)
#define HYSTSHIFT 2 // bimodal hysteresis shared by 4 entries
#define LOGB 13 // log of number of entries in bimodal predictor
#define PHISTWIDTH 27 // width of the path history used in TAGE
#define UWIDTH 1 // u counter width on TAGE (2 bits not worth the effort for a 512 Kbits predictor 0.2 %)
#define CWIDTH 3 // predictor counter width on the TAGE tagged tables
//the counter(s) to chose between longest match and alternate prediction on TAGE when weak counters
#define LOGSIZEUSEALT 4
bool AltConf; // Confidence on the alternate prediction
#define ALTWIDTH 5
#define SIZEUSEALT (1<<(LOGSIZEUSEALT))
#define INDUSEALT (((((HitBank-1)/8)<<1)+AltConf) % (SIZEUSEALT-1))
int8_t use_alt_on_na[SIZEUSEALT];
//very marginal benefit
long long GHIST;
int8_t BIM;
int TICK; // for the reset of the u counter
uint8_t ghist[HISTBUFFERLENGTH];
int ptghist;
long long phist; //path history
folded_history ch_i[NHIST + 1]; //utility for computing TAGE indices
folded_history ch_t[2][NHIST + 1]; //utility for computing TAGE tags
//For the TAGE predictor
bentry *btable; //bimodal TAGE table
gentry *gtable[NHIST + 1]; // tagged TAGE tables
int m[NHIST + 1];
int TB[NHIST + 1];
int logg[NHIST + 1];
int GI[NHIST + 1]; // indexes to the different tables are computed only once
uint GTAG[NHIST + 1]; // tags for the different tables are computed only once
int BI; // index of the bimodal table
bool pred_taken; // prediction
bool alttaken; // alternate TAGEprediction
bool tage_pred; // TAGE prediction
bool LongestMatchPred;
int HitBank; // longest matching bank
int AltBank; // alternate matching bank
int Seed; // for the pseudo-random number generator
bool pred_inter;
#ifdef LOOPPREDICTOR
//parameters of the loop predictor
#define LOGL 5
#define WIDTHNBITERLOOP 10 // we predict only loops with less than 1K iterations
#define LOOPTAG 10 //tag width in the loop predictor
class lentry //loop predictor entry
{
public:
uint16_t NbIter; //10 bits
uint8_t confid; // 4bits
uint16_t CurrentIter; // 10 bits
uint16_t TAG; // 10 bits
uint8_t age; // 4 bits
bool dir; // 1 bit
//39 bits per entry
lentry ()
{
confid = 0;
CurrentIter = 0;
NbIter = 0;
TAG = 0;
age = 0;
dir = false;
}
};
lentry *ltable; //loop predictor table
//variables for the loop predictor
bool predloop; // loop predictor prediction
int LIB;
int LI;
int LHIT; //hitting way in the loop predictor
int LTAG; //tag on the loop predictor
bool LVALID; // validity of the loop predictor prediction
int8_t WITHLOOP; // counter to monitor whether or not loop prediction is beneficial
#endif
int
predictorsize ()
{
int STORAGESIZE = 0;
int inter = 0;
STORAGESIZE +=
NBANKHIGH * (1 << (logg[BORN])) * (CWIDTH + UWIDTH + TB[BORN]);
STORAGESIZE += NBANKLOW * (1 << (logg[1])) * (CWIDTH + UWIDTH + TB[1]);
STORAGESIZE += (SIZEUSEALT) * ALTWIDTH;
STORAGESIZE += (1 << LOGB) + (1 << (LOGB - HYSTSHIFT));
STORAGESIZE += m[NHIST];
STORAGESIZE += PHISTWIDTH;
STORAGESIZE += 10; //the TICK counter
fprintf (stderr, " (TAGE %d) ", STORAGESIZE);
#ifdef SC
#ifdef LOOPPREDICTOR
inter = (1 << LOGL) * (2 * WIDTHNBITERLOOP + LOOPTAG + 4 + 4 + 1);
fprintf (stderr, " (LOOP %d) ", inter);
STORAGESIZE += inter;
#endif
inter += WIDTHRES;
inter = WIDTHRESP * ((1 << LOGSIZEUP)); //the update threshold counters
inter += 3 * EWIDTH * (1 << LOGSIZEUPS); // the extra weight of the partial sums
inter += (PERCWIDTH) * 3 * (1 << (LOGBIAS));
inter +=
(GNB - 2) * (1 << (LOGGNB)) * (PERCWIDTH) +
(1 << (LOGGNB - 1)) * (2 * PERCWIDTH);
inter += Gm[0]; //global histories for SC
inter += (PNB - 2) * (1 << (LOGPNB)) * (PERCWIDTH) +
(1 << (LOGPNB - 1)) * (2 * PERCWIDTH);
//we use phist already counted for these tables
#ifdef LOCALH
inter +=
(LNB - 2) * (1 << (LOGLNB)) * (PERCWIDTH) +
(1 << (LOGLNB - 1)) * (2 * PERCWIDTH);
inter += NLOCAL * Lm[0];
inter += EWIDTH * (1 << LOGSIZEUPS);
#ifdef LOCALS
inter +=
(SNB - 2) * (1 << (LOGSNB)) * (PERCWIDTH) +
(1 << (LOGSNB - 1)) * (2 * PERCWIDTH);
inter += NSECLOCAL * (Sm[0]);
inter += EWIDTH * (1 << LOGSIZEUPS);
#endif
#ifdef LOCALT
inter +=
(TNB - 2) * (1 << (LOGTNB)) * (PERCWIDTH) +
(1 << (LOGTNB - 1)) * (2 * PERCWIDTH);
inter += NTLOCAL * Tm[0];
inter += EWIDTH * (1 << LOGSIZEUPS);
#endif
#endif
#ifdef IMLI
inter += (1 << (LOGINB - 1)) * PERCWIDTH;
inter += Im[0];
inter += IMNB * (1 << (LOGIMNB - 1)) * PERCWIDTH;
inter += 2 * EWIDTH * (1 << LOGSIZEUPS); // the extra weight of the partial sums
inter += 256 * IMm[0];
#endif
inter += 2 * CONFWIDTH; //the 2 counters in the choser
STORAGESIZE += inter;
fprintf (stderr, " (SC %d) ", inter);
#endif
#ifdef PRINTSIZE
fprintf (stderr, " (TOTAL %d bits %d Kbits)\n", STORAGESIZE,
STORAGESIZE / 1024);
#endif
return (STORAGESIZE);
}
class PREDICTOR
{
public:
int THRES;
PREDICTOR (void)
{
reinit ();
#ifdef PRINTSIZE
predictorsize ();
#endif
}
void reinit ()
{
m[1] = MINHIST;
m[NHIST / 2] = MAXHIST;
for (int i = 2; i <= NHIST / 2; i++)
{
m[i] =
(int) (((double) MINHIST *
pow ((double) (MAXHIST) / (double) MINHIST,
(double) (i - 1) / (double) (((NHIST / 2) - 1)))) +
0.5);
// fprintf(stderr, "(%d %d)", m[i],i);
}
for (int i = 1; i <= NHIST; i++)
{
NOSKIP[i] = ((i - 1) & 1)
|| ((i >= BORNINFASSOC) & (i < BORNSUPASSOC));
}
NOSKIP[4] = 0;
NOSKIP[NHIST - 2] = 0;
NOSKIP[8] = 0;
NOSKIP[NHIST - 6] = 0;
// just eliminate some extra tables (very very marginal)
for (int i = NHIST; i > 1; i--)
{
m[i] = m[(i + 1) / 2];
}
for (int i = 1; i <= NHIST; i++)
{
TB[i] = TBITS + 4 * (i >= BORN);
logg[i] = LOGG;
}
#ifdef LOOPPREDICTOR
ltable = new lentry[1 << (LOGL)];
#endif
gtable[1] = new gentry[NBANKLOW * (1 << LOGG)];
SizeTable[1] = NBANKLOW * (1 << LOGG);
gtable[BORN] = new gentry[NBANKHIGH * (1 << LOGG)];
SizeTable[BORN] = NBANKHIGH * (1 << LOGG);
for (int i = BORN + 1; i <= NHIST; i++)
gtable[i] = gtable[BORN];
for (int i = 2; i <= BORN - 1; i++)
gtable[i] = gtable[1];
btable = new bentry[1 << LOGB];
for (int i = 1; i <= NHIST; i++)
{
ch_i[i].init (m[i], (logg[i]));
ch_t[0][i].init (ch_i[i].OLENGTH, TB[i]);
ch_t[1][i].init (ch_i[i].OLENGTH, TB[i] - 1);
}
#ifdef LOOPPREDICTOR
LVALID = false;
WITHLOOP = -1;
#endif
Seed = 0;
TICK = 0;
phist = 0;
Seed = 0;
for (int i = 0; i < HISTBUFFERLENGTH; i++)
ghist[0] = 0;
ptghist = 0;
updatethreshold=35<<3;
for (int i = 0; i < (1 << LOGSIZEUP); i++)
Pupdatethreshold[i] = 0;
for (int i = 0; i < GNB; i++)
GGEHL[i] = &GGEHLA[i][0];
for (int i = 0; i < LNB; i++)
LGEHL[i] = &LGEHLA[i][0];
for (int i = 0; i < GNB; i++)
for (int j = 0; j < ((1 << LOGGNB) - 1); j++)
{
if (!(j & 1))
{
GGEHL[i][j] = -1;
}
}
for (int i = 0; i < LNB; i++)
for (int j = 0; j < ((1 << LOGLNB) - 1); j++)
{
if (!(j & 1))
{
LGEHL[i][j] = -1;
}
}
for (int i = 0; i < SNB; i++)
SGEHL[i] = &SGEHLA[i][0];
for (int i = 0; i < TNB; i++)
TGEHL[i] = &TGEHLA[i][0];
for (int i = 0; i < PNB; i++)
PGEHL[i] = &PGEHLA[i][0];
#ifdef IMLI
#ifdef IMLIOH
for (int i = 0; i < FNB; i++)
FGEHL[i] = &FGEHLA[i][0];
for (int i = 0; i < FNB; i++)
for (int j = 0; j < ((1 << LOGFNB) - 1); j++)
{
if (!(j & 1))
{
FGEHL[i][j] = -1;
}
}
#endif
for (int i = 0; i < INB; i++)
IGEHL[i] = &IGEHLA[i][0];
for (int i = 0; i < INB; i++)
for (int j = 0; j < ((1 << LOGINB) - 1); j++)
{
if (!(j & 1))
{
IGEHL[i][j] = -1;
}
}
for (int i = 0; i < IMNB; i++)
IMGEHL[i] = &IMGEHLA[i][0];
for (int i = 0; i < IMNB; i++)
for (int j = 0; j < ((1 << LOGIMNB) - 1); j++)
{
if (!(j & 1))
{
IMGEHL[i][j] = -1;
}
}
#endif
for (int i = 0; i < SNB; i++)
for (int j = 0; j < ((1 << LOGSNB) - 1); j++)
{
if (!(j & 1))
{
SGEHL[i][j] = -1;
}
}
for (int i = 0; i < TNB; i++)
for (int j = 0; j < ((1 << LOGTNB) - 1); j++)
{
if (!(j & 1))
{
TGEHL[i][j] = -1;
}
}
for (int i = 0; i < PNB; i++)
for (int j = 0; j < ((1 << LOGPNB) - 1); j++)
{
if (!(j & 1))
{
PGEHL[i][j] = -1;
}
}
for (int i = 0; i < (1 << LOGB); i++)
{
btable[i].pred = 0;
btable[i].hyst = 1;
}
for (int j = 0; j < (1 << LOGBIAS); j++)
{
switch (j & 3)
{
case 0:
BiasSK[j] = -8;
break;
case 1:
BiasSK[j] = 7;
break;
case 2:
BiasSK[j] = -32;
break;
case 3:
BiasSK[j] = 31;
break;
}
}
for (int j = 0; j < (1 << LOGBIAS); j++)
{
switch (j & 3)
{
case 0:
Bias[j] = -32;
break;
case 1:
Bias[j] = 31;
break;
case 2:
Bias[j] = -1;
break;
case 3:
Bias[j] = 0;
break;
}
}
for (int j = 0; j < (1 << LOGBIAS); j++)
{
switch (j & 3)
{
case 0:
BiasBank[j] = -32;
break;
case 1:
BiasBank[j] = 31;
break;
case 2:
BiasBank[j] = -1;
break;
case 3:
BiasBank[j] = 0;
break;
}
}
for (int i = 0; i < SIZEUSEALT; i++)
{
use_alt_on_na[i] = 0;
}
for (int i = 0; i < (1 << LOGSIZEUPS); i++)
{
WG[i] = 7;
WL[i] = 7;
WS[i] = 7;
WT[i] = 7;
WP[i] = 7;
WI[i] = 7;
WB[i] = 4;
}
TICK = 0;
for (int i = 0; i < NLOCAL; i++)
{
L_shist[i] = 0;
}
for (int i = 0; i < NSECLOCAL; i++)
{
S_slhist[i] = 0;
}
GHIST = 0;
ptghist = 0;
phist = 0;
}
// index function for the bimodal table
int bindex (uint64_t PC)
{
return ((PC ^ (PC >> LOGB)) & ((1 << (LOGB)) - 1));
}
// the index functions for the tagged tables uses path history as in the OGEHL predictor
//F serves to mix path history: not very important impact
int F (long long A, int size, int bank)
{
int A1, A2;
A = A & ((1 << size) - 1);
A1 = (A & ((1 << logg[bank]) - 1));
A2 = (A >> logg[bank]);
if (bank < logg[bank])
A2 =
((A2 << bank) & ((1 << logg[bank]) - 1)) +
(A2 >> (logg[bank] - bank));
A = A1 ^ A2;
if (bank < logg[bank])
A =
((A << bank) & ((1 << logg[bank]) - 1)) + (A >> (logg[bank] - bank));
return (A);
}
// gindex computes a full hash of PC, ghist and phist
int gindex (unsigned int PC, int bank, long long hist,
folded_history * ch_i)
{
int index;
int M = (m[bank] > PHISTWIDTH) ? PHISTWIDTH : m[bank];
index =
PC ^ (PC >> (abs (logg[bank] - bank) + 1))
^ ch_i[bank].comp ^ F (hist, M, bank);
return (index & ((1 << (logg[bank])) - 1));
}
// tag computation
uint16_t gtag (unsigned int PC, int bank, folded_history * ch0,
folded_history * ch1)
{
int tag = (PC) ^ ch0[bank].comp ^ (ch1[bank].comp << 1);
return (tag & ((1 << (TB[bank])) - 1));
}
// up-down saturating counter
void ctrupdate (int8_t & ctr, bool taken, int nbits)
{
if (taken)
{
if (ctr < ((1 << (nbits - 1)) - 1))
ctr++;
}
else
{
if (ctr > -(1 << (nbits - 1)))
ctr--;
}
}
bool getbim ()
{
BIM = (btable[BI].pred << 1) + (btable[BI >> HYSTSHIFT].hyst);
HighConf = (BIM == 0) || (BIM == 3);
LowConf = !HighConf;
AltConf = HighConf;
MedConf = false;
return (btable[BI].pred > 0);
}
void baseupdate (bool Taken)
{
int inter = BIM;
if (Taken)
{
if (inter < 3)
inter += 1;
}
else if (inter > 0)
inter--;
btable[BI].pred = inter >> 1;
btable[BI >> HYSTSHIFT].hyst = (inter & 1);
};
//just a simple pseudo random number generator: use available information
// to allocate entries in the loop predictor
int MYRANDOM ()
{
Seed++;
Seed ^= phist;
Seed = (Seed >> 21) + (Seed << 11);
Seed ^= ptghist;
Seed = (Seed >> 10) + (Seed << 22);
return (Seed);
};
// TAGE PREDICTION: same code at fetch or retire time but the index and tags must recomputed
void Tagepred (uint64_t PC)
{
HitBank = 0;
AltBank = 0;
for (int i = 1; i <= NHIST; i += 2)
{
GI[i] = gindex (PC, i, phist, ch_i);
GTAG[i] = gtag (PC, i, ch_t[0], ch_t[1]);
GTAG[i + 1] = GTAG[i];
GI[i + 1] = GI[i] ^ (GTAG[i] & ((1 << LOGG) - 1));
}
int T = (PC ^ (phist & ((1 << m[BORN]) - 1))) % NBANKHIGH;
//int T = (PC ^ phist) % NBANKHIGH;
for (int i = BORN; i <= NHIST; i++)
if (NOSKIP[i])
{
GI[i] += (T << LOGG);
T++;
T = T % NBANKHIGH;
}
T = (PC ^ (phist & ((1 << m[1]) - 1))) % NBANKLOW;
for (int i = 1; i <= BORN - 1; i++)
if (NOSKIP[i])
{
GI[i] += (T << LOGG);
T++;
T = T % NBANKLOW;
}
//just do not forget most address are aligned on 4 bytes
BI = (PC ^ (PC >> 2)) & ((1 << LOGB) - 1);
{
alttaken = getbim ();
tage_pred = alttaken;
LongestMatchPred = alttaken;
}
//Look for the bank with longest matching history
for (int i = NHIST; i > 0; i--)
{
if (NOSKIP[i])
if (gtable[i][GI[i]].tag == GTAG[i])
{
HitBank = i;
LongestMatchPred = (gtable[HitBank][GI[HitBank]].ctr >= 0);
break;
}
}
//Look for the alternate bank
for (int i = HitBank - 1; i > 0; i--)
{
if (NOSKIP[i])
if (gtable[i][GI[i]].tag == GTAG[i])
{
AltBank = i;
break;
}
}
//computes the prediction and the alternate prediction
if (HitBank > 0)
{
if (AltBank > 0)
{
alttaken = (gtable[AltBank][GI[AltBank]].ctr >= 0);
AltConf = (abs (2 * gtable[AltBank][GI[AltBank]].ctr + 1) > 1);
}
else
alttaken = getbim ();
//if the entry is recognized as a newly allocated entry and
//USE_ALT_ON_NA is positive use the alternate prediction
bool Huse_alt_on_na = (use_alt_on_na[INDUSEALT] >= 0);
if ((!Huse_alt_on_na)
|| (abs (2 * gtable[HitBank][GI[HitBank]].ctr + 1) > 1))
tage_pred = LongestMatchPred;
else
tage_pred = alttaken;
HighConf =
(abs (2 * gtable[HitBank][GI[HitBank]].ctr + 1) >=
(1 << CWIDTH) - 1);
LowConf = (abs (2 * gtable[HitBank][GI[HitBank]].ctr + 1) == 1);
MedConf = (abs (2 * gtable[HitBank][GI[HitBank]].ctr + 1) == 5);
}
}
//compute the prediction
bool GetPrediction (uint64_t PC)
{