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
>From 699f0b0942c5390a46aa84ada95e5d38a9f21a10 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nat...@postgresql.org>
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)

>From 43b7c5f60e309c3404771aee2ca9488790db56de Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nat...@postgresql.org>
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)

Reply via email to