Fix handling of __clock() builtin for "generic" targets.
This commit is contained in:
@@ -3704,6 +3704,7 @@ void CWriter::lowerIntrinsics(llvm::Function &F) {
|
|||||||
case llvm::Intrinsic::sadd_with_overflow:
|
case llvm::Intrinsic::sadd_with_overflow:
|
||||||
case llvm::Intrinsic::trap:
|
case llvm::Intrinsic::trap:
|
||||||
case llvm::Intrinsic::objectsize:
|
case llvm::Intrinsic::objectsize:
|
||||||
|
case llvm::Intrinsic::readcyclecounter:
|
||||||
// We directly implement these intrinsics
|
// We directly implement these intrinsics
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -4056,6 +4057,9 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID,
|
|||||||
return true;
|
return true;
|
||||||
case llvm::Intrinsic::objectsize:
|
case llvm::Intrinsic::objectsize:
|
||||||
return true;
|
return true;
|
||||||
|
case llvm::Intrinsic::readcyclecounter:
|
||||||
|
Out << "__clock()";
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1759,3 +1759,23 @@ static FORCEINLINE uint64_t __atomic_cmpxchg(uint64_t *p, uint64_t cmpval,
|
|||||||
return __sync_val_compare_and_swap(p, cmpval, newval);
|
return __sync_val_compare_and_swap(p, cmpval, newval);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !WIN32
|
||||||
|
|
||||||
|
|||||||
@@ -1827,3 +1827,23 @@ static FORCEINLINE uint64_t __atomic_cmpxchg(uint64_t *p, uint64_t cmpval,
|
|||||||
return __sync_val_compare_and_swap(p, cmpval, newval);
|
return __sync_val_compare_and_swap(p, cmpval, newval);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
#endif // WIN32
|
||||||
|
|
||||||
|
#undef FORCEINLINE
|
||||||
|
|||||||
@@ -1960,3 +1960,23 @@ static FORCEINLINE uint64_t __atomic_cmpxchg(uint64_t *p, uint64_t cmpval,
|
|||||||
return __sync_val_compare_and_swap(p, cmpval, newval);
|
return __sync_val_compare_and_swap(p, cmpval, newval);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef FORCEINLINE
|
||||||
|
|||||||
@@ -2121,9 +2121,24 @@ static FORCEINLINE uint64_t __atomic_cmpxchg(uint64_t *p, uint64_t cmpval,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
#endif // !WIN32
|
||||||
|
|
||||||
#undef FORCEINLINE
|
#undef FORCEINLINE
|
||||||
#undef PRE_ALIGN
|
#undef PRE_ALIGN
|
||||||
#undef POST_ALIGN
|
#undef POST_ALIGN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2055,7 +2055,24 @@ static FORCEINLINE void __aos_to_soa4_float(float *ptr, __vec32_f *out0, __vec32
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
#endif // !WIN32
|
||||||
|
|
||||||
#undef FORCEINLINE
|
#undef FORCEINLINE
|
||||||
#undef PRE_ALIGN
|
#undef PRE_ALIGN
|
||||||
#undef POST_ALIGN
|
#undef POST_ALIGN
|
||||||
|
|
||||||
|
|||||||
@@ -4000,6 +4000,22 @@ static FORCEINLINE uint64_t __atomic_cmpxchg(uint64_t *p, uint64_t cmpval,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define __clock __rdtsc
|
||||||
|
#else // WIN32
|
||||||
|
static FORCEINLINE uint64_t __clock() {
|
||||||
|
uint32_t low, high;
|
||||||
|
#ifdef __x86_64
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%rax", "%rbx", "%rcx", "%rdx" );
|
||||||
|
#else
|
||||||
|
__asm__ __volatile__ ("xorl %%eax,%%eax \n cpuid"
|
||||||
|
::: "%eax", "%ebx", "%ecx", "%edx" );
|
||||||
|
#endif
|
||||||
|
__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high));
|
||||||
|
return (uint64_t)high << 32 | low;
|
||||||
|
}
|
||||||
|
#endif // !WIN32
|
||||||
|
|
||||||
#undef FORCEINLINE
|
#undef FORCEINLINE
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user