Closed
Description
The following should be discussed as part of an RFC for supporting portable vector types (repr(simd)
) but the current behavior is unsound (playground):
#![feature(repr_simd)]
#![feature(target_feature)]
#![allow(non_camel_case_types)]
// Given a SIMD vector type:
#[derive(Debug)]
#[repr(simd)]
struct f32x8(f32, f32, f32, f32,
f32, f32, f32, f32);
// and the following two functions:
#[target_feature = "+avx"]
fn foo() -> f32x8 { f32x8(0.,1.,2.,3.,4.,5.,6.,7.) } // f32x8 will be a 256bit vector
#[target_feature = "+sse3"]
fn bar(arg: f32x8) { // f32x8 will be 2x128bit vectors
println!("{:?} != f32x8(0, 1, 2, 3, 4, 5, 6, 7)", arg);
// prints: f32x8(0, 1, 2, 3, 6, 0, 0, 0) != f32x8(0, 1, 2, 3, 4, 5, 6, 7)
}
// what are the semantics of the following when
// executing on a machine that supports AVX?
fn main() { bar(foo()); }
Basically, those two objects of type f32x8
have a different layout, so foo
and bar
have a different ABI / calling convention. This can be introduced without target_feature
, by compiling two crates with different --target-cpu
s and linking them, but target_feature
was used here for simplicity.
Metadata
Metadata
Assignees
Labels
Area: SIMD (Single Instruction Multiple Data)Blocker: Implemented in the nightly compiler and unstable.Category: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessMedium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.