|
Rockbox mail archiveSubject: Re: busy loopRe: 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 > 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. Received on 2010-06-15 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |