SniperのGshareモデルを探すと既に存在していた。
PHTを参照するためのインデックスの作り方は、こんな感じになっている。
GsharePredictor::DualSaturatingPredictor GsharePredictor::getPHTEntry(IntPtr ip) { return this->pht[(this->bhr & this->mask) ^ (ip & this->mask)]; }
単純にPCとBHRをXORする実装になっている。なるほど。
PredictionとUpdateはこんな感じ。 update() は bhr < 1 ではなく bhr << 1 ではないかな?
bool GsharePredictor::predict(bool indirect, IntPtr ip, IntPtr target) { GsharePredictor::DualSaturatingPredictor predictor = this->getPHTEntry(ip); return predictor.predict(); } void GsharePredictor::update(bool predicted, bool actual, bool indirect, IntPtr ip, IntPtr target) { updateCounters(predicted, actual); GsharePredictor::DualSaturatingPredictor predictor = this->getPHTEntry(ip); predictor.update(actual); this->bhr = (this->bhr < 1) | actual; }
実際に実行してみて、性能を測定してみよう。