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

Proposal: Rename SIMD vectors #7305

Open
ikskuh opened this issue Dec 4, 2020 · 7 comments
Open

Proposal: Rename SIMD vectors #7305

ikskuh opened this issue Dec 4, 2020 · 7 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@ikskuh
Copy link
Contributor

ikskuh commented Dec 4, 2020

#7295 once again shows once again that most programmers associate the word vector with a linear algebra vector type and not with a SIMD vector.

I proposa a rename to SIMD array, but i'm open for other names. I'm pretty much happy with any name that is not vector, as it is more confusing than helping.

@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Dec 4, 2020
@Vexu Vexu added this to the 0.8.0 milestone Dec 4, 2020
@zigazeljko
Copy link
Contributor

For the type itself, we can simply use the name Simd (e.g. std.builtin.TypeInfo.Simd, std.meta.Simd).

@PetorSFZ
Copy link

PetorSFZ commented Dec 5, 2020

Why not just call them SIMD registers? Would also give it some synergy with the register keyword in C, as I assume you can't take the reference to a SIMD register or store it in a struct anyway.

@SpexGuy
Copy link
Contributor

SpexGuy commented Dec 5, 2020

I assume you can't take the reference to a SIMD register or store it in a struct anyway.

You can do this, it behaves more like __m128 from C. It can be stored in memory, and it's aligned to the appropriate alignment for fast access on your target platform. It's more like an array type but with support for parallel operations and more alignment.

@PetorSFZ
Copy link

PetorSFZ commented Dec 5, 2020

I assume you can't take the reference to a SIMD register or store it in a struct anyway.

You can do this, it behaves more like __m128 from C. It can be stored in memory, and it's aligned to the appropriate alignment for fast access on your target platform. It's more like an array type but with support for parallel operations and more alignment.

Huh, that's sort of weird. I always thought that was one of the biggest mistakes with __m128. Unless you have many elements you are processing (i.e. an array) SIMD is basically pointless. And having an array of __m128 is just weird.

@ikskuh
Copy link
Contributor Author

ikskuh commented Dec 5, 2020

For the type itself, we can simply use the name Simd (e.g. std.builtin.TypeInfo.Simd, std.meta.Simd).

I think that would be the most fitting type. "It's a type that provides simultaneous operations on a range of data".

As @SpexGuy said, Simd types aren't Simd register equivalents and may be emulated if the hardware doesn't support it, but allows to express the intent to process the data in parallel if possible

@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@floooh
Copy link
Contributor

floooh commented Jul 16, 2021

Sorry for my drive by comment, but for game and graphics programmers, the name "vector" is associated with vector math (of length 2 to 4), and the std::vector<> type name doesn't make much sense. The name SIMD would imply to me that SIMD registers/instructions are always involved, but this shouldn't be the case(?)

Whether the code is actually translated to SIMD instructions should depend on the target platform and compiler options (for instance it should still be possible to compile to WASM without SIMD support).

It would be great IMHO, if Zig could offer the feature set of Clangs ext_vector_type C extension (the ext is important), this seems to enable math code that looks identical to shading languages like GLSL or HLSL (for instance swizzling, or multiplying with a scalar):

https://www.godbolt.org/z/zWGfcY5a4

The other thing that's needed to be "feature complete" is an ext_matrix_type which seamlessly works together with ext_vector_type vectors.

@SpexGuy
Copy link
Contributor

SpexGuy commented Sep 15, 2021

The goal isn't so much to guarantee simd, but to encourage it. The semantics of other language constructs make it difficult or impossible to auto-vectorize code in most cases. Zig's Vector is trying to provide the optimizer with semantics that are more compatible to vectorization. It's not a hard guarantee that simd will be used, but the feature is designed in such a way that simd is usually the best way for the optimizer to implement it. However, the feature is defined in a way that does not strictly require hardware simd support. So if you are compiling to a platform that doesn't have simd instructions, the program will still compile and run correctly. Additionally, if you are for example doing a large number of by-element vector accesses on a platform with only SSE2, the optimizer may realize that simd would be less efficient than scalars, and decide to destructure the vector into multiple scalar values instead.

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

7 participants