};
/*
- * pg_popcount32_slow
+ * pg_popcount32_portable
* Return the number of 1 bits set in word
*/
int
-pg_popcount32_slow(uint32 word)
+pg_popcount32_portable(uint32 word)
{
#ifdef HAVE__BUILTIN_POPCOUNT
return __builtin_popcount(word);
}
/*
- * pg_popcount64_slow
+ * pg_popcount64_portable
* Return the number of 1 bits set in word
*/
int
-pg_popcount64_slow(uint64 word)
+pg_popcount64_portable(uint64 word)
{
#ifdef HAVE__BUILTIN_POPCOUNT
#if SIZEOF_LONG == 8
}
/*
- * pg_popcount_slow
+ * pg_popcount_portable
* Returns the number of 1-bits in buf
*/
uint64
-pg_popcount_slow(const char *buf, int bytes)
+pg_popcount_portable(const char *buf, int bytes)
{
uint64 popcnt = 0;
while (bytes >= 8)
{
- popcnt += pg_popcount64_slow(*words++);
+ popcnt += pg_popcount64_portable(*words++);
bytes -= 8;
}
while (bytes >= 4)
{
- popcnt += pg_popcount32_slow(*words++);
+ popcnt += pg_popcount32_portable(*words++);
bytes -= 4;
}
}
/*
- * pg_popcount_masked_slow
+ * pg_popcount_masked_portable
* Returns the number of 1-bits in buf after applying the mask to each byte
*/
uint64
-pg_popcount_masked_slow(const char *buf, int bytes, bits8 mask)
+pg_popcount_masked_portable(const char *buf, int bytes, bits8 mask)
{
uint64 popcnt = 0;
while (bytes >= 8)
{
- popcnt += pg_popcount64_slow(*words++ & maskv);
+ popcnt += pg_popcount64_portable(*words++ & maskv);
bytes -= 8;
}
while (bytes >= 4)
{
- popcnt += pg_popcount32_slow(*words++ & maskv);
+ popcnt += pg_popcount32_portable(*words++ & maskv);
bytes -= 4;
}
/*
* When special CPU instructions are not available, there's no point in using
- * function pointers to vary the implementation between the fast and slow
- * method. We instead just make these actual external functions. The compiler
- * should be able to inline the slow versions here.
+ * 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.
*/
int
pg_popcount32(uint32 word)
{
- return pg_popcount32_slow(word);
+ return pg_popcount32_portable(word);
}
int
pg_popcount64(uint64 word)
{
- return pg_popcount64_slow(word);
+ return pg_popcount64_portable(word);
}
/*
uint64
pg_popcount_optimized(const char *buf, int bytes)
{
- return pg_popcount_slow(buf, bytes);
+ return pg_popcount_portable(buf, bytes);
}
/*
uint64
pg_popcount_masked_optimized(const char *buf, int bytes, bits8 mask)
{
- return pg_popcount_masked_slow(buf, bytes, mask);
+ return pg_popcount_masked_portable(buf, bytes, mask);
}
#endif /* ! TRY_POPCNT_X86_64 && ! POPCNT_AARCH64 */
/*
* The SSE4.2 versions are built regardless of whether we are building the
* AVX-512 versions.
+ *
+ * Technically, POPCNT is not part of SSE4.2, and isn't even a vector
+ * operation, but in practice this is close enough, and "sse42" seems easier to
+ * follow than "popcnt" for these names.
*/
-static inline int pg_popcount32_fast(uint32 word);
-static inline int pg_popcount64_fast(uint64 word);
-static uint64 pg_popcount_fast(const char *buf, int bytes);
-static uint64 pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask);
+static inline int pg_popcount32_sse42(uint32 word);
+static inline int pg_popcount64_sse42(uint64 word);
+static uint64 pg_popcount_sse42(const char *buf, int bytes);
+static uint64 pg_popcount_masked_sse42(const char *buf, int bytes, bits8 mask);
/*
* These are the AVX-512 implementations of the popcount functions.
* Return true if CPUID indicates that the POPCNT instruction is available.
*/
static bool
-pg_popcount_available(void)
+pg_popcount_sse42_available(void)
{
unsigned int exx[4] = {0, 0, 0, 0};
static inline void
choose_popcount_functions(void)
{
- if (pg_popcount_available())
+ if (pg_popcount_sse42_available())
{
- pg_popcount32 = pg_popcount32_fast;
- pg_popcount64 = pg_popcount64_fast;
- pg_popcount_optimized = pg_popcount_fast;
- pg_popcount_masked_optimized = pg_popcount_masked_fast;
+ pg_popcount32 = pg_popcount32_sse42;
+ pg_popcount64 = pg_popcount64_sse42;
+ pg_popcount_optimized = pg_popcount_sse42;
+ pg_popcount_masked_optimized = pg_popcount_masked_sse42;
}
else
{
- pg_popcount32 = pg_popcount32_slow;
- pg_popcount64 = pg_popcount64_slow;
- pg_popcount_optimized = pg_popcount_slow;
- pg_popcount_masked_optimized = pg_popcount_masked_slow;
+ pg_popcount32 = pg_popcount32_portable;
+ pg_popcount64 = pg_popcount64_portable;
+ pg_popcount_optimized = pg_popcount_portable;
+ pg_popcount_masked_optimized = pg_popcount_masked_portable;
}
#ifdef USE_AVX512_POPCNT_WITH_RUNTIME_CHECK
#endif /* USE_AVX512_POPCNT_WITH_RUNTIME_CHECK */
/*
- * pg_popcount32_fast
+ * pg_popcount32_sse42
* Return the number of 1 bits set in word
*/
static inline int
-pg_popcount32_fast(uint32 word)
+pg_popcount32_sse42(uint32 word)
{
#ifdef _MSC_VER
return __popcnt(word);
}
/*
- * pg_popcount64_fast
+ * pg_popcount64_sse42
* Return the number of 1 bits set in word
*/
static inline int
-pg_popcount64_fast(uint64 word)
+pg_popcount64_sse42(uint64 word)
{
#ifdef _MSC_VER
return __popcnt64(word);
}
/*
- * pg_popcount_fast
+ * pg_popcount_sse42
* Returns the number of 1-bits in buf
*/
static uint64
-pg_popcount_fast(const char *buf, int bytes)
+pg_popcount_sse42(const char *buf, int bytes)
{
uint64 popcnt = 0;
while (bytes >= 8)
{
- popcnt += pg_popcount64_fast(*words++);
+ popcnt += pg_popcount64_sse42(*words++);
bytes -= 8;
}
while (bytes >= 4)
{
- popcnt += pg_popcount32_fast(*words++);
+ popcnt += pg_popcount32_sse42(*words++);
bytes -= 4;
}
}
/*
- * pg_popcount_masked_fast
+ * pg_popcount_masked_sse42
* Returns the number of 1-bits in buf after applying the mask to each byte
*/
static uint64
-pg_popcount_masked_fast(const char *buf, int bytes, bits8 mask)
+pg_popcount_masked_sse42(const char *buf, int bytes, bits8 mask)
{
uint64 popcnt = 0;
while (bytes >= 8)
{
- popcnt += pg_popcount64_fast(*words++ & maskv);
+ popcnt += pg_popcount64_sse42(*words++ & maskv);
bytes -= 8;
}
while (bytes >= 4)
{
- popcnt += pg_popcount32_fast(*words++ & maskv);
+ popcnt += pg_popcount32_sse42(*words++ & maskv);
bytes -= 4;
}