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