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 1vn2m1-001hmn-0h for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 22:52:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vn2m0-001tW8-0s for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Feb 2026 22:52:00 +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.96) (envelope-from ) id 1vn2lz-001tW0-39 for pgsql-hackers@lists.postgresql.org; Mon, 02 Feb 2026 22:51:59 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vn2ly-00000000Fk3-0oKb for pgsql-hackers@postgresql.org; Mon, 02 Feb 2026 22:51:58 +0000 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-7d122733808so2060504a34.2 for ; Mon, 02 Feb 2026 14:51:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770072717; x=1770677517; 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=pd0Yhjk5NvfjY8NNM/Qcw3YOCM2wAUwJ//NSVgIsrrA=; b=fd84GU21kaz1PkKErQdBsy29elFiZGStdxqi192oXxzdR+xY2BBJNgfthi7Au22cQK abQfqLiixd+TL4McDDL/abz3RGT1Jpl3zmjdk38NegM6FkZmQhiC0v+AqaCfgOqmBZ1l TaTEeEqXClDqgNFdF9HcMKm3QJKAxlfLpxP14s5Dohrh+DaVtVjtOTiC5ZFWHP/EYIwc /MgZSd+4cST6E/HWGkhO3jbnMZE7Rq6XHjhGN8ew85Z8OBowHaXzepp8MYrPt7XYm3ec GJSKARFlfom1YRwzR1MtYzmo6XRJhGvwhWPHP+KH9NFejEGagUPT753cdyRLLm1Ddu+T dJAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770072717; x=1770677517; 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=pd0Yhjk5NvfjY8NNM/Qcw3YOCM2wAUwJ//NSVgIsrrA=; b=pYX1HhqyjGxQpy2MZTqZk1z0z42oYJSl1TNU8jVydb8vdvBMioOqayxcai/tdEwdRN Bm3zhKxoimuD3KURr5VjPfBB9Oamz0EpXjDpL8uBfxED54dFHK1z65wQzEbbNG3khLIG /yoCQv7cpKqAzj4jX5Gs6g8Yy52MbVSYs8hnmdvoZBwAHj2LrTn/8r8vDr3gOk7nWY9a 4Rmrx+ltWiJZhcHyY1LnqkgCxh/+xsK368RSdVoaRdCoTKH9Oge4CCRB2Va3XgwHaB4/ OqYFulMpIzQsqwkmHOhB9PhXksFC8LXQttoxIJ4bnQ7lV0ayDYWi1Mbc3TzXOM17Phr1 CcDw== X-Forwarded-Encrypted: i=1; AJvYcCV3g7YadGxNLHl/ZliOIx4R/Ub9xcBnrTW7W92nl7BO3hIE2tbY2yKIvOjOcEJ+O2sAIeobAUE6wE5cM4h+@postgresql.org X-Gm-Message-State: AOJu0Yx5cLMIC3LARUlntcsxVGbV0ZceXBdMpM6mf5noAqNufaDfgxA6 1Fk9Eh11d14qJxcrVetb3M7HYtxAwfDcaUqk0txU1zEuOZHUm9yXEB0p X-Gm-Gg: AZuq6aJI+b75Dr4pQEdFFePSwWIhfxWa/t7sloly0HZao6hegpFFNvGHrfr9F0WZPkN m/fxp5t2gQKnFVP9ndnS8qQFbobqEv0gUXa49u/BR6LMzTpCcRs76VgAje6b16DNMvs5G0zN6OC FMgslN1wRLI1QRtiUyzARBuPPtIfyQaPT+7acStwrJhVee4BSoS5qLMsaQeACWuqyUsHP8VKSPA lAPtL+/qovcyzEotRbnt6PZO/VuepY85OM4q4wW41eWuEkr74rzuzaXZePJCEczWzGxGXizjERW tHLJlHsaFlqbYoMViHa0tKHUp/lbWO8V788zV6p9nhFwz+vnPPi2J6Z9yCyhurGevu0Lok/Ede0 5vBLOGj9FmHHvvCxbu/VsSVKfifB+cPremPSNciqM2l1685RvlNCk1JgZLdlkSbiLvGURqOb155 0U5YxU+XrxmCmhUW7ccnqWr/5QCDhA7OAMKz2iXSei1tgH8iyxNKdrsVGGgeish04E7m3zIjXrq 8O4 X-Received: by 2002:a05:6830:650b:b0:7c7:5458:75f8 with SMTP id 46e09a7af769-7d1a53284e5mr6231300a34.29.1770072717167; Mon, 02 Feb 2026 14:51:57 -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-7d18c670734sm11214217a34.4.2026.02.02.14.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 14:51:56 -0800 (PST) Date: Mon, 2 Feb 2026 16:51:54 -0600 From: Nathan Bossart To: John Naylor Cc: Heikki Linnakangas , pgsql-hackers@postgresql.org Subject: Re: refactor architecture-specific popcount code Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Feb 02, 2026 at 09:16:42PM +0700, John Naylor wrote: > It might be a good idea to do a little new testing, and I see a use > for a special 8-byte path independent of AVX512: v6 seems to regress a > little for single-words. But, it turns out that when gcc turns > __builtin_popcountl into a single instruction, it's inline, but if it > emits portable bitwise ops, it does so in a function called > __popcountdi2(). That can be avoided by hand-coding in C for normal > builds (and for 32-bit looks cleaner anyway), as in the attached 0005. Oh, interesting. I looked into this a little more [0]. Both gcc and clang generate cnt instructions for aarch64, so we're good there. However, clang on x86-64 generates the bit-twiddling version, and gcc on x86-64 generates a call to __popcountdi2() (which I imagine does something similar). It's not until you provide a compiler flag like -march=x86-64-v2 that gcc/clang start generating popcnt instructions for x86-64, which makes sense. 0005 seems like the correct move to me... [0] https://godbolt.org/z/he3WozG3E -- nathan