pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: David Rowley <david.rowley@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Using POPCNT and other advanced bit manipulation instructions
Date: Thu, 14 Feb 2019 00:24:50 -0500
Message-ID: <16168.1550121890@sss.pgh.pa.us> (raw)
In-Reply-To: <14024.1550119448@sss.pgh.pa.us>
References: <20190213221719.GA15976@alvherre.pgsql>
	<26998.1550097202@sss.pgh.pa.us>
	<27185.1550097476@sss.pgh.pa.us>
	<11319.1550115484@sss.pgh.pa.us>
	<CAEepm=0eyotC0jjVuX90vY2myxRodspDqfrBLa6hOS_MPFQyuQ@mail.gmail.com>
	<14024.1550119448@sss.pgh.pa.us>

Some further thoughts here ...

Does the "lzcnt" runtime probe actually do anything useful?
On the x86_64 compilers I tried (gcc 8.2.1 and 4.4.7), __builtin_clz
and __builtin_ctz compile to sequences involving bsrq and bsfq
regardless of -mpopcnt.  It's fairly hard to see how lzcnt would
buy anything over those sequences even if there were zero overhead
involved in using it.

Alvaro noted that the test programs used by c-compiler.m4 fail
to produce any actual code involving the builtin, because of
compile-time constant folding.  This seems pretty unwise.
I see that on my x86_64 compilers, without -mpopcnt,
__builtin_popcnt compiles to a call of some libgcc function
or other.  It's conceivable that on an (arguably misconfigured)
platform, these c-compiler.m4 tests would pass yet the build fails
at link because libgcc lacks the needed infrastructure.  These tests
should be coded in a way that doesn't allow the call to be optimized
away -- cf comments for PGAC_C_BUILTIN_OP_OVERFLOW.

Also, it's starting to seem like we have enough probes for compiler
builtins that we should fold them to use one set of infrastructure.
There are some like __builtin_constant_p that probably do need their
own custom tests, but these ones that just verify that a call
compiles seem pretty duplicative ...

			regards, tom lane




view thread (49+ messages)  latest in thread

Message-ID: <16168.1550121890@sss.pgh.pa.us>
Permalink:  ../16168.1550121890@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16168.1550121890@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, thomas.munro@enterprisedb.com, alvherre@2ndquadrant.com, andrew@tao11.riddles.org.uk, david.rowley@2ndquadrant.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Using POPCNT and other advanced bit manipulation instructions
  In-Reply-To: <16168.1550121890@sss.pgh.pa.us>

* 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