I was confused in the previous post, sorry. That has nothing to do with simd
:
using Random
broadcast_randn(x) = (x .= randn.())
inplace_randn(x) = randn!(x)
function myrandn!(x)
@inbounds @simd for i in eachindex(x)
x[i] = randn()
end
x
end
function myrandn_nosimd!(x)
@inbounds for i in eachindex(x)
x[i] = randn()
end
x
end
x = zeros(10_000)
@btime broadcast_randn($x);
@btime inplace_randn($x);
@btime myrandn!($x);
@btime myrandn_nosimd!($x);
is only slow in inplace_randn
. The real difference in the two cases is that randn
isn’t inlined in randn!
. This is despite randn
being marked as @inline
, so it looks like the inlining heuristics are being too conservative here.