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

Add saturating support #85

Open
danieltowner opened this issue May 9, 2023 · 6 comments
Open

Add saturating support #85

danieltowner opened this issue May 9, 2023 · 6 comments
Assignees

Comments

@danieltowner
Copy link
Collaborator

Intel's implementation does this too: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0543r2.html

Add it to std::simd (as that link itself suggests)?

@mattkretz
Copy link
Owner

Yes 👍. We need overloads for simd<T> with the same constraint on T as in P0543. Note that P0543 just cleared LEWG and sits in LWG targetting C++26.

@danieltowner
Copy link
Collaborator Author

I will write this up as a proposal.

@mattkretz mattkretz assigned mattkretz and danieltowner and unassigned mattkretz Jun 30, 2023
@danieltowner
Copy link
Collaborator Author

https://isocpp.org/files/papers/P2956R0.html

@mattkretz
Copy link
Owner

  • The wording will need some work (not necessarily for LEWG review, I think). Maybe there's a better way to pull in all constraints and preconditions from foo_sat(T, T). Some "equivalent to" or so magic incantation... :-)
  • The template parameter for saturate_cast needs a discussion. The direct equivalent would seem to be saturate_cast<simd<T>>(v) rather than saturate_cast<T>(v). I.e. we're casting to simd<T> not to T. I understand the desire for a shortcut and generic code. I'm undecided. The paper should explore both and guide a LEWG discussion & decision.

@danieltowner
Copy link
Collaborator Author

  • The template parameter for saturate_cast needs a discussion. The direct equivalent would seem to be saturate_cast<simd<T>>(v) rather than saturate_cast<T>(v). I.e. we're casting to simd<T> not to T. I understand the desire for a shortcut and generic code. I'm undecided.

I think this is desirable in other places too, such as simd_bit_cast<T> and simd_cast<T>. All three cases read better and are more concise if you can just provide the new type of element, without having to figure out the simd sizes too and create a complete simd type. This is especially true for the bit cast where a new simd size might be needed.

For consistency, whatever we decide, then we should do the same in all three cases.

Users objected when I removed simd_cast from the Intel implementation, and they continue to grumble about it even now.

@mattkretz
Copy link
Owner

I fully understand the desire for casting to T instead of simd<T>. I mean, I needed it in several places myself and it's just so much simpler for generic code.

However:

  1. This can't work with static_cast.
  2. simd_cast can be special because it has simd in its name.
  3. saturate_cast probably shouldn't be special because it does not have simd in its name.
  4. I floated the idea of a representation_cast or value_type_cast (or whatever name) that generically works for all kinds of types to change their value_type. I think that would be nice to have.

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

No branches or pull requests

2 participants