Hello, I’ve been on Zig for 3 weeks and have started to try some simple numerical calculations.
After reading the Zig language reference, I found that the vector section states that a @Vector
will use SIMD instructions if possible. There is an example following up as
const a = @Vector(4, i32){ 1, 2, 3, 4 };
const b = @Vector(4, i32){ 5, 6, 7, 8 };
// Math operations take place element-wise.
const c = a + b;
, but I am looking for whether I can write a for
loop to manipulate a single @Vector
in place and guarantee to use SIMD instructions. For instance, I can utilize SIMD instructions as follows in Julia
.
arr = Vector{Float64}(under, 32)
@simd for i in eachindex(arr)
@inbounds arr[i] = 2 * i
end
Thanks for your help!