From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Make use of compiler builtins and/or assembly for CLZ, CTZ, POPC
Date: Sat, 16 Feb 2019 04:23:44 +0000
Message-ID: <E1gurVw-0007kj-DV@gemulon.postgresql.org> (raw)
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 to
handwritten C code if they're available. Create src/port
infrastructure 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 POPCNT
opcode because that's not universally supported yet. Provide code
that checks CPUID and then calls POPCNT via asm() if available.
This requires indirecting through a function pointer, which is
an annoying amount of overhead for a one-instruction operation,
but it's probably not worth working harder than this for our
current use-cases.
I'm not sure we've found all the existing places that could profit
from this new infrastructure; but we at least touched all the
ones 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-function
macros with a single one that can handle all the cases we need
to worry about so far. Also, because I'm paranoid, make those
checks into AC_LINK checks rather than just AC_COMPILE; the
former coding failed to verify that libgcc has support for the
builtin, in cases where it's not inline code.
David Rowley, Thomas Munro, Alvaro Herrera, Tom Lane
Discussion: https://postgr.es/m/CAKJS1f9WTAGG1tPeJnD18hiQW5gAk59fQ6WK-vfdAKEHyRg2RA@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/02a6a54ecd6632f974b1b4eebfb2373363431084
Modified Files
--------------
config/c-compiler.m4 | 81 +++-----
configure | 347 +++++++++++++++++++++++++-------
configure.in | 35 +++-
contrib/intarray/_intbig_gist.c | 32 +--
contrib/ltree/_ltree_gist.c | 32 +--
contrib/pg_trgm/trgm_gist.c | 31 +--
src/backend/access/heap/visibilitymap.c | 74 +++----
src/backend/lib/bloomfilter.c | 15 +-
src/backend/nodes/bitmapset.c | 130 ++----------
src/backend/utils/adt/tsgistidx.c | 31 +--
src/include/pg_config.h.in | 12 ++
src/include/pg_config.h.win32 | 12 ++
src/include/port/pg_bitutils.h | 139 +++++++++++++
src/port/Makefile | 2 +-
src/port/pg_bitutils.c | 321 +++++++++++++++++++++++++++++
src/tools/msvc/Mkvcbuild.pm | 2 +-
16 files changed, 879 insertions(+), 417 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Make use of compiler builtins and/or assembly for CLZ, CTZ, POPC
In-Reply-To: <E1gurVw-0007kj-DV@gemulon.postgresql.org>
References: <E1gurVw-0007kj-DV@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox