From f7534b04ab52c5921141046a25738cc570ad0ad2 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 14 Jan 2026 14:14:41 -0500 Subject: [PATCH v1 3/3] Rename "fast" and "slow" popcount functions. Since we now how several implementations of the popcount functions, let's give them more descriptive names. This commit replaces "slow" with "generic" and "fast" with "sse42". --- src/include/port/pg_bitutils.h | 8 +++--- src/port/pg_bitutils.c | 38 ++++++++++++------------- src/port/pg_popcount_x86_64.c | 52 +++++++++++++++++----------------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h index c9c508d4ba3..f2f94894d3a 100644 --- a/src/include/port/pg_bitutils.h +++ b/src/include/port/pg_bitutils.h @@ -307,10 +307,10 @@ pg_ceil_log2_64(uint64 num) #define POPCNT_AARCH64 1 #endif -extern int pg_popcount32_slow(uint32 word); -extern int pg_popcount64_slow(uint64 word); -extern uint64 pg_popcount_slow(const char *buf, int bytes); -extern uint64 pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask); +extern int pg_popcount32_generic(uint32 word); +extern int pg_popcount64_generic(uint64 word); +extern uint64 pg_popcount_generic(const char *buf, int bytes); +extern uint64 pg_popcount_masked_generic(const char *buf, int bytes, bits8 mask); #ifdef TRY_POPCNT_X86_64 /* diff --git a/src/port/pg_bitutils.c b/src/port/pg_bitutils.c index 9f9f90ddd4d..2d8a7e0cf6a 100644 --- a/src/port/pg_bitutils.c +++ b/src/port/pg_bitutils.c @@ -97,11 +97,11 @@ const uint8 pg_number_of_ones[256] = { }; /* - * pg_popcount32_slow + * pg_popcount32_generic * Return the number of 1 bits set in word */ int -pg_popcount32_slow(uint32 word) +pg_popcount32_generic(uint32 word) { #ifdef HAVE__BUILTIN_POPCOUNT return __builtin_popcount(word); @@ -119,11 +119,11 @@ pg_popcount32_slow(uint32 word) } /* - * pg_popcount64_slow + * pg_popcount64_generic * Return the number of 1 bits set in word */ int -pg_popcount64_slow(uint64 word) +pg_popcount64_generic(uint64 word) { #ifdef HAVE__BUILTIN_POPCOUNT #if SIZEOF_LONG == 8 @@ -147,11 +147,11 @@ pg_popcount64_slow(uint64 word) } /* - * pg_popcount_slow + * pg_popcount_generic * Returns the number of 1-bits in buf */ uint64 -pg_popcount_slow(const char *buf, int bytes) +pg_popcount_generic(const char *buf, int bytes) { uint64 popcnt = 0; @@ -163,7 +163,7 @@ pg_popcount_slow(const char *buf, int bytes) while (bytes >= 8) { - popcnt += pg_popcount64_slow(*words++); + popcnt += pg_popcount64_generic(*words++); bytes -= 8; } @@ -177,7 +177,7 @@ pg_popcount_slow(const char *buf, int bytes) while (bytes >= 4) { - popcnt += pg_popcount32_slow(*words++); + popcnt += pg_popcount32_generic(*words++); bytes -= 4; } @@ -193,11 +193,11 @@ pg_popcount_slow(const char *buf, int bytes) } /* - * pg_popcount_masked_slow + * pg_popcount_masked_generic * Returns the number of 1-bits in buf after applying the mask to each byte */ uint64 -pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask) +pg_popcount_masked_generic(const char *buf, int bytes, bits8 mask) { uint64 popcnt = 0; @@ -211,7 +211,7 @@ pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask) while (bytes >= 8) { - popcnt += pg_popcount64_slow(*words++ & maskv); + popcnt += pg_popcount64_generic(*words++ & maskv); bytes -= 8; } @@ -227,7 +227,7 @@ pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask) while (bytes >= 4) { - popcnt += pg_popcount32_slow(*words++ & maskv); + popcnt += pg_popcount32_generic(*words++ & maskv); bytes -= 4; } @@ -246,20 +246,20 @@ pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask) /* * When special CPU instructions are not available, there's no point in using - * function pointers to vary the implementation between the fast and slow - * method. We instead just make these actual external functions. The compiler - * should be able to inline the slow versions here. + * function pointers to vary the implementation. We instead just make these + * actual external functions. The compiler should be able to inline the + * generic versions here. */ int pg_popcount32(uint32 word) { - return pg_popcount32_slow(word); + return pg_popcount32_generic(word); } int pg_popcount64(uint64 word) { - return pg_popcount64_slow(word); + return pg_popcount64_generic(word); } /* @@ -269,7 +269,7 @@ pg_popcount64(uint64 word) uint64 pg_popcount_optimized(const char *buf, int bytes) { - return pg_popcount_slow(buf, bytes); + return pg_popcount_generic(buf, bytes); } /* @@ -279,7 +279,7 @@ pg_popcount_optimized(const char *buf, int bytes) uint64 pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask) { - return pg_popcount_masked_slow(buf, bytes, mask); + return pg_popcount_masked_generic(buf, bytes, mask); } #endif /* ! TRY_POPCNT_X86_64 && ! POPCNT_AARCH64 */ diff --git a/src/port/pg_popcount_x86_64.c b/src/port/pg_popcount_x86_64.c index f8643642613..13c922f7ab1 100644 --- a/src/port/pg_popcount_x86_64.c +++ b/src/port/pg_popcount_x86_64.c @@ -32,10 +32,10 @@ * The SSE4.2 versions are built regardless of whether we are building the * AVX-512 versions. */ -static inline int pg_popcount32_fast(uint32 word); -static inline int pg_popcount64_fast(uint64 word); -static uint64 pg_popcount_fast(const char *buf, int bytes); -static uint64 pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask); +static inline int pg_popcount32_sse42(uint32 word); +static inline int pg_popcount64_sse42(uint64 word); +static uint64 pg_popcount_sse42(const char *buf, int bytes); +static uint64 pg_popcount_masked_sse42(const char *buf, int bytes, bits8 mask); /* * These are the AVX-512 implementations of the popcount functions. @@ -64,7 +64,7 @@ uint64 (*pg_popcount_masked_optimized) (const char *buf, int bytes, bits8 mask) * Return true if CPUID indicates that the POPCNT instruction is available. */ static bool -pg_popcount_available(void) +pg_popcount_sse42_available(void) { unsigned int exx[4] = {0, 0, 0, 0}; @@ -161,19 +161,19 @@ pg_popcount_avx512_available(void) static inline void choose_popcount_functions(void) { - if (pg_popcount_available()) + if (pg_popcount_sse42_available()) { - pg_popcount32 = pg_popcount32_fast; - pg_popcount64 = pg_popcount64_fast; - pg_popcount_optimized = pg_popcount_fast; - pg_popcount_masked_optimized = pg_popcount_masked_fast; + pg_popcount32 = pg_popcount32_sse42; + pg_popcount64 = pg_popcount64_sse42; + pg_popcount_optimized = pg_popcount_sse42; + pg_popcount_masked_optimized = pg_popcount_masked_sse42; } else { - pg_popcount32 = pg_popcount32_slow; - pg_popcount64 = pg_popcount64_slow; - pg_popcount_optimized = pg_popcount_slow; - pg_popcount_masked_optimized = pg_popcount_masked_slow; + pg_popcount32 = pg_popcount32_generic; + pg_popcount64 = pg_popcount64_generic; + pg_popcount_optimized = pg_popcount_generic; + pg_popcount_masked_optimized = pg_popcount_masked_generic; } #ifdef USE_AVX512_POPCNT_WITH_RUNTIME_CHECK @@ -335,11 +335,11 @@ pg_popcount_masked_avx512(const char *buf, int bytes, bits8 mask) #endif /* USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */ /* - * pg_popcount32_fast + * pg_popcount32_sse42 * Return the number of 1 bits set in word */ static inline int -pg_popcount32_fast(uint32 word) +pg_popcount32_sse42(uint32 word) { #ifdef _MSC_VER return __popcnt(word); @@ -352,11 +352,11 @@ __asm__ __volatile__(" popcntl %1,%0\n":"=q"(res):"rm"(word):"cc"); } /* - * pg_popcount64_fast + * pg_popcount64_sse42 * Return the number of 1 bits set in word */ static inline int -pg_popcount64_fast(uint64 word) +pg_popcount64_sse42(uint64 word) { #ifdef _MSC_VER return __popcnt64(word); @@ -369,11 +369,11 @@ __asm__ __volatile__(" popcntq %1,%0\n":"=q"(res):"rm"(word):"cc"); } /* - * pg_popcount_fast + * pg_popcount_sse42 * Returns the number of 1-bits in buf */ static uint64 -pg_popcount_fast(const char *buf, int bytes) +pg_popcount_sse42(const char *buf, int bytes) { uint64 popcnt = 0; @@ -385,7 +385,7 @@ pg_popcount_fast(const char *buf, int bytes) while (bytes >= 8) { - popcnt += pg_popcount64_fast(*words++); + popcnt += pg_popcount64_sse42(*words++); bytes -= 8; } @@ -399,7 +399,7 @@ pg_popcount_fast(const char *buf, int bytes) while (bytes >= 4) { - popcnt += pg_popcount32_fast(*words++); + popcnt += pg_popcount32_sse42(*words++); bytes -= 4; } @@ -415,11 +415,11 @@ pg_popcount_fast(const char *buf, int bytes) } /* - * pg_popcount_masked_fast + * pg_popcount_masked_sse42 * Returns the number of 1-bits in buf after applying the mask to each byte */ static uint64 -pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask) +pg_popcount_masked_sse42(const char *buf, int bytes, bits8 mask) { uint64 popcnt = 0; @@ -433,7 +433,7 @@ pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask) while (bytes >= 8) { - popcnt += pg_popcount64_fast(*words++ & maskv); + popcnt += pg_popcount64_sse42(*words++ & maskv); bytes -= 8; } @@ -449,7 +449,7 @@ pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask) while (bytes >= 4) { - popcnt += pg_popcount32_fast(*words++ & maskv); + popcnt += pg_popcount32_sse42(*words++ & maskv); bytes -= 4; } -- 2.50.1 (Apple Git-155)