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 1v1tVD-00DqZ5-8d for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 21:27:47 +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 1v1tV9-006Eq5-J3 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 21:27:43 +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 1v1tV9-006Epx-9a for pgsql-hackers@lists.postgresql.org; Thu, 25 Sep 2025 21:27:43 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1tV6-0005s2-0Z for pgsql-hackers@postgresql.org; Thu, 25 Sep 2025 21:27:42 +0000 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-8eeeeb37cc5so106137939f.0 for ; Thu, 25 Sep 2025 14:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758835658; x=1759440458; 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=bQYG/8Nml50gg6fAnb0I7bBf+NzFLCUrQ/e+ehMZFpc=; b=YOqePRz6gpqU0cX1Pm02erhTiuqujyZoCccHi5lYcs/TZnhtn80IyvkLxCbH/aKVhM 4qIwlnPYLPnGWR7+yhfLFhAedf4gHO/D9JA3BIwBapjZUkwuPd15tNRnZndZTEiVeI0a R3AMJHcViGDNKtn/VeOYydfvyJfQCoVl7uaBazUyhTZVPUBnzOw3RZGMVB6x7Lf/yrtP +jVRDlm+KOdjdaE3rhpuKn326V/qV58UuNeAzsAquAQylBZVsD021XkxDHEc4OiqaXBy BhVrPQi6ae8dDiww/J/WvJ4VF2//FNH+qFJ5UCdt5Too8z47qj8wQbWaC4dA0h19zgkj TmXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758835658; x=1759440458; 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=bQYG/8Nml50gg6fAnb0I7bBf+NzFLCUrQ/e+ehMZFpc=; b=iRPbkO3imT14CQlQ6p3I7otkFVEEtilDNhkO8nTscpN+YveRraigRtbNn3FtUSilX1 r7boKqQOxieHHj1xWOh85bPZ/pWcuaVlPtlyrMJGO+pI21/lmgq2okLJvE081o+xrp2j FBcqPfSVSvxYIs9wYiuUjkEnWk97/iQkhpt4j5P/T6jD8l6zF/xi8lGN2PfIcTrfWuFW 6lEE6nov5gbOBzfqLNbZT+a7FPnsKk8zCdHfNPgHZxGmdBn3OBucptz1AYqXa2U7AxuX X44IvsFM6IsHD+eGaZlIJRsk1gzmngwUnyHHsFQyg+nlHUlUd3vXGJFV9Ls5cOgYo21T 916Q== X-Gm-Message-State: AOJu0YwZ9mfv29AtxErDkF/Sp5vtpLIWTlGNqNL+WNTEJQxoHQQtgrSJ V3zCy8gv4JqufBQeIGFcYw4B05Deagav60tlyr7x4otdBqm3MTdBXC55ZM+HCA== X-Gm-Gg: ASbGnct1MAvrpXro9hjT8gy0MLUOLIgRdig4HDu3gliefdfXqSecCDI+k4pZ7KpGJgg UNIsaUY3iTohx1NRQGC+bsr0XRDu1b+4CXkVlAg+vshQkSmUtnEXLaoYJjHz8joj3JZGacANz98 wtKyHfoY3a3ktTUjk2VLF//RSJZeYYr3s53RjpOsRjqj+X4msvhHuN3Y4gsqjvTf6CiUMrCcOyf BC7zjhZMzlrQaASpBRijkDC28Bp0SMDAXjy/sNj/iEgTgG/nv3Da4nFusdr0W2EuKpCOGFf7zp0 9qD93QtxHTxHjiKaXT8OjIk02WTABfldL5XjJ66ee/KBneCgE7IccYG+eydOwRetLFYXYqZPTS2 CYH29z9iWmvBh1Y5pUsvAgnFE3HxCDGQgBbMzJ029XG6X5mYVWssg/l7CvwHT0g2HMDz8AlhVMr AAQM6QbDR6M+Sh X-Google-Smtp-Source: AGHT+IFlwJ8jzqml8p7pl2J3oMzgLTQfcgsuD20WC0CAMT0Kiox2+jlMUU3+KAfKAANzCUfyy/pcXQ== X-Received: by 2002:a05:6602:6404:b0:887:5303:b3f9 with SMTP id ca18e2360f4ac-9016857dec4mr781816939f.10.1758835658292; Thu, 25 Sep 2025 14:27:38 -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-903f6ea2edasm110908139f.6.2025.09.25.14.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Sep 2025 14:27:37 -0700 (PDT) Date: Thu, 25 Sep 2025 16:27:35 -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="WmTuzfKinJM6DHM0" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --WmTuzfKinJM6DHM0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Sep 25, 2025 at 02:10:19PM -0500, Nathan Bossart wrote: > Here's a new version of 0002 with a modified SSE2 implementation, as > discussed elsewhere [0]. This allows us to remove vector8_ssub(). Sorry for the noise. v3 fixes the mixed-declarations-and-code problems. -- nathan --WmTuzfKinJM6DHM0 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v3-0001-Optimize-vector8_has_le-on-AArch64.patch From 2d355136c9b6aede2c1cb6f8f08fa7eacd032b61 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 22 Sep 2025 16:17:09 -0500 Subject: [PATCH v3 1/1] Optimize vector8_has_le() on AArch64. --- src/include/port/simd.h | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 97c5f353022..79dd1f76962 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 /* @@ -213,6 +212,10 @@ static inline bool vector8_has_le(const Vector8 v, const uint8 c) { bool result = false; +#ifdef USE_SSE2 + Vector8 umin; + Vector8 cmpe; +#endif /* pre-compute the result for assert checking */ #ifdef USE_ASSERT_CHECKING @@ -250,14 +253,12 @@ vector8_has_le(const Vector8 v, const uint8 c) } } } -#else - - /* - * 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))); +#elif defined(USE_SSE2) + umin = _mm_min_epu8(v, vector8_broadcast(c)); + cmpe = _mm_cmpeq_epi8(umin, v); + result = vector8_is_highbit_set(cmpe); +#elif defined(USE_NEON) + result = vminvq_u8(v) <= c; #endif Assert(assert_result == result); @@ -358,24 +359,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) --WmTuzfKinJM6DHM0--