Created
January 4, 2013 16:38
-
-
Save kulp/4453946 to your computer and use it in GitHub Desktop.
Intel assembly timer routines for gcc inline asm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
// from http://download.intel.com/embedded/software/IA/324264.pdf | |
#define rdtscp_before() \ | |
({ uint32_t cycles_high, cycles_low; \ | |
__asm__ volatile ("CPUID\n\t" \ | |
"RDTSC\n\t" \ | |
"mov %%edx, %0\n\t" \ | |
"mov %%eax, %1\n\t": "=r" (cycles_high), "=r" (cycles_low):: \ | |
"%rax", "%rbx", "%rcx", "%rdx"); \ | |
(uint64_t)((uint64_t)cycles_high << 32) + cycles_low; }) | |
#define rdtscp_after() \ | |
({ uint32_t cycles_high, cycles_low; \ | |
__asm__ volatile ( "RDTSC\n\t" \ | |
"mov %%edx, %0\n\t" \ | |
"mov %%eax, %1\n\t" \ | |
"CPUID\n\t" : "=r" (cycles_high), "=r" (cycles_low):: \ | |
"%rax", "%rbx", "%rcx", "%rdx"); \ | |
(uint64_t)((uint64_t)cycles_high << 32) + cycles_low; }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment