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.96) (envelope-from ) id 1wf5Ls-005Fgv-1v for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 00:32:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wf5Lr-00GNB8-0u for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 00:32:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wf5Lq-00GNB0-3C for pgsql-hackers@lists.postgresql.org; Thu, 02 Jul 2026 00:32:22 +0000 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wf5Lo-000000019tE-4Btp for pgsql-hackers@postgresql.org; Thu, 02 Jul 2026 00:32:21 +0000 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-6a308736a36so671805eaf.3 for ; Wed, 01 Jul 2026 17:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782952340; x=1783557140; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=cXfqVIUv67wTliwX6d1Rq//z0THBL/fLfDzlOPktpqQ=; b=csOXt7fksG6S9iVrxDK7TXhWQdVMu1hn5oHhSh46vh+QYyELSHi8W/cs8HPt8u0/or THrcbNHeMmNCvBVIMz4Fv6nqTyQXOVfsoOOYjx76OOce6UXrDIHaaBlDr2TzeOre2VbJ eCWairZAI1G/KPjE6tuCRGC+V8kYZjBHq4NrSMUf0GxkfGwk3GnN8yzMt/ZLKiBgqWZy 7d/TN3xVBGM4HIiL/dM5F1Ke9Whj7mlmv3MQ/FPAn4/NctQaV2FxJHjsjs7ket8SgzgY DxgsSPTBxI3c+jad4cAZyhXoVGg4hVyvFp2311zy0YVmrrJdRkrnfrqWsIeGet1aUTf8 GgZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782952340; x=1783557140; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cXfqVIUv67wTliwX6d1Rq//z0THBL/fLfDzlOPktpqQ=; b=lRjxUtmaeYvbSsPkovvvbOvNi5A7NoV+BeeBG1zTEZyMvRMGx53PsDNT4Zc3wSqEYU tmTYX7jlTWC8i166mXbmAFEeRD9DTzem1Y60+65T0Kg9J6NGq1VTad4y/oknbUhrI1c+ 8hqZrk72dIO48C3nuEl6+iL/lX+r30Q/y7cuVz7ZqJTZcTYCfIeMvuRVzfqClxI60Q27 g9ZxRH0FTXHjljIoUra2gJdygibnrAf47Ihi/RV/lVWpNq7IP+osZMUewHD5ZU/bcvDQ Gky7eAvu1q7G9wszF4oJbgaC5a0k7qflun5g+Ls8IhXgOdz/wLDrcnj7AT5aLEXaj57m 28ag== X-Gm-Message-State: AOJu0YyAzdVt83CRAcpivh1epZ6aJYCZm1jUC0s8d0d5FDIS3KbnmliV EPPBdyUnDQmhgFLriaHau8ZDRyXJVCCmfZpkQAOTFOEa6CJ1hiLwm1ZlCc7VVw== X-Gm-Gg: AfdE7clI7VSW8QHAsXyEtparBCn+iBZ1xNu4Sz0oo//Mq3OoDHKacg53kS2fCyfhDmU tstmwVqZaSp1JfulcRgjywy89zEoFuqjAOsQhjYSRNRrZ4XhA3aCnvPQXGnNop0qDyMpnzzHiuD yi7azvfKiOQsOoJOtsMKhllUwa5AX95q2llCP0GD7PIm87coLnJaki15M4w/bVlZ4ZAusFCDqCv LKqcWbxwo/3xiMJ/Vz0rvMvXgMxt9+0QLdwgUFdazRWMiY4eMVPUOPRWz4fzSh9k161Hx2y04Xt TJseu4FNj2XnajBTbPUozeNN4Q8y2BzZQ1673MK37P+FYm/Bv1zppQouVLsGAhC68MF4cwHiyeB k3zpBkQJZPRub/RiZL2jjr9Uy5UmgyHFhjmRmv0WmOtKocORHYnSY3+moqgJOr9lUneyy0jItnX bzNfjs1PDSUqjpp68EnMI10RNuw3zkSwKZwKdulGpwtox2mCYJlh2EHJO66stJLpaBwnRgqKJnf aynMdWsafU= X-Received: by 2002:a4a:e910:0:b0:6a1:475f:1354 with SMTP id 006d021491bc7-6a30d79e1f1mr1999268eaf.21.1782952340161; Wed, 01 Jul 2026 17:32:20 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6a3103e064esm1103379eaf.14.2026.07.01.17.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 17:32:19 -0700 (PDT) Date: Wed, 1 Jul 2026 19:32:16 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Cc: johncnaylorls@gmail.com Subject: remove switch statement in vector8_shift_{left,right} Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9YipY07vKHAnXga/" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --9YipY07vKHAnXga/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In commit ec8719ccbf, I added a switch statement with all expected shift counts for vector8_shift_{left,right} because AArch64's vshlq_n_u32 and vshrq_n_u32 require an integer literal. I discovered that we can use vshlq_u32 instead for both cases, which avoids the need for the switch statement and compiles to the same machine code on recent gcc/clang. -- nathan --9YipY07vKHAnXga/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-remove-switch-statement-in-vector8_shift_-left-ri.patch From 12b9db50eed370ba94ed4a7c4c9dd2218bad5f48 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 1 Jul 2026 19:30:59 -0500 Subject: [PATCH v1 1/1] remove switch statement in vector8_shift_{left,right} --- src/include/port/simd.h | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/include/port/simd.h b/src/include/port/simd.h index 50615aec7f4..25a26c81cce 100644 --- a/src/include/port/simd.h +++ b/src/include/port/simd.h @@ -548,10 +548,6 @@ vector8_pack_16(const Vector8 v1, const Vector8 v2) /* * Unsigned shift left of each 32-bit element in the vector by "i" bits. - * - * XXX AArch64 requires an integer literal, so we have to list all expected - * values of "i" from all callers in a switch statement. If you add a new - * caller, be sure your expected values of "i" are handled. */ #ifndef USE_NO_SIMD static inline Vector8 @@ -560,24 +556,13 @@ vector8_shift_left(const Vector8 v1, int i) #ifdef USE_SSE2 return _mm_slli_epi32(v1, i); #elif defined(USE_NEON) - switch (i) - { - case 4: - return (Vector8) vshlq_n_u32((Vector32) v1, 4); - default: - Assert(false); - return vector8_broadcast(0); - } + return (Vector8) vshlq_u32((Vector32) v1, vdupq_n_s32(i)); #endif } #endif /* ! USE_NO_SIMD */ /* * Unsigned shift right of each 32-bit element in the vector by "i" bits. - * - * XXX AArch64 requires an integer literal, so we have to list all expected - * values of "i" from all callers in a switch statement. If you add a new - * caller, be sure your expected values of "i" are handled. */ #ifndef USE_NO_SIMD static inline Vector8 @@ -586,16 +571,8 @@ vector8_shift_right(const Vector8 v1, int i) #ifdef USE_SSE2 return _mm_srli_epi32(v1, i); #elif defined(USE_NEON) - switch (i) - { - case 4: - return (Vector8) vshrq_n_u32((Vector32) v1, 4); - case 8: - return (Vector8) vshrq_n_u32((Vector32) v1, 8); - default: - Assert(false); - return vector8_broadcast(0); - } + /* negative shift count means right shift */ + return (Vector8) vshlq_u32((Vector32) v1, vdupq_n_s32(-i)); #endif } #endif /* ! USE_NO_SIMD */ -- 2.50.1 (Apple Git-155) --9YipY07vKHAnXga/--