mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Rename TRY_POPCNT_FAST to TRY_POPCNT_X86_64.
This macro protects x86_64-specific code, and a subsequent commit will introduce AArch64-specific versions of that code. To prevent confusion, let's rename it to clearly indicate that it's for x86_64. We should likely move this code to its own file (perhaps merging it with the AVX-512 popcount code), but that is left as a future exercise. Reviewed-by: "Chiranmoy.Bhattacharya@fujitsu.com" <Chiranmoy.Bhattacharya@fujitsu.com> Reviewed-by: John Naylor <johncnaylorls@gmail.com> Discussion: https://postgr.es/m/010101936e4aaa70-b474ab9e-b9ce-474d-a3ba-a3dc223d295c-000000%40us-west-2.amazonses.com
This commit is contained in:
@ -294,11 +294,11 @@ pg_ceil_log2_64(uint64 num)
|
|||||||
*/
|
*/
|
||||||
#ifdef HAVE_X86_64_POPCNTQ
|
#ifdef HAVE_X86_64_POPCNTQ
|
||||||
#if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID)
|
#if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID)
|
||||||
#define TRY_POPCNT_FAST 1
|
#define TRY_POPCNT_X86_64 1
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TRY_POPCNT_FAST
|
#ifdef TRY_POPCNT_X86_64
|
||||||
/* Attempt to use the POPCNT instruction, but perform a runtime check first */
|
/* Attempt to use the POPCNT instruction, but perform a runtime check first */
|
||||||
extern PGDLLIMPORT int (*pg_popcount32) (uint32 word);
|
extern PGDLLIMPORT int (*pg_popcount32) (uint32 word);
|
||||||
extern PGDLLIMPORT int (*pg_popcount64) (uint64 word);
|
extern PGDLLIMPORT int (*pg_popcount64) (uint64 word);
|
||||||
@ -322,7 +322,7 @@ extern int pg_popcount64(uint64 word);
|
|||||||
extern uint64 pg_popcount_optimized(const char *buf, int bytes);
|
extern uint64 pg_popcount_optimized(const char *buf, int bytes);
|
||||||
extern uint64 pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask);
|
extern uint64 pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask);
|
||||||
|
|
||||||
#endif /* TRY_POPCNT_FAST */
|
#endif /* TRY_POPCNT_X86_64 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of 1-bits in buf.
|
* Returns the number of 1-bits in buf.
|
||||||
|
@ -108,7 +108,7 @@ static inline int pg_popcount64_slow(uint64 word);
|
|||||||
static uint64 pg_popcount_slow(const char *buf, int bytes);
|
static uint64 pg_popcount_slow(const char *buf, int bytes);
|
||||||
static uint64 pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask);
|
static uint64 pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask);
|
||||||
|
|
||||||
#ifdef TRY_POPCNT_FAST
|
#ifdef TRY_POPCNT_X86_64
|
||||||
static bool pg_popcount_available(void);
|
static bool pg_popcount_available(void);
|
||||||
static int pg_popcount32_choose(uint32 word);
|
static int pg_popcount32_choose(uint32 word);
|
||||||
static int pg_popcount64_choose(uint64 word);
|
static int pg_popcount64_choose(uint64 word);
|
||||||
@ -123,9 +123,9 @@ int (*pg_popcount32) (uint32 word) = pg_popcount32_choose;
|
|||||||
int (*pg_popcount64) (uint64 word) = pg_popcount64_choose;
|
int (*pg_popcount64) (uint64 word) = pg_popcount64_choose;
|
||||||
uint64 (*pg_popcount_optimized) (const char *buf, int bytes) = pg_popcount_choose;
|
uint64 (*pg_popcount_optimized) (const char *buf, int bytes) = pg_popcount_choose;
|
||||||
uint64 (*pg_popcount_masked_optimized) (const char *buf, int bytes, bits8 mask) = pg_popcount_masked_choose;
|
uint64 (*pg_popcount_masked_optimized) (const char *buf, int bytes, bits8 mask) = pg_popcount_masked_choose;
|
||||||
#endif /* TRY_POPCNT_FAST */
|
#endif /* TRY_POPCNT_X86_64 */
|
||||||
|
|
||||||
#ifdef TRY_POPCNT_FAST
|
#ifdef TRY_POPCNT_X86_64
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return true if CPUID indicates that the POPCNT instruction is available.
|
* Return true if CPUID indicates that the POPCNT instruction is available.
|
||||||
@ -337,7 +337,7 @@ pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask)
|
|||||||
return popcnt;
|
return popcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* TRY_POPCNT_FAST */
|
#endif /* TRY_POPCNT_X86_64 */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -486,13 +486,13 @@ pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask)
|
|||||||
return popcnt;
|
return popcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TRY_POPCNT_FAST
|
#ifndef TRY_POPCNT_X86_64
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When the POPCNT instruction is not available, there's no point in using
|
* When the POPCNT instruction is not available, there's no point in using
|
||||||
* function pointers to vary the implementation between the fast and slow
|
* function pointers to vary the implementation between the fast and slow
|
||||||
* method. We instead just make these actual external functions when
|
* method. We instead just make these actual external functions when
|
||||||
* TRY_POPCNT_FAST is not defined. The compiler should be able to inline
|
* TRY_POPCNT_X86_64 is not defined. The compiler should be able to inline
|
||||||
* the slow versions here.
|
* the slow versions here.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@ -527,4 +527,4 @@ pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask)
|
|||||||
return pg_popcount_masked_slow(buf, bytes, mask);
|
return pg_popcount_masked_slow(buf, bytes, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !TRY_POPCNT_FAST */
|
#endif /* !TRY_POPCNT_X86_64 */
|
||||||
|
@ -27,11 +27,11 @@
|
|||||||
#include "port/pg_bitutils.h"
|
#include "port/pg_bitutils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It's probably unlikely that TRY_POPCNT_FAST won't be set if we are able to
|
* It's probably unlikely that TRY_POPCNT_X86_64 won't be set if we are able to
|
||||||
* use AVX-512 intrinsics, but we check it anyway to be sure. We piggy-back on
|
* use AVX-512 intrinsics, but we check it anyway to be sure. We piggy-back on
|
||||||
* the function pointers that are only used when TRY_POPCNT_FAST is set.
|
* the function pointers that are only used when TRY_POPCNT_X86_64 is set.
|
||||||
*/
|
*/
|
||||||
#ifdef TRY_POPCNT_FAST
|
#ifdef TRY_POPCNT_X86_64
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Does CPUID say there's support for XSAVE instructions?
|
* Does CPUID say there's support for XSAVE instructions?
|
||||||
@ -219,5 +219,5 @@ pg_popcount_masked_avx512(const char *buf, int bytes, bits8 mask)
|
|||||||
return _mm512_reduce_add_epi64(accum);
|
return _mm512_reduce_add_epi64(accum);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* TRY_POPCNT_FAST */
|
#endif /* TRY_POPCNT_X86_64 */
|
||||||
#endif /* USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */
|
#endif /* USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */
|
||||||
|
Reference in New Issue
Block a user