0

I am trying to understand the concepts of loop unrolling, and according to Wikipedia, it limits/minimizes branch penalty?

Now, I understand what loop unrolling is. It is basically increasing the loop increment step, and repeating the statements inside the loop.

However, I can't quite understand how will that help with branch penalty?

Max
  • 9,100
  • 25
  • 72
  • 109

1 Answers1

1

The branch penalty is applied per branch. If you iterate a loop 100 times, and the loop code is not unrolled, then you will pay the branch penalty 100 times. But if the loop is unrolled once (that is, two total copies of the code), you'll only pay the penalty 50 times.

aghast
  • 14,785
  • 3
  • 24
  • 56