1 // Copyright 2022 The Abseil Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ABSL_BASE_INTERNAL_CYCLECLOCK_CONFIG_H_ 16 #define ABSL_BASE_INTERNAL_CYCLECLOCK_CONFIG_H_ 17 18 #include <cstdint> 19 20 #include "absl/base/config.h" 21 #include "absl/base/internal/unscaledcycleclock_config.h" 22 23 namespace absl { 24 ABSL_NAMESPACE_BEGIN 25 namespace base_internal { 26 27 #if ABSL_USE_UNSCALED_CYCLECLOCK 28 #ifdef NDEBUG 29 #ifdef ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY 30 // Not debug mode and the UnscaledCycleClock frequency is the CPU 31 // frequency. Scale the CycleClock to prevent overflow if someone 32 // tries to represent the time as cycles since the Unix epoch. 33 inline constexpr int32_t kCycleClockShift = 1; 34 #else 35 // Not debug mode and the UnscaledCycleClock isn't operating at the 36 // raw CPU frequency. There is no need to do any scaling, so don't 37 // needlessly sacrifice precision. 38 inline constexpr int32_t kCycleClockShift = 0; 39 #endif 40 #else // NDEBUG 41 // In debug mode use a different shift to discourage depending on a 42 // particular shift value. 43 inline constexpr int32_t kCycleClockShift = 2; 44 #endif // NDEBUG 45 46 inline constexpr double kCycleClockFrequencyScale = 47 1.0 / (1 << kCycleClockShift); 48 49 #endif // ABSL_USE_UNSCALED_CYCLECLOCK 50 51 } // namespace base_internal 52 ABSL_NAMESPACE_END 53 } // namespace absl 54 55 #endif // ABSL_BASE_INTERNAL_CYCLECLOCK_CONFIG_H_ 56