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 1vgPks-00C45r-01 for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 15:59:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgPkq-000EDx-0V for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 15:59:24 +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 1vgPkp-000EDn-2V for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 15:59:24 +0000 Received: from mail-oa1-x30.google.com ([2001:4860:4864:20::30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgPko-000dy1-05 for pgsql-hackers@postgresql.org; Thu, 15 Jan 2026 15:59:23 +0000 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-4042f55de3aso714780fac.1 for ; Thu, 15 Jan 2026 07:59:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768492760; x=1769097560; 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=2eyxHosYZ7qdvsoF/M40ENbbAyZaM/7v0u3Z+DQzJCc=; b=VjRrsKE14W7ssKP7MkGcBE/c4if29PWtbru8y59RVi/x68bOfVsv8TXiJ9FajIMAre qIpUqVG33eKLUxOmG+VdCX9DAKYUv33en/QjTelUQrlnlEVxZ9mGvMqcZp52d4+RY2nM I6PLc9R4fx653J7Jq7RGVANpDKUC5bEft3TtMmmI4QFQx+8kDPJtrGZotHI2wfu5+uR/ H7cjKA8bkpd3EYTIdm6UcKtKsKMNItsXUG0oaeY1wkyvw/pgH2e3whmf22fCg1oKL0uu CE2+sJUUl2DFIQfhMdi4908TswKgWmXWrDgrfokyZSKac6j95ng89VmQad0VEwUnvsM3 KlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768492760; x=1769097560; 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=2eyxHosYZ7qdvsoF/M40ENbbAyZaM/7v0u3Z+DQzJCc=; b=ROBRNtL70DIr2MgrQmtuTgFsQr2mNzqvgRkZRLL2DEFU/DGmzMwk15UrGb7cl5Trn2 xhFUHojFd/rp96zRiyBwpWdGpc5QKCzipXpvpXyqVJ0kup4PfZwizErDyXnQNlOYnn5M dpb0UgtnJUmYRWho9SsD0rUoJZLL1MXB/Zl/eynJs2oPDo33V06vssJ4dMgWGxAOsUmD pi31JGaLgHqJ/k1J00luaWkEY83XCe6l+dR3IeGH0icPPBXH+Pqm1NsSJgJ93ey77kKs s62d/PbJn0lFJgoUyEyW5+chFSkF1PBK5JF+ij2WmfyGyEPt2rvALv2XPG03mj030qzx WImg== X-Gm-Message-State: AOJu0YybPqpdBMFdh5JZN8Hyu64RcS5P2k7MY4lnDGSSpgtCZEDl9vmh nL1Nt0mKMVx76o7fWkBFB122AYX7X7yMjD51xU6A8zbdKVom2Ds//0j6 X-Gm-Gg: AY/fxX5H37u0Rvt5yvBbVBGnzv8et8rB9vHgD8Nv4vtZm5MxD0h1JFRzAZ8CtQCkPiU 0itNOTpMEPxPFbgAsu/THK1X5p7yFllvg8Ae6TPGv50aF+ntX/8W0msGHHlKmUG2gwB57DWP3G4 d2Iz7narE8oDc1BVR+0NMF/d7UpkCSZ6BI0FHo80N9R7jXYM/qFayrs5UeuQS125K53QBCDjGl/ rAbhLRWf6x6BhDCVy+EMhaQ20XAWAJINdtCD+0P1KMQVJmKhBppzrKaHiWTDpKS6NghOn7QCpMj 6EpfnrIkh+VDYqSfWy0MqBtUJomW8uB9XfxjS7THDgtH+evm9VPXSaEdTgMCx++U9bPs+AQvROh kTtrt6SukSdkmX4jyG58wJsUsvg/TPHtgUeuHe8L9P1AjJ1IflqIfLYUaZ21rZeZaf+6MP/dwQK Tzp+5HMybuyEt+wNgsLA2x1Q5uLZ5QGVd4bavXH7iBeTw+JAouINRX1bEbODd6bm3+slup/zhLY 8BL X-Received: by 2002:a05:6871:154:b0:3fa:aa5:be04 with SMTP id 586e51a60fabf-4042926594amr2255507fac.20.1768492760039; Thu, 15 Jan 2026 07:59:20 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3ffa4de55ffsm19234266fac.2.2026.01.15.07.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 07:59:19 -0800 (PST) Date: Thu, 15 Jan 2026 09:59:17 -0600 From: Nathan Bossart To: John Naylor Cc: 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 Thu, Jan 15, 2026 at 04:07:51PM +0700, John Naylor wrote: > Thanks for taking on some technical debt! Thanks for reviewing. > --- a/src/port/pg_popcount_avx512.c > +++ b/src/port/pg_popcount_x86_64.c > > Can we get away with just "x86" for brevity? We generally don't target > 32-bit CPUs for this kind of work, so there's no chance of confusion. WFM. > ``` > -#ifdef USE_AVX512_POPCNT_WITH_RUNTIME_CHECK > +#include "port/pg_bitutils.h" > + > +#ifdef TRY_POPCNT_X86_64 > > #if defined(HAVE__GET_CPUID) || defined(HAVE__GET_CPUID_COUNT) > #include > #endif > ``` > > With the above in the x86 .c file, I wonder we can get rid of this > stanza and the "try" symbol and gate only on HAVE_X86_64_POPCNTQ: > > #ifdef HAVE_X86_64_POPCNTQ > #if defined(HAVE__GET_CPUID) || defined(HAVE__CPUID) > #define TRY_POPCNT_X86_64 1 > #endif > #endif > > If we have to be cautious, we could just turn the #error on no CPUID > symbol into "return false". Yeah, the CPUID macro checks do seem overly cautious to me, especially since we've just #error'd when the CPUID intrinsics are missing in pg_crc32c_sse42_choose.c since 2015. That seems to suggest that nobody is trying to build Postgres with a compiler that knows about SSE4.2/POPCNT but not CPUID. For reference, CPUID was introduced in 1993. I bet we could also convert this bit into a configuration-time check: #if defined(_MSC_VER) && defined(_M_AMD64) #define HAVE_X86_64_POPCNTQ #endif > s/fast/sse42/: > > Seems okay in this file, but this isn't the best name, either. Maybe a > comment to head off future "corrections", something like: > "Technically, POPCNT is not part of SSE 4.2, and is not even a vector > operation, but many compilers emit the popcnt instruction with > -msse4.2 anyway." Makes sense. -- nathan