]> git.lizzy.rs Git - rust.git/blob - src/test/ui/abi/abi-sysv64-register-usage.rs
Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup
[rust.git] / src / test / ui / abi / abi-sysv64-register-usage.rs
1 // run-pass
2 // Checks if the correct registers are being used to pass arguments
3 // when the sysv64 ABI is specified.
4
5 // ignore-android
6 // ignore-arm
7 // ignore-aarch64
8
9 #![feature(llvm_asm)]
10 #![allow(deprecated)] // llvm_asm!
11
12 #[cfg(target_arch = "x86_64")]
13 pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64,
14                                          rcx: i64, r8 : i64, r9 : i64,
15                                          xmm0: f32, xmm1: f32, xmm2: f32,
16                                          xmm3: f32, xmm4: f32, xmm5: f32,
17                                          xmm6: f32, xmm7: f32) -> i64 {
18     assert_eq!(rdi, 1);
19     assert_eq!(rsi, 2);
20     assert_eq!(rdx, 3);
21     assert_eq!(rcx, 4);
22     assert_eq!(r8,  5);
23     assert_eq!(r9,  6);
24     assert_eq!(xmm0, 1.0f32);
25     assert_eq!(xmm1, 2.0f32);
26     assert_eq!(xmm2, 4.0f32);
27     assert_eq!(xmm3, 8.0f32);
28     assert_eq!(xmm4, 16.0f32);
29     assert_eq!(xmm5, 32.0f32);
30     assert_eq!(xmm6, 64.0f32);
31     assert_eq!(xmm7, 128.0f32);
32     42
33 }
34
35 // this struct contains 8 i64's, while only 6 can be passed in registers.
36 #[cfg(target_arch = "x86_64")]
37 #[derive(PartialEq, Eq, Debug)]
38 pub struct LargeStruct(i64, i64, i64, i64, i64, i64, i64, i64);
39
40 #[cfg(target_arch = "x86_64")]
41 #[inline(never)]
42 #[allow(improper_ctypes_definitions)]
43 pub extern "sysv64" fn large_struct_by_val(mut foo: LargeStruct) -> LargeStruct {
44     foo.0 *= 1;
45     foo.1 *= 2;
46     foo.2 *= 3;
47     foo.3 *= 4;
48     foo.4 *= 5;
49     foo.5 *= 6;
50     foo.6 *= 7;
51     foo.7 *= 8;
52     foo
53 }
54
55 #[cfg(target_arch = "x86_64")]
56 pub fn main() {
57     let result: i64;
58     unsafe {
59         llvm_asm!("mov rdi, 1;
60                    mov rsi, 2;
61                    mov rdx, 3;
62                    mov rcx, 4;
63                    mov r8,  5;
64                    mov r9,  6;
65                    mov eax, 0x3F800000;
66                    movd xmm0, eax;
67                    mov eax, 0x40000000;
68                    movd xmm1, eax;
69                    mov eax, 0x40800000;
70                    movd xmm2, eax;
71                    mov eax, 0x41000000;
72                    movd xmm3, eax;
73                    mov eax, 0x41800000;
74                    movd xmm4, eax;
75                    mov eax, 0x42000000;
76                    movd xmm5, eax;
77                    mov eax, 0x42800000;
78                    movd xmm6, eax;
79                    mov eax, 0x43000000;
80                    movd xmm7, eax;
81                    call r10
82                    "
83                  : "={rax}"(result)
84                  : "{r10}"(all_the_registers as usize)
85                  : "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11", "cc", "memory"
86                  : "intel", "alignstack"
87         )
88     }
89     assert_eq!(result, 42);
90
91     assert_eq!(
92         large_struct_by_val(LargeStruct(1, 2, 3, 4, 5, 6, 7, 8)),
93         LargeStruct(1, 4, 9, 16, 25, 36, 49, 64)
94     );
95 }
96
97 #[cfg(not(target_arch = "x86_64"))]
98 pub fn main() {}