testcases.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Copyright 1993 Bill Triggs <Bill.Triggs@inrialpes.fr>
  3. * Copyright 1995-2017 Bruno Haible <bruno@clisp.org>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* This file defines test functions of selected signatures, that exercise
  19. dark corners of the various ABIs. */
  20. #include <stdio.h>
  21. FILE* out;
  22. #define uchar unsigned char
  23. #define ushort unsigned short
  24. #define uint unsigned int
  25. #define ulong unsigned long
  26. typedef struct { char x; } Char;
  27. typedef struct { short x; } Short;
  28. typedef struct { int x; } Int;
  29. typedef struct { long x; } Long;
  30. typedef struct { float x; } Float;
  31. typedef struct { double x; } Double;
  32. typedef struct { char c; float f; } A;
  33. typedef struct { double d; int i[3]; } B;
  34. typedef struct { long l1; long l2; } J;
  35. typedef struct { long l1; long l2; long l3; long l4; } K;
  36. typedef struct { long l1; long l2; long l3; long l4; long l5; long l6; } L;
  37. typedef struct { char x1; } Size1;
  38. typedef struct { char x1; char x2; } Size2;
  39. typedef struct { char x1; char x2; char x3; } Size3;
  40. typedef struct { char x1; char x2; char x3; char x4; } Size4;
  41. typedef struct {
  42. char x1; char x2; char x3; char x4; char x5; char x6; char x7;
  43. } Size7;
  44. typedef struct {
  45. char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8;
  46. } Size8;
  47. typedef struct {
  48. char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8;
  49. char x9; char x10; char x11; char x12;
  50. } Size12;
  51. typedef struct {
  52. char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8;
  53. char x9; char x10; char x11; char x12; char x13; char x14; char x15;
  54. } Size15;
  55. typedef struct {
  56. char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8;
  57. char x9; char x10; char x11; char x12; char x13; char x14; char x15; char x16;
  58. } Size16;
  59. typedef struct { char c[3]; } T;
  60. typedef struct { char c[33],c1; } X;
  61. char c1='a', c2=127, c3=(char)128, c4=(char)255, c5=-1;
  62. short s1=32767, s2=(short)32768, s3=3, s4=4, s5=5, s6=6, s7=7, s8=8, s9=9;
  63. int i1=1, i2=2, i3=3, i4=4, i5=5, i6=6, i7=7, i8=8, i9=9,
  64. i10=11, i11=12, i12=13, i13=14, i14=15, i15=16, i16=17;
  65. long l1=1, l2=2, l3=3, l4=4, l5=5, l6=6, l7=7, l8=8, l9=9;
  66. long long ll1 = 3875056143130689530LL;
  67. float f1=0.1f, f2=0.2f, f3=0.3f, f4=0.4f, f5=0.5f, f6=0.6f, f7=0.7f, f8=0.8f, f9=0.9f,
  68. f10=1.1f, f11=1.2f, f12=1.3f, f13=1.4f, f14=1.5f, f15=1.6f, f16=1.7f, f17=1.8f,
  69. f18=1.9f, f19=2.1f, f20=2.2f, f21=2.3f, f22=2.4f, f23=2.5f, f24=2.6f;
  70. double d1=0.1, d2=0.2, d3=0.3, d4=0.4, d5=0.5, d6=0.6, d7=0.7, d8=0.8, d9=0.9,
  71. d10=1.1, d11=1.2, d12=1.3, d13=1.4, d14=1.5, d15=1.6, d16=1.7, d17=1.8;
  72. uchar uc1='a', uc2=127, uc3=128, uc4=255, uc5=(uchar)-1;
  73. ushort us1=1, us2=2, us3=3, us4=4, us5=5, us6=6, us7=7, us8=8, us9=9;
  74. uint ui1=1, ui2=2, ui3=3, ui4=4, ui5=5, ui6=6, ui7=7, ui8=8, ui9=9;
  75. ulong ul1=1, ul2=2, ul3=3, ul4=4, ul5=5, ul6=6, ul7=7, ul8=8, ul9=9;
  76. char *str1="hello",str2[]="goodbye",*str3="still here?";
  77. Char C1={'A'}, C2={'B'}, C3={'C'}, C4={'\377'}, C5={(char)(-1)};
  78. Short S1={1}, S2={2}, S3={3}, S4={4}, S5={5}, S6={6}, S7={7}, S8={8}, S9={9};
  79. Int I1={1}, I2={2}, I3={3}, I4={4}, I5={5}, I6={6}, I7={7}, I8={8}, I9={9};
  80. Float F1={0.1f}, F2={0.2f}, F3={0.3f}, F4={0.4f}, F5={0.5f}, F6={0.6f}, F7={0.7f}, F8={0.8f}, F9={0.9f};
  81. Double D1={0.1}, D2={0.2}, D3={0.3}, D4={0.4}, D5={0.5}, D6={0.6}, D7={0.7}, D8={0.8}, D9={0.9};
  82. A A1={'a',0.1f},A2={'b',0.2f},A3={'\377',0.3f};
  83. B B1={0.1,{1,2,3}},B2={0.2,{5,4,3}};
  84. J J1={47,11},J2={73,55};
  85. K K1={19,69,12,28};
  86. L L1={561,1105,1729,2465,2821,6601}; /* A002997 */
  87. Size1 Size1_1={'a'};
  88. Size2 Size2_1={'a','b'};
  89. Size3 Size3_1={'a','b','c'};
  90. Size4 Size4_1={'a','b','c','d'};
  91. Size7 Size7_1={'a','b','c','d','e','f','g'};
  92. Size8 Size8_1={'a','b','c','d','e','f','g','h'};
  93. Size12 Size12_1={'a','b','c','d','e','f','g','h','i','j','k','l'};
  94. Size15 Size15_1={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'};
  95. Size16 Size16_1={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
  96. T T1={{'t','h','e'}},T2={{'f','o','x'}};
  97. X X1={"abcdefghijklmnopqrstuvwxyzABCDEF",'G'}, X2={"123",'9'}, X3={"return-return-return",'R'};
  98. #if defined(__GNUC__)
  99. #define __STDCALL__ __attribute__((stdcall))
  100. #define __THISCALL__ __attribute__((thiscall))
  101. #define __FASTCALL__ __attribute__((fastcall))
  102. #define __MSABI__ __attribute__((ms_abi))
  103. #else
  104. #define __STDCALL__ __stdcall
  105. #define __THISCALL__ __thiscall
  106. #define __FASTCALL__ __fastcall
  107. #endif
  108. #ifndef ABI_ATTR
  109. #define ABI_ATTR
  110. #endif
  111. /* void tests */
  112. void ABI_ATTR v_v (void)
  113. {
  114. fprintf(out,"void f(void):\n");
  115. fflush(out);
  116. }
  117. /* int tests */
  118. int ABI_ATTR i_v (void)
  119. {
  120. int r=99;
  121. fprintf(out,"int f(void):");
  122. fflush(out);
  123. return r;
  124. }
  125. int ABI_ATTR i_i (int a)
  126. {
  127. int r=a+1;
  128. fprintf(out,"int f(int):(%d)",a);
  129. fflush(out);
  130. return r;
  131. }
  132. int ABI_ATTR i_i2 (int a, int b)
  133. {
  134. int r=a+b;
  135. fprintf(out,"int f(2*int):(%d,%d)",a,b);
  136. fflush(out);
  137. return r;
  138. }
  139. int ABI_ATTR i_i4 (int a, int b, int c, int d)
  140. {
  141. int r=a+b+c+d;
  142. fprintf(out,"int f(4*int):(%d,%d,%d,%d)",a,b,c,d);
  143. fflush(out);
  144. return r;
  145. }
  146. int ABI_ATTR i_i8 (int a, int b, int c, int d, int e, int f, int g, int h)
  147. {
  148. int r=a+b+c+d+e+f+g+h;
  149. fprintf(out,"int f(8*int):(%d,%d,%d,%d,%d,%d,%d,%d)",a,b,c,d,e,f,g,h);
  150. fflush(out);
  151. return r;
  152. }
  153. int ABI_ATTR i_i16 (int a, int b, int c, int d, int e, int f, int g, int h,
  154. int i, int j, int k, int l, int m, int n, int o, int p)
  155. {
  156. int r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  157. fprintf(out,"int f(16*int):(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
  158. a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  159. fflush(out);
  160. return r;
  161. }
  162. /* float tests */
  163. float ABI_ATTR f_f (float a)
  164. {
  165. float r=a+1.0f;
  166. fprintf(out,"float f(float):(%g)",a);
  167. fflush(out);
  168. return r;
  169. }
  170. float ABI_ATTR f_f2 (float a, float b)
  171. {
  172. float r=a+b;
  173. fprintf(out,"float f(2*float):(%g,%g)",a,b);
  174. fflush(out);
  175. return r;
  176. }
  177. float ABI_ATTR f_f4 (float a, float b, float c, float d)
  178. {
  179. float r=a+b+c+d;
  180. fprintf(out,"float f(4*float):(%g,%g,%g,%g)",a,b,c,d);
  181. fflush(out);
  182. return r;
  183. }
  184. float ABI_ATTR f_f8 (float a, float b, float c, float d, float e, float f,
  185. float g, float h)
  186. {
  187. float r=a+b+c+d+e+f+g+h;
  188. fprintf(out,"float f(8*float):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  189. fflush(out);
  190. return r;
  191. }
  192. float ABI_ATTR f_f16 (float a, float b, float c, float d, float e, float f, float g, float h,
  193. float i, float j, float k, float l, float m, float n, float o, float p)
  194. {
  195. float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  196. fprintf(out,"float f(16*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  197. fflush(out);
  198. return r;
  199. }
  200. float ABI_ATTR f_f24 (float a, float b, float c, float d, float e, float f, float g, float h,
  201. float i, float j, float k, float l, float m, float n, float o, float p,
  202. float q, float s, float t, float u, float v, float w, float x, float y)
  203. {
  204. float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+v+w+x+y;
  205. fprintf(out,"float f(24*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,v,w,x,y);
  206. fflush(out);
  207. return r;
  208. }
  209. /* double tests */
  210. double ABI_ATTR d_d (double a)
  211. {
  212. double r=a+1.0;
  213. fprintf(out,"double f(double):(%g)",a);
  214. fflush(out);
  215. return r;
  216. }
  217. double ABI_ATTR d_d2 (double a, double b)
  218. {
  219. double r=a+b;
  220. fprintf(out,"double f(2*double):(%g,%g)",a,b);
  221. fflush(out);
  222. return r;
  223. }
  224. double ABI_ATTR d_d4 (double a, double b, double c, double d)
  225. {
  226. double r=a+b+c+d;
  227. fprintf(out,"double f(4*double):(%g,%g,%g,%g)",a,b,c,d);
  228. fflush(out);
  229. return r;
  230. }
  231. double ABI_ATTR d_d8 (double a, double b, double c, double d, double e, double f,
  232. double g, double h)
  233. {
  234. double r=a+b+c+d+e+f+g+h;
  235. fprintf(out,"double f(8*double):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  236. fflush(out);
  237. return r;
  238. }
  239. double ABI_ATTR d_d16 (double a, double b, double c, double d, double e, double f,
  240. double g, double h, double i, double j, double k, double l,
  241. double m, double n, double o, double p)
  242. {
  243. double r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  244. fprintf(out,"double f(16*double):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  245. fflush(out);
  246. return r;
  247. }
  248. /* pointer tests */
  249. void* ABI_ATTR vp_vpdpcpsp (void* a, double* b, char* c, Int* d)
  250. {
  251. void* ret = (char*)b + 1;
  252. fprintf(out,"void* f(void*,double*,char*,Int*):(0x%p,0x%p,0x%p,0x%p)",a,b,c,d);
  253. fflush(out);
  254. return ret;
  255. }
  256. /* mixed number tests */
  257. uchar ABI_ATTR uc_ucsil (uchar a, ushort b, uint c, ulong d)
  258. {
  259. uchar r = (uchar)-1;
  260. fprintf(out,"uchar f(uchar,ushort,uint,ulong):(%u,%u,%u,%lu)",a,b,c,d);
  261. fflush(out);
  262. return r;
  263. }
  264. double ABI_ATTR d_iidd (int a, int b, double c, double d)
  265. {
  266. double r = a+b+c+d;
  267. fprintf(out,"double f(int,int,double,double):(%d,%d,%g,%g)",a,b,c,d);
  268. fflush(out);
  269. return r;
  270. }
  271. double ABI_ATTR d_iiidi (int a, int b, int c, double d, int e)
  272. {
  273. double r = a+b+c+d+e;
  274. fprintf(out,"double f(int,int,int,double,int):(%d,%d,%d,%g,%d)",a,b,c,d,e);
  275. fflush(out);
  276. return r;
  277. }
  278. double ABI_ATTR d_idid (int a, double b, int c, double d)
  279. {
  280. double r = a+b+c+d;
  281. fprintf(out,"double f(int,double,int,double):(%d,%g,%d,%g)",a,b,c,d);
  282. fflush(out);
  283. return r;
  284. }
  285. double ABI_ATTR d_fdi (float a, double b, int c)
  286. {
  287. double r = a+b+c;
  288. fprintf(out,"double f(float,double,int):(%g,%g,%d)",a,b,c);
  289. fflush(out);
  290. return r;
  291. }
  292. ushort ABI_ATTR us_cdcd (char a, double b, char c, double d)
  293. {
  294. ushort r = (ushort)(a + b + c + d);
  295. fprintf(out,"ushort f(char,double,char,double):('%c',%g,'%c',%g)",a,b,c,d);
  296. fflush(out);
  297. return r;
  298. }
  299. long long ABI_ATTR ll_iiilli (int a, int b, int c, long long d, int e)
  300. {
  301. long long r = (long long)(int)a+(long long)(int)b+(long long)(int)c+d+(long long)(int)e;
  302. fprintf(out,"long long f(int,int,int,long long,int):(%d,%d,%d,0x%lx%08lx,%d)",a,b,c,(long)(d>>32),(long)(d&0xffffffff),e);
  303. fflush(out);
  304. return r;
  305. }
  306. long long ABI_ATTR ll_flli (float a, long long b, int c)
  307. {
  308. long long r = (long long)(int)a + b + (long long)c;
  309. fprintf(out,"long long f(float,long long,int):(%g,0x%lx%08lx,0x%lx)",a,(long)(b>>32),(long)(b&0xffffffff),(long)c);
  310. fflush(out);
  311. return r;
  312. }
  313. float ABI_ATTR f_fi (float a, int z)
  314. {
  315. float r = a+z;
  316. fprintf(out,"float f(float,int):(%g,%d)",a,z);
  317. fflush(out);
  318. return r;
  319. }
  320. float ABI_ATTR f_f2i (float a, float b, int z)
  321. {
  322. float r = a+b+z;
  323. fprintf(out,"float f(2*float,int):(%g,%g,%d)",a,b,z);
  324. fflush(out);
  325. return r;
  326. }
  327. float ABI_ATTR f_f3i (float a, float b, float c, int z)
  328. {
  329. float r = a+b+c+z;
  330. fprintf(out,"float f(3*float,int):(%g,%g,%g,%d)",a,b,c,z);
  331. fflush(out);
  332. return r;
  333. }
  334. float ABI_ATTR f_f4i (float a, float b, float c, float d, int z)
  335. {
  336. float r = a+b+c+d+z;
  337. fprintf(out,"float f(4*float,int):(%g,%g,%g,%g,%d)",a,b,c,d,z);
  338. fflush(out);
  339. return r;
  340. }
  341. float ABI_ATTR f_f7i (float a, float b, float c, float d, float e, float f, float g,
  342. int z)
  343. {
  344. float r = a+b+c+d+e+f+g+z;
  345. fprintf(out,"float f(7*float,int):(%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,z);
  346. fflush(out);
  347. return r;
  348. }
  349. float ABI_ATTR f_f8i (float a, float b, float c, float d, float e, float f, float g,
  350. float h, int z)
  351. {
  352. float r = a+b+c+d+e+f+g+h+z;
  353. fprintf(out,"float f(8*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,z);
  354. fflush(out);
  355. return r;
  356. }
  357. float ABI_ATTR f_f12i (float a, float b, float c, float d, float e, float f, float g,
  358. float h, float i, float j, float k, float l, int z)
  359. {
  360. float r = a+b+c+d+e+f+g+h+i+j+k+l+z;
  361. fprintf(out,"float f(12*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,z);
  362. fflush(out);
  363. return r;
  364. }
  365. float ABI_ATTR f_f13i (float a, float b, float c, float d, float e, float f, float g,
  366. float h, float i, float j, float k, float l, float m, int z)
  367. {
  368. float r = a+b+c+d+e+f+g+h+i+j+k+l+m+z;
  369. fprintf(out,"float f(13*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,m,z);
  370. fflush(out);
  371. return r;
  372. }
  373. double ABI_ATTR d_di (double a, int z)
  374. {
  375. double r = a+z;
  376. fprintf(out,"double f(double,int):(%g,%d)",a,z);
  377. fflush(out);
  378. return r;
  379. }
  380. double ABI_ATTR d_d2i (double a, double b, int z)
  381. {
  382. double r = a+b+z;
  383. fprintf(out,"double f(2*double,int):(%g,%g,%d)",a,b,z);
  384. fflush(out);
  385. return r;
  386. }
  387. double ABI_ATTR d_d3i (double a, double b, double c, int z)
  388. {
  389. double r = a+b+c+z;
  390. fprintf(out,"double f(3*double,int):(%g,%g,%g,%d)",a,b,c,z);
  391. fflush(out);
  392. return r;
  393. }
  394. double ABI_ATTR d_d4i (double a, double b, double c, double d, int z)
  395. {
  396. double r = a+b+c+d+z;
  397. fprintf(out,"double f(4*double,int):(%g,%g,%g,%g,%d)",a,b,c,d,z);
  398. fflush(out);
  399. return r;
  400. }
  401. double ABI_ATTR d_d7i (double a, double b, double c, double d, double e, double f,
  402. double g, int z)
  403. {
  404. double r = a+b+c+d+e+f+g+z;
  405. fprintf(out,"double f(7*double,int):(%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,z);
  406. fflush(out);
  407. return r;
  408. }
  409. double ABI_ATTR d_d8i (double a, double b, double c, double d, double e, double f,
  410. double g, double h, int z)
  411. {
  412. double r = a+b+c+d+e+f+g+h+z;
  413. fprintf(out,"double f(8*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,z);
  414. fflush(out);
  415. return r;
  416. }
  417. double ABI_ATTR d_d12i (double a, double b, double c, double d, double e, double f,
  418. double g, double h, double i, double j, double k, double l,
  419. int z)
  420. {
  421. double r = a+b+c+d+e+f+g+h+i+j+k+l+z;
  422. fprintf(out,"double f(12*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,z);
  423. fflush(out);
  424. return r;
  425. }
  426. double ABI_ATTR d_d13i (double a, double b, double c, double d, double e, double f,
  427. double g, double h, double i, double j, double k, double l,
  428. double m, int z)
  429. {
  430. double r = a+b+c+d+e+f+g+h+i+j+k+l+m+z;
  431. fprintf(out,"double f(13*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,m,z);
  432. fflush(out);
  433. return r;
  434. }
  435. /* small structure return tests */
  436. Size1 ABI_ATTR S1_v (void)
  437. {
  438. fprintf(out,"Size1 f(void):");
  439. fflush(out);
  440. return Size1_1;
  441. }
  442. Size2 ABI_ATTR S2_v (void)
  443. {
  444. fprintf(out,"Size2 f(void):");
  445. fflush(out);
  446. return Size2_1;
  447. }
  448. Size3 ABI_ATTR S3_v (void)
  449. {
  450. fprintf(out,"Size3 f(void):");
  451. fflush(out);
  452. return Size3_1;
  453. }
  454. Size4 ABI_ATTR S4_v (void)
  455. {
  456. fprintf(out,"Size4 f(void):");
  457. fflush(out);
  458. return Size4_1;
  459. }
  460. Size7 ABI_ATTR S7_v (void)
  461. {
  462. fprintf(out,"Size7 f(void):");
  463. fflush(out);
  464. return Size7_1;
  465. }
  466. Size8 ABI_ATTR S8_v (void)
  467. {
  468. fprintf(out,"Size8 f(void):");
  469. fflush(out);
  470. return Size8_1;
  471. }
  472. Size12 ABI_ATTR S12_v (void)
  473. {
  474. fprintf(out,"Size12 f(void):");
  475. fflush(out);
  476. return Size12_1;
  477. }
  478. Size15 ABI_ATTR S15_v (void)
  479. {
  480. fprintf(out,"Size15 f(void):");
  481. fflush(out);
  482. return Size15_1;
  483. }
  484. Size16 ABI_ATTR S16_v (void)
  485. {
  486. fprintf(out,"Size16 f(void):");
  487. fflush(out);
  488. return Size16_1;
  489. }
  490. /* structure tests */
  491. Int ABI_ATTR I_III (Int a, Int b, Int c)
  492. {
  493. Int r;
  494. r.x = a.x + b.x + c.x;
  495. fprintf(out,"Int f(Int,Int,Int):({%d},{%d},{%d})",a.x,b.x,c.x);
  496. fflush(out);
  497. return r;
  498. }
  499. Char ABI_ATTR C_CdC (Char a, double b, Char c)
  500. {
  501. Char r;
  502. r.x = (a.x + c.x)/2;
  503. fprintf(out,"Char f(Char,double,Char):({'%c'},%g,{'%c'})",a.x,b,c.x);
  504. fflush(out);
  505. return r;
  506. }
  507. Float ABI_ATTR F_Ffd (Float a, float b, double c)
  508. {
  509. Float r;
  510. r.x = (float) (a.x + b + c);
  511. fprintf(out,"Float f(Float,float,double):({%g},%g,%g)",a.x,b,c);
  512. fflush(out);
  513. return r;
  514. }
  515. Double ABI_ATTR D_fDd (float a, Double b, double c)
  516. {
  517. Double r;
  518. r.x = a + b.x + c;
  519. fprintf(out,"Double f(float,Double,double):(%g,{%g},%g)",a,b.x,c);
  520. fflush(out);
  521. return r;
  522. }
  523. Double ABI_ATTR D_Dfd (Double a, float b, double c)
  524. {
  525. Double r;
  526. r.x = a.x + b + c;
  527. fprintf(out,"Double f(Double,float,double):({%g},%g,%g)",a.x,b,c);
  528. fflush(out);
  529. return r;
  530. }
  531. J ABI_ATTR J_JiJ (J a, int b, J c)
  532. {
  533. J r;
  534. r.l1 = a.l1+c.l1; r.l2 = a.l2+b+c.l2;
  535. fprintf(out,"J f(J,int,J):({%ld,%ld},%d,{%ld,%ld})",a.l1,a.l2,b,c.l1,c.l2);
  536. fflush(out);
  537. return r;
  538. }
  539. T ABI_ATTR T_TcT (T a, char b, T c)
  540. {
  541. T r;
  542. r.c[0]='b'; r.c[1]=c.c[1]; r.c[2]=c.c[2];
  543. fprintf(out,"T f(T,char,T):({\"%c%c%c\"},'%c',{\"%c%c%c\"})",a.c[0],a.c[1],a.c[2],b,c.c[0],c.c[1],c.c[2]);
  544. fflush(out);
  545. return r;
  546. }
  547. X ABI_ATTR X_BcdB (B a, char b, double c, B d)
  548. {
  549. static X xr={"return val",'R'};
  550. X r;
  551. r = xr;
  552. r.c1 = b;
  553. fprintf(out,"X f(B,char,double,B):({%g,{%d,%d,%d}},'%c',%g,{%g,{%d,%d,%d}})",
  554. a.d,a.i[0],a.i[1],a.i[2],b,c,d.d,d.i[0],d.i[1],d.i[2]);
  555. fflush(out);
  556. return r;
  557. }
  558. /* Test for cases where some argument (especially structure, 'long long', or
  559. 'double') may be passed partially in general-purpose argument registers
  560. and partially on the stack. Different ABIs pass between 4 and 8 arguments
  561. (or none) in general-purpose argument registers. */
  562. long ABI_ATTR l_l0K (K b, long c)
  563. {
  564. long r = b.l1 + b.l2 + b.l3 + b.l4 + c;
  565. fprintf(out,"long f(K,long):(%ld,%ld,%ld,%ld,%ld)",b.l1,b.l2,b.l3,b.l4,c);
  566. fflush(out);
  567. return r;
  568. }
  569. long ABI_ATTR l_l1K (long a1, K b, long c)
  570. {
  571. long r = a1 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  572. fprintf(out,"long f(long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld)",a1,b.l1,b.l2,b.l3,b.l4,c);
  573. fflush(out);
  574. return r;
  575. }
  576. long ABI_ATTR l_l2K (long a1, long a2, K b, long c)
  577. {
  578. long r = a1 + a2 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  579. fprintf(out,"long f(2*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,b.l1,b.l2,b.l3,b.l4,c);
  580. fflush(out);
  581. return r;
  582. }
  583. long ABI_ATTR l_l3K (long a1, long a2, long a3, K b, long c)
  584. {
  585. long r = a1 + a2 + a3 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  586. fprintf(out,"long f(3*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,b.l1,b.l2,b.l3,b.l4,c);
  587. fflush(out);
  588. return r;
  589. }
  590. long ABI_ATTR l_l4K (long a1, long a2, long a3, long a4, K b, long c)
  591. {
  592. long r = a1 + a2 + a3 + a4 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  593. fprintf(out,"long f(4*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,b.l1,b.l2,b.l3,b.l4,c);
  594. fflush(out);
  595. return r;
  596. }
  597. long ABI_ATTR l_l5K (long a1, long a2, long a3, long a4, long a5, K b, long c)
  598. {
  599. long r = a1 + a2 + a3 + a4 + a5 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  600. fprintf(out,"long f(5*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,a5,b.l1,b.l2,b.l3,b.l4,c);
  601. fflush(out);
  602. return r;
  603. }
  604. long ABI_ATTR l_l6K (long a1, long a2, long a3, long a4, long a5, long a6, K b, long c)
  605. {
  606. long r = a1 + a2 + a3 + a4 + a5 + a6 + b.l1 + b.l2 + b.l3 + b.l4 + c;
  607. fprintf(out,"long f(6*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,a5,a6,b.l1,b.l2,b.l3,b.l4,c);
  608. fflush(out);
  609. return r;
  610. }
  611. /* These tests is crafted on the knowledge that for all known ABIs:
  612. * 17 > number of floating-point argument registers,
  613. * 3 < number of general-purpose argument registers < 3 + 6. */
  614. float ABI_ATTR f_f17l3L (float a, float b, float c, float d, float e, float f, float g,
  615. float h, float i, float j, float k, float l, float m, float n,
  616. float o, float p, float q,
  617. long s, long t, long u, L z)
  618. {
  619. float r = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+z.l1+z.l2+z.l3+z.l4+z.l5+z.l6;
  620. fprintf(out,"float f(17*float,3*int,L):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,z.l1,z.l2,z.l3,z.l4,z.l5,z.l6);
  621. fflush(out);
  622. return r;
  623. }
  624. double ABI_ATTR d_d17l3L (double a, double b, double c, double d, double e, double f,
  625. double g, double h, double i, double j, double k, double l,
  626. double m, double n, double o, double p, double q,
  627. long s, long t, long u, L z)
  628. {
  629. double r = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+z.l1+z.l2+z.l3+z.l4+z.l5+z.l6;
  630. fprintf(out,"double f(17*double,3*int,L):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,z.l1,z.l2,z.l3,z.l4,z.l5,z.l6);
  631. fflush(out);
  632. return r;
  633. }
  634. long long ABI_ATTR ll_l2ll (long a1, long a2, long long b, long c)
  635. {
  636. long long r = (long long) (a1 + a2) + b + c;
  637. fprintf(out,"long long f(2*long,long long,long):(%ld,%ld,0x%lx%08lx,%ld)",a1,a2,(long)(b>>32),(long)(b&0xffffffff),c);
  638. fflush(out);
  639. return r;
  640. }
  641. long long ABI_ATTR ll_l3ll (long a1, long a2, long a3, long long b, long c)
  642. {
  643. long long r = (long long) (a1 + a2 + a3) + b + c;
  644. fprintf(out,"long long f(3*long,long long,long):(%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,(long)(b>>32),(long)(b&0xffffffff),c);
  645. fflush(out);
  646. return r;
  647. }
  648. long long ABI_ATTR ll_l4ll (long a1, long a2, long a3, long a4, long long b, long c)
  649. {
  650. long long r = (long long) (a1 + a2 + a3 + a4) + b + c;
  651. fprintf(out,"long long f(4*long,long long,long):(%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,(long)(b>>32),(long)(b&0xffffffff),c);
  652. fflush(out);
  653. return r;
  654. }
  655. long long ABI_ATTR ll_l5ll (long a1, long a2, long a3, long a4, long a5, long long b, long c)
  656. {
  657. long long r = (long long) (a1 + a2 + a3 + a4 + a5) + b + c;
  658. fprintf(out,"long long f(5*long,long long,long):(%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,(long)(b>>32),(long)(b&0xffffffff),c);
  659. fflush(out);
  660. return r;
  661. }
  662. long long ABI_ATTR ll_l6ll (long a1, long a2, long a3, long a4, long a5, long a6, long long b, long c)
  663. {
  664. long long r = (long long) (a1 + a2 + a3 + a4 + a5 + a6) + b + c;
  665. fprintf(out,"long long f(6*long,long long,long):(%ld,%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,a6,(long)(b>>32),(long)(b&0xffffffff),c);
  666. fflush(out);
  667. return r;
  668. }
  669. long long ABI_ATTR ll_l7ll (long a1, long a2, long a3, long a4, long a5, long a6, long a7, long long b, long c)
  670. {
  671. long long r = (long long) (a1 + a2 + a3 + a4 + a5 + a6 + a7) + b + c;
  672. fprintf(out,"long long f(7*long,long long,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,a6,a7,(long)(b>>32),(long)(b&0xffffffff),c);
  673. fflush(out);
  674. return r;
  675. }
  676. double ABI_ATTR d_l2d (long a1, long a2, double b, long c)
  677. {
  678. double r = (double) (a1 + a2) + b + c;
  679. fprintf(out,"double f(2*long,double,long):(%ld,%ld,%g,%ld)",a1,a2,b,c);
  680. fflush(out);
  681. return r;
  682. }
  683. double ABI_ATTR d_l3d (long a1, long a2, long a3, double b, long c)
  684. {
  685. double r = (double) (a1 + a2 + a3) + b + c;
  686. fprintf(out,"double f(3*long,double,long):(%ld,%ld,%ld,%g,%ld)",a1,a2,a3,b,c);
  687. fflush(out);
  688. return r;
  689. }
  690. double ABI_ATTR d_l4d (long a1, long a2, long a3, long a4, double b, long c)
  691. {
  692. double r = (double) (a1 + a2 + a3 + a4) + b + c;
  693. fprintf(out,"double f(4*long,double,long):(%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,b,c);
  694. fflush(out);
  695. return r;
  696. }
  697. double ABI_ATTR d_l5d (long a1, long a2, long a3, long a4, long a5, double b, long c)
  698. {
  699. double r = (double) (a1 + a2 + a3 + a4 + a5) + b + c;
  700. fprintf(out,"double f(5*long,double,long):(%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,b,c);
  701. fflush(out);
  702. return r;
  703. }
  704. double ABI_ATTR d_l6d (long a1, long a2, long a3, long a4, long a5, long a6, double b, long c)
  705. {
  706. double r = (double) (a1 + a2 + a3 + a4 + a5 + a6) + b + c;
  707. fprintf(out,"double f(6*long,double,long):(%ld,%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,a6,b,c);
  708. fflush(out);
  709. return r;
  710. }
  711. double ABI_ATTR d_l7d (long a1, long a2, long a3, long a4, long a5, long a6, long a7, double b, long c)
  712. {
  713. double r = (double) (a1 + a2 + a3 + a4 + a5 + a6 + a7) + b + c;
  714. fprintf(out,"double f(7*long,double,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,a6,a7,b,c);
  715. fflush(out);
  716. return r;
  717. }