I can't think of a reason not to allow a for loop over vector elements.
I'm not sure how SIMD is planned to work in Zig, but encouraging for loops (or just element access in general really) on what are supposed to be parallelized vector registers is playing a very dangerous game.
It encourages writing code with the hope it will auto-magically get vectorized. I admit that LLVM is pretty smart, but in general just blindly hoping that code vectorizes correctly is a complete crapshoot and very unreliable. That's part of why people so often take great pains to use intrinsics.
The root of the problem is that iteration over elements just isn't the correct programming model for vectors, you can't actually just access a single number from a SIMD register.
It's genuinely hard to write SIMD code, and it's even harder to read it, because SIMD is inherently a hard thing to do properly. You are forced to think about things like:
how reductions should happen (which creates other problems with floating point non-associativity)
Making a convenient syntax so that you can forget about the complexities and blindly write something like this:
for (a) |k, i| {
b[i] = somefunction(k, i);
}
Imo is a great disservice to the entire point of having a separation of vector and arrays in the first place. If you really want to write something like the above then you should be forced to convert a vector into an array first so that you understand that you are giving up parallelism.
Most helpful comment
I'm not sure how SIMD is planned to work in Zig, but encouraging for loops (or just element access in general really) on what are supposed to be parallelized vector registers is playing a very dangerous game.
It encourages writing code with the hope it will auto-magically get vectorized. I admit that LLVM is pretty smart, but in general just blindly hoping that code vectorizes correctly is a complete crapshoot and very unreliable. That's part of why people so often take great pains to use intrinsics.
The root of the problem is that iteration over elements just isn't the correct programming model for vectors, you can't actually just access a single number from a SIMD register.
It's genuinely hard to write SIMD code, and it's even harder to read it, because SIMD is inherently a hard thing to do properly. You are forced to think about things like:
how reductions should happen (which creates other problems with floating point non-associativity)
Making a convenient syntax so that you can forget about the complexities and blindly write something like this:
Imo is a great disservice to the entire point of having a separation of vector and arrays in the first place. If you really want to write something like the above then you should be forced to convert a vector into an array first so that you understand that you are giving up parallelism.