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 
135 /*
136  * Types
137  */
138 typedef signed char		_c;
139 typedef unsigned char		_uc;
140 typedef signed short		_s;
141 typedef unsigned short		_us;
142 typedef signed int		_i;
143 #if __WORDSIZE == 64
144 typedef unsigned int		_ui;
145 typedef signed long		_l;
146 #endif
147 typedef float			_f;
148 typedef double			_d;
149 
150 #define prt0(T)			T C##T##0(void);
151 #define prt1(T)			prt0(T)					\
152 				T C##T##1(T);
153 #define prt2(T)			prt1(T)					\
154 				T C##T##2(T,T);
155 #define prt3(T)			prt2(T)					\
156 				T C##T##3(T,T,T);
157 #define prt4(T)			prt3(T)					\
158 				T C##T##4(T,T,T,T);
159 #define prt5(T)			prt4(T)					\
160 				T C##T##5(T,T,T,T,T);
161 #define prt6(T)			prt5(T)					\
162 				T C##T##6(T,T,T,T,T,T);
163 #define prt7(T)			prt6(T)					\
164 				T C##T##7(T,T,T,T,T,T,T);
165 #define prt8(T)			prt7(T)					\
166 				T C##T##8(T,T,T,T,T,T,T,T);
167 #define prt9(T)			prt8(T)					\
168 				T C##T##9(T,T,T,T,T,T,T,T,T);
169 #define prt10(T)		prt9(T)					\
170 				T C##T##10(T,T,T,T,T,T,T,T,T,T);
171 #define prt11(T)		prt10(T)				\
172 				T C##T##11(T,T,T,T,T,T,T,T,T,T,T);
173 #define prt12(T)		prt11(T)				\
174 				T C##T##12(T,T,T,T,T,T,T,T,T,T,T,T);
175 #define prt13(T)		prt12(T)				\
176 				T C##T##13(T,T,T,T,T,T,T,T,T,T,T,T,T);
177 #define prt14(T)		prt13(T)				\
178 				T C##T##14(T,T,T,T,T,T,T,T,T,T,T,T,T,T);
179 #define prt15(T)		prt14(T)				\
180 				T C##T##15(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);
181 #define prt(T)			prt15(T)
182 prt(_c)
prt(_uc)183 prt(_uc)
184 prt(_s)
185 prt(_us)
186 prt(_i)
187 #if __WORDSIZE == 64
188 prt(_ui)
189 prt(_l)
190 #endif
191 prt(_f)
192 prt(_d)
193 #undef prt
194 #undef prt15
195 #undef prt14
196 #undef prt13
197 #undef prt12
198 #undef prt11
199 #undef prt10
200 #undef prt9
201 #undef prt8
202 #undef prt7
203 #undef prt6
204 #undef prt5
205 #undef prt4
206 #undef prt3
207 #undef prt2
208 #undef prt1
209 #undef prt0
210 
211 #define prtn(N,T)		T J##T##n(void);
212 #define prt0(T)			prtn(0,T)
213 #define prt1(T)			prt0(T)			prtn(1,T)
214 #define prt2(T)			prt1(T)			prtn(2,T)
215 #define prt3(T)			prt2(T)			prtn(3,T)
216 #define prt4(T)			prt3(T)			prtn(4,T)
217 #define prt5(T)			prt4(T)			prtn(5,T)
218 #define prt6(T)			prt5(T)			prtn(6,T)
219 #define prt7(T)			prt6(T)			prtn(7,T)
220 #define prt8(T)			prt7(T)			prtn(8,T)
221 #define prt9(T)			prt8(T)			prtn(9,T)
222 #define prt10(T)		prt9(T)			prtn(10,T)
223 #define prt11(T)		prt10(T)		prtn(11,T)
224 #define prt12(T)		prt11(T)		prtn(12,T)
225 #define prt13(T)		prt12(T)		prtn(13,T)
226 #define prt14(T)		prt13(T)		prtn(14,T)
227 #define prt15(T)		prt14(T)		prtn(15,T)
228 #define prt(T)			prt15(T)
229 prt(_c)
230 prt(_uc)
231 prt(_s)
232 prt(_us)
233 prt(_i)
234 #if __WORDSIZE == 64
235 prt(_ui)
236 prt(_l)
237 #endif
238 prt(_f)
239 prt(_d)
240 #undef prt
241 #undef prt15
242 #undef prt14
243 #undef prt13
244 #undef prt12
245 #undef prt11
246 #undef prt10
247 #undef prt9
248 #undef prt8
249 #undef prt7
250 #undef prt6
251 #undef prt5
252 #undef prt4
253 #undef prt3
254 #undef prt2
255 #undef prt1
256 #undef prt0
257 #undef prtn
258 
259 /*
260  * Initialization
261  */
262 
263 #define dat0(T)			T (*j##T##0)(void);			\
264 				jit_node_t *n##T##0;
265 #define dat1(T)			dat0(T)					\
266 				T (*j##T##1)(T);			\
267 				jit_node_t *n##T##1;
268 #define dat2(T)			dat1(T)					\
269 				T (*j##T##2)(T,T);			\
270 				jit_node_t *n##T##2;
271 #define dat3(T)			dat2(T)					\
272 				T (*j##T##3)(T,T,T);			\
273 				jit_node_t *n##T##3;
274 #define dat4(T)			dat3(T)					\
275 				T (*j##T##4)(T,T,T,T);			\
276 				jit_node_t *n##T##4;
277 #define dat5(T)			dat4(T)					\
278 				T (*j##T##5)(T,T,T,T,T);		\
279 				jit_node_t *n##T##5;
280 #define dat6(T)			dat5(T)					\
281 				T (*j##T##6)(T,T,T,T,T,T);		\
282 				jit_node_t *n##T##6;
283 #define dat7(T)			dat6(T)					\
284 				T (*j##T##7)(T,T,T,T,T,T,T);		\
285 				jit_node_t *n##T##7;
286 #define dat8(T)			dat7(T)					\
287 				T (*j##T##8)(T,T,T,T,T,T,T,T);		\
288 				jit_node_t *n##T##8;
289 #define dat9(T)			dat8(T)					\
290 				T (*j##T##9)(T,T,T,T,T,T,T,T,T);	\
291 				jit_node_t *n##T##9;
292 #define dat10(T)		dat9(T)					\
293 				T (*j##T##10)(T,T,T,T,T,T,T,T,T,T);	\
294 				jit_node_t *n##T##10;
295 #define dat11(T)		dat10(T)				\
296 				T (*j##T##11)(T,T,T,T,T,T,T,T,T,T,T);	\
297 				jit_node_t *n##T##11;
298 #define dat12(T)		dat11(T)				\
299 				T (*j##T##12)(T,T,T,T,T,T,T,T,T,T,T,T);	\
300 				jit_node_t *n##T##12;
301 #define dat13(T)		dat12(T)				\
302 				T (*j##T##13)(T,T,T,T,T,T,T,T,T,T,T,T,T);\
303 				jit_node_t *n##T##13;
304 #define dat14(T)		dat13(T)				\
305 				T (*j##T##14)(T,T,T,T,T,T,T,T,T,T,T,T,T,T);\
306 				jit_node_t *n##T##14;
307 #define dat15(T)		dat14(T)				\
308 				T (*j##T##15)(T,T,T,T,T,T,T,T,T,T,T,T,T,T,T);\
309 				jit_node_t *n##T##15;
310 #define dat(T)			dat15(T)
311 dat(_c)
312 dat(_uc)
313 dat(_s)
314 dat(_us)
315 dat(_i)
316 #if __WORDSIZE == 64
317 dat(_ui)
318 dat(_l)
319 #endif
320 dat(_f)
321 dat(_d)
322 #undef dat
323 #undef dat15
324 #undef dat14
325 #undef dat13
326 #undef dat12
327 #undef dat11
328 #undef dat10
329 #undef dat9
330 #undef dat8
331 #undef dat7
332 #undef dat6
333 #undef dat5
334 #undef dat4
335 #undef dat3
336 #undef dat2
337 #undef dat1
338 #undef dat0
339 
340 /*
341  * Implementation
342  */
343 #define dcl0(T)								\
344 T C##T##0(void)								\
345 {									\
346     return (0);								\
347 }
348 #define dcl1(T)								\
349 dcl0(T)									\
350 T C##T##1(T A)								\
351 {									\
352     return (A);								\
353 }
354 #define dcl2(T)								\
355 dcl1(T)									\
356 T C##T##2(T A,T B)							\
357 {									\
358     return (A-B);							\
359 }
360 #define dcl3(T)								\
361 dcl2(T)									\
362 T C##T##3(T A,T B,T C)							\
363 {									\
364     return (A-B-C);							\
365 }
366 #define dcl4(T)								\
367 dcl3(T)									\
368 T C##T##4(T A,T B,T C,T D)						\
369 {									\
370     return (A-B-C-D);							\
371 }
372 #define dcl5(T)								\
373 dcl4(T)									\
374 T C##T##5(T A,T B,T C,T D,T E)						\
375 {									\
376     return (A-B-C-D-E);							\
377 }
378 #define dcl6(T)								\
379 dcl5(T)									\
380 T C##T##6(T A,T B,T C,T D,T E,T F)					\
381 {									\
382     return (A-B-C-D-E-F);						\
383 }
384 #define dcl7(T)								\
385 dcl6(T)									\
386 T C##T##7(T A,T B,T C,T D,T E,T F,T G)					\
387 {									\
388     return (A-B-C-D-E-F-G);						\
389 }
390 #define dcl8(T)								\
391 dcl7(T)									\
392 T C##T##8(T A,T B,T C,T D,T E,T F,T G,T H)				\
393 {									\
394     return (A-B-C-D-E-F-G-H);						\
395 }
396 #define dcl9(T)								\
397 dcl8(T)									\
398 T C##T##9(T A,T B,T C,T D,T E,T F,T G,T H,T I)				\
399 {									\
400     return (A-B-C-D-E-F-G-H-I);						\
401 }
402 #define dcl10(T)							\
403 dcl9(T)									\
404 T C##T##10(T A,T B,T C,T D,T E,T F,T G,T H,T I,T J)			\
405 {									\
406     return (A-B-C-D-E-F-G-H-I-J);					\
407 }
408 #define dcl11(T)							\
409 dcl10(T)								\
410 T 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)			\
411 {									\
412     return (A-B-C-D-E-F-G-H-I-J-K);					\
413 }
414 #define dcl12(T)							\
415 dcl11(T)								\
416 T 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)		\
417 {									\
418     return (A-B-C-D-E-F-G-H-I-J-K-L);					\
419 }
420 #define dcl13(T)							\
421 dcl12(T)								\
422 T 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)		\
423 {									\
424     return (A-B-C-D-E-F-G-H-I-J-K-L-M);					\
425 }
426 #define dcl14(T)							\
427 dcl13(T)								\
428 T 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)	\
429 {									\
430     return (A-B-C-D-E-F-G-H-I-J-K-L-M-N);				\
431 }
432 #define dcl15(T)							\
433 dcl14(T)								\
434 T 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)	\
435 {									\
436     return (A-B-C-D-E-F-G-H-I-J-K-L-M-N-O);				\
437 }
438 #define dcl(T)	dcl15(T)
439 dcl(_c)
440 dcl(_uc)
441 dcl(_s)
442 dcl(_us)
443 dcl(_i)
444 #if __WORDSIZE == 64
445 dcl(_ui)
446 dcl(_l)
447 #endif
448 dcl(_f)
449 dcl(_d)
450 #undef dcl
451 #undef dcl15
452 #undef dcl14
453 #undef dcl13
454 #undef dcl12
455 #undef dcl11
456 #undef dcl10
457 #undef dcl9
458 #undef dcl8
459 #undef dcl7
460 #undef dcl6
461 #undef dcl5
462 #undef dcl4
463 #undef dcl3
464 #undef dcl2
465 #undef dcl1
466 #undef dcl0
467 
468 #define dcl0(T)								\
469 T CJ##T##0(void)							\
470 {									\
471     return ((*j##T##0)());						\
472 }
473 #define dcl1(T)								\
474 dcl0(T)									\
475 T CJ##T##1(void)							\
476 {									\
477     return ((*j##T##1)(1));						\
478 }
479 #define dcl2(T)								\
480 dcl1(T)									\
481 T CJ##T##2(void)							\
482 {									\
483     return ((*j##T##2)(1,2));						\
484 }
485 #define dcl3(T)								\
486 dcl2(T)									\
487 T CJ##T##3(void)							\
488 {									\
489     return ((*j##T##3)(1,2,3));						\
490 }
491 #define dcl4(T)								\
492 dcl3(T)									\
493 T CJ##T##4(void)							\
494 {									\
495     return ((*j##T##4)(1,2,3,4));					\
496 }
497 #define dcl5(T)								\
498 dcl4(T)									\
499 T CJ##T##5(void)							\
500 {									\
501     return ((*j##T##5)(1,2,3,4,5));					\
502 }
503 #define dcl6(T)								\
504 dcl5(T)									\
505 T CJ##T##6(void)							\
506 {									\
507     return ((*j##T##6)(1,2,3,4,5,6));					\
508 }
509 #define dcl7(T)								\
510 dcl6(T)									\
511 T CJ##T##7(void)							\
512 {									\
513     return ((*j##T##7)(1,2,3,4,5,6,7));					\
514 }
515 #define dcl8(T)								\
516 dcl7(T)									\
517 T CJ##T##8(void)							\
518 {									\
519     return ((*j##T##8)(1,2,3,4,5,6,7,8));				\
520 }
521 #define dcl9(T)								\
522 dcl8(T)									\
523 T CJ##T##9(void)							\
524 {									\
525     return ((*j##T##9)(1,2,3,4,5,6,7,8,9));				\
526 }
527 #define dcl10(T)							\
528 dcl9(T)									\
529 T CJ##T##10(void)							\
530 {									\
531     return ((*j##T##10)(1,2,3,4,5,6,7,8,9,10));				\
532 }
533 #define dcl11(T)							\
534 dcl10(T)								\
535 T CJ##T##11(void)							\
536 {									\
537     return ((*j##T##11)(1,2,3,4,5,6,7,8,9,10,11));			\
538 }
539 #define dcl12(T)							\
540 dcl11(T)								\
541 T CJ##T##12(void)							\
542 {									\
543     return ((*j##T##12)(1,2,3,4,5,6,7,8,9,10,11,12));			\
544 }
545 #define dcl13(T)							\
546 dcl12(T)								\
547 T CJ##T##13(void)							\
548 {									\
549     return ((*j##T##13)(1,2,3,4,5,6,7,8,9,10,11,12,13));		\
550 }
551 #define dcl14(T)							\
552 dcl13(T)								\
553 T CJ##T##14(void)							\
554 {									\
555     return ((*j##T##14)(1,2,3,4,5,6,7,8,9,10,11,12,13,14));		\
556 }
557 #define dcl15(T)							\
558 dcl14(T)								\
559 T CJ##T##15(void)							\
560 {									\
561     return ((*j##T##15)(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));		\
562 }
563 #define dcl(t)	dcl15(t)
564 dcl(_c)
565 dcl(_uc)
566 dcl(_s)
567 dcl(_us)
568 dcl(_i)
569 #if __WORDSIZE == 64
570 dcl(_ui)
571 dcl(_l)
572 #endif
573 dcl(_f)
574 dcl(_d)
575 #undef dcl
576 #undef dcl15
577 #undef dcl14
578 #undef dcl13
579 #undef dcl12
580 #undef dcl11
581 #undef dcl10
582 #undef dcl9
583 #undef dcl8
584 #undef dcl7
585 #undef dcl6
586 #undef dcl5
587 #undef dcl4
588 #undef dcl3
589 #undef dcl2
590 #undef dcl1
591 #undef dcl0
592 
593 int
594 main(int argc, char *argv[])
595 {
596     jit_state_t		 *_jit;
597     jit_node_t		 *jmpi_main;
598     void		(*function)(void);
599     jit_node_t		 *a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9;
600     jit_node_t		 *a10,*a11,*a12,*a13,*a14,*a15;
601     jit_node_t		 *jmp;
602 
603     init_jit(argv[0]);
604     _jit = jit_new_state();
605 
606     jmpi_main = jit_jmpi();
607 
608 
609 #define arg0(T)			/**/
610 #define arg1(T)						a1 = jit_arg##T();
611 #define arg2(T)			arg1(T)			a2 = jit_arg##T();
612 #define arg3(T)			arg2(T)			a3 = jit_arg##T();
613 #define arg4(T)			arg3(T)			a4 = jit_arg##T();
614 #define arg5(T)			arg4(T)			a5 = jit_arg##T();
615 #define arg6(T)			arg5(T)			a6 = jit_arg##T();
616 #define arg7(T)			arg6(T)			a7 = jit_arg##T();
617 #define arg8(T)			arg7(T)			a8 = jit_arg##T();
618 #define arg9(T)			arg8(T)			a9 = jit_arg##T();
619 #define arg10(T)		arg9(T)			a10 = jit_arg##T();
620 #define arg11(T)		arg10(T)		a11 = jit_arg##T();
621 #define arg12(T)		arg11(T)		a12 = jit_arg##T();
622 #define arg13(T)		arg12(T)		a13 = jit_arg##T();
623 #define arg14(T)		arg13(T)		a14 = jit_arg##T();
624 #define arg15(T)		arg14(T)		a15 = jit_arg##T();
625 
626 #define get0(B,T,R)		jit_movi##B(R##0,0);
627 #define get1(B,T,R)		jit_getarg##B(R##0,a##1);
628 #define get2(B,T,R)							\
629 	get1(B,T,R);							\
630 	jit_movr##B(R##1, R##0);					\
631 	jit_getarg##T(R##0, a##2);					\
632 	jit_subr##B(R##0, R##1, R##0);
633 #define get3(B,T,R)							\
634 	get2(B,T,R);							\
635 	jit_movr##B(R##1, R##0);					\
636 	jit_getarg##T(R##0, a##3);					\
637 	jit_subr##B(R##0, R##1, R##0);
638 #define get4(B,T,R)							\
639 	get3(B,T,R);							\
640 	jit_movr##B(R##1, R##0);					\
641 	jit_getarg##T(R##0, a##4);					\
642 	jit_subr##B(R##0, R##1, R##0);
643 #define get5(B,T,R)							\
644 	get4(B,T,R);							\
645 	jit_movr##B(R##1, R##0);					\
646 	jit_getarg##T(R##0, a##5);					\
647 	jit_subr##B(R##0, R##1, R##0);
648 #define get6(B,T,R)							\
649 	get5(B,T,R);							\
650 	jit_movr##B(R##1, R##0);					\
651 	jit_getarg##T(R##0, a##6);					\
652 	jit_subr##B(R##0, R##1, R##0);
653 #define get7(B,T,R)							\
654 	get6(B,T,R);							\
655 	jit_movr##B(R##1, R##0);					\
656 	jit_getarg##T(R##0, a##7);					\
657 	jit_subr##B(R##0, R##1, R##0);
658 #define get8(B,T,R)							\
659 	get7(B,T,R);							\
660 	jit_movr##B(R##1, R##0);					\
661 	jit_getarg##T(R##0, a##8);					\
662 	jit_subr##B(R##0, R##1, R##0);
663 #define get9(B,T,R)							\
664 	get8(B,T,R);							\
665 	jit_movr##B(R##1, R##0);					\
666 	jit_getarg##T(R##0, a##9);					\
667 	jit_subr##B(R##0, R##1, R##0);
668 #define get10(B,T,R)							\
669 	get9(B,T,R);							\
670 	jit_movr##B(R##1, R##0);					\
671 	jit_getarg##T(R##0, a##10);					\
672 	jit_subr##B(R##0, R##1, R##0);
673 #define get11(B,T,R)							\
674 	get10(B,T,R);							\
675 	jit_movr##B(R##1, R##0);					\
676 	jit_getarg##T(R##0, a##11);					\
677 	jit_subr##B(R##0, R##1, R##0);
678 #define get12(B,T,R)							\
679 	get11(B,T,R);							\
680 	jit_movr##B(R##1, R##0);					\
681 	jit_getarg##T(R##0, a##12);					\
682 	jit_subr##B(R##0, R##1, R##0);
683 #define get13(B,T,R)							\
684 	get12(B,T,R);							\
685 	jit_movr##B(R##1, R##0);					\
686 	jit_getarg##T(R##0, a##13);					\
687 	jit_subr##B(R##0, R##1, R##0);
688 #define get14(B,T,R)							\
689 	get13(B,T,R);							\
690 	jit_movr##B(R##1, R##0);					\
691 	jit_getarg##T(R##0, a##14);					\
692 	jit_subr##B(R##0, R##1, R##0);
693 #define get15(B,T,R)							\
694 	get14(B,T,R);							\
695 	jit_movr##B(R##1, R##0);					\
696 	jit_getarg##T(R##0, a##15);					\
697 	jit_subr##B(R##0, R##1, R##0);
698 
699 #if __WORDSIZE == 32
700 #  define jit_extr_i(u, v)			/**/
701 #else
702 #  define jit_extr_l(u, v)			/**/
703 #endif
704 
705 #define strfy(n)				#n
706 #define defi(T, N)							\
707     n##T##N = jit_name(strfy(n##T##N));					\
708     jit_note("ccall.c", __LINE__);					\
709     jit_prolog();							\
710     arg##N();								\
711     get##N(,T,JIT_R)							\
712     jit_extr##T(JIT_R0, JIT_R0);					\
713     jit_retr(JIT_R0);							\
714     jit_epilog();
715 #define deff(T, N)							\
716     n##T##N = jit_name(strfy(n##T##N));					\
717     jit_note("ccall.c", __LINE__);					\
718     jit_prolog();							\
719     arg##N(T);								\
720     get##N(T,T,JIT_F);							\
721     jit_retr##T(JIT_F0);						\
722     jit_epilog();
723 
724 #define  def0(X, T)				def##X(T, 0)
725 #define  def1(X, T)	def0(X, T)		def##X(T, 1)
726 #define  def2(X, T)	def1(X, T)		def##X(T, 2)
727 #define  def3(X, T)	def2(X, T)		def##X(T, 3)
728 #define  def4(X, T)	def3(X, T)		def##X(T, 4)
729 #define  def5(X, T)	def4(X, T)		def##X(T, 5)
730 #define  def6(X, T)	def5(X, T)		def##X(T, 6)
731 #define  def7(X, T)	def6(X, T)		def##X(T, 7)
732 #define  def8(X, T)	def7(X, T)		def##X(T, 8)
733 #define  def9(X, T)	def8(X, T)		def##X(T, 9)
734 #define def10(X, T)	def9(X, T)		def##X(T, 10)
735 #define def11(X, T)	def10(X, T)		def##X(T, 11)
736 #define def12(X, T)	def11(X, T)		def##X(T, 12)
737 #define def13(X, T)	def12(X, T)		def##X(T, 13)
738 #define def14(X, T)	def13(X, T)		def##X(T, 14)
739 #define def15(X, T)	def14(X, T)		def##X(T, 15)
740 #define def(T)		def15(i, T)
741 	def(_c)
742 	def(_uc)
743 	def(_s)
744 	def(_us)
745 	def(_i)
746 #if __WORDSIZE == 64
747 	def(_ui)
748 	def(_l)
749 #endif
750 #undef def
751 #define def(T)		def15(f, T)
752 	def(_f)
753 	def(_d)
754 #undef def
755 
756     jit_patch(jmpi_main);
757     jit_name("main");
758     jit_note("ccall.c", __LINE__);
759     jit_prolog();
760 
761 #define  push0(T)	/**/
762 #define  push1(T)				jit_pushargi##T(1);
763 #define  push2(T)	push1(T)		jit_pushargi##T(2);
764 #define  push3(T)	push2(T)		jit_pushargi##T(3);
765 #define  push4(T)	push3(T)		jit_pushargi##T(4);
766 #define  push5(T)	push4(T)		jit_pushargi##T(5);
767 #define  push6(T)	push5(T)		jit_pushargi##T(6);
768 #define  push7(T)	push6(T)		jit_pushargi##T(7);
769 #define  push8(T)	push7(T)		jit_pushargi##T(8);
770 #define  push9(T)	push8(T)		jit_pushargi##T(9);
771 #define  push10(T)	push9(T)		jit_pushargi##T(10);
772 #define  push11(T)	push10(T)		jit_pushargi##T(11);
773 #define  push12(T)	push11(T)		jit_pushargi##T(12);
774 #define  push13(T)	push12(T)		jit_pushargi##T(13);
775 #define  push14(T)	push13(T)		jit_pushargi##T(14);
776 #define  push15(T)	push14(T)		jit_pushargi##T(15);
777 
778 #define calin(T,N)							\
779 	jit_prepare();							\
780 		push##N()						\
781 	jit_finishi(C##T##N);						\
782 	jit_retval##T(JIT_R0);						\
783 	jmp = jit_beqi(JIT_R0, T##N);					\
784 	jit_calli(abort);						\
785 	jit_patch(jmp);
786 #define calfn(T,N)							\
787 	jit_prepare();							\
788 		push##N(T)						\
789 	jit_finishi(C##T##N);						\
790 	jit_retval##T(JIT_F0);						\
791 	jmp = jit_beqi##T(JIT_F0, _w##N);				\
792 	jit_calli(abort);						\
793 	jit_patch(jmp);
794 #define  calx0(X,T)				cal##X##n(T,0)
795 #define  calx1(X,T)	calx0(X,T)		cal##X##n(T,1)
796 #define  calx2(X,T)	calx1(X,T)		cal##X##n(T,2)
797 #define  calx3(X,T)	calx2(X,T)		cal##X##n(T,3)
798 #define  calx4(X,T)	calx3(X,T)		cal##X##n(T,4)
799 #define  calx5(X,T)	calx4(X,T)		cal##X##n(T,5)
800 #define  calx6(X,T)	calx5(X,T)		cal##X##n(T,6)
801 #define  calx7(X,T)	calx6(X,T)		cal##X##n(T,7)
802 #define  calx8(X,T)	calx7(X,T)		cal##X##n(T,8)
803 #define  calx9(X,T)	calx8(X,T)		cal##X##n(T,9)
804 #define calx10(X,T)	calx9(X,T)		cal##X##n(T,10)
805 #define calx11(X,T)	calx10(X,T)		cal##X##n(T,11)
806 #define calx12(X,T)	calx11(X,T)		cal##X##n(T,12)
807 #define calx13(X,T)	calx12(X,T)		cal##X##n(T,13)
808 #define calx14(X,T)	calx13(X,T)		cal##X##n(T,14)
809 #define calx15(X,T)	calx14(X,T)		cal##X##n(T,15)
810 #define cali(T)		calx15(i,T)
811 #define calf(T)		calx15(f,T)
812 
813     cali(_c)
814     cali(_uc)
815     cali(_s)
816     cali(_us)
817     cali(_i)
818 #if __WORDSIZE == 64
819     cali(_ui)
820     cali(_l)
821 #endif
822     calf(_f)
823     calf(_d)
824 
825 #undef calin
826 #undef calfn
827 #define calin(T,N)							\
828 	jit_prepare();							\
829 		push##N()						\
830 	jit_finishi(CJ##T##N);						\
831 	jit_retval##T(JIT_R0);						\
832 	jmp = jit_beqi(JIT_R0, T##N);					\
833 	jit_calli(abort);						\
834 	jit_patch(jmp);
835 #define calfn(T,N)							\
836 	jit_prepare();							\
837 		push##N(T)						\
838 	jit_finishi(CJ##T##N);						\
839 	jit_retval##T(JIT_F0);						\
840 	jmp = jit_beqi##T(JIT_F0, _w##N);				\
841 	jit_calli(abort);						\
842 	jit_patch(jmp);
843     cali(_c)
844     cali(_uc)
845     cali(_s)
846     cali(_us)
847     cali(_i)
848 #if __WORDSIZE == 64
849     cali(_ui)
850     cali(_l)
851 #endif
852     calf(_f)
853     calf(_d)
854 
855     jit_ret();
856 
857     function = jit_emit();
858 
859 #define initn(T,N)	j##T##N = jit_address(n##T##N);
860 #define init0(T)			initn(T,0)
861 #define init1(T)	 init0(T)	initn(T,1)
862 #define init2(T)	 init1(T)	initn(T,2)
863 #define init3(T)	 init2(T)	initn(T,3)
864 #define init4(T)	 init3(T)	initn(T,4)
865 #define init5(T)	 init4(T)	initn(T,5)
866 #define init6(T)	 init5(T)	initn(T,6)
867 #define init7(T)	 init6(T)	initn(T,7)
868 #define init8(T)	 init7(T)	initn(T,8)
869 #define init9(T)	 init8(T)	initn(T,9)
870 #define init10(T)	 init9(T)	initn(T,10)
871 #define init11(T)	init10(T)	initn(T,11)
872 #define init12(T)	init11(T)	initn(T,12)
873 #define init13(T)	init12(T)	initn(T,13)
874 #define init14(T)	init13(T)	initn(T,14)
875 #define init15(T)	init14(T)	initn(T,15)
876 #define init(T)		init15(T)
877     init(_c)
878     init(_uc)
879     init(_s)
880     init(_us)
881     init(_i)
882 #if __WORDSIZE == 64
883     init(_ui)
884     init(_l)
885 #endif
886     init(_f)
887     init(_d)
888 
889 #if 0
890     jit_print();
891     jit_disassemble();
892 #endif
893 
894     jit_clear_state();
895     (*function)();
896     jit_destroy_state();
897 
898     finish_jit();
899 
900     printf("ok\n");
901 
902     return (0);
903 }
904