From 9a9d403acee72d36d17988ae5a6ce9ede8051f11 Mon Sep 17 00:00:00 2001 From: Tulio Magno Quites Machado Filho Date: Thu, 8 Sep 2011 22:37:11 -0700 Subject: [PATCH] Optimize caa_get_cycles() for PowerPC64 Make caa_get_cycles() read from the Time Base register with only 1 instruction. [ Edit by Mathieu Desnoyers: coding style update ] Signed-off-by: Mathieu Desnoyers Signed-off-by: Tulio Magno Quites Machado Filho --- urcu/arch/ppc.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/urcu/arch/ppc.h b/urcu/arch/ppc.h index d7317bb..a03d688 100644 --- a/urcu/arch/ppc.h +++ b/urcu/arch/ppc.h @@ -48,11 +48,24 @@ extern "C" { rval; \ }) +#define mftb() \ + ({ \ + unsigned long long rval; \ + asm volatile("mftb %0" : "=r" (rval)); \ + rval; \ + }) + typedef unsigned long long cycles_t; -static inline cycles_t caa_get_cycles (void) +#ifdef __powerpc64__ +static inline cycles_t caa_get_cycles(void) { - long h, l; + return (cycles_t) mftb(); +} +#else +static inline cycles_t caa_get_cycles(void) +{ + unsigned long h, l; for (;;) { h = mftbu(); @@ -63,6 +76,7 @@ static inline cycles_t caa_get_cycles (void) return (((cycles_t) h) << 32) + l; } } +#endif #ifdef __cplusplus } -- 2.34.1