pgvector.git / summary / log / commit / refs

commit    3eba34e5e37bf6fe651e7c98b232ef8ffdc75fdd
Author:   Andrew Kane <andrew@ankane.org>
Date:     Mon Apr 08 21:40:12 2024 +0000

    Improved code for feature detection


src/halfutils.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/halfutils.c b/src/halfutils.c index c53da83d..7485e9d8 100644 --- a/src/halfutils.c +++ b/src/halfutils.c @@ -118,8 +118,11 @@ HalfvecInnerProductF16cFma(int dim, half * ax, half * bx) #endif #ifdef HALFVEC_DISPATCH +#define FEATURE_FMA (1 << 12) +#define FEATURE_F16C (1 << 29) + static bool -F16cFmaAvailable() +SupportsFeature(unsigned int feature) { unsigned int exx[4] = {0, 0, 0, 0}; @@ -129,8 +132,7 @@ F16cFmaAvailable() __cpuid(exx, 1); #endif - /* FMA = 12, F16C = 29 */ - return (exx[2] & (1 << 12)) != 0 && (exx[2] & (1 << 29)) != 0; + return (exx[2] & feature) == feature; } #endif @@ -145,7 +147,7 @@ HalfvecInit(void) HalfvecInnerProduct = HalfvecInnerProductDefault; #ifdef HALFVEC_DISPATCH - if (F16cFmaAvailable()) + if (SupportsFeature(FEATURE_FMA | FEATURE_F16C)) { HalfvecL2DistanceSquared = HalfvecL2DistanceSquaredF16cFma; HalfvecInnerProduct = HalfvecInnerProductF16cFma; [parent: 862f17c1de9f]