From 3a49d141b32359eaa4ea3b00940cb928ee6befc4 Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Wed, 18 Jun 2025 23:06:32 -0400 Subject: [PATCH] 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 --- src/vector.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vector.c b/src/vector.c index a5b2aac..0ced82b 100644 --- a/src/vector.c +++ b/src/vector.c @@ -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); }