Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSwMH-00Gtvs-7I for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 09:49:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSwMG-00EvVH-6I for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 09:49:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSwMF-00EvUx-Ha for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 09:49:15 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSwMD-003HQD-1Z for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 09:49:14 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 213105C017F; Thu, 25 Jan 2024 04:49:12 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 25 Jan 2024 04:49:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1706176152; x= 1706262552; bh=mH4nQ0OjDsO9IOuPAr5fW7/4DGw8k78do+IQ4q9rbc4=; b=r fDqJ1aXFgmKyu2n+gPsakHYo7rAp8FmsHDVoagZAThUNsvucuftsKmm3nmZQO6wR PfVmp4ckRUlVqh+2n0vJAJFAZ07Gq6EkKie4zOfYGEeJTsR0LYhzv3CEPNbi6uIi cjDoTKkVH6GWa8Agja4Z/CECxRd231eXGXKcvWsC6BskXXW8ro3eKxJ1ESRtcbLg ANdKjjLh7g8+KheLFnZ8vUqMcK761QF0iX00+QOlV6R043r7u0p5d8GuXpex3aYg SntDdml7T0bmurWfGGy/TqxW39/JSO1fxlAa2Lki/0RLbS62CiyYmdNMgtcazGSS BfeI+3nQAZZgC9VEwEWeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdelfedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepueeigfffueektdfgteeuuefgtedvueehgfehleefheel jeelfeffjedttdekvdejnecuffhomhgrihhnpehpohhsthhgrhdrvghspdgvnhhtvghrph hrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 Jan 2024 04:49:11 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1706176149; bh=jQTBGX8JOKz7SO6VTE1PvLNGaGISG6nIbHFAaPzIXPE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NOVfJwnrO3wSG5yHomYWwOk6IsOT3qr2ZhNr9uhdDeXda30+lvZjrhU3nCdQ8XYUu NXpNAvDUG+9gw1jA3bmUgwJ/37Wf31mmxAYPaAtbM9NhpyLkEcJX9sj42ANWz0H8s1 jYf5a0bpnvsy6ucqdpyT2FsjTWUJJC/m021pRPdOeaLaGWYyvqLZeooS/AWlMJK0gU 8PQ57UAPXmoYtetBbYSXX8fC6dyn/KavEZ0NKKKvBAQjKAImyQi32h506LnxDEfXYh +3xkyYv4CoMb497OYmvNutrQp4szjYY/0N2wvNX8qAQLFZKQDDGwIl1Seme9DxekZ5 ILuYKwV1CTRUw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 85EBC9B0; Thu, 25 Jan 2024 10:49:09 +0100 (CET) Date: Thu, 25 Jan 2024 10:49:09 +0100 From: Alvaro Herrera To: "Shankaran, Akash" Cc: Nathan Bossart , Noah Misch , "Amonson, Paul D" , Tom Lane , Matthias van de Meent , "pgsql-hackers@lists.postgresql.org" Subject: Re: Popcount optimization using AVX512 Message-ID: <202401250949.xrwkd46bgbpl@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Jan-25, Shankaran, Akash wrote: > With the updated patch, we observed significant improvements and > handily beat the previous popcount algorithm performance. No > regressions in any scenario are observed: > Platform: Intel Xeon Platinum 8360Y (Icelake) for data sizes 1kb - 64kb. > Microbenchmark: 2x - 3x gains presently vs 19% previously, on the same > microbenchmark described initially in this thread. These are great results. However, it would be much better if the improved code were available for all relevant builds and activated if a CPUID test determines that the relevant instructions are available, instead of requiring a compile-time flag -- which most builds are not going to use, thus wasting the opportunity for running the optimized code. I suppose this would require patching pg_popcount64_choose() to be more specific. Looking at the existing code, I would also consider renaming the "_fast" variants to something like pg_popcount32_asml/ pg_popcount64_asmq so that you can name the new one pg_popcount64_asmdq or such. (Or maybe leave the 32-bit version alone as "fast/slow", since there's no third option for that one -- or do I misread?) I also think this needs to move the CFLAGS-decision-making elsewhere; asking the user to get it right is too much of a burden. Is it workable to simply verify compiler support for the additional flags needed, and if so add them to a new CFLAGS_BITUTILS variable or such? We already have the CFLAGS_CRC model that should be easy to follow. Should be easy enough to mostly copy what's in configure.ac and meson.build, right? Finally, the matter of using ifunc as proposed by Noah seems to be still in the air, with no patches offered for the popcount family. Given that Nathan reports [1] a performance decrease, maybe we should set that thought aside for now and continue to use function pointers. It's worth keeping in mind that popcount is already using function pointers (at least in the case where we try to use POPCNT directly), so patching to select between three options instead of between two wouldn't be a regression. [1] https://postgr.es/m/20231107201441.GA898662@nathanxps13 -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Nunca se desea ardientemente lo que solo se desea por razón" (F. Alexandre)