From: mohakgoel1 (@mohakgoel1) <noreply+mohakgoel1@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #1067: [Arm CPU] Add SVE2 distance functions for halfvec on AArch64
Date: Thu, 19 Nov 2026 05:45:27 +0000
Message-ID: <gh-pgvector-pgvector-1067-c7000914309@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1067@github.com>
References: <gh-pgvector-pgvector-1067@github.com>
> Hi [@abhijain1204fujitsu](https://github.com/abhijain1204fujitsu), it looks like you've disabled SVE/SVE2 instructions in the baseline (`OPTFLAGS=""`). If the goal is runtime dispatch, I think it'd be better to use function multiversioning / `target_clones` like [#311](https://github.com/pgvector/pgvector/pull/311).
On the baseline: I used `OPTFLAGS=""` because that's how binary distributions build pgvector (e.g. the Debian `no-native` patch mentioned in #311), so it reflects what most packaged and cloud deployments run, and the case runtime dispatch is meant for. I've also compared against a `-march=native` baseline in my previous comment: the SVE2 kernels are still 1.6–2.4x faster with data in cache.
On `target_clones`: since it compiles the same C body for each target, it can't produce these kernels. As you found, compilers don't generate `FMLALB`/`FMLALT` from the scalar loop, and in my tests the SVE/SVE2 auto-vectorized clones measured 0.91–1.04x. The benefit needs explicit intrinsics, as with the F16C path for `halfvec` on x86, so I followed the same pattern as `HalfvecInit()`: a load-time `getauxval(AT_HWCAP2) & HWCAP2_SVE2` check that selects function pointers.
Function multiversioning with a separate body per target (`target_version("sve2")` / `target_version("default")`) would also work. I tried it, but it requires GCC 14+ or Clang with the compiler-rt runtime: Clang 17 with libgcc compiled it but silently dropped the SVE2 version, and GCC 12/13 don't support it on AArch64. The current approach works with GCC 12+ and Clang 16+ regardless of runtime library.
Happy to switch to `target_version` if you prefer it for consistency with future AArch64 dispatch. Let me know which you'd like.