How can I utilize SIMD in Zig explicitly?

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

Thanks for your help!

I don’t have a direct answer, however I think this article might be interesting to you: Fast, multi-platform, SIMD math library in Zig - Zig NEWS

Maybe you can take a look at its implementation and find some useful techniques, I didn’t have time so far to check it out in more detail.

I also think you might find somebody who can help more quickly if you ask on the zig discord.
In general it seems more active, it has a general help section with lots of already answered questions, you could ask there.
It also has channels for os-dev and embedded, in those channels, there are people that know a lot about low level and performance details.