Add 73_arm64 for testing some arm64 things, mostly PCS.

This commit is contained in:
Edmund Grimley Evans 2015-02-25 22:48:25 +00:00
parent a4d43618fb
commit 8329facdfa
3 changed files with 529 additions and 0 deletions

405
tests/tests2/73_arm64.c Normal file
View File

@ -0,0 +1,405 @@
// 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)
{
printf("Return values:\n");
printf("%.1s\n", &fr_s1().x[0]);
printf("%.2s\n", &fr_s2().x[0]);
printf("%.3s\n", &fr_s3().x[0]);
printf("%.4s\n", &fr_s4().x[0]);
printf("%.5s\n", &fr_s5().x[0]);
printf("%.6s\n", &fr_s6().x[0]);
printf("%.7s\n", &fr_s7().x[0]);
printf("%.8s\n", &fr_s8().x[0]);
printf("%.9s\n", &fr_s9().x[0]);
printf("%.10s\n", &fr_s10().x[0]);
printf("%.11s\n", &fr_s11().x[0]);
printf("%.12s\n", &fr_s12().x[0]);
printf("%.13s\n", &fr_s13().x[0]);
printf("%.14s\n", &fr_s14().x[0]);
printf("%.15s\n", &fr_s15().x[0]);
printf("%.16s\n", &fr_s16().x[0]);
printf("%.17s\n", &fr_s17().x[0]);
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"))
printf("%.7s", &va_arg(ap, struct s7).x[0]);
else if (match(&s, "%9s"))
printf("%.9s", &va_arg(ap, struct s9).x[0]);
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);
}
void pcs(void)
{
arg();
ret();
stdarg();
movi();
}
int main()
{
pcs();
return 0;
}

View File

@ -0,0 +1,123 @@
Arguments:
0
12
345
6789
abcde
fghijk
lmnopqr
stuvwxyz
ABCDEFGHI
JKLMNOPQRS
TUVWXYZ0123
456789abcdef
ghijklmnopqrs
tuvwxyzABCDEFG
HIJKLMNOPQRSTUV
WXYZ0123456789ab
cdefghijklmnopqrs
11.1
12.1 12.1
13.1 13.2 13.3
14.1 14.2 14.3 14.4
21.1
22.1 22.1
23.1 23.2 23.3
24.1 24.2 24.3 24.4
31.1
32.1 32.1
33.1 33.2 33.3
34.1 34.2 34.3 34.4
stu ABC JKL TUV 456 ghi
ABC JKL TUV 456 ghi tuv
14.1 14.4 23.1 23.3 32.1 32.2
0 14.1 14.4 12 24.1 24.4 345 34.1 34.4
Return values:
0
12
345
6789
abcde
fghijk
lmnopqr
stuvwxyz
ABCDEFGHI
JKLMNOPQRS
TUVWXYZ0123
456789abcdef
ghijklmnopqrs
tuvwxyzABCDEFG
HIJKLMNOPQRSTUV
WXYZ0123456789ab
cdefghijklmnopqrs
11.1
12.1 12.2
13.1 13.3
14.1 14.4
21.1
22.1 22.2
23.1 23.3
24.1 24.4
31.1
32.1 32.2
33.1 33.3
34.1 34.4
stdarg:
ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI
lmnopqr ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI ABCDEFGHI
HFA long double:
34.1,34.4 34.1,34.4 34.1,34.4 34.1,34.4
33.1,33.3 34.1,34.4 34.1,34.4 34.1,34.4
32.1,32.2 34.1,34.4 34.1,34.4 34.1,34.4
31.1,31.1 34.1,34.4 34.1,34.4 34.1,34.4
32.1,32.2 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3
31.1,31.1 33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3
33.1,33.3 33.1,33.3 33.1,33.3 33.1,33.3
34.1,34.4 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2
33.1,33.3 32.1,32.2 32.1,32.2 32.1,32.2 32.1,32.2
34.1,34.4 32.1,32.2 31.1,31.1 31.1,31.1 31.1,31.1 31.1,31.1
HFA double:
24.1,24.4 24.1,24.4 24.1,24.4 24.1,24.4
23.1,23.3 24.1,24.4 24.1,24.4 24.1,24.4
22.1,22.2 24.1,24.4 24.1,24.4 24.1,24.4
21.1,21.1 24.1,24.4 24.1,24.4 24.1,24.4
22.1,22.2 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3
21.1,21.1 23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3
23.1,23.3 23.1,23.3 23.1,23.3 23.1,23.3
24.1,24.4 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2
23.1,23.3 22.1,22.2 22.1,22.2 22.1,22.2 22.1,22.2
24.1,24.4 22.1,22.2 21.1,21.1 21.1,21.1 21.1,21.1 21.1,21.1
HFA float:
14.1,14.4 14.1,14.4 14.1,14.4 14.1,14.4
13.1,13.3 14.1,14.4 14.1,14.4 14.1,14.4
12.1,12.2 14.1,14.4 14.1,14.4 14.1,14.4
11.1,11.1 14.1,14.4 14.1,14.4 14.1,14.4
12.1,12.2 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3
11.1,11.1 13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3
13.1,13.3 13.1,13.3 13.1,13.3 13.1,13.3
14.1,14.4 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2
13.1,13.3 12.1,12.2 12.1,12.2 12.1,12.2 12.1,12.2
14.1,14.4 12.1,12.2 11.1,11.1 11.1,11.1 11.1,11.1 11.1,11.1
MOVI:
0
abcd
abcd0000
abcd00000000
abcd000000000000
ffffabcd
abcdffff
ffffffffffffabcd
ffffffffabcdffff
ffffabcdffffffff
abcdffffffffffff
aaaaaaaa
5555555555555555
77777777
3333333333333333
f8f8f8f8
1e1e1e1e1e1e1e1e
3f803f80
1ff01ff01ff01ff
7fffc0
3fff80003fff800
7fffffffffe00

View File

@ -92,6 +92,7 @@ TESTS = \
70_floating_point_literals.test \
71_macro_empty_arg.test \
72_long_long_constant.test \
73_arm64.test \
# 34_array_assignment.test -- array assignment is not in C standard