1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
// This program is designed to test some arm64-specific things, such as the
// calling convention, but should give the same results on any architecture.
#include <stdarg.h>
#include <stdio.h>
struct s1 { char x[1]; } s1 = { "0" };
struct s2 { char x[2]; } s2 = { "12" };
struct s3 { char x[3]; } s3 = { "345" };
struct s4 { char x[4]; } s4 = { "6789" };
struct s5 { char x[5]; } s5 = { "abcde" };
struct s6 { char x[6]; } s6 = { "fghijk" };
struct s7 { char x[7]; } s7 = { "lmnopqr" };
struct s8 { char x[8]; } s8 = { "stuvwxyz" };
struct s9 { char x[9]; } s9 = { "ABCDEFGHI" };
struct s10 { char x[10]; } s10 = { "JKLMNOPQRS" };
struct s11 { char x[11]; } s11 = { "TUVWXYZ0123" };
struct s12 { char x[12]; } s12 = { "456789abcdef" };
struct s13 { char x[13]; } s13 = { "ghijklmnopqrs" };
struct s14 { char x[14]; } s14 = { "tuvwxyzABCDEFG" };
struct s15 { char x[15]; } s15 = { "HIJKLMNOPQRSTUV" };
struct s16 { char x[16]; } s16 = { "WXYZ0123456789ab" };
struct s17 { char x[17]; } s17 = { "cdefghijklmnopqrs" };
struct hfa11 { float a; } hfa11 = { 11.1 };
struct hfa12 { float a, b; } hfa12 = { 12.1, 12.2 };
struct hfa13 { float a, b, c; } hfa13 = { 13.1, 13.2, 13.3 };
struct hfa14 { float a, b, c, d; } hfa14 = { 14.1, 14.2, 14.3, 14.4 };
struct hfa21 { double a; } hfa21 = { 21.1 };
struct hfa22 { double a, b; } hfa22 = { 22.1, 22.2 };
struct hfa23 { double a, b, c; } hfa23 = { 23.1, 23.2, 23.3 };
struct hfa24 { double a, b, c, d; } hfa24 = { 24.1, 24.2, 24.3, 24.4 };
struct hfa31 { long double a; } hfa31 = { 31.1 };
struct hfa32 { long double a, b; } hfa32 = { 32.1, 32.2 };
struct hfa33 { long double a, b, c; } hfa33 = { 33.1, 33.2, 33.3 };
struct hfa34 { long double a, b, c, d; } hfa34 = { 34.1, 34.2, 34.3, 34.4 };
void fa_s1(struct s1 a) { printf("%.1s\n", a.x); }
void fa_s2(struct s2 a) { printf("%.2s\n", a.x); }
void fa_s3(struct s3 a) { printf("%.3s\n", a.x); }
void fa_s4(struct s4 a) { printf("%.4s\n", a.x); }
void fa_s5(struct s5 a) { printf("%.5s\n", a.x); }
void fa_s6(struct s6 a) { printf("%.6s\n", a.x); }
void fa_s7(struct s7 a) { printf("%.7s\n", a.x); }
void fa_s8(struct s8 a) { printf("%.8s\n", a.x); }
void fa_s9(struct s9 a) { printf("%.9s\n", a.x); }
void fa_s10(struct s10 a) { printf("%.10s\n", a.x); }
void fa_s11(struct s11 a) { printf("%.11s\n", a.x); }
void fa_s12(struct s12 a) { printf("%.12s\n", a.x); }
void fa_s13(struct s13 a) { printf("%.13s\n", a.x); }
void fa_s14(struct s14 a) { printf("%.14s\n", a.x); }
void fa_s15(struct s15 a) { printf("%.15s\n", a.x); }
void fa_s16(struct s16 a) { printf("%.16s\n", a.x); }
void fa_s17(struct s17 a) { printf("%.17s\n", a.x); }
void fa_hfa11(struct hfa11 a)
{ printf("%.1f\n", a.a); }
void fa_hfa12(struct hfa12 a)
{ printf("%.1f %.1f\n", a.a, a.a); }
void fa_hfa13(struct hfa13 a)
{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); }
void fa_hfa14(struct hfa14 a)
{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); }
void fa_hfa21(struct hfa21 a)
{ printf("%.1f\n", a.a); }
void fa_hfa22(struct hfa22 a)
{ printf("%.1f %.1f\n", a.a, a.a); }
void fa_hfa23(struct hfa23 a)
{ printf("%.1f %.1f %.1f\n", a.a, a.b, a.c); }
void fa_hfa24(struct hfa24 a)
{ printf("%.1f %.1f %.1f %.1f\n", a.a, a.b, a.c, a.d); }
void fa_hfa31(struct hfa31 a)
{ printf("%.1Lf\n", a.a); }
void fa_hfa32(struct hfa32 a)
{ printf("%.1Lf %.1Lf\n", a.a, a.a); }
void fa_hfa33(struct hfa33 a)
{ printf("%.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c); }
void fa_hfa34(struct hfa34 a)
{ printf("%.1Lf %.1Lf %.1Lf %.1Lf\n", a.a, a.b, a.c, a.d); }
void fa1(struct s8 a, struct s9 b, struct s10 c, struct s11 d,
struct s12 e, struct s13 f)
{
printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x);
}
void fa2(struct s9 a, struct s10 b, struct s11 c, struct s12 d,
struct s13 e, struct s14 f)
{
printf("%.3s %.3s %.3s %.3s %.3s %.3s\n", a.x, b.x, c.x, d.x, e.x, f.x);
}
void fa3(struct hfa14 a, struct hfa23 b, struct hfa32 c)
{
printf("%.1f %.1f %.1f %.1f %.1Lf %.1Lf\n",
a.a, a.d, b.a, b.c, c.a, c.b);
}
void fa4(struct s1 a, struct hfa14 b, struct s2 c, struct hfa24 d,
struct s3 e, struct hfa34 f)
{
printf("%.1s %.1f %.1f %.2s %.1f %.1f %.3s %.1Lf %.1Lf\n",
a.x, b.a, b.d, c.x, d.a, d.d, e.x, f.a, f.d);
}
void arg(void)
{
printf("Arguments:\n");
fa_s1(s1);
fa_s2(s2);
fa_s3(s3);
fa_s4(s4);
fa_s5(s5);
fa_s6(s6);
fa_s7(s7);
fa_s8(s8);
fa_s9(s9);
fa_s10(s10);
fa_s11(s11);
fa_s12(s12);
fa_s13(s13);
fa_s14(s14);
fa_s15(s15);
fa_s16(s16);
fa_s17(s17);
fa_hfa11(hfa11);
fa_hfa12(hfa12);
fa_hfa13(hfa13);
fa_hfa14(hfa14);
fa_hfa21(hfa21);
fa_hfa22(hfa22);
fa_hfa23(hfa23);
fa_hfa24(hfa24);
fa_hfa31(hfa31);
fa_hfa32(hfa32);
fa_hfa33(hfa33);
fa_hfa34(hfa34);
fa1(s8, s9, s10, s11, s12, s13);
fa2(s9, s10, s11, s12, s13, s14);
fa3(hfa14, hfa23, hfa32);
fa4(s1, hfa14, s2, hfa24, s3, hfa34);
}
struct s1 fr_s1(void) { return s1; }
struct s2 fr_s2(void) { return s2; }
struct s3 fr_s3(void) { return s3; }
struct s4 fr_s4(void) { return s4; }
struct s5 fr_s5(void) { return s5; }
struct s6 fr_s6(void) { return s6; }
struct s7 fr_s7(void) { return s7; }
struct s8 fr_s8(void) { return s8; }
struct s9 fr_s9(void) { return s9; }
struct s10 fr_s10(void) { return s10; }
struct s11 fr_s11(void) { return s11; }
struct s12 fr_s12(void) { return s12; }
struct s13 fr_s13(void) { return s13; }
struct s14 fr_s14(void) { return s14; }
struct s15 fr_s15(void) { return s15; }
struct s16 fr_s16(void) { return s16; }
struct s17 fr_s17(void) { return s17; }
struct hfa11 fr_hfa11(void) { return hfa11; }
struct hfa12 fr_hfa12(void) { return hfa12; }
struct hfa13 fr_hfa13(void) { return hfa13; }
struct hfa14 fr_hfa14(void) { return hfa14; }
struct hfa21 fr_hfa21(void) { return hfa21; }
struct hfa22 fr_hfa22(void) { return hfa22; }
struct hfa23 fr_hfa23(void) { return hfa23; }
struct hfa24 fr_hfa24(void) { return hfa24; }
struct hfa31 fr_hfa31(void) { return hfa31; }
struct hfa32 fr_hfa32(void) { return hfa32; }
struct hfa33 fr_hfa33(void) { return hfa33; }
struct hfa34 fr_hfa34(void) { return hfa34; }
void ret(void)
{
struct s1 t1 = fr_s1();
struct s2 t2 = fr_s2();
struct s3 t3 = fr_s3();
struct s4 t4 = fr_s4();
struct s5 t5 = fr_s5();
struct s6 t6 = fr_s6();
struct s7 t7 = fr_s7();
struct s8 t8 = fr_s8();
struct s9 t9 = fr_s9();
struct s10 t10 = fr_s10();
struct s11 t11 = fr_s11();
struct s12 t12 = fr_s12();
struct s13 t13 = fr_s13();
struct s14 t14 = fr_s14();
struct s15 t15 = fr_s15();
struct s16 t16 = fr_s16();
struct s17 t17 = fr_s17();
printf("Return values:\n");
printf("%.1s\n", t1.x);
printf("%.2s\n", t2.x);
printf("%.3s\n", t3.x);
printf("%.4s\n", t4.x);
printf("%.5s\n", t5.x);
printf("%.6s\n", t6.x);
printf("%.7s\n", t7.x);
printf("%.8s\n", t8.x);
printf("%.9s\n", t9.x);
printf("%.10s\n", t10.x);
printf("%.11s\n", t11.x);
printf("%.12s\n", t12.x);
printf("%.13s\n", t13.x);
printf("%.14s\n", t14.x);
printf("%.15s\n", t15.x);
printf("%.16s\n", t16.x);
printf("%.17s\n", t17.x);
printf("%.1f\n", fr_hfa11().a);
printf("%.1f %.1f\n", fr_hfa12().a, fr_hfa12().b);
printf("%.1f %.1f\n", fr_hfa13().a, fr_hfa13().c);
printf("%.1f %.1f\n", fr_hfa14().a, fr_hfa14().d);
printf("%.1f\n", fr_hfa21().a);
printf("%.1f %.1f\n", fr_hfa22().a, fr_hfa22().b);
printf("%.1f %.1f\n", fr_hfa23().a, fr_hfa23().c);
printf("%.1f %.1f\n", fr_hfa24().a, fr_hfa24().d);
printf("%.1Lf\n", fr_hfa31().a);
printf("%.1Lf %.1Lf\n", fr_hfa32().a, fr_hfa32().b);
printf("%.1Lf %.1Lf\n", fr_hfa33().a, fr_hfa33().c);
printf("%.1Lf %.1Lf\n", fr_hfa34().a, fr_hfa34().d);
}
int match(const char **s, const char *f)
{
const char *p = *s;
for (p = *s; *f && *f == *p; f++, p++)
;
if (!*f) {
*s = p - 1;
return 1;
}
return 0;
}
void myprintf(const char *format, ...)
{
const char *s;
va_list ap;
va_start(ap, format);
for (s = format; *s; s++) {
if (match(&s, "%7s")) {
struct s7 t7 = va_arg(ap, struct s7);
printf("%.7s", t7.x);
}
else if (match(&s, "%9s")) {
struct s9 t9 = va_arg(ap, struct s9);
printf("%.9s", t9.x);
}
else if (match(&s, "%hfa11")) {
struct hfa11 x = va_arg(ap, struct hfa11);
printf("%.1f,%.1f", x.a, x.a);
}
else if (match(&s, "%hfa12")) {
struct hfa12 x = va_arg(ap, struct hfa12);
printf("%.1f,%.1f", x.a, x.b);
}
else if (match(&s, "%hfa13")) {
struct hfa13 x = va_arg(ap, struct hfa13);
printf("%.1f,%.1f", x.a, x.c);
}
else if (match(&s, "%hfa14")) {
struct hfa14 x = va_arg(ap, struct hfa14);
printf("%.1f,%.1f", x.a, x.d);
}
else if (match(&s, "%hfa21")) {
struct hfa21 x = va_arg(ap, struct hfa21);
printf("%.1f,%.1f", x.a, x.a);
}
else if (match(&s, "%hfa22")) {
struct hfa22 x = va_arg(ap, struct hfa22);
printf("%.1f,%.1f", x.a, x.b);
}
else if (match(&s, "%hfa23")) {
struct hfa23 x = va_arg(ap, struct hfa23);
printf("%.1f,%.1f", x.a, x.c);
}
else if (match(&s, "%hfa24")) {
struct hfa24 x = va_arg(ap, struct hfa24);
printf("%.1f,%.1f", x.a, x.d);
}
else if (match(&s, "%hfa31")) {
struct hfa31 x = va_arg(ap, struct hfa31);
printf("%.1Lf,%.1Lf", x.a, x.a);
}
else if (match(&s, "%hfa32")) {
struct hfa32 x = va_arg(ap, struct hfa32);
printf("%.1Lf,%.1Lf", x.a, x.b);
}
else if (match(&s, "%hfa33")) {
struct hfa33 x = va_arg(ap, struct hfa33);
printf("%.1Lf,%.1Lf", x.a, x.c);
}
else if (match(&s, "%hfa34")) {
struct hfa34 x = va_arg(ap, struct hfa34);
printf("%.1Lf,%.1Lf", x.a, x.d);
}
else
putchar(*s);
}
putchar('\n');
}
void stdarg(void)
{
printf("stdarg:\n");
myprintf("%9s %9s %9s %9s %9s %9s", s9, s9, s9, s9, s9, s9);
myprintf("%7s %9s %9s %9s %9s %9s", s7, s9, s9, s9, s9, s9);
myprintf("HFA long double:");
myprintf("%hfa34 %hfa34 %hfa34 %hfa34", hfa34, hfa34, hfa34, hfa34);
myprintf("%hfa33 %hfa34 %hfa34 %hfa34", hfa33, hfa34, hfa34, hfa34);
myprintf("%hfa32 %hfa34 %hfa34 %hfa34", hfa32, hfa34, hfa34, hfa34);
myprintf("%hfa31 %hfa34 %hfa34 %hfa34", hfa31, hfa34, hfa34, hfa34);
myprintf("%hfa32 %hfa33 %hfa33 %hfa33 %hfa33",
hfa32, hfa33, hfa33, hfa33, hfa33);
myprintf("%hfa31 %hfa33 %hfa33 %hfa33 %hfa33",
hfa31, hfa33, hfa33, hfa33, hfa33);
myprintf("%hfa33 %hfa33 %hfa33 %hfa33",
hfa33, hfa33, hfa33, hfa33);
myprintf("%hfa34 %hfa32 %hfa32 %hfa32 %hfa32",
hfa34, hfa32, hfa32, hfa32, hfa32);
myprintf("%hfa33 %hfa32 %hfa32 %hfa32 %hfa32",
hfa33, hfa32, hfa32, hfa32, hfa32);
myprintf("%hfa34 %hfa32 %hfa31 %hfa31 %hfa31 %hfa31",
hfa34, hfa32, hfa31, hfa31, hfa31, hfa31);
myprintf("HFA double:");
myprintf("%hfa24 %hfa24 %hfa24 %hfa24", hfa24, hfa24, hfa24, hfa24);
myprintf("%hfa23 %hfa24 %hfa24 %hfa24", hfa23, hfa24, hfa24, hfa24);
myprintf("%hfa22 %hfa24 %hfa24 %hfa24", hfa22, hfa24, hfa24, hfa24);
myprintf("%hfa21 %hfa24 %hfa24 %hfa24", hfa21, hfa24, hfa24, hfa24);
myprintf("%hfa22 %hfa23 %hfa23 %hfa23 %hfa23",
hfa22, hfa23, hfa23, hfa23, hfa23);
myprintf("%hfa21 %hfa23 %hfa23 %hfa23 %hfa23",
hfa21, hfa23, hfa23, hfa23, hfa23);
myprintf("%hfa23 %hfa23 %hfa23 %hfa23",
hfa23, hfa23, hfa23, hfa23);
myprintf("%hfa24 %hfa22 %hfa22 %hfa22 %hfa22",
hfa24, hfa22, hfa22, hfa22, hfa22);
myprintf("%hfa23 %hfa22 %hfa22 %hfa22 %hfa22",
hfa23, hfa22, hfa22, hfa22, hfa22);
myprintf("%hfa24 %hfa22 %hfa21 %hfa21 %hfa21 %hfa21",
hfa24, hfa22, hfa21, hfa21, hfa21, hfa21);
myprintf("HFA float:");
myprintf("%hfa14 %hfa14 %hfa14 %hfa14", hfa14, hfa14, hfa14, hfa14);
myprintf("%hfa13 %hfa14 %hfa14 %hfa14", hfa13, hfa14, hfa14, hfa14);
myprintf("%hfa12 %hfa14 %hfa14 %hfa14", hfa12, hfa14, hfa14, hfa14);
myprintf("%hfa11 %hfa14 %hfa14 %hfa14", hfa11, hfa14, hfa14, hfa14);
myprintf("%hfa12 %hfa13 %hfa13 %hfa13 %hfa13",
hfa12, hfa13, hfa13, hfa13, hfa13);
myprintf("%hfa11 %hfa13 %hfa13 %hfa13 %hfa13",
hfa11, hfa13, hfa13, hfa13, hfa13);
myprintf("%hfa13 %hfa13 %hfa13 %hfa13",
hfa13, hfa13, hfa13, hfa13);
myprintf("%hfa14 %hfa12 %hfa12 %hfa12 %hfa12",
hfa14, hfa12, hfa12, hfa12, hfa12);
myprintf("%hfa13 %hfa12 %hfa12 %hfa12 %hfa12",
hfa13, hfa12, hfa12, hfa12, hfa12);
myprintf("%hfa14 %hfa12 %hfa11 %hfa11 %hfa11 %hfa11",
hfa14, hfa12, hfa11, hfa11, hfa11, hfa11);
}
void pll(unsigned long long x)
{
printf("%llx\n", x);
}
void movi(void)
{
printf("MOVI:\n");
pll(0);
pll(0xabcd);
pll(0xabcd0000);
pll(0xabcd00000000);
pll(0xabcd000000000000);
pll(0xffffabcd);
pll(0xabcdffff);
pll(0xffffffffffffabcd);
pll(0xffffffffabcdffff);
pll(0xffffabcdffffffff);
pll(0xabcdffffffffffff);
pll(0xaaaaaaaa);
pll(0x5555555555555555);
pll(0x77777777);
pll(0x3333333333333333);
pll(0xf8f8f8f8);
pll(0x1e1e1e1e1e1e1e1e);
pll(0x3f803f80);
pll(0x01ff01ff01ff01ff);
pll(0x007fffc0);
pll(0x03fff80003fff800);
pll(0x0007fffffffffe00);
pll(0xabcd1234);
pll(0xabcd00001234);
pll(0xabcd000000001234);
pll(0xabcd12340000);
pll(0xabcd000012340000);
pll(0xabcd123400000000);
pll(0xffffffffabcd1234);
pll(0xffffabcdffff1234);
pll(0xabcdffffffff1234);
pll(0xffffabcd1234ffff);
pll(0xabcdffff1234ffff);
pll(0xabcd1234ffffffff);
pll(0xffffef0123456789);
pll(0xabcdef012345ffff);
pll(0xabcdef0123456789);
}
void pcs(void)
{
arg();
ret();
stdarg();
movi();
}
int main()
{
pcs();
return 0;
}
|