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 1gu3mJ-0002iR-5X for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Feb 2019 23:17:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gu3mG-0001uy-Nn for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Feb 2019 23:17:16 +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 1gu3mG-0001qX-Ez for pgsql-hackers@lists.postgresql.org; Wed, 13 Feb 2019 23:17:16 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gu3mD-0007tj-M2 for pgsql-hackers@lists.postgresql.org; Wed, 13 Feb 2019 23:17:15 +0000 Received: by mail-qt1-x843.google.com with SMTP id y4so4741933qtc.10 for ; Wed, 13 Feb 2019 15:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=MKNVE7sUe/FoUJzv1OWioH8fjO9q0M9VOxE3rd+Lwts=; b=kSFN6/v0X7RkIbOhFYMmlDsAJmGtbW5Jmpr36N/vyXemLC+m9soyQvZG1rO4iHYj2s UDB5O9nP/KN4Wl8Nu8J7HLD9QPuuCUgkXgQ/aSCC3TnyIuiDwCUtzC9BrPGajNKAfL6l gGlVggMBUzkYKBzi7dd4qzmqqdn69IlN5ujND4Q76MMZ82Ldg4KocBq3LI+BKlCsHYLj ZX9xXAHQlrTuRfxYOe5iIpdP8kYSYJ/ArD/YgAYVeG2YrBtfzi4dWSSa9nQarN8DeN8V 4zq86BqljNEg+T4l8AObizOzoFajzXL4hQcTP7u7uvBwzdIzVpmc7j92GU4j/N1xWTuo DbqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=MKNVE7sUe/FoUJzv1OWioH8fjO9q0M9VOxE3rd+Lwts=; b=n64zg5ty0yy334brJl5QeAkmFfZf+i6ANUIJkTFeMbayHktuB7u0oEyHokyaUFMuu8 uElM6mChirG5Kcu4ffmOBrg0Fufu+/KUiGmxRqfcS9Q6foGi1LcZYaar5CkL+sBIfIg3 6AvJSO8I5LnMFF0BZ5i830DsdWdluiVl1koFuBs0GIIEGDIfNRvW9MV/nZYZqIf8qOTx 2EBluTr9zw6VnhDRUH6xR2FnaKZ9GijSxtS2uDhmxsEYcddXySPY6CNYlFgRZuZSjmRP 7vdlOqvIZFy9x/9Ux7xqEvPcaP3iBMSjcIuiZlebKw9KQp4juX1/0VtJnRJZ3FKt6qUW B/DQ== X-Gm-Message-State: AHQUAua6YjHAwjxSSqkSoBLv+Cg0SGC3KmKDcazX5fOfx8pBT3T2bV3/ yQFa3Nc58uGkfqk3oIDpnVCwnWBR/xEueA== X-Google-Smtp-Source: AHgI3IYH6C/kEM7hSueGu7YTMNmKGEn473khIdAEgxk/z9YddvLVEFrlLsIpJyhuGSspFtdAkl0FHw== X-Received: by 2002:aed:23a3:: with SMTP id j32mr542233qtc.205.1550099832050; Wed, 13 Feb 2019 15:17:12 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id z126sm702981qkz.8.2019.02.13.15.17.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Feb 2019 15:17:11 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 5464812459B; Wed, 13 Feb 2019 20:17:09 -0300 (-03) Date: Wed, 13 Feb 2019 20:17:09 -0300 From: Alvaro Herrera To: Tom Lane Cc: Andrew Gierth , David Rowley , PostgreSQL Hackers , Thomas Munro Subject: Re: Using POPCNT and other advanced bit manipulation instructions Message-ID: <20190213231709.GA12159@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <26998.1550097202@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Feb-13, Tom Lane wrote: > Alvaro Herrera writes: > > and we have defined pg_popcount64() like this: > > > static int > > pg_popcount64_sse42(uint64 word) > > { > > return __builtin_popcountl(word); > > } > > That is clearly completely broken. Pushed my proposed fix, which includes removing the configure tests for builtins of varying widths. I couldn't resist sorting entries alphabetically in configure.in. (I also used autoheader to produce the new pg_config.h, which showed me that David had not used it to generate his diffs there.) For pg_config.h.win32 I used the compiler explorer tool I just learned about, and came to the conclusion that MSVC's compiler does not implement these builtins. I didn't do anything about the const-cast-away in pg_popcount() yet. I think that should use PointerIsAligned() instead of what it's doing now. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services