]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // run-pass |
2 | ||
92a42be0 SL |
3 | #![feature(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 | 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 { | |
9cc50fc6 | 17 | asm!("mov $1, $0" : "=*m" (ptr) : "r" (val)); |
92a42be0 SL |
18 | } |
19 | } | |
20 | ||
9cc50fc6 SL |
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 | asm!("mov $0, $1; mov $2, $0" : "+*m" (ptr), "=&r" (out) : "r" (val)); | |
26 | } | |
27 | out | |
28 | } | |
29 | ||
92a42be0 SL |
30 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
31 | pub fn main() { | |
32 | let a = 1; | |
92a42be0 | 33 | assert_eq!(read(&a), 1); |
9cc50fc6 | 34 | let mut b = 2; |
92a42be0 SL |
35 | write(&mut b, 3); |
36 | assert_eq!(b, 3); | |
9cc50fc6 SL |
37 | let mut c = 4; |
38 | assert_eq!(replace(&mut c, 5), 4); | |
39 | assert_eq!(c, 5); | |
92a42be0 SL |
40 | } |
41 | ||
42 | #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] | |
43 | pub fn main() {} |