abi8.ssa 7.8 KB

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