fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
8.3 KiB350 linesraw
1#include <assert.h>
2#include <stdint.h>
3
4struct Rect {
5    int32_t a;
6    int32_t b;
7    int32_t c;
8    int32_t d;
9};
10
11struct BiggerRect {
12    struct Rect s;
13    int32_t a;
14    int32_t b;
15};
16
17struct FloatRect {
18    int32_t a;
19    int32_t b;
20    double c;
21};
22
23struct Huge {
24    int32_t a;
25    int32_t b;
26    int32_t c;
27    int32_t d;
28    int32_t e;
29};
30
31struct Huge64 {
32    int64_t a;
33    int64_t b;
34    int64_t c;
35    int64_t d;
36    int64_t e;
37};
38
39struct FloatPoint {
40    double x;
41    double y;
42};
43
44struct FloatOne {
45    double x;
46};
47
48struct IntOdd {
49    int8_t a;
50    int8_t b;
51    int8_t c;
52};
53
54// System V x86_64 ABI:
55// a, b, c, d, e should be in registers
56// s should be byval pointer
57//
58// Win64 ABI:
59// a, b, c, d should be in registers
60// e should be on the stack
61// s should be byval pointer
62void byval_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, struct Rect s) {
63    assert(a == 1);
64    assert(b == 2);
65    assert(c == 3);
66    assert(d == 4);
67    assert(e == 5);
68    assert(s.a == 553);
69    assert(s.b == 554);
70    assert(s.c == 555);
71    assert(s.d == 556);
72}
73
74// System V x86_64 ABI:
75// a, b, c, d, e, f should be in registers
76// s should be byval pointer on the stack
77//
78// Win64 ABI:
79// a, b, c, d should be in registers
80// e, f should be on the stack
81// s should be byval pointer on the stack
82void byval_many_rect(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e,
83                     int32_t f, struct Rect s) {
84    assert(a == 1);
85    assert(b == 2);
86    assert(c == 3);
87    assert(d == 4);
88    assert(e == 5);
89    assert(f == 6);
90    assert(s.a == 553);
91    assert(s.b == 554);
92    assert(s.c == 555);
93    assert(s.d == 556);
94}
95
96// System V x86_64 ABI:
97// a, b, c, d, e, f, g should be in sse registers
98// s should be split across 2 registers
99// t should be byval pointer
100//
101// Win64 ABI:
102// a, b, c, d should be in sse registers
103// e, f, g should be on the stack
104// s should be on the stack (treated as 2 i64's)
105// t should be on the stack (treated as an i64 and a double)
106void byval_rect_floats(float a, float b, double c, float d, float e,
107                       float f, double g, struct Rect s, struct FloatRect t) {
108    assert(a == 1.);
109    assert(b == 2.);
110    assert(c == 3.);
111    assert(d == 4.);
112    assert(e == 5.);
113    assert(f == 6.);
114    assert(g == 7.);
115    assert(s.a == 553);
116    assert(s.b == 554);
117    assert(s.c == 555);
118    assert(s.d == 556);
119    assert(t.a == 3489);
120    assert(t.b == 3490);
121    assert(t.c == 8.);
122}
123
124// System V x86_64 ABI:
125// a, b, d, e, f should be in registers
126// c passed via sse registers
127// s should be byval pointer
128//
129// Win64 ABI:
130// a, b, d should be in registers
131// c passed via sse registers
132// e, f should be on the stack
133// s should be byval pointer
134void byval_rect_with_float(int32_t a, int32_t b, float c, int32_t d,
135                           int32_t e, int32_t f, struct Rect s) {
136    assert(a == 1);
137    assert(b == 2);
138    assert(c == 3.);
139    assert(d == 4);
140    assert(e == 5);
141    assert(f == 6);
142    assert(s.a == 553);
143    assert(s.b == 554);
144    assert(s.c == 555);
145    assert(s.d == 556);
146}
147
148// System V x86_64 ABI:
149// a, b, d, e, f should be byval pointer (on the stack)
150// g passed via register (fixes #41375)
151//
152// Win64 ABI:
153// a, b, d, e, f, g should be byval pointer
154void byval_rect_with_many_huge(struct Huge a, struct Huge b, struct Huge c,
155                               struct Huge d, struct Huge e, struct Huge f,
156                               struct Rect g) {
157    assert(g.a == 123);
158    assert(g.b == 456);
159    assert(g.c == 789);
160    assert(g.d == 420);
161}
162
163// System V x86_64 ABI:
164// a, b, d, e, f should be byval pointer (on the stack)
165// g passed via register (fixes #41375)
166//
167// i686-windows ABI:
168// a, b, d, e, f, g should be byval pointer
169void byval_rect_with_many_huge64(struct Huge64 a, struct Huge64 b, struct Huge64 c,
170                               struct Huge64 d, struct Huge64 e, struct Huge64 f,
171                               struct Rect g) {
172    assert(g.a == 1234);
173    assert(g.b == 4567);
174    assert(g.c == 7890);
175    assert(g.d == 4209);
176}
177
178// System V x86_64 & Win64 ABI:
179// a, b should be in registers
180// s should be split across 2 integer registers
181void split_rect(int32_t a, int32_t b, struct Rect s) {
182    assert(a == 1);
183    assert(b == 2);
184    assert(s.a == 553);
185    assert(s.b == 554);
186    assert(s.c == 555);
187    assert(s.d == 556);
188}
189
190// System V x86_64 & Win64 ABI:
191// a, b should be in sse registers
192// s should be split across integer & sse registers
193void split_rect_floats(float a, float b, struct FloatRect s) {
194    assert(a == 1.);
195    assert(b == 2.);
196    assert(s.a == 3489);
197    assert(s.b == 3490);
198    assert(s.c == 8.);
199}
200
201// System V x86_64 ABI:
202// a, b, d, f should be in registers
203// c, e passed via sse registers
204// s should be split across 2 registers
205//
206// Win64 ABI:
207// a, b, d should be in registers
208// c passed via sse registers
209// e, f should be on the stack
210// s should be on the stack (treated as 2 i64's)
211void split_rect_with_floats(int32_t a, int32_t b, float c,
212                            int32_t d, float e, int32_t f, struct Rect s) {
213    assert(a == 1);
214    assert(b == 2);
215    assert(c == 3.);
216    assert(d == 4);
217    assert(e == 5.);
218    assert(f == 6);
219    assert(s.a == 553);
220    assert(s.b == 554);
221    assert(s.c == 555);
222    assert(s.d == 556);
223}
224
225// System V x86_64 & Win64 ABI:
226// a, b, c should be in registers
227// s should be split across 2 registers
228// t should be a byval pointer
229void split_and_byval_rect(int32_t a, int32_t b, int32_t c, struct Rect s, struct Rect t) {
230    assert(a == 1);
231    assert(b == 2);
232    assert(c == 3);
233    assert(s.a == 553);
234    assert(s.b == 554);
235    assert(s.c == 555);
236    assert(s.d == 556);
237    assert(t.a == 553);
238    assert(t.b == 554);
239    assert(t.c == 555);
240    assert(t.d == 556);
241}
242
243// System V x86_64 & Win64 ABI:
244// a, b should in registers
245// s and return should be split across 2 registers
246struct Rect split_ret_byval_struct(int32_t a, int32_t b, struct Rect s) {
247    assert(a == 1);
248    assert(b == 2);
249    assert(s.a == 553);
250    assert(s.b == 554);
251    assert(s.c == 555);
252    assert(s.d == 556);
253    return s;
254}
255
256// System V x86_64 & Win64 ABI:
257// a, b, c, d should be in registers
258// return should be in a hidden sret pointer
259// s should be a byval pointer
260struct BiggerRect sret_byval_struct(int32_t a, int32_t b, int32_t c, int32_t d, struct Rect s) {
261    assert(a == 1);
262    assert(b == 2);
263    assert(c == 3);
264    assert(d == 4);
265    assert(s.a == 553);
266    assert(s.b == 554);
267    assert(s.c == 555);
268    assert(s.d == 556);
269
270    struct BiggerRect t;
271    t.s = s; t.a = 27834; t.b = 7657;
272    return t;
273}
274
275// System V x86_64 & Win64 ABI:
276// a, b should be in registers
277// return should be in a hidden sret pointer
278// s should be split across 2 registers
279struct BiggerRect sret_split_struct(int32_t a, int32_t b, struct Rect s) {
280    assert(a == 1);
281    assert(b == 2);
282    assert(s.a == 553);
283    assert(s.b == 554);
284    assert(s.c == 555);
285    assert(s.d == 556);
286
287    struct BiggerRect t;
288    t.s = s; t.a = 27834; t.b = 7657;
289    return t;
290}
291
292// System V x86_64 & Win64 ABI:
293// s should be byval pointer (since sizeof(s) > 16)
294// return should in a hidden sret pointer
295struct Huge huge_struct(struct Huge s) {
296    assert(s.a == 5647);
297    assert(s.b == 5648);
298    assert(s.c == 5649);
299    assert(s.d == 5650);
300    assert(s.e == 5651);
301
302    return s;
303}
304
305// System V x86_64 & i686-windows ABI:
306// s should be byval pointer
307// return should in a hidden sret pointer
308struct Huge64 huge64_struct(struct Huge64 s) {
309    assert(s.a == 1234);
310    assert(s.b == 1335);
311    assert(s.c == 1436);
312    assert(s.d == 1537);
313    assert(s.e == 1638);
314
315    return s;
316}
317
318// System V x86_64 ABI:
319// p should be in registers
320// return should be in registers
321//
322// Win64 ABI and 64-bit PowerPC ELFv1 ABI:
323// p should be a byval pointer
324// return should be in a hidden sret pointer
325struct FloatPoint float_point(struct FloatPoint p) {
326    assert(p.x == 5.);
327    assert(p.y == -3.);
328
329    return p;
330}
331
332// 64-bit PowerPC ELFv1 ABI:
333// f1 should be in a register
334// return should be in a hidden sret pointer
335struct FloatOne float_one(struct FloatOne f1) {
336    assert(f1.x == 7.);
337
338    return f1;
339}
340
341// 64-bit PowerPC ELFv1 ABI:
342// i should be in the least-significant bits of a register
343// return should be in a hidden sret pointer
344struct IntOdd int_odd(struct IntOdd i) {
345    assert(i.a == 1);
346    assert(i.b == 2);
347    assert(i.c == 3);
348
349    return i;
350}