Loop Unwinding - Advantages

Advantages

The overhead in "tight" loops often consists of instructions to increment a pointer or index to the next element in an array (pointer arithmetic), as well as "end of loop" tests. If an optimizing compiler or assembler is able to pre-calculate offsets to each individually referenced array variable, these can be built into the machine code instructions directly, therefore requiring no additional arithmetic operations at run time (note that in the example given below this is not the case).

  • Significant gains can be realized if the reduction in executed instructions more than compensates for any performance reduction caused by any increase in the size of the program.
  • branch penalty is minimised.
  • If the statements in the loop are independent of each other (i.e. where statements that occur earlier in the loop do not affect statements that follow them), the statements can potentially be executed in parallel.
  • Can be implemented dynamically if the number of array elements is unknown at compile time

Optimizing compilers will sometimes perform the unrolling automatically or upon request.

Read more about this topic:  Loop Unwinding

Famous quotes containing the word advantages:

    If we live in the Nineteenth Century, why should we not enjoy the advantages which the Nineteenth Century offers? Why should our life be in any respect provincial?
    Henry David Thoreau (1817–1862)

    If we help an educated man’s daughter to go to Cambridge are we not forcing her to think not about education but about war?—not how she can learn, but how she can fight in order that she might win the same advantages as her brothers?
    Virginia Woolf (1882–1941)

    For, the advantages which fashion values, are plants which thrive in very confined localities, in a few streets, namely. Out of this precinct, they go for nothing; are of no use in the farm, in the forest, in the market, in war, in the nuptial society, in the literary or scientific circle, at sea, in friendship, in the heaven of thought or virtue.
    Ralph Waldo Emerson (1803–1882)