2021-06-24 09:01:49 -05:00
|
|
|
// only-aarch64
|
2020-05-11 11:53:32 -05:00
|
|
|
// run-pass
|
2022-03-19 10:50:24 -05:00
|
|
|
// needs-asm-support
|
2021-05-14 08:22:30 -05:00
|
|
|
// revisions: mirunsafeck thirunsafeck
|
|
|
|
// [thirunsafeck]compile-flags: -Z thir-unsafeck
|
2020-05-11 11:53:32 -05:00
|
|
|
|
2021-12-09 18:15:33 -06:00
|
|
|
#![feature(asm_const)]
|
|
|
|
|
|
|
|
use std::arch::{asm, global_asm};
|
2020-05-11 11:53:32 -05:00
|
|
|
|
2021-04-05 23:50:55 -05:00
|
|
|
fn const_generic<const X: usize>() -> usize {
|
|
|
|
unsafe {
|
|
|
|
let a: usize;
|
|
|
|
asm!("mov {}, {}", out(reg) a, const X);
|
|
|
|
a
|
|
|
|
}
|
2020-05-11 11:53:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const fn constfn(x: usize) -> usize {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let a: usize;
|
|
|
|
asm!("mov {}, {}", out(reg) a, const 5);
|
|
|
|
assert_eq!(a, 5);
|
|
|
|
|
|
|
|
let b: usize;
|
|
|
|
asm!("mov {}, {}", out(reg) b, const constfn(5));
|
|
|
|
assert_eq!(b, 5);
|
|
|
|
|
|
|
|
let c: usize;
|
|
|
|
asm!("mov {}, {}", out(reg) c, const constfn(5) + constfn(5));
|
|
|
|
assert_eq!(c, 10);
|
|
|
|
}
|
|
|
|
|
2021-04-05 23:50:55 -05:00
|
|
|
let d = const_generic::<5>();
|
|
|
|
assert_eq!(d, 5);
|
2020-05-11 11:53:32 -05:00
|
|
|
}
|
2021-04-13 12:11:11 -05:00
|
|
|
|
2021-06-24 09:01:49 -05:00
|
|
|
global_asm!("mov x0, {}", const 5);
|
|
|
|
global_asm!("mov x0, {}", const constfn(5));
|
|
|
|
global_asm!("mov x0, {}", const constfn(5) + constfn(5));
|