From f7479ab4b1f55fd45ca6774e2f4d5ed7fb9e27d9 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 25 Jun 2023 12:46:45 +0700 Subject: [PATCH 1/9] add specialization for 24MHz QueryPerformanceFrequency Co-authored-by: Steven Noonan --- stl/inc/__msvc_chrono.hpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 45b9f75f782..53b3d14c26c 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -666,18 +666,35 @@ namespace chrono { using time_point = _CHRONO time_point; static constexpr bool is_steady = true; +#if defined(_M_ARM) || defined(_M_ARM64) +#define _LIKELY_ARM likely +#define _LIKELY_X86 unlikely +#elif defined(_M_IX86) || defined(_M_X64) +#define _LIKELY_ARM unlikely +#define _LIKELY_X86 likely +#else +#error Unknown architecture +#endif _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot const long long _Ctr = _Query_perf_counter(); static_assert(period::num == 1, "This assumes period::num == 1."); - // 10 MHz is a very common QPC frequency on modern PCs. Optimizing for + // 10 MHz is a very common QPC frequency on modern X86 PCs. Optimizing for // this specific frequency can double the performance of this function by // avoiding the expensive frequency conversion path. - constexpr long long _TenMHz = 10'000'000; - if (_Freq == _TenMHz) { + constexpr long long _TwentyFourMHz = 24'000'000; + constexpr long long _TenMHz = 10'000'000; + if (_Freq == _TenMHz) [[_LIKELY_X86]] { static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); + } else if (_Freq == _TwentyFourMHz) [[_LIKELY_ARM]] { + // The compiler recognizes the constants for frequency and time period and uses shifts and multiplies + // instead of divides to calculate the nanosecond value. This frequency is common on ARM64 (Windows + // devices, and Apple Silicon Macs using Parallels Desktop) + const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; + const long long _Part = (_Ctr % _TwentyFourMHz) * period::den / _TwentyFourMHz; + return time_point(duration(_Whole + _Part)); } else { // Instead of just having "(_Ctr * period::den) / _Freq", // the algorithm below prevents overflow when _Ctr is sufficiently large. @@ -690,6 +707,8 @@ namespace chrono { } } }; +#undef _LIKELY_ARM +#undef _LIKELY_X86 _EXPORT_STD using high_resolution_clock = steady_clock; } // namespace chrono From 28778701ccc377c0fe13364216cab1013c2a1943 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 25 Jun 2023 13:12:36 +0700 Subject: [PATCH 2/9] remove likely and unlikely --- stl/inc/__msvc_chrono.hpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 53b3d14c26c..94d8a8c01da 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -666,15 +666,6 @@ namespace chrono { using time_point = _CHRONO time_point; static constexpr bool is_steady = true; -#if defined(_M_ARM) || defined(_M_ARM64) -#define _LIKELY_ARM likely -#define _LIKELY_X86 unlikely -#elif defined(_M_IX86) || defined(_M_X64) -#define _LIKELY_ARM unlikely -#define _LIKELY_X86 likely -#else -#error Unknown architecture -#endif _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot const long long _Ctr = _Query_perf_counter(); @@ -684,11 +675,11 @@ namespace chrono { // avoiding the expensive frequency conversion path. constexpr long long _TwentyFourMHz = 24'000'000; constexpr long long _TenMHz = 10'000'000; - if (_Freq == _TenMHz) [[_LIKELY_X86]] { + if (_Freq == _TenMHz) { static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); - } else if (_Freq == _TwentyFourMHz) [[_LIKELY_ARM]] { + } else if (_Freq == _TwentyFourMHz) { // The compiler recognizes the constants for frequency and time period and uses shifts and multiplies // instead of divides to calculate the nanosecond value. This frequency is common on ARM64 (Windows // devices, and Apple Silicon Macs using Parallels Desktop) @@ -707,8 +698,6 @@ namespace chrono { } } }; -#undef _LIKELY_ARM -#undef _LIKELY_X86 _EXPORT_STD using high_resolution_clock = steady_clock; } // namespace chrono From b4557d4c02fe7e36d33b71d3ee3520057bd70e0e Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Sun, 25 Jun 2023 13:51:38 +0700 Subject: [PATCH 3/9] restore likely/unlikely logic --- stl/inc/__msvc_chrono.hpp | 41 +++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 94d8a8c01da..9bb1b050d38 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -666,6 +666,32 @@ namespace chrono { using time_point = _CHRONO time_point; static constexpr bool is_steady = true; +#if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM/ARM64 arch vvv + +#if _HAS_CXX20 +#define _LIKELY_ARM [[likely]] +#elif defined(__clang__) +#define _LIKELY_ARM [[__likely__]] +#else +#define _LIKELY_ARM +#endif +#define _LIKELY_X86 + +#elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM/ARM64 arch / X86/X64 arch vvv + +#if _HAS_CXX20 +#define _LIKELY_X86 [[likely]] +#elif defined(__clang__) +#define _LIKELY_X86 [[__likely__]] +#else +#define _LIKELY_X86 +#endif +#define _LIKELY_ARM + +#else // ^^^ X86/X64 arch / other arch vvv +#define _LIKELY_ARM +#define _LIKELY_X86 +#endif // ^^^ other arch ^^^ _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot const long long _Ctr = _Query_perf_counter(); @@ -675,14 +701,15 @@ namespace chrono { // avoiding the expensive frequency conversion path. constexpr long long _TwentyFourMHz = 24'000'000; constexpr long long _TenMHz = 10'000'000; - if (_Freq == _TenMHz) { + // clang-format off + if (_Freq == _TenMHz) _LIKELY_X86 { static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); - } else if (_Freq == _TwentyFourMHz) { - // The compiler recognizes the constants for frequency and time period and uses shifts and multiplies - // instead of divides to calculate the nanosecond value. This frequency is common on ARM64 (Windows - // devices, and Apple Silicon Macs using Parallels Desktop) + } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM { + // The compiler recognizes the constants for frequency and time period and uses shifts and + // multiplies instead of divides to calculate the nanosecond value. This frequency is common on + // ARM64 (Windows devices, and Apple Silicon Macs using Parallels Desktop) const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; const long long _Part = (_Ctr % _TwentyFourMHz) * period::den / _TwentyFourMHz; return time_point(duration(_Whole + _Part)); @@ -696,9 +723,11 @@ namespace chrono { const long long _Part = (_Ctr % _Freq) * period::den / _Freq; return time_point(duration(_Whole + _Part)); } + // clang-format on } }; - +#undef _LIKELY_ARM +#undef _LIKELY_X86 _EXPORT_STD using high_resolution_clock = steady_clock; } // namespace chrono From 9b32bef12f125344935c061ffa9fdb1c272c3d32 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 28 Jun 2023 16:16:54 +0700 Subject: [PATCH 4/9] code review suggestions --- stl/inc/__msvc_chrono.hpp | 51 ++++++++++++++------------------------- stl/inc/yvals_core.h | 11 +++++++++ 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 9bb1b050d38..4671ee1da7f 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -666,50 +666,35 @@ namespace chrono { using time_point = _CHRONO time_point; static constexpr bool is_steady = true; -#if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM/ARM64 arch vvv - -#if _HAS_CXX20 -#define _LIKELY_ARM [[likely]] -#elif defined(__clang__) -#define _LIKELY_ARM [[__likely__]] -#else -#define _LIKELY_ARM -#endif -#define _LIKELY_X86 - -#elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM/ARM64 arch / X86/X64 arch vvv - -#if _HAS_CXX20 -#define _LIKELY_X86 [[likely]] -#elif defined(__clang__) -#define _LIKELY_X86 [[__likely__]] -#else -#define _LIKELY_X86 -#endif -#define _LIKELY_ARM - -#else // ^^^ X86/X64 arch / other arch vvv -#define _LIKELY_ARM -#define _LIKELY_X86 +#if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM or ARM64 arch vvv +#define _STL_LIKELY_ARM _STL_LIKELY +#define _STL_LIKELY_X86 +#elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM or ARM64 arch / x86 or x64 arch vvv +#define _STL_LIKELY_ARM +#define _STL_LIKELY_X86 _STL_LIKELY +#else // ^^^ x86 or x64 arch / other arch vvv +#define _STL_LIKELY_ARM +#define _STL_LIKELY_X86 #endif // ^^^ other arch ^^^ _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot const long long _Ctr = _Query_perf_counter(); static_assert(period::num == 1, "This assumes period::num == 1."); - // 10 MHz is a very common QPC frequency on modern X86 PCs. Optimizing for - // this specific frequency can double the performance of this function by - // avoiding the expensive frequency conversion path. + // The compiler recognizes the constants for frequency and time period and uses shifts and + // multiplies instead of divides to calculate the nanosecond value. constexpr long long _TwentyFourMHz = 24'000'000; constexpr long long _TenMHz = 10'000'000; // clang-format off - if (_Freq == _TenMHz) _LIKELY_X86 { + if (_Freq == _TenMHz) _STL_LIKELY_X86 { + // 10 MHz is a very common QPC frequency on modern x86 PCs. Optimizing for + // this specific frequency can double the performance of this function by + // avoiding the expensive frequency conversion path. static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); - } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM { - // The compiler recognizes the constants for frequency and time period and uses shifts and - // multiplies instead of divides to calculate the nanosecond value. This frequency is common on - // ARM64 (Windows devices, and Apple Silicon Macs using Parallels Desktop) + } else if (_Freq == _TwentyFourMHz) _STL_LIKELY_ARM { + // 24 MHz frequency is a common frequency on ARM64, including cases where it emulates x86 + // (Windows devices, and Apple Silicon Macs using Parallels Desktop) const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; const long long _Part = (_Ctr % _TwentyFourMHz) * period::den / _TwentyFourMHz; return time_point(duration(_Whole + _Part)); diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index ceb2fce5ed8..6bc2f25b07c 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1920,5 +1920,16 @@ compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error. #define _STL_INTERNAL_STATIC_ASSERT(...) #endif // _ENABLE_STL_INTERNAL_CHECK +#if _HAS_CXX20 // vvv C++20 vvv +#define _STL_LIKELY [[likely]] +#define _STL_UNLIKELY [[unlikely]] +#elif defined(__clang__) // ^^^ C++20 / clang and C++17 or C++14 vvv +#define _STL_LIKELY [[__likely__]] +#define _STL_UNLIKELY [[__unlikely__]] +#else // ^^^ clang and C++17 or C++14 / C1XX and C++17 or C++14 vvv +#define _STL_LIKELY +#define _STL_UNLIKELY +#endif // ^^^ C1XX and C++14/C++17 ^^^ + #endif // _STL_COMPILER_PREPROCESSOR #endif // _YVALS_CORE_H_ From 5b995f07e16a5d7daf7984c594488f6f519e935f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 28 Jun 2023 16:25:43 +0700 Subject: [PATCH 5/9] remove _STL_ prefix --- stl/inc/__msvc_chrono.hpp | 16 ++++++++-------- stl/inc/yvals_core.h | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 4671ee1da7f..4f32ef81a69 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -667,14 +667,14 @@ namespace chrono { static constexpr bool is_steady = true; #if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM or ARM64 arch vvv -#define _STL_LIKELY_ARM _STL_LIKELY -#define _STL_LIKELY_X86 +#define _LIKELY_ARM _STL_LIKELY +#define _LIKELY_X86 #elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM or ARM64 arch / x86 or x64 arch vvv -#define _STL_LIKELY_ARM -#define _STL_LIKELY_X86 _STL_LIKELY +#define _LIKELY_ARM +#define _LIKELY_X86 _STL_LIKELY #else // ^^^ x86 or x64 arch / other arch vvv -#define _STL_LIKELY_ARM -#define _STL_LIKELY_X86 +#define _LIKELY_ARM +#define _LIKELY_X86 #endif // ^^^ other arch ^^^ _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot @@ -685,14 +685,14 @@ namespace chrono { constexpr long long _TwentyFourMHz = 24'000'000; constexpr long long _TenMHz = 10'000'000; // clang-format off - if (_Freq == _TenMHz) _STL_LIKELY_X86 { + if (_Freq == _TenMHz) _LIKELY_X86 { // 10 MHz is a very common QPC frequency on modern x86 PCs. Optimizing for // this specific frequency can double the performance of this function by // avoiding the expensive frequency conversion path. static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); - } else if (_Freq == _TwentyFourMHz) _STL_LIKELY_ARM { + } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM { // 24 MHz frequency is a common frequency on ARM64, including cases where it emulates x86 // (Windows devices, and Apple Silicon Macs using Parallels Desktop) const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 6bc2f25b07c..3a344b0eae3 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1921,14 +1921,14 @@ compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error. #endif // _ENABLE_STL_INTERNAL_CHECK #if _HAS_CXX20 // vvv C++20 vvv -#define _STL_LIKELY [[likely]] -#define _STL_UNLIKELY [[unlikely]] +#define _LIKELY [[likely]] +#define _UNLIKELY [[unlikely]] #elif defined(__clang__) // ^^^ C++20 / clang and C++17 or C++14 vvv -#define _STL_LIKELY [[__likely__]] -#define _STL_UNLIKELY [[__unlikely__]] +#define _LIKELY [[__likely__]] +#define _UNLIKELY [[__unlikely__]] #else // ^^^ clang and C++17 or C++14 / C1XX and C++17 or C++14 vvv -#define _STL_LIKELY -#define _STL_UNLIKELY +#define _LIKELY +#define _UNLIKELY #endif // ^^^ C1XX and C++14/C++17 ^^^ #endif // _STL_COMPILER_PREPROCESSOR From 0829dfa529b676201362c380668008bcd791b326 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 28 Jun 2023 16:37:00 +0700 Subject: [PATCH 6/9] typo --- stl/inc/__msvc_chrono.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 4f32ef81a69..e91cb9aa6c0 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -667,11 +667,11 @@ namespace chrono { static constexpr bool is_steady = true; #if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM or ARM64 arch vvv -#define _LIKELY_ARM _STL_LIKELY +#define _LIKELY_ARM _LIKELY #define _LIKELY_X86 #elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM or ARM64 arch / x86 or x64 arch vvv #define _LIKELY_ARM -#define _LIKELY_X86 _STL_LIKELY +#define _LIKELY_X86 _LIKELY #else // ^^^ x86 or x64 arch / other arch vvv #define _LIKELY_ARM #define _LIKELY_X86 From d4e3b492edad04aea7a90e11371c9763938ced29 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 28 Jun 2023 17:21:02 +0700 Subject: [PATCH 7/9] refactor --- stl/inc/yvals_core.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 3a344b0eae3..a1565110dc8 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -525,6 +525,20 @@ #define _FALLTHROUGH #endif +#ifndef __has_cpp_attribute // vvv no attributes vvv +#define _LIKELY +#define _UNLIKELY +#elif __has_cpp_attribute(likely) >= 201803L && __has_cpp_attribute(unlikely) >= 201803L // ^^^ no attr/C++20 attr vvv +#define _LIKELY [[likely]] +#define _UNLIKELY [[unlikely]] +#elif defined(__clang__) // ^^^ C++20 attributes / clang attributes and C++17 or C++14 vvv +#define _LIKELY [[__likely__]] +#define _UNLIKELY [[__unlikely__]] +#else // ^^^ clang attributes and C++17 or C++14 / C1XX attributes and C++17 or C++14 vvv +#define _LIKELY +#define _UNLIKELY +#endif // ^^^ C1XX attributes and C++17 or C++14 ^^^ + // _HAS_NODISCARD (in vcruntime.h) controls: // [[nodiscard]] attributes on STL functions @@ -1920,16 +1934,5 @@ compiler option, or define _ALLOW_RTCc_IN_STL to suppress this error. #define _STL_INTERNAL_STATIC_ASSERT(...) #endif // _ENABLE_STL_INTERNAL_CHECK -#if _HAS_CXX20 // vvv C++20 vvv -#define _LIKELY [[likely]] -#define _UNLIKELY [[unlikely]] -#elif defined(__clang__) // ^^^ C++20 / clang and C++17 or C++14 vvv -#define _LIKELY [[__likely__]] -#define _UNLIKELY [[__unlikely__]] -#else // ^^^ clang and C++17 or C++14 / C1XX and C++17 or C++14 vvv -#define _LIKELY -#define _UNLIKELY -#endif // ^^^ C1XX and C++14/C++17 ^^^ - #endif // _STL_COMPILER_PREPROCESSOR #endif // _YVALS_CORE_H_ From 92d37c74e5be2fb0f01be692adf3a9d043556cec Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 6 Jul 2023 16:26:06 -0700 Subject: [PATCH 8/9] Code review feedback. --- stl/inc/__msvc_chrono.hpp | 28 ++++++++++++++-------------- stl/inc/yvals_core.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index e91cb9aa6c0..e221082678a 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -667,14 +667,14 @@ namespace chrono { static constexpr bool is_steady = true; #if defined(_M_ARM) || defined(_M_ARM64) // vvv ARM or ARM64 arch vvv -#define _LIKELY_ARM _LIKELY -#define _LIKELY_X86 +#define _LIKELY_ARM_ARM64 _LIKELY +#define _LIKELY_X86_X64 #elif defined(_M_IX86) || defined(_M_X64) // ^^^ ARM or ARM64 arch / x86 or x64 arch vvv -#define _LIKELY_ARM -#define _LIKELY_X86 _LIKELY +#define _LIKELY_ARM_ARM64 +#define _LIKELY_X86_X64 _LIKELY #else // ^^^ x86 or x64 arch / other arch vvv -#define _LIKELY_ARM -#define _LIKELY_X86 +#define _LIKELY_ARM_ARM64 +#define _LIKELY_X86_X64 #endif // ^^^ other arch ^^^ _NODISCARD static time_point now() noexcept { // get current time const long long _Freq = _Query_perf_frequency(); // doesn't change after system boot @@ -682,19 +682,18 @@ namespace chrono { static_assert(period::num == 1, "This assumes period::num == 1."); // The compiler recognizes the constants for frequency and time period and uses shifts and // multiplies instead of divides to calculate the nanosecond value. - constexpr long long _TwentyFourMHz = 24'000'000; constexpr long long _TenMHz = 10'000'000; + constexpr long long _TwentyFourMHz = 24'000'000; // clang-format off - if (_Freq == _TenMHz) _LIKELY_X86 { - // 10 MHz is a very common QPC frequency on modern x86 PCs. Optimizing for + if (_Freq == _TenMHz) _LIKELY_X86_X64 { + // 10 MHz is a very common QPC frequency on modern x86/x64 PCs. Optimizing for // this specific frequency can double the performance of this function by // avoiding the expensive frequency conversion path. static_assert(period::den % _TenMHz == 0, "It should never fail."); constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); - } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM { - // 24 MHz frequency is a common frequency on ARM64, including cases where it emulates x86 - // (Windows devices, and Apple Silicon Macs using Parallels Desktop) + } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM_ARM64 { + // 24 MHz is a common frequency on ARM/ARM64. const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; const long long _Part = (_Ctr % _TwentyFourMHz) * period::den / _TwentyFourMHz; return time_point(duration(_Whole + _Part)); @@ -710,9 +709,10 @@ namespace chrono { } // clang-format on } +#undef _LIKELY_ARM_ARM64 +#undef _LIKELY_X86_X64 }; -#undef _LIKELY_ARM -#undef _LIKELY_X86 + _EXPORT_STD using high_resolution_clock = steady_clock; } // namespace chrono diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index a1565110dc8..13789b3be78 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -528,7 +528,7 @@ #ifndef __has_cpp_attribute // vvv no attributes vvv #define _LIKELY #define _UNLIKELY -#elif __has_cpp_attribute(likely) >= 201803L && __has_cpp_attribute(unlikely) >= 201803L // ^^^ no attr/C++20 attr vvv +#elif __has_cpp_attribute(likely) >= 201803L && __has_cpp_attribute(unlikely) >= 201803L // ^^^ no attr / C++20 attr vvv #define _LIKELY [[likely]] #define _UNLIKELY [[unlikely]] #elif defined(__clang__) // ^^^ C++20 attributes / clang attributes and C++17 or C++14 vvv From d9d5de131a3644efee6e806206417d6af27cb5ea Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 7 Jul 2023 01:57:35 -0700 Subject: [PATCH 9/9] Restore emulation comment. --- stl/inc/__msvc_chrono.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index e221082678a..581d2e74f0d 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -693,7 +693,7 @@ namespace chrono { constexpr long long _Multiplier = period::den / _TenMHz; return time_point(duration(_Ctr * _Multiplier)); } else if (_Freq == _TwentyFourMHz) _LIKELY_ARM_ARM64 { - // 24 MHz is a common frequency on ARM/ARM64. + // 24 MHz is a common frequency on ARM/ARM64, including cases where it emulates x86/x64. const long long _Whole = (_Ctr / _TwentyFourMHz) * period::den; const long long _Part = (_Ctr % _TwentyFourMHz) * period::den / _TwentyFourMHz; return time_point(duration(_Whole + _Part));