[all-commits] [llvm/llvm-project] 32c7dc: [ADT] Simplify countr_zero and countl_zero with co...

Kazu Hirata via All-commits all-commits at lists.llvm.org
Sun Jun 1 23:23:52 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 32c7dc017b7fd59a43a23ba33a4ff796fb21bd1c
      https://github.com/llvm/llvm-project/commit/32c7dc017b7fd59a43a23ba33a4ff796fb21bd1c
  Author: Kazu Hirata <kazu at google.com>
  Date:   2025-06-01 (Sun, 01 Jun 2025)

  Changed paths:
    M llvm/include/llvm/ADT/bit.h

  Log Message:
  -----------
  [ADT] Simplify countr_zero and countl_zero with constexpr if (NFC) (#141517)

The high-level idea in countr_zero and countl_zero is to use the
intrinsic if available and fall back otherwise, but the actual
implementation is unnecessarily complicated.

Specifically, without this patch, we are going through a long chain of
macros to check the availability of _BitScanForward64:

  #if defined(__GNUC__) || defined(_MSC_VER)
    #if !defined(_MSC_VER) || defined(_M_X64)
      #if __has_builtin(__builtin_ctzll) || defined(__GNUC__)
        ...
      #elif defined(_MSC_VER)
        _BitScanForward64(...);
      #endif
    #endif
  #endif

This basically says we can use _BitScanForward64 if:

  defined(_MSC_VER) && defined(_M_X64)

This patch simplifies all this with "constexpr if" and consolidates
the implementation into the body of countr_zero and countl_zero.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list