Skip to content

Commit acf5db8

Browse files
authored
Merge pull request #33 from fslaborg/perf/optimize-dot-product-pairwise-reduction-20251012-151836-f4cfea086616c539-f0d309f462bb0265
Daily Perf Improver - Optimize dot product with Vector.Sum horizontal reduction
2 parents 609313c + 5089504 commit acf5db8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/FsMath/SpanMath.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ type SpanMath =
3636
let vy = Numerics.Vector<'T>(y.Slice(yi, simdWidth))
3737
accVec <- accVec + (vx * vy)
3838

39-
let mutable acc = LanguagePrimitives.GenericZero<'T>
40-
for i = 0 to simdWidth - 1 do
41-
acc <- acc + accVec.[i]
39+
// Use Vector.Sum for optimized horizontal reduction (uses hardware-specific instructions)
40+
let mutable acc = Numerics.Vector.Sum(accVec)
4241

42+
// Handle remaining elements (tail)
4343
for i = ceiling to length - 1 do
4444
acc <- acc + x.[xOffset + i] * y.[yOffset + i]
4545

0 commit comments

Comments
 (0)