Vectorizing vector_concat for improved performance (#861)

* Vectorizing vector_concat for improved performance

On an ARM chip this should generate SIMD instructions to copy the two
incoming vectors to the new vector as opposed to doing it all in
software.

* Moving declarations to above CheckDim

* Removing const from dims

* Formatting
This commit is contained in:
Jon Daniel authored and GitHub committed 2025-06-18 20:06:32 -07:00
1 parent ce09c9a27a
commit 3a49d141b3
1 file changed
+7 -3
+7 -3
View File
@@ -916,15 +916,19 @@ vector_concat(PG_FUNCTION_ARGS)
Vector *b = PG_GETARG_VECTOR_P(1);
Vector *result;
int dim = a->dim + b->dim;
int dim_a = a->dim;
int dim_b = b->dim;
CheckDim(dim);
result = InitVector(dim);
for (int i = 0; i < a->dim; i++)
/* Auto-vectorized */
for (int i = 0; i < dim_a; i++)
result->x[i] = a->x[i];
for (int i = 0; i < b->dim; i++)
result->x[i + a->dim] = b->x[i];
/* Auto-vectorized */
for (int i = 0; i < dim_b; i++)
result->x[i + dim_a] = b->x[i];
PG_RETURN_POINTER(result);
}