File: generic-arithmetic-2.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 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; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (132 lines) | stat: -rw-r--r-- 4,069 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//@ build-fail

#![feature(repr_simd, intrinsics)]
#![allow(non_camel_case_types)]
#[repr(simd)]
#[derive(Copy, Clone)]
pub struct i32x4(pub [i32; 4]);

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct u32x4(pub [u32; 4]);

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct f32x4(pub [f32; 4]);

extern "rust-intrinsic" {
    fn simd_add<T>(x: T, y: T) -> T;
    fn simd_sub<T>(x: T, y: T) -> T;
    fn simd_mul<T>(x: T, y: T) -> T;
    fn simd_div<T>(x: T, y: T) -> T;
    fn simd_rem<T>(x: T, y: T) -> T;
    fn simd_shl<T>(x: T, y: T) -> T;
    fn simd_shr<T>(x: T, y: T) -> T;
    fn simd_and<T>(x: T, y: T) -> T;
    fn simd_or<T>(x: T, y: T) -> T;
    fn simd_xor<T>(x: T, y: T) -> T;

    fn simd_neg<T>(x: T) -> T;
    fn simd_bswap<T>(x: T) -> T;
    fn simd_bitreverse<T>(x: T) -> T;
    fn simd_ctlz<T>(x: T) -> T;
    fn simd_ctpop<T>(x: T) -> T;
    fn simd_cttz<T>(x: T) -> T;
}

fn main() {
    let x = i32x4([0, 0, 0, 0]);
    let y = u32x4([0, 0, 0, 0]);
    let z = f32x4([0.0, 0.0, 0.0, 0.0]);

    unsafe {
        simd_add(x, x);
        simd_add(y, y);
        simd_add(z, z);
        simd_sub(x, x);
        simd_sub(y, y);
        simd_sub(z, z);
        simd_mul(x, x);
        simd_mul(y, y);
        simd_mul(z, z);
        simd_div(x, x);
        simd_div(y, y);
        simd_div(z, z);
        simd_rem(x, x);
        simd_rem(y, y);
        simd_rem(z, z);

        simd_shl(x, x);
        simd_shl(y, y);
        simd_shr(x, x);
        simd_shr(y, y);
        simd_and(x, x);
        simd_and(y, y);
        simd_or(x, x);
        simd_or(y, y);
        simd_xor(x, x);
        simd_xor(y, y);

        simd_neg(x);
        simd_neg(z);
        simd_bswap(x);
        simd_bswap(y);
        simd_bitreverse(x);
        simd_bitreverse(y);
        simd_ctlz(x);
        simd_ctlz(y);
        simd_cttz(x);
        simd_cttz(y);

        simd_add(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_sub(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_mul(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_div(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_shl(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_shr(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_and(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_or(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_xor(0, 0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`

        simd_neg(0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_bswap(0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_bitreverse(0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_ctlz(0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
        simd_cttz(0);
        //~^ ERROR expected SIMD input type, found non-SIMD `i32`

        simd_shl(z, z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_shr(z, z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_and(z, z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_or(z, z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_xor(z, z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_bswap(z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_bitreverse(z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_ctlz(z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_ctpop(z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
        simd_cttz(z);
        //~^ ERROR unsupported operation on `f32x4` with element `f32`
    }
}