[libcxx-commits] [libcxx] [libc++] Use std::has_single_bit instead of std::popcount(v) == 0 (PR #181787)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 17 00:56:06 PST 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/181787
We have a function that specifically checks if a single bit is set. Use that instad of a `popcount`.
>From 72ce020538b7112de749df3e60b93b549197d538 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 17 Feb 2026 09:55:21 +0100
Subject: [PATCH] [libc++] Use std::has_single_bit instead of std::popcount(v)
== 0
---
libcxx/include/__stop_token/atomic_unique_lock.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libcxx/include/__stop_token/atomic_unique_lock.h b/libcxx/include/__stop_token/atomic_unique_lock.h
index 4b0ae05ca86c8..5dcb6d81dba71 100644
--- a/libcxx/include/__stop_token/atomic_unique_lock.h
+++ b/libcxx/include/__stop_token/atomic_unique_lock.h
@@ -10,9 +10,9 @@
#ifndef _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H
#define _LIBCPP___STOP_TOKEN_ATOMIC_UNIQUE_LOCK_H
-#include <__bit/popcount.h>
+#include <__atomic/atomic.h>
+#include <__bit/has_single_bit.h>
#include <__config>
-#include <atomic>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// and LockedBit is the value of State when the lock bit is set, e.g 1 << 2
template <class _State, _State _LockedBit>
class __atomic_unique_lock {
- static_assert(std::__popcount(static_cast<unsigned long long>(_LockedBit)) == 1,
+ static_assert(std::has_single_bit(static_cast<unsigned long long>(_LockedBit)),
"LockedBit must be an integer where only one bit is set");
std::atomic<_State>& __state_;
More information about the libcxx-commits
mailing list