delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/04/01:05:40

To: djgpp AT delorie DOT com
Subject: Re: Loop unrolling: What is it?
Message-ID: <19970303.220414.8255.5.chambersb@juno.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970303130541 DOT 9009A-100000 AT is>
<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 <pweeks AT execulink DOT com> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019