Re: Loop unrolling

Ian Collins wrote:

I assume that the loop must not exceed a particular size to avoid a
code size explosion. But are there any other heuristics?

They will be specific to the compiler and loops don't have to be
completely unrolled. For example a loop of 100 may be expanded to a
loop of 20 blocks of 5 repeats.

Some compilers provide a means for tuning loop unrolling as a
space/performance trade off.

We have looked at a lot of customer embedded system code related
to loop unrolling and eventually concluded that best thing that we
could do in our compilers was to compile the code as written.

Application code usually was very clear and almost always right
in their timing choice of straight line vs loop implementation. Rolling
up straight line code and unrolling loops more often than not
interfered with a conscience choice a developer made.


Walter Banks
Byte Craft Limited
Tel. (519) 888-6911


Relevant Pages

  • Re: Self Modifying Code in C
    ... runtime unrolling of the loop. ... Do compilers already do this? ...
  • Re: MATMUL slower than expected
    ... a couple of the compilers are faster running explicit loops than using MATMUL. ... double loop with dot_product: 11.52825 ...
  • Re: Duffs Device
    ... I'd disagree a little on the above assessment that even in C unless you were looking at a very low-level case similar to what Glen was talking about would the optimizer not likely make such improvements as were appropriate for the specific hardware platform/compiler implementation if one simply wrote the "straightahead" loop. ... If, of course, there's a lot of indirection and all inside, that could limit optimization but for the simple case don't think it would help much for most modern compilers. ...
  • Re: Self Modifying Code in C
    ... the main thing on my concern list is loop unrolling. ... >>it to a asm function that i would make, and then unrolling it... ... Or can compilers already do that? ... int inner, k; ...
  • Re: Learning Fortran
    ... Well, yes, I left out multiple cores and such other hardware but the point is that compilers will all generate essentially the same instruction set for a similar set of operations irregardless of the source code format. ... there was loop unrolling and automagic parallelization of DO loops to take advantage of the installed hardware. ...