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 1vnKPC-005AWs-2p for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 17:41:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnKPB-006eoZ-2V for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Feb 2026 17:41:37 +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 1vnKPB-006eoQ-1a for pgsql-hackers@lists.postgresql.org; Tue, 03 Feb 2026 17:41:37 +0000 Received: from mail-oo1-xc2f.google.com ([2607:f8b0:4864:20::c2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnKP8-00000000sHD-3dZd for pgsql-hackers@postgresql.org; Tue, 03 Feb 2026 17:41:36 +0000 Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-66a12c77a2cso126967eaf.3 for ; Tue, 03 Feb 2026 09:41:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770140493; x=1770745293; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZQkiGWdILoG/3HvUuI9Q3ge1aMhMhIlTzR0o3IDmgT8=; b=I0WTg/WM532FADxlCy/Q+2zAt4awjWIT1KO9PDcr3Tv3WQg+ZIOeB70QUIoAh58LQy lp2GNfypaPpf/2n6eEtkWD3HamDNzuqJNcRR2brBQ4V/pH2Il603O0sqciEhian9ruGc j+yuH4yoQbb4W3t2pnv3uaTYMZtQvRBdgKRiEyNTeZEncC96TrLfZwdxhvQEFvJQfGf8 Q8kIQdElB6y2uDxcBgC7OI/3sqWse2TWmbnhDcw+yEfkgLlpUrH3FmpG6Pjai94mem+w R7pz4eqwCa3C75KRu9tHOxpkuV6U8aczgg4Fx/UU2+l+jr2qs8j+6Hl5DVmAtuIPaW54 T7MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770140493; x=1770745293; h=in-reply-to: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=ZQkiGWdILoG/3HvUuI9Q3ge1aMhMhIlTzR0o3IDmgT8=; b=TUCr1KYsJnWUgJRsvHm1nKwEzKA6QHUfzF+Dm8AIjLlxzvKWjlvbK+OZbqFXWVHUpy JJ/YBtC9AZj2kwntQEZKMvAQ7HPyGkgyLIIwt+DblWrViJHFBTuZh3tqb8Kze8qp1oK7 fdyuH6klTAYLc5FJCQvQ1AZVNNJURxZ9N9Zs1a6VQ7ZxTY5TXvvuAtKq6ip1Z20HvoMF /5kra3g9OJ2pQf9g5Lxm8O6WmKax2FG3MXas8n11HLkxQqhZ7z6ZYY+638Zr1bEI7BYy FBWNZ9Lcy0erpdETfI6beHTHlLLl+Hdc5RXNNq4Z4ovJfdu5mjy1nzWKy1YGil0ooR1X s0+g== X-Forwarded-Encrypted: i=1; AJvYcCWhOJiiNY0uq9VEhck8okQIn8VIgca8zRmflNfprIpjn1eKQFV4ngMC/7DNCBpfrualCaFrZ3Cwqio7JI3P@postgresql.org X-Gm-Message-State: AOJu0Yw//njLHpxYDlG483yCrI+ccTTrGy/M2G6LwDM0A9DEOjdUfZUy YPCQQ4xg/fwkYd2iPAIMyTkvrFYOAA5aNzyC/Z4gOMcp64dijLI6VniC X-Gm-Gg: AZuq6aL1Ns6vu5TdDIGyO92czTPrHPRpeRV2Kemzq8W5HAecQIM2h6gkfyCRzs1ekhf 8UU+jA6CrnpGKdV91qXvrpsZAkR9n+s2t/mMj618g76zO8CLVPN9yLt77gXSWbYVtWgSgxWwbsH FWLlSoIOlpc3ya2gnFbZekXIFrZ146gWAwXDtOh6em9QgXgTAwUrWzIs5biC0lbU7ZbqoYlxzbf FUEQX5pUDzSPahcyHLVZP2fQaSeDqCPve+HfoK3psnOnUdYC3s1Baexxz9nCJWce0aIFJB9cAwg 48o+DvHYFQDd5H3gdWkXBQTrgIUKLI3SbD0p6XM/z9zBYs80YwSh/UySxgMMJ2aewIu9FJtBvnD VPIOrwC+bebzEUnUP6oer+G8z2cccjNUs3DUNaQr9AndLAJyw7eoXbJsadmi+FO8dTv0QPnb82q M7xAqmrB6q1WLJ9awbHAjXXfz0N2owOY/T4CIdk5tC+Km9EQe/gVscMx2ex9vVDigetZLiXn3Nz Qac X-Received: by 2002:a05:6820:4410:b0:662:fa52:9302 with SMTP id 006d021491bc7-66a20c6d3bcmr187715eaf.23.1770140493344; Tue, 03 Feb 2026 09:41:33 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-66a3318c761sm86213eaf.8.2026.02.03.09.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Feb 2026 09:41:32 -0800 (PST) Date: Tue, 3 Feb 2026 11:41:31 -0600 From: Nathan Bossart To: Greg Burd Cc: John Naylor , Heikki Linnakangas , pgsql-hackers Subject: Re: refactor architecture-specific popcount code Message-ID: References: <3a3ca14a-dada-4920-a614-42f2e5eb3f5d@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a3ca14a-dada-4920-a614-42f2e5eb3f5d@app.fastmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Feb 03, 2026 at 12:19:48PM -0500, Greg Burd wrote: > Thanks for the focus on this area of the code. I've been looking into > what to do with popcnt when building Win11/ARM64/MSVC. I know that when > _MSC_VER and _M_ARM64 are defined we can make use of the > __popcnt(unsigned int) and __popcnt64(unsigned __int64) intrinsics which > have been available since VS 2022 17.11+. I thought I'd check that combo > out and it turns out that it is identical to clang/gcc on that platform > [0]. > > I'll wait for your work to land before proposing a patch to add these > unless it is really easy to fit it and you feel like giving it a go. :) We should probably just add something like #ifdef _MSC_VER return __popcnt(word); for the new inlined versions of pg_popcount{32,64}. We're already doing that today for x86-64, and the AArch64-specific versions use intrinsics that in theory compile to the same thing. Plus, popcnt is required for Windows these days. I'm working on polishing/benchmarking these patches at the moment, so I will work this change in. Thanks! -- nathan