1 // assembly-output: emit-asm
2 // compile-flags: --target hexagon-unknown-linux-musl
3 // needs-llvm-components: hexagon
5 #![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
6 #![crate_type = "rlib"]
8 #![allow(asm_sub_register, non_camel_case_types)]
10 #[rustc_builtin_macro]
14 #[rustc_builtin_macro]
18 #[rustc_builtin_macro]
19 macro_rules! stringify {
28 type ptr = *const i32;
37 static extern_static: u8;
41 ($func:ident $ty:ident $class:ident) => {
43 pub unsafe fn $func(x: $ty) -> $ty {
44 // Hack to avoid function merging
46 fn dont_merge(s: &str);
48 dont_merge(stringify!($func));
51 asm!("{} = {}", out($class) y, in($class) x);
57 macro_rules! check_reg {
58 ($func:ident $ty:ident $reg:tt) => {
60 pub unsafe fn $func(x: $ty) -> $ty {
61 // Hack to avoid function merging
63 fn dont_merge(s: &str);
65 dont_merge(stringify!($func));
68 asm!(concat!($reg, " = ", $reg), lateout($reg) y, in($reg) x);
74 // CHECK-LABEL: sym_static:
75 // CHECK: InlineAsm Start
76 // CHECK: r0 = {{#+}}extern_static
77 // CHECK: InlineAsm End
79 pub unsafe fn sym_static() {
80 // Hack to avoid function merging
82 fn dont_merge(s: &str);
84 dont_merge(stringify!($func));
86 asm!("r0 = #{}", sym extern_static);
89 // CHECK-LABEL: sym_fn:
90 // CHECK: InlineAsm Start
91 // CHECK: r0 = {{#+}}extern_func
92 // CHECK: InlineAsm End
94 pub unsafe fn sym_fn() {
95 // Hack to avoid function merging
97 fn dont_merge(s: &str);
99 dont_merge(stringify!($func));
101 asm!("r0 = #{}", sym extern_func);
104 // This is a test for multi-instruction packets,
105 // which require the escaped braces.
107 // CHECK-LABEL: packet:
108 // CHECK: InlineAsm Start
110 // CHECK: r{{[0-9]+}} = r0
111 // CHECK: memw(r1{{(\+#0)?}}) = r{{[0-9]+}}
113 // CHECK: InlineAsm End
115 pub unsafe fn packet() {
120 }}", out(reg) _, in(reg) &val);
123 // CHECK-LABEL: reg_ptr:
124 // CHECK: InlineAsm Start
125 // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
126 // CHECK: InlineAsm End
127 check!(reg_ptr ptr reg);
129 // CHECK-LABEL: reg_f32:
130 // CHECK: InlineAsm Start
131 // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
132 // CHECK: InlineAsm End
133 check!(reg_f32 f32 reg);
135 // CHECK-LABEL: reg_i32:
136 // CHECK: InlineAsm Start
137 // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
138 // CHECK: InlineAsm End
139 check!(reg_i32 i32 reg);
141 // CHECK-LABEL: reg_i8:
142 // CHECK: InlineAsm Start
143 // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
144 // CHECK: InlineAsm End
145 check!(reg_i8 i8 reg);
147 // CHECK-LABEL: reg_i16:
148 // CHECK: InlineAsm Start
149 // CHECK: r{{[0-9]+}} = r{{[0-9]+}}
150 // CHECK: InlineAsm End
151 check!(reg_i16 i16 reg);
153 // CHECK-LABEL: r0_ptr:
154 // CHECK: InlineAsm Start
156 // CHECK: InlineAsm End
157 check_reg!(r0_ptr ptr "r0");
159 // CHECK-LABEL: r0_f32:
160 // CHECK: InlineAsm Start
162 // CHECK: InlineAsm End
163 check_reg!(r0_f32 f32 "r0");
165 // CHECK-LABEL: r0_i32:
166 // CHECK: InlineAsm Start
168 // CHECK: InlineAsm End
169 check_reg!(r0_i32 i32 "r0");
171 // CHECK-LABEL: r0_i8:
172 // CHECK: InlineAsm Start
174 // CHECK: InlineAsm End
175 check_reg!(r0_i8 i8 "r0");
177 // CHECK-LABEL: r0_i16:
178 // CHECK: InlineAsm Start
180 // CHECK: InlineAsm End
181 check_reg!(r0_i16 i16 "r0");