diff --git a/src/port/pg_bitutils.c b/src/port/pg_bitutils.c index 2252021854..dcbd270b71 100644 --- a/src/port/pg_bitutils.c +++ b/src/port/pg_bitutils.c @@ -110,7 +110,7 @@ const uint8 pg_number_of_ones[256] = { * Otherwise, we fall back to __builtin_popcount if the compiler has that, * or a hand-rolled implementation if not. */ -#ifdef HAVE_X86_64_POPCNTQ +#if defined(HAVE_X86_64_POPCNTQ) || (defined(_MSC_VER) && defined(_WIN64)) #if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID) #define USE_POPCNT_ASM 1 #endif @@ -201,10 +201,14 @@ pg_popcount64_choose(uint64 word) static int pg_popcount32_asm(uint32 word) { +#ifdef _MSC_VER + return __popcnt(word); +#else uint32 res; __asm__ __volatile__(" popcntl %1,%0\n":"=q"(res):"rm"(word):"cc"); return (int) res; +#endif } /* @@ -214,10 +218,14 @@ __asm__ __volatile__(" popcntl %1,%0\n":"=q"(res):"rm"(word):"cc"); static int pg_popcount64_asm(uint64 word) { +#ifdef _MSC_VER + return __popcnt64(word); +#else uint64 res; __asm__ __volatile__(" popcntq %1,%0\n":"=q"(res):"rm"(word):"cc"); return (int) res; +#endif } #endif /* USE_POPCNT_ASM */