Loop Unrolling

Loop unrolling is the compile-time expansion of a loop into repetitions of the code, with the loop index replaced by its value in each instance.

for i := 1 to 3 do x[i] := y[i];

is expanded into:

x[1] := y[1];
x[2] := y[2];
x[3] := y[3];

The second form may generate less code, and it runs faster. This is a useful optimization when the size of the loop is known to be a small constant at compile time.

Modulo unrolling unrolls a loop modulo some chosen constant. This can significantly reduce the loop overhead without expanding code size too much.

Contents    Page-10    Prev    Next    Page+10    Index