Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
865 B

  1. //========= Copyright c Valve Corporation, All rights reserved. ============//
  2. #ifndef TIER0_HARDWARE_TIMER
  3. #define TIER0_HARDWARE_TIMER
  4. #include "tier0/platform.h"
  5. #ifdef GNUC
  6. inline int GetHardwareClockFast( void )
  7. {
  8. unsigned long long int nRet;
  9. __asm__ volatile (".byte 0x0f, 0x31" : "=A" (nRet)); // rdtsc
  10. return ( int ) nRet;
  11. }
  12. #else
  13. #ifdef _X360
  14. inline /*__declspec(naked)*/ int GetHardwareClockFast()
  15. {
  16. /*__asm
  17. {
  18. lis r3,08FFFh
  19. ld r3,011E0h(r3)
  20. rldicl r3,r3,32,32
  21. blr
  22. } */
  23. return __mftb32() << 6;
  24. }
  25. #elif defined( _PS3 )
  26. inline int GetHardwareClockFast()
  27. {
  28. // The timebase frequency on PS/3 is 79.8 MHz, see sys_time_get_timebase_frequency()
  29. // this works out to 40.10025 clock ticks per timebase tick
  30. return __mftb() * 40;
  31. }
  32. #else
  33. #include <intrin.h>
  34. inline int GetHardwareClockFast()
  35. {
  36. return __rdtsc();
  37. }
  38. #endif
  39. #endif
  40. #endif