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 1v1rMK-00DOZ2-Pc for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 19:10:28 +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 1v1rMI-004xeS-R7 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 19:10:26 +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 1v1rMI-004xeJ-HR for pgsql-hackers@lists.postgresql.org; Thu, 25 Sep 2025 19:10:26 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1rMF-0004hi-2a for pgsql-hackers@postgresql.org; Thu, 25 Sep 2025 19:10:26 +0000 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-88432e60eebso40204239f.3 for ; Thu, 25 Sep 2025 12:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758827422; x=1759432222; 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=9z3SZt1EtlKTSoqHK2aIrgtVpCi9MLqPCmcq1wyV/1I=; b=a1AeT/qM/NoOAU6r19N+C4wGzdEPY/D2/5JC0VYTbuol/gmu2fza4gOEvFHYib7Poq YF7h6at7SkppzG4S1X/EoqjolUyP+rdxSc1h5K7FSX9vNhv7yOoj9kG/l4FXOzNxZu+g 5i8mowDkm6QA+b3DPtHbEZIBQvutz3uMxadBLNn1RbBGZFBBbCUr9OYVvb9UB8UvgoHp Xi41rDgUx5eI1Yg58mOaRqjH6Fmf3KZSF7DaDOrC4WOetEi1NiRvVqQ5T/SaEcLwuVJv ftixxYdY9u2UNtVzDfpGsSS/jfODQKVI2Sx+4QN1legaQgboHK6OGpuexsixKM7hio+0 XT+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758827422; x=1759432222; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9z3SZt1EtlKTSoqHK2aIrgtVpCi9MLqPCmcq1wyV/1I=; b=cpBkq7rfzXIsIo9+IX0RaDp8V7l43fHJI2xzavisRQbTXPLQno7aPWYlXw1zltZXNq RITqQqS59GPKdYOJOkCSAcwppu6mqmS996GsEVhfESInrgyFDbAN0vx4x8yeexcTplr4 3GS3079GcAj6ENx48aeHyZglNkzF/SDY98dwJe1cKZcXZyGbEZbIsMyZvLELiwZnaxIE udlG3cW4KCjMoTH3mT85i01rzwlfD0B6AfZVxaDsry4yxT24dWvxLvb40QArZHKMJC5y puebsaJYES9raTrgJrpvKWCxALPKLBGZ1zlY2WB5INt+deHThtRfG7ROwoR2phBu2nhC cWmA== X-Gm-Message-State: AOJu0YzHGBQ6GdIt3fAxu4R4oPnYkR9pF67oioJa/0UEs2mCcyJdLhxB rQH11/6SXEmdxzeF9JZOQGmAek5SEM4Okry8Q9gMyawCI2qHZ8A1lGGf X-Gm-Gg: ASbGncvdFTXB2ymiGlLKuNyLntj/G4pwg1uiqEhSKmKLAhaeyUR4r6XSjSgwKznCWhm L8f4fZUU0X9s0Ue1ZIJCUpgg12ay+NvEay9zSnhXgFLQFY1FP7gDT+0ugf7aAvFPtotyAwRzyIb hEp7S3U9Px12rwBsX9NF4Jdi7wp5FbCFAGo8uvNVOB3mnqbjxsXXc7tepoorT+xOrEjC6AGzOIs RjSt80n/D7fWsdJz75QrfQpE2Umf4e6NvHDdESMQVHGnS2Rv+GHnj0bkWy8duYy6HvcoqD7xU0s ez/ADEVyJSlWHjRtxCG8OxSAGEej/P3Lg1HNr/6YY9+VWw6Ku+Dk7rV7ACD7trVM02pcsc0ZSmy +OUO1Vuyuxc6xAKoesVrk0uDqHjepSvEzoyIw+3EYc6Amn0h+a0sF1JtZwEhBTJHNhad8pvgJxl X3LSEM5/k6E+HX X-Google-Smtp-Source: AGHT+IHq86LCV4kWVJhQ7AyQjsdLK+ivsdsSf5Q9L5a1HWByA8PMcze//drJjk9zTDDvuWvIK8gzgQ== X-Received: by 2002:a05:6602:408a:b0:875:d675:55f2 with SMTP id ca18e2360f4ac-90153fd19f6mr826930939f.7.1758827422335; Thu, 25 Sep 2025 12:10: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 ca18e2360f4ac-904100c3cfcsm102456539f.23.2025.09.25.12.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Sep 2025 12:10:21 -0700 (PDT) Date: Thu, 25 Sep 2025 14:10:19 -0500 From: Nathan Bossart To: John Naylor Cc: pgsql-hackers@postgresql.org Subject: Re: a couple of small patches for simd.h Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="WdyMl03n5Wf7ufXN" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --WdyMl03n5Wf7ufXN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --WdyMl03n5Wf7ufXN Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v2-0001-Optimize-vector8_has_le-on-AArch64.patch From a644f049add68ea78326f88d8994898c92f23c20 Mon Sep 17 00:00:00 2001 From: Nathan Bossart 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) --WdyMl03n5Wf7ufXN--