]> git.lizzy.rs Git - rust.git/blob - src/test/ui/asm/x86_64/const.rs
Rollup merge of #95040 - frank-king:fix/94981, r=Mark-Simulacrum
[rust.git] / src / test / ui / asm / x86_64 / const.rs
1 // only-x86_64
2 // run-pass
3 // needs-asm-support
4 // revisions: mirunsafeck thirunsafeck
5 // [thirunsafeck]compile-flags: -Z thir-unsafeck
6
7 #![feature(asm_const)]
8
9 use std::arch::{asm, global_asm};
10
11 fn const_generic<const X: usize>() -> usize {
12     unsafe {
13         let a: usize;
14         asm!("mov {}, {}", out(reg) a, const X);
15         a
16     }
17 }
18
19 const fn constfn(x: usize) -> usize {
20     x
21 }
22
23 fn main() {
24     unsafe {
25         let a: usize;
26         asm!("mov {}, {}", out(reg) a, const 5);
27         assert_eq!(a, 5);
28
29         let b: usize;
30         asm!("mov {}, {}", out(reg) b, const constfn(5));
31         assert_eq!(b, 5);
32
33         let c: usize;
34         asm!("mov {}, {}", out(reg) c, const constfn(5) + constfn(5));
35         assert_eq!(c, 10);
36     }
37
38     let d = const_generic::<5>();
39     assert_eq!(d, 5);
40 }
41
42 global_asm!("mov eax, {}", const 5);
43 global_asm!("mov eax, {}", const constfn(5));
44 global_asm!("mov eax, {}", const constfn(5) + constfn(5));