Skip to content

Commit 73eb5bc

Browse files
committed
Use at-simd in _vecdot instead of manually unrolling and relying on the SLP vectorizer.
1 parent ec26f0a commit 73eb5bc

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/linalg.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,17 @@ end
215215
end
216216

217217
@inline dot(a::StaticVector, b::StaticVector) = _vecdot(same_size(a, b), a, b)
218-
@generated function _vecdot(::Size{S}, a::StaticArray, b::StaticArray) where {S}
218+
@inline function _vecdot(::Size{S}, a::StaticArray, b::StaticArray) where {S}
219219
if prod(S) == 0
220-
return :(zero(promote_op(*, eltype(a), eltype(b))))
221-
end
222-
223-
expr = :(adjoint(a[1]) * b[1])
224-
for j = 2:prod(S)
225-
expr = :($expr + adjoint(a[$j]) * b[$j])
220+
return zero(promote_op(*, eltype(a), eltype(b)))
226221
end
227-
228-
return quote
229-
@_inline_meta
230-
@inbounds return $expr
222+
za = zero(a[1])
223+
zb = zero(b[1])
224+
ret = adjoint(za) * zb + adjoint(za) * zb
225+
@inbounds @simd for j = 1 : prod(S)
226+
ret += adjoint(a[j]) * b[j]
231227
end
228+
return ret
232229
end
233230

234231
@inline bilinear_vecdot(a::StaticArray, b::StaticArray) = _bilinear_vecdot(same_size(a, b), a, b)

0 commit comments

Comments
 (0)