1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: codegen.c 7900 2007-05-11 20:35:16Z twisti $
39 #include "vm/jit/arm/arch.h"
40 #include "vm/jit/arm/codegen.h"
42 #include "mm/memory.h"
44 #include "native/native.h"
46 #include "threads/lock-common.h"
48 #include "vm/builtin.h"
49 #include "vm/exceptions.h"
50 #include "vm/global.h"
53 #include "vm/jit/asmpart.h"
54 #include "vm/jit/codegen-common.h"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/emit-common.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/md.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher.h"
62 #include "vm/jit/reg.h"
64 #if defined(ENABLE_LSRA)
65 #include "vm/jit/allocator/lsra.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/options.h"
72 /* codegen_emit ****************************************************************
74 Generates machine code.
76 *******************************************************************************/
78 bool codegen_emit(jitdata *jd)
99 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
100 unresolved_method *um;
101 builtintable_entry *bte;
104 /* get required compiler data */
111 /* prevent compiler warnings */
119 /* space to save used callee saved registers */
121 savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
122 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
123 savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
125 spilledregs_num = rd->memuse;
127 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
128 if (checksync && (m->flags & ACC_SYNCHRONIZED))
132 cd->stackframesize = spilledregs_num + savedregs_num;
134 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
135 only in native stubs. */
136 /* align stack to 8-byte */
138 cd->stackframesize = (cd->stackframesize + 1) & ~1;
140 /* SECTION: Method Header */
141 /* create method header */
143 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
144 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
146 #if defined(ENABLE_THREADS)
147 /* IsSync contains the offset relative to the stack pointer for the
148 argument of monitor_exit used in the exception handler. Since the
149 offset could be zero and give a wrong meaning of the flag it is
153 if (checksync && (m->flags & ACC_SYNCHRONIZED))
154 (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 4);/* IsSync */
157 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
159 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
160 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
161 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
162 (void) dseg_addlinenumbertablesize(cd);
163 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
165 /* create exception table */
167 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
168 dseg_add_target(cd, ex->start);
169 dseg_add_target(cd, ex->end);
170 dseg_add_target(cd, ex->handler);
171 (void) dseg_add_unique_address(cd, ex->catchtype.any);
174 /* save return address and used callee saved registers */
176 savedregs_bitmask = 0;
178 if (!jd->isleafmethod)
179 savedregs_bitmask = (1<<REG_LR);
181 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
182 savedregs_bitmask |= (1<<(rd->savintregs[i]));
185 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
186 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
187 /* TODO: floating-point */
191 if (savedregs_bitmask)
192 M_STMFD(savedregs_bitmask, REG_SP);
194 /* create additional stack frame for spilled variables (if necessary) */
196 if ((cd->stackframesize - savedregs_num) > 0)
197 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
199 /* take arguments out of register or stack frame */
202 for (i = 0, len = 0; i < md->paramcount; i++) {
203 s1 = md->params[i].regoff;
204 t = md->paramtypes[i].type;
206 varindex = jd->local_map[len * 5 + t];
208 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
210 if (varindex == UNUSED)
215 /* ATTENTION: we use interger registers for all arguments (even float) */
216 #if !defined(ENABLE_SOFTFLOAT)
217 if (IS_INT_LNG_TYPE(t)) { /* integer args */
219 if (!md->params[i].inmemory) { /* register arguments */
220 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
221 if (GET_LOW_REG(var->vv.regoff) == REG_SPLIT || GET_HIGH_REG(var->vv.regoff) == REG_SPLIT) {
222 /* TODO: remove this!!! */
223 dolog("SPLIT in local var: %x>%x (%s.%s)", s1, var->vv.regoff, m->class->name->text, m->name->text);
224 assert(s1 == var->vv.regoff);
227 SPLIT_OPEN(t, s1, REG_ITMP1);
228 SPLIT_LOAD(t, s1, cd->stackframesize);
229 SPLIT_OPEN(t, s3, REG_ITMP1);
231 if (IS_2_WORD_TYPE(t))
236 SPLIT_STORE_AND_CLOSE(t, s3, cd->stackframesize);
238 else { /* reg arg -> spilled */
239 SPLIT_OPEN(t, s1, REG_ITMP1);
240 SPLIT_LOAD(t, s1, cd->stackframesize);
242 if (IS_2_WORD_TYPE(t))
243 M_LST(s1, REG_SP, var->vv.regoff * 4);
245 M_IST(s1, REG_SP, var->vv.regoff * 4);
246 /* no SPLIT_CLOSE here because arg is fully spilled now */
249 else { /* stack arguments */
250 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
251 if (IS_2_WORD_TYPE(t))
252 M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
254 M_ILD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
256 else { /* stack arg -> spilled */
257 /* Reuse Memory Position on Caller Stack */
258 var->vv.regoff = cd->stackframesize + s1;
261 #if !defined(ENABLE_SOFTFLOAT)
262 } else { /* floating args */
263 if (!md->params[i].inmemory) { /* register arguments */
264 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
265 SPLIT_OPEN(t, s1, REG_ITMP1);
266 SPLIT_LOAD(t, s1, cd->stackframesize);
267 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
269 else { /* reg arg -> spilled */
270 SPLIT_OPEN(t, s1, REG_ITMP1);
271 SPLIT_LOAD(t, s1, cd->stackframesize);
273 if (IS_2_WORD_TYPE(t))
274 M_LST(s1, REG_SP, var->vv.regoff * 4);
276 M_IST(s1, REG_SP, var->vv.regoff * 4);
277 /* no SPLIT_CLOSE here because arg is fully spilled now */
280 else { /* stack arguments */
281 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
282 if (IS_2_WORD_TYPE(t))
283 M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
285 M_FLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
287 else { /* stack arg -> spilled */
288 /* Reuse Memory Position on Caller Stack */
289 var->vv.regoff = cd->stackframesize + s1;
293 #endif /* !defined(ENABLE_SOFTFLOAT) */
296 #if defined(ENABLE_THREADS)
297 /* call monitorenter function */
299 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
300 /* stack offset for monitor argument */
304 # if !defined(NDEBUG)
305 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
306 M_STMFD(BITMASK_ARGS, REG_SP);
311 /* get the correct lock object */
313 if (m->flags & ACC_STATIC) {
314 disp = dseg_add_address(cd, &m->class->object.header);
315 M_DSEG_LOAD(REG_A0, disp);
318 emit_nullpointer_check_force(cd, iptr, REG_A0);
321 M_STR(REG_A0, REG_SP, s1 * 4);
322 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
324 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
327 # if !defined(NDEBUG)
328 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
329 M_LDMFD(BITMASK_ARGS, REG_SP);
335 /* call trace function */
337 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
338 emit_verbosecall_enter(jd);
341 /* end of header generation */
343 /* SECTION: ICMD Code Generation */
344 /* for all basic blocks */
346 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
348 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
350 /* is this basic block reached? */
352 if (bptr->flags < BBREACHED)
355 /* branch resolving */
357 codegen_resolve_branchrefs(cd, bptr);
359 /* copy interface registers to their destination */
365 #if defined(ENABLE_LSRA)
369 var = VAR(bptr->invars[len]);
370 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
371 if (!(var->flags & INMEMORY))
375 M_INTMOVE(REG_ITMP1, d);
376 emit_store(jd, NULL, var, d);
383 var = VAR(bptr->invars[len]);
385 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
386 d = codegen_reg_of_var(0, var, REG_ITMP1);
387 M_INTMOVE(REG_ITMP1, d);
388 emit_store(jd, NULL, var, d);
391 assert((var->flags & INOUT));
394 #if defined(ENABLE_LSRA)
398 /* for all instructions */
401 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
403 /* add line number */
404 if (iptr->line != currentline) {
405 dseg_addlinenumber(cd, iptr->line);
406 currentline = iptr->line;
409 MCODECHECK(64); /* an instruction usually needs < 64 words */
413 case ICMD_NOP: /* ... ==> ... */
416 /* constant operations ************************************************/
418 case ICMD_ICONST: /* ... ==> ..., constant */
420 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
421 ICONST(d, iptr->sx.val.i);
422 emit_store_dst(jd, iptr, d);
425 case ICMD_ACONST: /* ... ==> ..., constant */
427 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
428 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
429 disp = dseg_add_unique_address(cd, NULL);
431 codegen_addpatchref(cd, PATCHER_aconst,
435 if (opt_showdisassemble)
438 M_DSEG_LOAD(d, disp);
441 ICONST(d, (u4) iptr->sx.val.anyptr);
443 emit_store_dst(jd, iptr, d);
446 case ICMD_LCONST: /* ... ==> ..., constant */
448 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
449 LCONST(d, iptr->sx.val.l);
450 emit_store_dst(jd, iptr, d);
453 case ICMD_FCONST: /* ... ==> ..., constant */
455 #if defined(ENABLE_SOFTFLOAT)
456 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
457 ICONST(d, iptr->sx.val.i);
458 emit_store_dst(jd, iptr, d);
460 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
461 FCONST(d, iptr->sx.val.f);
462 emit_store_dst(jd, iptr, d);
466 case ICMD_DCONST: /* ... ==> ..., constant */
468 #if defined(ENABLE_SOFTFLOAT)
469 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
470 LCONST(d, iptr->sx.val.l);
471 emit_store_dst(jd, iptr, d);
473 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
474 DCONST(d, iptr->sx.val.d);
475 emit_store_dst(jd, iptr, d);
480 /* load/store/copy/move operations ************************************/
482 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
483 case ICMD_ALOAD: /* op1 = local variable */
487 case ICMD_ISTORE: /* ..., value ==> ... */
498 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
502 /* pop operations *****************************************************/
504 /* attention: double and longs are only one entry in CACAO ICMDs */
506 case ICMD_POP: /* ..., value ==> ... */
507 case ICMD_POP2: /* ..., value, value ==> ... */
512 /* integer operations *************************************************/
514 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
516 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
517 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
518 M_MOV(d, REG_LSL(s1, 24));
519 M_MOV(d, REG_ASR(d, 24));
520 emit_store_dst(jd, iptr, d);
523 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
525 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
526 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
527 M_MOV(d, REG_LSL(s1, 16));
528 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
529 emit_store_dst(jd, iptr, d);
532 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
534 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
535 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
536 M_MOV(d, REG_LSL(s1, 16));
537 M_MOV(d, REG_ASR(d, 16));
538 emit_store_dst(jd, iptr, d);
541 case ICMD_I2L: /* ..., value ==> ..., value */
543 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
544 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
545 M_INTMOVE(s1, GET_LOW_REG(d));
546 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
547 emit_store_dst(jd, iptr, d);
550 case ICMD_L2I: /* ..., value ==> ..., value */
552 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
553 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
555 emit_store_dst(jd, iptr, d);
558 case ICMD_INEG: /* ..., value ==> ..., - value */
560 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
561 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
563 emit_store_dst(jd, iptr, d);
566 case ICMD_LNEG: /* ..., value ==> ..., - value */
568 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
569 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
570 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
571 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
572 emit_store_dst(jd, iptr, d);
575 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
577 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
578 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
579 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
581 emit_store_dst(jd, iptr, d);
584 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
586 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
587 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
588 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
589 M_ADD_S(GET_LOW_REG(d), s1, s2);
590 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
591 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
592 M_ADC(GET_HIGH_REG(d), s1, s2);
593 emit_store_dst(jd, iptr, d);
599 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
600 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
602 if (IS_IMM(iptr->sx.val.i)) {
603 M_ADD_IMM(d, s1, iptr->sx.val.i);
604 } else if (IS_IMM(-iptr->sx.val.i)) {
605 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
607 ICONST(REG_ITMP3, iptr->sx.val.i);
608 M_ADD(d, s1, REG_ITMP3);
611 emit_store_dst(jd, iptr, d);
614 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
615 /* sx.val.l = constant */
617 s3 = iptr->sx.val.l & 0xffffffff;
618 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
619 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
621 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
623 ICONST(REG_ITMP3, s3);
624 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
626 s3 = iptr->sx.val.l >> 32;
627 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
629 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
631 ICONST(REG_ITMP3, s3);
632 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
634 emit_store_dst(jd, iptr, d);
637 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
639 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
640 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
641 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
643 emit_store_dst(jd, iptr, d);
646 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
648 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
649 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
650 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
651 M_SUB_S(GET_LOW_REG(d), s1, s2);
652 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
653 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
654 M_SBC(GET_HIGH_REG(d), s1, s2);
655 emit_store_dst(jd, iptr, d);
658 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
659 /* sx.val.i = constant */
661 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
662 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
663 if (IS_IMM(iptr->sx.val.i))
664 M_SUB_IMM(d, s1, iptr->sx.val.i);
666 ICONST(REG_ITMP3, iptr->sx.val.i);
667 M_SUB(d, s1, REG_ITMP3);
669 emit_store_dst(jd, iptr, d);
672 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
673 /* sx.val.l = constant */
675 s3 = iptr->sx.val.l & 0xffffffff;
676 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
677 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
679 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
681 ICONST(REG_ITMP3, s3);
682 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
684 s3 = iptr->sx.val.l >> 32;
685 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
687 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
689 ICONST(REG_ITMP3, s3);
690 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
692 emit_store_dst(jd, iptr, d);
695 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
697 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
698 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
699 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
701 emit_store_dst(jd, iptr, d);
704 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
705 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
707 s1 = emit_load_s1(jd, iptr, REG_A0);
708 s2 = emit_load_s2(jd, iptr, REG_A1);
709 emit_arithmetic_check(cd, iptr, s2);
711 /* move arguments into argument registers */
712 M_INTMOVE(s1, REG_A0);
713 M_INTMOVE(s2, REG_A1);
715 /* call builtin function */
716 bte = iptr->sx.s23.s3.bte;
717 disp = dseg_add_functionptr(cd, bte->fp);
721 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
724 /* move result into destination register */
725 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
726 M_INTMOVE(REG_RESULT, d);
727 emit_store_dst(jd, iptr, d);
730 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
731 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
733 /* move arguments into argument registers */
735 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
736 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
737 /* XXX TODO: only do this if arithmetic check is really done! */
738 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
739 emit_arithmetic_check(cd, iptr, REG_ITMP3);
741 M_LNGMOVE(s1, REG_A0_A1_PACKED);
742 M_LNGMOVE(s2, REG_A2_A3_PACKED);
744 /* call builtin function */
745 bte = iptr->sx.s23.s3.bte;
746 disp = dseg_add_functionptr(cd, bte->fp);
750 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
753 /* move result into destination register */
754 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
755 M_LNGMOVE(REG_RESULT_PACKED, d);
756 emit_store_dst(jd, iptr, d);
759 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
760 /* sx.val.i = constant */
762 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
763 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
764 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
765 emit_store_dst(jd, iptr, d);
768 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
769 /* sx.val.i = constant */
771 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
772 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
773 /* this rounds towards 0 as java likes it */
774 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
775 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
776 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
777 /* this rounds towards nearest, not java style */
778 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
779 M_ADCMI_IMM(d, d, 0);*/
780 emit_store_dst(jd, iptr, d);
783 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
784 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
786 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
787 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
788 M_MOV_S(REG_ITMP1, s1);
789 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
790 if (IS_IMM(iptr->sx.val.i))
791 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
793 ICONST(REG_ITMP3, iptr->sx.val.i);
794 M_AND(REG_ITMP1, REG_ITMP3, d);
796 M_RSBMI_IMM(d, d, 0);
797 emit_store_dst(jd, iptr, d);
800 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
802 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
803 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
804 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
805 M_AND_IMM(s2, 0x1f, REG_ITMP2);
806 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
807 emit_store_dst(jd, iptr, d);
810 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
812 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
813 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
814 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
815 M_AND_IMM(s2, 0x1f, REG_ITMP2);
816 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
817 emit_store_dst(jd, iptr, d);
820 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
822 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
823 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
824 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
825 M_AND_IMM(s2, 0x1f, REG_ITMP2);
826 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
827 emit_store_dst(jd, iptr, d);
830 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
831 /* sx.val.i = constant */
833 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
834 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
835 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
836 emit_store_dst(jd, iptr, d);
839 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
840 /* sx.val.i = constant */
842 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
843 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
844 /* we need to check for zero here because arm interprets it as SHR by 32 */
845 if ((iptr->sx.val.i & 0x1f) == 0) {
848 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
850 emit_store_dst(jd, iptr, d);
853 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
854 /* sx.val.i = constant */
856 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
857 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
858 /* we need to check for zero here because arm interprets it as SHR by 32 */
859 if ((iptr->sx.val.i & 0x1f) == 0)
862 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
863 emit_store_dst(jd, iptr, d);
866 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
868 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
869 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
870 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
872 emit_store_dst(jd, iptr, d);
875 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
877 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
878 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
879 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
880 M_AND(s1, s2, GET_LOW_REG(d));
881 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
882 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
883 M_AND(s1, s2, GET_HIGH_REG(d));
884 emit_store_dst(jd, iptr, d);
887 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
889 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
890 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
891 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
893 emit_store_dst(jd, iptr, d);
896 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
898 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
899 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
900 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
901 M_ORR(s1, s2, GET_LOW_REG(d));
902 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
903 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
904 M_ORR(s1, s2, GET_HIGH_REG(d));
905 emit_store_dst(jd, iptr, d);
908 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
910 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
911 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
912 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
914 emit_store_dst(jd, iptr, d);
917 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
919 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
920 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
921 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
922 M_EOR(s1, s2, GET_LOW_REG(d));
923 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
924 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
925 M_EOR(s1, s2, GET_HIGH_REG(d));
926 emit_store_dst(jd, iptr, d);
930 /* floating operations ************************************************/
932 #if !defined(ENABLE_SOFTFLOAT)
934 case ICMD_FNEG: /* ..., value ==> ..., - value */
936 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
937 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
939 emit_store_dst(jd, iptr, d);
942 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
944 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
945 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
946 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
948 emit_store_dst(jd, iptr, d);
951 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
953 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
954 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
955 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
957 emit_store_dst(jd, iptr, d);
960 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
962 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
963 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
964 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
966 emit_store_dst(jd, iptr, d);
969 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
970 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
971 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
972 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
974 emit_store_dst(jd, iptr, d);
977 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
980 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
982 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
983 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
984 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
986 emit_store_dst(jd, iptr, d);
989 case ICMD_DNEG: /* ..., value ==> ..., - value */
991 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
992 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
994 emit_store_dst(jd, iptr, d);
997 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
999 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1000 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1001 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1003 emit_store_dst(jd, iptr, d);
1006 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1008 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1009 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1010 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1012 emit_store_dst(jd, iptr, d);
1015 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1017 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1018 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1019 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1021 emit_store_dst(jd, iptr, d);
1024 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1026 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1027 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1028 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1030 emit_store_dst(jd, iptr, d);
1033 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1036 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1038 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1039 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1040 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1042 emit_store_dst(jd, iptr, d);
1045 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1047 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1048 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1050 emit_store_dst(jd, iptr, d);
1053 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1055 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1056 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1058 emit_store_dst(jd, iptr, d);
1061 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1063 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1064 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1065 /* this uses round towards zero, as Java likes it */
1067 /* this checks for NaN; to return zero as Java likes it */
1070 emit_store_dst(jd, iptr, d);
1073 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1075 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1076 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1077 /* this uses round towards zero, as Java likes it */
1079 /* this checks for NaN; to return zero as Java likes it */
1082 emit_store_dst(jd, iptr, d);
1085 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1087 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1088 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1090 emit_store_dst(jd, iptr, d);
1093 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1095 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1096 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1098 emit_store_dst(jd, iptr, d);
1101 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1103 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1104 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1105 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1108 M_SUBGT_IMM(d, d, 1);
1109 M_ADDLT_IMM(d, d, 1);
1110 emit_store_dst(jd, iptr, d);
1113 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1115 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1116 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1117 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1120 M_SUBGT_IMM(d, d, 1);
1121 M_ADDLT_IMM(d, d, 1);
1122 emit_store_dst(jd, iptr, d);
1125 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1127 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1128 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1129 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1132 M_SUBLT_IMM(d, d, 1);
1133 M_ADDGT_IMM(d, d, 1);
1134 emit_store_dst(jd, iptr, d);
1137 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1139 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1140 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1141 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1144 M_SUBLT_IMM(d, d, 1);
1145 M_ADDGT_IMM(d, d, 1);
1146 emit_store_dst(jd, iptr, d);
1149 #endif /* !defined(ENABLE_SOFTFLOAT) */
1152 /* memory operations **************************************************/
1154 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1156 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1157 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1158 /* implicit null-pointer check */
1159 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1160 emit_store_dst(jd, iptr, d);
1163 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1165 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1166 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1167 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1168 /* implicit null-pointer check */
1169 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1170 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1171 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1172 emit_store_dst(jd, iptr, d);
1175 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1177 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1178 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1179 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1180 /* implicit null-pointer check */
1181 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1182 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1183 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1184 emit_store_dst(jd, iptr, d);
1187 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1189 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1190 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1191 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1192 /* implicit null-pointer check */
1193 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1194 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1195 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1196 emit_store_dst(jd, iptr, d);
1199 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1201 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1202 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1203 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1204 /* implicit null-pointer check */
1205 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1206 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1207 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1208 emit_store_dst(jd, iptr, d);
1211 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1213 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1214 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1215 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1216 /* implicit null-pointer check */
1217 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1218 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1219 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1220 emit_store_dst(jd, iptr, d);
1223 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1225 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1226 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1227 /* implicit null-pointer check */
1228 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1229 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1230 #if !defined(ENABLE_SOFTFLOAT)
1231 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1232 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1234 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1235 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1237 emit_store_dst(jd, iptr, d);
1240 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1242 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1243 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1244 /* implicit null-pointer check */
1245 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1246 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1247 #if !defined(ENABLE_SOFTFLOAT)
1248 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1249 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1251 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1252 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1254 emit_store_dst(jd, iptr, d);
1257 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1259 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1260 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1261 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1262 /* implicit null-pointer check */
1263 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1264 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1265 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1266 emit_store_dst(jd, iptr, d);
1269 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1271 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1272 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1273 /* implicit null-pointer check */
1274 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1275 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1276 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1277 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1280 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1282 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1283 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1284 /* implicit null-pointer check */
1285 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1286 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1287 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1288 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1291 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1293 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1294 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1295 /* implicit null-pointer check */
1296 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1297 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1298 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1299 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1302 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1304 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1305 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1306 /* implicit null-pointer check */
1307 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1308 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1309 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1310 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1313 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1315 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1316 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1317 /* implicit null-pointer check */
1318 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1319 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1320 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1321 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1324 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1326 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1327 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1328 /* implicit null-pointer check */
1329 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1330 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1331 #if !defined(ENABLE_SOFTFLOAT)
1332 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1333 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1335 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1336 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1340 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1342 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1343 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1344 /* implicit null-pointer check */
1345 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1346 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1347 #if !defined(ENABLE_SOFTFLOAT)
1348 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1349 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1351 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1352 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1356 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1358 s1 = emit_load_s1(jd, iptr, REG_A0);
1359 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1360 s3 = emit_load_s3(jd, iptr, REG_A1);
1362 /* implicit null-pointer check */
1363 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1365 /* move arguments to argument registers */
1366 M_INTMOVE(s1, REG_A0);
1367 M_INTMOVE(s3, REG_A1);
1369 /* call builtin function */
1370 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1371 M_DSEG_BRANCH(disp);
1374 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1377 /* check resturn value of builtin */
1378 emit_exception_check(cd, iptr);
1380 /* finally store address into array */
1381 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1382 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1383 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1384 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1385 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1388 case ICMD_GETSTATIC: /* ... ==> ..., value */
1390 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1391 unresolved_field *uf = iptr->sx.s23.s3.uf;
1393 fieldtype = uf->fieldref->parseddesc.fd->type;
1395 disp = dseg_add_unique_address(cd, NULL);
1397 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1399 if (opt_showdisassemble)
1403 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1405 fieldtype = fi->type;
1407 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1408 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1410 if (opt_showdisassemble)
1414 disp = dseg_add_address(cd, &(fi->value));
1417 M_DSEG_LOAD(REG_ITMP3, disp);
1418 switch (fieldtype) {
1420 #if defined(ENABLE_SOFTFLOAT)
1424 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1425 M_ILD_INTERN(d, REG_ITMP3, 0);
1428 #if defined(ENABLE_SOFTFLOAT)
1431 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1432 M_LLD_INTERN(d, REG_ITMP3, 0);
1434 #if !defined(ENABLE_SOFTFLOAT)
1436 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1437 M_FLD_INTERN(d, REG_ITMP3, 0);
1440 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1441 M_DLD_INTERN(d, REG_ITMP3, 0);
1447 emit_store_dst(jd, iptr, d);
1450 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1452 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1453 unresolved_field *uf = iptr->sx.s23.s3.uf;
1455 fieldtype = uf->fieldref->parseddesc.fd->type;
1457 disp = dseg_add_unique_address(cd, NULL);
1459 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1461 if (opt_showdisassemble)
1465 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1467 fieldtype = fi->type;
1469 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1470 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1472 if (opt_showdisassemble)
1476 disp = dseg_add_address(cd, &(fi->value));
1479 M_DSEG_LOAD(REG_ITMP3, disp);
1480 switch (fieldtype) {
1482 #if defined(ENABLE_SOFTFLOAT)
1486 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1487 M_IST_INTERN(s1, REG_ITMP3, 0);
1490 #if defined(ENABLE_SOFTFLOAT)
1493 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1494 M_LST_INTERN(s1, REG_ITMP3, 0);
1496 #if !defined(ENABLE_SOFTFLOAT)
1498 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1499 M_FST_INTERN(s1, REG_ITMP3, 0);
1502 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1503 M_DST_INTERN(s1, REG_ITMP3, 0);
1511 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1513 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1514 emit_nullpointer_check(cd, iptr, s1);
1517 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1518 unresolved_field *uf = iptr->sx.s23.s3.uf;
1520 fieldtype = uf->fieldref->parseddesc.fd->type;
1523 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1525 fieldtype = fi->type;
1529 #if !defined(ENABLE_SOFTFLOAT)
1530 /* HACK: softnull checks on floats */
1531 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1532 emit_nullpointer_check_force(cd, iptr, s1);
1535 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1536 unresolved_field *uf = iptr->sx.s23.s3.uf;
1538 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1540 if (opt_showdisassemble)
1546 switch (fieldtype) {
1548 #if defined(ENABLE_SOFTFLOAT)
1552 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1556 #if defined(ENABLE_SOFTFLOAT)
1559 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1562 #if !defined(ENABLE_SOFTFLOAT)
1564 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1568 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1575 emit_store_dst(jd, iptr, d);
1578 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1580 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1581 emit_nullpointer_check(cd, iptr, s1);
1583 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1584 unresolved_field *uf = iptr->sx.s23.s3.uf;
1586 fieldtype = uf->fieldref->parseddesc.fd->type;
1589 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1591 fieldtype = fi->type;
1595 #if !defined(ENABLE_SOFTFLOAT)
1596 /* HACK: softnull checks on floats */
1597 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1598 emit_nullpointer_check_force(cd, iptr, s1);
1601 switch (fieldtype) {
1603 #if defined(ENABLE_SOFTFLOAT)
1607 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1609 #if defined(ENABLE_SOFTFLOAT)
1610 case TYPE_DBL: /* fall through */
1613 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1615 #if !defined(ENABLE_SOFTFLOAT)
1618 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1625 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1626 unresolved_field *uf = iptr->sx.s23.s3.uf;
1628 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1630 if (opt_showdisassemble)
1636 switch (fieldtype) {
1638 #if defined(ENABLE_SOFTFLOAT)
1642 M_IST(s2, s1, disp);
1645 #if defined(ENABLE_SOFTFLOAT)
1648 M_LST(s2, s1, disp);
1650 #if !defined(ENABLE_SOFTFLOAT)
1652 M_FST(s2, s1, disp);
1655 M_DST(s2, s1, disp);
1664 /* branch operations **************************************************/
1666 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1668 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1669 M_INTMOVE(s1, REG_ITMP1_XPTR);
1670 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1671 codegen_addpatchref(cd, PATCHER_athrow_areturn,
1672 iptr->sx.s23.s2.uc, 0);
1674 if (opt_showdisassemble)
1677 disp = dseg_add_functionptr(cd, asm_handle_exception);
1678 M_DSEG_LOAD(REG_ITMP3, disp);
1679 M_MOV(REG_ITMP2_XPC, REG_PC);
1680 M_MOV(REG_PC, REG_ITMP3);
1681 M_NOP; /* nop ensures that XPC is less than the end */
1682 /* of basic block */
1685 case ICMD_GOTO: /* ... ==> ... */
1688 emit_br(cd, iptr->dst.block);
1691 case ICMD_JSR: /* ... ==> ... */
1693 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1696 case ICMD_IFNULL: /* ..., value ==> ... */
1697 case ICMD_IFNONNULL:
1699 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1701 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1704 case ICMD_IFLT: /* ..., value ==> ... */
1705 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1711 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1712 M_COMPARE(s1, iptr->sx.val.i);
1713 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1716 case ICMD_IF_LEQ: /* ..., value ==> ... */
1718 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1719 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1720 if (iptr->sx.val.l == 0) {
1721 M_ORR_S(s1, s2, REG_ITMP3);
1724 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1725 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1726 M_CMP(s1, REG_ITMP3);*/
1727 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1728 M_CMPEQ(s2, REG_ITMP3);
1730 emit_beq(cd, iptr->dst.block);
1733 case ICMD_IF_LLT: /* ..., value ==> ... */
1735 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1736 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1737 if (iptr->sx.val.l == 0) {
1738 /* if high word is less than zero, the whole long is too */
1740 emit_blt(cd, iptr->dst.block);
1743 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1744 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1745 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1746 M_CMP(s1, REG_ITMP3);*/
1747 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1748 M_MOVGT_IMM(2, REG_ITMP1);
1749 M_MOVEQ_IMM(1, REG_ITMP1);
1751 /* low compare: x=x-1(ifLO) */
1752 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1753 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1754 M_CMP(s2, REG_ITMP3);*/
1755 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1757 /* branch if (x LT 1) */
1758 M_CMP_IMM(REG_ITMP1, 1);
1759 emit_blt(cd, iptr->dst.block);
1763 case ICMD_IF_LLE: /* ..., value ==> ... */
1765 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1766 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1767 if (iptr->sx.val.l == 0) {
1768 /* if high word is less than zero, the whole long is too */
1770 emit_blt(cd, iptr->dst.block);
1772 /* ... otherwise the low word has to be zero (tricky!) */
1774 emit_beq(cd, iptr->dst.block);
1777 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1778 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1779 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1780 M_CMP(s1, REG_ITMP3);*/
1781 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1782 M_MOVGT_IMM(2, REG_ITMP1);
1783 M_MOVEQ_IMM(1, REG_ITMP1);
1785 /* low compare: x=x+1(ifHI) */
1786 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1787 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1788 M_CMP(s2, REG_ITMP3);*/
1789 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1791 /* branch if (x LE 1) */
1792 M_CMP_IMM(REG_ITMP1, 1);
1793 emit_ble(cd, iptr->dst.block);
1797 case ICMD_IF_LGE: /* ..., value ==> ... */
1799 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1800 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1801 if (iptr->sx.val.l == 0) {
1802 /* if high word is greater or equal zero, the whole long is too */
1804 emit_bge(cd, iptr->dst.block);
1807 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1808 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1809 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1810 M_CMP(s1, REG_ITMP3);*/
1811 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1812 M_MOVGT_IMM(2, REG_ITMP1);
1813 M_MOVEQ_IMM(1, REG_ITMP1);
1815 /* low compare: x=x-1(ifLO) */
1816 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1817 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1818 M_CMP(s2, REG_ITMP3);*/
1819 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1821 /* branch if (x GE 1) */
1822 M_CMP_IMM(REG_ITMP1, 1);
1823 emit_bge(cd, iptr->dst.block);
1827 case ICMD_IF_LGT: /* ..., value ==> ... */
1829 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1830 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1832 if (iptr->sx.val.l == 0) {
1833 /* if high word is greater than zero, the whole long is too */
1836 codegen_add_branch_ref(cd, iptr->dst.block);
1838 /* ... or high was zero and low is non zero (tricky!) */
1839 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1840 M_MOVLT_IMM(1, REG_ITMP3);
1841 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1843 codegen_add_branch_ref(cd, iptr->dst.block);
1847 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1848 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1849 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1850 M_CMP(s1, REG_ITMP3);*/
1851 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1852 M_MOVGT_IMM(2, REG_ITMP1);
1853 M_MOVEQ_IMM(1, REG_ITMP1);
1855 /* low compare: x=x+1(ifHI) */
1856 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1857 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1858 M_CMP(s2, REG_ITMP3);*/
1859 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1861 /* branch if (x GT 1) */
1862 M_CMP_IMM(REG_ITMP1, 1);
1863 emit_bgt(cd, iptr->dst.block);
1869 case ICMD_IF_LNE: /* ..., value ==> ... */
1871 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1872 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1873 if (iptr->sx.val.l == 0) {
1874 M_ORR_S(s1, s2, REG_ITMP3);
1877 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1878 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1879 M_CMP(s1, REG_ITMP3);*/
1880 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1881 M_CMPEQ(s2, REG_ITMP3);
1883 emit_bne(cd, iptr->dst.block);
1886 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1887 case ICMD_IF_ICMPNE:
1888 case ICMD_IF_ICMPLT:
1889 case ICMD_IF_ICMPLE:
1890 case ICMD_IF_ICMPGT:
1891 case ICMD_IF_ICMPGE:
1893 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1894 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1896 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1899 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1900 case ICMD_IF_ACMPNE:
1902 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1903 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1905 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1908 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1909 /* op1 = target JavaVM pc */
1911 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1912 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1915 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1916 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1919 emit_beq(cd, iptr->dst.block);
1922 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1923 /* op1 = target JavaVM pc */
1925 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1926 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1929 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1930 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1933 emit_bne(cd, iptr->dst.block);
1936 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1937 /* op1 = target JavaVM pc */
1939 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1940 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1941 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1943 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1944 M_MOVGT_IMM(2, REG_ITMP3);
1945 M_MOVEQ_IMM(1, REG_ITMP3);
1947 /* low compare: x=x-1(ifLO) */
1948 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1949 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1951 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1953 /* branch if (x LT 1) */
1954 M_CMP_IMM(REG_ITMP3, 1);
1955 emit_blt(cd, iptr->dst.block);
1958 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1959 /* op1 = target JavaVM pc */
1961 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1962 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1963 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1965 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1966 M_MOVGT_IMM(2, REG_ITMP3);
1967 M_MOVEQ_IMM(1, REG_ITMP3);
1969 /* low compare: x=x-1(ifLO) */
1970 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1971 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1973 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1975 /* branch if (x LE 1) */
1976 M_CMP_IMM(REG_ITMP3, 1);
1977 emit_ble(cd, iptr->dst.block);
1980 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1981 /* op1 = target JavaVM pc */
1983 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1984 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1985 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1987 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1988 M_MOVGT_IMM(2, REG_ITMP3);
1989 M_MOVEQ_IMM(1, REG_ITMP3);
1991 /* low compare: x=x-1(ifLO) */
1992 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1993 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1995 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1997 /* branch if (x GT 1) */
1998 M_CMP_IMM(REG_ITMP3, 1);
1999 emit_bgt(cd, iptr->dst.block);
2002 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
2003 /* op1 = target JavaVM pc */
2005 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
2006 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
2007 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
2009 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
2010 M_MOVGT_IMM(2, REG_ITMP3);
2011 M_MOVEQ_IMM(1, REG_ITMP3);
2013 /* low compare: x=x-1(ifLO) */
2014 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
2015 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
2017 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2019 /* branch if (x GE 1) */
2020 M_CMP_IMM(REG_ITMP3, 1);
2021 emit_bge(cd, iptr->dst.block);
2024 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2027 branch_target_t *table;
2029 table = iptr->dst.table;
2031 l = iptr->sx.s23.s2.tablelow;
2032 i = iptr->sx.s23.s3.tablehigh;
2034 /* calculate new index (index - low) */
2035 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2037 M_INTMOVE(s1, REG_ITMP1);
2038 } else if (IS_IMM(l)) {
2039 M_SUB_IMM(REG_ITMP1, s1, l);
2041 ICONST(REG_ITMP2, l);
2042 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2045 /* range check (index <= high-low) */
2047 M_COMPARE(REG_ITMP1, i-1);
2048 emit_bugt(cd, table[0].block);
2050 /* build jump table top down and use address of lowest entry */
2055 dseg_add_target(cd, table->block);
2060 /* length of dataseg after last dseg_add_target is used by load */
2061 /* TODO: this loads from data-segment */
2062 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2063 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2066 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2069 lookup_target_t *lookup;
2071 lookup = iptr->dst.lookup;
2073 i = iptr->sx.s23.s2.lookupcount;
2076 MCODECHECK((i<<2)+8);
2077 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2080 M_COMPARE(s1, lookup->value);
2081 emit_beq(cd, lookup->target.block);
2085 /* default branch */
2086 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2090 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2092 #if !defined(ENABLE_SOFTFLOAT)
2093 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2094 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2095 goto ICMD_RETURN_do;
2098 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2100 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2101 M_INTMOVE(s1, REG_RESULT);
2102 goto ICMD_RETURN_do;
2104 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2106 #if !defined(ENABLE_SOFTFLOAT)
2107 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2108 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2109 goto ICMD_RETURN_do;
2112 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2114 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2115 M_LNGMOVE(s1, REG_RESULT_PACKED);
2116 goto ICMD_RETURN_do;
2118 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2120 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2121 M_INTMOVE(s1, REG_RESULT);
2122 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2123 codegen_addpatchref(cd, PATCHER_athrow_areturn,
2124 iptr->sx.s23.s2.uc, 0);
2126 if (opt_showdisassemble)
2129 goto ICMD_RETURN_do;
2131 case ICMD_RETURN: /* ... ==> ... */
2134 #if !defined(NDEBUG)
2135 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2136 emit_verbosecall_exit(jd);
2139 #if defined(ENABLE_THREADS)
2140 /* call monitorexit function */
2142 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2143 /* stack offset for monitor argument */
2147 /* we need to save the proper return value */
2149 switch (iptr->opc) {
2153 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2155 M_STMFD(BITMASK_RESULT, REG_SP);
2160 M_LDR(REG_A0, REG_SP, s1 * 4);
2161 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2162 M_DSEG_BRANCH(disp);
2164 /* we no longer need PV here, no more loading */
2165 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2166 M_RECOMPUTE_PV(s1);*/
2168 switch (iptr->opc) {
2172 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2174 M_LDMFD(BITMASK_RESULT, REG_SP);
2180 /* deallocate stackframe for spilled variables */
2182 if ((cd->stackframesize - savedregs_num) > 0)
2183 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
2185 /* restore callee saved registers + do return */
2187 if (savedregs_bitmask) {
2188 if (!jd->isleafmethod) {
2189 savedregs_bitmask &= ~(1<<REG_LR);
2190 savedregs_bitmask |= (1<<REG_PC);
2192 M_LDMFD(savedregs_bitmask, REG_SP);
2195 /* if LR was not on stack, we need to return manually */
2197 if (jd->isleafmethod)
2198 M_MOV(REG_PC, REG_LR);
2201 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2203 bte = iptr->sx.s23.s3.bte;
2205 goto ICMD_INVOKE_do;
2207 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2208 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2209 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2210 case ICMD_INVOKEINTERFACE:
2212 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2214 um = iptr->sx.s23.s3.um;
2215 md = um->methodref->parseddesc.md;
2218 lm = iptr->sx.s23.s3.fmiref->p.method;
2220 md = lm->parseddesc;
2224 /* copy arguments to registers or stack location */
2226 s3 = md->paramcount;
2228 MCODECHECK((s3 << 1) + 64);
2230 for (s3 = s3 - 1; s3 >= 0; s3--) {
2231 var = VAR(iptr->sx.s23.s2.args[s3]);
2232 d = md->params[s3].regoff;
2234 if (var->flags & PREALLOC) /* argument was precolored? */
2237 /* TODO: document me */
2238 #if !defined(ENABLE_SOFTFLOAT)
2239 if (IS_INT_LNG_TYPE(var->type)) {
2240 #endif /* !defined(ENABLE_SOFTFLOAT) */
2241 if (!md->params[s3].inmemory) {
2242 SPLIT_OPEN(var->type, s1, REG_ITMP2);
2243 s1 = emit_load(jd, iptr, var, d);
2245 if (IS_2_WORD_TYPE(var->type))
2250 SPLIT_STORE_AND_CLOSE(var->type, d, 0);
2253 if (IS_2_WORD_TYPE(var->type)) {
2254 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2255 M_LST(s1, REG_SP, d * 4);
2258 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2259 M_IST(s1, REG_SP, d * 4);
2262 #if !defined(ENABLE_SOFTFLOAT)
2265 if (!md->params[s3].inmemory) {
2266 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2267 SPLIT_OPEN(var->type, d, REG_ITMP1);
2268 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2269 SPLIT_STORE_AND_CLOSE(var->type, d, 0);
2272 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2273 if (IS_2_WORD_TYPE(var->type))
2274 M_DST(s1, REG_SP, d * 4);
2276 M_FST(s1, REG_SP, d * 4);
2279 #endif /* !defined(ENABLE_SOFTFLOAT) */
2282 switch (iptr->opc) {
2284 disp = dseg_add_functionptr(cd, bte->fp);
2286 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2288 /* generate the actual call */
2290 M_MOV(REG_LR, REG_PC);
2291 M_MOV(REG_PC, REG_PV);
2292 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2295 emit_exception_check(cd, iptr);
2298 case ICMD_INVOKESPECIAL:
2299 emit_nullpointer_check(cd, iptr, REG_A0);
2302 case ICMD_INVOKESTATIC:
2304 disp = dseg_add_unique_address(cd, NULL);
2306 codegen_addpatchref(cd, PATCHER_invokestatic_special,
2309 if (opt_showdisassemble)
2313 disp = dseg_add_address(cd, lm->stubroutine);
2315 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2317 /* generate the actual call */
2319 M_MOV(REG_LR, REG_PC);
2320 M_MOV(REG_PC, REG_PV);
2321 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2325 case ICMD_INVOKEVIRTUAL:
2327 codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
2329 if (opt_showdisassemble)
2335 s1 = OFFSET(vftbl_t, table[0]) +
2336 sizeof(methodptr) * lm->vftblindex;
2338 /* implicit null-pointer check */
2339 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2340 OFFSET(java_objectheader, vftbl));
2341 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2343 /* generate the actual call */
2345 M_MOV(REG_LR, REG_PC);
2346 M_MOV(REG_PC, REG_PV);
2347 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2351 case ICMD_INVOKEINTERFACE:
2353 codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
2355 if (opt_showdisassemble)
2362 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2363 sizeof(methodptr*) * lm->class->index;
2364 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2367 /* implicit null-pointer check */
2368 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2369 OFFSET(java_objectheader, vftbl));
2370 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2371 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2373 /* generate the actual call */
2375 M_MOV(REG_LR, REG_PC);
2376 M_MOV(REG_PC, REG_PV);
2377 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2382 /* store return value */
2384 d = md->returntype.type;
2386 #if !defined(__SOFTFP__)
2387 /* TODO: this is only a hack, since we use R0/R1 for float
2388 return! this depends on gcc; it is independent from
2389 our ENABLE_SOFTFLOAT define */
2390 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2391 #if 0 && !defined(NDEBUG)
2392 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2394 /* we cannot use this macro, since it is not defined
2395 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2396 REG_FRESULT, REG_RESULT_TYPED(d)); */
2397 if (IS_2_WORD_TYPE(d)) {
2398 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2399 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2401 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2402 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2407 if (d != TYPE_VOID) {
2408 #if !defined(ENABLE_SOFTFLOAT)
2409 if (IS_INT_LNG_TYPE(d)) {
2410 #endif /* !defined(ENABLE_SOFTFLOAT) */
2411 if (IS_2_WORD_TYPE(d)) {
2412 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2413 M_LNGMOVE(REG_RESULT_PACKED, s1);
2416 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2417 M_INTMOVE(REG_RESULT, s1);
2420 #if !defined(ENABLE_SOFTFLOAT)
2422 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2423 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2425 #endif /* !defined(ENABLE_SOFTFLOAT) */
2427 emit_store_dst(jd, iptr, s1);
2431 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2433 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2434 /* object type cast-check */
2439 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2444 super = iptr->sx.s23.s3.c.cls;
2445 superindex = super->index;
2448 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2449 CODEGEN_CRITICAL_SECTION_NEW;
2451 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2453 /* if class is not resolved, check which code to call */
2455 if (super == NULL) {
2457 emit_label_beq(cd, BRANCH_LABEL_1);
2459 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2460 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2461 iptr->sx.s23.s3.c.ref, disp);
2463 if (opt_showdisassemble)
2466 M_DSEG_LOAD(REG_ITMP2, disp);
2467 disp = dseg_add_s4(cd, ACC_INTERFACE);
2468 M_DSEG_LOAD(REG_ITMP3, disp);
2469 M_TST(REG_ITMP2, REG_ITMP3);
2470 emit_label_beq(cd, BRANCH_LABEL_2);
2473 /* interface checkcast code */
2475 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2476 if (super == NULL) {
2477 codegen_addpatchref(cd,
2478 PATCHER_checkcast_instanceof_interface,
2479 iptr->sx.s23.s3.c.ref, 0);
2481 if (opt_showdisassemble)
2486 emit_label_beq(cd, BRANCH_LABEL_3);
2489 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2490 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2491 assert(IS_IMM(superindex));
2492 M_CMP_IMM(REG_ITMP3, superindex);
2493 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2495 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2496 superindex * sizeof(methodptr*);
2498 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2499 M_TST(REG_ITMP3, REG_ITMP3);
2500 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2503 emit_label_br(cd, BRANCH_LABEL_4);
2505 emit_label(cd, BRANCH_LABEL_3);
2508 /* class checkcast code */
2510 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2511 if (super == NULL) {
2512 emit_label(cd, BRANCH_LABEL_2);
2514 disp = dseg_add_unique_address(cd, NULL);
2516 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2517 iptr->sx.s23.s3.c.ref,
2520 if (opt_showdisassemble)
2524 disp = dseg_add_address(cd, super->vftbl);
2527 emit_label_beq(cd, BRANCH_LABEL_5);
2530 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2531 M_DSEG_LOAD(REG_ITMP3, disp);
2533 CODEGEN_CRITICAL_SECTION_START;
2535 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2536 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2537 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2538 M_DSEG_LOAD(REG_ITMP3, disp);
2539 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2541 CODEGEN_CRITICAL_SECTION_END;
2543 M_CMP(REG_ITMP2, REG_ITMP3);
2544 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2547 emit_label(cd, BRANCH_LABEL_5);
2550 if (super == NULL) {
2551 emit_label(cd, BRANCH_LABEL_1);
2552 emit_label(cd, BRANCH_LABEL_4);
2555 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2558 /* array type cast-check */
2560 s1 = emit_load_s1(jd, iptr, REG_A0);
2561 M_INTMOVE(s1, REG_A0);
2563 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2564 disp = dseg_add_unique_address(cd, NULL);
2566 codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
2567 iptr->sx.s23.s3.c.ref,
2570 if (opt_showdisassemble)
2574 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2576 M_DSEG_LOAD(REG_A1, disp);
2577 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2578 M_DSEG_BRANCH(disp);
2581 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2582 M_RECOMPUTE_PV(disp);
2584 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2585 M_TST(REG_RESULT, REG_RESULT);
2586 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2588 d = codegen_reg_of_dst(jd, iptr, s1);
2592 emit_store_dst(jd, iptr, d);
2595 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2601 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2606 super = iptr->sx.s23.s3.c.cls;
2607 superindex = super->index;
2610 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2611 CODEGEN_CRITICAL_SECTION_NEW;
2613 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2614 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2617 M_MOV(REG_ITMP1, s1);
2621 /* if class is not resolved, check which code to call */
2623 if (super == NULL) {
2627 emit_label_beq(cd, BRANCH_LABEL_1);
2629 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2630 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2631 iptr->sx.s23.s3.c.ref, disp);
2633 if (opt_showdisassemble)
2636 M_DSEG_LOAD(REG_ITMP2, disp);
2637 disp = dseg_add_s4(cd, ACC_INTERFACE);
2638 M_DSEG_LOAD(REG_ITMP3, disp);
2639 M_TST(REG_ITMP2, REG_ITMP3);
2640 emit_label_beq(cd, BRANCH_LABEL_2);
2643 /* interface checkcast code */
2645 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2646 if (super == NULL) {
2647 /* If d == REG_ITMP2, then it's destroyed in check
2652 codegen_addpatchref(cd,
2653 PATCHER_checkcast_instanceof_interface,
2654 iptr->sx.s23.s3.c.ref, 0);
2656 if (opt_showdisassemble)
2662 emit_label_beq(cd, BRANCH_LABEL_3);
2665 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2666 M_LDR_INTERN(REG_ITMP3,
2667 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2668 assert(IS_IMM(superindex));
2669 M_CMP_IMM(REG_ITMP3, superindex);
2672 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2673 superindex * sizeof(methodptr*);
2675 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2676 M_TST(REG_ITMP3, REG_ITMP3);
2680 emit_label_br(cd, BRANCH_LABEL_4);
2682 emit_label(cd, BRANCH_LABEL_3);
2685 /* class checkcast code */
2687 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2688 if (super == NULL) {
2689 emit_label(cd, BRANCH_LABEL_2);
2691 disp = dseg_add_unique_address(cd, NULL);
2693 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2694 iptr->sx.s23.s3.c.ref,
2697 if (opt_showdisassemble)
2701 disp = dseg_add_address(cd, super->vftbl);
2705 emit_label_beq(cd, BRANCH_LABEL_5);
2708 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2709 M_DSEG_LOAD(REG_ITMP2, disp);
2711 CODEGEN_CRITICAL_SECTION_START;
2713 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2714 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2715 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2717 CODEGEN_CRITICAL_SECTION_END;
2719 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2720 M_CMP(REG_ITMP1, REG_ITMP2);
2721 /* If d == REG_ITMP2, then it's destroyed */
2727 emit_label(cd, BRANCH_LABEL_5);
2730 if (super == NULL) {
2731 emit_label(cd, BRANCH_LABEL_1);
2732 emit_label(cd, BRANCH_LABEL_4);
2737 emit_store_dst(jd, iptr, d);
2740 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2742 /* copy sizes to stack if necessary */
2744 MCODECHECK((iptr->s1.argcount << 1) + 64);
2746 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2748 var = VAR(iptr->sx.s23.s2.args[s1]);
2750 /* copy SAVEDVAR sizes to stack */
2752 if (!(var->flags & PREALLOC)) {
2753 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2754 M_STR(s2, REG_SP, s1 * 4);
2758 /* a0 = dimension count */
2760 assert(IS_IMM(iptr->s1.argcount));
2761 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2763 /* is patcher function set? */
2765 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2766 disp = dseg_add_unique_address(cd, NULL);
2768 codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
2769 iptr->sx.s23.s3.c.ref, disp);
2771 if (opt_showdisassemble)
2775 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2777 /* a1 = arraydescriptor */
2779 M_DSEG_LOAD(REG_A1, disp);
2781 /* a2 = pointer to dimensions = stack pointer */
2783 M_INTMOVE(REG_SP, REG_A2);
2785 /* call builtin_multianewarray here */
2787 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2788 M_DSEG_BRANCH(disp);
2792 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2795 /* check for exception before result assignment */
2797 emit_exception_check(cd, iptr);
2801 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2802 M_INTMOVE(REG_RESULT, d);
2803 emit_store_dst(jd, iptr, d);
2806 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2808 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2809 emit_nullpointer_check(cd, iptr, s1);
2813 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2816 } /* the big switch */
2818 } /* for all instructions */
2820 } /* for all basic blocks */
2822 dseg_createlinenumbertable(cd);
2825 /* generate stubs */
2827 emit_patcher_stubs(jd);
2829 /* everything's ok */
2835 /* codegen_emit_stub_compiler **************************************************
2837 Emits a stub routine which calls the compiler.
2839 *******************************************************************************/
2841 void codegen_emit_stub_compiler(jitdata *jd)
2846 /* get required compiler data */
2851 /* code for the stub */
2853 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2854 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2858 /* codegen_emit_stub_native ****************************************************
2860 Emits a stub routine which calls a native method.
2862 *******************************************************************************/
2864 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2873 s4 disp, funcdisp, s1, s2;
2875 /* get required compiler data */
2881 /* initialize variables */
2884 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2886 /* calculate stackframe size */
2888 cd->stackframesize =
2889 1 + /* return address */
2890 sizeof(stackframeinfo) / SIZEOF_VOID_P + /* stackframeinfo */
2891 sizeof(localref_table) / SIZEOF_VOID_P + /* localref_table */
2892 nmd->memuse; /* stack arguments */
2894 /* align stack to 8-byte */
2896 cd->stackframesize = (cd->stackframesize + 1) & ~1;
2898 /* create method header */
2900 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2901 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
2902 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2903 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2904 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2905 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2906 (void) dseg_addlinenumbertablesize(cd);
2907 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2909 /* generate stub code */
2911 M_STMFD(1<<REG_LR, REG_SP);
2912 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
2914 #if !defined(NDEBUG)
2915 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2916 emit_verbosecall_enter(jd);
2919 /* get function address (this must happen before the stackframeinfo) */
2921 funcdisp = dseg_add_functionptr(cd, f);
2923 #if !defined(WITH_STATIC_CLASSPATH)
2925 codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
2927 if (opt_showdisassemble)
2932 /* Save integer and float argument registers (these are 4
2933 registers, stack is 8-byte aligned). */
2935 M_STMFD(BITMASK_ARGS, REG_SP);
2936 /* TODO: floating point */
2938 /* create native stackframe info */
2940 assert(IS_IMM(4*4 + cd->stackframesize * 4));
2941 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2942 M_MOV(REG_A1, REG_PV);
2943 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize * 4);
2944 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2945 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2946 M_DSEG_BRANCH(disp);
2950 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2953 /* Restore integer and float argument registers (these are 4
2954 registers, stack is 8-byte aligned). */
2956 M_LDMFD(BITMASK_ARGS, REG_SP);
2957 /* TODO: floating point */
2959 /* copy or spill arguments to new locations */
2960 /* ATTENTION: the ARM has only integer argument registers! */
2962 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
2963 t = md->paramtypes[i].type;
2965 if (!md->params[i].inmemory) {
2966 s1 = md->params[i].regoff;
2967 s2 = nmd->params[j].regoff;
2969 if (!nmd->params[j].inmemory) {
2970 #if !defined(__ARM_EABI__)
2971 SPLIT_OPEN(t, s1, REG_ITMP1);
2972 SPLIT_LOAD(t, s1, cd->stackframesize);
2973 SPLIT_OPEN(t, s2, REG_ITMP1);
2976 if (IS_2_WORD_TYPE(t))
2981 #if !defined(__ARM_EABI__)
2982 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2986 #if !defined(__ARM_EABI__)
2987 SPLIT_OPEN(t, s1, REG_ITMP1);
2988 SPLIT_LOAD(t, s1, cd->stackframesize);
2991 if (IS_2_WORD_TYPE(t))
2992 M_LST(s1, REG_SP, s2 * 4);
2994 M_IST(s1, REG_SP, s2 * 4);
2995 /* no SPLIT_CLOSE here because argument is fully on stack now */
2999 s1 = md->params[i].regoff + cd->stackframesize;
3000 s2 = nmd->params[j].regoff;
3002 if (IS_2_WORD_TYPE(t)) {
3003 M_LLD(REG_ITMP12_PACKED, REG_SP, s1 * 4);
3004 M_LST(REG_ITMP12_PACKED, REG_SP, s2 * 4);
3007 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
3008 M_IST(REG_ITMP1, REG_SP, s2 * 4);
3013 /* put class into second argument register */
3015 if (m->flags & ACC_STATIC) {
3016 disp = dseg_add_address(cd, m->class);
3017 M_DSEG_LOAD(REG_A1, disp);
3020 /* put env into first argument register */
3022 disp = dseg_add_address(cd, _Jv_env);
3023 M_DSEG_LOAD(REG_A0, disp);
3025 /* do the native function call */
3027 M_DSEG_BRANCH(funcdisp);
3030 /* TODO: this is only needed because of the tracer ... do we
3033 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3036 #if !defined(__SOFTFP__)
3037 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3038 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3039 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3040 #if 0 && !defined(NDEBUG)
3041 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3043 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3044 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3045 if (IS_2_WORD_TYPE(md->returntype.type)) {
3046 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3047 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3049 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3050 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3055 #if !defined(NDEBUG)
3056 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3057 emit_verbosecall_exit(jd);
3060 /* remove native stackframe info */
3061 /* TODO: improve this store/load */
3063 M_STMFD(BITMASK_RESULT, REG_SP);
3065 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
3066 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3067 M_DSEG_BRANCH(disp);
3068 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3071 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3072 M_LDMFD(BITMASK_RESULT, REG_SP);
3074 /* finish stub code, but do not yet return to caller */
3076 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
3077 M_LDMFD(1<<REG_LR, REG_SP);
3079 /* check for exception */
3081 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3082 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3084 /* handle exception here */
3086 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3088 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3089 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3090 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3092 /* generate patcher stubs */
3094 emit_patcher_stubs(jd);
3098 /* asm_debug *******************************************************************
3102 *******************************************************************************/
3104 void asm_debug(int a1, int a2, int a3, int a4)
3106 printf("===> i am going to exit after this debugging message!\n");
3107 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3108 vm_abort("leave you now");
3113 * These are local overrides for various environment variables in Emacs.
3114 * Please do not remove this and leave it at the end of the file, where
3115 * Emacs will automagically detect them.
3116 * ---------------------------------------------------------------------
3119 * indent-tabs-mode: t
3123 * vim:noexpandtab:sw=4:ts=4: