git subrepo pull --force deps/lightrec
[pcsx_rearmed.git] / deps / lightning / check / ccall.c
CommitLineData
4a71579b
PC
1#include <lightning.h>
2#include <stdio.h>
3
4#define _w0 0
5#define _w1 1
6#define _w2 (_w1-2)
7#define _w3 (_w2-3)
8#define _w4 (_w3-4)
9#define _w5 (_w4-5)
10#define _w6 (_w5-6)
11#define _w7 (_w6-7)
12#define _w8 (_w7-8)
13#define _w9 (_w8-9)
14#define _w10 (_w9-10)
15#define _w11 (_w10-11)
16#define _w12 (_w11-12)
17#define _w13 (_w12-13)
18#define _w14 (_w13-14)
19#define _w15 (_w14-15)
20#define _c0 _w0
21#define _c1 _w1
22#define _c2 _w2
23#define _c3 _w3
24#define _c4 _w4
25#define _c5 _w5
26#define _c6 _w6
27#define _c7 _w7
28#define _c8 _w8
29#define _c9 _w9
30#define _c10 _w10
31#define _c11 _w11
32#define _c12 _w12
33#define _c13 _w13
34#define _c14 _w14
35#define _c15 _w15
36#define _uc0 (_w0&0xff)
37#define _uc1 (_w1&0xff)
38#define _uc2 (_w2&0xff)
39#define _uc3 (_w3&0xff)
40#define _uc4 (_w4&0xff)
41#define _uc5 (_w5&0xff)
42#define _uc6 (_w6&0xff)
43#define _uc7 (_w7&0xff)
44#define _uc8 (_w8&0xff)
45#define _uc9 (_w9&0xff)
46#define _uc10 (_w10&0xff)
47#define _uc11 (_w11&0xff)
48#define _uc12 (_w12&0xff)
49#define _uc13 (_w13&0xff)
50#define _uc14 (_w14&0xff)
51#define _uc15 (_w15&0xff)
52#define _s0 _w0
53#define _s1 _w1
54#define _s2 _w2
55#define _s3 _w3
56#define _s4 _w4
57#define _s5 _w5
58#define _s6 _w6
59#define _s7 _w7
60#define _s8 _w8
61#define _s9 _w9
62#define _s10 _w10
63#define _s11 _w11
64#define _s12 _w12
65#define _s13 _w13
66#define _s14 _w14
67#define _s15 _w15
68#define _us0 (_w0&0xffff)
69#define _us1 (_w1&0xffff)
70#define _us2 (_w2&0xffff)
71#define _us3 (_w3&0xffff)
72#define _us4 (_w4&0xffff)
73#define _us5 (_w5&0xffff)
74#define _us6 (_w6&0xffff)
75#define _us7 (_w7&0xffff)
76#define _us8 (_w8&0xffff)
77#define _us9 (_w9&0xffff)
78#define _us10 (_w10&0xffff)
79#define _us11 (_w11&0xffff)
80#define _us12 (_w12&0xffff)
81#define _us13 (_w13&0xffff)
82#define _us14 (_w14&0xffff)
83#define _us15 (_w15&0xffff)
84#define _i0 _w0
85#define _i1 _w1
86#define _i2 _w2
87#define _i3 _w3
88#define _i4 _w4
89#define _i5 _w5
90#define _i6 _w6
91#define _i7 _w7
92#define _i8 _w8
93#define _i9 _w9
94#define _i10 _w10
95#define _i11 _w11
96#define _i12 _w12
97#define _i13 _w13
98#define _i14 _w14
99#define _i15 _w15
100#if __WORDSIZE == 64
101# define _ui0 (_w0&0xffffffff)
102# define _ui1 (_w1&0xffffffff)
103# define _ui2 (_w2&0xffffffff)
104# define _ui3 (_w3&0xffffffff)
105# define _ui4 (_w4&0xffffffff)
106# define _ui5 (_w5&0xffffffff)
107# define _ui6 (_w6&0xffffffff)
108# define _ui7 (_w7&0xffffffff)
109# define _ui8 (_w8&0xffffffff)
110# define _ui9 (_w9&0xffffffff)
111# define _ui10 (_w10&0xffffffff)
112# define _ui11 (_w11&0xffffffff)
113# define _ui12 (_w12&0xffffffff)
114# define _ui13 (_w13&0xffffffff)
115# define _ui14 (_w14&0xffffffff)
116# define _ui15 (_w15&0xffffffff)
117# define _l0 _w0
118# define _l1 _w1
119# define _l2 _w2
120# define _l3 _w3
121# define _l4 _w4
122# define _l5 _w5
123# define _l6 _w6
124# define _l7 _w7
125# define _l8 _w8
126# define _l9 _w9
127# define _l10 _w10
128# define _l11 _w11
129# define _l12 _w12
130# define _l13 _w13
131# define _l14 _w14
132# define _l15 _w15
133#endif
134
79bfeef6
PC
135#ifndef jit_arg_uc
136# define jit_arg_uc jit_arg_c
137#endif
138#ifndef jit_arg_us
139# define jit_arg_us jit_arg_s
140#endif
141#ifndef jit_arg_ui
142# define jit_arg_ui jit_arg_i
143#endif
144
4a71579b
PC
145/*
146 * Types
147 */
148typedef signed char _c;
149typedef unsigned char _uc;
150typedef signed short _s;
151typedef unsigned short _us;
152typedef signed int _i;
153#if __WORDSIZE == 64
154typedef unsigned int _ui;
155typedef jit_word_t _l;
156#endif
157typedef float _f;
158typedef double _d;
159
160#define prt0(T) T C##T##0(void);
161#define prt1(T) prt0(T) \
162 T C##T##1(T);
163#define prt2(T) prt1(T) \
164 T C##T##2(T,T);
165#define prt3(T) prt2(T) \
166 T C##T##3(T,T,T);
167#define prt4(T) prt3(T) \
168 T C##T##4(T,T,T,T);
169#define prt5(T) prt4(T) \
170 T C##T##5(T,T,T,T,T);
171#define prt6(T) prt5(T) \
172 T C##T##6(T,T,T,T,T,T);
173#define prt7(T) prt6(T) \
174 T C##T##7(T,T,T,T,T,T,T);
175#define prt8(T) prt7(T) \
176 T C##T##8(T,T,T,T,T,T,T,T);
177#define prt9(T) prt8(T) \
178 T C##T##9(T,T,T,T,T,T,T,T,T);
179#define prt10(T) prt9(T) \
180 T C##T##10(T,T,T,T,T,T,T,T,T,T);
181#define prt11(T) prt10(T) \
182 T C##T##11(T,T,T,T,T,T,T,T,T,T,T);
183#define prt12(T) prt11(T) \
184 T C##T##12(T,T,T,T,T,T,T,T,T,T,T,T);
185#define prt13(T) prt12(T) \
186 T C##T##13(T,T,T,T,T,T,T,T,T,T,T,T,T);
187#define prt14(T) prt13(T) \
188 T C##T##14(T,T,T,T,T,T,T,T,T,T,T,T,T,T);
189#define prt15(T) prt14(T) \
190 T C##T##15(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);
191#define prt(T) prt15(T)
192prt(_c)
193prt(_uc)
194prt(_s)
195prt(_us)
196prt(_i)
197#if __WORDSIZE == 64
198prt(_ui)
199prt(_l)
200#endif
201prt(_f)
202prt(_d)
203#undef prt
204#undef prt15
205#undef prt14
206#undef prt13
207#undef prt12
208#undef prt11
209#undef prt10
210#undef prt9
211#undef prt8
212#undef prt7
213#undef prt6
214#undef prt5
215#undef prt4
216#undef prt3
217#undef prt2
218#undef prt1
219#undef prt0
220
221#define prtn(N,T) T J##T##n(void);
222#define prt0(T) prtn(0,T)
223#define prt1(T) prt0(T) prtn(1,T)
224#define prt2(T) prt1(T) prtn(2,T)
225#define prt3(T) prt2(T) prtn(3,T)
226#define prt4(T) prt3(T) prtn(4,T)
227#define prt5(T) prt4(T) prtn(5,T)
228#define prt6(T) prt5(T) prtn(6,T)
229#define prt7(T) prt6(T) prtn(7,T)
230#define prt8(T) prt7(T) prtn(8,T)
231#define prt9(T) prt8(T) prtn(9,T)
232#define prt10(T) prt9(T) prtn(10,T)
233#define prt11(T) prt10(T) prtn(11,T)
234#define prt12(T) prt11(T) prtn(12,T)
235#define prt13(T) prt12(T) prtn(13,T)
236#define prt14(T) prt13(T) prtn(14,T)
237#define prt15(T) prt14(T) prtn(15,T)
238#define prt(T) prt15(T)
239prt(_c)
240prt(_uc)
241prt(_s)
242prt(_us)
243prt(_i)
244#if __WORDSIZE == 64
245prt(_ui)
246prt(_l)
247#endif
248prt(_f)
249prt(_d)
250#undef prt
251#undef prt15
252#undef prt14
253#undef prt13
254#undef prt12
255#undef prt11
256#undef prt10
257#undef prt9
258#undef prt8
259#undef prt7
260#undef prt6
261#undef prt5
262#undef prt4
263#undef prt3
264#undef prt2
265#undef prt1
266#undef prt0
267#undef prtn
268
269/*
270 * Initialization
271 */
272
273#define dat0(T) T (*j##T##0)(void); \
274 jit_node_t *n##T##0;
275#define dat1(T) dat0(T) \
276 T (*j##T##1)(T); \
277 jit_node_t *n##T##1;
278#define dat2(T) dat1(T) \
279 T (*j##T##2)(T,T); \
280 jit_node_t *n##T##2;
281#define dat3(T) dat2(T) \
282 T (*j##T##3)(T,T,T); \
283 jit_node_t *n##T##3;
284#define dat4(T) dat3(T) \
285 T (*j##T##4)(T,T,T,T); \
286 jit_node_t *n##T##4;
287#define dat5(T) dat4(T) \
288 T (*j##T##5)(T,T,T,T,T); \
289 jit_node_t *n##T##5;
290#define dat6(T) dat5(T) \
291 T (*j##T##6)(T,T,T,T,T,T); \
292 jit_node_t *n##T##6;
293#define dat7(T) dat6(T) \
294 T (*j##T##7)(T,T,T,T,T,T,T); \
295 jit_node_t *n##T##7;
296#define dat8(T) dat7(T) \
297 T (*j##T##8)(T,T,T,T,T,T,T,T); \
298 jit_node_t *n##T##8;
299#define dat9(T) dat8(T) \
300 T (*j##T##9)(T,T,T,T,T,T,T,T,T); \
301 jit_node_t *n##T##9;
302#define dat10(T) dat9(T) \
303 T (*j##T##10)(T,T,T,T,T,T,T,T,T,T); \
304 jit_node_t *n##T##10;
305#define dat11(T) dat10(T) \
306 T (*j##T##11)(T,T,T,T,T,T,T,T,T,T,T); \
307 jit_node_t *n##T##11;
308#define dat12(T) dat11(T) \
309 T (*j##T##12)(T,T,T,T,T,T,T,T,T,T,T,T); \
310 jit_node_t *n##T##12;
311#define dat13(T) dat12(T) \
312 T (*j##T##13)(T,T,T,T,T,T,T,T,T,T,T,T,T);\
313 jit_node_t *n##T##13;
314#define dat14(T) dat13(T) \
315 T (*j##T##14)(T,T,T,T,T,T,T,T,T,T,T,T,T,T);\
316 jit_node_t *n##T##14;
317#define dat15(T) dat14(T) \
318 T (*j##T##15)(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);\
319 jit_node_t *n##T##15;
320#define dat(T) dat15(T)
321dat(_c)
322dat(_uc)
323dat(_s)
324dat(_us)
325dat(_i)
326#if __WORDSIZE == 64
327dat(_ui)
328dat(_l)
329#endif
330dat(_f)
331dat(_d)
332#undef dat
333#undef dat15
334#undef dat14
335#undef dat13
336#undef dat12
337#undef dat11
338#undef dat10
339#undef dat9
340#undef dat8
341#undef dat7
342#undef dat6
343#undef dat5
344#undef dat4
345#undef dat3
346#undef dat2
347#undef dat1
348#undef dat0
349
350/*
351 * Implementation
352 */
353#define dcl0(T) \
354T C##T##0(void) \
355{ \
356 return (0); \
357}
358#define dcl1(T) \
359dcl0(T) \
360T C##T##1(T A) \
361{ \
362 return (A); \
363}
364#define dcl2(T) \
365dcl1(T) \
366T C##T##2(T A,T B) \
367{ \
368 return (A-B); \
369}
370#define dcl3(T) \
371dcl2(T) \
372T C##T##3(T A,T B,T C) \
373{ \
374 return (A-B-C); \
375}
376#define dcl4(T) \
377dcl3(T) \
378T C##T##4(T A,T B,T C,T D) \
379{ \
380 return (A-B-C-D); \
381}
382#define dcl5(T) \
383dcl4(T) \
384T C##T##5(T A,T B,T C,T D,T E) \
385{ \
386 return (A-B-C-D-E); \
387}
388#define dcl6(T) \
389dcl5(T) \
390T C##T##6(T A,T B,T C,T D,T E,T F) \
391{ \
392 return (A-B-C-D-E-F); \
393}
394#define dcl7(T) \
395dcl6(T) \
396T C##T##7(T A,T B,T C,T D,T E,T F,T G) \
397{ \
398 return (A-B-C-D-E-F-G); \
399}
400#define dcl8(T) \
401dcl7(T) \
402T C##T##8(T A,T B,T C,T D,T E,T F,T G,T H) \
403{ \
404 return (A-B-C-D-E-F-G-H); \
405}
406#define dcl9(T) \
407dcl8(T) \
408T C##T##9(T A,T B,T C,T D,T E,T F,T G,T H,T I) \
409{ \
410 return (A-B-C-D-E-F-G-H-I); \
411}
412#define dcl10(T) \
413dcl9(T) \
414T C##T##10(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J) \
415{ \
416 return (A-B-C-D-E-F-G-H-I-J); \
417}
418#define dcl11(T) \
419dcl10(T) \
420T C##T##11(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J,T K) \
421{ \
422 return (A-B-C-D-E-F-G-H-I-J-K); \
423}
424#define dcl12(T) \
425dcl11(T) \
426T C##T##12(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J,T K,T L) \
427{ \
428 return (A-B-C-D-E-F-G-H-I-J-K-L); \
429}
430#define dcl13(T) \
431dcl12(T) \
432T C##T##13(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J,T K,T L,T M) \
433{ \
434 return (A-B-C-D-E-F-G-H-I-J-K-L-M); \
435}
436#define dcl14(T) \
437dcl13(T) \
438T C##T##14(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J,T K,T L,T M,T N) \
439{ \
440 return (A-B-C-D-E-F-G-H-I-J-K-L-M-N); \
441}
442#define dcl15(T) \
443dcl14(T) \
444T C##T##15(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J,T K,T L,T M,T N,T O) \
445{ \
446 return (A-B-C-D-E-F-G-H-I-J-K-L-M-N-O); \
447}
448#define dcl(T) dcl15(T)
449dcl(_c)
450dcl(_uc)
451dcl(_s)
452dcl(_us)
453dcl(_i)
454#if __WORDSIZE == 64
455dcl(_ui)
456dcl(_l)
457#endif
458dcl(_f)
459dcl(_d)
460#undef dcl
461#undef dcl15
462#undef dcl14
463#undef dcl13
464#undef dcl12
465#undef dcl11
466#undef dcl10
467#undef dcl9
468#undef dcl8
469#undef dcl7
470#undef dcl6
471#undef dcl5
472#undef dcl4
473#undef dcl3
474#undef dcl2
475#undef dcl1
476#undef dcl0
477
478#define dcl0(T) \
479T CJ##T##0(void) \
480{ \
481 return ((*j##T##0)()); \
482}
483#define dcl1(T) \
484dcl0(T) \
485T CJ##T##1(void) \
486{ \
487 return ((*j##T##1)(1)); \
488}
489#define dcl2(T) \
490dcl1(T) \
491T CJ##T##2(void) \
492{ \
493 return ((*j##T##2)(1,2)); \
494}
495#define dcl3(T) \
496dcl2(T) \
497T CJ##T##3(void) \
498{ \
499 return ((*j##T##3)(1,2,3)); \
500}
501#define dcl4(T) \
502dcl3(T) \
503T CJ##T##4(void) \
504{ \
505 return ((*j##T##4)(1,2,3,4)); \
506}
507#define dcl5(T) \
508dcl4(T) \
509T CJ##T##5(void) \
510{ \
511 return ((*j##T##5)(1,2,3,4,5)); \
512}
513#define dcl6(T) \
514dcl5(T) \
515T CJ##T##6(void) \
516{ \
517 return ((*j##T##6)(1,2,3,4,5,6)); \
518}
519#define dcl7(T) \
520dcl6(T) \
521T CJ##T##7(void) \
522{ \
523 return ((*j##T##7)(1,2,3,4,5,6,7)); \
524}
525#define dcl8(T) \
526dcl7(T) \
527T CJ##T##8(void) \
528{ \
529 return ((*j##T##8)(1,2,3,4,5,6,7,8)); \
530}
531#define dcl9(T) \
532dcl8(T) \
533T CJ##T##9(void) \
534{ \
535 return ((*j##T##9)(1,2,3,4,5,6,7,8,9)); \
536}
537#define dcl10(T) \
538dcl9(T) \
539T CJ##T##10(void) \
540{ \
541 return ((*j##T##10)(1,2,3,4,5,6,7,8,9,10)); \
542}
543#define dcl11(T) \
544dcl10(T) \
545T CJ##T##11(void) \
546{ \
547 return ((*j##T##11)(1,2,3,4,5,6,7,8,9,10,11)); \
548}
549#define dcl12(T) \
550dcl11(T) \
551T CJ##T##12(void) \
552{ \
553 return ((*j##T##12)(1,2,3,4,5,6,7,8,9,10,11,12)); \
554}
555#define dcl13(T) \
556dcl12(T) \
557T CJ##T##13(void) \
558{ \
559 return ((*j##T##13)(1,2,3,4,5,6,7,8,9,10,11,12,13)); \
560}
561#define dcl14(T) \
562dcl13(T) \
563T CJ##T##14(void) \
564{ \
565 return ((*j##T##14)(1,2,3,4,5,6,7,8,9,10,11,12,13,14)); \
566}
567#define dcl15(T) \
568dcl14(T) \
569T CJ##T##15(void) \
570{ \
571 return ((*j##T##15)(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)); \
572}
573#define dcl(t) dcl15(t)
574dcl(_c)
575dcl(_uc)
576dcl(_s)
577dcl(_us)
578dcl(_i)
579#if __WORDSIZE == 64
580dcl(_ui)
581dcl(_l)
582#endif
583dcl(_f)
584dcl(_d)
585#undef dcl
586#undef dcl15
587#undef dcl14
588#undef dcl13
589#undef dcl12
590#undef dcl11
591#undef dcl10
592#undef dcl9
593#undef dcl8
594#undef dcl7
595#undef dcl6
596#undef dcl5
597#undef dcl4
598#undef dcl3
599#undef dcl2
600#undef dcl1
601#undef dcl0
602
603int
604main(int argc, char *argv[])
605{
606 jit_state_t *_jit;
607 jit_node_t *jmpi_main;
608 void (*function)(void);
609 jit_node_t *a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9;
610 jit_node_t *a10,*a11,*a12,*a13,*a14,*a15;
611 jit_node_t *jmp;
612
613 init_jit(argv[0]);
614 _jit = jit_new_state();
615
616 jmpi_main = jit_jmpi();
617
618
619#define arg0(T) /**/
620#define arg1(T) a1 = jit_arg##T();
621#define arg2(T) arg1(T) a2 = jit_arg##T();
622#define arg3(T) arg2(T) a3 = jit_arg##T();
623#define arg4(T) arg3(T) a4 = jit_arg##T();
624#define arg5(T) arg4(T) a5 = jit_arg##T();
625#define arg6(T) arg5(T) a6 = jit_arg##T();
626#define arg7(T) arg6(T) a7 = jit_arg##T();
627#define arg8(T) arg7(T) a8 = jit_arg##T();
628#define arg9(T) arg8(T) a9 = jit_arg##T();
629#define arg10(T) arg9(T) a10 = jit_arg##T();
630#define arg11(T) arg10(T) a11 = jit_arg##T();
631#define arg12(T) arg11(T) a12 = jit_arg##T();
632#define arg13(T) arg12(T) a13 = jit_arg##T();
633#define arg14(T) arg13(T) a14 = jit_arg##T();
634#define arg15(T) arg14(T) a15 = jit_arg##T();
635
636#define get0(B,T,R) jit_movi##B(R##0,0);
79bfeef6 637#define get1(B,T,R) jit_getarg##T(R##0,a##1);
4a71579b
PC
638#define get2(B,T,R) \
639 get1(B,T,R); \
640 jit_movr##B(R##1, R##0); \
641 jit_getarg##T(R##0, a##2); \
642 jit_subr##B(R##0, R##1, R##0);
643#define get3(B,T,R) \
644 get2(B,T,R); \
645 jit_movr##B(R##1, R##0); \
646 jit_getarg##T(R##0, a##3); \
647 jit_subr##B(R##0, R##1, R##0);
648#define get4(B,T,R) \
649 get3(B,T,R); \
650 jit_movr##B(R##1, R##0); \
651 jit_getarg##T(R##0, a##4); \
652 jit_subr##B(R##0, R##1, R##0);
653#define get5(B,T,R) \
654 get4(B,T,R); \
655 jit_movr##B(R##1, R##0); \
656 jit_getarg##T(R##0, a##5); \
657 jit_subr##B(R##0, R##1, R##0);
658#define get6(B,T,R) \
659 get5(B,T,R); \
660 jit_movr##B(R##1, R##0); \
661 jit_getarg##T(R##0, a##6); \
662 jit_subr##B(R##0, R##1, R##0);
663#define get7(B,T,R) \
664 get6(B,T,R); \
665 jit_movr##B(R##1, R##0); \
666 jit_getarg##T(R##0, a##7); \
667 jit_subr##B(R##0, R##1, R##0);
668#define get8(B,T,R) \
669 get7(B,T,R); \
670 jit_movr##B(R##1, R##0); \
671 jit_getarg##T(R##0, a##8); \
672 jit_subr##B(R##0, R##1, R##0);
673#define get9(B,T,R) \
674 get8(B,T,R); \
675 jit_movr##B(R##1, R##0); \
676 jit_getarg##T(R##0, a##9); \
677 jit_subr##B(R##0, R##1, R##0);
678#define get10(B,T,R) \
679 get9(B,T,R); \
680 jit_movr##B(R##1, R##0); \
681 jit_getarg##T(R##0, a##10); \
682 jit_subr##B(R##0, R##1, R##0);
683#define get11(B,T,R) \
684 get10(B,T,R); \
685 jit_movr##B(R##1, R##0); \
686 jit_getarg##T(R##0, a##11); \
687 jit_subr##B(R##0, R##1, R##0);
688#define get12(B,T,R) \
689 get11(B,T,R); \
690 jit_movr##B(R##1, R##0); \
691 jit_getarg##T(R##0, a##12); \
692 jit_subr##B(R##0, R##1, R##0);
693#define get13(B,T,R) \
694 get12(B,T,R); \
695 jit_movr##B(R##1, R##0); \
696 jit_getarg##T(R##0, a##13); \
697 jit_subr##B(R##0, R##1, R##0);
698#define get14(B,T,R) \
699 get13(B,T,R); \
700 jit_movr##B(R##1, R##0); \
701 jit_getarg##T(R##0, a##14); \
702 jit_subr##B(R##0, R##1, R##0);
703#define get15(B,T,R) \
704 get14(B,T,R); \
705 jit_movr##B(R##1, R##0); \
706 jit_getarg##T(R##0, a##15); \
707 jit_subr##B(R##0, R##1, R##0);
708
709#if __WORDSIZE == 32
710# define jit_extr_i(u, v) /**/
711#else
712# define jit_extr_l(u, v) /**/
713#endif
714
715#define strfy(n) #n
716#define defi(T, N) \
717 n##T##N = jit_name(strfy(n##T##N)); \
718 jit_note("ccall.c", __LINE__); \
719 jit_prolog(); \
79bfeef6 720 arg##N(T); \
4a71579b
PC
721 get##N(,T,JIT_R) \
722 jit_extr##T(JIT_R0, JIT_R0); \
723 jit_retr(JIT_R0); \
724 jit_epilog();
725#define deff(T, N) \
726 n##T##N = jit_name(strfy(n##T##N)); \
727 jit_note("ccall.c", __LINE__); \
728 jit_prolog(); \
729 arg##N(T); \
730 get##N(T,T,JIT_F); \
731 jit_retr##T(JIT_F0); \
732 jit_epilog();
733
734#define def0(X, T) def##X(T, 0)
735#define def1(X, T) def0(X, T) def##X(T, 1)
736#define def2(X, T) def1(X, T) def##X(T, 2)
737#define def3(X, T) def2(X, T) def##X(T, 3)
738#define def4(X, T) def3(X, T) def##X(T, 4)
739#define def5(X, T) def4(X, T) def##X(T, 5)
740#define def6(X, T) def5(X, T) def##X(T, 6)
741#define def7(X, T) def6(X, T) def##X(T, 7)
742#define def8(X, T) def7(X, T) def##X(T, 8)
743#define def9(X, T) def8(X, T) def##X(T, 9)
744#define def10(X, T) def9(X, T) def##X(T, 10)
745#define def11(X, T) def10(X, T) def##X(T, 11)
746#define def12(X, T) def11(X, T) def##X(T, 12)
747#define def13(X, T) def12(X, T) def##X(T, 13)
748#define def14(X, T) def13(X, T) def##X(T, 14)
749#define def15(X, T) def14(X, T) def##X(T, 15)
750#define def(T) def15(i, T)
751 def(_c)
752 def(_uc)
753 def(_s)
754 def(_us)
755 def(_i)
756#if __WORDSIZE == 64
757 def(_ui)
758 def(_l)
759#endif
760#undef def
761#define def(T) def15(f, T)
762 def(_f)
763 def(_d)
764#undef def
765
766 jit_patch(jmpi_main);
767 jit_name("main");
768 jit_note("ccall.c", __LINE__);
769 jit_prolog();
770
771#define push0(T) /**/
772#define push1(T) jit_pushargi##T(1);
773#define push2(T) push1(T) jit_pushargi##T(2);
774#define push3(T) push2(T) jit_pushargi##T(3);
775#define push4(T) push3(T) jit_pushargi##T(4);
776#define push5(T) push4(T) jit_pushargi##T(5);
777#define push6(T) push5(T) jit_pushargi##T(6);
778#define push7(T) push6(T) jit_pushargi##T(7);
779#define push8(T) push7(T) jit_pushargi##T(8);
780#define push9(T) push8(T) jit_pushargi##T(9);
781#define push10(T) push9(T) jit_pushargi##T(10);
782#define push11(T) push10(T) jit_pushargi##T(11);
783#define push12(T) push11(T) jit_pushargi##T(12);
784#define push13(T) push12(T) jit_pushargi##T(13);
785#define push14(T) push13(T) jit_pushargi##T(14);
786#define push15(T) push14(T) jit_pushargi##T(15);
787
788#define calin(T,N) \
789 jit_prepare(); \
79bfeef6 790 push##N(T) \
4a71579b
PC
791 jit_finishi(C##T##N); \
792 jit_retval##T(JIT_R0); \
793 jmp = jit_beqi(JIT_R0, T##N); \
794 jit_calli(abort); \
795 jit_patch(jmp);
796#define calfn(T,N) \
797 jit_prepare(); \
798 push##N(T) \
799 jit_finishi(C##T##N); \
800 jit_retval##T(JIT_F0); \
801 jmp = jit_beqi##T(JIT_F0, _w##N); \
802 jit_calli(abort); \
803 jit_patch(jmp);
804#define calx0(X,T) cal##X##n(T,0)
805#define calx1(X,T) calx0(X,T) cal##X##n(T,1)
806#define calx2(X,T) calx1(X,T) cal##X##n(T,2)
807#define calx3(X,T) calx2(X,T) cal##X##n(T,3)
808#define calx4(X,T) calx3(X,T) cal##X##n(T,4)
809#define calx5(X,T) calx4(X,T) cal##X##n(T,5)
810#define calx6(X,T) calx5(X,T) cal##X##n(T,6)
811#define calx7(X,T) calx6(X,T) cal##X##n(T,7)
812#define calx8(X,T) calx7(X,T) cal##X##n(T,8)
813#define calx9(X,T) calx8(X,T) cal##X##n(T,9)
814#define calx10(X,T) calx9(X,T) cal##X##n(T,10)
815#define calx11(X,T) calx10(X,T) cal##X##n(T,11)
816#define calx12(X,T) calx11(X,T) cal##X##n(T,12)
817#define calx13(X,T) calx12(X,T) cal##X##n(T,13)
818#define calx14(X,T) calx13(X,T) cal##X##n(T,14)
819#define calx15(X,T) calx14(X,T) cal##X##n(T,15)
820#define cali(T) calx15(i,T)
821#define calf(T) calx15(f,T)
822
823 cali(_c)
824 cali(_uc)
825 cali(_s)
826 cali(_us)
827 cali(_i)
828#if __WORDSIZE == 64
829 cali(_ui)
830 cali(_l)
831#endif
832 calf(_f)
833 calf(_d)
834
835#undef calin
836#undef calfn
837#define calin(T,N) \
838 jit_prepare(); \
79bfeef6 839 push##N(T) \
4a71579b
PC
840 jit_finishi(CJ##T##N); \
841 jit_retval##T(JIT_R0); \
842 jmp = jit_beqi(JIT_R0, T##N); \
843 jit_calli(abort); \
844 jit_patch(jmp);
845#define calfn(T,N) \
846 jit_prepare(); \
847 push##N(T) \
848 jit_finishi(CJ##T##N); \
849 jit_retval##T(JIT_F0); \
850 jmp = jit_beqi##T(JIT_F0, _w##N); \
851 jit_calli(abort); \
852 jit_patch(jmp);
853 cali(_c)
854 cali(_uc)
855 cali(_s)
856 cali(_us)
857 cali(_i)
858#if __WORDSIZE == 64
859 cali(_ui)
860 cali(_l)
861#endif
862 calf(_f)
863 calf(_d)
864
865 jit_ret();
866
867 function = jit_emit();
868
869#define initn(T,N) j##T##N = jit_address(n##T##N);
870#define init0(T) initn(T,0)
871#define init1(T) init0(T) initn(T,1)
872#define init2(T) init1(T) initn(T,2)
873#define init3(T) init2(T) initn(T,3)
874#define init4(T) init3(T) initn(T,4)
875#define init5(T) init4(T) initn(T,5)
876#define init6(T) init5(T) initn(T,6)
877#define init7(T) init6(T) initn(T,7)
878#define init8(T) init7(T) initn(T,8)
879#define init9(T) init8(T) initn(T,9)
880#define init10(T) init9(T) initn(T,10)
881#define init11(T) init10(T) initn(T,11)
882#define init12(T) init11(T) initn(T,12)
883#define init13(T) init12(T) initn(T,13)
884#define init14(T) init13(T) initn(T,14)
885#define init15(T) init14(T) initn(T,15)
886#define init(T) init15(T)
887 init(_c)
888 init(_uc)
889 init(_s)
890 init(_us)
891 init(_i)
892#if __WORDSIZE == 64
893 init(_ui)
894 init(_l)
895#endif
896 init(_f)
897 init(_d)
898
899#if 0
900 jit_print();
901 jit_disassemble();
902#endif
903
904 jit_clear_state();
905 (*function)();
906 jit_destroy_state();
907
908 finish_jit();
909
910 printf("ok\n");
911
912 return (0);
913}