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

Structures with arbitrary size #4

Open
flip111 opened this issue Mar 2, 2017 · 3 comments
Open

Structures with arbitrary size #4

flip111 opened this issue Mar 2, 2017 · 3 comments

Comments

@flip111
Copy link

flip111 commented Mar 2, 2017

Would it be possible to define a structure where the right SIMD instruction is chosen automatically (question 1)? Where the possible SIMD instructions are detected on compile time (question 2)?

Let's say i have an older CPU so no AVX2, hopefully the compiler can hint this just like gcc. Then i can have a maximum of 128 bits vectors.

For example i have a 1300 bit vector which i want to AND with another 1300 vector. Which would take 10x 128 bit vectors and 1x 20 bit vector (round up to 32 bits). If the size of the vector is known at compile time could rust generate the right instructors for it, with only me specifying the 1300 bit size?
If 1300 is the wrong example, think of 1312 or 1344.

Runtime would also be interesting (question 3), but i think actually less interesting than compile time because you would have to branch to normal instructions (for 32 bits and so) and avx instructions based on size which will make you loose performance.

@BurntSushi
Copy link
Contributor

Internally, this library uses cfg(target_feature = "...") to define certain things depending on compile options. You can see a simple example here: https://github.com/rust-lang-nursery/simd/blob/master/src/x86/mod.rs --- You can use cfg(target_feature = "...") in your code too.

Runtime would also be interesting (question 3), but i think actually less interesting than compile time because you would have to branch to normal instructions (for 32 bits and so) and avx instructions based on size which will make you loose performance.

I imagine you would amortize the branch (possibly by detecting it once at startup and setting a global function pointer). Regardless, this library doesn't support that anyway. But hopefully some day. :-)

@flip111
Copy link
Author

flip111 commented Mar 3, 2017

Looks good :) What about adding support for arbitrary size vectors though? So that chosing SIMD instructions or not is abstracted away?

@BurntSushi
Copy link
Contributor

@flip111 I'm not sure that's in scope for this crate. I'd recommend building something yourself in a separate crate and see where it takes us.

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

No branches or pull requests

2 participants