#include #define NR 100000000 #define LOOP(x) for(int i = 0; i < NR/16; i++) do { \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ asm volatile(x); sum += base; \ } while (0) static inline unsigned int rdtsc(void) { unsigned int a,d; asm volatile("rdtsc":"=a"(a),"=d"(d)::"memory"); return a; } #define TEST(x) do { \ unsigned int s = rdtsc(); \ LOOP(x); \ s = rdtsc()-s; \ fprintf(stderr, " " #x "=%ul: %f\n", sum, s / (double)NR); \ } while (0) int main(int argc, char **argv) { unsigned long base = 0, sum = 0; unsigned long zero = 0; TEST("nop"); TEST("nop"); TEST("nop"); TEST("mov %1,%0":"=r"(base):"m"(zero)); TEST("rdgsbase %0":"=r"(base)); return 0; }