Reputation: 41
I have seen that it's rather simple in C to access values in a __m128
register by index. However, it is not possible to do that in rust. How can I access those values?
Concretely, I am calculating four values at once, then I compare them using _mm_cmplt_ps
. I use that return register as a mask for further computation.
Upvotes: 1
Views: 455
Reputation: 117681
There are SIMD instructions precisely for this, e.g. such as _mm_extract_epi32
, but they often require newer versions of SIMD than just SSE2.
I think the easiest way to do this using foolproof safe Rust is using the bytemuck
crate, in your example:
let cmp = _mm_cmplt_ps(a, b);
let cmp_arr: [u32; 4] = bytemuck::cast(cmp);
Now cmp_arr[0]
, cmp_arr[1]
, ..., contain your results.
Upvotes: 2