2 * Copyright (C) 2012-2023 Free Software Foundation, Inc.
4 * This file is part of GNU lightning.
6 * GNU lightning is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 3, or (at your option)
11 * GNU lightning is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
17 * Paulo Cesar Pereira de Andrade
20 #define jit_arg_reg_p(i) ((i) >= 0 && (i) < 8)
22 # define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 13)
24 # define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 8)
26 # define va_gp_shift 2
28 # define va_gp_shift 3
30 # define va_gp_increment sizeof(jit_word_t)
31 # define first_gp_argument r3
32 # define first_gp_offset offsetof(jit_va_list_t, \
34 # define va_fp_increment sizeof(jit_float64_t)
35 # define first_fp_argument f1
36 # define first_fp_offset offsetof(jit_va_list_t, \
39 #if __BYTE_ORDER == __LITTLE_ENDIAN
45 # define C_DISP (__WORDSIZE >> 3) - sizeof(jit_int8_t)
46 # define S_DISP (__WORDSIZE >> 3) - sizeof(jit_int16_t)
47 # define I_DISP (__WORDSIZE >> 3) - sizeof(jit_int32_t)
48 # define F_DISP (__WORDSIZE >> 3) - sizeof(jit_float32_t)
55 typedef struct jit_va_list {
85 typedef jit_pointer_t jit_va_list_t;
91 #define patch(instr, node) _patch(_jit, instr, node)
92 static void _patch(jit_state_t*,jit_word_t,jit_node_t*);
95 extern void __clear_cache(void *, void *);
98 # include "jit_ppc-cpu.c"
99 # include "jit_ppc-fpu.c"
105 jit_register_t _rvs[] = {
106 { rc(sav) | 0, "r0" },
107 { rc(sav) | 11, "r11" }, /* env */
108 { rc(sav) | 12, "r12" }, /* exception */
109 { rc(sav) | 13, "r13" }, /* thread */
110 { rc(sav) | 2, "r2" }, /* toc */
111 { rc(sav) | rc(gpr) | 14, "r14" },
112 { rc(sav) | rc(gpr) | 15, "r15" },
113 { rc(sav) | rc(gpr) | 16, "r16" },
114 { rc(sav) | rc(gpr) | 17, "r17" },
115 { rc(sav) | rc(gpr) | 18, "r18" },
116 { rc(sav) | rc(gpr) | 19, "r19" },
117 { rc(sav) | rc(gpr) | 20, "r20" },
118 { rc(sav) | rc(gpr) | 21, "r21" },
119 { rc(sav) | rc(gpr) | 22, "r22" },
120 { rc(sav) | rc(gpr) | 23, "r23" },
121 { rc(sav) | rc(gpr) | 24, "r24" },
122 { rc(sav) | rc(gpr) | 25, "r25" },
123 { rc(sav) | rc(gpr) | 26, "r26" },
124 { rc(sav) | rc(gpr) | 27, "r27" },
125 { rc(sav) | rc(gpr) | 28, "r28" },
126 { rc(sav) | rc(gpr) | 29, "r29" },
127 { rc(sav) | rc(gpr) | 30, "r30" },
128 { rc(sav) | 1, "r1" },
129 { rc(sav) | 31, "r31" },
130 { rc(arg) | rc(gpr) | 10, "r10" },
131 { rc(arg) | rc(gpr) | 9, "r9" },
132 { rc(arg) | rc(gpr) | 8, "r8" },
133 { rc(arg) | rc(gpr) | 7, "r7" },
134 { rc(arg) | rc(gpr) | 6, "r6" },
135 { rc(arg) | rc(gpr) | 5, "r5" },
136 { rc(arg) | rc(gpr) | 4, "r4" },
137 { rc(arg) | rc(gpr) | 3, "r3" },
138 { rc(fpr) | 0, "f0" },
139 { rc(sav) | rc(fpr) | 14, "f14" },
140 { rc(sav) | rc(fpr) | 15, "f15" },
141 { rc(sav) | rc(fpr) | 16, "f16" },
142 { rc(sav) | rc(fpr) | 17, "f17" },
143 { rc(sav) | rc(fpr) | 18, "f18" },
144 { rc(sav) | rc(fpr) | 19, "f19" },
145 { rc(sav) | rc(fpr) | 20, "f20" },
146 { rc(sav) | rc(fpr) | 21, "f21" },
147 { rc(sav) | rc(fpr) | 22, "f22" },
148 { rc(sav) | rc(fpr) | 23, "f23" },
149 { rc(sav) | rc(fpr) | 24, "f24" },
150 { rc(sav) | rc(fpr) | 25, "f25" },
151 { rc(sav) | rc(fpr) | 26, "f26" },
152 { rc(sav) | rc(fpr) | 27, "f27" },
153 { rc(sav) | rc(fpr) | 28, "f28" },
154 { rc(sav) | rc(fpr) | 29, "f29" },
155 { rc(sav) | rc(fpr) | 30, "f30" },
156 { rc(sav) | rc(fpr) | 31, "f31" },
158 { rc(arg) | rc(fpr) | 13, "f13" },
159 { rc(arg) | rc(fpr) | 12, "f12" },
160 { rc(arg) | rc(fpr) | 11, "f11" },
161 { rc(arg) | rc(fpr) | 10, "f10" },
162 { rc(arg) | rc(fpr) | 9, "f9" },
164 { rc(fpr) | 13, "f13" },
165 { rc(fpr) | 12, "f12" },
166 { rc(fpr) | 11, "f11" },
167 { rc(fpr) | 10, "f10" },
168 { rc(fpr) | 9, "f9" },
170 { rc(arg) | rc(fpr) | 8, "f8" },
171 { rc(arg) | rc(fpr) | 7, "f7" },
172 { rc(arg) | rc(fpr) | 6, "f6" },
173 { rc(arg) | rc(fpr) | 5, "f5" },
174 { rc(arg) | rc(fpr) | 4, "f4" },
175 { rc(arg) | rc(fpr) | 3, "f3" },
176 { rc(arg) | rc(fpr) | 2, "f2" },
177 { rc(arg) | rc(fpr) | 1, "f1" },
178 { _NOREG, "<none>" },
190 _jit_init(jit_state_t *_jit)
192 _jitc->reglen = jit_size(_rvs) - 1;
196 _jit_prolog(jit_state_t *_jit)
202 assert(jit_regset_cmp_ui(&_jitc->regarg, 0) == 0);
203 jit_regset_set_ui(&_jitc->regsav, 0);
204 offset = _jitc->functions.offset;
205 if (offset >= _jitc->functions.length) {
206 jit_realloc((jit_pointer_t *)&_jitc->functions.ptr,
207 _jitc->functions.length * sizeof(jit_function_t),
208 (_jitc->functions.length + 16) * sizeof(jit_function_t));
209 _jitc->functions.length += 16;
211 _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
212 _jitc->function->self.size = params_offset;
213 _jitc->function->self.argi = _jitc->function->self.argf =
214 _jitc->function->self.alen = 0;
215 /* float conversion */
216 _jitc->function->self.aoff = alloca_offset - 8;
217 _jitc->function->self.call = jit_call_default;
218 jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
219 _jitc->reglen * sizeof(jit_int32_t));
221 /* _no_link here does not mean the jit_link() call can be removed
223 * _jitc->function->prolog = jit_new_node(jit_code_prolog);
225 _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
226 jit_link(_jitc->function->prolog);
227 _jitc->function->prolog->w.w = offset;
228 _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
230 * v: offset in blocks vector
231 * w: offset in functions vector
233 _jitc->function->epilog->w.w = offset;
235 jit_regset_new(&_jitc->function->regset);
239 _jit_allocai(jit_state_t *_jit, jit_int32_t length)
241 assert(_jitc->function);
243 case 0: case 1: break;
244 case 2: _jitc->function->self.aoff &= -2; break;
245 case 3: case 4: _jitc->function->self.aoff &= -4; break;
246 default: _jitc->function->self.aoff &= -8; break;
248 _jitc->function->self.aoff -= length;
249 if (!_jitc->realize) {
250 jit_inc_synth_ww(allocai, _jitc->function->self.aoff, length);
253 return (_jitc->function->self.aoff);
257 _jit_allocar(jit_state_t *_jit, jit_int32_t u, jit_int32_t v)
260 assert(_jitc->function);
261 jit_inc_synth_ww(allocar, u, v);
262 if (!_jitc->function->allocar) {
263 _jitc->function->aoffoff = jit_allocai(sizeof(jit_int32_t));
264 _jitc->function->allocar = 1;
266 r0 = jit_get_reg(jit_class_gpr);
267 r1 = jit_get_reg(jit_class_gpr);
270 jit_andi(r1, r1, -16);
271 jit_ldxi_i(u, JIT_FP, _jitc->function->aoffoff);
273 jit_addr(JIT_SP, JIT_SP, r1);
274 jit_stxi_i(_jitc->function->aoffoff, JIT_FP, u);
282 _jit_ret(jit_state_t *_jit)
285 assert(_jitc->function);
289 jit_patch_at(instr, _jitc->function->epilog);
294 _jit_retr(jit_state_t *_jit, jit_int32_t u, jit_code_t code)
296 jit_code_inc_synth_w(code, u);
297 jit_movr(JIT_RET, u);
303 _jit_reti(jit_state_t *_jit, jit_word_t u, jit_code_t code)
305 jit_code_inc_synth_w(code, u);
306 jit_movi(JIT_RET, u);
312 _jit_retr_f(jit_state_t *_jit, jit_int32_t u)
314 jit_inc_synth_w(retr_f, u);
316 jit_movr_f(JIT_FRET, u);
324 _jit_reti_f(jit_state_t *_jit, jit_float32_t u)
326 jit_inc_synth_f(reti_f, u);
327 jit_movi_f(JIT_FRET, u);
333 _jit_retr_d(jit_state_t *_jit, jit_int32_t u)
335 jit_inc_synth_w(retr_d, u);
337 jit_movr_d(JIT_FRET, u);
345 _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
347 jit_inc_synth_d(reti_d, u);
348 jit_movi_d(JIT_FRET, u);
354 _jit_epilog(jit_state_t *_jit)
356 assert(_jitc->function);
357 assert(_jitc->function->epilog->next == NULL);
358 jit_link(_jitc->function->epilog);
359 _jitc->function = NULL;
363 _jit_arg_register_p(jit_state_t *_jit, jit_node_t *u)
365 if (u->code >= jit_code_arg_c && u->code <= jit_code_arg)
366 return (jit_arg_reg_p(u->u.w));
367 assert(u->code == jit_code_arg_f || u->code == jit_code_arg_d);
368 return (jit_arg_f_reg_p(u->u.w));
372 _jit_ellipsis(jit_state_t *_jit)
374 jit_inc_synth(ellipsis);
375 if (_jitc->prepare) {
377 assert(!(_jitc->function->call.call & jit_call_varargs));
378 _jitc->function->call.call |= jit_call_varargs;
382 assert(!(_jitc->function->self.call & jit_call_varargs));
383 _jitc->function->self.call |= jit_call_varargs;
385 /* Allocate va_list like object in the stack.
386 * If applicable, with enough space to save all argument
387 * registers, and use fixed offsets for them. */
388 _jitc->function->vaoff = jit_allocai(sizeof(jit_va_list_t));
390 _jitc->function->vagp = _jitc->function->self.argi;
391 _jitc->function->vafp = _jitc->function->self.argf;
397 _jit_va_push(jit_state_t *_jit, jit_int32_t u)
399 jit_inc_synth_w(va_push, u);
405 _jit_arg(jit_state_t *_jit, jit_code_t code)
410 assert(_jitc->function);
411 assert(!(_jitc->function->self.call & jit_call_varargs));
412 #if STRONG_TYPE_CHECKING
413 assert(code >= jit_code_arg_c && code <= jit_code_arg);
415 if (jit_arg_reg_p(_jitc->function->self.argi)) {
416 offset = _jitc->function->self.argi++;
422 offset = _jitc->function->self.size;
424 _jitc->function->self.size += sizeof(jit_word_t);
425 node = jit_new_node_ww(code, offset,
426 ++_jitc->function->self.argn);
432 _jit_arg_f(jit_state_t *_jit)
437 assert(_jitc->function);
438 if (jit_arg_f_reg_p(_jitc->function->self.argf)) {
439 offset = _jitc->function->self.argf++;
445 offset = _jitc->function->self.size + F_DISP;
447 if (jit_arg_reg_p(_jitc->function->self.argi)) {
448 # if __WORDSIZE == 32
449 _jitc->function->self.argi += 2;
451 _jitc->function->self.argi++;
456 _jitc->function->self.size += sizeof(jit_word_t);
457 node = jit_new_node_ww(jit_code_arg_f, offset,
458 ++_jitc->function->self.argn);
464 _jit_arg_d(jit_state_t *_jit)
469 assert(_jitc->function);
470 if (jit_arg_f_reg_p(_jitc->function->self.argf)) {
471 offset = _jitc->function->self.argf++;
478 if (_jitc->function->self.size & 7)
479 _jitc->function->self.size += 4;
481 offset = _jitc->function->self.size;
484 if (jit_arg_reg_p(_jitc->function->self.argi)) {
485 # if __WORDSIZE == 32
486 _jitc->function->self.argi += 2;
488 _jitc->function->self.argi++;
493 _jitc->function->self.size += sizeof(jit_float64_t);
494 node = jit_new_node_ww(jit_code_arg_d, offset,
495 ++_jitc->function->self.argn);
501 _jit_getarg_c(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
503 assert_arg_type(v->code, jit_code_arg_c);
504 jit_inc_synth_wp(getarg_c, u, v);
505 if (jit_arg_reg_p(v->u.w))
506 jit_extr_c(u, JIT_RA0 - v->u.w);
508 jit_ldxi_c(u, JIT_FP, v->u.w + C_DISP);
513 _jit_getarg_uc(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
515 assert_arg_type(v->code, jit_code_arg_c);
516 jit_inc_synth_wp(getarg_uc, u, v);
517 if (jit_arg_reg_p(v->u.w))
518 jit_extr_uc(u, JIT_RA0 - v->u.w);
520 jit_ldxi_uc(u, JIT_FP, v->u.w + C_DISP);
525 _jit_getarg_s(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
527 assert_arg_type(v->code, jit_code_arg_s);
528 jit_inc_synth_wp(getarg_s, u, v);
529 if (jit_arg_reg_p(v->u.w))
530 jit_extr_s(u, JIT_RA0 - v->u.w);
532 jit_ldxi_s(u, JIT_FP, v->u.w + S_DISP);
537 _jit_getarg_us(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
539 assert_arg_type(v->code, jit_code_arg_s);
540 jit_inc_synth_wp(getarg_us, u, v);
541 if (jit_arg_reg_p(v->u.w))
542 jit_extr_us(u, JIT_RA0 - v->u.w);
544 jit_ldxi_us(u, JIT_FP, v->u.w + S_DISP);
549 _jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
551 assert_arg_type(v->code, jit_code_arg_i);
552 jit_inc_synth_wp(getarg_i, u, v);
553 if (jit_arg_reg_p(v->u.w)) {
555 jit_movr(u, JIT_RA0 - v->u.w);
557 jit_extr_i(u, JIT_RA0 - v->u.w);
561 jit_ldxi_i(u, JIT_FP, v->u.w + I_DISP);
567 _jit_getarg_ui(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
569 assert_arg_type(v->code, jit_code_arg_i);
570 jit_inc_synth_wp(getarg_ui, u, v);
571 if (jit_arg_reg_p(v->u.w))
572 jit_extr_ui(u, JIT_RA0 - v->u.w);
574 jit_ldxi_ui(u, JIT_FP, v->u.w + I_DISP);
579 _jit_getarg_l(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
581 assert_arg_type(v->code, jit_code_arg_l);
582 jit_inc_synth_wp(getarg_l, u, v);
583 if (jit_arg_reg_p(v->u.w))
584 jit_movr(u, JIT_RA0 - v->u.w);
586 jit_ldxi_l(u, JIT_FP, v->u.w);
592 _jit_putargr(jit_state_t *_jit, jit_int32_t u, jit_node_t *v, jit_code_t code)
594 assert_putarg_type(code, v->code);
595 jit_code_inc_synth_wp(code, u, v);
596 if (jit_arg_reg_p(v->u.w))
597 jit_movr(JIT_RA0 - v->u.w, u);
599 jit_stxi(v->u.w, JIT_FP, u);
604 _jit_putargi(jit_state_t *_jit, jit_word_t u, jit_node_t *v, jit_code_t code)
607 assert_putarg_type(code, v->code);
608 jit_code_inc_synth_wp(code, u, v);
609 if (jit_arg_reg_p(v->u.w))
610 jit_movi(JIT_RA0 - v->u.w, u);
612 regno = jit_get_reg(jit_class_gpr);
614 jit_stxi(v->u.w, JIT_FP, regno);
615 jit_unget_reg(regno);
621 _jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
623 assert(v->code == jit_code_arg_f);
624 jit_inc_synth_wp(getarg_f, u, v);
625 if (jit_arg_f_reg_p(v->u.w))
626 jit_movr_d(u, JIT_FA0 - v->u.w);
628 jit_ldxi_f(u, JIT_FP, v->u.w);
633 _jit_putargr_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
635 assert(v->code == jit_code_arg_f);
636 jit_inc_synth_wp(putargr_f, u, v);
637 if (jit_arg_f_reg_p(v->u.w))
638 jit_movr_d(JIT_FA0 - v->u.w, u);
640 jit_stxi_f(v->u.w, JIT_FP, u);
645 _jit_putargi_f(jit_state_t *_jit, jit_float32_t u, jit_node_t *v)
648 assert(v->code == jit_code_arg_f);
649 jit_inc_synth_fp(putargi_f, u, v);
650 if (jit_arg_f_reg_p(v->u.w))
651 jit_movi_d(JIT_FA0 - v->u.w, u);
653 regno = jit_get_reg(jit_class_fpr);
654 jit_movi_d(regno, u);
655 jit_stxi_f(v->u.w, JIT_FP, regno);
656 jit_unget_reg(regno);
662 _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
664 assert(v->code == jit_code_arg_d);
665 jit_inc_synth_wp(getarg_d, u, v);
666 if (jit_arg_f_reg_p(v->u.w))
667 jit_movr_d(u, JIT_FA0 - v->u.w);
669 jit_ldxi_d(u, JIT_FP, v->u.w);
674 _jit_putargr_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
676 assert(v->code == jit_code_arg_d);
677 jit_inc_synth_wp(putargr_d, u, v);
678 if (jit_arg_f_reg_p(v->u.w))
679 jit_movr_d(JIT_FA0 - v->u.w, u);
681 jit_stxi_d(v->u.w, JIT_FP, u);
686 _jit_putargi_d(jit_state_t *_jit, jit_float64_t u, jit_node_t *v)
689 assert(v->code == jit_code_arg_d);
690 jit_inc_synth_dp(putargi_d, u, v);
691 if (jit_arg_f_reg_p(v->u.w))
692 jit_movi_d(JIT_FA0 - v->u.w, u);
694 regno = jit_get_reg(jit_class_fpr);
695 jit_movi_d(regno, u);
696 jit_stxi_d(v->u.w, JIT_FP, regno);
697 jit_unget_reg(regno);
703 _jit_pushargr(jit_state_t *_jit, jit_int32_t u, jit_code_t code)
706 assert(_jitc->function);
707 jit_code_inc_synth_w(code, u);
709 if (jit_arg_reg_p(_jitc->function->call.argi)) {
710 jit_movr(JIT_RA0 - _jitc->function->call.argi, u);
711 ++_jitc->function->call.argi;
717 jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, u);
719 _jitc->function->call.size += sizeof(jit_word_t);
724 _jit_pushargi(jit_state_t *_jit, jit_word_t u, jit_code_t code)
728 assert(_jitc->function);
729 jit_code_inc_synth_w(code, u);
731 if (jit_arg_reg_p(_jitc->function->call.argi)) {
732 jit_movi(JIT_RA0 - _jitc->function->call.argi, u);
733 ++_jitc->function->call.argi;
739 regno = jit_get_reg(jit_class_gpr);
741 jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, regno);
742 jit_unget_reg(regno);
745 _jitc->function->call.size += sizeof(jit_word_t);
750 _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
753 assert(_jitc->function);
754 jit_inc_synth_w(pushargr_f, u);
756 if (jit_arg_f_reg_p(_jitc->function->call.argf)
758 && !(_jitc->function->call.call & jit_call_varargs)
761 jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
762 ++_jitc->function->call.argf;
764 /* in case of excess arguments */
765 if (jit_arg_reg_p(_jitc->function->call.argi)) {
766 # if __WORDSIZE == 32
767 _jitc->function->call.argi += 2;
768 if (!jit_arg_reg_p(_jitc->function->call.argi - 1))
769 --_jitc->function->call.argi;
771 _jitc->function->call.argi++;
779 else if (jit_arg_reg_p(_jitc->function->call.argi
780 # if __WORDSIZE == 32
784 /* use reserved 8 bytes area */
785 jit_stxi_d(alloca_offset - 8, JIT_FP, u);
786 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
788 _jitc->function->call.argi++;
789 # if __WORDSIZE == 32
790 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
792 _jitc->function->call.argi++;
797 jit_stxi_f(_jitc->function->call.size + params_offset + F_DISP,
800 _jitc->function->call.size += sizeof(jit_word_t);
805 _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
809 assert(_jitc->function);
810 jit_inc_synth_f(pushargi_f, u);
812 if (jit_arg_f_reg_p(_jitc->function->call.argf)
814 && !(_jitc->function->call.call & jit_call_varargs)
817 jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
818 ++_jitc->function->call.argf;
820 /* in case of excess arguments */
821 # if __WORDSIZE == 32
822 _jitc->function->call.argi += 2;
823 if (!jit_arg_reg_p(_jitc->function->call.argi - 1))
824 --_jitc->function->call.argi;
826 _jitc->function->call.argi++;
833 regno = jit_get_reg(jit_class_fpr);
834 jit_movi_f(regno, u);
836 if (jit_arg_reg_p(_jitc->function->call.argi
837 # if __WORDSIZE == 32
841 /* use reserved 8 bytes area */
842 jit_stxi_d(alloca_offset - 8, JIT_FP, regno);
843 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
845 _jitc->function->call.argi++;
846 # if __WORDSIZE == 32
847 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
849 _jitc->function->call.argi++;
854 jit_stxi_f(_jitc->function->call.size + params_offset + F_DISP,
856 jit_unget_reg(regno);
859 _jitc->function->call.size += sizeof(jit_word_t);
864 _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
867 assert(_jitc->function);
868 jit_inc_synth_w(pushargr_d, u);
870 if (jit_arg_f_reg_p(_jitc->function->call.argf)
872 && !(_jitc->function->call.call & jit_call_varargs)
875 jit_movr_d(JIT_FA0 - _jitc->function->call.argf, u);
876 ++_jitc->function->call.argf;
878 /* in case of excess arguments */
879 # if __WORDSIZE == 32
880 _jitc->function->call.argi += 2;
881 if (!jit_arg_reg_p(_jitc->function->call.argi - 1))
882 --_jitc->function->call.argi;
884 _jitc->function->call.argi++;
886 #else /* _CALL_SYSV */
891 else if (jit_arg_reg_p(_jitc->function->call.argi
892 # if __WORDSIZE == 32
896 /* use reserved 8 bytes area */
897 jit_stxi_d(alloca_offset - 8, JIT_FP, u);
898 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
900 _jitc->function->call.argi++;
901 # if __WORDSIZE == 32
902 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
904 _jitc->function->call.argi++;
908 #endif /* !_CALL_SYSV */
911 if (_jitc->function->call.size & 7)
912 _jitc->function->call.size += 4;
914 jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, u);
915 #if !_CALL_SYSV && __WORDSIZE == 32
916 if (jit_arg_reg_p(_jitc->function->call.argi)) {
917 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_SP,
918 _jitc->function->call.size + params_offset);
919 _jitc->function->call.argi++;
924 _jitc->function->call.size += sizeof(jit_float64_t);
929 _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
933 assert(_jitc->function);
934 jit_inc_synth_d(pushargi_d, u);
936 if (jit_arg_f_reg_p(_jitc->function->call.argf)
938 && !(_jitc->function->call.call & jit_call_varargs)
941 jit_movi_d(JIT_FA0 - _jitc->function->call.argf, u);
942 ++_jitc->function->call.argf;
944 /* in case of excess arguments */
945 if (jit_arg_reg_p(_jitc->function->call.argi)) {
946 # if __WORDSIZE == 32
947 _jitc->function->call.argi += 2;
948 if (!jit_arg_reg_p(_jitc->function->call.argi - 1))
949 --_jitc->function->call.argi;
951 _jitc->function->call.argi++;
954 #else /* _CALL_SYSV */
959 regno = jit_get_reg(jit_class_fpr);
960 jit_movi_d(regno, u);
962 if (jit_arg_reg_p(_jitc->function->call.argi
963 # if __WORDSIZE == 32
967 /* use reserved 8 bytes area */
968 jit_stxi_d(alloca_offset - 8, JIT_FP, regno);
969 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
971 _jitc->function->call.argi++;
972 # if __WORDSIZE == 32
973 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_FP,
975 _jitc->function->call.argi++;
979 #endif /* !_CALL_SYSV */
982 if (_jitc->function->call.size & 7)
983 _jitc->function->call.size += 4;
985 jit_stxi_d(_jitc->function->call.size + params_offset,
987 #if !_CALL_SYSV && __WORDSIZE == 32
988 if (jit_arg_reg_p(_jitc->function->call.argi)) {
989 jit_ldxi(JIT_RA0 - _jitc->function->call.argi, JIT_SP,
990 _jitc->function->call.size + params_offset);
991 _jitc->function->call.argi++;
995 jit_unget_reg(regno);
998 _jitc->function->call.size += sizeof(jit_float64_t);
1003 _jit_regarg_p(jit_state_t *_jit, jit_node_t *node, jit_int32_t regno)
1006 spec = jit_class(_rvs[regno].spec);
1007 if (spec & jit_class_arg) {
1008 if (spec & jit_class_gpr) {
1009 regno = JIT_RA0 - regno;
1010 if (regno >= 0 && regno < node->v.w)
1013 else if (spec & jit_class_fpr) {
1014 regno = JIT_FA0 - regno;
1015 if (regno >= 0 && regno < node->w.w)
1023 _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
1026 assert(_jitc->function);
1027 jit_inc_synth_w(finishr, r0);
1028 if (_jitc->function->self.alen < _jitc->function->call.size)
1029 _jitc->function->self.alen = _jitc->function->call.size;
1030 call = jit_callr(r0);
1031 call->v.w = _jitc->function->call.argi;
1032 call->w.w = _jitc->function->call.argf;
1034 /* If passing float arguments in registers */
1035 if ((_jitc->function->call.call & jit_call_varargs) && call->w.w)
1036 call->flag |= jit_flag_varargs;
1038 _jitc->function->call.argi = _jitc->function->call.argf = 0;
1044 _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
1047 assert(_jitc->function);
1048 jit_inc_synth_w(finishi, (jit_word_t)i0);
1049 if (_jitc->function->self.alen < _jitc->function->call.size)
1050 _jitc->function->self.alen = _jitc->function->call.size;
1051 node = jit_calli(i0);
1052 node->v.w = _jitc->function->call.argi;
1053 node->w.w = _jitc->function->call.argf;
1055 if ((_jitc->function->call.call & jit_call_varargs) && node->w.w)
1056 node->flag |= jit_flag_varargs;
1058 _jitc->function->call.argi = _jitc->function->call.argf = 0;
1065 _jit_retval_c(jit_state_t *_jit, jit_int32_t r0)
1067 jit_inc_synth(retval_c);
1068 jit_extr_c(r0, JIT_RET);
1073 _jit_retval_uc(jit_state_t *_jit, jit_int32_t r0)
1075 jit_inc_synth(retval_uc);
1076 jit_extr_uc(r0, JIT_RET);
1081 _jit_retval_s(jit_state_t *_jit, jit_int32_t r0)
1083 jit_inc_synth(retval_s);
1084 jit_extr_s(r0, JIT_RET);
1089 _jit_retval_us(jit_state_t *_jit, jit_int32_t r0)
1091 jit_inc_synth(retval_us);
1092 jit_extr_us(r0, JIT_RET);
1097 _jit_retval_i(jit_state_t *_jit, jit_int32_t r0)
1099 jit_inc_synth(retval_i);
1100 #if __WORDSIZE == 32
1102 jit_movr(r0, JIT_RET);
1104 jit_extr_i(r0, JIT_RET);
1109 #if __WORDSIZE == 64
1111 _jit_retval_ui(jit_state_t *_jit, jit_int32_t r0)
1113 jit_inc_synth(retval_ui);
1114 jit_extr_ui(r0, JIT_RET);
1119 _jit_retval_l(jit_state_t *_jit, jit_int32_t r0)
1121 jit_inc_synth(retval_l);
1123 jit_movr(r0, JIT_RET);
1129 _jit_retval_f(jit_state_t *_jit, jit_int32_t r0)
1131 jit_inc_synth(retval_f);
1137 _jit_retval_d(jit_state_t *_jit, jit_int32_t r0)
1139 jit_inc_synth(retval_d);
1141 jit_movr_d(r0, JIT_FRET);
1146 _emit_code(jit_state_t *_jit)
1153 jit_bool_t no_flag = 0; /* Set if previous instruction is
1154 * *not* a jump target. */
1158 jit_function_t func;
1159 #if DEVEL_DISASSEMBLER
1162 jit_word_t patch_offset;
1164 jit_word_t prolog_offset;
1167 #if DEVEL_DISASSEMBLER
1171 _jitc->function = NULL;
1173 jit_reglive_setup();
1177 undo.patch_offset = 0;
1179 #if DEVEL_DISASSEMBLER
1183 undo.prolog_offset = 0;
1184 for (node = _jitc->head; node; node = node->next)
1185 if (node->code != jit_code_label &&
1186 node->code != jit_code_note &&
1187 node->code != jit_code_name)
1189 if (node && (node->code != jit_code_prolog ||
1190 !(_jitc->functions.ptr + node->w.w)->assume_frame)) {
1191 /* code may start with a jump so add an initial function descriptor */
1192 word = _jit->pc.w + sizeof(void*) * 3;
1193 iw(word); /* addr */
1199 #define case_rr(name, type) \
1200 case jit_code_##name##r##type: \
1201 name##r##type(rn(node->u.w), rn(node->v.w)); \
1203 #define case_rw(name, type) \
1204 case jit_code_##name##i##type: \
1205 name##i##type(rn(node->u.w), node->v.w); \
1207 #define case_wr(name, type) \
1208 case jit_code_##name##i##type: \
1209 name##i##type(node->u.w, rn(node->v.w)); \
1211 #define case_rrr(name, type) \
1212 case jit_code_##name##r##type: \
1213 name##r##type(rn(node->u.w), \
1214 rn(node->v.w), rn(node->w.w)); \
1216 #define case_rrrr(name, type) \
1217 case jit_code_##name##r##type: \
1218 name##r##type(rn(node->u.q.l), rn(node->u.q.h), \
1219 rn(node->v.w), rn(node->w.w)); \
1221 #define case_rrw(name, type) \
1222 case jit_code_##name##i##type: \
1223 name##i##type(rn(node->u.w), rn(node->v.w), node->w.w); \
1225 #define case_rrrw(name, type) \
1226 case jit_code_##name##i##type: \
1227 name##i##type(rn(node->u.q.l), rn(node->u.q.h), \
1228 rn(node->v.w), node->w.w); \
1230 #define case_rrf(name, type, size) \
1231 case jit_code_##name##i##type: \
1232 assert(node->flag & jit_flag_data); \
1233 name##i##type(rn(node->u.w), rn(node->v.w), \
1234 (jit_float##size##_t *)node->w.n->u.w); \
1236 #define case_wrr(name, type) \
1237 case jit_code_##name##i##type: \
1238 name##i##type(node->u.w, rn(node->v.w), rn(node->w.w)); \
1240 #define case_brr(name, type) \
1241 case jit_code_##name##r##type: \
1243 assert(temp->code == jit_code_label || \
1244 temp->code == jit_code_epilog); \
1245 if (temp->flag & jit_flag_patch) \
1246 name##r##type(temp->u.w, rn(node->v.w), \
1249 word = name##r##type(_jit->pc.w, \
1250 rn(node->v.w), rn(node->w.w)); \
1251 patch(word, node); \
1254 #define case_brw(name, type) \
1255 case jit_code_##name##i##type: \
1257 assert(temp->code == jit_code_label || \
1258 temp->code == jit_code_epilog); \
1259 if (temp->flag & jit_flag_patch) \
1260 name##i##type(temp->u.w, \
1261 rn(node->v.w), node->w.w); \
1263 word = name##i##type(_jit->pc.w, \
1264 rn(node->v.w), node->w.w); \
1265 patch(word, node); \
1268 #define case_brf(name, type, size) \
1269 case jit_code_##name##i##type: \
1271 assert(temp->code == jit_code_label || \
1272 temp->code == jit_code_epilog); \
1273 if (temp->flag & jit_flag_patch) \
1274 name##i##type(temp->u.w, rn(node->v.w), \
1275 (jit_float##size##_t *)node->w.n->u.w); \
1277 word = name##i##type(_jit->pc.w, rn(node->v.w), \
1278 (jit_float##size##_t *)node->w.n->u.w); \
1279 patch(word, node); \
1282 for (node = _jitc->head; node; node = node->next) {
1283 if (_jit->pc.uc >= _jitc->code.end)
1286 #if DEVEL_DISASSEMBLER
1287 node->offset = (jit_uword_t)_jit->pc.w - (jit_uword_t)prevw;
1290 value = jit_classify(node->code);
1291 jit_regarg_set(node, value);
1292 switch (node->code) {
1293 case jit_code_align:
1294 /* Must align to a power of two */
1295 assert(!(node->u.w & (node->u.w - 1)));
1296 if ((word = _jit->pc.w & (node->u.w - 1)))
1297 nop(node->u.w - word);
1300 nop((node->u.w + 3) & ~3);
1302 case jit_code_note: case jit_code_name:
1303 node->u.w = _jit->pc.w;
1305 case jit_code_label:
1306 /* remember label is defined */
1307 node->flag |= jit_flag_patch;
1308 node->u.w = _jit->pc.w;
1327 case_rrrr(qmul, _u);
1328 case_rrrw(qmul, _u);
1335 case_rrrr(qdiv, _u);
1336 case_rrrw(qdiv, _u);
1357 # if __WORDSIZE == 64
1363 # if __WORDSIZE == 64
1366 case jit_code_bswapr_us:
1367 bswapr_us_lh(rn(node->u.w), rn(node->v.w), no_flag);
1369 case jit_code_bswapr_ui:
1370 bswapr_ui_lw(rn(node->u.w), rn(node->v.w), no_flag);
1372 # if __WORDSIZE == 64
1373 case_rr(bswap, _ul);
1382 casr(rn(node->u.w), rn(node->v.w),
1383 rn(node->w.q.l), rn(node->w.q.h));
1386 casi(rn(node->u.w), node->v.w,
1387 rn(node->w.q.l), rn(node->w.q.h));
1393 if (node->flag & jit_flag_node) {
1395 if (temp->code == jit_code_data ||
1396 (temp->code == jit_code_label &&
1397 (temp->flag & jit_flag_patch)))
1398 movi(rn(node->u.w), temp->u.w);
1400 assert(temp->code == jit_code_label ||
1401 temp->code == jit_code_epilog);
1402 word = movi_p(rn(node->u.w), node->v.w);
1407 movi(rn(node->u.w), node->v.w);
1409 case_rr(trunc, _f_i);
1410 case_rr(trunc, _d_i);
1411 # if __WORDSIZE == 64
1412 case_rr(trunc, _f_l);
1413 case_rr(trunc, _d_l);
1463 case_brr(boadd, _u);
1464 case_brw(boadd, _u);
1467 case_brr(bxadd, _u);
1468 case_brw(bxadd, _u);
1471 case_brr(bosub, _u);
1472 case_brw(bosub, _u);
1475 case_brr(bxsub, _u);
1476 case_brw(bxsub, _u);
1495 #if __WORDSIZE == 64
1517 #if __WORDSIZE == 64
1524 case jit_code_movi_f:
1525 assert(node->flag & jit_flag_data);
1526 movi_f(rn(node->u.w), (jit_float32_t *)node->v.n->u.w);
1534 case_rrf(add, _f, 32);
1536 case_rrf(sub, _f, 32);
1537 case_rrf(rsb, _f, 32);
1539 case_rrf(mul, _f, 32);
1541 case_rrf(div, _f, 32);
1543 case_rrf(lt, _f, 32);
1545 case_rrf(le, _f, 32);
1547 case_rrf(eq, _f, 32);
1549 case_rrf(ge, _f, 32);
1551 case_rrf(gt, _f, 32);
1553 case_rrf(ne, _f, 32);
1555 case_rrf(unlt, _f, 32);
1557 case_rrf(unle, _f, 32);
1559 case_rrf(uneq, _f, 32);
1561 case_rrf(unge, _f, 32);
1563 case_rrf(ungt, _f, 32);
1565 case_rrf(ltgt, _f, 32);
1567 case_rrf(ord, _f, 32);
1568 case_rrr(unord, _f);
1569 case_rrf(unord, _f, 32);
1571 case_brf(blt, _f, 32);
1573 case_brf(ble, _f, 32);
1575 case_brf(beq, _f, 32);
1577 case_brf(bge, _f, 32);
1579 case_brf(bgt, _f, 32);
1581 case_brf(bne, _f, 32);
1582 case_brr(bunlt, _f);
1583 case_brf(bunlt, _f, 32);
1584 case_brr(bunle, _f);
1585 case_brf(bunle, _f, 32);
1586 case_brr(buneq, _f);
1587 case_brf(buneq, _f, 32);
1588 case_brr(bunge, _f);
1589 case_brf(bunge, _f, 32);
1590 case_brr(bungt, _f);
1591 case_brf(bungt, _f, 32);
1592 case_brr(bltgt, _f);
1593 case_brf(bltgt, _f, 32);
1595 case_brf(bord, _f, 32);
1596 case_brr(bunord, _f);
1597 case_brf(bunord, _f, 32);
1607 case jit_code_movi_d:
1608 assert(node->flag & jit_flag_data);
1609 movi_d(rn(node->u.w), (jit_float64_t *)node->v.n->u.w);
1617 case_rrf(add, _d, 64);
1619 case_rrf(sub, _d, 64);
1620 case_rrf(rsb, _d, 64);
1622 case_rrf(mul, _d, 64);
1624 case_rrf(div, _d, 64);
1626 case_rrf(lt, _d, 64);
1628 case_rrf(le, _d, 64);
1630 case_rrf(eq, _d, 64);
1632 case_rrf(ge, _d, 64);
1634 case_rrf(gt, _d, 64);
1636 case_rrf(ne, _d, 64);
1638 case_rrf(unlt, _d, 64);
1640 case_rrf(unle, _d, 64);
1642 case_rrf(uneq, _d, 64);
1644 case_rrf(unge, _d, 64);
1646 case_rrf(ungt, _d, 64);
1648 case_rrf(ltgt, _d, 64);
1650 case_rrf(ord, _d, 64);
1651 case_rrr(unord, _d);
1652 case_rrf(unord, _d, 64);
1654 case_brf(blt, _d, 64);
1656 case_brf(ble, _d, 64);
1658 case_brf(beq, _d, 64);
1660 case_brf(bge, _d, 64);
1662 case_brf(bgt, _d, 64);
1664 case_brf(bne, _d, 64);
1665 case_brr(bunlt, _d);
1666 case_brf(bunlt, _d, 64);
1667 case_brr(bunle, _d);
1668 case_brf(bunle, _d, 64);
1669 case_brr(buneq, _d);
1670 case_brf(buneq, _d, 64);
1671 case_brr(bunge, _d);
1672 case_brf(bunge, _d, 64);
1673 case_brr(bungt, _d);
1674 case_brf(bungt, _d, 64);
1675 case_brr(bltgt, _d);
1676 case_brf(bltgt, _d, 64);
1678 case_brf(bord, _d, 64);
1679 case_brr(bunord, _d);
1680 case_brf(bunord, _d, 64);
1690 jmpr(rn(node->u.w));
1693 if (node->flag & jit_flag_node) {
1695 if (_jit->pc.uc == _jit->code.ptr + sizeof(void*) * 3)
1699 assert(temp->code == jit_code_label ||
1700 temp->code == jit_code_epilog);
1701 if (temp->flag & jit_flag_patch)
1704 word = _jit->code.length -
1705 (_jit->pc.uc - _jit->code.ptr);
1706 if (can_sign_extend_jump_p(word))
1707 word = jmpi(_jit->pc.w);
1709 word = jmpi_p(_jit->pc.w);
1716 case jit_code_callr:
1718 # define xcallr(u, v) callr(u, v)
1719 # define xcalli_p(u, v) calli_p(u, v)
1720 # define xcalli(u, v) calli(u, v)
1722 # define xcallr(u, v) callr(u)
1723 # define xcalli_p(u, v) calli_p(u)
1724 # define xcalli(u, v) calli(u)
1726 xcallr(rn(node->u.w), !!(node->flag & jit_flag_varargs));
1728 case jit_code_calli:
1729 value = !!(node->flag & jit_flag_varargs);
1730 if (node->flag & jit_flag_node) {
1732 assert(temp->code == jit_code_label ||
1733 temp->code == jit_code_epilog);
1734 if (temp->flag & jit_flag_patch)
1735 xcalli(temp->u.w, value);
1737 word = _jit->code.length -
1738 (_jit->pc.uc - _jit->code.ptr);
1740 if (can_sign_extend_jump_p(word + value * 4))
1741 word = xcalli(_jit->pc.w, value);
1744 word = xcalli_p(_jit->pc.w, value);
1749 xcalli(node->u.w, value);
1751 case jit_code_prolog:
1752 _jitc->function = _jitc->functions.ptr + node->w.w;
1754 undo.word = _jit->pc.w;
1755 memcpy(&undo.func, _jitc->function, sizeof(undo.func));
1756 #if DEVEL_DISASSEMBLER
1759 undo.patch_offset = _jitc->patches.offset;
1761 undo.prolog_offset = _jitc->prolog.offset;
1766 if (_jitc->jump && !_jitc->function->assume_frame) {
1767 /* remember prolog to hide offset adjustment for a jump
1768 * to the start of a function, what is expected to be
1769 * a common practice as first jit instruction */
1770 if (_jitc->prolog.offset >= _jitc->prolog.length) {
1771 _jitc->prolog.length += 16;
1772 jit_realloc((jit_pointer_t *)&_jitc->prolog.ptr,
1773 (_jitc->prolog.length - 16) *
1775 _jitc->prolog.length * sizeof(jit_word_t));
1777 _jitc->prolog.ptr[_jitc->prolog.offset++] = _jit->pc.w;
1778 /* function descriptor */
1779 word = _jit->pc.w + sizeof(void*) * 3;
1780 iw(word); /* addr */
1787 case jit_code_epilog:
1788 assert(_jitc->function == _jitc->functions.ptr + node->w.w);
1790 for (temp = undo.node->next;
1791 temp != node; temp = temp->next) {
1792 if (temp->code == jit_code_label ||
1793 temp->code == jit_code_epilog)
1794 temp->flag &= ~jit_flag_patch;
1796 temp->flag &= ~jit_flag_patch;
1798 _jit->pc.w = undo.word;
1799 /* undo.func.self.aoff and undo.func.regset should not
1800 * be undone, as they will be further updated, and are
1801 * the reason of the undo. */
1802 undo.func.self.aoff = _jitc->function->frame +
1803 _jitc->function->self.aoff;
1804 jit_regset_set(&undo.func.regset, &_jitc->function->regset);
1805 /* allocar information also does not need to be undone */
1806 undo.func.aoffoff = _jitc->function->aoffoff;
1807 undo.func.allocar = _jitc->function->allocar;
1808 memcpy(_jitc->function, &undo.func, sizeof(undo.func));
1809 #if DEVEL_DISASSEMBLER
1812 _jitc->patches.offset = undo.patch_offset;
1814 _jitc->prolog.offset = undo.prolog_offset;
1816 goto restart_function;
1818 /* remember label is defined */
1819 node->flag |= jit_flag_patch;
1820 node->u.w = _jit->pc.w;
1822 _jitc->function = NULL;
1824 case jit_code_va_start:
1825 vastart(rn(node->u.w));
1827 case jit_code_va_arg:
1828 vaarg(rn(node->u.w), rn(node->v.w));
1830 case jit_code_va_arg_d:
1831 vaarg_d(rn(node->u.w), rn(node->v.w));
1833 case jit_code_live: case jit_code_ellipsis:
1834 case jit_code_va_push:
1835 case jit_code_allocai: case jit_code_allocar:
1836 case jit_code_arg_c: case jit_code_arg_s:
1837 case jit_code_arg_i:
1838 # if __WORDSIZE == 64
1839 case jit_code_arg_l:
1841 case jit_code_arg_f: case jit_code_arg_d:
1842 case jit_code_va_end:
1844 case jit_code_retr_c: case jit_code_reti_c:
1845 case jit_code_retr_uc: case jit_code_reti_uc:
1846 case jit_code_retr_s: case jit_code_reti_s:
1847 case jit_code_retr_us: case jit_code_reti_us:
1848 case jit_code_retr_i: case jit_code_reti_i:
1849 #if __WORDSIZE == 64
1850 case jit_code_retr_ui: case jit_code_reti_ui:
1851 case jit_code_retr_l: case jit_code_reti_l:
1853 case jit_code_retr_f: case jit_code_reti_f:
1854 case jit_code_retr_d: case jit_code_reti_d:
1855 case jit_code_getarg_c: case jit_code_getarg_uc:
1856 case jit_code_getarg_s: case jit_code_getarg_us:
1857 case jit_code_getarg_i:
1858 #if __WORDSIZE == 64
1859 case jit_code_getarg_ui: case jit_code_getarg_l:
1861 case jit_code_getarg_f: case jit_code_getarg_d:
1862 case jit_code_putargr_c: case jit_code_putargi_c:
1863 case jit_code_putargr_uc: case jit_code_putargi_uc:
1864 case jit_code_putargr_s: case jit_code_putargi_s:
1865 case jit_code_putargr_us: case jit_code_putargi_us:
1866 case jit_code_putargr_i: case jit_code_putargi_i:
1867 #if __WORDSIZE == 64
1868 case jit_code_putargr_ui: case jit_code_putargi_ui:
1869 case jit_code_putargr_l: case jit_code_putargi_l:
1871 case jit_code_putargr_f: case jit_code_putargi_f:
1872 case jit_code_putargr_d: case jit_code_putargi_d:
1873 case jit_code_pushargr_c: case jit_code_pushargi_c:
1874 case jit_code_pushargr_uc: case jit_code_pushargi_uc:
1875 case jit_code_pushargr_s: case jit_code_pushargi_s:
1876 case jit_code_pushargr_us: case jit_code_pushargi_us:
1877 case jit_code_pushargr_i: case jit_code_pushargi_i:
1878 #if __WORDSIZE == 64
1879 case jit_code_pushargr_ui: case jit_code_pushargi_ui:
1880 case jit_code_pushargr_l: case jit_code_pushargi_l:
1882 case jit_code_pushargr_f: case jit_code_pushargi_f:
1883 case jit_code_pushargr_d: case jit_code_pushargi_d:
1884 case jit_code_retval_c: case jit_code_retval_uc:
1885 case jit_code_retval_s: case jit_code_retval_us:
1886 case jit_code_retval_i:
1887 #if __WORDSIZE == 64
1888 case jit_code_retval_ui: case jit_code_retval_l:
1890 case jit_code_retval_f: case jit_code_retval_d:
1891 case jit_code_prepare:
1892 case jit_code_finishr: case jit_code_finishi:
1897 jit_regarg_clr(node, value);
1898 assert(_jitc->regarg == 0 && _jitc->synth == 0);
1899 /* update register live state */
1902 no_flag = !(node->flag & jit_flag_patch);
1915 for (offset = 0; offset < _jitc->patches.offset; offset++) {
1916 node = _jitc->patches.ptr[offset].node;
1917 word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
1918 patch_at(_jitc->patches.ptr[offset].inst, word);
1921 jit_flush(_jit->code.ptr, _jit->pc.uc);
1923 return (_jit->code.ptr);
1927 # include "jit_ppc-cpu.c"
1928 # include "jit_ppc-fpu.c"
1932 jit_flush(void *fptr, void *tptr)
1934 #if defined(__GNUC__)
1937 s = sysconf(_SC_PAGE_SIZE);
1938 f = (jit_word_t)fptr & -s;
1939 t = (((jit_word_t)tptr) + s - 1) & -s;
1940 __clear_cache((void *)f, (void *)t);
1945 _emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
1947 #if __WORDSIZE == 32
1948 ldxi_i(rn(r0), rn(r1), i0);
1950 ldxi_l(rn(r0), rn(r1), i0);
1955 _emit_stxi(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
1957 #if __WORDSIZE == 32
1958 stxi_i(i0, rn(r0), rn(r1));
1960 stxi_l(i0, rn(r0), rn(r1));
1965 _emit_ldxi_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
1967 ldxi_d(rn(r0), rn(r1), i0);
1971 _emit_stxi_d(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
1973 stxi_d(i0, rn(r0), rn(r1));
1977 _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
1981 assert(node->flag & jit_flag_node);
1982 if (node->code == jit_code_movi)
1983 flag = node->v.n->flag;
1985 flag = node->u.n->flag;
1986 assert(!(flag & jit_flag_patch));
1987 if (_jitc->patches.offset >= _jitc->patches.length) {
1988 jit_realloc((jit_pointer_t *)&_jitc->patches.ptr,
1989 _jitc->patches.length * sizeof(jit_patch_t),
1990 (_jitc->patches.length + 1024) * sizeof(jit_patch_t));
1991 _jitc->patches.length += 1024;
1993 _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
1994 _jitc->patches.ptr[_jitc->patches.offset].node = node;
1995 ++_jitc->patches.offset;