pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: pgsql-hackers@postgresql.org
Cc: johncnaylorls@gmail.com
Subject: a couple of small patches for simd.h
Date: Mon, 22 Sep 2025 16:44:20 -0500
Message-ID: <aNHDNDSHleq0ogC_@nathan> (raw)

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

Attachments: download all (2 files, .tar.gz)

v1-0001-Remove-vector32_is_highbit_set.patch (text/plain, 2.1K) download From 699f0b0942c5390a46aa84ada95e5d38a9f21a10 Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@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)
v1-0002-Optimize-vector8_has_le-on-AArch64.patch (text/plain, 625B) download From 43b7c5f60e309c3404771aee2ca9488790db56de Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@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)

view thread (8+ messages)  latest in thread

Message-ID: <aNHDNDSHleq0ogC_@nathan>
Permalink:  ../aNHDNDSHleq0ogC_@nathan/
Also on:    postgresql.org/message-id/aNHDNDSHleq0ogC_@nathan

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: nathandbossart@gmail.com, johncnaylorls@gmail.com
  Subject: Re: a couple of small patches for simd.h
  In-Reply-To: <aNHDNDSHleq0ogC_@nathan>
  References: <aNHDNDSHleq0ogC_@nathan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox