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
This commit is contained in:
Jon Daniel
2025-06-18 19:09:43 -04:00
committed by GitHub
parent bf28ed8176
commit fe697e8788

View File

@@ -295,8 +295,10 @@ static void
VectorSumCenter(Pointer v, float *x) VectorSumCenter(Pointer v, float *x)
{ {
Vector *vec = (Vector *) v; 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]; x[k] += vec->x[k];
} }
@@ -304,8 +306,10 @@ static void
HalfvecSumCenter(Pointer v, float *x) HalfvecSumCenter(Pointer v, float *x)
{ {
HalfVector *vec = (HalfVector *) v; 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]); x[k] += HalfToFloat4(vec->x[k]);
} }