To: djgpp AT delorie DOT com Subject: Re: Loop unrolling: What is it? Message-ID: <19970303.220414.8255.5.chambersb@juno.com> References: <5ffjqj$g5a AT nr1 DOT toronto DOT istar DOT net> From: chambersb AT juno DOT com (Benjamin D Chambers) Date: Tue, 04 Mar 1997 01:01:10 EST On 3 Mar 1997 22:37:07 GMT Jeff Weeks writes: >All this talk about unrolling loop and I feel like an idiot :) What >exactly is invovled in the process of unrolling loops? Say you have: for (i=0;i<4;i++) {a;} Then you would do: a; a; a; a; This has several advantages: Fewer branches; Fewer additions (i never gets incremented, important in loops under 20 cycles per iteration); Fewer compares (see above); I've been able to unroll loops 64 times and fit them into about 1k - however, more than 16 iterations usually doesn't help any more (the overhead from taking care of the ends (since it rarely is a multiple of 64 iterations) just slows it down too much). Don't bother unless you get down to nitty-gritty assembly optimizing, though. ...Chambers