-1

Consider


int t = 0;
for( int i = 0; i < 8; i++ )
{
  for( int j = 0; j < 8; j++ )
  {
     t = t + i*j;
  }
}

Ex: Create a branch history table in t = t + i*j if we assume branch taken in dynamic branch predictor with one bit predictor.

Now to me the anwser is quite simple because the target addres is always the same, since we always jump from the end of the loop to the updation, same with the branch address and the prediciton, because we always predict branch. So all the the branch history table entries remain constant which makes me sceptical wether my thinking is right.

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Iwan5050
  • 163
  • 6
  • CPUs run assembly, not C. But whether it compiles naively with a conditional branch at the top, or [like a real compiler with only a conditional branch at the bottom](https://stackoverflow.com/questions/47783926/why-are-loops-always-compiled-into-do-while-style-tail-jump) (after seeing that `j<8` is true for the first iteration), the loop branch has to jump the opposite way from usual to leave the loop, once per outer loop iteration. Assuming the compiler doesn't unroll the loop, of course, i.e. that this is pseudocode for asm. – Peter Cordes May 13 '22 at 13:38
  • What does "Create a branch history table in t = t + i*j" mean? That expression does not represent conditional or unconditional branching. – Erik Eidt May 13 '22 at 13:58
  • My guess was right. Indeed one has to apply a little fantasy that the code jumps from the end to to the updation and condition I should have posed the questoin more clearly – Iwan5050 May 13 '22 at 17:07

0 Answers0