Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02a6a54

Browse files
committed
Make use of compiler builtins and/or assembly for CLZ, CTZ, POPCNT.
Test for the compiler builtins __builtin_clz, __builtin_ctz, and__builtin_popcount, and make use of these in preference tohandwritten C code if they're available. Create src/portinfrastructure for "leftmost one", "rightmost one", and "popcount"so as to centralize these decisions.On x86_64, __builtin_popcount generally won't make use of the POPCNTopcode because that's not universally supported yet. Provide codethat checks CPUID and then calls POPCNT via asm() if available.This requires indirecting through a function pointer, which isan annoying amount of overhead for a one-instruction operation,but it's probably not worth working harder than this for ourcurrent use-cases.I'm not sure we've found all the existing places that could profitfrom this new infrastructure; but we at least touched all theones that used copied-and-pasted versions of the bitmapset.c code,and got rid of multiple copies of the associated constant arrays.While at it, replace c-compiler.m4's one-per-builtin-functionmacros with a single one that can handle all the cases we needto worry about so far. Also, because I'm paranoid, make thosechecks into AC_LINK checks rather than just AC_COMPILE; theformer coding failed to verify that libgcc has support for thebuiltin, in cases where it's not inline code.David Rowley, Thomas Munro, Alvaro Herrera, Tom LaneDiscussion:https://postgr.es/m/CAKJS1f9WTAGG1tPeJnD18hiQW5gAk59fQ6WK-vfdAKEHyRg2RA@mail.gmail.com
1 parent72880ac commit02a6a54

File tree

16 files changed

+879
-417
lines changed

16 files changed

+879
-417
lines changed

‎config/c-compiler.m4

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -273,60 +273,6 @@ AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
273273
fi])# PGAC_C_TYPES_COMPATIBLE
274274

275275

276-
# PGAC_C_BUILTIN_BSWAP16
277-
# -------------------------
278-
# Check if the C compiler understands __builtin_bswap16(),
279-
# and define HAVE__BUILTIN_BSWAP16 if so.
280-
AC_DEFUN([PGAC_C_BUILTIN_BSWAP16],
281-
[AC_CACHE_CHECK(for__builtin_bswap16,pgac_cv__builtin_bswap16,
282-
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
283-
[static unsigned long int x = __builtin_bswap16(0xaabb);]
284-
)],
285-
[pgac_cv__builtin_bswap16=yes],
286-
[pgac_cv__builtin_bswap16=no])])
287-
if test x"$pgac_cv__builtin_bswap16" = xyes ; then
288-
AC_DEFINE(HAVE__BUILTIN_BSWAP16,1,
289-
[Define to 1 if your compiler understands __builtin_bswap16.])
290-
fi])# PGAC_C_BUILTIN_BSWAP16
291-
292-
293-
294-
# PGAC_C_BUILTIN_BSWAP32
295-
# -------------------------
296-
# Check if the C compiler understands __builtin_bswap32(),
297-
# and define HAVE__BUILTIN_BSWAP32 if so.
298-
AC_DEFUN([PGAC_C_BUILTIN_BSWAP32],
299-
[AC_CACHE_CHECK(for__builtin_bswap32,pgac_cv__builtin_bswap32,
300-
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
301-
[static unsigned long int x = __builtin_bswap32(0xaabbccdd);]
302-
)],
303-
[pgac_cv__builtin_bswap32=yes],
304-
[pgac_cv__builtin_bswap32=no])])
305-
if test x"$pgac_cv__builtin_bswap32" = xyes ; then
306-
AC_DEFINE(HAVE__BUILTIN_BSWAP32,1,
307-
[Define to 1 if your compiler understands __builtin_bswap32.])
308-
fi])# PGAC_C_BUILTIN_BSWAP32
309-
310-
311-
312-
# PGAC_C_BUILTIN_BSWAP64
313-
# -------------------------
314-
# Check if the C compiler understands __builtin_bswap64(),
315-
# and define HAVE__BUILTIN_BSWAP64 if so.
316-
AC_DEFUN([PGAC_C_BUILTIN_BSWAP64],
317-
[AC_CACHE_CHECK(for__builtin_bswap64,pgac_cv__builtin_bswap64,
318-
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
319-
[static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);]
320-
)],
321-
[pgac_cv__builtin_bswap64=yes],
322-
[pgac_cv__builtin_bswap64=no])])
323-
if test x"$pgac_cv__builtin_bswap64" = xyes ; then
324-
AC_DEFINE(HAVE__BUILTIN_BSWAP64,1,
325-
[Define to 1 if your compiler understands __builtin_bswap64.])
326-
fi])# PGAC_C_BUILTIN_BSWAP64
327-
328-
329-
330276
# PGAC_C_BUILTIN_CONSTANT_P
331277
# -------------------------
332278
# Check if the C compiler understands __builtin_constant_p(),
@@ -423,6 +369,33 @@ fi])# PGAC_C_COMPUTED_GOTO
423369

424370

425371

372+
# PGAC_CHECK_BUILTIN_FUNC
373+
# -----------------------
374+
# This is similar to AC_CHECK_FUNCS(), except that it will work for compiler
375+
# builtin functions, as that usually fails to.
376+
# The first argument is the function name, eg [__builtin_clzl], and the
377+
# second is its argument list, eg [unsigned long x]. The current coding
378+
# works only for a single argument named x; we might generalize that later.
379+
# It's assumed that the function's result type is coercible to int.
380+
# On success, we define "HAVEfuncname" (there's usually more than enough
381+
# underscores already, so we don't add another one).
382+
AC_DEFUN([PGAC_CHECK_BUILTIN_FUNC],
383+
[AC_CACHE_CHECK(for$1,pgac_cv$1,
384+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
385+
int
386+
call$1($2)
387+
{
388+
return$1(x);
389+
}],[])],
390+
[pgac_cv$1=yes],
391+
[pgac_cv$1=no])])
392+
if test x"${pgac_cv$1}" = xyes ; then
393+
AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE$1]),1,
394+
[Define to 1 if your compiler understands$1.])
395+
fi])# PGAC_CHECK_BUILTIN_FUNC
396+
397+
398+
426399
# PGAC_PROG_VARCC_VARFLAGS_OPT
427400
# -----------------------
428401
# Given a compiler, variable name and a string, check if the compiler

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp