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 1gurci-00005M-3m for pgsql-committers@arkaria.postgresql.org; Sat, 16 Feb 2019 04:30:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gurcg-0007XY-Q6 for pgsql-committers@arkaria.postgresql.org; Sat, 16 Feb 2019 04:30:42 +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 1gurcg-0007XK-KT for pgsql-committers@lists.postgresql.org; Sat, 16 Feb 2019 04:30:42 +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 1gurca-0007bJ-JI for pgsql-committers@lists.postgresql.org; Sat, 16 Feb 2019 04:30:42 +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 x1G4UXUW031414; Fri, 15 Feb 2019 23:30:33 -0500 From: Tom Lane To: Alvaro Herrera cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Fix compiler builtin usage in new pg_bitutils.c In-reply-to: <20190215201804.GA791@alvherre.pgsql> References: <20190215201804.GA791@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 15 Feb 2019 17:18:05 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31412.1550291433.1@sss.pgh.pa.us> Date: Fri, 15 Feb 2019 23:30:33 -0500 Message-ID: <31413.1550291433@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > (BTW, my reading of the articles I cited, as well as my own runs of the > test programs therein, suggest that in order to get a really good > performance improvement you need to hand-code calls to the POPCNT > instruction in assembly rather than rely on the compiler intrinsics. That observation led me to think about using asm() instead of __builtin_popcount + -mpopcnt, and I realized there are several fewer moving parts if we do it that way: we don't need to worry about the compiler switch, and we don't need to rely on faith that it actually changes the emitted code, and we don't need a separate source file to limit the scope of the switch. And really, requiring __builtin_popcount + -mpopcnt is pretty much restricting the optimization to GCC-alikes anyway, so requiring asm() probably doesn't eliminate any toolchains that would've handled the other way. Hence, I made it work like that. Committed with that and some cosmetic cleanups. regards, tom lane