cpucycles.c 439 B

12345678910111213141516171819202122
  1. /*
  2. * File: dclxvi-20130329/cpucycles.c
  3. * Author: Ruben Niederhagen, Peter Schwabe
  4. * Public Domain
  5. */
  6. #include <stdio.h>
  7. long long int cpucycles(void)
  8. {
  9. #ifdef __x86_64__
  10. unsigned long long result;
  11. __asm__ volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
  12. : "=a" (result) :: "%rdx");
  13. return result;
  14. #else
  15. long long result;
  16. __asm__ volatile(".byte 15;.byte 49" : "=A" (result));
  17. return result;
  18. #endif
  19. }