]> git.proxmox.com Git - rustc.git/blob - src/test/ui/asm/aarch64/type-check-3.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / src / test / ui / asm / aarch64 / type-check-3.rs
1 // only-aarch64
2 // compile-flags: -C target-feature=+neon
3
4 #![feature(asm, global_asm, repr_simd, stdsimd, asm_const)]
5
6 use std::arch::aarch64::float64x2_t;
7
8 #[repr(simd)]
9 #[derive(Copy, Clone)]
10 struct Simd256bit(f64, f64, f64, f64);
11
12 fn main() {
13 let f64x2: float64x2_t = unsafe { std::mem::transmute(0i128) };
14 let f64x4 = Simd256bit(0.0, 0.0, 0.0, 0.0);
15
16 unsafe {
17 // Types must be listed in the register class.
18
19 // Success cases
20 asm!("{:w}", in(reg) 0u8);
21 asm!("{:w}", in(reg) 0u16);
22 asm!("{:w}", in(reg) 0u32);
23 asm!("{:w}", in(reg) 0f32);
24 asm!("{}", in(reg) 0i64);
25 asm!("{}", in(reg) 0f64);
26
27 asm!("{:b}", in(vreg) 0u8);
28 asm!("{:h}", in(vreg) 0u16);
29 asm!("{:s}", in(vreg) 0u32);
30 asm!("{:s}", in(vreg) 0f32);
31 asm!("{:d}", in(vreg) 0u64);
32 asm!("{:d}", in(vreg) 0f64);
33 asm!("{:q}", in(vreg) f64x2);
34 asm!("{:v}", in(vreg) f64x2);
35
36 // Should be the same as vreg
37 asm!("{:q}", in(vreg_low16) f64x2);
38
39 // Template modifiers of a different size to the argument are fine
40 asm!("{:w}", in(reg) 0u64);
41 asm!("{:x}", in(reg) 0u32);
42 asm!("{:b}", in(vreg) 0u64);
43 asm!("{:d}", in(vreg_low16) f64x2);
44
45 // Template modifier suggestions for sub-registers
46
47 asm!("{}", in(reg) 0u8);
48 //~^ WARN formatting may not be suitable for sub-register argument
49 asm!("{}", in(reg) 0u16);
50 //~^ WARN formatting may not be suitable for sub-register argument
51 asm!("{}", in(reg) 0i32);
52 //~^ WARN formatting may not be suitable for sub-register argument
53 asm!("{}", in(reg) 0f32);
54 //~^ WARN formatting may not be suitable for sub-register argument
55
56 asm!("{}", in(vreg) 0i16);
57 //~^ WARN formatting may not be suitable for sub-register argument
58 asm!("{}", in(vreg) 0f32);
59 //~^ WARN formatting may not be suitable for sub-register argument
60 asm!("{}", in(vreg) 0f64);
61 //~^ WARN formatting may not be suitable for sub-register argument
62 asm!("{}", in(vreg_low16) 0f64);
63 //~^ WARN formatting may not be suitable for sub-register argument
64
65 asm!("{0} {0}", in(reg) 0i16);
66 //~^ WARN formatting may not be suitable for sub-register argument
67 asm!("{0} {0:x}", in(reg) 0i16);
68 //~^ WARN formatting may not be suitable for sub-register argument
69
70 // Invalid registers
71
72 asm!("{}", in(reg) 0i128);
73 //~^ ERROR type `i128` cannot be used with this register class
74 asm!("{}", in(reg) f64x2);
75 //~^ ERROR type `float64x2_t` cannot be used with this register class
76 asm!("{}", in(vreg) f64x4);
77 //~^ ERROR type `Simd256bit` cannot be used with this register class
78
79 // Split inout operands must have compatible types
80
81 let mut val_i16: i16;
82 let mut val_f32: f32;
83 let mut val_u32: u32;
84 let mut val_u64: u64;
85 let mut val_ptr: *mut u8;
86 asm!("{:x}", inout(reg) 0u16 => val_i16);
87 asm!("{:x}", inout(reg) 0u32 => val_f32);
88 //~^ ERROR incompatible types for asm inout argument
89 asm!("{:x}", inout(reg) 0u32 => val_ptr);
90 //~^ ERROR incompatible types for asm inout argument
91 asm!("{:x}", inout(reg) main => val_u32);
92 //~^ ERROR incompatible types for asm inout argument
93 asm!("{:x}", inout(reg) 0u64 => val_ptr);
94 asm!("{:x}", inout(reg) main => val_u64);
95 }
96 }
97
98 // Constants must be... constant
99
100 static S: i32 = 1;
101 const fn const_foo(x: i32) -> i32 {
102 x
103 }
104 const fn const_bar<T>(x: T) -> T {
105 x
106 }
107 global_asm!("{}", const S);
108 //~^ ERROR constants cannot refer to statics
109 global_asm!("{}", const const_foo(0));
110 global_asm!("{}", const const_foo(S));
111 //~^ ERROR constants cannot refer to statics
112 global_asm!("{}", const const_bar(0));
113 global_asm!("{}", const const_bar(S));
114 //~^ ERROR constants cannot refer to statics