Rockbox mail archiveSubject: Re: busy loop
Re: busy loop
From: Edgar Toernig <froese_at_gmx.de>
Date: Tue, 15 Jun 2010 20:31:24 +0200
pouly amaury wrote:
> > > for (x = (unsigned)(FREQ>>22); x; x--)
> > > asm volatile("":::"memory");
> > But it will break with loop-unrolling (i.e. -O3). x times nothing
> > is nothing ;-) You *have* to use a nop-instruction.
> Tell me if I'm wrong but the compiler can hardly unroll a loop with a
> non-constant size.
Sure it can. Unroll u times, loop that n/u times, then the
unrolled loop n%u times. Both may be overlayed with computed
gotos, i.e. Duff's Device.
> As FREQ is a define for cpu_frequency which has external
Well, for me an all caps identifier is const ;-) But anyway,
with link-time-optimization external linkage does not hide
> rewriting it in assembly is cleary the safe way :)
Indeed! Trying to write busy loops in a compiled language is
fighting against decades of compiler optimization research ;-)
Received on 2010-06-15
Page was last modified "Sat May 23 08:12:40 2020" The Rockbox Crew