-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
The platform independent simd types have constructors which are const fns, so they can be used in things like lookup tables: https://raw.githubusercontent.com/sfackler/stream-vbyte64/ea0d5b0afdf97f31473fafbf33d460fbbb313785/src/tables.rs.
However, the same is not the case for the vendor-specific types like __m256i
. There are platform intrinsics which initialize those types (e.g. _mm256_setr_epi32
is equivalent to i32x8::new
) but those are not const fns.
One way to work around this is by type-punning through unions:
#![feature(stdsimd)]
use std::arch::x86_64::*;
#[repr(C)]
union Pun {
a: __m256i,
b: [u32; 8],
}
static FOO: Pun = Pun { b: [1, 2, 3, 4, 5, 6, 7, 8] };
fn main() {
let x = unsafe { _mm256_extract_epi32(FOO.a, 3) };
println!("{}", x);
}
This kind of union is pretty common in SIMD-related C code I've seen, and I think well defined behavior from what the unions RFC describes. Is this the "right" way to do this? Can/should we make functions like _mm256_set_epi32
const?