diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-04-03 12:22:02 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-04-03 12:22:02 -0500 |
commit | deb1486c7d36e5430b50b63e8c0f2d8405e24a2a (patch) | |
tree | 2c573b3c3d08c7a01e7ed0c5c8bca2757a3bd456 /src/port/pg_bitutils.c | |
parent | 6dbb490261a6170a3fc3e326c6983ad63e795047 (diff) |
Inline pg_popcount() for small buffers.
If there aren't many bytes to process, the function call overhead
of the optimized implementation isn't worth taking, so instead we
inline a loop that consults pg_number_of_ones in that case. If
there are many bytes to process, we accept the function call
overhead because the optimized versions are likely to be faster.
The threshold at which we use the optimized implementation is set
to the smallest amount of data required to use special popcount
instructions.
Reviewed-by: Alvaro Herrera, Tom Lane
Discussion: https://postgr.es/m/20240402155301.GA2750455%40nathanxps13
Diffstat (limited to 'src/port/pg_bitutils.c')
-rw-r--r-- | src/port/pg_bitutils.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/port/pg_bitutils.c b/src/port/pg_bitutils.c index 28312f3dd95..6271acea600 100644 --- a/src/port/pg_bitutils.c +++ b/src/port/pg_bitutils.c @@ -118,7 +118,7 @@ static uint64 pg_popcount_fast(const char *buf, int bytes); int (*pg_popcount32) (uint32 word) = pg_popcount32_choose; int (*pg_popcount64) (uint64 word) = pg_popcount64_choose; -uint64 (*pg_popcount) (const char *buf, int bytes) = pg_popcount_choose; +uint64 (*pg_popcount_optimized) (const char *buf, int bytes) = pg_popcount_choose; #endif /* TRY_POPCNT_FAST */ #ifdef TRY_POPCNT_FAST @@ -155,13 +155,13 @@ choose_popcount_functions(void) { pg_popcount32 = pg_popcount32_fast; pg_popcount64 = pg_popcount64_fast; - pg_popcount = pg_popcount_fast; + pg_popcount_optimized = pg_popcount_fast; } else { pg_popcount32 = pg_popcount32_slow; pg_popcount64 = pg_popcount64_slow; - pg_popcount = pg_popcount_slow; + pg_popcount_optimized = pg_popcount_slow; } } @@ -183,7 +183,7 @@ static uint64 pg_popcount_choose(const char *buf, int bytes) { choose_popcount_functions(); - return pg_popcount(buf, bytes); + return pg_popcount_optimized(buf, bytes); } /* @@ -387,11 +387,11 @@ pg_popcount64(uint64 word) } /* - * pg_popcount + * pg_popcount_optimized * Returns the number of 1-bits in buf */ uint64 -pg_popcount(const char *buf, int bytes) +pg_popcount_optimized(const char *buf, int bytes) { return pg_popcount_slow(buf, bytes); } |