File: simd-abi-checks.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (110 lines) | stat: -rw-r--r-- 3,921 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//@ only-x86_64
//@ build-pass
//@ ignore-pass (test emits codegen-time warnings)

#![feature(avx512_target_feature)]
#![feature(portable_simd)]
#![feature(target_feature_11, simd_ffi)]
#![allow(improper_ctypes_definitions)]

use std::arch::x86_64::*;

#[repr(transparent)]
struct Wrapper(__m256);

unsafe extern "C" fn w(_: Wrapper) {
    //~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
    //~| WARNING this was previously accepted by the compiler
    todo!()
}

unsafe extern "C" fn f(_: __m256) {
    //~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
    //~| WARNING this was previously accepted by the compiler
    todo!()
}

unsafe extern "C" fn g() -> __m256 {
    //~^ this function definition uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled
    //~| WARNING this was previously accepted by the compiler
    todo!()
}

#[target_feature(enable = "avx")]
unsafe extern "C" fn favx() -> __m256 {
    todo!()
}

// avx2 implies avx, so no error here.
#[target_feature(enable = "avx2")]
unsafe extern "C" fn gavx(_: __m256) {
    todo!()
}

// No error because of "Rust" ABI.
fn as_f64x8(d: __m512d) -> std::simd::f64x8 {
    unsafe { std::mem::transmute(d) }
}

unsafe fn test() {
    let arg = std::mem::transmute([0.0f64; 8]);
    as_f64x8(arg);
}

#[target_feature(enable = "avx")]
unsafe fn in_closure() -> impl FnOnce() -> __m256 {
    #[inline(always)] // this disables target-feature inheritance
    || g()
    //~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
    //~| WARNING this was previously accepted by the compiler
}

fn main() {
    unsafe {
        f(g());
        //~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this was previously accepted by the compiler
        //~| WARNING this was previously accepted by the compiler
    }

    unsafe {
        gavx(favx());
        //~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this was previously accepted by the compiler
        //~| WARNING this was previously accepted by the compiler
    }

    unsafe {
        test();
    }

    unsafe {
        w(Wrapper(g()));
        //~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this was previously accepted by the compiler
        //~| WARNING this was previously accepted by the compiler
    }

    unsafe {
        in_closure()();
    }

    unsafe {
        #[expect(improper_ctypes)]
        extern "C" {
            fn some_extern() -> __m256;
        }
        some_extern();
        //~^ WARNING this function call uses a SIMD vector type that (with the chosen ABI) requires the `avx` target feature, which is not enabled in the caller
        //~| WARNING this was previously accepted by the compiler
    }
}

#[no_mangle]
#[target_feature(enable = "avx")]
fn some_extern() -> __m256 {
    todo!()
}