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:

    When the manipulations of childhood are a little larceny, they may grow and change with the child into qualities useful and admire in the grown-up world. When they are the futile struggle for love and concern and protection, they may become the warped and ruthless machinations of adults who seek in the advantages of power what they could never win as children.
    Leontine Young (20th century)

    There are great advantages to seeing yourself as an accident created by amateur parents as they practiced. You then have been left in an imperfect state and the rest is up to you. Only the most pitifully inept child requires perfection from parents.
    Frank Pittman (20th century)

    [T]here is no Part of the World where Servants have those Privileges and Advantages as in England: They have no where else such plentiful Diet, large Wages, or indulgent Liberty: There is no place wherein they labour less, and yet where they are so little respectful, more wasteful, more negligent, or where they so frequently change their Masters.
    Richard Steele (1672–1729)