add fallback rpcc implementation

- use on arm, arm64 and any new platform
- use faster integer math instead of double
- use similar scale as rdtsc so that timeouts work
This commit is contained in:
Grazvydas Ignotas 2015-08-16 17:27:25 +02:00
parent d3e2f0a1af
commit e12cf1123e
10 changed files with 36 additions and 20 deletions

View File

@ -410,7 +410,35 @@ typedef char env_var_t[MAX_PATH];
typedef char* env_var_t;
#define readenv(p, n) ((p)=getenv(n))
#endif
#if !defined(RPCC_DEFINED) && !defined(OS_WINDOWS)
#ifdef _POSIX_MONOTONIC_CLOCK
#if defined(__GNUC_PREREQ) && __GLIBC_PREREQ(2, 17) // don't require -lrt
#define USE_MONOTONIC
#elif defined(OS_ANDROID)
#define USE_MONOTONIC
#endif
#endif
/* use similar scale as x86 rdtsc for timeouts to work correctly */
static inline unsigned long long rpcc(void){
#ifdef USE_MONOTONIC
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (unsigned long long)ts.tv_sec * 1000000000ull + ts.tv_nsec;
#else
struct timeval tv;
gettimeofday(&tv,NULL);
return (unsigned long long)tv.tv_sec * 1000000000ull + tv.tv_usec * 1000;
#endif
}
#define RPCC_DEFINED
#define RPCC64BIT
#endif // !RPCC_DEFINED
#ifndef RPCC_DEFINED
#error "rpcc() implementation is missing for your platform"
#endif
#endif // !ASSEMBLER
#ifdef OS_LINUX
#include "common_linux.h"

View File

@ -89,6 +89,7 @@ static __inline unsigned int rpcc(void){
return r0;
}
#define RPCC_DEFINED
#define HALT ldq $0, 0($0)

View File

@ -72,16 +72,6 @@ static void __inline blas_lock(volatile BLASULONG *address){
}
static inline unsigned long long rpcc(void){
unsigned long long ret=0;
double v;
struct timeval tv;
gettimeofday(&tv,NULL);
v=(double) tv.tv_sec + (double) tv.tv_usec * 1e-6;
ret = (unsigned long long) ( v * 1000.0d );
return ret;
}
static inline int blas_quickdivide(blasint x, blasint y){
return x / y;
}

View File

@ -71,16 +71,6 @@ static void __inline blas_lock(volatile BLASULONG *address){
}
static inline unsigned long long rpcc(void){
unsigned long long ret=0;
double v;
struct timeval tv;
gettimeofday(&tv,NULL);
v=(double) tv.tv_sec + (double) tv.tv_usec * 1e-6;
ret = (unsigned long long) ( v * 1000.0d );
return ret;
}
static inline int blas_quickdivide(blasint x, blasint y){
return x / y;
}

View File

@ -75,6 +75,7 @@ static __inline unsigned long rpcc(void) {
__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(clocks));
return clocks;
}
#define RPCC_DEFINED
static __inline unsigned long stmxcsr(void){
@ -103,6 +104,7 @@ static __inline void blas_lock(volatile unsigned long *address){
static __inline unsigned int rpcc(void) {
return __getReg(_IA64_REG_AR_ITC);
}
#define RPCC_DEFINED
static __inline unsigned int stmxcsr(void) {
return __getReg(_IA64_REG_AR_FPSR);

View File

@ -118,6 +118,7 @@ static inline unsigned int rpcc(void){
#endif
return ret;
}
#define RPCC_DEFINED
#if defined(LOONGSON3A) || defined(LOONGSON3B)
#ifndef NO_AFFINITY

View File

@ -103,6 +103,7 @@ static inline unsigned long rpcc(void){
#endif
}
#define RPCC_DEFINED
#ifdef __64BIT__
#define RPCC64BIT

View File

@ -66,6 +66,7 @@ static __inline unsigned long rpcc(void){
return clocks;
};
#define RPCC_DEFINED
#ifdef __64BIT__
#define RPCC64BIT

View File

@ -73,6 +73,7 @@ static __inline unsigned long long rpcc(void){
return ((unsigned long long)a + ((unsigned long long)d << 32));
};
#define RPCC_DEFINED
static __inline unsigned long getstackaddr(void){
unsigned long addr;

View File

@ -82,6 +82,7 @@ static __inline BLASULONG rpcc(void){
return ((BLASULONG)a + ((BLASULONG)d << 32));
}
#define RPCC_DEFINED
#define RPCC64BIT