MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / ip_impl

Function ip_impl

nodedb-vector/src/distance/simd/avx512.rs:82–101  ·  view source on GitHub ↗
(a: &[f32], b: &[f32])

Source from the content-addressed store, hash-verified

80
81#[target_feature(enable = "avx512f")]
82unsafe fn ip_impl(a: &[f32], b: &[f32]) -> f32 {
83 assert_eq!(a.len(), b.len(), "avx512 ip_impl: length mismatch");
84 unsafe {
85 use std::arch::x86_64::*;
86 let n = a.len();
87 let mut vdot = _mm512_setzero_ps();
88 let chunks = n / 16;
89 for i in 0..chunks {
90 let off = i * 16;
91 let va = _mm512_loadu_ps(a.as_ptr().add(off));
92 let vb = _mm512_loadu_ps(b.as_ptr().add(off));
93 vdot = _mm512_fmadd_ps(va, vb, vdot);
94 }
95 let mut dot = _mm512_reduce_add_ps(vdot);
96 for i in (chunks * 16)..n {
97 dot += a[i] * b[i];
98 }
99 -dot
100 }
101}

Callers 1

neg_inner_productFunction · 0.70

Calls 3

lenMethod · 0.45
addMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected