I became curious how Coremark performance changes with different branch prediction implementations when measured on a cycle-accurate simulator, so I decided to try it.
I will use Sniper as the cycle-accurate simulator. Sniper has front-end branch predictor implementations, and they can be switched through the configuration.
The PentiumM model consists of the following components.
sniper/common/performance_model/branch_predictors/pentium_m_branch_predictor.h
PentiumMGlobalPredictor m_global_predictor; PentiumMBranchTargetBuffer m_btb; PentiumMBimodalTable m_bimodal_table; PentiumMLoopBranchPredictor m_lpb; PentiumMIndirectBranchTargetBuffer ibtb;
PentiumMGlobalPredictor
I think this is the global branch history.
sniper/common/performance_model/branch_predictors/pentium_m_global_predictor.h
public:
// The Pentium M Global Branch Predictor
// 512-entries
// 6 tag bits per entry
// 4-way set associative
PentiumMGlobalPredictor()
: GlobalPredictor(2048, 6, 4)
{}
};
Let's see what this GlobalPredictor does.
sniper/common/performance_model/branch_predictors/global_predictor.h
class GlobalPredictor : BranchPredictor { /* ... omitted ... */ bool predict(bool indirect, IntPtr ip, IntPtr target, IntPtr pir) { UInt32 index, tag; gen_index_tag(ip, pir, index, tag);
I think gen_index_tag() is what creates the index for the global branch prediction... and pir seems to be the branch history.
sniper/common/performance_model/branch_predictors/global_predictor.h
// Pentium M-specific indexing and tag values void gen_index_tag(IntPtr ip, IntPtr pir, UInt32& index, UInt32 &tag) { index = ((ip >> 4) ^ (pir >> 6)) & 0x1FF; tag = ((ip >> 13) ^ pir) & 0x3F; }
sniper/common/performance_model/branch_predictors/pentium_m_branch_predictor.cc
void PentiumMBranchPredictor::update_pir(bool actual, IntPtr ip, IntPtr target, BranchPredictorReturnValue::BranchType branch_type) { IntPtr rhs; if ((branch_type == BranchPredictorReturnValue::ConditionalBranch) & actual) { rhs = ip >> 4; } else if (branch_type == BranchPredictorReturnValue::IndirectBranch) { rhs = (ip >> 4) | target; } else { // No PIR update return; } m_pir = ((m_pir << 2) ^ rhs) & 0x7fff; }
For a BranchPredictorReturnValue::ConditionalBranch, if the branch is taken, the PC is shifted by 4 bits (is this based on the assumption that the lower 4 bits are within the same cache line?). The hash function is built by XORing this with the PIR shifted left by 2 bits. Roughly speaking, I think it looks like the following. Isn't this just a simple branch history?
{pir, 2'b00} ^ ip[19: 4]
Looking around, PIR apparently stands for Path Based Indirect predictor Register. So the hash function is built from the paths executed so far (that is, the IPs), and that is used to create the index for prediction?
This is an English translation of the original Japanese post: Sniperを使った各種分岐予測器の動作確認 (3. 分岐予測器のモデルを調査)