Compare commits

...

2 Commits

Author SHA1 Message Date
Andrew Kane
0ff9f6511a Use f32 [skip ci] 2024-04-27 23:02:00 -07:00
Andrew Kane
17855c9861 Started Neon intrinsics [skip ci] 2024-04-27 22:50:47 -07:00

View File

@@ -1,5 +1,7 @@
#include "postgres.h"
#include <arm_neon.h>
#include "halfutils.h"
#include "halfvec.h"
@@ -28,9 +30,27 @@ static float
HalfvecL2SquaredDistanceDefault(int dim, half * ax, half * bx)
{
float distance = 0.0;
int i = 0;
/* TODO Improve */
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
int count = (dim / 4) * 4;
float32x4_t dist = vmovq_n_f32(0);
for (; i < count; i += 4)
{
float16x4_t axs = vld1_f16((const __fp16 *) (ax + i));
float16x4_t bxs = vld1_f16((const __fp16 *) (bx + i));
float32x4_t diff = vsubq_f32(vcvt_f32_f16(axs), vcvt_f32_f16(bxs));
dist = vfmaq_f32(dist, diff, diff);
}
distance += vaddvq_f32(dist);
#endif
/* Auto-vectorized */
for (int i = 0; i < dim; i++)
for (; i < dim; i++)
{
float diff = HalfToFloat4(ax[i]) - HalfToFloat4(bx[i]);