While much of the time, the entity that performs the loop-unrolling will be an optimizing compiler, you the programmer can also do the task in your high-level language. Taking the loop
You can quickly and simply halve the number of iterations by changing it to this, instead:
Note, however, that with a stupid compiler (one that does not optimize well), the second fragment may be worse than the first, because of the extra addtions needed in each loop (i+1). In theory, both loops would be unrolled and rescheduled by the compiler to exactly the same assembly code. Be aware of outsmarting the compiler's optimizing techniques; the folk who write compilers today are very good at what they do.
Prev | Next |