mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
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:
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user