unscaledcycleclock.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
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 // System timer of ARMv8 runs at a different frequency than the CPU's.
00069 // The frequency is fixed, typically in the range 1-50MHz.  It can be
00070 // read at CNTFRQ special register.  We assume the OS has set up
00071 // the virtual timer properly.
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 }  // namespace base_internal
00099 }  // namespace absl
00100 
00101 #endif  // ABSL_USE_UNSCALED_CYCLECLOCK


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:16