Commit | Line | Data |
---|---|---|
4a71579b | 1 | /* |
79bfeef6 | 2 | * Copyright (C) 2013-2023 Free Software Foundation, Inc. |
4a71579b PC |
3 | * |
4 | * This file is part of GNU lightning. | |
5 | * | |
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) | |
9 | * any later version. | |
10 | * | |
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. | |
15 | * | |
16 | * Authors: | |
17 | * Paulo Cesar Pereira de Andrade | |
18 | */ | |
19 | ||
20 | #include <lightning.h> | |
21 | #include <lightning/jit_private.h> | |
c0c16242 PC |
22 | #if defined(__linux__) |
23 | # include <sys/syscall.h> | |
24 | # include <unistd.h> | |
25 | #endif | |
4a71579b PC |
26 | |
27 | #define jit_arg_reg_p(i) (i >= 0 && i < 4) | |
28 | ||
29 | #define PROTO 1 | |
30 | # include "jit_hppa-cpu.c" | |
31 | # include "jit_hppa-fpu.c" | |
ba3814c1 | 32 | # include "jit_fallback.c" |
4a71579b PC |
33 | #undef PROTO |
34 | ||
35 | /* | |
36 | * Types | |
37 | */ | |
38 | typedef jit_pointer_t jit_va_list; | |
39 | ||
40 | /* | |
41 | * Prototypes | |
42 | */ | |
43 | #define patch(instr, node) _patch(_jit, instr, node) | |
44 | static void _patch(jit_state_t*,jit_word_t,jit_node_t*); | |
45 | ||
46 | /* libgcc */ | |
47 | extern void __clear_cache(void *, void *); | |
48 | ||
49 | /* | |
50 | * Initialization | |
51 | */ | |
ba86ff93 | 52 | jit_cpu_t jit_cpu; |
4a71579b PC |
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 */ | |
68 | /* JIT_R0- JIT_R2 */ | |
69 | { rc(gpr) | rc(sav) | 4, "r4" }, | |
70 | { rc(gpr) | rc(sav) | 5, "r5" }, | |
71 | { rc(gpr) | rc(sav) | 6, "r6" }, | |
72 | /* JIT_V0- JIT_V2 */ | |
73 | { rc(gpr) | rc(sav) | 7, "r7" }, | |
74 | { rc(sav) | rc(sav) | 8, "r8" }, | |
75 | { rc(gpr) | rc(sav) | 9, "r9" }, | |
76 | /* JIT_R3 */ | |
77 | { rc(gpr) | rc(sav) | 10, "r10" }, | |
78 | /* JIT_V3+ */ | |
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" }, | |
87 | /* Arguments */ | |
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 */ | |
93 | { 30, "sp" }, | |
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" }, | |
109 | /* Arguments */ | |
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" }, | |
114 | /* Callee Saves */ | |
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" }, | |
125 | { 0, "fpsr" }, | |
126 | { 1, "fpe2" }, | |
127 | { 2, "fpe4" }, | |
128 | { 3, "fpe6" }, | |
129 | { _NOREG, "<none>" }, | |
130 | }; | |
131 | ||
132 | /* | |
133 | * Implementation | |
134 | */ | |
135 | void | |
136 | jit_get_cpu(void) | |
137 | { | |
138 | /* FIXME Expecting PARISC 2.0, for PARISC 1.0 should not use fr16-fr31 */ | |
ba86ff93 PC |
139 | |
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. */ | |
144 | jit_cpu.imm_idx = 1; | |
4a71579b PC |
145 | } |
146 | ||
147 | void | |
148 | _jit_init(jit_state_t *_jit) | |
149 | { | |
150 | _jitc->reglen = jit_size(_rvs) - 1; | |
151 | } | |
152 | ||
153 | void | |
154 | _jit_prolog(jit_state_t *_jit) | |
155 | { | |
156 | jit_int32_t offset; | |
157 | ||
158 | if (_jitc->function) | |
159 | jit_epilog(); | |
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; | |
168 | } | |
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; | |
ba86ff93 | 174 | _jitc->function->cvt_offset = alloca_offset - 8; |
4a71579b PC |
175 | _jitc->function->self.call = jit_call_default; |
176 | jit_alloc((jit_pointer_t *)&_jitc->function->regoff, | |
177 | _jitc->reglen * sizeof(jit_int32_t)); | |
178 | ||
179 | /* _no_link here does not mean the jit_link() call can be removed | |
180 | * by rewriting as: | |
181 | * _jitc->function->prolog = jit_new_node(jit_code_prolog); | |
182 | */ | |
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); | |
187 | /* u: label value | |
188 | * v: offset in blocks vector | |
189 | * w: offset in functions vector | |
190 | */ | |
191 | _jitc->function->epilog->w.w = offset; | |
192 | ||
193 | jit_regset_new(&_jitc->function->regset); | |
194 | } | |
195 | ||
196 | jit_int32_t | |
197 | _jit_allocai(jit_state_t *_jit, jit_int32_t length) | |
198 | { | |
199 | jit_int32_t offset; | |
200 | assert(_jitc->function); | |
201 | switch (length) { | |
202 | case 0: case 1: | |
203 | break; | |
204 | case 2: | |
205 | _jitc->function->self.aoff = (_jitc->function->self.aoff + 1) & -2; | |
206 | break; | |
207 | case 3: case 4: | |
208 | _jitc->function->self.aoff = (_jitc->function->self.aoff + 3) & -4; | |
209 | break; | |
210 | default: | |
211 | _jitc->function->self.aoff = (_jitc->function->self.aoff + 7) & -8; | |
212 | break; | |
213 | } | |
214 | if (!_jitc->realize) { | |
215 | jit_inc_synth_ww(allocai, _jitc->function->self.aoff, length); | |
216 | jit_dec_synth(); | |
217 | } | |
218 | offset = _jitc->function->self.aoff; | |
219 | _jitc->function->self.aoff += length; | |
220 | return (offset); | |
221 | } | |
222 | ||
223 | void | |
224 | _jit_allocar(jit_state_t *_jit, jit_int32_t u, jit_int32_t v) | |
225 | { | |
226 | jit_int32_t reg; | |
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; | |
232 | } | |
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); | |
239 | jit_unget_reg(reg); | |
240 | jit_dec_synth(); | |
241 | } | |
242 | ||
243 | void | |
244 | _jit_ret(jit_state_t *_jit) | |
245 | { | |
246 | jit_node_t *instr; | |
247 | assert(_jitc->function); | |
248 | jit_inc_synth(ret); | |
249 | /* jump to epilog */ | |
250 | instr = jit_jmpi(); | |
251 | jit_patch_at(instr, _jitc->function->epilog); | |
252 | jit_dec_synth(); | |
253 | } | |
254 | ||
255 | void | |
79bfeef6 | 256 | _jit_retr(jit_state_t *_jit, jit_int32_t u, jit_code_t code) |
4a71579b | 257 | { |
79bfeef6 | 258 | jit_code_inc_synth_w(code, u); |
4a71579b PC |
259 | jit_movr(JIT_RET, u); |
260 | jit_ret(); | |
261 | jit_dec_synth(); | |
262 | } | |
263 | ||
264 | void | |
79bfeef6 | 265 | _jit_reti(jit_state_t *_jit, jit_word_t u, jit_code_t code) |
4a71579b | 266 | { |
79bfeef6 | 267 | jit_code_inc_synth_w(code, u); |
4a71579b PC |
268 | jit_movi(JIT_RET, u); |
269 | jit_ret(); | |
270 | jit_dec_synth(); | |
271 | } | |
272 | ||
273 | void | |
274 | _jit_retr_f(jit_state_t *_jit, jit_int32_t u) | |
275 | { | |
276 | jit_inc_synth_w(retr_f, u); | |
277 | jit_movr_f(JIT_FRET, u); | |
278 | jit_ret(); | |
279 | jit_dec_synth(); | |
280 | } | |
281 | ||
282 | void | |
283 | _jit_reti_f(jit_state_t *_jit, jit_float32_t u) | |
284 | { | |
285 | jit_inc_synth_f(reti_f, u); | |
286 | jit_movi_f(JIT_FRET, u); | |
287 | jit_ret(); | |
288 | jit_dec_synth(); | |
289 | } | |
290 | ||
291 | void | |
292 | _jit_retr_d(jit_state_t *_jit, jit_int32_t u) | |
293 | { | |
294 | jit_inc_synth_w(retr_d, u); | |
295 | jit_movr_d(JIT_FRET, u); | |
296 | jit_ret(); | |
297 | jit_dec_synth(); | |
298 | } | |
299 | ||
300 | void | |
301 | _jit_reti_d(jit_state_t *_jit, jit_float64_t u) | |
302 | { | |
303 | jit_inc_synth_d(reti_d, u); | |
304 | jit_movi_d(JIT_FRET, u); | |
305 | jit_ret(); | |
306 | jit_dec_synth(); | |
307 | } | |
308 | ||
309 | void | |
310 | _jit_epilog(jit_state_t *_jit) | |
311 | { | |
312 | assert(_jitc->function); | |
313 | assert(_jitc->function->epilog->next == NULL); | |
314 | jit_link(_jitc->function->epilog); | |
315 | _jitc->function = NULL; | |
316 | } | |
317 | ||
318 | jit_bool_t | |
319 | _jit_arg_register_p(jit_state_t *_jit, jit_node_t *u) | |
320 | { | |
79bfeef6 | 321 | assert((u->code >= jit_code_arg_c && u->code <= jit_code_arg) || |
4a71579b PC |
322 | u->code == jit_code_arg_f || u->code == jit_code_arg_d); |
323 | return (jit_arg_reg_p(u->u.w)); | |
324 | } | |
325 | ||
326 | void | |
327 | _jit_ellipsis(jit_state_t *_jit) | |
328 | { | |
329 | jit_inc_synth(ellipsis); | |
330 | if (_jitc->prepare) { | |
331 | jit_link_prepare(); | |
332 | assert(!(_jitc->function->call.call & jit_call_varargs)); | |
333 | _jitc->function->call.call |= jit_call_varargs; | |
334 | } | |
335 | else { | |
336 | jit_link_prolog(); | |
337 | assert(!(_jitc->function->self.call & jit_call_varargs)); | |
338 | _jitc->function->self.call |= jit_call_varargs; | |
339 | ||
340 | _jitc->function->vagp = _jitc->function->self.argi; | |
341 | } | |
342 | jit_dec_synth(); | |
343 | } | |
344 | ||
345 | void | |
346 | _jit_va_push(jit_state_t *_jit, jit_int32_t u) | |
347 | { | |
348 | jit_inc_synth_w(va_push, u); | |
349 | jit_pushargr(u); | |
350 | jit_dec_synth(); | |
351 | } | |
352 | ||
353 | jit_node_t * | |
79bfeef6 | 354 | _jit_arg(jit_state_t *_jit, jit_code_t code) |
4a71579b PC |
355 | { |
356 | jit_node_t *node; | |
357 | jit_int32_t offset; | |
358 | assert(_jitc->function); | |
79bfeef6 PC |
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); | |
362 | #endif | |
4a71579b PC |
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++; | |
366 | else | |
367 | offset = _jitc->function->self.size; | |
79bfeef6 | 368 | node = jit_new_node_ww(code, offset, |
4a71579b PC |
369 | ++_jitc->function->self.argn); |
370 | jit_link_prolog(); | |
371 | return (node); | |
372 | } | |
373 | ||
374 | jit_node_t * | |
375 | _jit_arg_f(jit_state_t *_jit) | |
376 | { | |
377 | jit_node_t *node; | |
378 | jit_int32_t offset; | |
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++; | |
383 | else | |
384 | offset = _jitc->function->self.size; | |
385 | node = jit_new_node_ww(jit_code_arg_f, offset, | |
386 | ++_jitc->function->self.argn); | |
387 | jit_link_prolog(); | |
388 | return (node); | |
389 | } | |
390 | ||
391 | jit_node_t * | |
392 | _jit_arg_d(jit_state_t *_jit) | |
393 | { | |
394 | jit_node_t *node; | |
395 | jit_int32_t offset; | |
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); | |
400 | } | |
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; | |
405 | } | |
406 | else { | |
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; | |
411 | } | |
412 | node = jit_new_node_ww(jit_code_arg_d, offset, | |
413 | ++_jitc->function->self.argn); | |
414 | jit_link_prolog(); | |
415 | return (node); | |
416 | } | |
417 | ||
418 | void | |
419 | _jit_getarg_c(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
420 | { | |
79bfeef6 | 421 | assert_arg_type(v->code, jit_code_arg_c); |
4a71579b PC |
422 | jit_inc_synth_wp(getarg_c, u, v); |
423 | if (v->u.w >= 0) | |
424 | jit_extr_c(u, _R26 - v->u.w); | |
425 | else | |
426 | jit_ldxi_c(u, JIT_FP, v->u.w + 3); | |
427 | jit_dec_synth(); | |
428 | } | |
429 | ||
430 | void | |
431 | _jit_getarg_uc(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
432 | { | |
79bfeef6 | 433 | assert_arg_type(v->code, jit_code_arg_c); |
4a71579b PC |
434 | jit_inc_synth_wp(getarg_uc, u, v); |
435 | if (v->u.w >= 0) | |
436 | jit_extr_uc(u, _R26 - v->u.w); | |
437 | else | |
438 | jit_ldxi_uc(u, JIT_FP, v->u.w + 3); | |
439 | jit_dec_synth(); | |
440 | } | |
441 | ||
442 | void | |
443 | _jit_getarg_s(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
444 | { | |
79bfeef6 | 445 | assert_arg_type(v->code, jit_code_arg_s); |
4a71579b PC |
446 | jit_inc_synth_wp(getarg_s, u, v); |
447 | if (v->u.w >= 0) | |
448 | jit_extr_s(u, _R26 - v->u.w); | |
449 | else | |
450 | jit_ldxi_s(u, JIT_FP, v->u.w + 2); | |
451 | jit_dec_synth(); | |
452 | } | |
453 | ||
454 | void | |
455 | _jit_getarg_us(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
456 | { | |
79bfeef6 | 457 | assert_arg_type(v->code, jit_code_arg_s); |
4a71579b PC |
458 | jit_inc_synth_wp(getarg_us, u, v); |
459 | if (v->u.w >= 0) | |
460 | jit_extr_us(u, _R26 - v->u.w); | |
461 | else | |
462 | jit_ldxi_us(u, JIT_FP, v->u.w + 2); | |
463 | jit_dec_synth(); | |
464 | } | |
465 | ||
466 | void | |
467 | _jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
468 | { | |
79bfeef6 | 469 | assert_arg_type(v->code, jit_code_arg_i); |
4a71579b PC |
470 | jit_inc_synth_wp(getarg_i, u, v); |
471 | if (v->u.w >= 0) | |
472 | jit_movr(u, _R26 - v->u.w); | |
473 | else | |
474 | jit_ldxi_i(u, JIT_FP, v->u.w); | |
475 | jit_dec_synth(); | |
476 | } | |
477 | ||
478 | void | |
79bfeef6 | 479 | _jit_putargr(jit_state_t *_jit, jit_int32_t u, jit_node_t *v, jit_code_t code) |
4a71579b | 480 | { |
79bfeef6 PC |
481 | assert_putarg_type(code, v->code); |
482 | jit_code_inc_synth_wp(code, u, v); | |
4a71579b PC |
483 | if (v->u.w >= 0) |
484 | jit_movr(_R26 - v->u.w, u); | |
485 | else | |
486 | jit_stxi(v->u.w, JIT_FP, u); | |
487 | jit_dec_synth(); | |
488 | } | |
489 | ||
490 | void | |
79bfeef6 | 491 | _jit_putargi(jit_state_t *_jit, jit_word_t u, jit_node_t *v, jit_code_t code) |
4a71579b PC |
492 | { |
493 | jit_int32_t regno; | |
79bfeef6 PC |
494 | assert_putarg_type(code, v->code); |
495 | jit_code_inc_synth_wp(code, u, v); | |
4a71579b PC |
496 | if (v->u.w >= 0) |
497 | jit_movi(_R26 - v->u.w, u); | |
498 | else { | |
499 | regno = jit_get_reg(jit_class_gpr); | |
500 | jit_movi(regno, u); | |
501 | jit_stxi(v->u.w, JIT_FP, regno); | |
502 | jit_unget_reg(regno); | |
503 | } | |
504 | jit_dec_synth(); | |
505 | } | |
506 | ||
507 | void | |
508 | _jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
509 | { | |
510 | assert(v->code == jit_code_arg_f); | |
511 | jit_inc_synth_wp(getarg_f, u, v); | |
512 | if (v->u.w >= 0) | |
513 | jit_movr_f(u, _F4 - v->u.w); | |
514 | else | |
515 | jit_ldxi_f(u, JIT_FP, v->u.w); | |
516 | jit_dec_synth(); | |
517 | } | |
518 | ||
519 | void | |
520 | _jit_putargr_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
521 | { | |
522 | assert(v->code == jit_code_arg_f); | |
523 | jit_inc_synth_wp(putargr_f, u, v); | |
524 | if (v->u.w >= 0) | |
525 | jit_movr_f(_F4 - v->u.w, u); | |
526 | else | |
527 | jit_stxi_f(v->u.w, JIT_FP, u); | |
528 | jit_dec_synth(); | |
529 | } | |
530 | ||
531 | void | |
532 | _jit_putargi_f(jit_state_t *_jit, jit_float32_t u, jit_node_t *v) | |
533 | { | |
534 | jit_int32_t regno; | |
535 | assert(v->code == jit_code_arg_f); | |
536 | jit_inc_synth_fp(putargi_f, u, v); | |
537 | if (v->u.w >= 0) | |
538 | jit_movi_f(_R26 - v->u.w, u); | |
539 | else { | |
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); | |
544 | } | |
545 | jit_dec_synth(); | |
546 | } | |
547 | ||
548 | void | |
549 | _jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
550 | { | |
551 | assert(v->code == jit_code_arg_d); | |
552 | jit_inc_synth_wp(getarg_d, u, v); | |
553 | if (v->u.w >= 0) | |
554 | jit_movr_d(u, _F4 - v->u.w); | |
555 | else | |
556 | jit_ldxi_d(u, JIT_FP, v->u.w); | |
557 | jit_dec_synth(); | |
558 | } | |
559 | ||
560 | void | |
561 | _jit_putargr_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v) | |
562 | { | |
563 | assert(v->code == jit_code_arg_d); | |
564 | jit_inc_synth_wp(putargr_d, u, v); | |
565 | if (v->u.w >= 0) | |
566 | jit_movr_d(_F4 - v->u.w, u); | |
567 | else | |
568 | jit_stxi_d(v->u.w, JIT_FP, u); | |
569 | jit_dec_synth(); | |
570 | } | |
571 | ||
572 | void | |
573 | _jit_putargi_d(jit_state_t *_jit, jit_float64_t u, jit_node_t *v) | |
574 | { | |
575 | jit_int32_t regno; | |
576 | assert(v->code == jit_code_arg_d); | |
577 | jit_inc_synth_dp(putargi_d, u, v); | |
578 | if (v->u.w >= 0) | |
579 | jit_movi_d(_R26 - v->u.w, u); | |
580 | else { | |
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); | |
585 | } | |
586 | jit_dec_synth(); | |
587 | } | |
588 | ||
589 | void | |
79bfeef6 | 590 | _jit_pushargr(jit_state_t *_jit, jit_int32_t u, jit_code_t code) |
4a71579b PC |
591 | { |
592 | assert(_jitc->function); | |
79bfeef6 | 593 | jit_code_inc_synth_w(code, u); |
4a71579b PC |
594 | jit_link_prepare(); |
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; | |
599 | } | |
600 | else | |
601 | jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, u); | |
602 | jit_dec_synth(); | |
603 | } | |
604 | ||
605 | void | |
79bfeef6 | 606 | _jit_pushargi(jit_state_t *_jit, jit_word_t u, jit_code_t code) |
4a71579b PC |
607 | { |
608 | jit_int32_t regno; | |
609 | assert(_jitc->function); | |
79bfeef6 | 610 | jit_code_inc_synth_w(code, u); |
4a71579b PC |
611 | jit_link_prepare(); |
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; | |
616 | } | |
617 | else { | |
618 | regno = jit_get_reg(jit_class_gpr); | |
619 | jit_movi(regno, u); | |
620 | jit_stxi(_jitc->function->call.size + params_offset, JIT_SP, regno); | |
621 | jit_unget_reg(regno); | |
622 | } | |
623 | jit_dec_synth(); | |
624 | } | |
625 | ||
626 | void | |
627 | _jit_pushargr_f(jit_state_t *_jit, jit_int32_t u) | |
628 | { | |
629 | assert(_jitc->function); | |
630 | jit_inc_synth_w(pushargr_f, u); | |
631 | jit_link_prepare(); | |
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); | |
635 | #if !defined(__hpux) | |
636 | /* HP-UX appears to always pass float arguments in gpr registers */ | |
637 | if (_jitc->function->call.call & jit_call_varargs) | |
638 | #endif | |
639 | { | |
640 | jit_stxi_f(alloca_offset - 8, JIT_FP, u); | |
641 | jit_ldxi(_R26 - _jitc->function->call.argi, JIT_FP, | |
642 | alloca_offset - 8); | |
643 | } | |
644 | ++_jitc->function->call.argi; | |
645 | } | |
646 | else | |
647 | jit_stxi_f(_jitc->function->call.size + params_offset, JIT_SP, u); | |
648 | jit_dec_synth(); | |
649 | } | |
650 | ||
651 | void | |
652 | _jit_pushargi_f(jit_state_t *_jit, jit_float32_t u) | |
653 | { | |
654 | jit_int32_t regno; | |
655 | assert(_jitc->function); | |
656 | jit_inc_synth_f(pushargi_f, u); | |
657 | jit_link_prepare(); | |
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); | |
661 | #if !defined(__hpux) | |
662 | /* HP-UX appears to always pass float arguments in gpr registers */ | |
663 | if (_jitc->function->call.call & jit_call_varargs) | |
664 | #endif | |
665 | { | |
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); | |
670 | } | |
671 | ++_jitc->function->call.argi; | |
672 | } | |
673 | else { | |
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); | |
678 | } | |
679 | jit_dec_synth(); | |
680 | } | |
681 | ||
682 | void | |
683 | _jit_pushargr_d(jit_state_t *_jit, jit_int32_t u) | |
684 | { | |
685 | assert(_jitc->function); | |
686 | jit_inc_synth_w(pushargr_d, u); | |
687 | jit_link_prepare(); | |
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); | |
692 | } | |
693 | if (jit_arg_reg_p(_jitc->function->call.argi)) { | |
694 | jit_movr_d(_F4 - (_jitc->function->call.argi + 1), u); | |
695 | #if !defined(__hpux) | |
696 | /* HP-UX appears to always pass float arguments in gpr registers */ | |
697 | if (_jitc->function->call.call & jit_call_varargs) | |
698 | #endif | |
699 | { | |
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); | |
705 | } | |
706 | _jitc->function->call.argi += 2; | |
707 | } | |
708 | else { | |
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); | |
713 | } | |
714 | jit_dec_synth(); | |
715 | } | |
716 | ||
717 | void | |
718 | _jit_pushargi_d(jit_state_t *_jit, jit_float64_t u) | |
719 | { | |
720 | jit_int32_t regno; | |
721 | assert(_jitc->function); | |
722 | jit_inc_synth_d(pushargi_d, u); | |
723 | jit_link_prepare(); | |
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); | |
728 | } | |
729 | if (jit_arg_reg_p(_jitc->function->call.argi)) { | |
730 | jit_movi_d(_F4 - (_jitc->function->call.argi + 1), u); | |
731 | #if !defined(__hpux) | |
732 | /* HP-UX appears to always pass float arguments in gpr registers */ | |
733 | if (_jitc->function->call.call & jit_call_varargs) | |
734 | #endif | |
735 | { | |
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); | |
742 | } | |
743 | _jitc->function->call.argi += 2; | |
744 | } | |
745 | else { | |
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); | |
752 | } | |
753 | jit_dec_synth(); | |
754 | } | |
755 | ||
756 | jit_bool_t | |
757 | _jit_regarg_p(jit_state_t *_jit, jit_node_t *node, jit_int32_t regno) | |
758 | { | |
759 | jit_int32_t spec; | |
760 | spec = jit_class(_rvs[regno].spec); | |
761 | if (spec & jit_class_arg) { | |
762 | if (spec & jit_class_gpr) { | |
763 | regno -= _R23; | |
764 | if (regno >= 0 && regno < node->v.w) | |
765 | return (1); | |
766 | } | |
767 | else if (spec & jit_class_fpr) { | |
768 | regno = _F4 - regno; | |
769 | if (regno >= 0 && regno < node->w.w) | |
770 | return (1); | |
771 | } | |
772 | } | |
773 | return (0); | |
774 | } | |
775 | ||
776 | void | |
777 | _jit_finishr(jit_state_t *_jit, jit_int32_t r0) | |
778 | { | |
779 | jit_node_t *call; | |
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; | |
787 | _jitc->prepare = 0; | |
788 | jit_dec_synth(); | |
789 | } | |
790 | ||
791 | jit_node_t * | |
792 | _jit_finishi(jit_state_t *_jit, jit_pointer_t i0) | |
793 | { | |
794 | jit_node_t *node; | |
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; | |
802 | _jitc->prepare = 0; | |
803 | jit_dec_synth(); | |
804 | return (node); | |
805 | } | |
806 | ||
807 | void | |
808 | _jit_retval_c(jit_state_t *_jit, jit_int32_t r0) | |
809 | { | |
810 | jit_inc_synth_w(retval_c, r0); | |
811 | jit_extr_c(r0, JIT_RET); | |
812 | jit_dec_synth(); | |
813 | } | |
814 | ||
815 | void | |
816 | _jit_retval_uc(jit_state_t *_jit, jit_int32_t r0) | |
817 | { | |
818 | jit_inc_synth_w(retval_uc, r0); | |
819 | jit_extr_uc(r0, JIT_RET); | |
820 | jit_dec_synth(); | |
821 | } | |
822 | ||
823 | void | |
824 | _jit_retval_s(jit_state_t *_jit, jit_int32_t r0) | |
825 | { | |
826 | jit_inc_synth_w(retval_s, r0); | |
827 | jit_extr_s(r0, JIT_RET); | |
828 | jit_dec_synth(); | |
829 | } | |
830 | ||
831 | void | |
832 | _jit_retval_us(jit_state_t *_jit, jit_int32_t r0) | |
833 | { | |
834 | jit_inc_synth_w(retval_us, r0); | |
835 | jit_extr_us(r0, JIT_RET); | |
836 | jit_dec_synth(); | |
837 | } | |
838 | ||
839 | void | |
840 | _jit_retval_i(jit_state_t *_jit, jit_int32_t r0) | |
841 | { | |
842 | jit_inc_synth_w(retval_i, r0); | |
843 | jit_movr(r0, JIT_RET); | |
844 | jit_dec_synth(); | |
845 | } | |
846 | ||
847 | void | |
848 | _jit_retval_f(jit_state_t *_jit, jit_int32_t r0) | |
849 | { | |
850 | jit_inc_synth_w(retval_f, r0); | |
851 | jit_movr_f(r0, JIT_FRET); | |
852 | jit_dec_synth(); | |
853 | } | |
854 | ||
855 | void | |
856 | _jit_retval_d(jit_state_t *_jit, jit_int32_t r0) | |
857 | { | |
858 | jit_inc_synth_w(retval_d, r0); | |
859 | jit_movr_d(r0, JIT_FRET); | |
860 | jit_dec_synth(); | |
861 | } | |
862 | ||
863 | jit_pointer_t | |
864 | _emit_code(jit_state_t *_jit) | |
865 | { | |
866 | jit_node_t *node; | |
867 | jit_node_t *temp; | |
868 | jit_word_t word; | |
869 | jit_int32_t value; | |
870 | jit_int32_t offset; | |
871 | struct { | |
872 | jit_node_t *node; | |
873 | jit_word_t word; | |
79bfeef6 | 874 | jit_function_t func; |
4a71579b PC |
875 | #if DEVEL_DISASSEMBLER |
876 | jit_word_t prevw; | |
877 | #endif | |
878 | jit_int32_t patch_offset; | |
879 | } undo; | |
880 | #if DEVEL_DISASSEMBLER | |
881 | jit_word_t prevw; | |
882 | #endif | |
883 | ||
884 | _jitc->function = NULL; | |
885 | ||
886 | jit_reglive_setup(); | |
887 | ||
888 | undo.word = 0; | |
889 | undo.node = NULL; | |
890 | undo.patch_offset = 0; | |
891 | ||
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)); \ | |
895 | break | |
896 | #define case_rw(name, type) \ | |
897 | case jit_code_##name##i##type: \ | |
898 | name##i##type(rn(node->u.w), node->v.w); \ | |
899 | break | |
900 | #define case_wr(name, type) \ | |
901 | case jit_code_##name##i##type: \ | |
902 | name##i##type(node->u.w, rn(node->v.w)); \ | |
903 | break | |
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)); \ | |
908 | break | |
ba86ff93 PC |
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: \ | |
914 | break; | |
4a71579b PC |
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)); \ | |
919 | break | |
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); \ | |
923 | break | |
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); \ | |
928 | break | |
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); \ | |
934 | break | |
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)); \ | |
938 | break | |
939 | #define case_brr(name, type) \ | |
940 | case jit_code_##name##r##type: \ | |
941 | temp = node->u.n; \ | |
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), \ | |
946 | rn(node->w.w)); \ | |
947 | else { \ | |
948 | word = name##r##type(_jit->pc.w, \ | |
949 | rn(node->v.w), rn(node->w.w)); \ | |
950 | patch(word, node); \ | |
951 | } \ | |
952 | break | |
953 | #define case_brw(name, type) \ | |
954 | case jit_code_##name##i##type: \ | |
955 | temp = node->u.n; \ | |
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); \ | |
961 | else { \ | |
962 | word = name##i##type(_jit->pc.w, \ | |
963 | rn(node->v.w), node->w.w); \ | |
964 | patch(word, node); \ | |
965 | } \ | |
966 | break | |
967 | #define case_brf(name, type, size) \ | |
968 | case jit_code_##name##i##type: \ | |
969 | temp = node->u.n; \ | |
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); \ | |
975 | else { \ | |
976 | word = name##i##type(_jit->pc.w, rn(node->v.w), \ | |
977 | (jit_float##size##_t *)node->w.n->u.w); \ | |
978 | patch(word, node); \ | |
979 | } \ | |
980 | break | |
981 | #if DEVEL_DISASSEMBLER | |
982 | prevw = _jit->pc.w; | |
983 | #endif | |
984 | for (node = _jitc->head; node; node = node->next) { | |
985 | if (_jit->pc.uc >= _jitc->code.end) | |
986 | return (NULL); | |
987 | ||
988 | #if DEVEL_DISASSEMBLER | |
989 | node->offset = (jit_uword_t)_jit->pc.w - (jit_uword_t)prevw; | |
990 | prevw = _jit->pc.w; | |
991 | #endif | |
992 | value = jit_classify(node->code); | |
993 | jit_regarg_set(node, value); | |
994 | switch (node->code) { | |
995 | case jit_code_align: | |
c0c16242 PC |
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); | |
4a71579b | 1000 | break; |
79bfeef6 PC |
1001 | case jit_code_skip: |
1002 | nop((node->u.w + 3) & ~3); | |
1003 | break; | |
4a71579b PC |
1004 | case jit_code_note: case jit_code_name: |
1005 | node->u.w = _jit->pc.w; | |
1006 | break; | |
1007 | case jit_code_label: | |
1008 | /* remember label is defined */ | |
1009 | node->flag |= jit_flag_patch; | |
1010 | node->u.w = _jit->pc.w; | |
1011 | break; | |
1012 | case_rrr(add,); | |
1013 | case_rrw(add,); | |
1014 | case_rrr(addc,); | |
1015 | case_rrw(addc,); | |
1016 | case_rrr(addx,); | |
1017 | case_rrw(addx,); | |
1018 | case_rrr(sub,); | |
1019 | case_rrw(sub,); | |
1020 | case_rrr(subc,); | |
1021 | case_rrw(subc,); | |
1022 | case_rrr(subx,); | |
1023 | case_rrw(subx,); | |
1024 | case_rrw(rsb,); | |
1025 | case_rrr(mul,); | |
1026 | case_rrw(mul,); | |
ba86ff93 PC |
1027 | case_rrr(hmul,); |
1028 | case_rrw(hmul,); | |
1029 | case_rrr(hmul, _u); | |
1030 | case_rrw(hmul, _u); | |
4a71579b PC |
1031 | case_rrrr(qmul,); |
1032 | case_rrrw(qmul,); | |
1033 | case_rrrr(qmul, _u); | |
1034 | case_rrrw(qmul, _u); | |
1035 | case_rrr(div,); | |
1036 | case_rrw(div,); | |
1037 | case_rrr(div, _u); | |
1038 | case_rrw(div, _u); | |
1039 | case_rrr(rem,); | |
1040 | case_rrw(rem,); | |
1041 | case_rrr(rem, _u); | |
1042 | case_rrw(rem, _u); | |
1043 | case_rrrr(qdiv,); | |
1044 | case_rrrw(qdiv,); | |
1045 | case_rrrr(qdiv, _u); | |
1046 | case_rrrw(qdiv, _u); | |
1047 | case_rrr(and,); | |
1048 | case_rrw(and,); | |
1049 | case_rrr(or,); | |
1050 | case_rrw(or,); | |
1051 | case_rrr(xor,); | |
1052 | case_rrw(xor,); | |
1053 | case_rrr(lsh,); | |
1054 | case_rrw(lsh,); | |
ba86ff93 PC |
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) | |
1060 | case_rrrr(qlsh,); | |
1061 | case_rrrw(qlsh,); | |
1062 | case_rrrr(qlsh, _u); | |
1063 | case_rrrw(qlsh, _u); | |
4a71579b PC |
1064 | case_rrr(rsh,); |
1065 | case_rrw(rsh,); | |
1066 | case_rrr(rsh, _u); | |
1067 | case_rrw(rsh, _u); | |
ba86ff93 PC |
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) | |
1072 | case_rrrr(qrsh,); | |
1073 | case_rrrw(qrsh,); | |
1074 | case_rrrr(qrsh, _u); | |
1075 | case_rrrw(qrsh, _u); | |
1076 | case_rrr(lrot,); | |
1077 | case_rrw(lrot,); | |
1078 | case_rrr(rrot,); | |
1079 | case_rrw(rrot,); | |
40a44dcb PC |
1080 | case_rrr(movn,); |
1081 | case_rrr(movz,); | |
ba3814c1 PC |
1082 | case jit_code_casr: |
1083 | casr(rn(node->u.w), rn(node->v.w), | |
1084 | rn(node->w.q.l), rn(node->w.q.h)); | |
1085 | break; | |
1086 | case jit_code_casi: | |
1087 | casi(rn(node->u.w), node->v.w, | |
1088 | rn(node->w.q.l), rn(node->w.q.h)); | |
1089 | break; | |
4a71579b PC |
1090 | case_rr(mov,); |
1091 | case jit_code_movi: | |
1092 | if (node->flag & jit_flag_node) { | |
1093 | temp = node->v.n; | |
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); | |
1098 | else { | |
1099 | assert(temp->code == jit_code_label || | |
1100 | temp->code == jit_code_epilog); | |
1101 | word = movi_p(rn(node->u.w), node->v.w); | |
1102 | patch(word, node); | |
1103 | } | |
1104 | } | |
1105 | else | |
1106 | movi(rn(node->u.w), node->v.w); | |
1107 | break; | |
1108 | case_rr(neg,); | |
1109 | case_rr(com,); | |
79bfeef6 PC |
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) | |
ba86ff93 PC |
1114 | #define rbitr(r0, r1) fallback_rbit(r0, r1) |
1115 | #define popcntr(r0, r1) fallback_popcnt(r0, r1) | |
79bfeef6 PC |
1116 | case_rr(clo,); |
1117 | case_rr(clz,); | |
1118 | case_rr(cto,); | |
1119 | case_rr(ctz,); | |
ba86ff93 PC |
1120 | case_rr(rbit,); |
1121 | case_rr(popcnt,); | |
1122 | case jit_code_extr: | |
1123 | extr(rn(node->u.w), rn(node->v.w), node->w.q.l, node->w.q.h); | |
1124 | break; | |
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); | |
1127 | break; | |
1128 | case jit_code_depr: | |
1129 | depr(rn(node->u.w), rn(node->v.w), node->w.q.l, node->w.q.h); | |
1130 | break; | |
1131 | case jit_code_depi: | |
1132 | depi(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h); | |
1133 | break; | |
4a71579b PC |
1134 | case_rr(ext, _c); |
1135 | case_rr(ext, _uc); | |
1136 | case_rr(ext, _s); | |
1137 | case_rr(ext, _us); | |
1138 | case_rr(hton, _us); | |
1139 | case_rr(hton, _ui); | |
40a44dcb PC |
1140 | case_rr(bswap, _us); |
1141 | case_rr(bswap, _ui); | |
4a71579b PC |
1142 | case_rrr(lt,); |
1143 | case_rrw(lt,); | |
1144 | case_rrr(lt, _u); | |
1145 | case_rrw(lt, _u); | |
1146 | case_rrr(le,); | |
1147 | case_rrw(le,); | |
1148 | case_rrr(le, _u); | |
1149 | case_rrw(le, _u); | |
1150 | case_rrr(eq,); | |
1151 | case_rrw(eq,); | |
1152 | case_rrr(ge,); | |
1153 | case_rrw(ge,); | |
1154 | case_rrr(ge, _u); | |
1155 | case_rrw(ge, _u); | |
1156 | case_rrr(gt,); | |
1157 | case_rrw(gt,); | |
1158 | case_rrr(gt, _u); | |
1159 | case_rrw(gt, _u); | |
1160 | case_rrr(ne,); | |
1161 | case_rrw(ne,); | |
1162 | case_rr(ld, _c); | |
1163 | case_rw(ld, _c); | |
1164 | case_rr(ld, _uc); | |
1165 | case_rw(ld, _uc); | |
1166 | case_rr(ld, _s); | |
1167 | case_rw(ld, _s); | |
1168 | case_rr(ld, _us); | |
1169 | case_rw(ld, _us); | |
1170 | case_rr(ld, _i); | |
1171 | case_rw(ld, _i); | |
1172 | case_rrr(ldx, _c); | |
1173 | case_rrw(ldx, _c); | |
1174 | case_rrr(ldx, _uc); | |
1175 | case_rrw(ldx, _uc); | |
1176 | case_rrr(ldx, _s); | |
1177 | case_rrw(ldx, _s); | |
1178 | case_rrr(ldx, _us); | |
1179 | case_rrw(ldx, _us); | |
1180 | case_rrr(ldx, _i); | |
1181 | case_rrw(ldx, _i); | |
ba86ff93 PC |
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); | |
1185 | break; | |
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); | |
1189 | break; | |
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); | |
1193 | break; | |
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); | |
1197 | break; | |
4a71579b PC |
1198 | case_rr(st, _c); |
1199 | case_wr(st, _c); | |
1200 | case_rr(st, _s); | |
1201 | case_wr(st, _s); | |
1202 | case_rr(st, _i); | |
1203 | case_wr(st, _i); | |
1204 | case_rrr(stx, _c); | |
1205 | case_wrr(stx, _c); | |
1206 | case_rrr(stx, _s); | |
1207 | case_wrr(stx, _s); | |
1208 | case_rrr(stx, _i); | |
1209 | case_wrr(stx, _i); | |
ba86ff93 PC |
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); | |
1213 | break; | |
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); | |
1217 | break; | |
4a71579b PC |
1218 | case_brr(blt,); |
1219 | case_brw(blt,); | |
1220 | case_brr(blt, _u); | |
1221 | case_brw(blt, _u); | |
1222 | case_brr(ble,); | |
1223 | case_brw(ble,); | |
1224 | case_brr(ble, _u); | |
1225 | case_brw(ble, _u); | |
1226 | case_brr(beq,); | |
1227 | case_brw(beq,); | |
1228 | case_brr(bge,); | |
1229 | case_brw(bge,); | |
1230 | case_brr(bge, _u); | |
1231 | case_brw(bge, _u); | |
1232 | case_brr(bgt,); | |
1233 | case_brw(bgt,); | |
1234 | case_brr(bgt, _u); | |
1235 | case_brw(bgt, _u); | |
1236 | case_brr(bne,); | |
1237 | case_brw(bne,); | |
1238 | case_brr(bms,); | |
1239 | case_brw(bms,); | |
1240 | case_brr(bmc,); | |
1241 | case_brw(bmc,); | |
1242 | case_brr(boadd,); | |
1243 | case_brw(boadd,); | |
1244 | case_brr(boadd, _u); | |
1245 | case_brw(boadd, _u); | |
1246 | case_brr(bxadd,); | |
1247 | case_brw(bxadd,); | |
1248 | case_brr(bxadd, _u); | |
1249 | case_brw(bxadd, _u); | |
1250 | case_brr(bosub,); | |
1251 | case_brw(bosub,); | |
1252 | case_brr(bosub, _u); | |
1253 | case_brw(bosub, _u); | |
1254 | case_brr(bxsub,); | |
1255 | case_brw(bxsub,); | |
1256 | case_brr(bxsub, _u); | |
1257 | case_brw(bxsub, _u); | |
1258 | case_rr(mov, _f); | |
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); | |
1262 | break; | |
1263 | case_rr(mov, _d); | |
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); | |
1267 | break; | |
1268 | case_rr(trunc, _f_i); | |
1269 | case_rr(trunc, _d_i); | |
1270 | case_rr(ext, _f); | |
1271 | case_rr(ext, _d); | |
1272 | case_rr(ext, _d_f); | |
1273 | case_rr(ext, _f_d); | |
1274 | case_rr(abs, _f); | |
1275 | case_rr(abs, _d); | |
1276 | case_rr(neg, _f); | |
1277 | case_rr(neg, _d); | |
1278 | case_rr(sqrt, _f); | |
ba86ff93 PC |
1279 | case_rqr(fma, _f); |
1280 | case_rqr(fms, _f); | |
1281 | case_rqr(fnma, _f); | |
1282 | case_rqr(fnms, _f); | |
4a71579b | 1283 | case_rr(sqrt, _d); |
ba86ff93 PC |
1284 | case_rqr(fma, _d); |
1285 | case_rqr(fms, _d); | |
1286 | case_rqr(fnma, _d); | |
1287 | case_rqr(fnms, _d); | |
4a71579b PC |
1288 | case_rrr(add, _f); |
1289 | case_rrf(add, _f, 32); | |
1290 | case_rrr(add, _d); | |
1291 | case_rrf(add, _d, 64); | |
1292 | case_rrr(sub, _f); | |
1293 | case_rrf(sub, _f, 32); | |
1294 | case_rrf(rsb, _f, 32); | |
1295 | case_rrr(sub, _d); | |
1296 | case_rrf(sub, _d, 64); | |
1297 | case_rrf(rsb, _d, 64); | |
1298 | case_rrr(mul, _f); | |
1299 | case_rrf(mul, _f, 32); | |
1300 | case_rrr(mul, _d); | |
1301 | case_rrf(mul, _d, 64); | |
1302 | case_rrr(div, _f); | |
1303 | case_rrf(div, _f, 32); | |
1304 | case_rrr(div, _d); | |
1305 | case_rrf(div, _d, 64); | |
1306 | case_rrr(lt, _f); | |
1307 | case_rrf(lt, _f, 32); | |
1308 | case_rrr(lt, _d); | |
1309 | case_rrf(lt, _d, 64); | |
1310 | case_rrr(le, _f); | |
1311 | case_rrf(le, _f, 32); | |
1312 | case_rrr(le, _d); | |
1313 | case_rrf(le, _d, 64); | |
1314 | case_rrr(eq, _f); | |
1315 | case_rrf(eq, _f, 32); | |
1316 | case_rrr(eq, _d); | |
1317 | case_rrf(eq, _d, 64); | |
1318 | case_rrr(ge, _f); | |
1319 | case_rrf(ge, _f, 32); | |
1320 | case_rrr(ge, _d); | |
1321 | case_rrf(ge, _d, 64); | |
1322 | case_rrr(gt, _f); | |
1323 | case_rrf(gt, _f, 32); | |
1324 | case_rrr(gt, _d); | |
1325 | case_rrf(gt, _d, 64); | |
1326 | case_rrr(ne, _f); | |
1327 | case_rrf(ne, _f, 32); | |
1328 | case_rrr(ne, _d); | |
1329 | case_rrf(ne, _d, 64); | |
1330 | case_rrr(unlt, _f); | |
1331 | case_rrf(unlt, _f, 32); | |
1332 | case_rrr(unlt, _d); | |
1333 | case_rrf(unlt, _d, 64); | |
1334 | case_rrr(unle, _f); | |
1335 | case_rrf(unle, _f, 32); | |
1336 | case_rrr(unle, _d); | |
1337 | case_rrf(unle, _d, 64); | |
1338 | case_rrr(uneq, _f); | |
1339 | case_rrf(uneq, _f, 32); | |
1340 | case_rrr(uneq, _d); | |
1341 | case_rrf(uneq, _d, 64); | |
1342 | case_rrr(unge, _f); | |
1343 | case_rrf(unge, _f, 32); | |
1344 | case_rrr(unge, _d); | |
1345 | case_rrf(unge, _d, 64); | |
1346 | case_rrr(ungt, _f); | |
1347 | case_rrf(ungt, _f, 32); | |
1348 | case_rrr(ungt, _d); | |
1349 | case_rrf(ungt, _d, 64); | |
1350 | case_rrr(ltgt, _f); | |
1351 | case_rrf(ltgt, _f, 32); | |
1352 | case_rrr(ltgt, _d); | |
1353 | case_rrf(ltgt, _d, 64); | |
1354 | case_rrr(ord, _f); | |
1355 | case_rrf(ord, _f, 32); | |
1356 | case_rrr(ord, _d); | |
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); | |
1362 | case_rr(ld, _f); | |
1363 | case_rw(ld, _f); | |
1364 | case_rr(ld, _d); | |
1365 | case_rw(ld, _d); | |
1366 | case_rrr(ldx, _f); | |
1367 | case_rrw(ldx, _f); | |
1368 | case_rrr(ldx, _d); | |
1369 | case_rrw(ldx, _d); | |
ba86ff93 PC |
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); | |
1373 | break; | |
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); | |
1377 | break; | |
4a71579b PC |
1378 | case_rr(st, _f); |
1379 | case_wr(st, _f); | |
1380 | case_rr(st, _d); | |
1381 | case_wr(st, _d); | |
1382 | case_rrr(stx, _f); | |
1383 | case_wrr(stx, _f); | |
1384 | case_rrr(stx, _d); | |
1385 | case_wrr(stx, _d); | |
ba86ff93 PC |
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); | |
1389 | break; | |
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); | |
1393 | break; | |
4a71579b PC |
1394 | case_brr(blt, _f); |
1395 | case_brf(blt, _f, 32); | |
1396 | case_brr(blt, _d); | |
1397 | case_brf(blt, _d, 64); | |
1398 | case_brr(ble, _f); | |
1399 | case_brf(ble, _f, 32); | |
1400 | case_brr(ble, _d); | |
1401 | case_brf(ble, _d, 64); | |
1402 | case_brr(beq, _f); | |
1403 | case_brf(beq, _f, 32); | |
1404 | case_brr(beq, _d); | |
1405 | case_brf(beq, _d, 64); | |
1406 | case_brr(bge, _f); | |
1407 | case_brf(bge, _f, 32); | |
1408 | case_brr(bge, _d); | |
1409 | case_brf(bge, _d, 64); | |
1410 | case_brr(bgt, _f); | |
1411 | case_brf(bgt, _f, 32); | |
1412 | case_brr(bgt, _d); | |
1413 | case_brf(bgt, _d, 64); | |
1414 | case_brr(bne, _f); | |
1415 | case_brf(bne, _f, 32); | |
1416 | case_brr(bne, _d); | |
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); | |
1442 | case_brr(bord, _f); | |
1443 | case_brf(bord, _f, 32); | |
1444 | case_brr(bord, _d); | |
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); | |
1450 | case jit_code_jmpr: | |
1451 | jmpr(rn(node->u.w)); | |
1452 | break; | |
1453 | case jit_code_jmpi: | |
1454 | if (node->flag & jit_flag_node) { | |
1455 | temp = node->u.n; | |
1456 | assert(temp->code == jit_code_label || | |
1457 | temp->code == jit_code_epilog); | |
1458 | if (temp->flag & jit_flag_patch) | |
1459 | jmpi(temp->u.w); | |
1460 | else { | |
79bfeef6 PC |
1461 | word = _jit->code.length - |
1462 | (_jit->pc.uc - _jit->code.ptr); | |
1463 | if (word >= -32768 && word <= 32767) | |
1464 | word = jmpi(_jit->pc.w); | |
1465 | else | |
1466 | word = jmpi_p(_jit->pc.w); | |
4a71579b PC |
1467 | patch(word, node); |
1468 | } | |
1469 | } | |
1470 | else | |
1471 | jmpi(node->u.w); | |
1472 | break; | |
1473 | case jit_code_callr: | |
1474 | callr(rn(node->u.w)); | |
1475 | break; | |
1476 | case jit_code_calli: | |
1477 | if (node->flag & jit_flag_node) { | |
1478 | temp = node->u.n; | |
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); | |
1483 | patch(word, node); | |
1484 | } | |
1485 | else | |
1486 | calli(temp->u.w); | |
1487 | } | |
1488 | else | |
1489 | calli(node->u.w); | |
1490 | break; | |
1491 | case jit_code_prolog: | |
1492 | _jitc->function = _jitc->functions.ptr + node->w.w; | |
1493 | undo.node = node; | |
1494 | undo.word = _jit->pc.w; | |
79bfeef6 | 1495 | memcpy(&undo.func, _jitc->function, sizeof(undo.func)); |
4a71579b PC |
1496 | #if DEVEL_DISASSEMBLER |
1497 | undo.prevw = prevw; | |
1498 | #endif | |
1499 | undo.patch_offset = _jitc->patches.offset; | |
1500 | restart_function: | |
1501 | _jitc->again = 0; | |
1502 | prolog(node); | |
1503 | break; | |
1504 | case jit_code_epilog: | |
1505 | assert(_jitc->function == _jitc->functions.ptr + node->w.w); | |
1506 | if (_jitc->again) { | |
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; | |
1512 | } | |
1513 | temp->flag &= ~jit_flag_patch; | |
1514 | node = undo.node; | |
1515 | _jit->pc.w = undo.word; | |
79bfeef6 PC |
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 | |
1520 | * stack grows up */ | |
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; | |
ba86ff93 PC |
1527 | /* cvt_offset must also not be undone */ |
1528 | undo.func.cvt_offset = _jitc->function->cvt_offset; | |
79bfeef6 | 1529 | memcpy(_jitc->function, &undo.func, sizeof(undo.func)); |
4a71579b PC |
1530 | #if DEVEL_DISASSEMBLER |
1531 | prevw = undo.prevw; | |
1532 | #endif | |
1533 | _jitc->patches.offset = undo.patch_offset; | |
1534 | goto restart_function; | |
1535 | } | |
1536 | /* remember label is defined */ | |
1537 | node->flag |= jit_flag_patch; | |
1538 | node->u.w = _jit->pc.w; | |
1539 | epilog(node); | |
1540 | _jitc->function = NULL; | |
1541 | break; | |
ba86ff93 PC |
1542 | case jit_code_movr_w_f: |
1543 | movr_w_f(rn(node->u.w), rn(node->v.w)); | |
1544 | break; | |
1545 | case jit_code_movr_f_w: | |
1546 | movr_f_w(rn(node->u.w), rn(node->v.w)); | |
1547 | break; | |
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); | |
1551 | break; | |
1552 | case jit_code_movi_w_f: | |
1553 | movi_w_f(rn(node->u.w), node->v.w); | |
1554 | break; | |
1555 | case jit_code_movr_ww_d: | |
1556 | movr_ww_d(rn(node->u.w), rn(node->v.w), rn(node->w.w)); | |
1557 | break; | |
1558 | case jit_code_movr_d_ww: | |
1559 | movr_d_ww(rn(node->u.w), rn(node->v.w), rn(node->w.w)); | |
1560 | break; | |
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); | |
1565 | break; | |
1566 | case jit_code_movi_ww_d: | |
1567 | movi_ww_d(rn(node->u.w), node->v.w, node->w.w); | |
1568 | break; | |
4a71579b PC |
1569 | case jit_code_va_start: |
1570 | vastart(rn(node->u.w)); | |
1571 | break; | |
1572 | case jit_code_va_arg: | |
1573 | vaarg(rn(node->u.w), rn(node->v.w)); | |
1574 | break; | |
1575 | case jit_code_va_arg_d: | |
1576 | vaarg_d(rn(node->u.w), rn(node->v.w)); | |
1577 | break; | |
79bfeef6 | 1578 | case jit_code_live: case jit_code_ellipsis: |
4a71579b PC |
1579 | case jit_code_va_push: |
1580 | case jit_code_allocai: case jit_code_allocar: | |
79bfeef6 PC |
1581 | case jit_code_arg_c: case jit_code_arg_s: |
1582 | case jit_code_arg_i: | |
4a71579b PC |
1583 | case jit_code_arg_f: case jit_code_arg_d: |
1584 | case jit_code_va_end: | |
1585 | case jit_code_ret: | |
79bfeef6 PC |
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: | |
4a71579b PC |
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: | |
79bfeef6 PC |
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: | |
4a71579b PC |
1602 | case jit_code_putargr_f: case jit_code_putargi_f: |
1603 | case jit_code_putargr_d: case jit_code_putargi_d: | |
79bfeef6 PC |
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: | |
4a71579b PC |
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: | |
ba86ff93 PC |
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: | |
1620 | break; | |
1621 | case jit_code_negi: | |
1622 | negi(rn(node->u.w), node->v.w); | |
1623 | break; | |
1624 | case jit_code_comi: | |
1625 | comi(rn(node->u.w), node->v.w); | |
1626 | break; | |
1627 | case jit_code_exti_c: | |
1628 | exti_c(rn(node->u.w), node->v.w); | |
1629 | break; | |
1630 | case jit_code_exti_uc: | |
1631 | exti_uc(rn(node->u.w), node->v.w); | |
1632 | break; | |
1633 | case jit_code_exti_s: | |
1634 | exti_s(rn(node->u.w), node->v.w); | |
1635 | break; | |
1636 | case jit_code_exti_us: | |
1637 | exti_us(rn(node->u.w), node->v.w); | |
1638 | break; | |
1639 | case jit_code_bswapi_us: | |
1640 | bswapi_us(rn(node->u.w), node->v.w); | |
1641 | break; | |
1642 | case jit_code_bswapi_ui: | |
1643 | bswapi_ui(rn(node->u.w), node->v.w); | |
1644 | break; | |
1645 | case jit_code_htoni_us: | |
1646 | htoni_us(rn(node->u.w), node->v.w); | |
1647 | break; | |
1648 | case jit_code_htoni_ui: | |
1649 | htoni_ui(rn(node->u.w), node->v.w); | |
1650 | break; | |
1651 | case jit_code_cloi: | |
1652 | cloi(rn(node->u.w), node->v.w); | |
1653 | break; | |
1654 | case jit_code_clzi: | |
1655 | clzi(rn(node->u.w), node->v.w); | |
1656 | break; | |
1657 | case jit_code_ctoi: | |
1658 | ctoi(rn(node->u.w), node->v.w); | |
1659 | break; | |
1660 | case jit_code_ctzi: | |
1661 | ctzi(rn(node->u.w), node->v.w); | |
1662 | break; | |
1663 | case jit_code_rbiti: | |
1664 | rbiti(rn(node->u.w), node->v.w); | |
1665 | break; | |
1666 | case jit_code_popcnti: | |
1667 | popcnti(rn(node->u.w), node->v.w); | |
1668 | break; | |
1669 | case jit_code_exti: | |
1670 | exti(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h); | |
1671 | break; | |
1672 | case jit_code_exti_u: | |
1673 | exti_u(rn(node->u.w), node->v.w, node->w.q.l, node->w.q.h); | |
4a71579b PC |
1674 | break; |
1675 | default: | |
1676 | abort(); | |
1677 | } | |
1678 | jit_regarg_clr(node, value); | |
1679 | assert(_jitc->regarg == 0 && _jitc->synth == 0); | |
1680 | /* update register live state */ | |
1681 | jit_reglive(node); | |
1682 | } | |
1683 | #undef case_brf | |
1684 | #undef case_brw | |
1685 | #undef case_brr | |
1686 | #undef case_wrr | |
1687 | #undef case_rrf | |
1688 | #undef case_rrrw | |
1689 | #undef case_rrw | |
1690 | #undef case_rrrr | |
1691 | #undef case_rrr | |
1692 | #undef case_wr | |
1693 | #undef case_rw | |
1694 | #undef case_rr | |
1695 | ||
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); | |
1700 | } | |
1701 | ||
1702 | jit_flush(_jit->code.ptr, _jit->pc.uc); | |
1703 | ||
1704 | return (_jit->code.ptr); | |
1705 | } | |
1706 | ||
1707 | #define CODE 1 | |
1708 | # include "jit_hppa-cpu.c" | |
1709 | # include "jit_hppa-fpu.c" | |
ba3814c1 | 1710 | # include "jit_fallback.c" |
4a71579b PC |
1711 | #undef CODE |
1712 | ||
1713 | void | |
1714 | jit_flush(void *fptr, void *tptr) | |
1715 | { | |
1716 | jit_word_t f, t, s; | |
1717 | s = sysconf(_SC_PAGE_SIZE); | |
1718 | f = (jit_word_t)fptr & -s; | |
1719 | t = (((jit_word_t)tptr) + s - 1) & -s; | |
1720 | #if defined(__hppa) | |
1721 | /* --- parisc2.0.pdf --- | |
1722 | Programming Note | |
1723 | ||
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. | |
1729 | ||
1730 | LDIL l%newinstr,rnew | |
1731 | LDW r%newinstr(0,rnew),temp | |
1732 | LDIL l%instr,rinstr | |
1733 | STW temp,r%instr(0,rinstr) | |
1734 | FDC r%instr(0,rinstr) | |
1735 | SYNC | |
1736 | FIC r%instr(rinstr) | |
1737 | SYNC | |
1738 | instr ... | |
1739 | (at least seven instructions) | |
1740 | ||
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 | |
1743 | of being modified. | |
1744 | */ | |
1745 | ||
1746 | /* | |
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. | |
1751 | */ | |
1752 | /* | |
1753 | * Copyright 1995-1997 Bruno Haible, <bruno@clisp.org> | |
1754 | * | |
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, | |
1758 | * on this software. | |
1759 | */ | |
1760 | { | |
1761 | jit_word_t n = f + 32; | |
1762 | register int u, v; | |
1763 | for (; f <= t; n = f + 32, f += 64) { | |
1764 | asm volatile ("fdc 0(0,%0)" | |
1765 | "\n\t" "fdc 0(0,%1)" | |
1766 | "\n\t" "sync" | |
1767 | : | |
1768 | : "r" (f), "r" (n) | |
1769 | ); | |
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)" | |
1775 | "\n\t" "sync" | |
1776 | "\n\t" "mtsp %1,%%sr0" | |
1777 | "\n\t" "nop" | |
1778 | "\n\t" "nop" | |
1779 | "\n\t" "nop" | |
1780 | "\n\t" "nop" | |
1781 | "\n\t" "nop" | |
1782 | "\n\t" "nop" | |
1783 | : "=r" (u), "=r" (v) | |
1784 | : "r" (f), "r" (n), "r" (f) | |
1785 | ); | |
1786 | } | |
1787 | } | |
1788 | #else | |
1789 | /* This is supposed to work but appears to fail on multiprocessor systems */ | |
1790 | __clear_cache((void *)f, (void *)t); | |
1791 | #endif | |
1792 | } | |
1793 | ||
1794 | void | |
1795 | _emit_ldxi(jit_state_t *_jit, jit_gpr_t r0, jit_gpr_t r1, jit_word_t i0) | |
1796 | { | |
1797 | ldxi(rn(r0), rn(r1), i0); | |
1798 | } | |
1799 | ||
1800 | void | |
1801 | _emit_stxi(jit_state_t *_jit, jit_word_t i0, jit_gpr_t r0, jit_gpr_t r1) | |
1802 | { | |
1803 | stxi(i0, rn(r0), rn(r1)); | |
1804 | } | |
1805 | ||
1806 | void | |
1807 | _emit_ldxi_d(jit_state_t *_jit, jit_fpr_t r0, jit_gpr_t r1, jit_word_t i0) | |
1808 | { | |
1809 | ldxi_d(rn(r0), rn(r1), i0); | |
1810 | } | |
1811 | ||
1812 | void | |
1813 | _emit_stxi_d(jit_state_t *_jit, jit_word_t i0, jit_gpr_t r0, jit_fpr_t r1) | |
1814 | { | |
1815 | stxi_d(i0, rn(r0), rn(r1)); | |
1816 | } | |
1817 | ||
1818 | static void | |
1819 | _patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node) | |
1820 | { | |
1821 | jit_int32_t flag; | |
1822 | ||
1823 | assert(node->flag & jit_flag_node); | |
1824 | if (node->code == jit_code_movi) | |
1825 | flag = node->v.n->flag; | |
1826 | else | |
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; | |
1834 | } | |
1835 | _jitc->patches.ptr[_jitc->patches.offset].inst = instr; | |
1836 | _jitc->patches.ptr[_jitc->patches.offset].node = node; | |
1837 | ++_jitc->patches.offset; | |
1838 | } |