From 1e6c90a167d7b31eff476debd68023ad485881e1 Mon Sep 17 00:00:00 2001 From: Charlie Barto Date: Mon, 11 Apr 2022 15:33:36 -0700 Subject: [PATCH 1/3] Fix countl_zero on arm64 to properly subtract the zeros resulting from widening --- stl/inc/bit | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stl/inc/bit b/stl/inc/bit index fe1d267f7fd..8f7ca14481f 100644 --- a/stl/inc/bit +++ b/stl/inc/bit @@ -253,9 +253,11 @@ _NODISCARD int _Checked_arm_arm64_countl_zero(const _Ty _Val) noexcept { } #else // ^^^ workaround / no workaround vvv if constexpr (_Digits <= 32) { - return static_cast(_CountLeadingZeros(_Val)); + return static_cast(_CountLeadingZeros(_Val)) + - (numeric_limits::digits - _Digits); } else { - return static_cast(_CountLeadingZeros64(_Val)); + return static_cast(_CountLeadingZeros64(_Val)) + - (numeric_limits::digits - _Digits); } #endif // TRANSITION, GH-1586 } From 0552a200679f5177fd6e54a3fb6c54d49b1a07f7 Mon Sep 17 00:00:00 2001 From: Charlie Barto Date: Mon, 11 Apr 2022 15:41:32 -0700 Subject: [PATCH 2/3] clang-format --- stl/inc/bit | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stl/inc/bit b/stl/inc/bit index 8f7ca14481f..b19b6256ca0 100644 --- a/stl/inc/bit +++ b/stl/inc/bit @@ -253,11 +253,9 @@ _NODISCARD int _Checked_arm_arm64_countl_zero(const _Ty _Val) noexcept { } #else // ^^^ workaround / no workaround vvv if constexpr (_Digits <= 32) { - return static_cast(_CountLeadingZeros(_Val)) - - (numeric_limits::digits - _Digits); + return static_cast(_CountLeadingZeros(_Val)) - (numeric_limits::digits - _Digits); } else { - return static_cast(_CountLeadingZeros64(_Val)) - - (numeric_limits::digits - _Digits); + return static_cast(_CountLeadingZeros64(_Val)) - (numeric_limits::digits - _Digits); } #endif // TRANSITION, GH-1586 } From 5ef76e0902754cad385f3da4559cfc7a92590b3a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 13 Apr 2022 22:28:48 -0700 Subject: [PATCH 3/3] Remove unnecessary code (thanks AlexGuteniev). --- stl/inc/bit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/bit b/stl/inc/bit index b19b6256ca0..eeed2dcd357 100644 --- a/stl/inc/bit +++ b/stl/inc/bit @@ -255,7 +255,7 @@ _NODISCARD int _Checked_arm_arm64_countl_zero(const _Ty _Val) noexcept { if constexpr (_Digits <= 32) { return static_cast(_CountLeadingZeros(_Val)) - (numeric_limits::digits - _Digits); } else { - return static_cast(_CountLeadingZeros64(_Val)) - (numeric_limits::digits - _Digits); + return static_cast(_CountLeadingZeros64(_Val)); } #endif // TRANSITION, GH-1586 }