4 /* Simple test for arguments handling, that also shows how to use
5 * arguments to store values.
6 * Register arguments, if available, are very fast, but are also
7 * very volatile on some ports, because some ports will do C calls
8 * to implement division, remainder, sometimes multiplication, or
9 * some float operations.
10 * Arguments in registers should be fetched in the prolog of the
11 * function, and if they must be saved, they should be saved in
13 * The predicate macro "jit_arg_register_p(arg)" allows knowing if
14 * an argument lives in a register, where it is known for being a very
15 * fast to read/write temporary storage.
19 #define F jit_float32_t
20 #define D jit_float64_t
25 cw(W a1, W a2, W a3, W a4, W a5, W a6, W a7, W a8,
26 W a9, W a10, W a11, W a12, W a13, W a14, W a15, W a16)
28 if ( a1 != 1 || a2 != 2 || a3 != 3 || a4 != 4 ||
29 a5 != 5 || a6 != 6 || a7 != 7 || a8 != 8 ||
30 a9 != 9 || a10 != 10 || a11 != 11 || a12 != 12 ||
31 a13 != 13 || a14 != 14 || a15 != 15 || a16 != 16)
36 cf(F a1, F a2, F a3, F a4, F a5, F a6, F a7, F a8,
37 F a9, F a10, F a11, F a12, F a13, F a14, F a15, F a16)
39 if ( a1 != 1 || a2 != 2 || a3 != 3 || a4 != 4 ||
40 a5 != 5 || a6 != 6 || a7 != 7 || a8 != 8 ||
41 a9 != 9 || a10 != 10 || a11 != 11 || a12 != 12 ||
42 a13 != 13 || a14 != 14 || a15 != 15 || a16 != 16)
47 cd(D a1, D a2, D a3, D a4, D a5, D a6, D a7, D a8,
48 D a9, D a10, D a11, D a12, D a13, D a14, D a15, D a16)
50 if ( a1 != 1 || a2 != 2 || a3 != 3 || a4 != 4 ||
51 a5 != 5 || a6 != 6 || a7 != 7 || a8 != 8 ||
52 a9 != 9 || a10 != 10 || a11 != 11 || a12 != 12 ||
53 a13 != 13 || a14 != 14 || a15 != 15 || a16 != 16)
58 main(int argc, char *argv[])
61 jit_node_t *jmp, *pass, *fail;
62 jit_node_t *jw, *jf, *jd;
63 jit_int32_t s1, s2, s3, s4, s5, s6, s7, s8,
64 s9, s10, s11, s12, s13, s14, s15, s16;
65 jit_node_t *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8,
66 *a9, *a10, *a11, *a12, *a13, *a14, *a15, *a16;
69 _jit = jit_new_state();
71 /* jump to "main" label */
74 /* Create jit function that
75 * o Receives 16 word arguments
76 * o Save in the stack any register argument. Also force register
77 * arguments to be clobbered to properly make the test
78 * o Calls a C function that receives 16 word arguments, with
79 * values different from the ones received by this function
80 * o Reload from stack any register argument
81 * o Validated all arguments were not modified in the known
82 * cases it could have been clobbered
86 jit_note(__FILE__, __LINE__);
104 #define SAVE_ARG(N) \
106 if (jit_arg_register_p(a##N)) { \
107 s##N = jit_allocai(sizeof(W)); \
108 jit_getarg(JIT_R0, a##N); \
109 jit_stxi(s##N, JIT_FP, JIT_R0); \
110 jit_putargi(-1, a##N); \
150 #define LOAD_ARG(N) \
152 if (jit_arg_register_p(a##N)) { \
153 jit_ldxi(JIT_R0, JIT_FP, s##N); \
154 jit_putargr(JIT_R0, a##N); \
174 pass = jit_forward();
175 fail = jit_forward();
176 #define CHECK_ARG(N) \
178 jit_getarg(JIT_R0, a##N); \
179 jit_patch_at(jit_bnei(JIT_R0, 17 - N), fail); \
198 jit_patch_at(jit_jmpi(), pass);
205 /* Create jit function that
206 * o Receives 16 float arguments
207 * o Save in the stack any register argument. Also force register
208 * arguments to be clobbered to properly make the test
209 * o Calls a C function that receives 16 float arguments, with
210 * values different from the ones received by this function
211 * o Reload from stack any register argument
212 * o Validated all arguments were not modified in the known
213 * cases it could have been clobbered
217 jit_note(__FILE__, __LINE__);
235 #define SAVE_ARG(N) \
237 if (jit_arg_register_p(a##N)) { \
238 s##N = jit_allocai(sizeof(F)); \
239 jit_getarg_f(JIT_F0, a##N); \
240 jit_stxi_f(s##N, JIT_FP, JIT_F0); \
241 jit_putargi_f(-1, a##N); \
281 #define LOAD_ARG(N) \
283 if (jit_arg_register_p(a##N)) { \
284 jit_ldxi_f(JIT_F0, JIT_FP, s##N); \
285 jit_putargr_f(JIT_F0, a##N); \
305 pass = jit_forward();
306 fail = jit_forward();
307 #define CHECK_ARG(N) \
309 jit_getarg_f(JIT_F0, a##N); \
310 jit_patch_at(jit_bnei_f(JIT_F0, 17 - N), fail); \
329 jit_patch_at(jit_jmpi(), pass);
336 /* Create jit function that
337 * o Receives 16 double arguments
338 * o Save in the stack any register argument. Also force register
339 * arguments to be clobbered to properly make the test
340 * o Calls a C function that receives 16 double arguments, with
341 * values different from the ones received by this function
342 * o Reload from stack any register argument
343 * o Validated all arguments were not modified in the known
344 * cases it could have been clobbered
348 jit_note(__FILE__, __LINE__);
366 #define SAVE_ARG(N) \
368 if (jit_arg_register_p(a##N)) { \
369 s##N = jit_allocai(sizeof(D)); \
370 jit_getarg_d(JIT_F0, a##N); \
371 jit_stxi_d(s##N, JIT_FP, JIT_F0); \
372 jit_putargi_d(-1, a##N); \
412 #define LOAD_ARG(N) \
414 if (jit_arg_register_p(a##N)) { \
415 jit_ldxi_d(JIT_F0, JIT_FP, s##N); \
416 jit_putargr_d(JIT_F0, a##N); \
436 pass = jit_forward();
437 fail = jit_forward();
438 #define CHECK_ARG(N) \
440 jit_getarg_d(JIT_F0, a##N); \
441 jit_patch_at(jit_bnei_d(JIT_F0, 17 - N), fail); \
460 jit_patch_at(jit_jmpi(), pass);
467 /* Create a jit function that calls the 3 previous ones.
468 * o First call the function that receives 16 word arguments
469 * o Then call the function that receives 16 float arguments
470 * o Finally call the function that receives 16 double arguments
474 jit_note(__FILE__, __LINE__);
495 jit_patch_at(jit_finishi(NULL), jw);
516 jit_patch_at(jit_finishi(NULL), jf);
537 jit_patch_at(jit_finishi(NULL), jd);