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.



Regards,

--
Walter Banks
Byte Craft Limited
Tel. (519) 888-6911
http://www.bytecraft.com
walter@xxxxxxxxxxxxx




.



Relevant Pages

  • Re: Self Modifying Code in C
    ... runtime unrolling of the loop. ... Do compilers already do this? ...
    (alt.lang.asm)
  • 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 ...
    (comp.lang.fortran)
  • 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. ...
    (comp.lang.fortran)
  • 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; ...
    (alt.lang.asm)
  • Re: Likely/Unlikely and standards
    ... Some will say this subject should be left entirely to forums dedicated to particular compilers or platforms, but there are a few generalizations. ... Default optimization for conditional branch not taken is a de facto standard. ... There should be no performance penalty for the use of a break, except that it is preferable to use an ifblock rather than break, in the case where the last part of a loop body is to be skipped on the last loop iteration. ... I have waged a several year campaign against compilers requiring break to be placed in an else block to enable optimization. ...
    (comp.lang.c)