File: const-vector.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 (91 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download | duplicates (3)
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
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0

// This test checks that constants of SIMD type are passed as immediate vectors.
// We ensure that both vector representations (struct with fields and struct wrapping array) work.
#![crate_type = "lib"]
#![feature(abi_unadjusted)]
#![feature(const_trait_impl)]
#![feature(repr_simd)]
#![feature(rustc_attrs)]
#![feature(simd_ffi)]
#![allow(non_camel_case_types)]

// Setting up structs that can be used as const vectors
#[repr(simd)]
#[derive(Clone)]
pub struct i8x2([i8; 2]);

#[repr(simd)]
#[derive(Clone)]
pub struct f32x2([f32; 2]);

#[repr(simd, packed)]
#[derive(Copy, Clone)]
pub struct Simd<T, const N: usize>([T; N]);

// The following functions are required for the tests to ensure
// that they are called with a const vector

extern "unadjusted" {
    fn test_i8x2(a: i8x2);
}

extern "unadjusted" {
    fn test_i8x2_two_args(a: i8x2, b: i8x2);
}

extern "unadjusted" {
    fn test_i8x2_mixed_args(a: i8x2, c: i32, b: i8x2);
}

extern "unadjusted" {
    fn test_i8x2_arr(a: i8x2);
}

extern "unadjusted" {
    fn test_f32x2(a: f32x2);
}

extern "unadjusted" {
    fn test_f32x2_arr(a: f32x2);
}

extern "unadjusted" {
    fn test_simd(a: Simd<i32, 4>);
}

extern "unadjusted" {
    fn test_simd_unaligned(a: Simd<i32, 3>);
}

// Ensure the packed variant of the simd struct does not become a const vector
// if the size is not a power of 2
// CHECK: %"Simd<i32, 3>" = type { [3 x i32] }

pub fn do_call() {
    unsafe {
        // CHECK: call void @test_i8x2(<2 x i8> <i8 32, i8 64>
        test_i8x2(const { i8x2([32, 64]) });

        // CHECK: call void @test_i8x2_two_args(<2 x i8> <i8 32, i8 64>, <2 x i8> <i8 8, i8 16>
        test_i8x2_two_args(const { i8x2([32, 64]) }, const { i8x2([8, 16]) });

        // CHECK: call void @test_i8x2_mixed_args(<2 x i8> <i8 32, i8 64>, i32 43, <2 x i8> <i8 8, i8 16>
        test_i8x2_mixed_args(const { i8x2([32, 64]) }, 43, const { i8x2([8, 16]) });

        // CHECK: call void @test_i8x2_arr(<2 x i8> <i8 32, i8 64>
        test_i8x2_arr(const { i8x2([32, 64]) });

        // CHECK: call void @test_f32x2(<2 x float> <float 0x3FD47AE140000000, float 0x3FE47AE140000000>
        test_f32x2(const { f32x2([0.32, 0.64]) });

        // CHECK: void @test_f32x2_arr(<2 x float> <float 0x3FD47AE140000000, float 0x3FE47AE140000000>
        test_f32x2_arr(const { f32x2([0.32, 0.64]) });

        // CHECK: call void @test_simd(<4 x i32> <i32 2, i32 4, i32 6, i32 8>
        test_simd(const { Simd::<i32, 4>([2, 4, 6, 8]) });

        // CHECK: call void @test_simd_unaligned(%"Simd<i32, 3>" %1
        test_simd_unaligned(const { Simd::<i32, 3>([2, 4, 6]) });
    }
}