]> git.lizzy.rs Git - rust.git/blob - src/test/ui/abi/abi-sysv64-register-usage.rs
Rollup merge of #66048 - mjptree:patch-1, r=Dylan-DPC
[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 #[repr(C)]
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 pub extern "sysv64" fn large_struct_by_val(mut foo: LargeStruct) -> LargeStruct {
43     foo.0 *= 1;
44     foo.1 *= 2;
45     foo.2 *= 3;
46     foo.3 *= 4;
47     foo.4 *= 5;
48     foo.5 *= 6;
49     foo.6 *= 7;
50     foo.7 *= 8;
51     foo
52 }
53
54 #[cfg(target_arch = "x86_64")]
55 pub fn main() {
56     let result: i64;
57     unsafe {
58         asm!("mov rdi, 1;
59               mov rsi, 2;
60               mov rdx, 3;
61               mov rcx, 4;
62               mov r8,  5;
63               mov r9,  6;
64               mov eax, 0x3F800000;
65               movd xmm0, eax;
66               mov eax, 0x40000000;
67               movd xmm1, eax;
68               mov eax, 0x40800000;
69               movd xmm2, eax;
70               mov eax, 0x41000000;
71               movd xmm3, eax;
72               mov eax, 0x41800000;
73               movd xmm4, eax;
74               mov eax, 0x42000000;
75               movd xmm5, eax;
76               mov eax, 0x42800000;
77               movd xmm6, eax;
78               mov eax, 0x43000000;
79               movd xmm7, eax;
80               call r10
81               "
82             : "={rax}"(result)
83             : "{r10}"(all_the_registers as usize)
84             : "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11", "cc", "memory"
85             : "intel", "alignstack"
86         )
87     }
88     assert_eq!(result, 42);
89
90     assert_eq!(
91         large_struct_by_val(LargeStruct(1, 2, 3, 4, 5, 6, 7, 8)),
92         LargeStruct(1, 4, 9, 16, 25, 36, 49, 64)
93     );
94 }
95
96 #[cfg(not(target_arch = "x86_64"))]
97 pub fn main() {}