[libcxx-commits] [libcxx] [libc++] Use _BitScanForward64 more often, by fixing availability detection, avoiding calling _BitScanForward twice (PR #142000)

Eugene Golushkov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 11 08:06:34 PDT 2025


================
@@ -479,7 +479,7 @@ struct __floating_decimal_64 {
           36893488u, 7378697u, 1475739u, 295147u, 59029u, 11805u, 2361u, 472u, 94u, 18u, 3u };
 
         unsigned long _Trailing_zero_bits;
-#if _LIBCPP_HAS_BITSCAN64
+#if !defined(_MSC_VER) || defined(_M_AMD64) || defined(_M_ARM64) // we have own _BitScanForward64 for non-MSVC
----------------
eugenegff wrote:

std::to_chars is C++17, std::countr_zero is C++20, but probably std::__countr_zero will work in C++17 mode

codegen is different for x64 https://godbolt.org/z/TjeT661eT, countr_zero translates to tzcnt == rep bsf, that properly works with zero input, but may be more expensive - but benefits of the standard function can be more important

https://github.com/llvm/llvm-project/pull/142000


More information about the libcxx-commits mailing list