This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop unrolling
- To: egcs at cygnus dot com
- Subject: Re: Loop unrolling
- From: Stephen Williams <steve at icarus dot icarus dot com>
- Date: Wed, 03 Jun 1998 21:06:50 -0700
I think I'm the embedded programmer that started this thread. (Sorry:-)
branko.cibej@hermes.si said:
> If they want _accurate_ timing loops, they should, as Tim Hollebeek
> pointed out, use asm statements. Otherwise they can always use
> volatile loop variables.
If I want inaccurate timing loops (that is, at *least* some number of
iterations and excess is OK) I put a thread_yield() in the body.
If I want more accurate loops that really waits for a certain number of
bus cycle clocks, I will read a volatile variable in the body. For example,
if a device needs N PCI clocks to complete something, I can usually resort
to a PCI read N/2 times.
If wall-clock time is important, I use an interval timer or an assembly
coded nap function.
As one of the embedded programmers who read gcc.info and believed it, I would
be delighted to see egcs eliminate empty loops, always unroll short loops,
etc. It would even be OK to me if:
for (int idx = 0 ; idx < 4 ; idx += 1)
asm("");
were to go away, as long as I can change the body to "asm volatile ("")"
to prevent the loop vanishing, although I can even see that being changed
into:
asm volatile("");
asm volatile("");
asm volatile("");
asm volatile("");
(Yikes!)
This leaves:
for (volatile idx = 0 ; idx < 4 ; idx += 1)
;
as something that should continue to work as it does now. Heck, turning
that into:
idx = 0;
idx = 1;
idx = 2;
idx = 3;
would get the desired delay.
--
Steve Williams "The woods are lovely, dark and deep.
steve@icarus.com But I have promises to keep,
steve@picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."