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