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 1v0oKl-000qkd-RM for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Sep 2025 21:44:31 +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 1v0oKk-002Md2-4M for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Sep 2025 21:44:30 +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.94.2) (envelope-from ) id 1v0oKj-002Mcs-Qu for pgsql-hackers@lists.postgresql.org; Mon, 22 Sep 2025 21:44:29 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v0oKd-002GIh-2B for pgsql-hackers@postgresql.org; Mon, 22 Sep 2025 21:44:28 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-4248c9a64f7so13298085ab.0 for ; Mon, 22 Sep 2025 14:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758577463; x=1759182263; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=HyNDKYs3n99TRVsXagCMElNqLswpWCulqgJa1fQ0LlY=; b=SsB/LOjLrvwd5ucQ5NCHvT+QhOyFDv6xVqohVTDbpM3YQd2egu0k5OJpoT5KzB7oLX psMZAZv241aBbAlbAPI+DEEKZYuT508M9uNK5VIrejlQ4FMwh0w51t+JHqxY47ZGpmFA enLBgqxnoi3EB1bY6Ds1B5ANSIcXtAyh8Kn3XYzMudri0FnoCg5iEXQ2Y2RCyTdVdl0R xItHe3GM52IVNycwvXLE5FN+wdqmGKMvIYM2VB3oixlhnuYi3xdu6Mi6IKJgStbpdV0b p4VOpXZIZ/TgWLRPk3QpO/FcZK0SyjEHdP0dm5SJ8LHkPsgh0xRWP8hBqMnWZkjVb+8y lrPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758577463; x=1759182263; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HyNDKYs3n99TRVsXagCMElNqLswpWCulqgJa1fQ0LlY=; b=BA4qzhKZMcGdlXXfCVGZbmxow5FRu4F9myD3vDtUEt3Is+bfajUD8ff5901auxYLP1 Tb1FSXV5p+1rqks9uYPyZyylaPW2RSqmjNKE8aET9K/RsNC0JR+pDascuBvSxOMCrjCA rnX01wwpl0GWzbCfI3fjAMREONFWw9XGPZW3RlwD15gmt6piOQA/pEj/Aa3d4uNskukA WcpJBOVih9zpv/FrYk3xl2DIxfhvEpaBX54WmrTsXXmxnWqdCs8ZxRll+iBabjAZWAAA LSHSIVgLo+Ub/7WKwyWaWM0KzNGt49nutSYtCfZwAZwqFM1jXImP34vWi19S67CzNkAp A8HA== X-Gm-Message-State: AOJu0YzJjut12VKLPcM1bjWy1hWdf931m+9dpsD+YY9R0BfJbKAg26il tfodNMUB/61gX0YknvUXXSE6OaxMP6rMtcHNmjea5dhjd8L3Xk8lMaJAmhKnQw== X-Gm-Gg: ASbGncsjaqVC7/faCxCN+oOsZkXKGMZ4P1LW5Z9pMa99Q85jUsQ70hsY83lnEKAi5yX Qz+f9dDbaH4AceTtzz8bsPC+2JnkURC0WPicP9T+utKrmJV8vsI9uWFI/9FleTSxKWwxqS2sPp4 BcU6djuFWbrVIXa5uBlaXS5IYeTE0P3H81Pqb2xukIaibWwVOzxb2j6QjK8cNYxrPlLo1AwIinS RQzrkZFlMLHZAgRjNRa6JH3gshUAB1p8KK912+AwtoRrwEWFdNYyCKekfV7me+9gR/oMn9FVFx0 AR3SsYlHh4TLlbuteD1mVo0VlcZKzku2QB0rQqFQ3mXHcAifH31eYdGy0tAuy0vktteSfQ4gUWY JEsrZlaWyRn2/NbCUHtT90+XzBgS8cHDrk0k4d+Mx0ofK9KF84N/DLhHAWubnIPrpCg7xRXKekp PBsfbREoPHnSi1 X-Google-Smtp-Source: AGHT+IGKgo0IT/Y0n4Gvq9A1T6sZX5Q6kvVdxrpxjj9ZGteL5kyA79PPTDbl5e9zCittK+N+dwQ+cA== X-Received: by 2002:a05:6e02:460f:b0:424:52b:add8 with SMTP id e9e14a558f8ab-425822933e3mr4698695ab.3.1758577462865; Mon, 22 Sep 2025 14:44:22 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-53d50f6be3esm6147765173.38.2025.09.22.14.44.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Sep 2025 14:44:22 -0700 (PDT) Date: Mon, 22 Sep 2025 16:44:20 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Cc: johncnaylorls@gmail.com Subject: a couple of small patches for simd.h Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Yiao/tYUtO4LhsB3" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Yiao/tYUtO4LhsB3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 0001 essentially reverts commit c6a43c2, and instead fixes the problem (MSVC dislikes casts to the same type) by omitting the cast in the problematic line in pg_lfind32(). While working on optimizing hex_encode() and hex_decode() [0], I noticed that implicit conversions sufficed. 0002 optimizes vector8_has_le() on AArch64 by using vminvq_u8(). I needed vector8_has_ge() for the hex_encode()/hex_decode() work and noticed this opportunity. [0] https://commitfest.postgresql.org/patch/5538/ -- nathan --Yiao/tYUtO4LhsB3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-Remove-vector32_is_highbit_set.patch From 699f0b0942c5390a46aa84ada95e5d38a9f21a10 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 22 Sep 2025 16:02:10 -0500 Subject: [PATCH v1 1/2] Remove vector32_is_highbit_set(). --- src/include/port/pg_lfind.h | 2 +- src/include/port/simd.h | 23 ----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/include/port/pg_lfind.h b/src/include/port/pg_lfind.h index 20f7497dcb7..0f460472601 100644 --- a/src/include/port/pg_lfind.h +++ b/src/include/port/pg_lfind.h @@ -139,7 +139,7 @@ pg_lfind32_simd_helper(const Vector32 keys, const uint32 *base) result = vector32_or(tmp1, tmp2); /* return whether there was a match */ - return vector32_is_highbit_set(result); + return vector8_is_highbit_set(result); } #endif /* ! USE_NO_SIMD */ diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 97c5f353022..6424e8f5a97 100644 --- a/src/include/port/simd.h +++ b/src/include/port/simd.h @@ -78,7 +78,6 @@ static inline bool vector8_has_zero(const Vector8 v); static inline bool vector8_has_le(const Vector8 v, const uint8 c); static inline bool vector8_is_highbit_set(const Vector8 v); #ifndef USE_NO_SIMD -static inline bool vector32_is_highbit_set(const Vector32 v); static inline uint32 vector8_highbit_mask(const Vector8 v); #endif @@ -279,28 +278,6 @@ vector8_is_highbit_set(const Vector8 v) #endif } -/* - * Exactly like vector8_is_highbit_set except for the input type, so it - * looks at each byte separately. - * - * XXX x86 uses the same underlying type for 8-bit, 16-bit, and 32-bit - * integer elements, but Arm does not, hence the need for a separate - * function. We could instead adopt the behavior of Arm's vmaxvq_u32(), i.e. - * check each 32-bit element, but that would require an additional mask - * operation on x86. - */ -#ifndef USE_NO_SIMD -static inline bool -vector32_is_highbit_set(const Vector32 v) -{ -#if defined(USE_NEON) - return vector8_is_highbit_set((Vector8) v); -#else - return vector8_is_highbit_set(v); -#endif -} -#endif /* ! USE_NO_SIMD */ - /* * Return a bitmask formed from the high-bit of each element. */ -- 2.39.5 (Apple Git-154) --Yiao/tYUtO4LhsB3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0002-Optimize-vector8_has_le-on-AArch64.patch From 43b7c5f60e309c3404771aee2ca9488790db56de Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 22 Sep 2025 16:17:09 -0500 Subject: [PATCH v1 2/2] Optimize vector8_has_le() on AArch64. --- src/include/port/simd.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 6424e8f5a97..a594f1c1de3 100644 --- a/src/include/port/simd.h +++ b/src/include/port/simd.h @@ -249,6 +249,8 @@ vector8_has_le(const Vector8 v, const uint8 c) } } } +#elif defined(USE_NEON) + result = vminvq_u8(v) <= c; #else /* -- 2.39.5 (Apple Git-154) --Yiao/tYUtO4LhsB3--