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