pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathandbossart@gmail.com>
To: John Naylor <johncnaylorls@gmail.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: a couple of small patches for simd.h
Date: Thu, 25 Sep 2025 14:10:19 -0500
Message-ID: <aNWTmzIHyqeTo7Kw@nathan> (raw)
In-Reply-To: <aNQtN89VW8z-yo3B@nathan>
References: <aNHDNDSHleq0ogC_@nathan>
	<CANWCAZaLyxDHoDFjvtaz0aM6Agx=P5i=0T8HnkgLNdwXwJn9Ug@mail.gmail.com>
	<aNQtN89VW8z-yo3B@nathan>

Here's a new version of 0002 with a modified SSE2 implementation, as
discussed elsewhere [0].  This allows us to remove vector8_ssub().

[0] https://postgr.es/m/aNWO7L43UevRErw_%40nathan

-- 
nathan

Attachments:

v2-0001-Optimize-vector8_has_le-on-AArch64.patch (text/plain, 2.2K) download From a644f049add68ea78326f88d8994898c92f23c20 Mon Sep 17 00:00:00 2001 From: Nathan Bossart <nathan@postgresql.org> Date: Mon, 22 Sep 2025 16:17:09 -0500 Subject: [PATCH v2 1/1] Optimize vector8_has_le() on AArch64. --- src/include/port/simd.h | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 97c5f353022..e317e5fdfc0 100644 --- a/src/include/port/simd.h +++ b/src/include/port/simd.h @@ -86,7 +86,6 @@ static inline uint32 vector8_highbit_mask(const Vector8 v); static inline Vector8 vector8_or(const Vector8 v1, const Vector8 v2); #ifndef USE_NO_SIMD static inline Vector32 vector32_or(const Vector32 v1, const Vector32 v2); -static inline Vector8 vector8_ssub(const Vector8 v1, const Vector8 v2); #endif /* @@ -250,14 +249,13 @@ vector8_has_le(const Vector8 v, const uint8 c) } } } -#else +#elif defined(USE_SSE2) + Vector8 umin = _mm_min_epu8(v, vector8_broadcast(c)); + Vector8 cmpe = _mm_cmpeq_epi8(umin, v); - /* - * Use saturating subtraction to find bytes <= c, which will present as - * NUL bytes. This approach is a workaround for the lack of unsigned - * comparison instructions on some architectures. - */ - result = vector8_has_zero(vector8_ssub(v, vector8_broadcast(c))); + result = vector8_is_highbit_set(cmpe); +#elif defined(USE_NEON) + result = vminvq_u8(v) <= c; #endif Assert(assert_result == result); @@ -358,24 +356,6 @@ vector32_or(const Vector32 v1, const Vector32 v2) } #endif /* ! USE_NO_SIMD */ -/* - * Return the result of subtracting the respective elements of the input - * vectors using saturation (i.e., if the operation would yield a value less - * than zero, zero is returned instead). For more information on saturation - * arithmetic, see https://en.wikipedia.org/wiki/Saturation_arithmetic - */ -#ifndef USE_NO_SIMD -static inline Vector8 -vector8_ssub(const Vector8 v1, const Vector8 v2) -{ -#ifdef USE_SSE2 - return _mm_subs_epu8(v1, v2); -#elif defined(USE_NEON) - return vqsubq_u8(v1, v2); -#endif -} -#endif /* ! USE_NO_SIMD */ - /* * Return a vector with all bits set in each lane where the corresponding * lanes in the inputs are equal. -- 2.39.5 (Apple Git-154)

view thread (8+ messages)  latest in thread

Message-ID: <aNWTmzIHyqeTo7Kw@nathan>
Permalink:  ../aNWTmzIHyqeTo7Kw@nathan/
Also on:    postgresql.org/message-id/aNWTmzIHyqeTo7Kw@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: <aNWTmzIHyqeTo7Kw@nathan>
  References: <aNHDNDSHleq0ogC_@nathan> <CANWCAZaLyxDHoDFjvtaz0aM6Agx=P5i=0T8HnkgLNdwXwJn9Ug@mail.gmail.com> <aNQtN89VW8z-yo3B@nathan> <aNWTmzIHyqeTo7Kw@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