From 7897d6d886900521c0264353604bcad10ee350de Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Tue, 19 Aug 2014 14:29:57 +0200 Subject: [PATCH] Add cycle counters for 64-bit ARM The gcc code has been tested on actual ARM64 hardware, but the MSVC one is only implemented from the MSVC manual. Change-Id: I13aac4d65345c684b6ddc5812ca9c3fcbe27b81a --- src/gromacs/timing/cyclecounter.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/gromacs/timing/cyclecounter.h b/src/gromacs/timing/cyclecounter.h index 87d19b19a1..7751db4390 100644 --- a/src/gromacs/timing/cyclecounter.h +++ b/src/gromacs/timing/cyclecounter.h @@ -79,6 +79,11 @@ extern "C" typedef unsigned long long gmx_cycles_t; +#elif ((defined __aarch64__) && (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__PATHSCALE__) || defined(__PGIC__))) +/* 64-bit ARM cycle counters with GCC inline assembly */ +typedef unsigned long long + gmx_cycles_t; + #elif defined(_MSC_VER) #include typedef __int64 @@ -210,6 +215,12 @@ static __inline__ int gmx_cycles_have_counter(void) /* x86 or x86-64 with GCC inline assembly - pentium TSC register */ return 1; } +#elif ((defined __aarch64__) && (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__PATHSCALE__) || defined(__PGIC__))) +static __inline int gmx_cycles_have_counter(void) +{ + /* 64-bit ARM cycle counters with GCC inline assembly */ + return 1; +} #elif (defined(_MSC_VER)) static __inline int gmx_cycles_have_counter(void) { @@ -350,14 +361,30 @@ static __inline__ gmx_cycles_t gmx_cycles_read(void) return cycle; } +#elif ((defined __aarch64__) && (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__PATHSCALE__) || defined(__PGIC__))) +static __inline__ gmx_cycles_t gmx_cycles_read(void) +{ + /* 64-bit ARM cycle counters with GCC inline assembly */ + gmx_cycles_t cycle; + __asm__ __volatile__("mrs %0, cntvct_el0" : "=r" (cycle) ); + + return cycle; +} + #elif defined(_MSC_VER) static __inline gmx_cycles_t gmx_cycles_read(void) { -#ifdef HAVE_RDTSCP +#ifdef _M_ARM + /* Windows on 64-bit ARM */ + return __rdpmccntr64(); +#else + /* x86 */ +# ifdef HAVE_RDTSCP unsigned int ui; return __rdtscp(&ui); -#else +# else return __rdtsc(); +# endif #endif } #elif (defined(__hpux) || defined(__HP_cc)) && defined(__ia64) -- 2.22.0