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

Swizzle support #15

Closed
bitshifter opened this issue Jul 23, 2019 · 2 comments
Closed

Swizzle support #15

bitshifter opened this issue Jul 23, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@bitshifter
Copy link
Owner

bitshifter commented Jul 23, 2019

It would be good to support generic swizzles.

Ideally this would support swizzling to return the same size vector but a long term goal would be to provide swizzling into a vector of a different size, smaller or larger.

The problem with SSE2 shuffles is the mask needs to be constant. The intrinsic itself is not a const function so I can't provide a method that will take a mask or at least I don't think that's possible. There are a couple of alternatives:

  • Generate shuffle methods for all possible permutations. This is what pathfinder does but that's 255 methods for swizzling a Vec4 to another Vec4, potentially more if swizzling to a different size is supported. My main concern with this approach is making sure it doesn't make a mess of the docs.
  • Use macros - the underlying __m128 is accessible so I think a macro solution would be possible. I would probably provide vec4_swizzle, vec3_swizzle, and vec2_swizzle so that the type is known and the number of lanes specified in the macro could be used to specify the output size.
@bitshifter bitshifter added the enhancement New feature or request label Jul 23, 2019
@Lokathor
Copy link

Lokathor commented Aug 8, 2019

Just write a program to auto-generate all the swizzles

it's only 4000 lines of code give or take once the program prints it out ;3

@bitshifter bitshifter changed the title Write a shuffle macro Swizzle support Oct 23, 2020
bitshifter added a commit that referenced this issue Oct 27, 2020
Add vector swizzle functions.

Fixes #14 and #15.
@bitshifter
Copy link
Owner Author

I wrote a program to generate all the swizzles :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants