diff options
author | Alvaro Herrera | 2019-02-15 16:07:02 +0000 |
---|---|---|
committer | Alvaro Herrera | 2019-02-15 16:39:56 +0000 |
commit | fc6c72747ae6db6909fcd7d1adbc3d923ec1fffa (patch) | |
tree | 56b2b45a42608e52eae0d2602e067f7981c164c3 /configure | |
parent | b060e6c1f5b4609718468a0b6562dd03db26ea46 (diff) |
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
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/configure b/configure index 73e9c235b69..2e3cc372a6e 100755 --- a/configure +++ b/configure @@ -651,7 +651,7 @@ CFLAGS_ARMV8_CRC32C CFLAGS_SSE42 have_win32_dbghelp LIBOBJS -CFLAGS_POPCNT +have__builtin_popcount UUID_LIBS LDAP_LIBS_BE LDAP_LIBS_FE @@ -733,6 +733,7 @@ CPP BITCODE_CXXFLAGS BITCODE_CFLAGS CFLAGS_VECTOR +CFLAGS_POPCNT PERMIT_DECLARATION_AFTER_STATEMENT LLVM_BINPATH LLVM_CXXFLAGS @@ -6581,6 +6582,48 @@ fi fi +# Optimization flags and options for bit-twiddling +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -mpopcnt, for CFLAGS_POPCNT" >&5 +$as_echo_n "checking whether ${CC} supports -mpopcnt, for CFLAGS_POPCNT... " >&6; } +if ${pgac_cv_prog_CC_cflags__mpopcnt+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CFLAGS=$CFLAGS +pgac_save_CC=$CC +CC=${CC} +CFLAGS="${CFLAGS_POPCNT} -mpopcnt" +ac_save_c_werror_flag=$ac_c_werror_flag +ac_c_werror_flag=yes +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + pgac_cv_prog_CC_cflags__mpopcnt=yes +else + pgac_cv_prog_CC_cflags__mpopcnt=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_c_werror_flag=$ac_save_c_werror_flag +CFLAGS="$pgac_save_CFLAGS" +CC="$pgac_save_CC" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__mpopcnt" >&5 +$as_echo "$pgac_cv_prog_CC_cflags__mpopcnt" >&6; } +if test x"$pgac_cv_prog_CC_cflags__mpopcnt" = x"yes"; then + CFLAGS_POPCNT="${CFLAGS_POPCNT} -mpopcnt" +fi + + + + CFLAGS_VECTOR=$CFLAGS_VECTOR @@ -14111,32 +14154,28 @@ $as_echo "#define HAVE__BUILTIN_CTZ 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_popcount" >&5 $as_echo_n "checking for __builtin_popcount... " >&6; } -if ${pgac_cv_popcount+:} false; then : +if ${pgac_cv__builtin_popcount+:} false; then : $as_echo_n "(cached) " >&6 else - pgac_save_CFLAGS=$CFLAGS -CFLAGS="$pgac_save_CFLAGS -mpopcnt" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ static int x = __builtin_popcount(255); + _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_popcount=yes + pgac_cv__builtin_popcount=yes else - pgac_cv_popcount=no + pgac_cv__builtin_popcount=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -CFLAGS="$pgac_save_CFLAGS" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_popcount" >&5 -$as_echo "$pgac_cv_popcount" >&6; } -if test x"$pgac_cv_popcount" = x"yes"; then - CFLAGS_POPCNT="-mpopcnt" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__builtin_popcount" >&5 +$as_echo "$pgac_cv__builtin_popcount" >&6; } +if test x"$pgac_cv__builtin_popcount" = x"yes"; then $as_echo "#define HAVE__BUILTIN_POPCOUNT 1" >>confdefs.h fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_unreachable" >&5 $as_echo_n "checking for __builtin_unreachable... " >&6; } if ${pgac_cv__builtin_unreachable+:} false; then : @@ -14654,6 +14693,7 @@ $as_echo "#define LOCALE_T_IN_XLOCALE 1" >>confdefs.h fi +have__builtin_popcount=$pgac_cv__builtin_popcount # MSVC doesn't cope well with defining restrict to __restrict, the |