dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Re: busy loop

Re: busy loop

From: Edgar Toernig <>
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
> linkage.

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 ;-)

Ciao, ET.
Received on 2010-06-15

Page was last modified "Jan 10 2012" The Rockbox Crew