diff --git a/CHANGELOG.md b/CHANGELOG.md index edc5da8..b38b189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added `hamming_distance` function - Added `jaccard_distance` function - Added `subvector` function +- Added CPU dispatching for distance functions on Linux x86-64 - Updated comparison operators to support vectors with different dimensions ## 0.6.2 (2024-03-18) diff --git a/src/vector.c b/src/vector.c index 2e50fca..065a5aa 100644 --- a/src/vector.c +++ b/src/vector.c @@ -33,6 +33,13 @@ #define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1) #define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1)) +/* target_clones requires glibc */ +#if defined(__x86_64__) && defined(__gnu_linux__) && defined(__has_attribute) && __has_attribute(target_clones) && !defined(__FMA__) +#define VECTOR_DISPATCH __attribute__((target_clones("default", "fma"))) +#else +#define VECTOR_DISPATCH +#endif + PG_MODULE_MAGIC; /* @@ -557,7 +564,7 @@ halfvec_to_vector(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } -static float +VECTOR_DISPATCH static float VectorL2SquaredDistance(int dim, float *ax, float *bx) { float distance = 0.0; @@ -604,7 +611,7 @@ vector_l2_squared_distance(PG_FUNCTION_ARGS) PG_RETURN_FLOAT8((double) VectorL2SquaredDistance(a->dim, a->x, b->x)); } -static float +VECTOR_DISPATCH static float VectorInnerProduct(int dim, float *ax, float *bx) { float distance = 0.0;