Skip to content

Commit 9ac6f7e

Browse files
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
1 parent a5419bc commit 9ac6f7e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/include/port/pg_bitutils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,11 @@ pg_ceil_log2_64(uint64 num)
294294
*/
295295
#ifdef HAVE_X86_64_POPCNTQ
296296
#if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID)
297-
#define TRY_POPCNT_FAST 1
297+
#define TRY_POPCNT_X86_64 1
298298
#endif
299299
#endif
300300

301-
#ifdef TRY_POPCNT_FAST
301+
#ifdef TRY_POPCNT_X86_64
302302
/* Attempt to use the POPCNT instruction, but perform a runtime check first */
303303
extern PGDLLIMPORT int (*pg_popcount32) (uint32 word);
304304
extern PGDLLIMPORT int (*pg_popcount64) (uint64 word);
@@ -322,7 +322,7 @@ extern int pg_popcount64(uint64 word);
322322
extern uint64 pg_popcount_optimized(const char *buf, int bytes);
323323
extern uint64 pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask);
324324

325-
#endif /* TRY_POPCNT_FAST */
325+
#endif /* TRY_POPCNT_X86_64 */
326326

327327
/*
328328
* Returns the number of 1-bits in buf.

src/port/pg_bitutils.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline int pg_popcount64_slow(uint64 word);
108108
static uint64 pg_popcount_slow(const char *buf, int bytes);
109109
static uint64 pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask);
110110

111-
#ifdef TRY_POPCNT_FAST
111+
#ifdef TRY_POPCNT_X86_64
112112
static bool pg_popcount_available(void);
113113
static int pg_popcount32_choose(uint32 word);
114114
static int pg_popcount64_choose(uint64 word);
@@ -123,9 +123,9 @@ int (*pg_popcount32) (uint32 word) = pg_popcount32_choose;
123123
int (*pg_popcount64) (uint64 word) = pg_popcount64_choose;
124124
uint64 (*pg_popcount_optimized) (const char *buf, int bytes) = pg_popcount_choose;
125125
uint64 (*pg_popcount_masked_optimized) (const char *buf, int bytes, bits8 mask) = pg_popcount_masked_choose;
126-
#endif /* TRY_POPCNT_FAST */
126+
#endif /* TRY_POPCNT_X86_64 */
127127

128-
#ifdef TRY_POPCNT_FAST
128+
#ifdef TRY_POPCNT_X86_64
129129

130130
/*
131131
* 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)
337337
return popcnt;
338338
}
339339

340-
#endif /* TRY_POPCNT_FAST */
340+
#endif /* TRY_POPCNT_X86_64 */
341341

342342

343343
/*
@@ -486,13 +486,13 @@ pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask)
486486
return popcnt;
487487
}
488488

489-
#ifndef TRY_POPCNT_FAST
489+
#ifndef TRY_POPCNT_X86_64
490490

491491
/*
492492
* When the POPCNT instruction is not available, there's no point in using
493493
* function pointers to vary the implementation between the fast and slow
494494
* method. We instead just make these actual external functions when
495-
* TRY_POPCNT_FAST is not defined. The compiler should be able to inline
495+
* TRY_POPCNT_X86_64 is not defined. The compiler should be able to inline
496496
* the slow versions here.
497497
*/
498498
int
@@ -527,4 +527,4 @@ pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask)
527527
return pg_popcount_masked_slow(buf, bytes, mask);
528528
}
529529

530-
#endif /* !TRY_POPCNT_FAST */
530+
#endif /* !TRY_POPCNT_X86_64 */

src/port/pg_popcount_avx512.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
#include "port/pg_bitutils.h"
2828

2929
/*
30-
* It's probably unlikely that TRY_POPCNT_FAST won't be set if we are able to
30+
* It's probably unlikely that TRY_POPCNT_X86_64 won't be set if we are able to
3131
* use AVX-512 intrinsics, but we check it anyway to be sure. We piggy-back on
32-
* the function pointers that are only used when TRY_POPCNT_FAST is set.
32+
* the function pointers that are only used when TRY_POPCNT_X86_64 is set.
3333
*/
34-
#ifdef TRY_POPCNT_FAST
34+
#ifdef TRY_POPCNT_X86_64
3535

3636
/*
3737
* Does CPUID say there's support for XSAVE instructions?
@@ -219,5 +219,5 @@ pg_popcount_masked_avx512(const char *buf, int bytes, bits8 mask)
219219
return _mm512_reduce_add_epi64(accum);
220220
}
221221

222-
#endif /* TRY_POPCNT_FAST */
222+
#endif /* TRY_POPCNT_X86_64 */
223223
#endif /* USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */

0 commit comments

Comments
 (0)