1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Fix compiler builtin usage in new pg_bitutils.c

Split out these new functions in three parts: one in a new file that
uses the compiler builtin and gets compiled with the -mpopcnt compiler
option if it exists; another one that uses the compiler builtin but not
the compiler option; and finally the fallback with open-coded
algorithms.

Split out the configure logic: in the original commit, it was selecting
to use the -mpopcnt compiler switch together with deciding whether to
use the compiler builtin, but those two things are really separate.
Split them out.  Also, expose whether the builtin exists to
Makefile.global, so that src/port's Makefile can decide whether to
compile the hw-optimized file.

Remove CPUID test for CTZ/CLZ.  Make pg_{right,left}most_ones use either
the compiler intrinsic or open-coded algo; trying to use the
HW-optimized version is a waste of time.  Make them static inline
functions.

Discussion: https://postgr.es/m/20190213221719.GA15976@alvherre.pgsql
This commit is contained in:
Alvaro Herrera
2019-02-15 13:07:02 -03:00
parent b060e6c1f5
commit fc6c72747a
8 changed files with 327 additions and 376 deletions

View File

@ -381,22 +381,16 @@ fi])# PGAC_C_BUILTIN_OP_OVERFLOW
# PGAC_C_BUILTIN_POPCOUNT
# -------------------------
AC_DEFUN([PGAC_C_BUILTIN_POPCOUNT],
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_popcount])])dnl
AC_CACHE_CHECK([for __builtin_popcount], [Ac_cachevar],
[pgac_save_CFLAGS=$CFLAGS
CFLAGS="$pgac_save_CFLAGS -mpopcnt"
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[static int x = __builtin_popcount(255);])],
[Ac_cachevar=yes],
[Ac_cachevar=no])
CFLAGS="$pgac_save_CFLAGS"])
if test x"$Ac_cachevar" = x"yes"; then
CFLAGS_POPCNT="-mpopcnt"
[AC_CACHE_CHECK([for __builtin_popcount], pgac_cv__builtin_popcount,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[static int x = __builtin_popcount(255);]
)],
[pgac_cv__builtin_popcount=yes],
[pgac_cv__builtin_popcount=no])])
if test x"$pgac_cv__builtin_popcount" = x"yes"; then
AC_DEFINE(HAVE__BUILTIN_POPCOUNT, 1,
[Define to 1 if your compiler understands __builtin_popcount.])
fi
undefine([Ac_cachevar])dnl
])# PGAC_C_BUILTIN_POPCOUNT
fi])# PGAC_C_BUILTIN_POPCOUNT