00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "btb.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 void BTB::predict(int ip,int slot,bool &find_btb,int &target)
00033 {
00034
00035
00036 int index=ip>>_b;
00037 index=index&_index_mask;
00038
00039 int start_index=index*_num_of_entry_per_set;
00040
00041
00042
00043 int this_index;
00044 int i;
00045 for(i=0;i<_num_of_entry_per_set;i++)
00046 {
00047 this_index=start_index+i;
00048
00049
00050 if(_tag[this_index]==ip && _slot[this_index]==slot)
00051 {
00052 break;
00053 }
00054 }
00055
00056 if(i==_num_of_entry_per_set)
00057 {
00058 find_btb=false;
00059
00060
00061 return;
00062 }
00063 else
00064 {
00065 find_btb=true;
00066 target=_target[this_index];
00067
00068
00069 return;
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080 void BTB::update(int ip,int slot,int target,int global_cycle)
00081 {
00082
00083
00084 int index=ip>>_b;
00085 index=index&_index_mask;
00086
00087 int start_index=index*_num_of_entry_per_set;
00088
00089
00090
00091
00092 int this_index = 0;
00093 int i;
00094 int oldest_time=_time[start_index];
00095 int oldest_entry=start_index;
00096 int empty_entry=-1;
00097
00098 for(i=0;i<_num_of_entry_per_set;i++)
00099 {
00100 this_index=start_index+i;
00101
00102 int this_tag=_tag[this_index];
00103 int this_slot=_slot[this_index];
00104
00105 if(this_tag==ip && this_slot==slot)
00106 {
00107 break;
00108 }
00109
00110
00111 if(empty_entry==-1 && this_tag==-1)
00112 {
00113 empty_entry=this_index;
00114 }
00115
00116
00117 int this_time=_time[this_index];
00118 if(this_time<oldest_time)
00119 {
00120 oldest_time=this_time;
00121 oldest_entry=this_index;
00122 }
00123 }
00124
00125 if(i==_num_of_entry_per_set)
00126 {
00127
00128
00129 if(empty_entry==-1)
00130 {
00131 _time[oldest_entry]=global_cycle;
00132 _tag[oldest_entry]=ip;
00133 _slot[oldest_entry]=slot;
00134 _target[oldest_entry]=target;
00135
00136
00137 }
00138 else
00139 {
00140 _time[empty_entry]=global_cycle;
00141 _tag[empty_entry]=ip;
00142 _slot[empty_entry]=slot;
00143 _target[empty_entry]=target;
00144
00145
00146 }
00147 }
00148 else
00149 {
00150
00151 _time[this_index]=global_cycle;
00152
00153 if(_target[this_index]!=target)
00154 {
00155
00156 _target[this_index]=target;
00157 }
00158 }
00159 }