diff options
| author | Alvaro Herrera | 2019-02-13 19:10:06 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2019-02-13 19:10:06 +0000 |
| commit | 711bab1e4d19b5c9967328315a542d93386b1ac5 (patch) | |
| tree | 65ee7e238438642e152ff52b24f042eb1491e28a /src/include | |
| parent | 754ca99314e9e1debe855b0462869ef6e58b7e7a (diff) | |
Add basic support for using the POPCNT and SSE4.2s LZCNT opcodes
These opcodes have been around in the AMD world since 2007, and 2008 in
the case of intel. They're supported in GCC and Clang via some __builtin
macros. The opcodes may be unavailable during runtime, in which case we
fall back on a C-based implementation of the code. In order to get the
POPCNT instruction we must pass the -mpopcnt option to the compiler. We
do this only for the pg_bitutils.c file.
David Rowley (with fragments taken from a patch by Thomas Munro)
Discussion: https://postgr.es/m/CAKJS1f9WTAGG1tPeJnD18hiQW5gAk59fQ6WK-vfdAKEHyRg2RA@mail.gmail.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/pg_config.h.in | 18 | ||||
| -rw-r--r-- | src/include/pg_config.h.win32 | 18 | ||||
| -rw-r--r-- | src/include/port/pg_bitutils.h | 26 |
3 files changed, 62 insertions, 0 deletions
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index b38b0ae1899..53a11f2ab82 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -754,6 +754,24 @@ /* Define to 1 if your compiler understands __builtin_$op_overflow. */ #undef HAVE__BUILTIN_OP_OVERFLOW +/* Define to 1 if your compiler understands __builtin_popcount. */ +#undef HAVE__BUILTIN_POPCOUNT + +/* Define to 1 if your compiler understands __builtin_popcountl. */ +#undef HAVE__BUILTIN_POPCOUNTL + +/* Define to 1 if your compiler understands __builtin_ctz. */ +#undef HAVE__BUILTIN_CTZ + +/* Define to 1 if your compiler understands __builtin_ctzl. */ +#undef HAVE__BUILTIN_CTZL + +/* Define to 1 if your compiler understands __builtin_clz. */ +#undef HAVE__BUILTIN_CLZ + +/* Define to 1 if your compiler understands __builtin_clzl. */ +#undef HAVE__BUILTIN_CLZL + /* Define to 1 if your compiler understands __builtin_types_compatible_p. */ #undef HAVE__BUILTIN_TYPES_COMPATIBLE_P diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index 160fa1279e4..e45db7a12ea 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -593,6 +593,24 @@ /* Define to 1 if your compiler understands __builtin_$op_overflow. */ /* #undef HAVE__BUILTIN_OP_OVERFLOW */ +/* Define to 1 if your compiler understands __builtin_popcount. */ +/* #undef HAVE__BUILTIN_POPCOUNT */ + +/* Define to 1 if your compiler understands __builtin_popcountl. */ +/* #undef HAVE__BUILTIN_POPCOUNTL */ + +/* Define to 1 if your compiler understands __builtin_ctz. */ +/* #undef HAVE__BUILTIN_CTZ */ + +/* Define to 1 if your compiler understands __builtin_ctzl. */ +/* #undef HAVE__BUILTIN_CTZL */ + +/* Define to 1 if your compiler understands __builtin_clz. */ +/* #undef HAVE__BUILTIN_CLZ */ + +/* Define to 1 if your compiler understands __builtin_clzl. */ +/* #undef HAVE__BUILTIN_CLZL */ + /* Define to 1 if your compiler understands __builtin_types_compatible_p. */ /* #undef HAVE__BUILTIN_TYPES_COMPATIBLE_P */ diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h new file mode 100644 index 00000000000..148c5550573 --- /dev/null +++ b/src/include/port/pg_bitutils.h @@ -0,0 +1,26 @@ +/*------------------------------------------------------------------------ - + * + * pg_bitutils.h + * miscellaneous functions for bit-wise operations. + * + * + * Portions Copyright(c) 2019, PostgreSQL Global Development Group + * + * src/include/port/pg_bitutils.h + * + *------------------------------------------------------------------------ - + */ + +#ifndef PG_BITUTILS_H +#define PG_BITUTILS_H + +extern int (*pg_popcount32) (uint32 word); +extern int (*pg_popcount64) (uint64 word); +extern int (*pg_rightmost_one32) (uint32 word); +extern int (*pg_rightmost_one64) (uint64 word); +extern int (*pg_leftmost_one32) (uint32 word); +extern int (*pg_leftmost_one64) (uint64 word); + +extern uint64 pg_popcount(const char *buf, int bytes); + +#endif /* PG_BITUTILS_H */ |
