From fe697e878808383b3546db335ae47d61ffec57fa Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 18 Jun 2025 19:09:43 -0400 Subject: [PATCH] vectorize: optimize VectorSumCenter and HalfvecSumCenter (#860) * vectorize: optimize VectorSumCenter and HalfvecSumCenter The functions VectorSumCenter and HalfvecSumCenter were not being vectorized by the compiler. A few slight changes will allow these optimizations to take place and get a performance boost by utilizing SIMD instructions. This optimization helps improve performance of vector operations in IVF index building and updating. * Removing const, commenting that it is only vectoirzed on ARM --- src/ivfutils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ivfutils.c b/src/ivfutils.c index da241ee..044fbab 100644 --- a/src/ivfutils.c +++ b/src/ivfutils.c @@ -295,8 +295,10 @@ static void VectorSumCenter(Pointer v, float *x) { Vector *vec = (Vector *) v; + int dim = vec->dim; - for (int k = 0; k < vec->dim; k++) + /* Auto-vectorized */ + for (int k = 0; k < dim; k++) x[k] += vec->x[k]; } @@ -304,8 +306,10 @@ static void HalfvecSumCenter(Pointer v, float *x) { HalfVector *vec = (HalfVector *) v; + int dim = vec->dim; - for (int k = 0; k < vec->dim; k++) + /* Auto-vectorized on aarch64 */ + for (int k = 0; k < dim; k++) x[k] += HalfToFloat4(vec->x[k]); }