Added helper function to read out TSC.

This commit is contained in:
Michael Mueller
2024-07-23 16:24:01 +02:00
parent c9d7921ef6
commit 7a53462109

View File

@@ -24,6 +24,23 @@ public:
return true; return true;
} }
static uint64_t timestamp()
{
uint32_t lo, hi;
__asm__ __volatile__("xorl %%eax,%%eax\n\t" /* provide constant argument to cpuid to reduce variance */
"cpuid\n\t" /* synchronise, i.e. finish all preceeding instructions */
:
:
: "%rax", "%rbx", "%rcx", "%rdx");
__asm__ __volatile__("rdtsc"
: "=a"(lo), "=d"(hi)
:
: "memory" /* prevent reordering of asm statements */
);
return (uint64_t)hi << 32 | lo;
}
static constexpr auto is_sse2() static constexpr auto is_sse2()
{ {
#ifdef USE_SSE2 #ifdef USE_SSE2