Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/base/internal/unscaledcycleclock.h"
00016
00017 #if ABSL_USE_UNSCALED_CYCLECLOCK
00018
00019 #if defined(_WIN32)
00020 #include <intrin.h>
00021 #endif
00022
00023 #if defined(__powerpc__) || defined(__ppc__)
00024 #include <sys/platform/ppc.h>
00025 #endif
00026
00027 #include "absl/base/internal/sysinfo.h"
00028
00029 namespace absl {
00030 namespace base_internal {
00031
00032 #if defined(__i386__)
00033
00034 int64_t UnscaledCycleClock::Now() {
00035 int64_t ret;
00036 __asm__ volatile("rdtsc" : "=A"(ret));
00037 return ret;
00038 }
00039
00040 double UnscaledCycleClock::Frequency() {
00041 return base_internal::NominalCPUFrequency();
00042 }
00043
00044 #elif defined(__x86_64__)
00045
00046 int64_t UnscaledCycleClock::Now() {
00047 uint64_t low, high;
00048 __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
00049 return (high << 32) | low;
00050 }
00051
00052 double UnscaledCycleClock::Frequency() {
00053 return base_internal::NominalCPUFrequency();
00054 }
00055
00056 #elif defined(__powerpc__) || defined(__ppc__)
00057
00058 int64_t UnscaledCycleClock::Now() {
00059 return __ppc_get_timebase();
00060 }
00061
00062 double UnscaledCycleClock::Frequency() {
00063 return __ppc_get_timebase_freq();
00064 }
00065
00066 #elif defined(__aarch64__)
00067
00068
00069
00070
00071
00072 int64_t UnscaledCycleClock::Now() {
00073 int64_t virtual_timer_value;
00074 asm volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
00075 return virtual_timer_value;
00076 }
00077
00078 double UnscaledCycleClock::Frequency() {
00079 uint64_t aarch64_timer_frequency;
00080 asm volatile("mrs %0, cntfrq_el0" : "=r"(aarch64_timer_frequency));
00081 return aarch64_timer_frequency;
00082 }
00083
00084 #elif defined(_M_IX86) || defined(_M_X64)
00085
00086 #pragma intrinsic(__rdtsc)
00087
00088 int64_t UnscaledCycleClock::Now() {
00089 return __rdtsc();
00090 }
00091
00092 double UnscaledCycleClock::Frequency() {
00093 return base_internal::NominalCPUFrequency();
00094 }
00095
00096 #endif
00097
00098 }
00099 }
00100
00101 #endif // ABSL_USE_UNSCALED_CYCLECLOCK