mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 12:07:34 +08:00
Compare commits
2 Commits
v0.8.1
...
neon-intri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ff9f6511a | ||
|
|
17855c9861 |
@@ -1,5 +1,7 @@
|
|||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include <arm_neon.h>
|
||||||
|
|
||||||
#include "halfutils.h"
|
#include "halfutils.h"
|
||||||
#include "halfvec.h"
|
#include "halfvec.h"
|
||||||
|
|
||||||
@@ -28,9 +30,27 @@ static float
|
|||||||
HalfvecL2SquaredDistanceDefault(int dim, half * ax, half * bx)
|
HalfvecL2SquaredDistanceDefault(int dim, half * ax, half * bx)
|
||||||
{
|
{
|
||||||
float distance = 0.0;
|
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 */
|
/* Auto-vectorized */
|
||||||
for (int i = 0; i < dim; i++)
|
for (; i < dim; i++)
|
||||||
{
|
{
|
||||||
float diff = HalfToFloat4(ax[i]) - HalfToFloat4(bx[i]);
|
float diff = HalfToFloat4(ax[i]) - HalfToFloat4(bx[i]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user