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

wip: constexpr vec (constructors) when using simd #1313

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

sharkautarch
Copy link

@sharkautarch sharkautarch commented Sep 11, 2024

Yes this is creating a whole new vec implementation, because trying to add std::is_constant_evaluated() while also making both constexpr and simd work well, and also maintain backwards compatibility would be too complicated to incorporate into the pre-existing vec classes.

oh also this is only compatible with gcc and clang, because it makes use of gcc’s vector extension for simd in vec’s comstructors (for when std::is_constant_evaluated() = false)
This is because it allows me to write one simd construction function that works for all vec lengths (and I will be adding support for use w/ packed vecs soon)

I don't intend this separate vec implementation to make the pre-existing vec implementations deprecated, this is just the most straightforward way to make constexpr work well w/ simd, without making the entire codebase unreadable

@sharkautarch
Copy link
Author

sharkautarch commented Sep 11, 2024

Todo:

  • Add all the operators to this vec struct
  • Edit the setup headers so that the simd define bits are enabled when using the c++20 vec class
  • Add support for packed vec types by changing the gcc vec attributes to __attribute__((vector_size(sizeof(T)*L), aligned(alignof(data_t))))
  • Add support for converting a packed vec to an aligned vec & vice versa (I’ll probably just use a non-constexpr constructor for this to make things simpler)
    ^ after adding support for packed vecs, now I’m pretty sure that the current constructors should now already allow converting between packed and unpacked vecs

@sharkautarch
Copy link
Author

sharkautarch commented Sep 11, 2024

I did a small amount of testing, (though only with aligned highp vec4), so far things are seeming to work OK~~, except:~~

When swizzling w/ .y (etc), passing stuff to c-style va_arg functions via a direct swizzle expression (ex: printf("%f\n", v.y); prints 0.000 no matter what) is broken
I think it is because of default conversions that are specific to only c-style va_arg functions:
https://en.cppreference.com/w/cpp/language/variadic_arguments
Edit: I fixed the aforementioned issue

@sharkautarch
Copy link
Author

sharkautarch commented Sep 27, 2024

New feature added: swizzling functions (enabled by default)
They leverage the compiler intrinsic (this is done for both packed and aligned vecs) __builtin_shufflevector() so that the swizzle functions will get optimized into simd shuffle/blend instructions.

Tho you have to specify at least two swizzle members, max N swizzle members for vec of length N, and you can’t have duplicate members (you can’t swizzle vec1’s because that’d be silly). Example: v.yzx(), v.gbr()

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.

1 participant