Forum Discussion
Altera_Forum
Honored Contributor
16 years agoThe only text about the branch predictor is on page 5-10 (just below table 5-8) "Dynamic branch prediction is implemented using a 2-bit branch history table". This doesn't give very much information!
Code wise, we need to minimise the worst case code paths, not the most common code paths. Consider the following test (edited a little) which is in the longest code path. # define et(x) (__builtin_expect((x),1))
if (et(x->p == 17)
&& et(x->val - HI < LIM)
&& et((x->hi << 16 | x->lo) == cfg->v)
&& et((x->ver & 0xff) == VER)
&& et((x->flg & 0x3fff) == 0)) {
/* code to do something */
}
Each time through it is likely to take different exit. With static branch prediction there is at most 1 mispredicted branch, and that is never in the worst case path, all the other branches are 'fall through'. However the dynamic prediction could easily get all 5 wrong! (and there are 4 more conditionals before this one!). This all adds a significant cost to the code paths. Ideally I'd like to build the II/f cpu without the branch predictor.