1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Fix portability issues in pg_bitutils

We were using uint64 function arguments as "long int" arguments to
compiler builtins, which fails on machines where long ints are 32 bits:
the upper half of the uint64 was being ignored.  Fix by using the "ll"
builtin variants instead, which on those machines take 64 bit arguments.

Also, remove configure tests for __builtin_popcountl() (as well as
"long" variants for ctz and clz): the theory here is that any compiler
version will provide all widths or none, so one test suffices.  Were
this theory to be wrong, we'd have to add tests for
__builtin_popcountll() and friends, which would be tedious.

Per failures in buildfarm member lapwing and ensuing discussion.
This commit is contained in:
Alvaro Herrera
2019-02-13 20:09:48 -03:00
parent 80c468b4a4
commit 109de05cbb
6 changed files with 98 additions and 256 deletions

View File

@ -400,28 +400,6 @@ undefine([Ac_cachevar])dnl
# PGAC_C_BUILTIN_POPCOUNTL
# -------------------------
AC_DEFUN([PGAC_C_BUILTIN_POPCOUNTL],
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_popcountl])])dnl
AC_CACHE_CHECK([for __builtin_popcountl], [Ac_cachevar],
[pgac_save_CFLAGS=$CFLAGS
CFLAGS="$pgac_save_CFLAGS -mpopcnt"
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[static int x = __builtin_popcountl(255);])],
[Ac_cachevar=yes],
[Ac_cachevar=no])
CFLAGS="$pgac_save_CFLAGS"])
if test x"$Ac_cachevar" = x"yes"; then
CFLAGS_POPCNT="-mpopcnt"
AC_DEFINE(HAVE__BUILTIN_POPCOUNTL, 1,
[Define to 1 if your compiler understands __builtin_popcountl.])
fi
undefine([Ac_cachevar])dnl
])# PGAC_C_BUILTIN_POPCOUNTL
# PGAC_C_BUILTIN_CTZ
# -------------------------
# Check if the C compiler understands __builtin_ctz(),
@ -440,24 +418,6 @@ fi])# PGAC_C_BUILTIN_CTZ
# PGAC_C_BUILTIN_CTZL
# -------------------------
# Check if the C compiler understands __builtin_ctzl(),
# and define HAVE__BUILTIN_CTZL if so.
AC_DEFUN([PGAC_C_BUILTIN_CTZL],
[AC_CACHE_CHECK(for __builtin_ctzl, pgac_cv__builtin_ctzl,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[static int x = __builtin_ctzl(256);]
)],
[pgac_cv__builtin_ctzl=yes],
[pgac_cv__builtin_ctzl=no])])
if test x"$pgac_cv__builtin_ctzl" = xyes ; then
AC_DEFINE(HAVE__BUILTIN_CTZL, 1,
[Define to 1 if your compiler understands __builtin_ctzl.])
fi])# PGAC_C_BUILTIN_CTZL
# PGAC_C_BUILTIN_CLZ
# -------------------------
# Check if the C compiler understands __builtin_clz(),
@ -476,24 +436,6 @@ fi])# PGAC_C_BUILTIN_CLZ
# PGAC_C_BUILTIN_CLZL
# -------------------------
# Check if the C compiler understands __builtin_clzl(),
# and define HAVE__BUILTIN_CLZL if so.
AC_DEFUN([PGAC_C_BUILTIN_CLZL],
[AC_CACHE_CHECK(for __builtin_clzl, pgac_cv__builtin_clzl,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[static int x = __builtin_clzl(256);]
)],
[pgac_cv__builtin_clzl=yes],
[pgac_cv__builtin_clzl=no])])
if test x"$pgac_cv__builtin_clzl" = xyes ; then
AC_DEFINE(HAVE__BUILTIN_CLZL, 1,
[Define to 1 if your compiler understands __builtin_clzl.])
fi])# PGAC_C_BUILTIN_CLZL
# PGAC_C_BUILTIN_UNREACHABLE
# --------------------------
# Check if the C compiler understands __builtin_unreachable(),