On Wed, 29 Aug 2012, Segher Boessenkool wrote:
> > +++ b/gcc/testsuite/gcc.target/powerpc/ppc-get-timebase.c
> > @@ -0,0 +1,22 @@
> > +/* { dg-do run { target { powerpc*-*-* } } } */
> > +
> > +/* Test if __builtin_ppc_get_timebase() is compatible with the current
> > + processor and if it's changing between reads. A read failure might
> > indicate
> > + a Power ISA or binutils change. */
> > +
> > +#include <inttypes.h>
> > +
> > +int
> > +main(void)
> > +{
> > + uint64_t t1, t2, t3;
> > +
> > + t1 = __builtin_ppc_get_timebase ();
> > + t2 = __builtin_ppc_get_timebase ();
> > + t3 = __builtin_ppc_get_timebase ();
> > +
> > + if (t1 != t2 && t1 != t3 && t2 != t3)
> > + return 0;
> > +
> > + return 1;
> > +}
>
> On some systems the timebase runs at a rather low frequency, say 20MHz.
> This test will spuriously fail there. Waste a million CPU cycles before
> reading TB the second time?
Waste said million cycles portably by calling sched_yield()?
(Available only on POSIX systems. :)
brgds, H-P