tiempo.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef __TIEMPO_H__
  2. #define __TIEMPO_H__
  3. // uso:
  4. // unsigned long start, end;
  5. // MEDIR_TIEMPO_START(start);
  6. // ... codigo ...
  7. // MEDIR_TIEMPO_STOP(end);
  8. // unsigned long delta = end - start;
  9. #define MEDIR_TIEMPO(var) \
  10. { \
  11. __asm__ __volatile__ ( \
  12. "xor %%rdx, %%rdx\n\t" \
  13. "xor %%rax, %%rax\n\t" \
  14. "lfence\n\t" \
  15. "rdtsc\n\t" \
  16. "sal $32, %%rdx\n\t" \
  17. "or %%rdx, %%rax\n\t" \
  18. "movq %%rax, %0\n\t" \
  19. : "=r" (var) \
  20. : /* no input */ \
  21. : "%rax", "%rdx" \
  22. ); \
  23. }
  24. #define MEDIR_TIEMPO_START(start) \
  25. { \
  26. /* warm up ... */ \
  27. MEDIR_TIEMPO(start); \
  28. MEDIR_TIEMPO(start); \
  29. MEDIR_TIEMPO(start); \
  30. }
  31. #define MEDIR_TIEMPO_STOP(end) \
  32. { \
  33. MEDIR_TIEMPO(end); \
  34. }
  35. #endif /* !__TIEMPO_H__ */