4

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 of 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!

YuChan Tai
  • 73
  • 3
  • One question per question please - your two questions above are seemingly unrelated and should therefore be in two separate questions on SO. – Paul R Feb 07 '23 at 11:04
  • Please check the [guide](https://stackoverflow.com/help/how-to-ask) on how to ask questions. – sigod Feb 07 '23 at 17:50
  • Thanks for reminding me. I have edited my post with a more specific question. – YuChan Tai Feb 08 '23 at 02:24

1 Answers1

1

There is unfortunately no Zig equivalent to the Julia code you provided.

I don't think there is need for such tags in Zig. It's reasonable to trust the compiler that it will do the right thing: https://godbolt.org/z/KoGbqEvYf. And if it doesn't, you should file a bug on the zig/llvm compiler :D

Somewhat related: 7702 9389

prokop
  • 23
  • 5