From d67aced067d8334874da7755425d0a18be8f29a9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 11 Feb 2026 11:19:35 -0600 Subject: [PATCH v13 4/5] Convert some popcount functions to macros. Presently, if no special popcount instructions are available, pg_popcount() and pg_popcount_masked() are implemented as external functions that call the portable versions. By converting these to macros, we can save a handful of lines of code and avoid extra function calls (if the compiler wasn't previously inlining the portable versions in the external functions). Author: John Naylor Discussion: https://postgr.es/m/CANWCAZZkp2_wP3Dd1p_cVqWyXuJYL7wCMHSQL4p-m-cy0iwHAg%40mail.gmail.com --- src/include/port/pg_bitutils.h | 9 +++++++-- src/port/pg_bitutils.c | 31 ------------------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h index c9b1f5f17dc..11ee206a7b2 100644 --- a/src/include/port/pg_bitutils.h +++ b/src/include/port/pg_bitutils.h @@ -287,11 +287,16 @@ extern uint64 pg_popcount_masked_portable(const char *buf, int bytes, bits8 mask extern PGDLLIMPORT uint64 (*pg_popcount_optimized) (const char *buf, int bytes); extern PGDLLIMPORT uint64 (*pg_popcount_masked_optimized) (const char *buf, int bytes, bits8 mask); -#else -/* Use a portable implementation -- no need for a function pointer. */ +#elif defined(USE_NEON) +/* Use Neon implementations -- no need for a function pointer. */ extern uint64 pg_popcount_optimized(const char *buf, int bytes); extern uint64 pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask); +#else +/* Use a portable implementation -- no need for a function pointer. */ +#define pg_popcount_optimized(buf, bytes) pg_popcount_portable(buf, bytes) +#define pg_popcount_masked_optimized(buf, bytes, mask) pg_popcount_masked_portable(buf, bytes, mask) + #endif /* diff --git a/src/port/pg_bitutils.c b/src/port/pg_bitutils.c index 49b130f1306..047044b2917 100644 --- a/src/port/pg_bitutils.c +++ b/src/port/pg_bitutils.c @@ -161,34 +161,3 @@ pg_popcount_masked_portable(const char *buf, int bytes, bits8 mask) return popcnt; } - -#if !defined(HAVE_X86_64_POPCNTQ) && !defined(USE_NEON) - -/* - * When special CPU instructions are not available, there's no point in using - * function pointers to vary the implementation. We instead just make these - * actual external functions. The compiler should be able to inline the - * portable versions here. - */ - -/* - * pg_popcount_optimized - * Returns the number of 1-bits in buf - */ -uint64 -pg_popcount_optimized(const char *buf, int bytes) -{ - return pg_popcount_portable(buf, bytes); -} - -/* - * pg_popcount_masked_optimized - * Returns the number of 1-bits in buf after applying the mask to each byte - */ -uint64 -pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask) -{ - return pg_popcount_masked_portable(buf, bytes, mask); -} - -#endif /* ! HAVE_X86_64_POPCNTQ && ! USE_NEON */ -- 2.50.1 (Apple Git-155)