Skip to content

remove vector type; support SIMD operations on arrays directly #23327

Closed as not planned
@andrewrk

Description

@andrewrk

I could have sworn there was an issue for this already but I couldn't find it, so here it is.

Arrays coerce to vectors. Vectors coerce to arrays. What's the point of a separate type? I don't know of any type safety argument.

Typically, SIMD operations are performed on arrays. Converting between vector and array is a chore that does not accomplish anything.

There is also the awkwardness of @Vector as a way to create the type. There are multiple proposals (see below) trying to make the syntax more palatable.

Problems:

The vector type affects the ABI of C calling convention functions. This is load-bearing in compiler_rt for example:

const v2u64 = @Vector(2, u64);
fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 {

If anyone comes up with examples of how this could lead to worsened type safety (i.e. it could be easy to make a mistake and have a bug rather than compile error), that would be a critical flaw in this proposal that would be likely to make it rejected.

Finally, alignment. For many CPUs, vectors have larger alignment than arrays. This proposal is to keep arrays having the same alignment as status quo. To upgrade code that should lower to exactly the same machine code as before, those arrays that are used as vectors will need to be explicitly overaligned to vector alignment. Such extra alignment is a tradeoff; the more compact memory layout can help CPU cache efficiency, but vector alignment ensures that aligned vector load instructions can be selected rather than unaligned variants. Generally, programmers would be able to use default alignment, and then occasionally, after measuring, decide that the aligned vector load instructions are worth it to put an alignment annotation on the arrays that are used for SIMD operations.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions