]> git.lizzy.rs Git - rust.git/blob - tests/assembly/asm/mips-types.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / assembly / asm / mips-types.rs
1 // revisions: mips32 mips64
2 // assembly-output: emit-asm
3 //[mips32] compile-flags: --target mips-unknown-linux-gnu
4 //[mips32] needs-llvm-components: mips
5 //[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
6 //[mips64] needs-llvm-components: mips
7
8 #![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
9 #![crate_type = "rlib"]
10 #![no_core]
11 #![allow(asm_sub_register, non_camel_case_types)]
12
13 #[rustc_builtin_macro]
14 macro_rules! asm {
15     () => {};
16 }
17 #[rustc_builtin_macro]
18 macro_rules! concat {
19     () => {};
20 }
21 #[rustc_builtin_macro]
22 macro_rules! stringify {
23     () => {};
24 }
25
26 #[lang = "sized"]
27 trait Sized {}
28 #[lang = "copy"]
29 trait Copy {}
30
31 type ptr = *const i32;
32
33 impl Copy for i8 {}
34 impl Copy for u8 {}
35 impl Copy for i16 {}
36 impl Copy for i32 {}
37 impl Copy for i64 {}
38 impl Copy for f32 {}
39 impl Copy for f64 {}
40 impl Copy for ptr {}
41 extern "C" {
42     fn extern_func();
43     static extern_static: u8;
44 }
45
46 // Hack to avoid function merging
47 extern "Rust" {
48     fn dont_merge(s: &str);
49 }
50
51 macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => {
52     #[no_mangle]
53     pub unsafe fn $func(x: $ty) -> $ty {
54         dont_merge(stringify!($func));
55
56         let y;
57         asm!(concat!($mov," {}, {}"), out($class) y, in($class) x);
58         y
59     }
60 };}
61
62 macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {
63     #[no_mangle]
64     pub unsafe fn $func(x: $ty) -> $ty {
65         dont_merge(stringify!($func));
66
67         let y;
68         asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x);
69         y
70     }
71 };}
72
73 // mips32-LABEL: sym_static_32:
74 // mips32: #APP
75 // mips32: lw $3, %got(extern_static)
76 // mips32: #NO_APP
77 #[cfg(mips32)]
78 #[no_mangle]
79 pub unsafe fn sym_static_32() {
80     asm!("lw $v1, {}", sym extern_static);
81 }
82
83 // mips32-LABEL: sym_fn_32:
84 // mips32: #APP
85 // mips32: lw $3, %got(extern_func)
86 // mips32: #NO_APP
87 #[cfg(mips32)]
88 #[no_mangle]
89 pub unsafe fn sym_fn_32() {
90     asm!("lw $v1, {}", sym extern_func);
91 }
92
93 // mips64-LABEL: sym_static_64:
94 // mips64: #APP
95 // mips64: ld $3, %got_disp(extern_static)
96 // mips64: #NO_APP
97 #[cfg(mips64)]
98 #[no_mangle]
99 pub unsafe fn sym_static_64() {
100     asm!("ld $v1, {}", sym extern_static);
101 }
102
103 // mips64-LABEL: sym_fn_64:
104 // mips64: #APP
105 // mips64: ld $3, %got_disp(extern_func)
106 // mips64: #NO_APP
107 #[cfg(mips64)]
108 #[no_mangle]
109 pub unsafe fn sym_fn_64() {
110     asm!("ld $v1, {}", sym extern_func);
111 }
112
113 // CHECK-LABEL: reg_f32:
114 // CHECK: #APP
115 // CHECK: mov.s $f{{[0-9]+}}, $f{{[0-9]+}}
116 // CHECK: #NO_APP
117 check!(reg_f32, f32, freg, "mov.s");
118
119 // CHECK-LABEL: f0_f32:
120 // CHECK: #APP
121 // CHECK: mov.s $f0, $f0
122 // CHECK: #NO_APP
123 #[no_mangle]
124 check_reg!(f0_f32, f32, "$f0", "mov.s");
125
126 // CHECK-LABEL: reg_f32_64:
127 // CHECK: #APP
128 // CHECK: mov.d $f{{[0-9]+}}, $f{{[0-9]+}}
129 // CHECK: #NO_APP
130 check!(reg_f32_64, f32, freg, "mov.d");
131
132 // CHECK-LABEL: f0_f32_64:
133 // CHECK: #APP
134 // CHECK: mov.d $f0, $f0
135 // CHECK: #NO_APP
136 #[no_mangle]
137 check_reg!(f0_f32_64, f32, "$f0", "mov.d");
138
139 // CHECK-LABEL: reg_f64:
140 // CHECK: #APP
141 // CHECK: mov.d $f{{[0-9]+}}, $f{{[0-9]+}}
142 // CHECK: #NO_APP
143 #[no_mangle]
144 check!(reg_f64, f64, freg, "mov.d");
145
146 // CHECK-LABEL: f0_f64:
147 // CHECK: #APP
148 // CHECK: mov.d $f0, $f0
149 // CHECK: #NO_APP
150 #[no_mangle]
151 check_reg!(f0_f64, f64, "$f0", "mov.d");
152
153 // CHECK-LABEL: reg_ptr:
154 // CHECK: #APP
155 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
156 // CHECK: #NO_APP
157 check!(reg_ptr, ptr, reg, "move");
158
159 // CHECK-LABEL: reg_i32:
160 // CHECK: #APP
161 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
162 // CHECK: #NO_APP
163 check!(reg_i32, i32, reg, "move");
164
165 // CHECK-LABEL: reg_f32_soft:
166 // CHECK: #APP
167 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
168 // CHECK: #NO_APP
169 check!(reg_f32_soft, f32, reg, "move");
170
171 // mips64-LABEL: reg_f64_soft:
172 // mips64: #APP
173 // mips64: move ${{[0-9]+}}, ${{[0-9]+}}
174 // mips64: #NO_APP
175 #[cfg(mips64)]
176 check!(reg_f64_soft, f64, reg, "move");
177
178 // CHECK-LABEL: reg_i8:
179 // CHECK: #APP
180 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
181 // CHECK: #NO_APP
182 check!(reg_i8, i8, reg, "move");
183
184 // CHECK-LABEL: reg_u8:
185 // CHECK: #APP
186 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
187 // CHECK: #NO_APP
188 check!(reg_u8, u8, reg, "move");
189
190 // CHECK-LABEL: reg_i16:
191 // CHECK: #APP
192 // CHECK: move ${{[0-9]+}}, ${{[0-9]+}}
193 // CHECK: #NO_APP
194 check!(reg_i16, i16, reg, "move");
195
196 // mips64-LABEL: reg_i64:
197 // mips64: #APP
198 // mips64: move ${{[0-9]+}}, ${{[0-9]+}}
199 // mips64: #NO_APP
200 #[cfg(mips64)]
201 check!(reg_i64, i64, reg, "move");
202
203 // CHECK-LABEL: r8_ptr:
204 // CHECK: #APP
205 // CHECK: move $8, $8
206 // CHECK: #NO_APP
207 check_reg!(r8_ptr, ptr, "$8", "move");
208
209 // CHECK-LABEL: r8_i32:
210 // CHECK: #APP
211 // CHECK: move $8, $8
212 // CHECK: #NO_APP
213 check_reg!(r8_i32, i32, "$8", "move");
214
215 // CHECK-LABEL: r8_f32:
216 // CHECK: #APP
217 // CHECK: move $8, $8
218 // CHECK: #NO_APP
219 check_reg!(r8_f32, f32, "$8", "move");
220
221 // CHECK-LABEL: r8_i8:
222 // CHECK: #APP
223 // CHECK: move $8, $8
224 // CHECK: #NO_APP
225 check_reg!(r8_i8, i8, "$8", "move");
226
227 // CHECK-LABEL: r8_u8:
228 // CHECK: #APP
229 // CHECK: move $8, $8
230 // CHECK: #NO_APP
231 check_reg!(r8_u8, u8, "$8", "move");
232
233 // CHECK-LABEL: r8_i16:
234 // CHECK: #APP
235 // CHECK: move $8, $8
236 // CHECK: #NO_APP
237 check_reg!(r8_i16, i16, "$8", "move");