Skip to content
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

Simd array #3580

Closed
wants to merge 4 commits into from
Closed

Simd array #3580

wants to merge 4 commits into from

Conversation

shawnl
Copy link
Contributor

@shawnl shawnl commented Nov 3, 2019

This is the first pull request that adds array access of vectors to zig, extracted from #2945. It implements

a[4] = 5;
i = a[4];

and that index also being a scalar integer. There will be another PR with @scatter and @gather and some vector array accesses that lower to these, and then another (not yet written) that implements pointers to vector elements the way gcc-9 does it.

Lots of pain was caused by a5cb0f7
This brings up to parity to clang and gcc < 9.
@dimenus
Copy link
Contributor

dimenus commented Nov 3, 2019

@shawnl I have a couple tests that currently fail.

these both fail to compile on vanilla zig, but segfault the compiler (ir.cpp:16111) in your pr:

test "vector literal" {
    const S = struct {
        fn doTheTest() void {
            var foo = @Vector(4, f32) { 1, 2, 3, 4 };
        }
    };
    S.doTheTest();
    //comptime S.doTheTest();
}
const Vec4Obj = struct {
    data: @Vector(4, f32),
};

test "vector in a struct" {
    const S = struct {
        fn doTheTest() void {
            var foo = Vec4Obj {
                .data = [_]f32 { 1, 2, 3, 4},
            };
        }
    };
    S.doTheTest();
    comptime S.doTheTest();
}

@shawnl
Copy link
Contributor Author

shawnl commented Nov 3, 2019

@dimenus thanks. I fixed the first, and while I managed to make the second not crash the compiler, the assignment is not going anywhere because vectors do not use ResultLoc as they need to (I am working on this already for getting &a[4] to work).

@shawnl
Copy link
Contributor Author

shawnl commented Nov 3, 2019

I guess actually supporting vector literals is a change in the language, but I don't see why we have to do it by casting from array (which was the original design and how I've always done it).

If we are going to prohibit vector literals, I think we should also prohibit array literals that use a array type (and only allow them with scalar types), so that this code no longer works:

test "array type literal" {
    const S = struct {
        const A = [4]f32;
        fn doTheTest() void {
            var foo = A{ 1, 2, 3, 4 };
        }
    };
    S.doTheTest();
    comptime S.doTheTest();
}

<andrewrk> tomorrow, end of day, ziglang#3580 will be closed and ziglang#3575 will be
closed, and dimenus's examples will work (except for vector literals which
is not happening, see ziglang#208)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants