diff --git a/Utilities/asm.h b/Utilities/asm.h index fae1ef5316..ff0080e14f 100644 --- a/Utilities/asm.h +++ b/Utilities/asm.h @@ -52,18 +52,21 @@ namespace utils #endif } - inline u8 popcnt16(u16 arg) + inline u8 popcnt32(u32 arg) { - const u32 a1 = arg & 0x5555; - const u32 a2 = (arg >> 1) & 0x5555; +#ifdef _MSC_VER + const u32 a1 = arg & 0x55555555; + const u32 a2 = (arg >> 1) & 0x55555555; const u32 a3 = a1 + a2; - const u32 b1 = a3 & 0x3333; - const u32 b2 = (a3 >> 2) & 0x3333; + const u32 b1 = a3 & 0x33333333; + const u32 b2 = (a3 >> 2) & 0x33333333; const u32 b3 = b1 + b2; - const u32 c1 = b3 & 0x0f0f; - const u32 c2 = (b3 >> 4) & 0x0f0f; - const u32 c3 = c1 + c2; - return static_cast(c3 + (c3 >> 8)); + const u32 c3 = (b3 + (b3 >> 4)) & 0x0f0f0f0f; + const u32 d3 = c3 + (c3 >> 8); + return static_cast(d3 + (d3 >> 16)); +#else + return __builtin_popcount(arg); +#endif } // Rotate helpers diff --git a/Utilities/cond.cpp b/Utilities/cond.cpp index c263990227..0e5951ce55 100644 --- a/Utilities/cond.cpp +++ b/Utilities/cond.cpp @@ -267,7 +267,7 @@ void cond_x16::imp_notify() noexcept return; } - balanced_awaken(m_cvx16, utils::popcnt16(wait_mask)); + balanced_awaken(m_cvx16, utils::popcnt32(wait_mask)); } bool lf_queue_base::wait(u64 _timeout)