-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-SIMDArea: SIMD (Single Instruction Multiple Data)Area: SIMD (Single Instruction Multiple Data)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
Description
The platform independent simd types have constructors which are const fns, so they can be used in things like lookup tables: https://github.com/raw/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?
Metadata
Metadata
Assignees
Labels
A-SIMDArea: SIMD (Single Instruction Multiple Data)Area: SIMD (Single Instruction Multiple Data)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team