git subrepo pull --force deps/lightning
[pcsx_rearmed.git] / deps / lightning / lib / jit_alpha.c
CommitLineData
4a71579b 1/*
c0c16242 2 * Copyright (C) 2014-2022 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#define jit_arg_reg_p(i) ((i) >= 0 && (i) < 6)
21#define jit_arg_f_reg_p(i) ((i) >= 0 && (i) < 6)
22#if __BYTE_ORDER == __LITTLE_ENDIAN
23# define C_DISP 0
24# define S_DISP 0
25# define I_DISP 0
26# define F_DISP 0
27#else
28# define C_DISP 8 - sizeof(jit_int8_t)
29# define S_DISP 8 - sizeof(jit_int16_t)
30# define I_DISP 8 - sizeof(jit_int32_t)
31# define F_DISP 8 - sizeof(jit_float32_t)
32#endif
33
34/*
35 * Types
36 */
37/*
38 * What I could understand from gcc/config/alpha/alpha.c:alpha_build_builtin_va_list()
39 * and other helpers, as well as objdump of simple test programs; could not
40 * get gdb working on the test system I had access...
41 *
42 * base-48 to base is where up to 6 float registers are saved.
43 * base to base+48 is where up to 6 integer registers are saved.
44 * base+48... is where varargs arguments are stored.
45 *
46 * if (offset < 48) {
47 * if (type == double)
48 * offset -= 48;
49 * }
50 * load(reg, base, offset);
51 * offset += 8;
52 */
53typedef struct jit_va_list {
54 jit_pointer_t base;
55 jit_word_t offset;
56} jit_va_list_t;
57
58/*
59 * Prototypes
60 */
61#define patch(instr, node) _patch(_jit, instr, node)
62static void _patch(jit_state_t*,jit_word_t,jit_node_t*);
63
64#define PROTO 1
65# include "jit_alpha-cpu.c"
66# include "jit_alpha-fpu.c"
67#undef PROTO
68
69/*
70 * Initialization
71 */
72jit_register_t _rvs[] = {
73 { rc(gpr) | 0x1c, "at" },
74 { rc(gpr) | 0x00, "v0" },
75 { rc(gpr) | 0x01, "t0" },
76 { rc(gpr) | 0x02, "t1" },
77 { rc(gpr) | 0x03, "t2" },
78 { rc(gpr) | 0x04, "t3" },
79 { rc(gpr) | 0x05, "t4" },
80 { rc(gpr) | 0x06, "t5" },
81 { rc(gpr) | 0x07, "t6" },
82 { rc(gpr) | 0x08, "t7" },
83 { rc(gpr) | 0x16, "t8" },
84 { rc(gpr) | 0x17, "t9" },
85 { rc(gpr) | 0x18, "t10" },
86 { rc(gpr) | 0x19, "t11" },
87 { rc(sav) | rc(gpr) | 0x09, "s0" },
88 { rc(sav) | rc(gpr) | 0x0a, "s1" },
89 { rc(sav) | rc(gpr) | 0x0b, "s2" },
90 { rc(sav) | rc(gpr) | 0x0c, "s3" },
91 { rc(sav) | rc(gpr) | 0x0d, "s4" },
92 { rc(sav) | rc(gpr) | 0x0e, "s5" },
93 { 0x0f, "fp" },
94 { rc(arg) | rc(gpr) | 0x15, "a5" },
95 { rc(arg) | rc(gpr) | 0x14, "a4" },
96 { rc(arg) | rc(gpr) | 0x13, "a3" },
97 { rc(arg) | rc(gpr) | 0x12, "a2" },
98 { rc(arg) | rc(gpr) | 0x11, "a1" },
99 { rc(arg) | rc(gpr) | 0x10, "a0" },
100 { 0x1a, "ra" },
101 { 0x1b, "pv" },
102 { 0x1d, "gp" },
103 { 0x1e, "sp" },
104 { 0x1f, "zero" },
105 { rc(fpr) | 0x00, "$f0" },
106 { rc(fpr) | 0x01, "$f1" },
107 { rc(sav) | rc(fpr) | 0x02, "$f2" },
108 { rc(sav) | rc(fpr) | 0x03, "$f3" },
109 { rc(sav) | rc(fpr) | 0x04, "$f4" },
110 { rc(sav) | rc(fpr) | 0x05, "$f5" },
111 { rc(sav) | rc(fpr) | 0x06, "$f6" },
112 { rc(sav) | rc(fpr) | 0x07, "$f7" },
113 { rc(sav) | rc(fpr) | 0x08, "$f8" },
114 { rc(sav) | rc(fpr) | 0x09, "$f9" },
115 { rc(fpr) | 0x0a, "$f10" },
116 { rc(fpr) | 0x0b, "$f11" },
117 { rc(fpr) | 0x0c, "$f12" },
118 { rc(fpr) | 0x0d, "$f13" },
119 { rc(fpr) | 0x0e, "$f14" },
120 { rc(fpr) | 0x0f, "$f15" },
121 { rc(arg) | rc(fpr) | 0x15, "$f21" },
122 { rc(arg) | rc(fpr) | 0x14, "$f20" },
123 { rc(arg) | rc(fpr) | 0x13, "$f19" },
124 { rc(arg) | rc(fpr) | 0x12, "$f18" },
125 { rc(arg) | rc(fpr) | 0x11, "$f17" },
126 { rc(arg) | rc(fpr) | 0x10, "$f16" },
127 { rc(fpr) | 0x16, "$f22" },
128 { rc(fpr) | 0x17, "$f23" },
129 { rc(fpr) | 0x18, "$f24" },
130 { rc(fpr) | 0x19, "$f25" },
131 { rc(fpr) | 0x1a, "$f26" },
132 { rc(fpr) | 0x1b, "$f27" },
133 { rc(fpr) | 0x1c, "$f28" },
134 { rc(fpr) | 0x1d, "$f29" },
135 { rc(fpr) | 0x1e, "$f30" },
136 { 0x1f, "$f31" },
137 { _NOREG, "<none>" },
138};
139
140/*
141 * Implementation
142 */
143void
144jit_get_cpu(void)
145{
146}
147
148void
149_jit_init(jit_state_t *_jit)
150{
151 _jitc->reglen = jit_size(_rvs) - 1;
152 jit_carry = _NOREG;
153}
154
155void
156_jit_prolog(jit_state_t *_jit)
157{
158 jit_int32_t offset;
159
160 if (_jitc->function)
161 jit_epilog();
162 assert(jit_regset_cmp_ui(&_jitc->regarg, 0) == 0);
163 jit_regset_set_ui(&_jitc->regsav, 0);
164 offset = _jitc->functions.offset;
165 if (offset >= _jitc->functions.length) {
166 jit_realloc((jit_pointer_t *)&_jitc->functions.ptr,
167 _jitc->functions.length * sizeof(jit_function_t),
168 (_jitc->functions.length + 16) * sizeof(jit_function_t));
169 _jitc->functions.length += 16;
170 }
171 _jitc->function = _jitc->functions.ptr + _jitc->functions.offset++;
172 _jitc->function->self.size = stack_framesize;
173 _jitc->function->self.argi = _jitc->function->self.alen = 0;
174 /* float conversion */
175 _jitc->function->self.aoff = -8;
176 _jitc->function->self.call = jit_call_default;
177 jit_alloc((jit_pointer_t *)&_jitc->function->regoff,
178 _jitc->reglen * sizeof(jit_int32_t));
179
180 /* _no_link here does not mean the jit_link() call can be removed
181 * by rewriting as:
182 * _jitc->function->prolog = jit_new_node(jit_code_prolog);
183 */
184 _jitc->function->prolog = jit_new_node_no_link(jit_code_prolog);
185 jit_link(_jitc->function->prolog);
186 _jitc->function->prolog->w.w = offset;
187 _jitc->function->epilog = jit_new_node_no_link(jit_code_epilog);
188 /* u: label value
189 * v: offset in blocks vector
190 * w: offset in functions vector
191 */
192 _jitc->function->epilog->w.w = offset;
193
194 jit_regset_new(&_jitc->function->regset);
195}
196
197jit_int32_t
198_jit_allocai(jit_state_t *_jit, jit_int32_t length)
199{
200 assert(_jitc->function != NULL);
201 switch (length) {
202 case 0: case 1: break;
203 case 2: _jitc->function->self.aoff &= -2; break;
204 case 3: case 4: _jitc->function->self.aoff &= -4; break;
205 default: _jitc->function->self.aoff &= -8; break;
206 }
207 _jitc->function->self.aoff -= length;
208 if (!_jitc->realize) {
209 jit_inc_synth_ww(allocai, _jitc->function->self.aoff, length);
210 jit_dec_synth();
211 }
212 return (_jitc->function->self.aoff);
213}
214
215void
216_jit_allocar(jit_state_t *_jit, jit_int32_t u, jit_int32_t v)
217{
218 jit_int32_t reg;
219 assert(_jitc->function != NULL);
220 jit_inc_synth_ww(allocar, u, v);
221 if (!_jitc->function->allocar) {
222 _jitc->function->aoffoff = jit_allocai(sizeof(jit_int32_t));
223 _jitc->function->allocar = 1;
224 }
225 reg = jit_get_reg(jit_class_gpr);
226 jit_negr(reg, v);
227 jit_andi(reg, reg, -8);
228 jit_ldxi_i(u, JIT_FP, _jitc->function->aoffoff);
229 jit_addr(u, u, reg);
230 jit_addr(JIT_SP, JIT_SP, reg);
231 jit_stxi_i(_jitc->function->aoffoff, JIT_FP, u);
232 jit_unget_reg(reg);
233 jit_dec_synth();
234}
235
236void
237_jit_ret(jit_state_t *_jit)
238{
239 jit_node_t *instr;
240 assert(_jitc->function != NULL);
241 jit_inc_synth(ret);
242 /* jump to epilog */
243 instr = jit_jmpi();
244 jit_patch_at(instr, _jitc->function->epilog);
245 jit_dec_synth();
246}
247
248void
249_jit_retr(jit_state_t *_jit, jit_int32_t u)
250{
251 jit_inc_synth_w(retr, u);
252 if (JIT_RET != u)
253 jit_movr(JIT_RET, u);
254 jit_live(JIT_RET);
255 jit_ret();
256 jit_dec_synth();
257}
258
259void
260_jit_reti(jit_state_t *_jit, jit_word_t u)
261{
262 jit_inc_synth_w(reti, u);
263 jit_movi(JIT_RET, u);
264 jit_ret();
265 jit_dec_synth();
266}
267
268void
269_jit_retr_f(jit_state_t *_jit, jit_int32_t u)
270{
271 jit_inc_synth_w(retr_f, u);
272 if (u != JIT_FRET)
273 jit_movr_f(JIT_FRET, u);
274 else
275 jit_live(JIT_FRET);
276 jit_ret();
277 jit_dec_synth();
278}
279
280void
281_jit_reti_f(jit_state_t *_jit, jit_float32_t u)
282{
283 jit_inc_synth_f(reti_f, u);
284 jit_movi_f(JIT_FRET, u);
285 jit_ret();
286 jit_dec_synth();
287}
288
289void
290_jit_retr_d(jit_state_t *_jit, jit_int32_t u)
291{
292 jit_inc_synth_w(retr_d, u);
293 if (u != JIT_FRET)
294 jit_movr_d(JIT_FRET, u);
295 else
296 jit_live(JIT_FRET);
297 jit_ret();
298 jit_dec_synth();
299}
300
301void
302_jit_reti_d(jit_state_t *_jit, jit_float64_t u)
303{
304 jit_inc_synth_d(reti_d, u);
305 jit_movi_d(JIT_FRET, u);
306 jit_ret();
307 jit_dec_synth();
308}
309
310void
311_jit_epilog(jit_state_t *_jit)
312{
313 assert(_jitc->function != NULL);
314 assert(_jitc->function->epilog->next == NULL);
315 jit_link(_jitc->function->epilog);
316 _jitc->function = NULL;
317}
318
319jit_bool_t
320_jit_arg_register_p(jit_state_t *_jit, jit_node_t *u)
321{
322 if (u->code == jit_code_arg)
323 return (jit_arg_reg_p(u->u.w));
324 assert(u->code == jit_code_arg_f || u->code == jit_code_arg_d);
325 return (jit_arg_f_reg_p(u->u.w));
326}
327
328void
329_jit_ellipsis(jit_state_t *_jit)
330{
331 jit_inc_synth(ellipsis);
332 if (_jitc->prepare) {
333 jit_link_prepare();
334 assert(!(_jitc->function->call.call & jit_call_varargs));
335 _jitc->function->call.call |= jit_call_varargs;
336 }
337 else {
338 jit_link_prolog();
339 assert(!(_jitc->function->self.call & jit_call_varargs));
340 _jitc->function->self.call |= jit_call_varargs;
341
342 /* Allocate va_list like object in the stack */
343 _jitc->function->vaoff = jit_allocai(sizeof(jit_va_list_t));
344 _jitc->function->vagp = _jitc->function->self.argi;
345 }
346 jit_dec_synth();
347}
348
349void
350_jit_va_push(jit_state_t *_jit, jit_int32_t u)
351{
352 jit_int32_t reg;
353 jit_inc_synth_w(va_push, u);
354 reg = jit_get_reg(jit_class_gpr);
355 jit_ldxi(reg, u, offsetof(jit_va_list_t, base));
356 jit_pushargr(reg);
357 jit_ldxi(reg, u, offsetof(jit_va_list_t, offset));
358 jit_pushargr(reg);
359 jit_unget_reg(reg);
360 jit_dec_synth();
361}
362
363jit_node_t *
364_jit_arg(jit_state_t *_jit)
365{
366 jit_node_t *node;
367 jit_int32_t offset;
368 assert(_jitc->function != NULL);
369 if (jit_arg_reg_p(_jitc->function->self.argi))
370 offset = _jitc->function->self.argi++;
371 else {
372 offset = _jitc->function->self.size;
373 _jitc->function->self.size += 8;
374 }
375 node = jit_new_node_ww(jit_code_arg, offset,
376 ++_jitc->function->self.argn);
377 jit_link_prolog();
378 return (node);
379}
380
381jit_node_t *
382_jit_arg_f(jit_state_t *_jit)
383{
384 jit_node_t *node;
385 jit_int32_t offset;
386 assert(_jitc->function != NULL);
387 if (jit_arg_f_reg_p(_jitc->function->self.argi))
388 offset = _jitc->function->self.argi++;
389 else {
390 offset = _jitc->function->self.size;
391 _jitc->function->self.size += 8;
392 }
393 node = jit_new_node_ww(jit_code_arg_f, offset,
394 ++_jitc->function->self.argn);
395 jit_link_prolog();
396 return (node);
397}
398
399jit_node_t *
400_jit_arg_d(jit_state_t *_jit)
401{
402 jit_node_t *node;
403 jit_int32_t offset;
404 assert(_jitc->function != NULL);
405 if (jit_arg_f_reg_p(_jitc->function->self.argi))
406 offset = _jitc->function->self.argi++;
407 else {
408 offset = _jitc->function->self.size;
409 _jitc->function->self.size += 8;
410 }
411 node = jit_new_node_ww(jit_code_arg_d, offset,
412 ++_jitc->function->self.argn);
413 jit_link_prolog();
414 return (node);
415}
416
417void
418_jit_getarg_c(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
419{
420 assert(v->code == jit_code_arg);
421 jit_inc_synth_wp(getarg_c, u, v);
422 if (jit_arg_reg_p(v->u.w))
423 jit_extr_c(u, _A0 - v->u.w);
424 else
425 jit_ldxi_c(u, _FP, v->u.w + C_DISP);
426 jit_dec_synth();
427}
428
429void
430_jit_getarg_uc(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
431{
432 assert(v->code == jit_code_arg);
433 jit_inc_synth_wp(getarg_uc, u, v);
434 if (jit_arg_reg_p(v->u.w))
435 jit_extr_uc(u, _A0 - v->u.w);
436 else
437 jit_ldxi_uc(u, _FP, v->u.w + C_DISP);
438 jit_dec_synth();
439}
440
441void
442_jit_getarg_s(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
443{
444 assert(v->code == jit_code_arg);
445 jit_inc_synth_wp(getarg_s, u, v);
446 if (jit_arg_reg_p(v->u.w))
447 jit_extr_s(u, _A0 - v->u.w);
448 else
449 jit_ldxi_s(u, _FP, v->u.w + S_DISP);
450 jit_dec_synth();
451}
452
453void
454_jit_getarg_us(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
455{
456 assert(v->code == jit_code_arg);
457 jit_inc_synth_wp(getarg_us, u, v);
458 if (jit_arg_reg_p(v->u.w))
459 jit_extr_us(u, _A0 - v->u.w);
460 else
461 jit_ldxi_us(u, _FP, v->u.w + S_DISP);
462 jit_dec_synth();
463}
464
465void
466_jit_getarg_i(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
467{
468 assert(v->code == jit_code_arg);
469 jit_inc_synth_wp(getarg_i, u, v);
470 if (jit_arg_reg_p(v->u.w))
471 jit_extr_i(u, _A0 - v->u.w);
472 else
473 jit_ldxi_i(u, _FP, v->u.w + I_DISP);
474 jit_dec_synth();
475}
476
477void
478_jit_getarg_ui(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
479{
480 assert(v->code == jit_code_arg);
481 jit_inc_synth_wp(getarg_ui, u, v);
482 if (jit_arg_reg_p(v->u.w))
483 jit_extr_ui(u, _A0 - v->u.w);
484 else
485 jit_ldxi_ui(u, _FP, v->u.w + I_DISP);
486 jit_dec_synth();
487}
488
489void
490_jit_getarg_l(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
491{
492 assert(v->code == jit_code_arg);
493 jit_inc_synth_wp(getarg_l, u, v);
494 if (jit_arg_reg_p(v->u.w))
495 jit_movr(u, _A0 - v->u.w);
496 else
497 jit_ldxi_l(u, _FP, v->u.w);
498 jit_dec_synth();
499}
500
501void
502_jit_putargr(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
503{
504 assert(v->code == jit_code_arg);
505 jit_inc_synth_wp(putargr, u, v);
506 if (jit_arg_reg_p(v->u.w))
507 jit_movr(_A0 - v->u.w, u);
508 else
509 jit_stxi(v->u.w, _FP, u);
510 jit_dec_synth();
511}
512
513void
514_jit_putargi(jit_state_t *_jit, jit_word_t u, jit_node_t *v)
515{
516 jit_int32_t regno;
517 assert(v->code == jit_code_arg);
518 jit_inc_synth_wp(putargi, u, v);
519 if (jit_arg_reg_p(v->u.w))
520 jit_movi(_A0 - v->u.w, u);
521 else {
522 regno = jit_get_reg(jit_class_gpr);
523 jit_movi(regno, u);
524 jit_stxi(v->u.w, _FP, regno);
525 jit_unget_reg(regno);
526 }
527 jit_dec_synth();
528}
529
530void
531_jit_getarg_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
532{
533 assert(v->code == jit_code_arg_f);
534 jit_inc_synth_wp(getarg_f, u, v);
535 if (jit_arg_f_reg_p(v->u.w))
536 jit_movr_f(u, _F16 - v->u.w);
537 else
538 jit_ldxi_f(u, _FP, v->u.w + F_DISP);
539 jit_dec_synth();
540}
541
542void
543_jit_putargr_f(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
544{
545 assert(v->code == jit_code_arg_f);
546 jit_inc_synth_wp(putargr_f, u, v);
547 if (jit_arg_f_reg_p(v->u.w))
548 jit_movr_f(_F16 - v->u.w, u);
549 else
550 jit_stxi_f(v->u.w, _FP, u + F_DISP);
551 jit_dec_synth();
552}
553
554void
555_jit_putargi_f(jit_state_t *_jit, jit_float32_t u, jit_node_t *v)
556{
557 jit_int32_t regno;
558 assert(v->code == jit_code_arg_f);
559 jit_inc_synth_fp(putargi_f, u, v);
560 if (jit_arg_f_reg_p(v->u.w))
561 jit_movi_f(_F16 - v->u.w, u);
562 else {
563 regno = jit_get_reg(jit_class_fpr);
564 jit_movi_f(regno, u);
565 jit_stxi_f(v->u.w, _FP, regno + F_DISP);
566 jit_unget_reg(regno);
567 }
568 jit_dec_synth();
569}
570
571void
572_jit_getarg_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
573{
574 assert(v->code == jit_code_arg_d);
575 jit_inc_synth_wp(getarg_d, u, v);
576 if (jit_arg_f_reg_p(v->u.w))
577 jit_movr_d(u, _F16 - v->u.w);
578 else
579 jit_ldxi_d(u, _FP, v->u.w);
580 jit_dec_synth();
581}
582
583void
584_jit_putargr_d(jit_state_t *_jit, jit_int32_t u, jit_node_t *v)
585{
586 assert(v->code == jit_code_arg_d);
587 jit_inc_synth_wp(putargr_d, u, v);
588 if (jit_arg_f_reg_p(v->u.w))
589 jit_movr_d(_F16 - v->u.w, u);
590 else
591 jit_stxi_d(v->u.w, _FP, u);
592 jit_dec_synth();
593}
594
595void
596_jit_putargi_d(jit_state_t *_jit, jit_float64_t u, jit_node_t *v)
597{
598 jit_int32_t regno;
599 assert(v->code == jit_code_arg_d);
600 jit_inc_synth_dp(putargi_d, u, v);
601 if (jit_arg_f_reg_p(v->u.w))
602 jit_movi_d(_F16 - v->u.w, u);
603 else {
604 regno = jit_get_reg(jit_class_fpr);
605 jit_movi_d(regno, u);
606 jit_stxi_d(v->u.w, _FP, regno);
607 jit_unget_reg(regno);
608 }
609 jit_dec_synth();
610}
611
612void
613_jit_pushargr(jit_state_t *_jit, jit_int32_t u)
614{
615 assert(_jitc->function != NULL);
616 jit_inc_synth_w(pushargr, u);
617 jit_link_prepare();
618 if (jit_arg_reg_p(_jitc->function->call.argi)) {
619 jit_movr(_A0 - _jitc->function->call.argi, u);
620 ++_jitc->function->call.argi;
621 }
622 else {
623 jit_stxi(_jitc->function->call.size, JIT_SP, u);
624 _jitc->function->call.size += 8;
625 }
626 jit_dec_synth();
627}
628
629void
630_jit_pushargi(jit_state_t *_jit, jit_int64_t u)
631{
632 jit_int32_t regno;
633 assert(_jitc->function != NULL);
634 jit_inc_synth_w(pushargi, u);
635 jit_link_prepare();
636 if (jit_arg_reg_p(_jitc->function->call.argi)) {
637 jit_movi(_A0 - _jitc->function->call.argi, u);
638 ++_jitc->function->call.argi;
639 }
640 else {
641 regno = jit_get_reg(jit_class_gpr);
642 jit_movi(regno, u);
643 jit_stxi(_jitc->function->call.size, JIT_SP, regno);
644 _jitc->function->call.size += 8;
645 jit_unget_reg(regno);
646 }
647 jit_dec_synth();
648}
649
650void
651_jit_pushargr_f(jit_state_t *_jit, jit_int32_t u)
652{
653 assert(_jitc->function != NULL);
654 jit_inc_synth_w(pushargr_f, u);
655 jit_link_prepare();
656 if (jit_arg_f_reg_p(_jitc->function->call.argi)) {
657 jit_movr_f(_F16 - _jitc->function->call.argi, u);
658 ++_jitc->function->call.argi;
659 }
660 else {
661 jit_stxi_f(_jitc->function->call.size + F_DISP, JIT_SP, u);
662 _jitc->function->call.size += 8;
663 }
664 jit_dec_synth();
665}
666
667void
668_jit_pushargi_f(jit_state_t *_jit, jit_float32_t u)
669{
670 jit_int32_t regno;
671 assert(_jitc->function != NULL);
672 jit_inc_synth_f(pushargi_f, u);
673 jit_link_prepare();
674 if (jit_arg_f_reg_p(_jitc->function->call.argi)) {
675 jit_movi_f(_F16 - _jitc->function->call.argi, u);
676 ++_jitc->function->call.argi;
677 }
678 else {
679 regno = jit_get_reg(jit_class_fpr);
680 jit_movi_f(regno, u);
681 jit_stxi_f(_jitc->function->call.size + F_DISP, JIT_SP, regno);
682 _jitc->function->call.size += 8;
683 jit_unget_reg(regno);
684 }
685 jit_dec_synth();
686}
687
688void
689_jit_pushargr_d(jit_state_t *_jit, jit_int32_t u)
690{
691 assert(_jitc->function != NULL);
692 jit_inc_synth_w(pushargr_d, u);
693 jit_link_prepare();
694 if (jit_arg_f_reg_p(_jitc->function->call.argi)) {
695 jit_movr_d(_F16 - _jitc->function->call.argi, u);
696 ++_jitc->function->call.argi;
697 }
698 else {
699 jit_stxi_d(_jitc->function->call.size, JIT_SP, u);
700 _jitc->function->call.size += 8;
701 }
702 jit_dec_synth();
703}
704
705void
706_jit_pushargi_d(jit_state_t *_jit, jit_float64_t u)
707{
708 jit_int32_t regno;
709 assert(_jitc->function != NULL);
710 jit_inc_synth_d(pushargi_d, u);
711 jit_link_prepare();
712 if (jit_arg_f_reg_p(_jitc->function->call.argi)) {
713 jit_movi_d(_F16 - _jitc->function->call.argi, u);
714 ++_jitc->function->call.argi;
715 }
716 else {
717 regno = jit_get_reg(jit_class_fpr);
718 jit_movi_d(regno, u);
719 jit_stxi_d(_jitc->function->call.size, JIT_SP, regno);
720 _jitc->function->call.size += 8;
721 jit_unget_reg(regno);
722 }
723 jit_dec_synth();
724}
725
726jit_bool_t
727_jit_regarg_p(jit_state_t *_jit, jit_node_t *node, jit_int32_t regno)
728{
729 jit_int32_t spec;
730
731 spec = jit_class(_rvs[regno].spec);
732 if (spec & jit_class_arg) {
733 if (spec & jit_class_gpr) {
734 regno = _A0 - regno;
735 if (regno >= 0 && regno < node->v.w)
736 return (1);
737 }
738 else if (spec & jit_class_fpr) {
739 regno = _F16 - regno;
740 if (regno >= 0 && regno < node->w.w)
741 return (1);
742 }
743 }
744
745 return (0);
746}
747
748void
749_jit_finishr(jit_state_t *_jit, jit_int32_t r0)
750{
751 jit_node_t *call;
752 assert(_jitc->function != NULL);
753 jit_inc_synth_w(finishr, r0);
754 if (_jitc->function->self.alen < _jitc->function->call.size)
755 _jitc->function->self.alen = _jitc->function->call.size;
756 call = jit_callr(r0);
757 call->v.w = call->w.w = _jitc->function->self.argi;
758 _jitc->function->call.argi = _jitc->function->call.size = 0;
759 _jitc->prepare = 0;
760 jit_dec_synth();
761}
762
763jit_node_t *
764_jit_finishi(jit_state_t *_jit, jit_pointer_t i0)
765{
766 jit_node_t *call;
767 assert(_jitc->function != NULL);
768 jit_inc_synth_w(finishi, (jit_word_t)i0);
769 if (_jitc->function->self.alen < _jitc->function->call.size)
770 _jitc->function->self.alen = _jitc->function->call.size;
771 call = jit_calli(i0);
772 call->v.w = call->w.w = _jitc->function->self.argf;
773 _jitc->function->call.argi = _jitc->function->call.size = 0;
774 _jitc->prepare = 0;
775 jit_dec_synth();
776 return (call);
777}
778
779void
780_jit_retval_c(jit_state_t *_jit, jit_int32_t r0)
781{
782 jit_inc_synth_w(retval_c, r0);
783 jit_extr_c(r0, JIT_RET);
784 jit_dec_synth();
785}
786
787void
788_jit_retval_uc(jit_state_t *_jit, jit_int32_t r0)
789{
790 jit_inc_synth_w(retval_uc, r0);
791 jit_extr_uc(r0, JIT_RET);
792 jit_dec_synth();
793}
794
795void
796_jit_retval_s(jit_state_t *_jit, jit_int32_t r0)
797{
798 jit_inc_synth_w(retval_s, r0);
799 jit_extr_s(r0, JIT_RET);
800 jit_dec_synth();
801}
802
803void
804_jit_retval_us(jit_state_t *_jit, jit_int32_t r0)
805{
806 jit_inc_synth_w(retval_us, r0);
807 jit_extr_us(r0, JIT_RET);
808 jit_dec_synth();
809}
810
811void
812_jit_retval_i(jit_state_t *_jit, jit_int32_t r0)
813{
814 jit_inc_synth_w(retval_i, r0);
815 jit_extr_i(r0, JIT_RET);
816 jit_dec_synth();
817}
818
819void
820_jit_retval_ui(jit_state_t *_jit, jit_int32_t r0)
821{
822 jit_inc_synth_w(retval_ui, r0);
823 jit_extr_ui(r0, JIT_RET);
824 jit_dec_synth();
825}
826
827void
828_jit_retval_l(jit_state_t *_jit, jit_int32_t r0)
829{
830 jit_inc_synth_w(retval_l, r0);
831 if (r0 != JIT_RET)
832 jit_movr(r0, JIT_RET);
833 jit_dec_synth();
834}
835
836void
837_jit_retval_f(jit_state_t *_jit, jit_int32_t r0)
838{
839 jit_inc_synth_w(retval_f, r0);
840 if (r0 != JIT_FRET)
841 jit_movr_f(r0, JIT_FRET);
842 jit_dec_synth();
843}
844
845void
846_jit_retval_d(jit_state_t *_jit, jit_int32_t r0)
847{
848 jit_inc_synth_w(retval_d, r0);
849 if (r0 != JIT_FRET)
850 jit_movr_d(r0, JIT_FRET);
851 jit_dec_synth();
852}
853
854jit_pointer_t
855_emit_code(jit_state_t *_jit)
856{
857 jit_node_t *node;
858 jit_node_t *temp;
859 jit_word_t word;
860 jit_word_t value;
861 jit_int32_t offset;
862 struct {
863 jit_node_t *node;
864 jit_uint8_t *data;
865 jit_word_t word;
866#if DEVEL_DISASSEMBLER
867 jit_word_t prevw;
868#endif
869 jit_int32_t const_offset;
870 jit_int32_t patch_offset;
871 } undo;
872#if DEVEL_DISASSEMBLER
873 jit_word_t prevw;
874#endif
875
876 _jitc->function = NULL;
877
878 jit_reglive_setup();
879
880 undo.word = 0;
881 undo.node = NULL;
882 undo.const_offset = undo.patch_offset = 0;
883#define case_rr(name, type) \
884 case jit_code_##name##r##type: \
885 name##r##type(rn(node->u.w), rn(node->v.w)); \
886 break
887#define case_rw(name, type) \
888 case jit_code_##name##i##type: \
889 name##i##type(rn(node->u.w), node->v.w); \
890 break
891#define case_wr(name, type) \
892 case jit_code_##name##i##type: \
893 name##i##type(node->u.w, rn(node->v.w)); \
894 break
895#define case_rrr(name, type) \
896 case jit_code_##name##r##type: \
897 name##r##type(rn(node->u.w), \
898 rn(node->v.w), rn(node->w.w)); \
899 break
900#define case_rrw(name, type) \
901 case jit_code_##name##i##type: \
902 name##i##type(rn(node->u.w), rn(node->v.w), node->w.w); \
903 break
904#define case_rrf(name, type, size) \
905 case jit_code_##name##i##type: \
906 assert(node->flag & jit_flag_data); \
907 name##i##type(rn(node->u.w), rn(node->v.w), \
908 (jit_float##size##_t *)node->w.n->u.w); \
909 break
910#define case_rrrr(name, type) \
911 case jit_code_##name##r##type: \
912 name##r##type(rn(node->u.q.l), rn(node->u.q.h), \
913 rn(node->v.w), rn(node->w.w)); \
914 break
915#define case_rrrw(name, type) \
916 case jit_code_##name##i##type: \
917 name##i##type(rn(node->u.q.l), rn(node->u.q.h), \
918 rn(node->v.w), node->w.w); \
919 break
920#define case_wrr(name, type) \
921 case jit_code_##name##i##type: \
922 name##i##type(node->u.w, rn(node->v.w), rn(node->w.w)); \
923 break
924#define case_brr(name, type) \
925 case jit_code_##name##r##type: \
926 temp = node->u.n; \
927 assert(temp->code == jit_code_label || \
928 temp->code == jit_code_epilog); \
929 if (temp->flag & jit_flag_patch) \
930 name##r##type(temp->u.w, rn(node->v.w), \
931 rn(node->w.w)); \
932 else { \
933 word = name##r##type(_jit->pc.w, \
934 rn(node->v.w), rn(node->w.w)); \
935 patch(word, node); \
936 } \
937 break
938#define case_brw(name, type) \
939 case jit_code_##name##i##type: \
940 temp = node->u.n; \
941 assert(temp->code == jit_code_label || \
942 temp->code == jit_code_epilog); \
943 if (temp->flag & jit_flag_patch) \
944 name##i##type(temp->u.w, \
945 rn(node->v.w), node->w.w); \
946 else { \
947 word = name##i##type(_jit->pc.w, \
948 rn(node->v.w), node->w.w); \
949 patch(word, node); \
950 } \
951 break
952#define case_brf(name, type, size) \
953 case jit_code_##name##i##type: \
954 temp = node->u.n; \
955 assert(temp->code == jit_code_label || \
956 temp->code == jit_code_epilog); \
957 if (temp->flag & jit_flag_patch) \
958 name##i##type(temp->u.w, rn(node->v.w), \
959 (jit_float##size##_t *)node->w.n->u.w); \
960 else { \
961 word = name##i##type(_jit->pc.w, rn(node->v.w), \
962 (jit_float##size##_t *)node->w.n->u.w); \
963 patch(word, node); \
964 } \
965 break
966#if DEVEL_DISASSEMBLER
967 prevw = _jit->pc.w;
968#endif
969 for (node = _jitc->head; node; node = node->next) {
970 if (_jit->pc.uc >= _jitc->code.end)
971 return (NULL);
972
973#if DEVEL_DISASSEMBLER
974 node->offset = (jit_uword_t)_jit->pc.w - (jit_uword_t)prevw;
975 prevw = _jit->pc.w;
976#endif
977 value = jit_classify(node->code);
978 jit_regarg_set(node, value);
979 switch (node->code) {
980 case jit_code_align:
c0c16242
PC
981 /* Must align to a power of two */
982 assert(!(node->u.w & (node->u.w - 1)));
983 if ((word = _jit->pc.w & (node->u.w - 1)))
984 nop(node->u.w - word);
4a71579b
PC
985 break;
986 case jit_code_note: case jit_code_name:
987 node->u.w = _jit->pc.w;
988 break;
989 case jit_code_label:
990 /* remember label is defined */
991 node->flag |= jit_flag_patch;
992 node->u.w = _jit->pc.w;
993 break;
994 case_rrr(add,);
995 case_rrw(add,);
996 case_rrr(addc,);
997 case_rrw(addc,);
998 case_rrr(addx,);
999 case_rrw(addx,);
1000 case_rrr(sub,);
1001 case_rrw(sub,);
1002 case_rrr(subc,);
1003 case_rrw(subc,);
1004 case_rrr(subx,);
1005 case_rrw(subx,);
1006 case_rrw(rsb,);
1007 case_rrr(mul,);
1008 case_rrw(mul,);
1009 case_rrrr(qmul,);
1010 case_rrrw(qmul,);
1011 case_rrrr(qmul, _u);
1012 case_rrrw(qmul, _u);
1013 case_rrr(div,);
1014 case_rrw(div,);
1015 case_rrr(div, _u);
1016 case_rrw(div, _u);
1017 case_rrrr(qdiv,);
1018 case_rrrw(qdiv,);
1019 case_rrrr(qdiv, _u);
1020 case_rrrw(qdiv, _u);
1021 case_rrr(rem,);
1022 case_rrw(rem,);
1023 case_rrr(rem, _u);
1024 case_rrw(rem, _u);
1025 case_rrr(lsh,);
1026 case_rrw(lsh,);
1027 case_rrr(rsh,);
1028 case_rrw(rsh,);
1029 case_rrr(rsh, _u);
1030 case_rrw(rsh, _u);
1031 case_rrr(and,);
1032 case_rrw(and,);
1033 case_rrr(or,);
1034 case_rrw(or,);
1035 case_rrr(xor,);
1036 case_rrw(xor,);
1037 case_rr(trunc, _f_i);
1038 case_rr(trunc, _d_i);
1039 case_rr(trunc, _f_l);
1040 case_rr(trunc, _d_l);
1041 case_rr(ld, _c);
1042 case_rw(ld, _c);
1043 case_rr(ld, _uc);
1044 case_rw(ld, _uc);
1045 case_rr(ld, _s);
1046 case_rw(ld, _s);
1047 case_rr(ld, _us);
1048 case_rw(ld, _us);
1049 case_rr(ld, _i);
1050 case_rw(ld, _i);
1051 case_rr(ld, _ui);
1052 case_rw(ld, _ui);
1053 case_rr(ld, _l);
1054 case_rw(ld, _l);
1055 case_rrr(ldx, _c);
1056 case_rrw(ldx, _c);
1057 case_rrr(ldx, _uc);
1058 case_rrw(ldx, _uc);
1059 case_rrr(ldx, _s);
1060 case_rrw(ldx, _s);
1061 case_rrr(ldx, _us);
1062 case_rrw(ldx, _us);
1063 case_rrr(ldx, _i);
1064 case_rrw(ldx, _i);
1065 case_rrr(ldx, _ui);
1066 case_rrw(ldx, _ui);
1067 case_rrr(ldx, _l);
1068 case_rrw(ldx, _l);
1069 case_rr(st, _c);
1070 case_wr(st, _c);
1071 case_rr(st, _s);
1072 case_wr(st, _s);
1073 case_rr(st, _i);
1074 case_wr(st, _i);
1075 case_rr(st, _l);
1076 case_wr(st, _l);
1077 case_rrr(stx, _c);
1078 case_wrr(stx, _c);
1079 case_rrr(stx, _s);
1080 case_wrr(stx, _s);
1081 case_rrr(stx, _i);
1082 case_wrr(stx, _i);
1083 case_rrr(stx, _l);
1084 case_wrr(stx, _l);
1085 case_rr(hton, _us);
1086 case_rr(hton, _ui);
1087 case_rr(hton, _ul);
40a44dcb
PC
1088 case_rr(bswap, _us);
1089 case_rr(bswap, _ui);
1090 case_rr(bswap, _ul);
4a71579b
PC
1091 case_rr(ext, _c);
1092 case_rr(ext, _uc);
1093 case_rr(ext, _s);
1094 case_rr(ext, _us);
1095 case_rr(ext, _i);
1096 case_rr(ext, _ui);
ba3814c1
PC
1097 case jit_code_casr:
1098 casr(rn(node->u.w), rn(node->v.w),
1099 rn(node->w.q.l), rn(node->w.q.h));
1100 break;
1101 case jit_code_casi:
1102 casi(rn(node->u.w), node->v.w,
1103 rn(node->w.q.l), rn(node->w.q.h));
1104 break;
40a44dcb
PC
1105 case_rrr(movn,);
1106 case_rrr(movz,);
4a71579b
PC
1107 case_rr(mov,);
1108 case jit_code_movi:
1109 if (node->flag & jit_flag_node) {
1110 temp = node->v.n;
1111 if (temp->code == jit_code_data ||
1112 (temp->code == jit_code_label &&
1113 (temp->flag & jit_flag_patch)))
1114 movi(rn(node->u.w), temp->u.w);
1115 else {
1116 assert(temp->code == jit_code_label ||
1117 temp->code == jit_code_epilog);
1118 word = movi_p(rn(node->u.w), node->v.w);
1119 patch(word, node);
1120 }
1121 }
1122 else
1123 movi(rn(node->u.w), node->v.w);
1124 break;
1125 case_rr(neg,);
1126 case_rr(com,);
1127 case_rrr(lt,);
1128 case_rrw(lt,);
1129 case_rrr(lt, _u);
1130 case_rrw(lt, _u);
1131 case_rrr(le,);
1132 case_rrw(le,);
1133 case_rrr(le, _u);
1134 case_rrw(le, _u);
1135 case_rrr(eq,);
1136 case_rrw(eq,);
1137 case_rrr(ge,);
1138 case_rrw(ge,);
1139 case_rrr(ge, _u);
1140 case_rrw(ge, _u);
1141 case_rrr(gt,);
1142 case_rrw(gt,);
1143 case_rrr(gt, _u);
1144 case_rrw(gt, _u);
1145 case_rrr(ne,);
1146 case_rrw(ne,);
1147 case_brr(blt,);
1148 case_brw(blt,);
1149 case_brr(blt, _u);
1150 case_brw(blt, _u);
1151 case_brr(ble,);
1152 case_brw(ble,);
1153 case_brr(ble, _u);
1154 case_brw(ble, _u);
1155 case_brr(beq,);
1156 case_brw(beq,);
1157 case_brr(bge,);
1158 case_brw(bge,);
1159 case_brr(bge, _u);
1160 case_brw(bge, _u);
1161 case_brr(bgt,);
1162 case_brw(bgt,);
1163 case_brr(bgt, _u);
1164 case_brw(bgt, _u);
1165 case_brr(bne,);
1166 case_brw(bne,);
1167 case_brr(boadd,);
1168 case_brw(boadd,);
1169 case_brr(boadd, _u);
1170 case_brw(boadd, _u);
1171 case_brr(bxadd,);
1172 case_brw(bxadd,);
1173 case_brr(bxadd, _u);
1174 case_brw(bxadd, _u);
1175 case_brr(bosub,);
1176 case_brw(bosub,);
1177 case_brr(bosub, _u);
1178 case_brw(bosub, _u);
1179 case_brr(bxsub,);
1180 case_brw(bxsub,);
1181 case_brr(bxsub, _u);
1182 case_brw(bxsub, _u);
1183 case_brr(bms,);
1184 case_brw(bms,);
1185 case_brr(bmc,);
1186 case_brw(bmc,);
1187 case_rrr(add, _f);
1188 case_rrf(add, _f, 32);
1189 case_rrr(sub, _f);
1190 case_rrf(sub, _f, 32);
1191 case_rrf(rsb, _f, 32);
1192 case_rrr(mul, _f);
1193 case_rrf(mul, _f, 32);
1194 case_rrr(div, _f);
1195 case_rrf(div, _f, 32);
1196 case_rr(abs, _f);
1197 case_rr(neg, _f);
1198 case_rr(sqrt, _f);
1199 case_rr(ext, _f);
1200 case_rr(ld, _f);
1201 case_rw(ld, _f);
1202 case_rrr(ldx, _f);
1203 case_rrw(ldx, _f);
1204 case_rr(st, _f);
1205 case_wr(st, _f);
1206 case_rrr(stx, _f);
1207 case_wrr(stx, _f);
1208 case_rr(mov, _f);
1209 case jit_code_movi_f:
1210 assert(node->flag & jit_flag_data);
1211 movi_f(rn(node->u.w), (jit_float32_t *)node->v.n->u.w);
1212 break;
1213 case_rr(ext, _d_f);
1214 case_rrr(lt, _f);
1215 case_rrf(lt, _f, 32);
1216 case_rrr(le, _f);
1217 case_rrf(le, _f, 32);
1218 case_rrr(eq, _f);
1219 case_rrf(eq, _f, 32);
1220 case_rrr(ge, _f);
1221 case_rrf(ge, _f, 32);
1222 case_rrr(gt, _f);
1223 case_rrf(gt, _f, 32);
1224 case_rrr(ne, _f);
1225 case_rrf(ne, _f, 32);
1226 case_rrr(unlt, _f);
1227 case_rrf(unlt, _f, 32);
1228 case_rrr(unle, _f);
1229 case_rrf(unle, _f, 32);
1230 case_rrr(uneq, _f);
1231 case_rrf(uneq, _f, 32);
1232 case_rrr(unge, _f);
1233 case_rrf(unge, _f, 32);
1234 case_rrr(ungt, _f);
1235 case_rrf(ungt, _f, 32);
1236 case_rrr(ltgt, _f);
1237 case_rrf(ltgt, _f, 32);
1238 case_rrr(ord, _f);
1239 case_rrf(ord, _f, 32);
1240 case_rrr(unord, _f);
1241 case_rrf(unord, _f, 32);
1242 case_brr(blt, _f);
1243 case_brf(blt, _f, 32);
1244 case_brr(ble, _f);
1245 case_brf(ble, _f, 32);
1246 case_brr(beq, _f);
1247 case_brf(beq, _f, 32);
1248 case_brr(bge, _f);
1249 case_brf(bge, _f, 32);
1250 case_brr(bgt, _f);
1251 case_brf(bgt, _f, 32);
1252 case_brr(bne, _f);
1253 case_brf(bne, _f, 32);
1254 case_brr(bunlt, _f);
1255 case_brf(bunlt, _f, 32);
1256 case_brr(bunle, _f);
1257 case_brf(bunle, _f, 32);
1258 case_brr(buneq, _f);
1259 case_brf(buneq, _f, 32);
1260 case_brr(bunge, _f);
1261 case_brf(bunge, _f, 32);
1262 case_brr(bungt, _f);
1263 case_brf(bungt, _f, 32);
1264 case_brr(bltgt, _f);
1265 case_brf(bltgt, _f, 32);
1266 case_brr(bord, _f);
1267 case_brf(bord, _f, 32);
1268 case_brr(bunord, _f);
1269 case_brf(bunord, _f, 32);
1270 case_rrr(add, _d);
1271 case_rrf(add, _d, 64);
1272 case_rrr(sub, _d);
1273 case_rrf(sub, _d, 64);
1274 case_rrf(rsb, _d, 64);
1275 case_rrr(mul, _d);
1276 case_rrf(mul, _d, 64);
1277 case_rrr(div, _d);
1278 case_rrf(div, _d, 64);
1279 case_rr(abs, _d);
1280 case_rr(neg, _d);
1281 case_rr(sqrt, _d);
1282 case_rr(ext, _d);
1283 case_rr(ld, _d);
1284 case_rw(ld, _d);
1285 case_rrr(ldx, _d);
1286 case_rrw(ldx, _d);
1287 case_rr(st, _d);
1288 case_wr(st, _d);
1289 case_rrr(stx, _d);
1290 case_wrr(stx, _d);
1291 case_rr(mov, _d);
1292 case jit_code_movi_d:
1293 assert(node->flag & jit_flag_data);
1294 movi_d(rn(node->u.w), (jit_float64_t *)node->v.n->u.w);
1295 break;
1296 case_rr(ext, _f_d);
1297 case_rrr(lt, _d);
1298 case_rrf(lt, _d, 64);
1299 case_rrr(le, _d);
1300 case_rrf(le, _d, 64);
1301 case_rrr(eq, _d);
1302 case_rrf(eq, _d, 64);
1303 case_rrr(ge, _d);
1304 case_rrf(ge, _d, 64);
1305 case_rrr(gt, _d);
1306 case_rrf(gt, _d, 64);
1307 case_rrr(ne, _d);
1308 case_rrf(ne, _d, 64);
1309 case_rrr(unlt, _d);
1310 case_rrf(unlt, _d, 64);
1311 case_rrr(unle, _d);
1312 case_rrf(unle, _d, 64);
1313 case_rrr(uneq, _d);
1314 case_rrf(uneq, _d, 64);
1315 case_rrr(unge, _d);
1316 case_rrf(unge, _d, 64);
1317 case_rrr(ungt, _d);
1318 case_rrf(ungt, _d, 64);
1319 case_rrr(ltgt, _d);
1320 case_rrf(ltgt, _d, 64);
1321 case_rrr(ord, _d);
1322 case_rrf(ord, _d, 64);
1323 case_rrr(unord, _d);
1324 case_rrf(unord, _d, 64);
1325 case_brr(blt, _d);
1326 case_brf(blt, _d, 64);
1327 case_brr(ble, _d);
1328 case_brf(ble, _d, 64);
1329 case_brr(beq, _d);
1330 case_brf(beq, _d, 64);
1331 case_brr(bge, _d);
1332 case_brf(bge, _d, 64);
1333 case_brr(bgt, _d);
1334 case_brf(bgt, _d, 64);
1335 case_brr(bne, _d);
1336 case_brf(bne, _d, 64);
1337 case_brr(bunlt, _d);
1338 case_brf(bunlt, _d, 64);
1339 case_brr(bunle, _d);
1340 case_brf(bunle, _d, 64);
1341 case_brr(buneq, _d);
1342 case_brf(buneq, _d, 64);
1343 case_brr(bunge, _d);
1344 case_brf(bunge, _d, 64);
1345 case_brr(bungt, _d);
1346 case_brf(bungt, _d, 64);
1347 case_brr(bltgt, _d);
1348 case_brf(bltgt, _d, 64);
1349 case_brr(bord, _d);
1350 case_brf(bord, _d, 64);
1351 case_brr(bunord, _d);
1352 case_brf(bunord, _d, 64);
1353 case jit_code_jmpr:
1354 jmpr(rn(node->u.w));
1355 break;
1356 case jit_code_jmpi:
1357 if (node->flag & jit_flag_node) {
1358 temp = node->u.n;
1359 assert(temp->code == jit_code_label ||
1360 temp->code == jit_code_epilog);
1361 if (temp->flag & jit_flag_patch)
1362 jmpi(temp->u.w);
1363 else {
1364 word = jmpi_p(_jit->pc.w);
1365 patch(word, node);
1366 }
1367 }
1368 else
1369 jmpi(node->u.w);
1370 break;
1371 case jit_code_callr:
1372 callr(rn(node->u.w));
1373 break;
1374 case jit_code_calli:
1375 if (node->flag & jit_flag_node) {
1376 temp = node->u.n;
1377 assert(temp->code == jit_code_label ||
1378 temp->code == jit_code_epilog);
1379 if (!(temp->flag & jit_flag_patch)) {
1380 word = calli_p(temp->u.w);
1381 patch(word, node);
1382 }
1383 else
1384 calli(temp->u.w);
1385 }
1386 else
1387 calli(node->u.w);
1388 break;
1389 case jit_code_prolog:
1390 _jitc->function = _jitc->functions.ptr + node->w.w;
1391 undo.node = node;
1392 undo.word = _jit->pc.w;
1393#if DEVEL_DISASSEMBLER
1394 undo.prevw = prevw;
1395#endif
1396 undo.patch_offset = _jitc->patches.offset;
1397 restart_function:
1398 _jitc->again = 0;
1399 prolog(node);
1400 break;
1401 case jit_code_epilog:
1402 assert(_jitc->function == _jitc->functions.ptr + node->w.w);
1403 if (_jitc->again) {
1404 for (temp = undo.node->next;
1405 temp != node; temp = temp->next) {
1406 if (temp->code == jit_code_label ||
1407 temp->code == jit_code_epilog)
1408 temp->flag &= ~jit_flag_patch;
1409 }
1410 temp->flag &= ~jit_flag_patch;
1411 node = undo.node;
1412 _jit->pc.w = undo.word;
1413#if DEVEL_DISASSEMBLER
1414 prevw = undo.prevw;
1415#endif
1416 _jitc->patches.offset = undo.patch_offset;
1417 goto restart_function;
1418 }
1419 /* remember label is defined */
1420 node->flag |= jit_flag_patch;
1421 node->u.w = _jit->pc.w;
1422 epilog(node);
1423 _jitc->function = NULL;
1424 break;
1425 case jit_code_va_start:
1426 vastart(rn(node->u.w));
1427 break;
1428 case jit_code_va_arg:
1429 vaarg(rn(node->u.w), rn(node->v.w));
1430 break;
1431 case jit_code_va_arg_d:
1432 vaarg_d(rn(node->u.w), rn(node->v.w));
1433 break;
1434 case jit_code_live: case jit_code_ellipsis:
1435 case jit_code_va_push:
1436 case jit_code_allocai: case jit_code_allocar:
1437 case jit_code_arg:
1438 case jit_code_arg_f: case jit_code_arg_d:
1439 case jit_code_va_end:
1440 case jit_code_ret:
1441 case jit_code_retr: case jit_code_reti:
1442 case jit_code_retr_f: case jit_code_reti_f:
1443 case jit_code_retr_d: case jit_code_reti_d:
1444 case jit_code_getarg_c: case jit_code_getarg_uc:
1445 case jit_code_getarg_s: case jit_code_getarg_us:
1446 case jit_code_getarg_i: case jit_code_getarg_ui:
1447 case jit_code_getarg_l:
1448 case jit_code_getarg_f: case jit_code_getarg_d:
1449 case jit_code_putargr: case jit_code_putargi:
1450 case jit_code_putargr_f: case jit_code_putargi_f:
1451 case jit_code_putargr_d: case jit_code_putargi_d:
1452 case jit_code_pushargr: case jit_code_pushargi:
1453 case jit_code_pushargr_f: case jit_code_pushargi_f:
1454 case jit_code_pushargr_d: case jit_code_pushargi_d:
1455 case jit_code_retval_c: case jit_code_retval_uc:
1456 case jit_code_retval_s: case jit_code_retval_us:
1457 case jit_code_retval_i:
1458 case jit_code_retval_ui: case jit_code_retval_l:
1459 case jit_code_retval_f: case jit_code_retval_d:
1460 case jit_code_prepare:
1461 case jit_code_finishr: case jit_code_finishi:
1462 break;
1463 default:
1464 abort();
1465 }
1466 if (jit_carry != _NOREG) {
1467 switch (node->code) {
1468 case jit_code_note:
1469 case jit_code_addcr: case jit_code_addci:
1470 case jit_code_addxr: case jit_code_addxi:
1471 case jit_code_subcr: case jit_code_subci:
1472 case jit_code_subxr: case jit_code_subxi:
1473 break;
1474 default:
1475 jit_unget_reg(jit_carry);
1476 jit_carry = _NOREG;
1477 break;
1478 }
1479 }
1480 jit_regarg_clr(node, value);
1481 assert(_jitc->regarg == 0 ||
1482 (jit_carry != _NOREG && _jitc->regarg == (1 << jit_carry)));
1483 assert(_jitc->synth == 0);
1484 /* update register live state */
1485 jit_reglive(node);
1486 }
1487#undef case_brf
1488#undef case_brw
1489#undef case_brr
1490#undef case_wrr
1491#undef case_rrrw
1492#undef case_rrrr
1493#undef case_rrf
1494#undef case_rrw
1495#undef case_rrr
1496#undef case_wr
1497#undef case_rw
1498#undef case_rr
1499 for (offset = 0; offset < _jitc->patches.offset; offset++) {
1500 node = _jitc->patches.ptr[offset].node;
1501 word = node->code == jit_code_movi ? node->v.n->u.w : node->u.n->u.w;
1502 patch_at(_jitc->patches.ptr[offset].inst, word);
1503 }
1504
1505 jit_flush(_jit->code.ptr, _jit->pc.uc);
1506
1507 return (_jit->code.ptr);
1508}
1509
1510#define CODE 1
1511# include "jit_alpha-cpu.c"
1512# include "jit_alpha-fpu.c"
1513#undef CODE
1514
1515void
1516jit_flush(void *fptr, void *tptr)
1517{
1518}
1519
1520void
1521_emit_ldxi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
1522{
1523 ldxi(rn(r0), rn(r1), i0);
1524}
1525
1526void
1527_emit_stxi(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
1528{
1529 stxi(i0, rn(r0), rn(r1));
1530}
1531
1532void
1533_emit_ldxi_d(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0)
1534{
1535 ldxi_d(rn(r0), rn(r1), i0);
1536}
1537
1538void
1539_emit_stxi_d(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
1540{
1541 stxi_d(i0, rn(r0), rn(r1));
1542}
1543
1544static void
1545_patch(jit_state_t *_jit, jit_word_t instr, jit_node_t *node)
1546{
1547 jit_int32_t flag;
1548
1549 assert(node->flag & jit_flag_node);
1550 if (node->code == jit_code_movi)
1551 flag = node->v.n->flag;
1552 else
1553 flag = node->u.n->flag;
1554 assert(!(flag & jit_flag_patch));
1555 if (_jitc->patches.offset >= _jitc->patches.length) {
1556 jit_realloc((jit_pointer_t *)&_jitc->patches.ptr,
1557 _jitc->patches.length * sizeof(jit_patch_t),
1558 (_jitc->patches.length + 1024) * sizeof(jit_patch_t));
1559 _jitc->patches.length += 1024;
1560 }
1561 _jitc->patches.ptr[_jitc->patches.offset].inst = instr;
1562 _jitc->patches.ptr[_jitc->patches.offset].node = node;
1563 ++_jitc->patches.offset;
1564}