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.96) (envelope-from ) id 1vtSbc-0097F7-0f for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Feb 2026 15:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vtSba-008MY7-2q for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Feb 2026 15:39:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vtSba-008MXt-1s for pgsql-hackers@lists.postgresql.org; Fri, 20 Feb 2026 15:39:46 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vtSbW-00000000OtI-1NfW for pgsql-hackers@postgresql.org; Fri, 20 Feb 2026 15:39:46 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-7d19bfe1190so1839236a34.1 for ; Fri, 20 Feb 2026 07:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771601981; x=1772206781; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=7Zp/02s7R2BKyvuFRh0v48z8k/SUw1zaHuB6q25ORaQ=; b=SBJISar+9a1IAeAiyEaVipjXXeNJO6ZEBelFmz+TFimLgMiM/yrOS7JWma1SbPIAr0 F48Nl8UTk8xcka1tMHgBCaHKeWkUbzPgaeIxAPK/Vouj5TW5j2oavLtOeyQPWcAjtOby El/ZNlXarNfweNkYxAABsZV0cgfeSi4ixqTgXbW+j3Wbhcc8pd7iObnHdmQWuhT815ex iVUMZbOSqreD3wdQJyK/fyqkf4TV6XYdj1kM6NAIbAX3endgvROTct+fkwQb7dzv4+j8 zFT3knDz/7yhGahCAtwK5EHgyKA/8uZa4rTJIKBGAvJQdvMGkc4TzFEvAKnLNpS6Udk6 MaKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771601981; x=1772206781; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7Zp/02s7R2BKyvuFRh0v48z8k/SUw1zaHuB6q25ORaQ=; b=m+3nmZ+R3zaN88lMNMmk41ICBdbv8qyS/gOiNeHsna7CyVy2D/bf4uwNO4l9eiZpC9 klwBWvez9phlu/vA4X/P9o/2VnDime9clTR/pkKd3hye3sZg4o7xVP7kO2yk6uwla7XS R6gfTfO5r6oZWqoSRIF3TfeFHm0lv93xjFG5qqMaWVUWEtppsAGLRzqMNALvlAvw6QTo +IR+J7eSxXLpoV/w1kCyETCQDAzkytbBCw//y8zSCXpQ5UFiYFQQUbH0lPbw+DYdS8IP 1nCWxAplSRTgu9XQ1Cdw4bZBCFZZJ7XWqK5r0xviCG5dIwytB8JCAhVuDNbmRyuZ6aLm dckQ== X-Forwarded-Encrypted: i=1; AJvYcCVl9rHlT+Z5wflTL7k0l7BgfPFnRs1lNp9bFT2nULda1x1IQvcRe3MSVBd59gzzU9DND+1jTbLmwm6jKDSJ@postgresql.org X-Gm-Message-State: AOJu0YxM6aZ7ENVy2aY1qTUsSjS/9EqZq/PRBARmy5z+UJWZ1Uxsto5v jEF71JHj84SYdQMom1dJ9iWqdkB07EA1ZpmB/hB/5jDTibvokVc3ebCQ X-Gm-Gg: AZuq6aJ08s0+V9CqRqO80+/mxBMQVCQOj4nWz4T8UIm/AjNELK4FNoTKS75fQqp66Fz cGglexUFZjEJR+ipO8+TxylXOKhunGjFwbYOVj69yCQTU/dM3I1w1Vmb/uGK38z0nEj0PhCHp7t zgOUD1jjYbh33sakzQZogKlrVti/EJR3Qae6R65ZMtKAiwGYyX6Ox2ehCJSRTsyi+SUGNHiX7Q9 EvIiHkd3CETcABDaB3pBOLlGpK0nvN4pUrTa8EYoNJq0b6PT8klHF40i9JlV0a3UUmpfVw7lEvo 5uJRF6F06tFTx19VC7Dt+b+5ZTAdJvIaYvXMviIaoa+wRTaUsDHBBvnXStVxeKbp4AZbpqRUECF 3fnJNjbSkHdEx1V+2Hjw0NfxFaM6tJ6rXkUq1kKP7KllJeEPv3g+0tNUJShu+MxV6b5PxfvKFIj jc572AjvyGrtScPeLLvHPWft4aowBA52O9JBpTVyha8HHAEWYrC9AV9+XPeAm0Q5U/9jwxaJ33b RBWj0nVzoXlyZmC X-Received: by 2002:a05:6830:2588:b0:7d1:9572:9111 with SMTP id 46e09a7af769-7d52bdf76bemr138354a34.1.1771601980656; Fri, 20 Feb 2026 07:39:40 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d4a771bcebsm24871983a34.25.2026.02.20.07.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Feb 2026 07:39:40 -0800 (PST) Date: Fri, 20 Feb 2026 09:39:38 -0600 From: Nathan Bossart To: John Naylor Cc: Greg Burd , Heikki Linnakangas , pgsql-hackers Subject: Re: refactor architecture-specific popcount code Message-ID: References: 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 Fri, Feb 20, 2026 at 03:21:05PM +0700, John Naylor wrote: > On Thu, Feb 5, 2026 at 4:43 AM Nathan Bossart wrote: >> Yeah, the plain C version might be marginally slower than the built-in >> version for that test, but it still seems quite a bit faster than HEAD. >> >> HEAD v8 v10 >> 40 25 29 > > (for the following, numbers are nanoseconds per call from > drive_bms_num_members()) > > Seems similar on S390X / gcc 13.3 (last week I only tested a single > bitmapword and feel don't like repeating): > > master (older): 4.1083 (call builtin) > v8: 2.8889 (inline builtin) > v10: 2.7961 (inline pure C) Thanks for testing it. > On ppc64le / gcc 8.5, without native popcount it suffers: > > words master v14 > 1 4.5 6.5 > 2 5.8 9.7 > 64 67.9 101 > 128 143 190 > > So one up, one down among obscure platforms. There seems to be a > fairly thin case for the builtin anymore, although it's not zero. I spent some time looking at how clang/gcc compiled the plain-C version on various architectures [0], and I was pleasantly surprised to discover that at some point in recent history they started automatically converting it to special popcount instructions. I suspect that you'd see better results on ppc64le if you upgraded the compiler... [0] https://godbolt.org/z/v9vvx7E89 -- nathan