Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufrp-00072h-U7 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 15:57:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gufrn-0005Gi-QU for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 15:57:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufrn-0005AX-GL for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 15:57:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufrk-0006yv-J1 for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 15:57:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x1FFvK6j003294; Fri, 15 Feb 2019 10:57:20 -0500 From: Tom Lane To: Alvaro Herrera cc: Thomas Munro , Andrew Gierth , David Rowley , PostgreSQL Hackers Subject: Re: Using POPCNT and other advanced bit manipulation instructions In-reply-to: <20190215145425.GA32071@alvherre.pgsql> References: <20190215145425.GA32071@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 15 Feb 2019 11:54:25 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3292.1550246240.1@sss.pgh.pa.us> Date: Fri, 15 Feb 2019 10:57:20 -0500 Message-ID: <3293.1550246240@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > I noticed in Compiler Explorer that some (ancient?) Power cpus > implement instruction "popcntb", and GCC support for those uses > -mpopcntb switch enabling __builtin_popcount() to use it. I added the > switch to configure.in but I'm not sure how well that will work ... I > don't know if this is represented in buildfarm. I experimented a bit with this on an old Apple laptop. Apple's compiler rejects -mpopcntb altogether. FreeBSD's compiler (gcc 4.2.1) recognizes the switch, but I could not get it to emit the instruction, even when specifying -mcpu=power5, which ought to enable it according to the gcc docs: ... The `-mpopcntb' option allows GCC to generate the popcount and double precision FP reciprocal estimate instruction implemented on the POWER5 processor and other processors that support the PowerPC V2.02 architecture. A more recent gcc info file also mentions The `-mpopcntd' option allows GCC to generate the popcount instruction implemented on the POWER7 processor and other processors that support the PowerPC V2.06 architecture. but the gcc version I have on this laptop doesn't know that switch. In any case, I'm pretty sure Apple never shipped a CPU that could run either instruction. I suspect that probing for either option may not be worth the configure cycles it'd consume :-( ... there are just way too few of those specific POWER variants out there anymore, even granting that you have a compiler that will play along. Moreover, you can't turn on -mpopcntb without having some POWER equivalent to the CPUID test. However, if you want to leave the option for this open in future, it really makes the file name pg_bitutils_sse42.c quite inappropriate. How about pg_bitutils_hwpopcnt.c or something like that? regards, tom lane