move countBits to impl::popcnt
diff --git a/test/cpumask_test.cpp b/test/cpumask_test.cpp index c651066..95ec88f 100644 --- a/test/cpumask_test.cpp +++ b/test/cpumask_test.cpp
@@ -5,16 +5,6 @@ using namespace Xbyak::util; -uint32_t popcnt(uint32_t v) -{ - uint32_t n = 0; - while (v) { - if (v & 1) n++; - v >>= 1; - } - return n; -} - CYBOZU_TEST_AUTO(pattern) { const uint32_t bitN = XBYAK_CPUMASK_BITN;
diff --git a/xbyak/xbyak_util.h b/xbyak/xbyak_util.h index 976e603..1072c2a 100644 --- a/xbyak/xbyak_util.h +++ b/xbyak/xbyak_util.h
@@ -1124,31 +1124,33 @@ friend void impl::initCpuTopology(CpuTopology&, const Cpu&); std::vector<LogicalCpu> logicalCpus_; size_t physicalCoreNum_; - size_t socketNum_; uint32_t lineSize_; bool isHybrid_; }; namespace impl { + +inline uint32_t popcnt(uint64_t mask) +{ +#if defined(_M_X64) || defined(_M_AMD64) + return (int)__popcnt64(mask); +#elif defined(__GNUC__) || defined(__clang__) + return __builtin_popcountll(mask); +#else + uint32_t count = 0; + while (mask) { + count += (mask & 1); + mask >>= 1; + } + return count; +#endif +} + #ifdef _WIN32 inline void initCpuTopology(CpuTopology& cpuTopo, const Cpu& cpu) { typedef SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX processorInfo; - // Helper lambda to count set bits in a mask - auto countBits = [](KAFFINITY mask) -> int { -#if defined(_M_X64) || defined(_M_AMD64) - return (int)__popcnt64(mask); -#else - int count = 0; - while (mask) { - count += (mask & 1); - mask >>= 1; - } - return count; -#endif - }; - // First pass: Get processor core information DWORD len = 0; GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &len);