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

Switch from vecn function to vecn! macro #109

Closed
bitshifter opened this issue Dec 10, 2020 · 4 comments
Closed

Switch from vecn function to vecn! macro #109

bitshifter opened this issue Dec 10, 2020 · 4 comments
Labels
discussion Feedback from users about this proposal is desired enhancement New feature or request

Comments

@bitshifter
Copy link
Owner

bitshifter commented Dec 10, 2020

It might be more useful if functions like vec2, vec3, mat2 etc became macros as then they could support different parameter types, e.g.

  • vec4!(1.0, 2.0, 3.0, 4.0) - regular construction
  • vec4![1.0, 2.0, 3.0, 4.0] or vec4![2.0; 4] - array construction
  • vec4!(3.0) - splat from a scalar

It might mean these are a bit more useful than the currently are.

@bitshifter bitshifter added discussion Feedback from users about this proposal is desired enhancement New feature or request labels Dec 10, 2020
@Boscop
Copy link

Boscop commented Dec 13, 2020

Yeah, that would be useful.
Also vec3!(vec2!(1.0, 2.0), 3.0), vec3!(3.0, vec2!(1.0, 2.0)), vec4!(vec2!(1.0, 2.0), vec2!(3.0, 4.0)) etc.


vec4![2.0; 4]

I don't think this one makes sense, the size is already expressed in the macro name, one would just call vec4!(2.0). But it would be useful to have an easy way to convert a [f32; 4] to Vec4.

@LPGhatguy
Copy link
Contributor

Can the existing const macros be merged into the idea of these new macros? Is there a reason to keep const and non-const initialization separate?

As an intermediate step, would you be interested in merging the const macros with these functions to create new macros that are also const? It would be very nice to have a single shorthand for creating values.

The new macros could later be extended with scalar splat or array construction.

@bitshifter
Copy link
Owner Author

bitshifter commented Oct 4, 2021

The const_vecn! macros are a workaround for limitations in Rust itself, see #76 for more details.

It might be possible to merge const_vecn! into vecn!. I'm not totally sure about doing that though, the const_vecn! does some hacky things (union casts) to be able to create a const value which possibly could produce worse code than the current vecn! macros which are simple inlined function calls. Technically it should be possible though. The only other reason to not do that is hopefully it's clear that the const_vecn! macros can be used to create const values. Without that naming it might not be obvious that vecn! can be used to create const values while the regular function VecN::new can not.

Long term if SIMD constructors in core::arch are made const fn the const_vecn macros will no longer be necessary.

@bitshifter
Copy link
Owner Author

Decided not to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Feedback from users about this proposal is desired enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants