00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_BRANCH_H
00023 #define INCLUDED_BRANCH_H
00024
00025 #include <stdio.h>
00026 #include <assert.h>
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 class Branch_Predictor
00044 {
00045 public:
00046 Branch_Predictor():_tag(NULL),_counter(NULL) {}
00047
00048
00049
00050
00051
00052 Branch_Predictor(int b, int m,int s,int l):_b(b),_m(m),_num_of_slot(s+1),_l(l)
00053 {
00054 _num_of_entry=1<<_m;
00055
00056 _tag=new int[_num_of_entry];
00057 _counter=new int[_num_of_entry];
00058
00059 for(int i=0;i<_num_of_entry;i++)
00060 {
00061 _counter[i]=0;
00062 }
00063
00064 _low_bhr_mask=(1<<_l)-1;
00065
00066 _index_mask=(1<<_m)-1;
00067
00068 _num_of_slot_bits;
00069 int num_of_slot=_num_of_slot;
00070 for(;num_of_slot!=0;_num_of_slot_bits++)
00071 {
00072 num_of_slot=num_of_slot>>1;
00073 }
00074
00075 _strong_mask=1<<_num_of_slot_bits;
00076 _slot_mask=_strong_mask-1;
00077
00078
00079
00080 }
00081
00082 void show(FILE *f)
00083 {
00084 fprintf(f,"_b=%d\n",_b);
00085 fprintf(f,"_m=%d\n",_m);
00086 fprintf(f,"_num_of_entry=%d\n",_num_of_entry);
00087 fprintf(f,"_l=%d\n",_l);
00088 fprintf(f,"_low_bhr_mask=%d\n",_low_bhr_mask);
00089 fprintf(f,"_index_mask=%d\n",_index_mask);
00090 fprintf(f,"_num_of_slot=%d\n",_num_of_slot);
00091 fprintf(f,"_num_of_slot_bits=%d\n",_num_of_slot_bits);
00092 fprintf(f,"_strong_mask=%d\n",_strong_mask);
00093 fprintf(f,"_slot_mask=%d\n",_slot_mask);
00094 }
00095
00096 void predict(int bhr,int ip,int &direction);
00097 void update(int bhr,int ip,int actual_slot_taken);
00098
00099 ~Branch_Predictor()
00100 {
00101 delete []_tag;
00102 delete []_counter;
00103 }
00104
00105 private:
00106 int _b;
00107 int _m;
00108 int _l;
00109 int _num_of_entry;
00110 int *_tag;
00111 int *_counter;
00112 int _num_of_slot;
00113
00114 int _index_mask;
00115 int _low_bhr_mask;
00116
00117 int _num_of_slot_bits;
00118 int _strong_mask;
00119 int _slot_mask;
00120
00121
00122
00123
00124
00125
00126
00127 };
00128
00129 #endif // INCLUDED_BRANCH_H