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
constants.

> 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.

Reply via email to