Skip to content

Commit

Permalink
Add support for PPC architecture, provide fallback
Browse files Browse the repository at this point in the history
Add high precision cpu cycles support for powerpc and powerpc64.

Provide a fallback for other architectures and warn during
compilation.

Signed-off-by: James Page <[email protected]>
  • Loading branch information
javacruft committed Mar 13, 2015
1 parent e3bbe4e commit b2781fb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common/Cycles.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ class Cycles {
uint64_t cntvct;
asm volatile ("isb; mrs %0, cntvct_el0; isb; " : "=r" (cntvct) :: "memory");
return cntvct;
#elif defined(__powerpc__) || defined (__powerpc64__)
// Based on:
// https://github.com/randombit/botan/blob/net.randombit.botan/src/lib/entropy/hres_timer/hres_timer.cpp
uint32_t lo = 0, hi = 0;
asm volatile("mftbu %0; mftb %1" : "=r" (hi), "=r" (lo));
return (((uint64_t)hi << 32) | lo);
#else
#error No high-precision counter available for your OS/arch
#warning No high-precision counter available for your OS/arch
return 0;
#endif
}

Expand Down

0 comments on commit b2781fb

Please sign in to comment.