If a loop is unrolled by N, duplicating the body N times and reducing the trip-count by a factor of N, you may need 0 to N-1 "final iterations" after the loop - the non-zero cases occurring if your original trip-count wasn't a multiple of N.
What are these final iterations called?
As an example, the following loop:
int sum = 0;
for (int i = 0; i < max; i++) {
sum += i;
}
Can be unrolled by a factor of 4 as follows:
int sum = 0;
for (int i = 0; i + 3 < max; i += 4) {
sum += i;
sum += i + 1;
sum += i + 2;
sum += i + 3;
}
// "final iterations" handling here
... and of the author will probably simplify the entire body to something like sum += i *4 + 6
1. You also need some "final iterations" handling which could be about as simple as the original loop:
// handle the final 0 to 3 iterations
for (; i < max; i++) {
sum += i;
}
1 Indeed the compiler will probably do an even better job of simplifying even the original loop, often removing it completely and calculating the final result directly via multiplication based on a sum formula. This is only an example, after all.