mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-03 03:00:56 +08:00
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
#ifndef HALFVEC_H
|
|
#define HALFVEC_H
|
|
|
|
#define __STDC_WANT_IEC_60559_TYPES_EXT__
|
|
|
|
#include <float.h>
|
|
|
|
#include "vector.h"
|
|
|
|
/* F16C has better performance than _Float16 (on x86-64) */
|
|
#if defined(__F16C__)
|
|
#define F16C_SUPPORT
|
|
/* TODO Improve detection */
|
|
#elif defined(_MSC_VER) && defined(__AVX2__)
|
|
#define F16C_SUPPORT
|
|
#elif defined(__FLT16_MAX__)
|
|
#define FLT16_SUPPORT
|
|
#else
|
|
#error "Not supported"
|
|
#endif
|
|
|
|
#ifdef FLT16_SUPPORT
|
|
#define half _Float16
|
|
#define HALF_MAX FLT16_MAX
|
|
#else
|
|
#define half uint16
|
|
#define HALF_MAX 65504
|
|
#endif
|
|
|
|
#define HALFVEC_MAX_DIM VECTOR_MAX_DIM
|
|
|
|
#define HALFVEC_SIZE(_dim) (offsetof(HalfVector, x) + sizeof(half)*(_dim))
|
|
#define DatumGetHalfVector(x) ((HalfVector *) PG_DETOAST_DATUM(x))
|
|
#define PG_GETARG_HALFVEC_P(x) DatumGetHalfVector(PG_GETARG_DATUM(x))
|
|
#define PG_RETURN_HALFVEC_P(x) PG_RETURN_POINTER(x)
|
|
|
|
typedef struct HalfVector
|
|
{
|
|
int32 vl_len_; /* varlena header (do not touch directly!) */
|
|
int16 dim; /* number of dimensions */
|
|
int16 unused;
|
|
half x[FLEXIBLE_ARRAY_MEMBER];
|
|
} HalfVector;
|
|
|
|
HalfVector *InitHalfVector(int dim);
|
|
float HalfToFloat4(half num);
|
|
half Float4ToHalf(float num);
|
|
half Float4ToHalfUnchecked(float num);
|
|
|
|
#endif
|