Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / testsuite / gcc.target / x86_64 / abi / test_passing_structs.c
blob3ce0db14652e4ed6f579a3b9ed3fdf3830d2a55f
1 /* This tests passing of structs. */
3 #include "defines.h"
4 #include "args.h"
6 struct IntegerRegisters iregs;
7 struct FloatRegisters fregs;
8 unsigned int num_iregs, num_fregs;
10 struct int_struct
12 int i;
15 struct long_struct
17 long l;
20 struct long2_struct
22 long l1, l2;
25 struct long3_struct
27 long l1, l2, l3;
31 /* Check that the struct is passed as the individual members in iregs. */
32 void
33 check_struct_passing1 (struct int_struct is ATTRIBUTE_UNUSED)
35 check_int_arguments;
38 void
39 check_struct_passing2 (struct long_struct ls ATTRIBUTE_UNUSED)
41 check_int_arguments;
44 void
45 check_struct_passing3 (struct long2_struct ls ATTRIBUTE_UNUSED)
47 check_int_arguments;
50 void
51 check_struct_passing4 (struct long3_struct ls ATTRIBUTE_UNUSED)
53 /* Check the passing on the stack by comparing the address of the
54 stack elements to the expected place on the stack. */
55 assert ((unsigned long)&ls.l1 == rsp+8);
56 assert ((unsigned long)&ls.l2 == rsp+16);
57 assert ((unsigned long)&ls.l3 == rsp+24);
60 #ifdef CHECK_M64_M128
61 struct m128_struct
63 __m128 x;
66 struct m128_2_struct
68 __m128 x1, x2;
71 /* Check that the struct is passed as the individual members in fregs. */
72 void
73 check_struct_passing5 (struct m128_struct ms1 ATTRIBUTE_UNUSED,
74 struct m128_struct ms2 ATTRIBUTE_UNUSED,
75 struct m128_struct ms3 ATTRIBUTE_UNUSED,
76 struct m128_struct ms4 ATTRIBUTE_UNUSED,
77 struct m128_struct ms5 ATTRIBUTE_UNUSED,
78 struct m128_struct ms6 ATTRIBUTE_UNUSED,
79 struct m128_struct ms7 ATTRIBUTE_UNUSED,
80 struct m128_struct ms8 ATTRIBUTE_UNUSED)
82 check_m128_arguments;
85 void
86 check_struct_passing6 (struct m128_2_struct ms ATTRIBUTE_UNUSED)
88 /* Check the passing on the stack by comparing the address of the
89 stack elements to the expected place on the stack. */
90 assert ((unsigned long)&ms.x1 == rsp+8);
91 assert ((unsigned long)&ms.x2 == rsp+24);
93 #endif
95 int
96 main (void)
98 struct int_struct is = { 48 };
99 struct long_struct ls = { 49 };
100 #ifdef CHECK_LARGER_STRUCTS
101 struct long2_struct l2s = { 50, 51 };
102 struct long3_struct l3s = { 52, 53, 54 };
103 #endif
104 #ifdef CHECK_M64_M128
105 struct m128_struct m128s[8];
106 struct m128_2_struct m128_2s = {
107 { 48.394, 39.3, -397.9, 3484.9 },
108 { -8.394, -93.3, 7.9, 84.94 }
110 int i;
111 #endif
113 clear_struct_registers;
114 iregs.I0 = is.i;
115 num_iregs = 1;
116 clear_int_hardware_registers;
117 WRAP_CALL (check_struct_passing1)(is);
119 clear_struct_registers;
120 iregs.I0 = ls.l;
121 num_iregs = 1;
122 clear_int_hardware_registers;
123 WRAP_CALL (check_struct_passing2)(ls);
125 #ifdef CHECK_LARGER_STRUCTS
126 clear_struct_registers;
127 iregs.I0 = l2s.l1;
128 iregs.I1 = l2s.l2;
129 num_iregs = 2;
130 clear_int_hardware_registers;
131 WRAP_CALL (check_struct_passing3)(l2s);
132 WRAP_CALL (check_struct_passing4)(l3s);
133 #endif
135 #ifdef CHECK_M64_M128
136 clear_struct_registers;
137 for (i = 0; i < 8; i++)
139 m128s[i].x = (__m128){32+i, 0, i, 0};
140 fregs.xmm0._m128[i] = m128s[i].x;
142 num_fregs = 8;
143 clear_float_hardware_registers;
144 WRAP_CALL (check_struct_passing5)(m128s[0], m128s[1], m128s[2], m128s[3],
145 m128s[4], m128s[5], m128s[6], m128s[7]);
146 WRAP_CALL (check_struct_passing6)(m128_2s);
147 #endif
149 return 0;