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

"Casting" boolean vectors back to integer vectors #22

Open
birkenfeld opened this issue Feb 26, 2016 · 1 comment
Open

"Casting" boolean vectors back to integer vectors #22

birkenfeld opened this issue Feb 26, 2016 · 1 comment

Comments

@birkenfeld
Copy link

When translating routines from C intrinsics to Rust, conceptually boolean vectors are freely mixed with non-boolean ones.

To get back from boolean to its representation you currently have to do b.select(splat(-1), splat(0)) or similar while on the instruction level it's a no-op. It already optimizes back to a no-op, but would it make sense to have a shorthand for coding it?

@wickerwaka
Copy link

I ran into something similar porting some code from C. Another common pattern is doing bitwise operations on floating point values, such as XOR-ing each lane with 0x80000000 in order to flip the sign bit.

It's not clear from the documentation what to_u32, to_i32 and to_f32 do, they just say they lanes are "converted". Looking at the code it uses the simd_cast intrinsic, which is also ambiguous. It was only through experiment and/or looking at the disassembly that you can see what is actually happening.

It seems like the work currently done by these to_ methods would be more idiomatic if they were implemented using the From and Into traits. Then a direct cast without conversion could be implemented as as_f32, as_i32, etc methods at perform an unsafe mem::transmute.

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