- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
design flaw: SIMD vectors are indexable in an inconsistent way #5427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What's wrong? const std = @import("std");
const meta = std.meta;
const warn = std.debug.warn;
const isIndexable = meta.trait.isIndexable;
pub fn main() void {
const int32: i32 = 0;
const array = [_]u8{0} ** 10;
const vector: meta.Vector(2, u32) = [_]u32{0} ** 2;
warn("isIndexable(int32): {}\n", .{isIndexable(@TypeOf(int32))});
warn("isIndexable(&int32): {}\n", .{isIndexable(@TypeOf(&int32))});
warn("isIndexable(array): {}\n", .{isIndexable(@TypeOf(array))});
warn("isIndexable(&array): {}\n", .{isIndexable(@TypeOf(&array))});
warn("isIndexable(vector): {}\n", .{isIndexable(@TypeOf(vector))});
warn("isIndexable(&vector): {}\n", .{isIndexable(@TypeOf(&vector))});
warn("@typeInfo(&vector): {}\n", .{@typeInfo(@TypeOf(&vector))});
} Outputs:
|
This same discussion has happened over and over again for months, and I have answered it a number of times: if the index is scalar it addresses the element numbers. The extension is that if it is a vector, then it does a Both gcc and clang work this way. Unrelated, the big thing that caused me to drop my patch series on the floor was a technical mistake that means zig can't match gcc's feature set: runtime vector indexes. (that doesn't mean I understand how to use ResultLoc, which was the reason I couldn't get my code working doing it the way gcc does it).
@data-man This can be fixed, and gcc supports this. I dropped all my work on the floor when it looked like @andrewrk couldn't change his mind about an incorrect technical decision. (which was made while I was trying to tell him it was incorrect) |
You are absolutely correct. I apologize for forgetting this again.
I don't know what you are referring to. Please just open an issue to explain the situation rather than saying negative things about me |
I am sorry if that came across as an ad homonim. |
I'm confused about why this was closed; the inconsistency still exists. |
As @shawnl noted, if the index is scalar then it indexes elements. If the index is a vector, then it can perform array element access or struct field access. |
SIMD: #903
Thanks @daurnimator for pointing this out in #5425 (comment).
Currently, vectors are indexable:
zig/test/stage1/behavior/vector.zig
Lines 166 to 239 in 4b1a846
Using an index accesses the vector elements. However, this conflicts with the plan to have vectors of single-item pointers to structs. Already it is strange, because if you can index something then you would expect the
len
property to work. But vectors do not support this because if there is a vector of single-item pointers to structs, then one of the fields could belen
.But vectors could also be vectors of single-item pointers to arrays! In this case, in the same way that field access would work for the vector of struct pointers, indexing the vector should work on the inner array pointers.
Related: #5425 this would need to get reworked to check the element type
The text was updated successfully, but these errors were encountered: