Forum Discussion
Altera_Forum
Honored Contributor
19 years agoNios II dynamic branch prediction uses the classic gShare algorithm.
Check out this paper http://www.cs.ucsb.edu/~arch/cs254/papers/combining.pdf (http://www.cs.ucsb.edu/~arch/cs254/papers/combining.pdf) for more details on gShare. The branch history table is 256 entries (of 2 bits each). When the CPU feches a branch, it indexes into this table using the 8 LSB of the instruction address XORed with the 8 global branch history bits. This 2 bit entry specifies one of four states: strongly taken, weakly taken, weakly not taken, and strongly not taken. If the branch is either weakly or strongly predicted taken, the CPU predicts that the branch will be taken and fetches the target of the branch. If the prediciton is wrong, it takes four cycles to recover. Static prediction just assumes all backwards branches are taken and all forward branches are not taken. This takes advantage of the branches at the end of loops which tend to be taken and tend to be backwards.