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

Function ip_impl

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

Source from the content-addressed store, hash-verified

81
82#[target_feature(enable = "avx2,fma")]
83unsafe fn ip_impl(a: &[f32], b: &[f32]) -> f32 {
84 assert_eq!(a.len(), b.len(), "avx2 ip_impl: length mismatch");
85 unsafe {
86 use std::arch::x86_64::*;
87 let n = a.len();
88 let mut vdot = _mm256_setzero_ps();
89 let chunks = n / 8;
90 for i in 0..chunks {
91 let off = i * 8;
92 let va = _mm256_loadu_ps(a.as_ptr().add(off));
93 let vb = _mm256_loadu_ps(b.as_ptr().add(off));
94 vdot = _mm256_fmadd_ps(va, vb, vdot);
95 }
96 let mut dot = hsum256(vdot);
97 for i in (chunks * 8)..n {
98 dot += a[i] * b[i];
99 }
100 -dot
101 }
102}
103
104/// Horizontal sum of 8 × f32 in a __m256.
105#[target_feature(enable = "avx2")]

Callers 1

neg_inner_productFunction · 0.70

Calls 4

hsum256Function · 0.70
lenMethod · 0.45
addMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected