History

new abi stress test

Quentin Carbonneaux committed 4 years ago

Commit 7f7e34c1 parent 90609812 files · +367 −0Browse files

Unified · Split

2 files
  1. test/abi8.ssa +257 −0
  2. tools/abi8.py +110 −0
test/abi8.ssa+257−0
@@ -0,0 +1,257 @@
1# riscv64 ABI stress
2# see tools/abi8.py
3
4type :fi1 = { h, s } # in a gp & fp pair
5type :fi2 = { s, w } # ditto
6type :uw = { { w } }
7type :fi3 = { s, :uw } # in a single gp reg
8type :ss = { s, s } # in two fp regs
9type :sd = { s, d } # ditto
10type :ww = { w, w } # in a single gp reg
11type :lb = { l, b } # in two gp regs
12type :big = { b 17 } # by reference
13
14data $ctoqbestr = { b "c->qbe(%d)", b 0 }
15data $emptystr = { b 0 }
16
17export
18function $qfn0(s %p0, s %p1, s %p2, s %p3, s %p4, s %p5, s %p6, s %p7, s %p8) {
19@start
20 %r0 =w call $printf(l $ctoqbestr, w 0)
21 call $ps(s %p8)
22 %r1 =w call $puts(l $emptystr)
23 ret
24}
25export
26function $qfn1(w %p0, s %p1, :fi1 %p2) {
27@start
28 %r0 =w call $printf(l $ctoqbestr, w 1)
29 call $pw(w %p0)
30 call $ps(s %p1)
31 call $pfi1(l %p2)
32 %r1 =w call $puts(l $emptystr)
33 ret
34}
35export
36function $qfn2(w %p0, :fi2 %p1, s %p2) {
37@start
38 %r0 =w call $printf(l $ctoqbestr, w 2)
39 call $pw(w %p0)
40 call $pfi2(l %p1)
41 call $ps(s %p2)
42 %r1 =w call $puts(l $emptystr)
43 ret
44}
45export
46function $qfn3(w %p0, s %p1, :fi3 %p2) {
47@start
48 %r0 =w call $printf(l $ctoqbestr, w 3)
49 call $pw(w %p0)
50 call $ps(s %p1)
51 call $pfi3(l %p2)
52 %r1 =w call $puts(l $emptystr)
53 ret
54}
55export
56function $qfn4(:ss %p0) {
57@start
58 %r0 =w call $printf(l $ctoqbestr, w 4)
59 call $pss(l %p0)
60 %r1 =w call $puts(l $emptystr)
61 ret
62}
63export
64function $qfn5(d %p0, d %p1, d %p2, d %p3, d %p4, d %p5, d %p6, :ss %p7, s %p8, l %p9) {
65@start
66 %r0 =w call $printf(l $ctoqbestr, w 5)
67 call $pss(l %p7)
68 call $ps(s %p8)
69 call $pl(l %p9)
70 %r1 =w call $puts(l $emptystr)
71 ret
72}
73export
74function $qfn6(:lb %p0) {
75@start
76 %r0 =w call $printf(l $ctoqbestr, w 6)
77 call $plb(l %p0)
78 %r1 =w call $puts(l $emptystr)
79 ret
80}
81export
82function $qfn7(w %p0, w %p1, w %p2, w %p3, w %p4, w %p5, w %p6, :lb %p7) {
83@start
84 %r0 =w call $printf(l $ctoqbestr, w 7)
85 call $plb(l %p7)
86 %r1 =w call $puts(l $emptystr)
87 ret
88}
89export
90function $qfn8(w %p0, w %p1, w %p2, w %p3, w %p4, w %p5, w %p6, w %p7, :lb %p8) {
91@start
92 %r0 =w call $printf(l $ctoqbestr, w 8)
93 call $plb(l %p8)
94 %r1 =w call $puts(l $emptystr)
95 ret
96}
97export
98function $qfn9(:big %p0) {
99@start
100 %r0 =w call $printf(l $ctoqbestr, w 9)
101 call $pbig(l %p0)
102 %r1 =w call $puts(l $emptystr)
103 ret
104}
105export
106function $qfn10(w %p0, w %p1, w %p2, w %p3, w %p4, w %p5, w %p6, w %p7, :big %p8, s %p9, l %p10) {
107@start
108 %r0 =w call $printf(l $ctoqbestr, w 10)
109 call $pbig(l %p8)
110 call $ps(s %p9)
111 call $pl(l %p10)
112 %r1 =w call $puts(l $emptystr)
113 ret
114}
115
116export
117function w $main() {
118@start
119
120 call $cfn0(s 0, s 0, s 0, s 0, s 0, s 0, s 0, s 0, s s_9.9)
121 call $cfn1(w 1, s s_2.2, :fi1 $fi1)
122 call $cfn2(w 1, :fi2 $fi2, s s_3.3)
123 call $cfn3(w 1, s s_2.2, :fi3 $fi3)
124 call $cfn4(:ss $ss)
125 call $cfn5(d 0, d 0, d 0, d 0, d 0, d 0, d 0, :ss $ss, s s_9.9, l 10)
126 call $cfn6(:lb $lb)
127 call $cfn7(w 0, w 0, w 0, w 0, w 0, w 0, w 0, :lb $lb)
128 call $cfn8(w 0, w 0, w 0, w 0, w 0, w 0, w 0, w 0, :lb $lb)
129 call $cfn9(:big $big)
130 call $cfn10(w 0, w 0, w 0, w 0, w 0, w 0, w 0, w 0, :big $big, s s_10.10, l 11)
131
132 ret 0
133}
134
135# >>> driver
136# #include <stdio.h>
137# typedef struct { short h; float s; } Sfi1;
138# typedef struct { float s; int w; } Sfi2;
139# typedef struct { float s; union { int w; } u; } Sfi3;
140# typedef struct { float s0, s1; } Sss;
141# typedef struct { float s; double d; } Ssd;
142# typedef struct { int w0, w1; } Sww;
143# typedef struct { long l; char b; } Slb;
144# typedef struct { char b[17]; } Sbig;
145# Sfi1 zfi1, fi1 = { -123, 4.56 };
146# Sfi2 zfi2, fi2 = { 1.23, 456 };
147# Sfi3 zfi3, fi3 = { 3.45, 567 };
148# Sss zss, ss = { 1.23, 45.6 };
149# Ssd zsd, sd = { 2.34, 5.67 };
150# Sww zww, ww = { -123, -456 };
151# Slb zlb, lb = { 123, 'z' };
152# Sbig zbig, big = { "abcdefhijklmnopqr" };
153# void pfi1(Sfi1 *s) { printf(" { %d, %g }", s->h, s->s); }
154# void pfi2(Sfi2 *s) { printf(" { %g, %d }", s->s, s->w); }
155# void pfi3(Sfi3 *s) { printf(" { %g, %d }", s->s, s->u.w); }
156# void pss(Sss *s) { printf(" { %g, %g }", s->s0, s->s1); }
157# void psd(Ssd *s) { printf(" { %g, %g }", s->s, s->d); }
158# void pww(Sww *s) { printf(" { %d, %d }", s->w0, s->w1); }
159# void plb(Slb *s) { printf(" { %ld, '%c' }", s->l, s->b); }
160# void pbig(Sbig *s) { printf(" \"%.17s\"", s->b); }
161# void pw(int w) { printf(" %d", w); }
162# void pl(long l) { printf(" %ld", l); }
163# void ps(float s) { printf(" %g", s); }
164# void pd(double d) { printf(" %g", d); }
165# /* --------------------------- */
166# extern void qfn0(float, float, float, float, float, float, float, float, float);
167# void cfn0(float p0, float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8) {
168# printf("qbe->c(%d)", 0);
169# ps(p8); puts("");
170# qfn0(p0, p1, p2, p3, p4, p5, p6, p7, p8);
171# }
172# extern void qfn1(int, float, Sfi1);
173# void cfn1(int p0, float p1, Sfi1 p2) {
174# printf("qbe->c(%d)", 1);
175# pw(p0); ps(p1); pfi1(&p2); puts("");
176# qfn1(p0, p1, p2);
177# }
178# extern void qfn2(int, Sfi2, float);
179# void cfn2(int p0, Sfi2 p1, float p2) {
180# printf("qbe->c(%d)", 2);
181# pw(p0); pfi2(&p1); ps(p2); puts("");
182# qfn2(p0, p1, p2);
183# }
184# extern void qfn3(int, float, Sfi3);
185# void cfn3(int p0, float p1, Sfi3 p2) {
186# printf("qbe->c(%d)", 3);
187# pw(p0); ps(p1); pfi3(&p2); puts("");
188# qfn3(p0, p1, p2);
189# }
190# extern void qfn4(Sss);
191# void cfn4(Sss p0) {
192# printf("qbe->c(%d)", 4);
193# pss(&p0); puts("");
194# qfn4(p0);
195# }
196# extern void qfn5(double, double, double, double, double, double, double, Sss, float, long);
197# void cfn5(double p0, double p1, double p2, double p3, double p4, double p5, double p6, Sss p7, float p8, long p9) {
198# printf("qbe->c(%d)", 5);
199# pss(&p7); ps(p8); pl(p9); puts("");
200# qfn5(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
201# }
202# extern void qfn6(Slb);
203# void cfn6(Slb p0) {
204# printf("qbe->c(%d)", 6);
205# plb(&p0); puts("");
206# qfn6(p0);
207# }
208# extern void qfn7(int, int, int, int, int, int, int, Slb);
209# void cfn7(int p0, int p1, int p2, int p3, int p4, int p5, int p6, Slb p7) {
210# printf("qbe->c(%d)", 7);
211# plb(&p7); puts("");
212# qfn7(p0, p1, p2, p3, p4, p5, p6, p7);
213# }
214# extern void qfn8(int, int, int, int, int, int, int, int, Slb);
215# void cfn8(int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7, Slb p8) {
216# printf("qbe->c(%d)", 8);
217# plb(&p8); puts("");
218# qfn8(p0, p1, p2, p3, p4, p5, p6, p7, p8);
219# }
220# extern void qfn9(Sbig);
221# void cfn9(Sbig p0) {
222# printf("qbe->c(%d)", 9);
223# pbig(&p0); puts("");
224# qfn9(p0);
225# }
226# extern void qfn10(int, int, int, int, int, int, int, int, Sbig, float, long);
227# void cfn10(int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7, Sbig p8, float p9, long p10) {
228# printf("qbe->c(%d)", 10);
229# pbig(&p8); ps(p9); pl(p10); puts("");
230# qfn10(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
231# }
232# <<<
233
234# >>> output
235# qbe->c(0) 9.9
236# c->qbe(0) 9.9
237# qbe->c(1) 1 2.2 { -123, 4.56 }
238# c->qbe(1) 1 2.2 { -123, 4.56 }
239# qbe->c(2) 1 { 1.23, 456 } 3.3
240# c->qbe(2) 1 { 1.23, 456 } 3.3
241# qbe->c(3) 1 2.2 { 3.45, 567 }
242# c->qbe(3) 1 2.2 { 3.45, 567 }
243# qbe->c(4) { 1.23, 45.6 }
244# c->qbe(4) { 1.23, 45.6 }
245# qbe->c(5) { 1.23, 45.6 } 9.9 10
246# c->qbe(5) { 1.23, 45.6 } 9.9 10
247# qbe->c(6) { 123, 'z' }
248# c->qbe(6) { 123, 'z' }
249# qbe->c(7) { 123, 'z' }
250# c->qbe(7) { 123, 'z' }
251# qbe->c(8) { 123, 'z' }
252# c->qbe(8) { 123, 'z' }
253# qbe->c(9) "abcdefhijklmnopqr"
254# c->qbe(9) "abcdefhijklmnopqr"
255# qbe->c(10) "abcdefhijklmnopqr" 10.1 11
256# c->qbe(10) "abcdefhijklmnopqr" 10.1 11
257# <<<
tools/abi8.py+110−0
@@ -0,0 +1,110 @@
1#!/usr/bin/python3
2
3# support script to create
4# the abi8.ssa test
5
6def ctype(arg):
7 if arg[0] == 'p': return ctype(arg[1:])
8 if arg[0] == ':': return 'S' + arg[1:]
9 return {'w':'int', 'l':'long',
10 's':'float', 'd':'double'}[arg]
11
12def cparam(iarg):
13 return ctype(iarg[1]) + ' p' + str(iarg[0])
14
15def gencfn(id, args):
16 out = '# extern void qfn' + id + '('
17 out += ', '.join(map(ctype, args)) + ');\n'
18 out += '# void cfn' + id + '('
19 out += ', '.join(map(cparam, enumerate(args)))
20 out += ') {\n'
21 out += '# \tprintf("qbe->c(%d)", ' + id + ');\n'
22 out += '# \t'
23 for (i, arg) in enumerate(args):
24 if arg[0] != 'p': continue
25 ty = arg[1:]
26 if ty[0] == ':':
27 out += 'p' + ty[1:] + '(&'
28 else:
29 out += 'p' + ty + '('
30 out += 'p' + str(i) + '); '
31 out += 'puts("");\n'
32 out += '# \tqfn' + id + '('
33 out += ', '.join('p'+str(i) for i in range(len(args)))
34 out += ');\n'
35 out += '# }\n'
36 return out
37
38def qparam(iarg):
39 ty = iarg[1][1:] if iarg[1][0] == 'p' else iarg[1]
40 return ty + ' %p' + str(iarg[0])
41
42def genqfn(id, args):
43 out = 'export\nfunction $qfn' + id + '('
44 out += ', '.join(map(qparam, enumerate(args)))
45 out += ') {\n'
46 out += '@start\n'
47 out += '\t%r0 =w call $printf(l $ctoqbestr, w ' + id + ')\n'
48 for (i, arg) in enumerate(args):
49 if arg[0] != 'p': continue
50 ty = arg[1:]
51 if ty[0] == ':':
52 out += '\tcall $p' + ty[1:]
53 out += '(l %p' + str(i) + ')\n'
54 else:
55 out += '\tcall $p' + ty
56 out += '(' + ty + ' %p' + str(i) + ')\n'
57 out += '\t%r1 =w call $puts(l $emptystr)\n'
58 out += '\tret\n'
59 out += '}\n'
60 return out
61
62def carg(iarg):
63 i, arg = iarg
64 print = arg[0] == 'p'
65 ty = arg if not print else arg[1:]
66 if ty[0] == ':':
67 if print:
68 return ty + ' $' + ty[1:]
69 else:
70 return ty + ' $z' + ty[1:]
71 if not print:
72 return ty + ' 0'
73 if ty == 'w' or ty == 'l':
74 return ty + ' ' + str(i+1)
75 if ty == 's' or ty == 'd':
76 flt = str(i+1) + '.' + str(i+1)
77 return ty + ' ' + ty + '_' + flt
78
79def genmaincall(id, args):
80 out = '\tcall $cfn' + id + '('
81 out += ', '.join(map(carg, enumerate(args)))
82 out += ')\n'
83 return out
84
85def gen(tvec):
86 for i, t in enumerate(tvec):
87 print(genqfn(str(i), t), end='')
88 print('')
89 for i, t in enumerate(tvec):
90 print(genmaincall(str(i), t), end='')
91 print('')
92 for i, t in enumerate(tvec):
93 print(gencfn(str(i), t), end='')
94
95TVEC = [
96 ['s']*8 + ['ps'],
97 ['pw', 'ps', 'p:fi1'],
98 ['pw', 'p:fi2', 'ps'],
99 ['pw', 'ps', 'p:fi3'],
100 ['p:ss'],
101 ['d']*7 + ['p:ss', 'ps', 'pl'],
102 ['p:lb'],
103 ['w']*7 + ['p:lb'],
104 ['w']*8 + ['p:lb'],
105 [ 'p:big' ],
106 ['w']*8 + ['p:big', 'ps', 'pl'],
107]
108
109if __name__ == '__main__':
110 gen(TVEC)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t