2 * Copyright (C) 2013-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 #include <lightning.h>
21 #include <lightning/jit_private.h>
22 #if defined(__linux__)
23 # include <sys/syscall.h>
27 #define jit_arg_reg_p(i) (i >= 0 && i < 4)
30 # include "jit_hppa-cpu.c"
31 # include "jit_hppa-fpu.c"
32 # include "jit_fallback.c"
38 typedef jit_pointer_t jit_va_list;
43 #define patch(instr, node) _patch(_jit, instr, node)
44 static void _patch(jit_state_t*,jit_word_t,jit_node_t*);
47 extern void __clear_cache(void *, void *);
53 jit_register_t _rvs[] = {
54 { 0, "r0" }, /* Zero */
55 /* Not register starved, so, avoid allocating r1 and rp
56 * due to being implicit target of ADDIL and B,L */
57 { 1, "r1" }, /* Scratch */
58 { 2, "rp" }, /* Return Pointer and scratch */
59 { rc(sav) | 3, "r3" },
60 { 19, "r19" }, /* Linkage Table */
61 { rc(gpr) | 20, "r20" },
62 { rc(gpr) | 21, "r21" },
63 { rc(gpr) | 22, "r22" },
64 { rc(gpr) | 29, "ret1" },
65 { rc(gpr) | 28, "ret0" },
66 /* JIT_Rx in callee save registers due to need to call
67 * functions to implement some instructions */
69 { rc(gpr) | rc(sav) | 4, "r4" },
70 { rc(gpr) | rc(sav) | 5, "r5" },
71 { rc(gpr) | rc(sav) | 6, "r6" },
73 { rc(gpr) | rc(sav) | 7, "r7" },
74 { rc(sav) | rc(sav) | 8, "r8" },
75 { rc(gpr) | rc(sav) | 9, "r9" },
77 { rc(gpr) | rc(sav) | 10, "r10" },
79 { rc(gpr) | rc(sav) | 11, "r11" },
80 { rc(gpr) | rc(sav) | 12, "r12" },
81 { rc(gpr) | rc(sav) | 13, "r13" },
82 { rc(gpr) | rc(sav) | 14, "r14" },
83 { rc(gpr) | rc(sav) | 15, "r15" },
84 { rc(gpr) | rc(sav) | 16, "r16" },
85 { rc(gpr) | rc(sav) | 17, "r17" },
86 { rc(gpr) | rc(sav) | 18, "r18" },
88 { rc(gpr) | rc(arg) | 23, "r23" },
89 { rc(gpr) | rc(arg) | 24, "r24" },
90 { rc(gpr) | rc(arg) | 25, "r25" },
91 { rc(gpr) | rc(arg) | 26, "r26" },
92 { 27, "dp" }, /* Data Pointer */
94 { 31, "r31" }, /* Link Register */
95 { rc(fpr) | 31, "fr31" },
96 { rc(fpr) | 30, "fr30" },
97 { rc(fpr) | 29, "fr29" },
98 { rc(fpr) | 28, "fr28" },
99 { rc(fpr) | 27, "fr27" },
100 { rc(fpr) | 26, "fr26" },
101 { rc(fpr) | 25, "fr25" },
102 { rc(fpr) | 24, "fr24" },
103 { rc(fpr) | 23, "fr23" },
104 { rc(fpr) | 22, "fr22" },
105 { rc(fpr) | 11, "fr11" },
106 { rc(fpr) | 10, "fr10" },
107 { rc(fpr) | 9, "fr9" },
108 { rc(fpr) | 8, "fr8" },
110 { rc(fpr) | rc(arg) | 7, "fr7" },
111 { rc(fpr) | rc(arg) | 6, "fr6" },
112 { rc(fpr) | rc(arg) | 5, "fr5" },
113 { rc(fpr) | rc(arg) | 4, "fr4" },
115 { rc(fpr) | rc(sav) | 21, "fr21" },
116 { rc(fpr) | rc(sav) | 20, "fr20" },
117 { rc(fpr) | rc(sav) | 19, "fr19" },
118 { rc(fpr) | rc(sav) | 18, "fr18" },
119 { rc(fpr) | rc(sav) | 17, "fr17" },
120 { rc(fpr) | rc(sav) | 16, "fr16" },
121 { rc(fpr) | rc(sav) | 15, "fr15" },
122 { rc(fpr) | rc(sav) | 14, "fr14" },
123 { rc(fpr) | rc(sav) | 13, "fr13" },
124 { rc(fpr) | rc(sav) | 12, "fr12" },
129 { _NOREG, "<none>" },
138 /* FIXME Expecting PARISC 2.0, for PARISC 1.0 should not use fr16-fr31 */
140 /* Set to zero to pass all tests in unldst.tst */
141 /* Note that it only fails for instructions with an immediate, and
142 * it does not look like an encoding error, as even if only generating
143 * the encoding if ((immediate & 3) == 0) it still fails. */
148 _jit_init(jit_state_t *_jit)
150 _jitc->reglen = jit_size(_rvs) - 1;
154 _jit_prolog(jit_state_t *_jit)
160 assert(jit_regset_cmp_ui(&_jitc->regarg, 0) == 0);
161 jit_regset_set_ui(&_jitc->regsav, 0);
162 offset = _jitc->functions.offset;
163 if (offset >= _jitc->functions.length) {
164 jit_realloc((jit_pointer_t *)&_jitc->functions.ptr,
165 _jitc->functions.length * sizeof(jit_function_t),
166 (_jitc->functions.length + 16) * sizeof(jit_function_t));
167 _jitc->functions.length += 16;
169 _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
170 _jitc->function->self.size = params_offset;
171 _jitc->function->self.argi = _jitc->function->self.alen = 0;
172 /* float conversion */
173 _jitc->function->self.aoff = alloca_offset;
174 _jitc->function->cvt_offset = alloca_offset - 8;
175 _jitc->function->self.call = jit_call_default;
176 jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
177 _jitc->reglen * sizeof(jit_int32_t));
179 /* _no_link here does not mean the jit_link() call can be removed
181 * _jitc->function->prolog = jit_new_node(jit_code_prolog);
183 _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
184 jit_link(_jitc->function->prolog);
185 _jitc->function->prolog->w.w = offset;
186 _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
188 * v: offset in blocks vector
189 * w: offset in functions vector
191 _jitc->function->epilog->w.w = offset;
193 jit_regset_new(&_jitc->function->regset);
197 _jit_allocai(jit_state_t *_jit, jit_int32_t length)
200 assert(_jitc->function);
205 _jitc->function->self.aoff = (_jitc->function->self.aoff + 1) & -2;
208 _jitc->function->self.aoff = (_jitc->function->self.aoff + 3) & -4;
211 _jitc->function->self.aoff = (_jitc->function->self.aoff + 7) & -8;
214 if (!_jitc->realize) {
215 jit_inc_synth_ww(allocai, _jitc->function->self.aoff, length);
218 offset = _jitc->function->self.aoff;
219 _jitc->function->self.aoff += length;
224 _jit_allocar(jit_state_t *_jit, jit_int32_t u, jit_int32_t v)
227 assert(_jitc->function);
228 jit_inc_synth_ww(allocar, u, v);
229 if (!_jitc->function->allocar) {
230 _jitc->function->aoffoff = jit_allocai(sizeof(jit_int32_t));
231 _jitc->function->allocar = 1;
233 reg = jit_get_reg(jit_class_gpr);
234 jit_addi(reg, v, 63);
235 jit_andi(reg, reg, -64);
236 jit_ldxi_i(u, JIT_FP, _jitc->function->aoffoff);
237 jit_addr(JIT_SP, JIT_SP, reg);
238 jit_stxi_i(_jitc->function->aoffoff, JIT_FP, u);
244 _jit_ret(jit_state_t *_jit)
247 assert(_jitc->function);
251 jit_patch_at(instr, _jitc->function->epilog);
256 _jit_retr(jit_state_t *_jit, jit_int32_t u, jit_code_t code)
258 jit_code_inc_synth_w(code, u);
259 jit_movr(JIT_RET, u);
265 _jit_reti(jit_state_t *_jit, jit_word_t u, jit_code_t code)
267 jit_code_inc_synth_w(code, u);
268 jit_movi(JIT_RET, u);
274 _jit_retr_f(jit_state_t *_jit, jit_int32_t u)
276 jit_inc_synth_w(retr_f, u);
277 jit_movr_f(JIT_FRET, u);
283 _jit_reti_f(jit_state_t *_jit, jit_float32_t u)
285 jit_inc_synth_f(reti_f, u);
286 jit_movi_f(JIT_FRET, u);
292 _jit_retr_d(jit_state_t *_jit, jit_int32_t u)
294 jit_inc_synth_w(retr_d, u);
295 jit_movr_d(JIT_FRET, u);
301 _jit_reti_d(jit_state_t *_jit, jit_float64_t u)
303 jit_inc_synth_d(reti_d, u);
304 jit_movi_d(JIT_FRET, u);
310 _jit_epilog(jit_state_t *_jit)
312 assert(_jitc->function);
313 assert(_jitc->function->epilog->next == NULL);
314 jit_link(_jitc->function->epilog);
315 _jitc->function = NULL;
319 _jit_arg_register_p(jit_state_t *_jit, jit_node_t *u)
321 assert((u->code >= jit_code_arg_c && u->code <= jit_code_arg) ||
322 u->code == jit_code_arg_f || u->code == jit_code_arg_d);
323 return (jit_arg_reg_p(u->u.w));
327 _jit_ellipsis(jit_state_t *_jit)
329 jit_inc_synth(ellipsis);
330 if (_jitc->prepare) {
332 assert(!(_jitc->function->call.call & jit_call_varargs));
333 _jitc->function->call.call |= jit_call_varargs;
337 assert(!(_jitc->function->self.call & jit_call_varargs));
338 _jitc->function->self.call |= jit_call_varargs;
340 _jitc->function->vagp = _jitc->function->self.argi;
346 _jit_va_push(jit_state_t *_jit, jit_int32_t u)
348 jit_inc_synth_w(va_push, u);
354 _jit_arg(jit_state_t *_jit, jit_code_t code)
358 assert(_jitc->function);
359 assert(!(_jitc->function->self.call & jit_call_varargs));
360 #if STRONG_TYPE_CHECKING
361 assert(code >= jit_code_arg_c && code <= jit_code_arg);
363 _jitc->function->self.size -= sizeof(jit_word_t);
364 if (jit_arg_reg_p(_jitc->function->self.argi))
365 offset = _jitc->function->self.argi++;
367 offset = _jitc->function->self.size;
368 node = jit_new_node_ww(code, offset,
369 ++_jitc->function->self.argn);
375 _jit_arg_f(jit_state_t *_jit)
379 assert(_jitc->function);
380 _jitc->function->self.size -= sizeof(jit_word_t);
381 if (jit_arg_reg_p(_jitc->function->self.argi))
382 offset = _jitc->function->self.argi++;
384 offset = _jitc->function->self.size;
385 node = jit_new_node_ww(jit_code_arg_f, offset,
386 ++_jitc->function->self.argn);
392 _jit_arg_d(jit_state_t *_jit)
396 assert(_jitc->function);
397 if (_jitc->function->self.argi & 1) {
398 ++_jitc->function->self.argi;
399 _jitc->function->self.size -= sizeof(jit_word_t);
401 _jitc->function->self.size -= sizeof(jit_float64_t);
402 if (jit_arg_reg_p(_jitc->function->self.argi)) {
403 offset = _jitc->function->self.argi + 1;
404 _jitc->function->self.argi += 2;
407 /* "Standard" initial value (-52) is unaligned */
408 if (_jitc->function->self.size & 7)
409 _jitc->function->self.size -= sizeof(jit_word_t);
410 offset = _jitc->function->self.size;
412 node = jit_new_node_ww(jit_code_arg_d, offset,
413 ++_jitc->function->self.argn);
419 _jit_getarg_c(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
421 assert_arg_type(v->code, jit_code_arg_c);
422 jit_inc_synth_wp(getarg_c, u, v);
424 jit_extr_c(u, _R26 - v->u.w);
426 jit_ldxi_c(u, JIT_FP, v->u.w + 3);
431 _jit_getarg_uc(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
433 assert_arg_type(v->code, jit_code_arg_c);
434 jit_inc_synth_wp(getarg_uc, u, v);
436 jit_extr_uc(u, _R26 - v->u.w);
438 jit_ldxi_uc(u, JIT_FP, v->u.w + 3);
443 _jit_getarg_s(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
445 assert_arg_type(v->code, jit_code_arg_s);
446 jit_inc_synth_wp(getarg_s, u, v);
448 jit_extr_s(u, _R26 - v->u.w);
450 jit_ldxi_s(u, JIT_FP, v->u.w + 2);
455 _jit_getarg_us(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
457 assert_arg_type(v->code, jit_code_arg_s);
458 jit_inc_synth_wp(getarg_us, u, v);
460 jit_extr_us(u, _R26 - v->u.w);
462 jit_ldxi_us(u, JIT_FP, v->u.w + 2);
467 _jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
469 assert_arg_type(v->code, jit_code_arg_i);
470 jit_inc_synth_wp(getarg_i, u, v);
472 jit_movr(u, _R26 - v->u.w);
474 jit_ldxi_i(u, JIT_FP, v->u.w);
479 _jit_putargr(jit_state_t *_jit, jit_int32_t u, jit_node_t *v, jit_code_t code)
481 assert_putarg_type(code, v->code);
482 jit_code_inc_synth_wp(code, u, v);
484 jit_movr(_R26 - v->u.w, u);
486 jit_stxi(v->u.w, JIT_FP, u);
491 _jit_putargi(jit_state_t *_jit, jit_word_t u, jit_node_t *v, jit_code_t code)
494 assert_putarg_type(code, v->code);
495 jit_code_inc_synth_wp(code, u, v);
497 jit_movi(_R26 - v->u.w, u);
499 regno = jit_get_reg(jit_class_gpr);
501 jit_stxi(v->u.w, JIT_FP, regno);
502 jit_unget_reg(regno);
508 _jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
510 assert(v->code == jit_code_arg_f);
511 jit_inc_synth_wp(getarg_f, u, v);
513 jit_movr_f(u, _F4 - v->u.w);
515 jit_ldxi_f(u, JIT_FP, v->u.w);
520 _jit_putargr_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
522 assert(v->code == jit_code_arg_f);
523 jit_inc_synth_wp(putargr_f, u, v);
525 jit_movr_f(_F4 - v->u.w, u);
527 jit_stxi_f(v->u.w, JIT_FP, u);
532 _jit_putargi_f(jit_state_t *_jit, jit_float32_t u, jit_node_t *v)
535 assert(v->code == jit_code_arg_f);
536 jit_inc_synth_fp(putargi_f, u, v);
538 jit_movi_f(_R26 - v->u.w, u);
540 regno = jit_get_reg(jit_class_fpr);
541 jit_movi_f(regno, u);
542 jit_stxi_f(v->u.w, JIT_FP, regno);
543 jit_unget_reg(regno);
549 _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
551 assert(v->code == jit_code_arg_d);
552 jit_inc_synth_wp(getarg_d, u, v);
554 jit_movr_d(u, _F4 - v->u.w);
556 jit_ldxi_d(u, JIT_FP, v->u.w);
561 _jit_putargr_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
563 assert(v->code == jit_code_arg_d);
564 jit_inc_synth_wp(putargr_d, u, v);
566 jit_movr_d(_F4 - v->u.w, u);
568 jit_stxi_d(v->u.w, JIT_FP, u);
573 _jit_putargi_d(jit_state_t *_jit, jit_float64_t u, jit_node_t *v)
576 assert(v->code == jit_code_arg_d);
577 jit_inc_synth_dp(putargi_d, u, v);
579 jit_movi_d(_R26 - v->u.w, u);
581 regno = jit_get_reg(jit_class_fpr);
582 jit_movi_d(regno, u);
583 jit_stxi_d(v->u.w, JIT_FP, regno);
584 jit_unget_reg(regno);
590 _jit_pushargr(jit_state_t *_jit, jit_int32_t u, jit_code_t code)
592 assert(_jitc->function);
593 jit_code_inc_synth_w(code, u);
595 _jitc->function->call.size -= sizeof(jit_word_t);
596 if (jit_arg_reg_p(_jitc->function->call.argi)) {
597 jit_movr(_R26 - _jitc->function->call.argi, u);
598 ++_jitc->function->call.argi;
601 jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, u);
606 _jit_pushargi(jit_state_t *_jit, jit_word_t u, jit_code_t code)
609 assert(_jitc->function);
610 jit_code_inc_synth_w(code, u);
612 _jitc->function->call.size -= sizeof(jit_word_t);
613 if (jit_arg_reg_p(_jitc->function->call.argi)) {
614 jit_movi(_R26 - _jitc->function->call.argi, u);
615 ++_jitc->function->call.argi;
618 regno = jit_get_reg(jit_class_gpr);
620 jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, regno);
621 jit_unget_reg(regno);
627 _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
629 assert(_jitc->function);
630 jit_inc_synth_w(pushargr_f, u);
632 _jitc->function->call.size -= sizeof(jit_word_t);
633 if (jit_arg_reg_p(_jitc->function->call.argi)) {
634 jit_movr_f(_F4 - _jitc->function->call.argi, u);
636 /* HP-UX appears to always pass float arguments in gpr registers */
637 if (_jitc->function->call.call & jit_call_varargs)
640 jit_stxi_f(alloca_offset - 8, JIT_FP, u);
641 jit_ldxi(_R26 - _jitc->function->call.argi, JIT_FP,
644 ++_jitc->function->call.argi;
647 jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, u);
652 _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
655 assert(_jitc->function);
656 jit_inc_synth_f(pushargi_f, u);
658 _jitc->function->call.size -= sizeof(jit_word_t);
659 if (jit_arg_reg_p(_jitc->function->call.argi)) {
660 jit_movi_f(_F4 - _jitc->function->call.argi, u);
662 /* HP-UX appears to always pass float arguments in gpr registers */
663 if (_jitc->function->call.call & jit_call_varargs)
666 jit_stxi_f(alloca_offset - 8, JIT_FP,
667 _F4 - _jitc->function->call.argi);
668 jit_ldxi(_R26 - _jitc->function->call.argi,
669 JIT_FP, alloca_offset - 8);
671 ++_jitc->function->call.argi;
674 regno = jit_get_reg(jit_class_fpr);
675 jit_movi_f(regno, u);
676 jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, regno);
677 jit_unget_reg(regno);
683 _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
685 assert(_jitc->function);
686 jit_inc_synth_w(pushargr_d, u);
688 _jitc->function->call.size -= sizeof(jit_float64_t);
689 if (_jitc->function->call.argi & 1) {
690 ++_jitc->function->call.argi;
691 _jitc->function->call.size -= sizeof(jit_word_t);
693 if (jit_arg_reg_p(_jitc->function->call.argi)) {
694 jit_movr_d(_F4 - (_jitc->function->call.argi + 1), u);
696 /* HP-UX appears to always pass float arguments in gpr registers */
697 if (_jitc->function->call.call & jit_call_varargs)
700 jit_stxi_d(alloca_offset - 8, JIT_FP, u);
701 jit_ldxi(_R26 - _jitc->function->call.argi,
702 JIT_FP, alloca_offset - 4);
703 jit_ldxi(_R25 - _jitc->function->call.argi,
704 JIT_FP, alloca_offset - 8);
706 _jitc->function->call.argi += 2;
709 /* "Standard" initial value (-52) is unaligned */
710 if ((_jitc->function->call.size + params_offset) & 7)
711 _jitc->function->call.size -= sizeof(jit_word_t);
712 jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, u);
718 _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
721 assert(_jitc->function);
722 jit_inc_synth_d(pushargi_d, u);
724 _jitc->function->call.size -= sizeof(jit_float64_t);
725 if (_jitc->function->call.argi & 1) {
726 ++_jitc->function->call.argi;
727 _jitc->function->call.size -= sizeof(jit_word_t);
729 if (jit_arg_reg_p(_jitc->function->call.argi)) {
730 jit_movi_d(_F4 - (_jitc->function->call.argi + 1), u);
732 /* HP-UX appears to always pass float arguments in gpr registers */
733 if (_jitc->function->call.call & jit_call_varargs)
736 jit_stxi_d(alloca_offset - 8, JIT_FP,
737 _F4 - (_jitc->function->call.argi + 1));
738 jit_ldxi(_R26 - _jitc->function->call.argi,
739 JIT_FP, alloca_offset - 4);
740 jit_ldxi(_R25 - _jitc->function->call.argi,
741 JIT_FP, alloca_offset - 8);
743 _jitc->function->call.argi += 2;
746 regno = jit_get_reg(jit_class_fpr);
747 jit_movi_d(regno, u);
748 if ((_jitc->function->call.size + params_offset) & 7)
749 _jitc->function->call.size -= sizeof(jit_word_t);
750 jit_stxi_d(_jitc->function->call.size + params_offset, JIT_SP, regno);
751 jit_unget_reg(regno);
757 _jit_regarg_p(jit_state_t *_jit, jit_node_t *node, jit_int32_t regno)
760 spec = jit_class(_rvs[regno].spec);
761 if (spec & jit_class_arg) {
762 if (spec & jit_class_gpr) {
764 if (regno >= 0 && regno < node->v.w)
767 else if (spec & jit_class_fpr) {
769 if (regno >= 0 && regno < node->w.w)
777 _jit_finishr(jit_state_t *_jit, jit_int32_t r0)
780 assert(_jitc->function);
781 jit_inc_synth_w(finishr, r0);
782 if (_jitc->function->self.alen > _jitc->function->call.size)
783 _jitc->function->self.alen = _jitc->function->call.size;
784 call = jit_callr(r0);
785 call->v.w = call->w.w = _jitc->function->call.argi;
786 _jitc->function->call.argi = _jitc->function->call.size = 0;
792 _jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
795 assert(_jitc->function);
796 jit_inc_synth_w(finishi, (jit_word_t)i0);
797 if (_jitc->function->self.alen > _jitc->function->call.size)
798 _jitc->function->self.alen = _jitc->function->call.size;
799 node = jit_calli(i0);
800 node->v.w = node->w.w = _jitc->function->call.argi;
801 _jitc->function->call.argi = _jitc->function->call.size = 0;
808 _jit_retval_c(jit_state_t *_jit, jit_int32_t r0)
810 jit_inc_synth_w(retval_c, r0);
811 jit_extr_c(r0, JIT_RET);
816 _jit_retval_uc(jit_state_t *_jit, jit_int32_t r0)
818 jit_inc_synth_w(retval_uc, r0);
819 jit_extr_uc(r0, JIT_RET);
824 _jit_retval_s(jit_state_t *_jit, jit_int32_t r0)
826 jit_inc_synth_w(retval_s, r0);
827 jit_extr_s(r0, JIT_RET);
832 _jit_retval_us(jit_state_t *_jit, jit_int32_t r0)
834 jit_inc_synth_w(retval_us, r0);
835 jit_extr_us(r0, JIT_RET);
840 _jit_retval_i(jit_state_t *_jit, jit_int32_t r0)
842 jit_inc_synth_w(retval_i, r0);
843 jit_movr(r0, JIT_RET);
848 _jit_retval_f(jit_state_t *_jit, jit_int32_t r0)
850 jit_inc_synth_w(retval_f, r0);
851 jit_movr_f(r0, JIT_FRET);
856 _jit_retval_d(jit_state_t *_jit, jit_int32_t r0)
858 jit_inc_synth_w(retval_d, r0);
859 jit_movr_d(r0, JIT_FRET);
864 _emit_code(jit_state_t *_jit)
875 #if DEVEL_DISASSEMBLER
878 jit_int32_t patch_offset;
880 #if DEVEL_DISASSEMBLER
884 _jitc->function = NULL;
890 undo.patch_offset = 0;
892 #define case_rr(name, type) \
893 case jit_code_##name##r##type: \
894 name##r##type(rn(node->u.w), rn(node->v.w)); \
896 #define case_rw(name, type) \
897 case jit_code_##name##i##type: \
898 name##i##type(rn(node->u.w), node->v.w); \
900 #define case_wr(name, type) \
901 case jit_code_##name##i##type: \
902 name##i##type(node->u.w, rn(node->v.w)); \
904 #define case_rrr(name, type) \
905 case jit_code_##name##r##type: \
906 name##r##type(rn(node->u.w), \
907 rn(node->v.w), rn(node->w.w)); \
909 #define case_rqr(name, type) \
910 case jit_code_##name##r##type: \
911 name##r##type(rn(node->u.w), rn(node->v.q.l), \
912 rn(node->v.q.h), rn(node->w.w)); \
913 case jit_code_##name##i##type: \
915 #define case_rrrr(name, type) \
916 case jit_code_##name##r##type: \
917 name##r##type(rn(node->u.q.l), rn(node->u.q.h), \
918 rn(node->v.w), rn(node->w.w)); \
920 #define case_rrw(name, type) \
921 case jit_code_##name##i##type: \
922 name##i##type(rn(node->u.w),rn(node->v.w), node->w.w); \
924 #define case_rrrw(name, type) \
925 case jit_code_##name##i##type: \
926 name##i##type(rn(node->u.q.l), rn(node->u.q.h), \
927 rn(node->v.w), node->w.w); \
929 #define case_rrf(name, type, size) \
930 case jit_code_##name##i##type: \
931 assert(node->flag & jit_flag_data); \
932 name##i##type(rn(node->u.w), rn(node->v.w), \
933 (jit_float##size##_t *)node->w.n->u.w); \
935 #define case_wrr(name, type) \
936 case jit_code_##name##i##type: \
937 name##i##type(node->u.w,rn(node->v.w), rn(node->w.w)); \
939 #define case_brr(name, type) \
940 case jit_code_##name##r##type: \
942 assert(temp->code == jit_code_label || \
943 temp->code == jit_code_epilog); \
944 if (temp->flag & jit_flag_patch) \
945 name##r##type(temp->u.w, rn(node->v.w), \
948 word = name##r##type(_jit->pc.w, \
949 rn(node->v.w), rn(node->w.w)); \
953 #define case_brw(name, type) \
954 case jit_code_##name##i##type: \
956 assert(temp->code == jit_code_label || \
957 temp->code == jit_code_epilog); \
958 if (temp->flag & jit_flag_patch) \
959 name##i##type(temp->u.w, \
960 rn(node->v.w), node->w.w); \
962 word = name##i##type(_jit->pc.w, \
963 rn(node->v.w), node->w.w); \
967 #define case_brf(name, type, size) \
968 case jit_code_##name##i##type: \
970 assert(temp->code == jit_code_label || \
971 temp->code == jit_code_epilog); \
972 if (temp->flag & jit_flag_patch) \
973 name##i##type(temp->u.w, rn(node->v.w), \
974 (jit_float##size##_t *)node->w.n->u.w); \
976 word = name##i##type(_jit->pc.w, rn(node->v.w), \
977 (jit_float##size##_t *)node->w.n->u.w); \
981 #if DEVEL_DISASSEMBLER
984 for (node = _jitc->head; node; node = node->next) {
985 if (_jit->pc.uc >= _jitc->code.end)
988 #if DEVEL_DISASSEMBLER
989 node->offset = (jit_uword_t)_jit->pc.w - (jit_uword_t)prevw;
992 value = jit_classify(node->code);
993 jit_regarg_set(node, value);
994 switch (node->code) {
996 /* Must align to a power of two */
997 assert(!(node->u.w & (node->u.w - 1)));
998 if ((word = _jit->pc.w & (node->u.w - 1)))
999 nop(node->u.w - word);
1002 nop((node->u.w + 3) & ~3);
1004 case jit_code_note: case jit_code_name:
1005 node->u.w = _jit->pc.w;
1007 case jit_code_label:
1008 /* remember label is defined */
1009 node->flag |= jit_flag_patch;
1010 node->u.w = _jit->pc.w;
1033 case_rrrr(qmul, _u);
1034 case_rrrw(qmul, _u);
1045 case_rrrr(qdiv, _u);
1046 case_rrrw(qdiv, _u);
1055 #define qlshr(r0, r1, r2, r3) fallback_qlshr(r0, r1, r2, r3)
1056 #define qlshi(r0, r1, r2, i0) fallback_qlshi(r0, r1, r2, i0)
1057 #define qlshr_u(r0, r1, r2, r3) fallback_qlshr_u(r0, r1, r2, r3)
1058 #define qlshi_u(r0, r1, r2, i0) fallback_qlshi_u(r0, r1, r2, i0)
1059 #define qlshi_u(r0, r1, r2, i0) fallback_qlshi_u(r0, r1, r2, i0)
1062 case_rrrr(qlsh, _u);
1063 case_rrrw(qlsh, _u);
1068 #define qrshr(r0, r1, r2, r3) fallback_qrshr(r0, r1, r2, r3)
1069 #define qrshi(r0, r1, r2, i0) fallback_qrshi(r0, r1, r2, i0)
1070 #define qrshr_u(r0, r1, r2, r3) fallback_qrshr_u(r0, r1, r2, r3)
1071 #define qrshi_u(r0, r1, r2, i0) fallback_qrshi_u(r0, r1, r2, i0)
1074 case_rrrr(qrsh, _u);
1075 case_rrrw(qrsh, _u);
1083 casr(rn(node->u.w), rn(node->v.w),
1084 rn(node->w.q.l), rn(node->w.q.h));
1087 casi(rn(node->u.w), node->v.w,
1088 rn(node->w.q.l), rn(node->w.q.h));
1092 if (node->flag & jit_flag_node) {
1094 if (temp->code == jit_code_data ||
1095 (temp->code == jit_code_label &&
1096 (temp->flag & jit_flag_patch)))
1097 movi(rn(node->u.w), temp->u.w);
1099 assert(temp->code == jit_code_label ||
1100 temp->code == jit_code_epilog);
1101 word = movi_p(rn(node->u.w), node->v.w);
1106 movi(rn(node->u.w), node->v.w);
1110 #define clor(r0, r1) fallback_clo(r0, r1)
1111 #define clzr(r0, r1) fallback_clz(r0, r1)
1112 #define ctor(r0, r1) fallback_cto(r0, r1)
1113 #define ctzr(r0, r1) fallback_ctz(r0, r1)
1114 #define rbitr(r0, r1) fallback_rbit(r0, r1)
1115 #define popcntr(r0, r1) fallback_popcnt(r0, r1)
1123 extr(rn(node->u.w), rn(node->v.w), node->w.q.l, node->w.q.h);
1125 case jit_code_extr_u:
1126 extr_u(rn(node->u.w), rn(node->v.w), node->w.q.l, node->w.q.h);
1129 depr(rn(node->u.w), rn(node->v.w), node->w.q.l, node->w.q.h);
1132 depi(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h);
1140 case_rr(bswap, _us);
1141 case_rr(bswap, _ui);
1182 #define unldr(r0, r1, i0) fallback_unldr(r0, r1, i0)
1183 case jit_code_unldr:
1184 unldr(rn(node->u.w), rn(node->v.w), node->w.w);
1186 #define unldi(r0, i0, i1) fallback_unldi(r0, i0, i1)
1187 case jit_code_unldi:
1188 unldi(rn(node->u.w), node->v.w, node->w.w);
1190 #define unldr_u(r0, r1, i0) fallback_unldr_u(r0, r1, i0)
1191 case jit_code_unldr_u:
1192 unldr_u(rn(node->u.w), rn(node->v.w), node->w.w);
1194 #define unldi_u(r0, i0, i1) fallback_unldi_u(r0, i0, i1)
1195 case jit_code_unldi_u:
1196 unldi_u(rn(node->u.w), node->v.w, node->w.w);
1210 #define unstr(r0, r1, i0) fallback_unstr(r0, r1, i0)
1211 case jit_code_unstr:
1212 unstr(rn(node->u.w), rn(node->v.w), node->w.w);
1214 #define unsti(i0, r0, i1) fallback_unsti(i0, r0, i1)
1215 case jit_code_unsti:
1216 unsti(node->u.w, rn(node->v.w), node->w.w);
1244 case_brr(boadd, _u);
1245 case_brw(boadd, _u);
1248 case_brr(bxadd, _u);
1249 case_brw(bxadd, _u);
1252 case_brr(bosub, _u);
1253 case_brw(bosub, _u);
1256 case_brr(bxsub, _u);
1257 case_brw(bxsub, _u);
1259 case jit_code_movi_f:
1260 assert(node->flag & jit_flag_data);
1261 movi_f(rn(node->u.w), (jit_float32_t *)node->v.n->u.w);
1264 case jit_code_movi_d:
1265 assert(node->flag & jit_flag_data);
1266 movi_d(rn(node->u.w), (jit_float64_t *)node->v.n->u.w);
1268 case_rr(trunc, _f_i);
1269 case_rr(trunc, _d_i);
1289 case_rrf(add, _f, 32);
1291 case_rrf(add, _d, 64);
1293 case_rrf(sub, _f, 32);
1294 case_rrf(rsb, _f, 32);
1296 case_rrf(sub, _d, 64);
1297 case_rrf(rsb, _d, 64);
1299 case_rrf(mul, _f, 32);
1301 case_rrf(mul, _d, 64);
1303 case_rrf(div, _f, 32);
1305 case_rrf(div, _d, 64);
1307 case_rrf(lt, _f, 32);
1309 case_rrf(lt, _d, 64);
1311 case_rrf(le, _f, 32);
1313 case_rrf(le, _d, 64);
1315 case_rrf(eq, _f, 32);
1317 case_rrf(eq, _d, 64);
1319 case_rrf(ge, _f, 32);
1321 case_rrf(ge, _d, 64);
1323 case_rrf(gt, _f, 32);
1325 case_rrf(gt, _d, 64);
1327 case_rrf(ne, _f, 32);
1329 case_rrf(ne, _d, 64);
1331 case_rrf(unlt, _f, 32);
1333 case_rrf(unlt, _d, 64);
1335 case_rrf(unle, _f, 32);
1337 case_rrf(unle, _d, 64);
1339 case_rrf(uneq, _f, 32);
1341 case_rrf(uneq, _d, 64);
1343 case_rrf(unge, _f, 32);
1345 case_rrf(unge, _d, 64);
1347 case_rrf(ungt, _f, 32);
1349 case_rrf(ungt, _d, 64);
1351 case_rrf(ltgt, _f, 32);
1353 case_rrf(ltgt, _d, 64);
1355 case_rrf(ord, _f, 32);
1357 case_rrf(ord, _d, 64);
1358 case_rrr(unord, _f);
1359 case_rrf(unord, _f, 32);
1360 case_rrr(unord, _d);
1361 case_rrf(unord, _d, 64);
1370 #define unldr_x(r0, r1, i0) fallback_unldr_x(r0, r1, i0)
1371 case jit_code_unldr_x:
1372 unldr_x(rn(node->u.w), rn(node->v.w), node->w.w);
1374 #define unldi_x(r0, i0, i1) fallback_unldi_x(r0, i0, i1)
1375 case jit_code_unldi_x:
1376 unldi_x(rn(node->u.w), node->v.w, node->w.w);
1386 #define unstr_x(r0, r1, i0) fallback_unstr_x(r0, r1, i0)
1387 case jit_code_unstr_x:
1388 unstr_x(rn(node->u.w), rn(node->v.w), node->w.w);
1390 #define unsti_x(i0, r0, i1) fallback_unsti_x(i0, r0, i1)
1391 case jit_code_unsti_x:
1392 unsti_x(node->u.w, rn(node->v.w), node->w.w);
1395 case_brf(blt, _f, 32);
1397 case_brf(blt, _d, 64);
1399 case_brf(ble, _f, 32);
1401 case_brf(ble, _d, 64);
1403 case_brf(beq, _f, 32);
1405 case_brf(beq, _d, 64);
1407 case_brf(bge, _f, 32);
1409 case_brf(bge, _d, 64);
1411 case_brf(bgt, _f, 32);
1413 case_brf(bgt, _d, 64);
1415 case_brf(bne, _f, 32);
1417 case_brf(bne, _d, 64);
1418 case_brr(bunlt, _f);
1419 case_brf(bunlt, _f, 32);
1420 case_brr(bunlt, _d);
1421 case_brf(bunlt, _d, 64);
1422 case_brr(bunle, _f);
1423 case_brf(bunle, _f, 32);
1424 case_brr(bunle, _d);
1425 case_brf(bunle, _d, 64);
1426 case_brr(buneq, _f);
1427 case_brf(buneq, _f, 32);
1428 case_brr(buneq, _d);
1429 case_brf(buneq, _d, 64);
1430 case_brr(bunge, _f);
1431 case_brf(bunge, _f, 32);
1432 case_brr(bunge, _d);
1433 case_brf(bunge, _d, 64);
1434 case_brr(bungt, _f);
1435 case_brf(bungt, _f, 32);
1436 case_brr(bungt, _d);
1437 case_brf(bungt, _d, 64);
1438 case_brr(bltgt, _f);
1439 case_brf(bltgt, _f, 32);
1440 case_brr(bltgt, _d);
1441 case_brf(bltgt, _d, 64);
1443 case_brf(bord, _f, 32);
1445 case_brf(bord, _d, 64);
1446 case_brr(bunord, _f);
1447 case_brf(bunord, _f, 32);
1448 case_brr(bunord, _d);
1449 case_brf(bunord, _d, 64);
1451 jmpr(rn(node->u.w));
1454 if (node->flag & jit_flag_node) {
1456 assert(temp->code == jit_code_label ||
1457 temp->code == jit_code_epilog);
1458 if (temp->flag & jit_flag_patch)
1461 word = _jit->code.length -
1462 (_jit->pc.uc - _jit->code.ptr);
1463 if (word >= -32768 && word <= 32767)
1464 word = jmpi(_jit->pc.w);
1466 word = jmpi_p(_jit->pc.w);
1473 case jit_code_callr:
1474 callr(rn(node->u.w));
1476 case jit_code_calli:
1477 if (node->flag & jit_flag_node) {
1479 assert(temp->code == jit_code_label ||
1480 temp->code == jit_code_epilog);
1481 if (!(temp->flag & jit_flag_patch)) {
1482 word = calli_p(temp->u.w);
1491 case jit_code_prolog:
1492 _jitc->function = _jitc->functions.ptr + node->w.w;
1494 undo.word = _jit->pc.w;
1495 memcpy(&undo.func, _jitc->function, sizeof(undo.func));
1496 #if DEVEL_DISASSEMBLER
1499 undo.patch_offset = _jitc->patches.offset;
1504 case jit_code_epilog:
1505 assert(_jitc->function == _jitc->functions.ptr + node->w.w);
1507 for (temp = undo.node->next;
1508 temp != node; temp = temp->next) {
1509 if (temp->code == jit_code_label ||
1510 temp->code == jit_code_epilog)
1511 temp->flag &= ~jit_flag_patch;
1513 temp->flag &= ~jit_flag_patch;
1515 _jit->pc.w = undo.word;
1516 /* undo.func.self.aoff and undo.func.regset should not
1517 * be undone, as they will be further updated, and are
1518 * the reason of the undo.
1519 * Note that for hppa use '-' instead of '+' as hppa
1521 undo.func.self.aoff = _jitc->function->frame -
1522 _jitc->function->self.aoff;
1523 jit_regset_set(&undo.func.regset, &_jitc->function->regset);
1524 /* allocar information also does not need to be undone */
1525 undo.func.aoffoff = _jitc->function->aoffoff;
1526 undo.func.allocar = _jitc->function->allocar;
1527 /* cvt_offset must also not be undone */
1528 undo.func.cvt_offset = _jitc->function->cvt_offset;
1529 memcpy(_jitc->function, &undo.func, sizeof(undo.func));
1530 #if DEVEL_DISASSEMBLER
1533 _jitc->patches.offset = undo.patch_offset;
1534 goto restart_function;
1536 /* remember label is defined */
1537 node->flag |= jit_flag_patch;
1538 node->u.w = _jit->pc.w;
1540 _jitc->function = NULL;
1542 case jit_code_movr_w_f:
1543 movr_w_f(rn(node->u.w), rn(node->v.w));
1545 case jit_code_movr_f_w:
1546 movr_f_w(rn(node->u.w), rn(node->v.w));
1548 case jit_code_movi_f_w:
1549 assert(node->flag & jit_flag_data);
1550 movi_f_w(rn(node->u.w), *(jit_float32_t *)node->v.n->u.w);
1552 case jit_code_movi_w_f:
1553 movi_w_f(rn(node->u.w), node->v.w);
1555 case jit_code_movr_ww_d:
1556 movr_ww_d(rn(node->u.w), rn(node->v.w), rn(node->w.w));
1558 case jit_code_movr_d_ww:
1559 movr_d_ww(rn(node->u.w), rn(node->v.w), rn(node->w.w));
1561 case jit_code_movi_d_ww:
1562 assert(node->flag & jit_flag_data);
1563 movi_d_ww(rn(node->u.w), rn(node->v.w),
1564 *(jit_float64_t *)node->w.n->u.w);
1566 case jit_code_movi_ww_d:
1567 movi_ww_d(rn(node->u.w), node->v.w, node->w.w);
1569 case jit_code_va_start:
1570 vastart(rn(node->u.w));
1572 case jit_code_va_arg:
1573 vaarg(rn(node->u.w), rn(node->v.w));
1575 case jit_code_va_arg_d:
1576 vaarg_d(rn(node->u.w), rn(node->v.w));
1578 case jit_code_live: case jit_code_ellipsis:
1579 case jit_code_va_push:
1580 case jit_code_allocai: case jit_code_allocar:
1581 case jit_code_arg_c: case jit_code_arg_s:
1582 case jit_code_arg_i:
1583 case jit_code_arg_f: case jit_code_arg_d:
1584 case jit_code_va_end:
1586 case jit_code_retr_c: case jit_code_reti_c:
1587 case jit_code_retr_uc: case jit_code_reti_uc:
1588 case jit_code_retr_s: case jit_code_reti_s:
1589 case jit_code_retr_us: case jit_code_reti_us:
1590 case jit_code_retr_i: case jit_code_reti_i:
1591 case jit_code_retr_f: case jit_code_reti_f:
1592 case jit_code_retr_d: case jit_code_reti_d:
1593 case jit_code_getarg_c: case jit_code_getarg_uc:
1594 case jit_code_getarg_s: case jit_code_getarg_us:
1595 case jit_code_getarg_i:
1596 case jit_code_getarg_f: case jit_code_getarg_d:
1597 case jit_code_putargr_c: case jit_code_putargi_c:
1598 case jit_code_putargr_uc: case jit_code_putargi_uc:
1599 case jit_code_putargr_s: case jit_code_putargi_s:
1600 case jit_code_putargr_us: case jit_code_putargi_us:
1601 case jit_code_putargr_i: case jit_code_putargi_i:
1602 case jit_code_putargr_f: case jit_code_putargi_f:
1603 case jit_code_putargr_d: case jit_code_putargi_d:
1604 case jit_code_pushargr_c: case jit_code_pushargi_c:
1605 case jit_code_pushargr_uc: case jit_code_pushargi_uc:
1606 case jit_code_pushargr_s: case jit_code_pushargi_s:
1607 case jit_code_pushargr_us: case jit_code_pushargi_us:
1608 case jit_code_pushargr_i: case jit_code_pushargi_i:
1609 case jit_code_pushargr_f: case jit_code_pushargi_f:
1610 case jit_code_pushargr_d: case jit_code_pushargi_d:
1611 case jit_code_retval_c: case jit_code_retval_uc:
1612 case jit_code_retval_s: case jit_code_retval_us:
1613 case jit_code_retval_i:
1614 case jit_code_retval_f: case jit_code_retval_d:
1615 case jit_code_prepare:
1616 case jit_code_finishr: case jit_code_finishi:
1617 case jit_code_negi_f: case jit_code_absi_f:
1618 case jit_code_sqrti_f: case jit_code_negi_d:
1619 case jit_code_absi_d: case jit_code_sqrti_d:
1622 negi(rn(node->u.w), node->v.w);
1625 comi(rn(node->u.w), node->v.w);
1627 case jit_code_exti_c:
1628 exti_c(rn(node->u.w), node->v.w);
1630 case jit_code_exti_uc:
1631 exti_uc(rn(node->u.w), node->v.w);
1633 case jit_code_exti_s:
1634 exti_s(rn(node->u.w), node->v.w);
1636 case jit_code_exti_us:
1637 exti_us(rn(node->u.w), node->v.w);
1639 case jit_code_bswapi_us:
1640 bswapi_us(rn(node->u.w), node->v.w);
1642 case jit_code_bswapi_ui:
1643 bswapi_ui(rn(node->u.w), node->v.w);
1645 case jit_code_htoni_us:
1646 htoni_us(rn(node->u.w), node->v.w);
1648 case jit_code_htoni_ui:
1649 htoni_ui(rn(node->u.w), node->v.w);
1652 cloi(rn(node->u.w), node->v.w);
1655 clzi(rn(node->u.w), node->v.w);
1658 ctoi(rn(node->u.w), node->v.w);
1661 ctzi(rn(node->u.w), node->v.w);
1663 case jit_code_rbiti:
1664 rbiti(rn(node->u.w), node->v.w);
1666 case jit_code_popcnti:
1667 popcnti(rn(node->u.w), node->v.w);
1670 exti(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h);
1672 case jit_code_exti_u:
1673 exti_u(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h);
1678 jit_regarg_clr(node, value);
1679 assert(_jitc->regarg == 0 && _jitc->synth == 0);
1680 /* update register live state */
1696 for (offset = 0; offset < _jitc->patches.offset; offset++) {
1697 node = _jitc->patches.ptr[offset].node;
1698 word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
1699 patch_at(_jitc->patches.ptr[offset].inst, word);
1702 jit_flush(_jit->code.ptr, _jit->pc.uc);
1704 return (_jit->code.ptr);
1708 # include "jit_hppa-cpu.c"
1709 # include "jit_hppa-fpu.c"
1710 # include "jit_fallback.c"
1714 jit_flush(void *fptr, void *tptr)
1717 s = sysconf(_SC_PAGE_SIZE);
1718 f = (jit_word_t)fptr & -s;
1719 t = (((jit_word_t)tptr) + s - 1) & -s;
1721 /* --- parisc2.0.pdf ---
1724 The minimum spacing that is guaranteed to work for "self-modifying code" is
1725 shown in the code segment below. Since instruction prefetching is permitted,
1726 any data cache flushes must be separated from any instruction cache flushes
1727 by a SYNC. This will ensure that the "new" instruction will be written to
1728 memory prior to any attempts at prefetching it as an instruction.
1730 LDIL l%newinstr,rnew
1731 LDW r%newinstr(0,rnew),temp
1733 STW temp,r%instr(0,rinstr)
1734 FDC r%instr(0,rinstr)
1739 (at least seven instructions)
1741 This sequence assumes a uniprocessor system. In a multiprocessor system,
1742 software must ensure no processor is executing code which is in the process
1747 Adapted from ffcall/trampoline/cache-hppa.c:__TR_clear_cache to
1748 loop over addresses as it is unlikely from and to addresses would fit in
1749 at most two cachelines.
1750 FIXME A cache line can be 16, 32, or 64 bytes.
1753 * Copyright 1995-1997 Bruno Haible, <bruno@clisp.org>
1755 * This is free software distributed under the GNU General Public Licence
1756 * described in the file COPYING. Contact the author if you don't have this
1757 * or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
1761 jit_word_t n = f + 32;
1763 for (; f <= t; n = f + 32, f += 64) {
1764 asm volatile ("fdc 0(0,%0)"
1765 "\n\t" "fdc 0(0,%1)"
1770 asm volatile ("mfsp %%sr0,%1"
1771 "\n\t" "ldsid (0,%4),%0"
1772 "\n\t" "mtsp %0,%%sr0"
1773 "\n\t" "fic 0(%%sr0,%2)"
1774 "\n\t" "fic 0(%%sr0,%3)"
1776 "\n\t" "mtsp %1,%%sr0"
1783 : "=r" (u), "=r" (v)
1784 : "r" (f), "r" (n), "r" (f)
1789 /* This is supposed to work but appears to fail on multiprocessor systems */
1790 __clear_cache((void *)f, (void *)t);
1795 _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0)
1797 ldxi(rn(r0), rn(r1), i0);
1801 _emit_stxi(jit_state_t *_jit, jit_word_t i0, jit_gpr_t r0, jit_gpr_t r1)
1803 stxi(i0, rn(r0), rn(r1));
1807 _emit_ldxi_d(jit_state_t *_jit, jit_fpr_t r0, jit_gpr_t r1, jit_word_t i0)
1809 ldxi_d(rn(r0), rn(r1), i0);
1813 _emit_stxi_d(jit_state_t *_jit, jit_word_t i0, jit_gpr_t r0, jit_fpr_t r1)
1815 stxi_d(i0, rn(r0), rn(r1));
1819 _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
1823 assert(node->flag & jit_flag_node);
1824 if (node->code == jit_code_movi)
1825 flag = node->v.n->flag;
1827 flag = node->u.n->flag;
1828 assert(!(flag & jit_flag_patch));
1829 if (_jitc->patches.offset >= _jitc->patches.length) {
1830 jit_realloc((jit_pointer_t *)&_jitc->patches.ptr,
1831 _jitc->patches.length * sizeof(jit_patch_t),
1832 (_jitc->patches.length + 1024) * sizeof(jit_patch_t));
1833 _jitc->patches.length += 1024;
1835 _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
1836 _jitc->patches.ptr[_jitc->patches.offset].node = node;
1837 ++_jitc->patches.offset;