TickCounter.h 821 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #ifdef JPH_PLATFORM_WINDOWS
  5. #include <intrin.h> // for __rdtsc
  6. #endif
  7. namespace JPH {
  8. /// Functionality to get the processors cycle counter
  9. JPH_INLINE uint64 GetProcessorTickCount()
  10. {
  11. #if defined(JPH_PLATFORM_BLUE)
  12. return JPH_PLATFORM_BLUE_GET_TICKS();
  13. #elif defined(JPH_CPU_X64)
  14. return __rdtsc();
  15. #elif defined(JPH_CPU_ARM64)
  16. uint64 val;
  17. asm volatile("mrs %0, cntvct_el0" : "=r" (val));
  18. return val;
  19. #else
  20. #error Undefined
  21. #endif
  22. }
  23. /// Get the amount of ticks per second, note that this number will never be fully accurate as the amound of ticks per second may vary with CPU load, so this number is only to be used to give an indication of time for profiling purposes
  24. uint64 GetProcessorTicksPerSecond();
  25. } // JPH