1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-06 19:59:18 +03:00

Refactor code for setting pg_popcount* function pointers.

Presently, there are three copies of this code, and a proposed
follow-up patch would add more code to each copy.  This commit
introduces a new inline function for this code and makes use of it
in the pg_popcount*_choose functions, thereby reducing code
duplication.

Author: Paul Amonson
Discussion: https://postgr.es/m/BL1PR11MB5304097DF7EA81D04C33F3D1DCA6A%40BL1PR11MB5304.namprd11.prod.outlook.com
This commit is contained in:
Nathan Bossart 2024-04-02 10:16:00 -05:00
parent 38698dd38e
commit 6687430c98

View File

@ -148,8 +148,8 @@ pg_popcount_available(void)
* the function pointers so that subsequent calls are routed directly to * the function pointers so that subsequent calls are routed directly to
* the chosen implementation. * the chosen implementation.
*/ */
static int static inline void
pg_popcount32_choose(uint32 word) choose_popcount_functions(void)
{ {
if (pg_popcount_available()) if (pg_popcount_available())
{ {
@ -163,45 +163,26 @@ pg_popcount32_choose(uint32 word)
pg_popcount64 = pg_popcount64_slow; pg_popcount64 = pg_popcount64_slow;
pg_popcount = pg_popcount_slow; pg_popcount = pg_popcount_slow;
} }
}
static int
pg_popcount32_choose(uint32 word)
{
choose_popcount_functions();
return pg_popcount32(word); return pg_popcount32(word);
} }
static int static int
pg_popcount64_choose(uint64 word) pg_popcount64_choose(uint64 word)
{ {
if (pg_popcount_available()) choose_popcount_functions();
{
pg_popcount32 = pg_popcount32_fast;
pg_popcount64 = pg_popcount64_fast;
pg_popcount = pg_popcount_fast;
}
else
{
pg_popcount32 = pg_popcount32_slow;
pg_popcount64 = pg_popcount64_slow;
pg_popcount = pg_popcount_slow;
}
return pg_popcount64(word); return pg_popcount64(word);
} }
static uint64 static uint64
pg_popcount_choose(const char *buf, int bytes) pg_popcount_choose(const char *buf, int bytes)
{ {
if (pg_popcount_available()) choose_popcount_functions();
{
pg_popcount32 = pg_popcount32_fast;
pg_popcount64 = pg_popcount64_fast;
pg_popcount = pg_popcount_fast;
}
else
{
pg_popcount32 = pg_popcount32_slow;
pg_popcount64 = pg_popcount64_slow;
pg_popcount = pg_popcount_slow;
}
return pg_popcount(buf, bytes); return pg_popcount(buf, bytes);
} }