Skip to content

Instantly share code, notes, and snippets.

@jonathan-beard
Created July 7, 2014 14:24
Show Gist options
  • Save jonathan-beard/ed2f3bba8ae5f2f33280 to your computer and use it in GitHub Desktop.
Save jonathan-beard/ed2f3bba8ae5f2f33280 to your computer and use it in GitHub Desktop.
std::uint64_t cycles( 0 );
/** begin assembly section to init previous **/
#ifdef __x86_64
__asm__ volatile(
#if RDTSCP
"\
rdtscp \n\
shl $32, %%rdx \n\
orq %%rax, %%rdx \n\
movq %%rdx, %[cyc]"
#elif defined INTEL
"\
lfence \n\
rdtsc \n\
shl $32, %%rdx \n\
orq %%rax, %%rdx \n\
movq %%rdx, %[cyc]"
#elif defined AMD
"\
mfence \n\
rdtsc \n\
shl $32, %%rdx \n\
orq %%rax, %%rdx \n\
movq %%rdx, %[cyc]"
#elif NOSERIAL
"\
rdtsc \n\
shl $32, %%rdx \n\
orq %%rax, %%rdx \n\
movq %%rdx, %[cyc]"
#endif
:
/*outputs here*/
[cyc] "=r" (cycles)
:
/*inputs here*/
:
/*clobbered registers*/
"rax","eax","rcx","ecx","rdx"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment