]> git.lizzy.rs Git - rust.git/blob - src/test/ui/asm-indirect-memory.rs
Rollup merge of #70649 - GuillaumeGomez:cleanup-e0468, r=Dylan-DPC
[rust.git] / src / test / ui / asm-indirect-memory.rs
1 // run-pass
2
3 #![feature(llvm_asm)]
4
5 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6 fn read(ptr: &u32) -> u32 {
7     let out: u32;
8     unsafe {
9         llvm_asm!("mov $1, $0" : "=r" (out) : "*m" (ptr));
10     }
11     out
12 }
13
14 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
15 fn write(ptr: &mut u32, val: u32) {
16     unsafe {
17         llvm_asm!("mov $1, $0" : "=*m" (ptr) : "r" (val));
18     }
19 }
20
21 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
22 fn replace(ptr: &mut u32, val: u32) -> u32 {
23     let out: u32;
24     unsafe {
25         llvm_asm!("mov $0, $1; mov $2, $0" : "+*m" (ptr), "=&r" (out) : "r" (val));
26     }
27     out
28 }
29
30 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
31 pub fn main() {
32     let a = 1;
33     assert_eq!(read(&a), 1);
34     let mut b = 2;
35     write(&mut b, 3);
36     assert_eq!(b, 3);
37     let mut c = 4;
38     assert_eq!(replace(&mut c, 5), 4);
39     assert_eq!(c, 5);
40 }
41
42 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
43 pub fn main() {}