Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8ab0f2d

Browse files
committed
Add tests for asm!
1 parent abed45f commit 8ab0f2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3489
-40
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// assembly-output: emit-asm
2+
// compile-flags: -O
3+
// compile-flags: --target aarch64-unknown-linux-gnu
4+
5+
#![feature(no_core, lang_items, rustc_attrs)]
6+
#![crate_type = "rlib"]
7+
#![no_core]
8+
#![allow(asm_sub_register)]
9+
10+
#[rustc_builtin_macro]
11+
macro_rules! asm {
12+
() => {};
13+
}
14+
#[rustc_builtin_macro]
15+
macro_rules! stringify {
16+
() => {};
17+
}
18+
19+
#[lang = "sized"]
20+
trait Sized {}
21+
#[lang = "copy"]
22+
trait Copy {}
23+
24+
impl Copy for i32 {}
25+
26+
macro_rules! check {
27+
($func:ident $reg:ident $code:literal) => {
28+
// -O and extern "C" guarantee that the selected register is always r0/s0/d0/q0
29+
#[no_mangle]
30+
pub unsafe extern "C" fn $func() -> i32 {
31+
// Hack to avoid function merging
32+
extern "Rust" {
33+
fn dont_merge(s: &str);
34+
}
35+
dont_merge(stringify!($func));
36+
37+
let y;
38+
asm!($code, out($reg) y);
39+
y
40+
}
41+
};
42+
}
43+
44+
// CHECK-LABEL: reg:
45+
// CHECK: //APP
46+
// CHECK: mov x0, x0
47+
// CHECK: //NO_APP
48+
check!(reg reg "mov {0}, {0}");
49+
50+
// CHECK-LABEL: reg_w:
51+
// CHECK: //APP
52+
// CHECK: mov w0, w0
53+
// CHECK: //NO_APP
54+
check!(reg_w reg "mov {0:w}, {0:w}");
55+
56+
// CHECK-LABEL: reg_x:
57+
// CHECK: //APP
58+
// CHECK: mov x0, x0
59+
// CHECK: //NO_APP
60+
check!(reg_x reg "mov {0:x}, {0:x}");
61+
62+
// CHECK-LABEL: vreg:
63+
// CHECK: //APP
64+
// CHECK: add v0.4s, v0.4s, v0.4s
65+
// CHECK: //NO_APP
66+
check!(vreg vreg "add {0}.4s, {0}.4s, {0}.4s");
67+
68+
// CHECK-LABEL: vreg_b:
69+
// CHECK: //APP
70+
// CHECK: ldr b0, [x0]
71+
// CHECK: //NO_APP
72+
check!(vreg_b vreg "ldr {:b}, [x0]");
73+
74+
// CHECK-LABEL: vreg_h:
75+
// CHECK: //APP
76+
// CHECK: ldr h0, [x0]
77+
// CHECK: //NO_APP
78+
check!(vreg_h vreg "ldr {:h}, [x0]");
79+
80+
// CHECK-LABEL: vreg_s:
81+
// CHECK: //APP
82+
// CHECK: ldr s0, [x0]
83+
// CHECK: //NO_APP
84+
check!(vreg_s vreg "ldr {:s}, [x0]");
85+
86+
// CHECK-LABEL: vreg_d:
87+
// CHECK: //APP
88+
// CHECK: ldr d0, [x0]
89+
// CHECK: //NO_APP
90+
check!(vreg_d vreg "ldr {:d}, [x0]");
91+
92+
// CHECK-LABEL: vreg_q:
93+
// CHECK: //APP
94+
// CHECK: ldr q0, [x0]
95+
// CHECK: //NO_APP
96+
check!(vreg_q vreg "ldr {:q}, [x0]");
97+
98+
// CHECK-LABEL: vreg_v:
99+
// CHECK: //APP
100+
// CHECK: add v0.4s, v0.4s, v0.4s
101+
// CHECK: //NO_APP
102+
check!(vreg_v vreg "add {0:v}.4s, {0:v}.4s, {0:v}.4s");
103+
104+
// CHECK-LABEL: vreg_low16:
105+
// CHECK: //APP
106+
// CHECK: add v0.4s, v0.4s, v0.4s
107+
// CHECK: //NO_APP
108+
check!(vreg_low16 vreg_low16 "add {0}.4s, {0}.4s, {0}.4s");
109+
110+
// CHECK-LABEL: vreg_low16_b:
111+
// CHECK: //APP
112+
// CHECK: ldr b0, [x0]
113+
// CHECK: //NO_APP
114+
check!(vreg_low16_b vreg_low16 "ldr {:b}, [x0]");
115+
116+
// CHECK-LABEL: vreg_low16_h:
117+
// CHECK: //APP
118+
// CHECK: ldr h0, [x0]
119+
// CHECK: //NO_APP
120+
check!(vreg_low16_h vreg_low16 "ldr {:h}, [x0]");
121+
122+
// CHECK-LABEL: vreg_low16_s:
123+
// CHECK: //APP
124+
// CHECK: ldr s0, [x0]
125+
// CHECK: //NO_APP
126+
check!(vreg_low16_s vreg_low16 "ldr {:s}, [x0]");
127+
128+
// CHECK-LABEL: vreg_low16_d:
129+
// CHECK: //APP
130+
// CHECK: ldr d0, [x0]
131+
// CHECK: //NO_APP
132+
check!(vreg_low16_d vreg_low16 "ldr {:d}, [x0]");
133+
134+
// CHECK-LABEL: vreg_low16_q:
135+
// CHECK: //APP
136+
// CHECK: ldr q0, [x0]
137+
// CHECK: //NO_APP
138+
check!(vreg_low16_q vreg_low16 "ldr {:q}, [x0]");
139+
140+
// CHECK-LABEL: vreg_low16_v:
141+
// CHECK: //APP
142+
// CHECK: add v0.4s, v0.4s, v0.4s
143+
// CHECK: //NO_APP
144+
check!(vreg_low16_v vreg_low16 "add {0:v}.4s, {0:v}.4s, {0:v}.4s");

0 commit comments

Comments
 (0)