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 8115 2007-06-20 19:14:05Z michi $
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)) {
219 if (!md->params[i].inmemory) {
220 if (!(var->flags & INMEMORY)) {
221 if (IS_2_WORD_TYPE(t))
222 M_LNGMOVE(s1, var->vv.regoff);
224 M_INTMOVE(s1, var->vv.regoff);
227 if (IS_2_WORD_TYPE(t))
228 M_LST(s1, REG_SP, var->vv.regoff);
230 M_IST(s1, REG_SP, var->vv.regoff);
233 else { /* stack arguments */
234 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
235 if (IS_2_WORD_TYPE(t))
236 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
238 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
240 else { /* stack arg -> spilled */
241 /* Reuse Memory Position on Caller Stack */
242 var->vv.regoff = cd->stackframesize * 4 + s1;
245 #if !defined(ENABLE_SOFTFLOAT)
248 if (!md->params[i].inmemory) {
249 if (!(var->flags & INMEMORY)) {
250 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
253 if (IS_2_WORD_TYPE(t))
254 M_LST(s1, REG_SP, var->vv.regoff);
256 M_IST(s1, REG_SP, var->vv.regoff);
260 if (!(var->flags & INMEMORY)) {
261 if (IS_2_WORD_TYPE(t))
262 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
264 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
267 /* Reuse Memory Position on Caller Stack */
268 var->vv.regoff = cd->stackframesize * 4 + s1;
272 #endif /* !defined(ENABLE_SOFTFLOAT) */
275 #if defined(ENABLE_THREADS)
276 /* call monitorenter function */
278 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
279 /* stack offset for monitor argument */
283 # if !defined(NDEBUG)
284 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
285 M_STMFD(BITMASK_ARGS, REG_SP);
290 /* get the correct lock object */
292 if (m->flags & ACC_STATIC) {
293 disp = dseg_add_address(cd, &m->class->object.header);
294 M_DSEG_LOAD(REG_A0, disp);
297 emit_nullpointer_check_force(cd, iptr, REG_A0);
300 M_STR(REG_A0, REG_SP, s1 * 4);
301 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
303 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
306 # if !defined(NDEBUG)
307 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
308 M_LDMFD(BITMASK_ARGS, REG_SP);
314 /* call trace function */
316 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
317 emit_verbosecall_enter(jd);
320 /* end of header generation */
322 /* SECTION: ICMD Code Generation */
323 /* for all basic blocks */
325 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
327 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
329 /* is this basic block reached? */
331 if (bptr->flags < BBREACHED)
334 /* branch resolving */
336 codegen_resolve_branchrefs(cd, bptr);
338 /* copy interface registers to their destination */
344 #if defined(ENABLE_LSRA)
348 var = VAR(bptr->invars[len]);
349 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
350 if (!(var->flags & INMEMORY))
354 M_INTMOVE(REG_ITMP1, d);
355 emit_store(jd, NULL, var, d);
362 var = VAR(bptr->invars[len]);
364 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
365 d = codegen_reg_of_var(0, var, REG_ITMP1);
366 M_INTMOVE(REG_ITMP1, d);
367 emit_store(jd, NULL, var, d);
370 assert((var->flags & INOUT));
373 #if defined(ENABLE_LSRA)
377 /* for all instructions */
380 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
382 /* add line number */
383 if (iptr->line != currentline) {
384 dseg_addlinenumber(cd, iptr->line);
385 currentline = iptr->line;
388 MCODECHECK(64); /* an instruction usually needs < 64 words */
392 case ICMD_NOP: /* ... ==> ... */
395 /* constant operations ************************************************/
397 case ICMD_ICONST: /* ... ==> ..., constant */
399 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
400 ICONST(d, iptr->sx.val.i);
401 emit_store_dst(jd, iptr, d);
404 case ICMD_ACONST: /* ... ==> ..., constant */
406 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
407 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
408 disp = dseg_add_unique_address(cd, NULL);
410 codegen_addpatchref(cd, PATCHER_aconst,
414 if (opt_showdisassemble)
417 M_DSEG_LOAD(d, disp);
420 ICONST(d, (u4) iptr->sx.val.anyptr);
422 emit_store_dst(jd, iptr, d);
425 case ICMD_LCONST: /* ... ==> ..., constant */
427 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
428 LCONST(d, iptr->sx.val.l);
429 emit_store_dst(jd, iptr, d);
432 case ICMD_FCONST: /* ... ==> ..., constant */
434 #if defined(ENABLE_SOFTFLOAT)
435 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
436 ICONST(d, iptr->sx.val.i);
437 emit_store_dst(jd, iptr, d);
439 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
440 FCONST(d, iptr->sx.val.f);
441 emit_store_dst(jd, iptr, d);
445 case ICMD_DCONST: /* ... ==> ..., constant */
447 #if defined(ENABLE_SOFTFLOAT)
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);
452 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
453 DCONST(d, iptr->sx.val.d);
454 emit_store_dst(jd, iptr, d);
459 /* load/store/copy/move operations ************************************/
461 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
462 case ICMD_ALOAD: /* op1 = local variable */
466 case ICMD_ISTORE: /* ..., value ==> ... */
477 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
481 /* pop operations *****************************************************/
483 /* attention: double and longs are only one entry in CACAO ICMDs */
485 case ICMD_POP: /* ..., value ==> ... */
486 case ICMD_POP2: /* ..., value, value ==> ... */
491 /* integer operations *************************************************/
493 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
495 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
496 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
497 M_MOV(d, REG_LSL(s1, 24));
498 M_MOV(d, REG_ASR(d, 24));
499 emit_store_dst(jd, iptr, d);
502 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
504 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
505 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
506 M_MOV(d, REG_LSL(s1, 16));
507 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
508 emit_store_dst(jd, iptr, d);
511 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
513 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
514 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
515 M_MOV(d, REG_LSL(s1, 16));
516 M_MOV(d, REG_ASR(d, 16));
517 emit_store_dst(jd, iptr, d);
520 case ICMD_I2L: /* ..., value ==> ..., value */
522 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
523 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
524 M_INTMOVE(s1, GET_LOW_REG(d));
525 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
526 emit_store_dst(jd, iptr, d);
529 case ICMD_L2I: /* ..., value ==> ..., value */
531 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
532 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
534 emit_store_dst(jd, iptr, d);
537 case ICMD_INEG: /* ..., value ==> ..., - value */
539 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
540 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
542 emit_store_dst(jd, iptr, d);
545 case ICMD_LNEG: /* ..., value ==> ..., - value */
547 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
548 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
549 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
550 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
551 emit_store_dst(jd, iptr, d);
554 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
556 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
557 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
558 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
560 emit_store_dst(jd, iptr, d);
563 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
565 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
566 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
567 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
568 M_ADD_S(GET_LOW_REG(d), s1, s2);
569 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
570 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
571 M_ADC(GET_HIGH_REG(d), s1, s2);
572 emit_store_dst(jd, iptr, d);
578 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
579 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
581 if (IS_IMM(iptr->sx.val.i)) {
582 M_ADD_IMM(d, s1, iptr->sx.val.i);
583 } else if (IS_IMM(-iptr->sx.val.i)) {
584 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
586 ICONST(REG_ITMP3, iptr->sx.val.i);
587 M_ADD(d, s1, REG_ITMP3);
590 emit_store_dst(jd, iptr, d);
593 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
594 /* sx.val.l = constant */
596 s3 = iptr->sx.val.l & 0xffffffff;
597 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
598 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
600 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
602 ICONST(REG_ITMP3, s3);
603 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
605 s3 = iptr->sx.val.l >> 32;
606 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
608 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
610 ICONST(REG_ITMP3, s3);
611 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
613 emit_store_dst(jd, iptr, d);
616 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
618 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
619 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
620 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
622 emit_store_dst(jd, iptr, d);
625 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
627 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
628 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
629 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
630 M_SUB_S(GET_LOW_REG(d), s1, s2);
631 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
632 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
633 M_SBC(GET_HIGH_REG(d), s1, s2);
634 emit_store_dst(jd, iptr, d);
637 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
638 /* sx.val.i = constant */
640 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
641 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
642 if (IS_IMM(iptr->sx.val.i))
643 M_SUB_IMM(d, s1, iptr->sx.val.i);
645 ICONST(REG_ITMP3, iptr->sx.val.i);
646 M_SUB(d, s1, REG_ITMP3);
648 emit_store_dst(jd, iptr, d);
651 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
652 /* sx.val.l = constant */
654 s3 = iptr->sx.val.l & 0xffffffff;
655 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
656 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
658 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
660 ICONST(REG_ITMP3, s3);
661 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
663 s3 = iptr->sx.val.l >> 32;
664 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
666 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
668 ICONST(REG_ITMP3, s3);
669 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
671 emit_store_dst(jd, iptr, d);
674 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
676 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
677 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
678 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
680 emit_store_dst(jd, iptr, d);
683 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
684 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
686 s1 = emit_load_s1(jd, iptr, REG_A0);
687 s2 = emit_load_s2(jd, iptr, REG_A1);
688 emit_arithmetic_check(cd, iptr, s2);
690 /* move arguments into argument registers */
691 M_INTMOVE(s1, REG_A0);
692 M_INTMOVE(s2, REG_A1);
694 /* call builtin function */
695 bte = iptr->sx.s23.s3.bte;
696 disp = dseg_add_functionptr(cd, bte->fp);
700 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
703 /* move result into destination register */
704 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
705 M_INTMOVE(REG_RESULT, d);
706 emit_store_dst(jd, iptr, d);
709 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
710 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
712 /* move arguments into argument registers */
714 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
715 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
716 /* XXX TODO: only do this if arithmetic check is really done! */
717 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
718 emit_arithmetic_check(cd, iptr, REG_ITMP3);
720 M_LNGMOVE(s1, REG_A0_A1_PACKED);
721 M_LNGMOVE(s2, REG_A2_A3_PACKED);
723 /* call builtin function */
724 bte = iptr->sx.s23.s3.bte;
725 disp = dseg_add_functionptr(cd, bte->fp);
729 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
732 /* move result into destination register */
733 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
734 M_LNGMOVE(REG_RESULT_PACKED, d);
735 emit_store_dst(jd, iptr, d);
738 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
739 /* sx.val.i = constant */
741 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
742 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
743 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
744 emit_store_dst(jd, iptr, d);
747 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
748 /* sx.val.i = constant */
750 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
751 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
752 /* this rounds towards 0 as java likes it */
753 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
754 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
755 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
756 /* this rounds towards nearest, not java style */
757 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
758 M_ADCMI_IMM(d, d, 0);*/
759 emit_store_dst(jd, iptr, d);
762 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
763 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
765 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
766 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
767 M_MOV_S(REG_ITMP1, s1);
768 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
769 if (IS_IMM(iptr->sx.val.i))
770 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
772 ICONST(REG_ITMP3, iptr->sx.val.i);
773 M_AND(REG_ITMP1, REG_ITMP3, d);
775 M_RSBMI_IMM(d, d, 0);
776 emit_store_dst(jd, iptr, d);
779 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
781 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
782 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
783 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
784 M_AND_IMM(s2, 0x1f, REG_ITMP2);
785 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
786 emit_store_dst(jd, iptr, d);
789 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
791 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
792 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
793 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
794 M_AND_IMM(s2, 0x1f, REG_ITMP2);
795 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
796 emit_store_dst(jd, iptr, d);
799 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
801 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
802 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
803 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
804 M_AND_IMM(s2, 0x1f, REG_ITMP2);
805 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
806 emit_store_dst(jd, iptr, d);
809 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
810 /* sx.val.i = constant */
812 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
813 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
814 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
815 emit_store_dst(jd, iptr, d);
818 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
819 /* sx.val.i = constant */
821 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
822 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
823 /* we need to check for zero here because arm interprets it as SHR by 32 */
824 if ((iptr->sx.val.i & 0x1f) == 0) {
827 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
829 emit_store_dst(jd, iptr, d);
832 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
833 /* sx.val.i = constant */
835 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
836 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
837 /* we need to check for zero here because arm interprets it as SHR by 32 */
838 if ((iptr->sx.val.i & 0x1f) == 0)
841 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
842 emit_store_dst(jd, iptr, d);
845 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
847 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
848 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
849 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
851 emit_store_dst(jd, iptr, d);
854 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
856 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
857 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
858 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
859 M_AND(s1, s2, GET_LOW_REG(d));
860 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
861 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
862 M_AND(s1, s2, GET_HIGH_REG(d));
863 emit_store_dst(jd, iptr, d);
866 case ICMD_IOR: /* ..., 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_LOR: /* ..., 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_ORR(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_ORR(s1, s2, GET_HIGH_REG(d));
884 emit_store_dst(jd, iptr, d);
887 case ICMD_IXOR: /* ..., 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_LXOR: /* ..., 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_EOR(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_EOR(s1, s2, GET_HIGH_REG(d));
905 emit_store_dst(jd, iptr, d);
909 /* floating operations ************************************************/
911 #if !defined(ENABLE_SOFTFLOAT)
913 case ICMD_FNEG: /* ..., value ==> ..., - value */
915 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
916 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
918 emit_store_dst(jd, iptr, d);
921 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
923 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
924 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
925 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
927 emit_store_dst(jd, iptr, d);
930 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
932 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
933 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
934 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
936 emit_store_dst(jd, iptr, d);
939 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
941 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
942 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
943 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
945 emit_store_dst(jd, iptr, d);
948 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
949 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
950 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
951 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
953 emit_store_dst(jd, iptr, d);
956 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
959 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
961 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
962 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
963 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
965 emit_store_dst(jd, iptr, d);
968 case ICMD_DNEG: /* ..., value ==> ..., - value */
970 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
971 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
973 emit_store_dst(jd, iptr, d);
976 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
978 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
979 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
980 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
982 emit_store_dst(jd, iptr, d);
985 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
987 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
988 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
989 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
991 emit_store_dst(jd, iptr, d);
994 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
996 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
997 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
998 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1000 emit_store_dst(jd, iptr, d);
1003 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1005 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1006 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1007 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1009 emit_store_dst(jd, iptr, d);
1012 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1015 case ICMD_DREM: /* ..., 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_I2F: /* ..., value ==> ..., (float) value */
1026 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1027 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1029 emit_store_dst(jd, iptr, d);
1032 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1034 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1035 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1037 emit_store_dst(jd, iptr, d);
1040 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1042 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1043 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1044 /* this uses round towards zero, as Java likes it */
1046 /* this checks for NaN; to return zero as Java likes it */
1049 emit_store_dst(jd, iptr, d);
1052 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1054 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1055 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1056 /* this uses round towards zero, as Java likes it */
1058 /* this checks for NaN; to return zero as Java likes it */
1061 emit_store_dst(jd, iptr, d);
1064 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1066 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1067 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1069 emit_store_dst(jd, iptr, d);
1072 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1074 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1075 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1077 emit_store_dst(jd, iptr, d);
1080 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1082 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1083 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1084 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1087 M_SUBGT_IMM(d, d, 1);
1088 M_ADDLT_IMM(d, d, 1);
1089 emit_store_dst(jd, iptr, d);
1092 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1094 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1095 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1096 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1099 M_SUBGT_IMM(d, d, 1);
1100 M_ADDLT_IMM(d, d, 1);
1101 emit_store_dst(jd, iptr, d);
1104 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1106 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1107 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1108 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1111 M_SUBLT_IMM(d, d, 1);
1112 M_ADDGT_IMM(d, d, 1);
1113 emit_store_dst(jd, iptr, d);
1116 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1118 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1119 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1120 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1123 M_SUBLT_IMM(d, d, 1);
1124 M_ADDGT_IMM(d, d, 1);
1125 emit_store_dst(jd, iptr, d);
1128 #endif /* !defined(ENABLE_SOFTFLOAT) */
1131 /* memory operations **************************************************/
1133 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1135 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1136 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1137 /* implicit null-pointer check */
1138 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1139 emit_store_dst(jd, iptr, d);
1142 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1144 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1145 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1146 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1147 /* implicit null-pointer check */
1148 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1149 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1150 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1151 emit_store_dst(jd, iptr, d);
1154 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1156 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1157 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1158 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1159 /* implicit null-pointer check */
1160 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1161 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1162 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1163 emit_store_dst(jd, iptr, d);
1166 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1168 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1169 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1170 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1171 /* implicit null-pointer check */
1172 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1173 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1174 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1175 emit_store_dst(jd, iptr, d);
1178 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1180 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1181 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1182 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1183 /* implicit null-pointer check */
1184 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1185 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1186 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1187 emit_store_dst(jd, iptr, d);
1190 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1192 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1193 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1194 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1195 /* implicit null-pointer check */
1196 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1197 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1198 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1199 emit_store_dst(jd, iptr, d);
1202 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1204 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1205 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1206 /* implicit null-pointer check */
1207 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1208 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1209 #if !defined(ENABLE_SOFTFLOAT)
1210 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1211 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1213 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1214 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1216 emit_store_dst(jd, iptr, d);
1219 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1221 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1222 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1223 /* implicit null-pointer check */
1224 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1225 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1226 #if !defined(ENABLE_SOFTFLOAT)
1227 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1228 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1230 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1231 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1233 emit_store_dst(jd, iptr, d);
1236 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1238 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1239 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1240 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1241 /* implicit null-pointer check */
1242 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1243 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1244 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1245 emit_store_dst(jd, iptr, d);
1248 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1250 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1251 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1252 /* implicit null-pointer check */
1253 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1254 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1255 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1256 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1259 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1261 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1262 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1263 /* implicit null-pointer check */
1264 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1265 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1266 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1267 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1270 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1272 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1273 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1274 /* implicit null-pointer check */
1275 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1276 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1277 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1278 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1281 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1283 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1284 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1285 /* implicit null-pointer check */
1286 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1287 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1288 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1289 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1292 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1294 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1295 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1296 /* implicit null-pointer check */
1297 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1298 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1299 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1300 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1303 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1305 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1306 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1307 /* implicit null-pointer check */
1308 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1309 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1310 #if !defined(ENABLE_SOFTFLOAT)
1311 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1312 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1314 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1315 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1319 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1321 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1322 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1323 /* implicit null-pointer check */
1324 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1325 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1326 #if !defined(ENABLE_SOFTFLOAT)
1327 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1328 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1330 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1331 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1335 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1337 s1 = emit_load_s1(jd, iptr, REG_A0);
1338 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1339 s3 = emit_load_s3(jd, iptr, REG_A1);
1341 /* implicit null-pointer check */
1342 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1344 /* move arguments to argument registers */
1345 M_INTMOVE(s1, REG_A0);
1346 M_INTMOVE(s3, REG_A1);
1348 /* call builtin function */
1349 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1350 M_DSEG_BRANCH(disp);
1353 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1356 /* check resturn value of builtin */
1357 emit_exception_check(cd, iptr);
1359 /* finally store address into array */
1360 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1361 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1362 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1363 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1364 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1367 case ICMD_GETSTATIC: /* ... ==> ..., value */
1369 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1370 unresolved_field *uf = iptr->sx.s23.s3.uf;
1372 fieldtype = uf->fieldref->parseddesc.fd->type;
1374 disp = dseg_add_unique_address(cd, NULL);
1376 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1378 if (opt_showdisassemble)
1382 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1384 fieldtype = fi->type;
1386 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1387 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1389 if (opt_showdisassemble)
1393 disp = dseg_add_address(cd, &(fi->value));
1396 M_DSEG_LOAD(REG_ITMP3, disp);
1397 switch (fieldtype) {
1399 #if defined(ENABLE_SOFTFLOAT)
1403 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1404 M_ILD_INTERN(d, REG_ITMP3, 0);
1407 #if defined(ENABLE_SOFTFLOAT)
1410 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1411 M_LLD_INTERN(d, REG_ITMP3, 0);
1413 #if !defined(ENABLE_SOFTFLOAT)
1415 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1416 M_FLD_INTERN(d, REG_ITMP3, 0);
1419 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1420 M_DLD_INTERN(d, REG_ITMP3, 0);
1426 emit_store_dst(jd, iptr, d);
1429 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1431 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1432 unresolved_field *uf = iptr->sx.s23.s3.uf;
1434 fieldtype = uf->fieldref->parseddesc.fd->type;
1436 disp = dseg_add_unique_address(cd, NULL);
1438 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1440 if (opt_showdisassemble)
1444 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1446 fieldtype = fi->type;
1448 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1449 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1451 if (opt_showdisassemble)
1455 disp = dseg_add_address(cd, &(fi->value));
1458 M_DSEG_LOAD(REG_ITMP3, disp);
1459 switch (fieldtype) {
1461 #if defined(ENABLE_SOFTFLOAT)
1465 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1466 M_IST_INTERN(s1, REG_ITMP3, 0);
1469 #if defined(ENABLE_SOFTFLOAT)
1472 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1473 M_LST_INTERN(s1, REG_ITMP3, 0);
1475 #if !defined(ENABLE_SOFTFLOAT)
1477 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1478 M_FST_INTERN(s1, REG_ITMP3, 0);
1481 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1482 M_DST_INTERN(s1, REG_ITMP3, 0);
1490 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1492 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1493 emit_nullpointer_check(cd, iptr, s1);
1496 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1497 unresolved_field *uf = iptr->sx.s23.s3.uf;
1499 fieldtype = uf->fieldref->parseddesc.fd->type;
1502 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1504 fieldtype = fi->type;
1508 #if !defined(ENABLE_SOFTFLOAT)
1509 /* HACK: softnull checks on floats */
1510 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1511 emit_nullpointer_check_force(cd, iptr, s1);
1514 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1515 unresolved_field *uf = iptr->sx.s23.s3.uf;
1517 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1519 if (opt_showdisassemble)
1525 switch (fieldtype) {
1527 #if defined(ENABLE_SOFTFLOAT)
1531 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1535 #if defined(ENABLE_SOFTFLOAT)
1538 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1541 #if !defined(ENABLE_SOFTFLOAT)
1543 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1547 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1554 emit_store_dst(jd, iptr, d);
1557 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1559 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1560 emit_nullpointer_check(cd, iptr, s1);
1562 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1563 unresolved_field *uf = iptr->sx.s23.s3.uf;
1565 fieldtype = uf->fieldref->parseddesc.fd->type;
1568 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1570 fieldtype = fi->type;
1574 #if !defined(ENABLE_SOFTFLOAT)
1575 /* HACK: softnull checks on floats */
1576 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1577 emit_nullpointer_check_force(cd, iptr, s1);
1580 switch (fieldtype) {
1582 #if defined(ENABLE_SOFTFLOAT)
1586 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1588 #if defined(ENABLE_SOFTFLOAT)
1589 case TYPE_DBL: /* fall through */
1592 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1594 #if !defined(ENABLE_SOFTFLOAT)
1597 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1604 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1605 unresolved_field *uf = iptr->sx.s23.s3.uf;
1607 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1609 if (opt_showdisassemble)
1615 switch (fieldtype) {
1617 #if defined(ENABLE_SOFTFLOAT)
1621 M_IST(s2, s1, disp);
1624 #if defined(ENABLE_SOFTFLOAT)
1627 M_LST(s2, s1, disp);
1629 #if !defined(ENABLE_SOFTFLOAT)
1631 M_FST(s2, s1, disp);
1634 M_DST(s2, s1, disp);
1643 /* branch operations **************************************************/
1645 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1647 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1648 M_INTMOVE(s1, REG_ITMP1_XPTR);
1649 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1650 codegen_addpatchref(cd, PATCHER_athrow_areturn,
1651 iptr->sx.s23.s2.uc, 0);
1653 if (opt_showdisassemble)
1656 disp = dseg_add_functionptr(cd, asm_handle_exception);
1657 M_DSEG_LOAD(REG_ITMP3, disp);
1658 M_MOV(REG_ITMP2_XPC, REG_PC);
1659 M_MOV(REG_PC, REG_ITMP3);
1660 M_NOP; /* nop ensures that XPC is less than the end */
1661 /* of basic block */
1664 case ICMD_GOTO: /* ... ==> ... */
1667 emit_br(cd, iptr->dst.block);
1670 case ICMD_JSR: /* ... ==> ... */
1672 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1675 case ICMD_IFNULL: /* ..., value ==> ... */
1676 case ICMD_IFNONNULL:
1678 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1680 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1683 case ICMD_IFLT: /* ..., value ==> ... */
1684 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1690 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1691 M_COMPARE(s1, iptr->sx.val.i);
1692 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1695 case ICMD_IF_LEQ: /* ..., value ==> ... */
1697 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1698 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1699 if (iptr->sx.val.l == 0) {
1700 M_ORR_S(s1, s2, REG_ITMP3);
1703 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1704 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1705 M_CMP(s1, REG_ITMP3);*/
1706 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1707 M_CMPEQ(s2, REG_ITMP3);
1709 emit_beq(cd, iptr->dst.block);
1712 case ICMD_IF_LLT: /* ..., value ==> ... */
1714 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1715 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1716 if (iptr->sx.val.l == 0) {
1717 /* if high word is less than zero, the whole long is too */
1719 emit_blt(cd, iptr->dst.block);
1722 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1723 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1724 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1725 M_CMP(s1, REG_ITMP3);*/
1726 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1727 M_MOVGT_IMM(2, REG_ITMP1);
1728 M_MOVEQ_IMM(1, REG_ITMP1);
1730 /* low compare: x=x-1(ifLO) */
1731 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1732 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1733 M_CMP(s2, REG_ITMP3);*/
1734 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1736 /* branch if (x LT 1) */
1737 M_CMP_IMM(REG_ITMP1, 1);
1738 emit_blt(cd, iptr->dst.block);
1742 case ICMD_IF_LLE: /* ..., value ==> ... */
1744 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1745 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1746 if (iptr->sx.val.l == 0) {
1747 /* if high word is less than zero, the whole long is too */
1749 emit_blt(cd, iptr->dst.block);
1751 /* ... otherwise the low word has to be zero (tricky!) */
1753 emit_beq(cd, iptr->dst.block);
1756 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1757 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1758 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1759 M_CMP(s1, REG_ITMP3);*/
1760 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1761 M_MOVGT_IMM(2, REG_ITMP1);
1762 M_MOVEQ_IMM(1, REG_ITMP1);
1764 /* low compare: x=x+1(ifHI) */
1765 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1766 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1767 M_CMP(s2, REG_ITMP3);*/
1768 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1770 /* branch if (x LE 1) */
1771 M_CMP_IMM(REG_ITMP1, 1);
1772 emit_ble(cd, iptr->dst.block);
1776 case ICMD_IF_LGE: /* ..., value ==> ... */
1778 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1779 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1780 if (iptr->sx.val.l == 0) {
1781 /* if high word is greater or equal zero, the whole long is too */
1783 emit_bge(cd, iptr->dst.block);
1786 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1787 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1788 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1789 M_CMP(s1, REG_ITMP3);*/
1790 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1791 M_MOVGT_IMM(2, REG_ITMP1);
1792 M_MOVEQ_IMM(1, REG_ITMP1);
1794 /* low compare: x=x-1(ifLO) */
1795 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1796 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1797 M_CMP(s2, REG_ITMP3);*/
1798 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1800 /* branch if (x GE 1) */
1801 M_CMP_IMM(REG_ITMP1, 1);
1802 emit_bge(cd, iptr->dst.block);
1806 case ICMD_IF_LGT: /* ..., value ==> ... */
1808 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1809 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1811 if (iptr->sx.val.l == 0) {
1812 /* if high word is greater than zero, the whole long is too */
1815 codegen_add_branch_ref(cd, iptr->dst.block);
1817 /* ... or high was zero and low is non zero (tricky!) */
1818 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1819 M_MOVLT_IMM(1, REG_ITMP3);
1820 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1822 codegen_add_branch_ref(cd, iptr->dst.block);
1826 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1827 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1828 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1829 M_CMP(s1, REG_ITMP3);*/
1830 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1831 M_MOVGT_IMM(2, REG_ITMP1);
1832 M_MOVEQ_IMM(1, REG_ITMP1);
1834 /* low compare: x=x+1(ifHI) */
1835 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1836 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1837 M_CMP(s2, REG_ITMP3);*/
1838 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1840 /* branch if (x GT 1) */
1841 M_CMP_IMM(REG_ITMP1, 1);
1842 emit_bgt(cd, iptr->dst.block);
1848 case ICMD_IF_LNE: /* ..., value ==> ... */
1850 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1851 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1852 if (iptr->sx.val.l == 0) {
1853 M_ORR_S(s1, s2, REG_ITMP3);
1856 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1857 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1858 M_CMP(s1, REG_ITMP3);*/
1859 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1860 M_CMPEQ(s2, REG_ITMP3);
1862 emit_bne(cd, iptr->dst.block);
1865 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1866 case ICMD_IF_ICMPNE:
1867 case ICMD_IF_ICMPLT:
1868 case ICMD_IF_ICMPLE:
1869 case ICMD_IF_ICMPGT:
1870 case ICMD_IF_ICMPGE:
1872 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1873 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1875 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1878 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1879 case ICMD_IF_ACMPNE:
1881 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1882 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1884 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1887 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1888 /* op1 = target JavaVM pc */
1890 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1891 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1894 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1895 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1898 emit_beq(cd, iptr->dst.block);
1901 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1902 /* op1 = target JavaVM pc */
1904 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1905 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1908 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1909 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1912 emit_bne(cd, iptr->dst.block);
1915 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1916 /* op1 = target JavaVM pc */
1918 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1919 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1920 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1922 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1923 M_MOVGT_IMM(2, REG_ITMP3);
1924 M_MOVEQ_IMM(1, REG_ITMP3);
1926 /* low compare: x=x-1(ifLO) */
1927 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1928 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1930 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1932 /* branch if (x LT 1) */
1933 M_CMP_IMM(REG_ITMP3, 1);
1934 emit_blt(cd, iptr->dst.block);
1937 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1938 /* op1 = target JavaVM pc */
1940 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1941 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1942 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1944 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1945 M_MOVGT_IMM(2, REG_ITMP3);
1946 M_MOVEQ_IMM(1, REG_ITMP3);
1948 /* low compare: x=x-1(ifLO) */
1949 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1950 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1952 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1954 /* branch if (x LE 1) */
1955 M_CMP_IMM(REG_ITMP3, 1);
1956 emit_ble(cd, iptr->dst.block);
1959 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1960 /* op1 = target JavaVM pc */
1962 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1963 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1964 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1966 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1967 M_MOVGT_IMM(2, REG_ITMP3);
1968 M_MOVEQ_IMM(1, REG_ITMP3);
1970 /* low compare: x=x-1(ifLO) */
1971 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1972 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1974 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1976 /* branch if (x GT 1) */
1977 M_CMP_IMM(REG_ITMP3, 1);
1978 emit_bgt(cd, iptr->dst.block);
1981 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1982 /* op1 = target JavaVM pc */
1984 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1985 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1986 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1988 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1989 M_MOVGT_IMM(2, REG_ITMP3);
1990 M_MOVEQ_IMM(1, REG_ITMP3);
1992 /* low compare: x=x-1(ifLO) */
1993 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1994 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1996 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1998 /* branch if (x GE 1) */
1999 M_CMP_IMM(REG_ITMP3, 1);
2000 emit_bge(cd, iptr->dst.block);
2003 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2006 branch_target_t *table;
2008 table = iptr->dst.table;
2010 l = iptr->sx.s23.s2.tablelow;
2011 i = iptr->sx.s23.s3.tablehigh;
2013 /* calculate new index (index - low) */
2014 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2016 M_INTMOVE(s1, REG_ITMP1);
2017 } else if (IS_IMM(l)) {
2018 M_SUB_IMM(REG_ITMP1, s1, l);
2020 ICONST(REG_ITMP2, l);
2021 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2024 /* range check (index <= high-low) */
2026 M_COMPARE(REG_ITMP1, i-1);
2027 emit_bugt(cd, table[0].block);
2029 /* build jump table top down and use address of lowest entry */
2034 dseg_add_target(cd, table->block);
2039 /* length of dataseg after last dseg_add_target is used by load */
2040 /* TODO: this loads from data-segment */
2041 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2042 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2045 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2048 lookup_target_t *lookup;
2050 lookup = iptr->dst.lookup;
2052 i = iptr->sx.s23.s2.lookupcount;
2055 MCODECHECK((i<<2)+8);
2056 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2059 M_COMPARE(s1, lookup->value);
2060 emit_beq(cd, lookup->target.block);
2064 /* default branch */
2065 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2069 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2071 #if !defined(ENABLE_SOFTFLOAT)
2072 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2073 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2074 goto ICMD_RETURN_do;
2077 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2079 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2080 M_INTMOVE(s1, REG_RESULT);
2081 goto ICMD_RETURN_do;
2083 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2085 #if !defined(ENABLE_SOFTFLOAT)
2086 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2087 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2088 goto ICMD_RETURN_do;
2091 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2093 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2094 M_LNGMOVE(s1, REG_RESULT_PACKED);
2095 goto ICMD_RETURN_do;
2097 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2099 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2100 M_INTMOVE(s1, REG_RESULT);
2101 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2102 codegen_addpatchref(cd, PATCHER_athrow_areturn,
2103 iptr->sx.s23.s2.uc, 0);
2105 if (opt_showdisassemble)
2108 goto ICMD_RETURN_do;
2110 case ICMD_RETURN: /* ... ==> ... */
2113 #if !defined(NDEBUG)
2114 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2115 emit_verbosecall_exit(jd);
2118 #if defined(ENABLE_THREADS)
2119 /* call monitorexit function */
2121 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2122 /* stack offset for monitor argument */
2126 /* we need to save the proper return value */
2128 switch (iptr->opc) {
2132 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2134 M_STMFD(BITMASK_RESULT, REG_SP);
2139 M_LDR(REG_A0, REG_SP, s1 * 4);
2140 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2141 M_DSEG_BRANCH(disp);
2143 /* we no longer need PV here, no more loading */
2144 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2145 M_RECOMPUTE_PV(s1);*/
2147 switch (iptr->opc) {
2151 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2153 M_LDMFD(BITMASK_RESULT, REG_SP);
2159 /* deallocate stackframe for spilled variables */
2161 if ((cd->stackframesize - savedregs_num) > 0)
2162 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
2164 /* restore callee saved registers + do return */
2166 if (savedregs_bitmask) {
2167 if (!jd->isleafmethod) {
2168 savedregs_bitmask &= ~(1<<REG_LR);
2169 savedregs_bitmask |= (1<<REG_PC);
2171 M_LDMFD(savedregs_bitmask, REG_SP);
2174 /* if LR was not on stack, we need to return manually */
2176 if (jd->isleafmethod)
2177 M_MOV(REG_PC, REG_LR);
2180 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2182 bte = iptr->sx.s23.s3.bte;
2184 goto ICMD_INVOKE_do;
2186 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2187 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2188 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2189 case ICMD_INVOKEINTERFACE:
2191 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2193 um = iptr->sx.s23.s3.um;
2194 md = um->methodref->parseddesc.md;
2197 lm = iptr->sx.s23.s3.fmiref->p.method;
2199 md = lm->parseddesc;
2203 /* copy arguments to registers or stack location */
2205 s3 = md->paramcount;
2207 MCODECHECK((s3 << 1) + 64);
2209 for (s3 = s3 - 1; s3 >= 0; s3--) {
2210 var = VAR(iptr->sx.s23.s2.args[s3]);
2211 d = md->params[s3].regoff;
2213 if (var->flags & PREALLOC) /* argument was precolored? */
2216 /* TODO: document me */
2217 #if !defined(ENABLE_SOFTFLOAT)
2218 if (IS_INT_LNG_TYPE(var->type)) {
2219 #endif /* !defined(ENABLE_SOFTFLOAT) */
2220 if (!md->params[s3].inmemory) {
2221 s1 = emit_load(jd, iptr, var, d);
2223 if (IS_2_WORD_TYPE(var->type))
2229 if (IS_2_WORD_TYPE(var->type)) {
2230 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2231 M_LST(s1, REG_SP, d);
2234 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2235 M_IST(s1, REG_SP, d);
2238 #if !defined(ENABLE_SOFTFLOAT)
2241 if (!md->params[s3].inmemory) {
2242 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2243 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2246 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2247 if (IS_2_WORD_TYPE(var->type))
2248 M_DST(s1, REG_SP, d);
2250 M_FST(s1, REG_SP, d);
2253 #endif /* !defined(ENABLE_SOFTFLOAT) */
2256 switch (iptr->opc) {
2258 disp = dseg_add_functionptr(cd, bte->fp);
2260 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2262 /* generate the actual call */
2264 M_MOV(REG_LR, REG_PC);
2265 M_MOV(REG_PC, REG_PV);
2266 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2269 emit_exception_check(cd, iptr);
2272 case ICMD_INVOKESPECIAL:
2273 emit_nullpointer_check(cd, iptr, REG_A0);
2276 case ICMD_INVOKESTATIC:
2278 disp = dseg_add_unique_address(cd, NULL);
2280 codegen_addpatchref(cd, PATCHER_invokestatic_special,
2283 if (opt_showdisassemble)
2287 disp = dseg_add_address(cd, lm->stubroutine);
2289 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2291 /* generate the actual call */
2293 M_MOV(REG_LR, REG_PC);
2294 M_MOV(REG_PC, REG_PV);
2295 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2299 case ICMD_INVOKEVIRTUAL:
2301 codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
2303 if (opt_showdisassemble)
2309 s1 = OFFSET(vftbl_t, table[0]) +
2310 sizeof(methodptr) * lm->vftblindex;
2312 /* implicit null-pointer check */
2313 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2314 OFFSET(java_objectheader, vftbl));
2315 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
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_INVOKEINTERFACE:
2327 codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
2329 if (opt_showdisassemble)
2336 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2337 sizeof(methodptr*) * lm->class->index;
2338 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2341 /* implicit null-pointer check */
2342 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2343 OFFSET(java_objectheader, vftbl));
2344 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2345 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2347 /* generate the actual call */
2349 M_MOV(REG_LR, REG_PC);
2350 M_MOV(REG_PC, REG_PV);
2351 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2356 /* store return value */
2358 d = md->returntype.type;
2360 #if !defined(__SOFTFP__)
2361 /* TODO: this is only a hack, since we use R0/R1 for float
2362 return! this depends on gcc; it is independent from
2363 our ENABLE_SOFTFLOAT define */
2364 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2365 #if 0 && !defined(NDEBUG)
2366 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2368 /* we cannot use this macro, since it is not defined
2369 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2370 REG_FRESULT, REG_RESULT_TYPED(d)); */
2371 if (IS_2_WORD_TYPE(d)) {
2372 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2373 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2375 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2376 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2381 if (d != TYPE_VOID) {
2382 #if !defined(ENABLE_SOFTFLOAT)
2383 if (IS_INT_LNG_TYPE(d)) {
2384 #endif /* !defined(ENABLE_SOFTFLOAT) */
2385 if (IS_2_WORD_TYPE(d)) {
2386 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2387 M_LNGMOVE(REG_RESULT_PACKED, s1);
2390 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2391 M_INTMOVE(REG_RESULT, s1);
2394 #if !defined(ENABLE_SOFTFLOAT)
2396 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2397 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2399 #endif /* !defined(ENABLE_SOFTFLOAT) */
2401 emit_store_dst(jd, iptr, s1);
2405 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2407 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2408 /* object type cast-check */
2413 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2418 super = iptr->sx.s23.s3.c.cls;
2419 superindex = super->index;
2422 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2423 CODEGEN_CRITICAL_SECTION_NEW;
2425 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2427 /* if class is not resolved, check which code to call */
2429 if (super == NULL) {
2431 emit_label_beq(cd, BRANCH_LABEL_1);
2433 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2434 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2435 iptr->sx.s23.s3.c.ref, disp);
2437 if (opt_showdisassemble)
2440 M_DSEG_LOAD(REG_ITMP2, disp);
2441 disp = dseg_add_s4(cd, ACC_INTERFACE);
2442 M_DSEG_LOAD(REG_ITMP3, disp);
2443 M_TST(REG_ITMP2, REG_ITMP3);
2444 emit_label_beq(cd, BRANCH_LABEL_2);
2447 /* interface checkcast code */
2449 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2450 if ((super == NULL) || !IS_IMM(superindex)) {
2451 disp = dseg_add_unique_s4(cd, superindex);
2453 if (super == NULL) {
2454 codegen_addpatchref(cd,
2455 PATCHER_checkcast_instanceof_interface,
2456 iptr->sx.s23.s3.c.ref, disp);
2458 if (opt_showdisassemble)
2463 emit_label_beq(cd, BRANCH_LABEL_3);
2466 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2467 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2469 /* we put unresolved or non-immediate superindices onto dseg */
2470 if ((super == NULL) || !IS_IMM(superindex)) {
2471 /* disp was computed before we added the patcher */
2472 M_DSEG_LOAD(REG_ITMP2, disp);
2473 M_CMP(REG_ITMP3, REG_ITMP2);
2475 assert(IS_IMM(superindex));
2476 M_CMP_IMM(REG_ITMP3, superindex);
2479 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2481 /* if we loaded the superindex out of the dseg above, we do
2482 things differently here! */
2483 if ((super == NULL) || !IS_IMM(superindex)) {
2485 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_objectheader, vftbl));
2487 /* this assumes something */
2488 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2490 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2491 assert(sizeof(methodptr*) == 4);
2492 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2498 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2499 superindex * sizeof(methodptr*);
2503 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2504 M_TST(REG_ITMP3, REG_ITMP3);
2505 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2508 emit_label_br(cd, BRANCH_LABEL_4);
2510 emit_label(cd, BRANCH_LABEL_3);
2513 /* class checkcast code */
2515 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2516 if (super == NULL) {
2517 emit_label(cd, BRANCH_LABEL_2);
2519 disp = dseg_add_unique_address(cd, NULL);
2521 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2522 iptr->sx.s23.s3.c.ref,
2525 if (opt_showdisassemble)
2529 disp = dseg_add_address(cd, super->vftbl);
2532 emit_label_beq(cd, BRANCH_LABEL_5);
2535 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2536 M_DSEG_LOAD(REG_ITMP3, disp);
2538 CODEGEN_CRITICAL_SECTION_START;
2540 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2541 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2542 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2543 M_DSEG_LOAD(REG_ITMP3, disp);
2544 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2546 CODEGEN_CRITICAL_SECTION_END;
2548 M_CMP(REG_ITMP2, REG_ITMP3);
2549 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2552 emit_label(cd, BRANCH_LABEL_5);
2555 if (super == NULL) {
2556 emit_label(cd, BRANCH_LABEL_1);
2557 emit_label(cd, BRANCH_LABEL_4);
2560 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2563 /* array type cast-check */
2565 s1 = emit_load_s1(jd, iptr, REG_A0);
2566 M_INTMOVE(s1, REG_A0);
2568 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2569 disp = dseg_add_unique_address(cd, NULL);
2571 codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
2572 iptr->sx.s23.s3.c.ref,
2575 if (opt_showdisassemble)
2579 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2581 M_DSEG_LOAD(REG_A1, disp);
2582 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2583 M_DSEG_BRANCH(disp);
2586 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2587 M_RECOMPUTE_PV(disp);
2589 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2590 M_TST(REG_RESULT, REG_RESULT);
2591 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2593 d = codegen_reg_of_dst(jd, iptr, s1);
2597 emit_store_dst(jd, iptr, d);
2600 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2606 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2611 super = iptr->sx.s23.s3.c.cls;
2612 superindex = super->index;
2615 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2616 CODEGEN_CRITICAL_SECTION_NEW;
2618 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2619 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2622 M_MOV(REG_ITMP1, s1);
2626 /* if class is not resolved, check which code to call */
2628 if (super == NULL) {
2632 emit_label_beq(cd, BRANCH_LABEL_1);
2634 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2635 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2636 iptr->sx.s23.s3.c.ref, disp);
2638 if (opt_showdisassemble)
2641 M_DSEG_LOAD(REG_ITMP2, disp);
2642 disp = dseg_add_s4(cd, ACC_INTERFACE);
2643 M_DSEG_LOAD(REG_ITMP3, disp);
2644 M_TST(REG_ITMP2, REG_ITMP3);
2645 emit_label_beq(cd, BRANCH_LABEL_2);
2648 /* interface checkcast code */
2650 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2651 if ((super == NULL) || !IS_IMM(superindex)) {
2652 disp = dseg_add_unique_s4(cd, superindex);
2654 if (super == NULL) {
2655 /* If d == REG_ITMP2, then it's destroyed in check
2660 codegen_addpatchref(cd,
2661 PATCHER_checkcast_instanceof_interface,
2662 iptr->sx.s23.s3.c.ref, disp);
2664 if (opt_showdisassemble)
2670 emit_label_beq(cd, BRANCH_LABEL_3);
2673 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2674 M_LDR_INTERN(REG_ITMP3,
2675 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2677 /* we put unresolved or non-immediate superindices onto dseg
2678 and do things slightly different */
2679 if ((super == NULL) || !IS_IMM(superindex)) {
2680 /* disp was computed before we added the patcher */
2681 M_DSEG_LOAD(REG_ITMP2, disp);
2682 M_CMP(REG_ITMP3, REG_ITMP2);
2684 if (d == REG_ITMP2) {
2691 /* this assumes something */
2692 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2694 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2695 assert(sizeof(methodptr*) == 4);
2696 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2698 if (d == REG_ITMP2) {
2705 assert(IS_IMM(superindex));
2706 M_CMP_IMM(REG_ITMP3, superindex);
2710 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2711 superindex * sizeof(methodptr*);
2715 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2716 M_TST(REG_ITMP3, REG_ITMP3);
2720 emit_label_br(cd, BRANCH_LABEL_4);
2722 emit_label(cd, BRANCH_LABEL_3);
2725 /* class checkcast code */
2727 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2728 if (super == NULL) {
2729 emit_label(cd, BRANCH_LABEL_2);
2731 disp = dseg_add_unique_address(cd, NULL);
2733 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2734 iptr->sx.s23.s3.c.ref,
2737 if (opt_showdisassemble)
2741 disp = dseg_add_address(cd, super->vftbl);
2745 emit_label_beq(cd, BRANCH_LABEL_5);
2748 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2749 M_DSEG_LOAD(REG_ITMP2, disp);
2751 CODEGEN_CRITICAL_SECTION_START;
2753 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2754 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2755 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2757 CODEGEN_CRITICAL_SECTION_END;
2759 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2760 M_CMP(REG_ITMP1, REG_ITMP2);
2761 /* If d == REG_ITMP2, then it's destroyed */
2767 emit_label(cd, BRANCH_LABEL_5);
2770 if (super == NULL) {
2771 emit_label(cd, BRANCH_LABEL_1);
2772 emit_label(cd, BRANCH_LABEL_4);
2777 emit_store_dst(jd, iptr, d);
2780 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2782 /* copy sizes to stack if necessary */
2784 MCODECHECK((iptr->s1.argcount << 1) + 64);
2786 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2788 var = VAR(iptr->sx.s23.s2.args[s1]);
2790 /* copy SAVEDVAR sizes to stack */
2792 if (!(var->flags & PREALLOC)) {
2793 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2794 M_STR(s2, REG_SP, s1 * 4);
2798 /* a0 = dimension count */
2800 assert(IS_IMM(iptr->s1.argcount));
2801 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2803 /* is patcher function set? */
2805 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2806 disp = dseg_add_unique_address(cd, NULL);
2808 codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
2809 iptr->sx.s23.s3.c.ref, disp);
2811 if (opt_showdisassemble)
2815 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2817 /* a1 = arraydescriptor */
2819 M_DSEG_LOAD(REG_A1, disp);
2821 /* a2 = pointer to dimensions = stack pointer */
2823 M_INTMOVE(REG_SP, REG_A2);
2825 /* call builtin_multianewarray here */
2827 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2828 M_DSEG_BRANCH(disp);
2832 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2835 /* check for exception before result assignment */
2837 emit_exception_check(cd, iptr);
2841 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2842 M_INTMOVE(REG_RESULT, d);
2843 emit_store_dst(jd, iptr, d);
2846 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2848 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2849 emit_nullpointer_check(cd, iptr, s1);
2853 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2856 } /* the big switch */
2858 } /* for all instructions */
2860 } /* for all basic blocks */
2862 dseg_createlinenumbertable(cd);
2865 /* generate stubs */
2867 emit_patcher_stubs(jd);
2869 /* everything's ok */
2875 /* codegen_emit_stub_compiler **************************************************
2877 Emits a stub routine which calls the compiler.
2879 *******************************************************************************/
2881 void codegen_emit_stub_compiler(jitdata *jd)
2886 /* get required compiler data */
2891 /* code for the stub */
2893 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2894 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2898 /* codegen_emit_stub_native ****************************************************
2900 Emits a stub routine which calls a native method.
2902 *******************************************************************************/
2904 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2913 s4 disp, funcdisp, s1, s2;
2915 /* get required compiler data */
2921 /* initialize variables */
2924 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2926 /* calculate stackframe size */
2928 cd->stackframesize =
2929 1 + /* return address */
2930 sizeof(stackframeinfo) / SIZEOF_VOID_P + /* stackframeinfo */
2931 sizeof(localref_table) / SIZEOF_VOID_P + /* localref_table */
2932 nmd->memuse; /* stack arguments */
2934 /* align stack to 8-byte */
2936 cd->stackframesize = (cd->stackframesize + 1) & ~1;
2938 /* create method header */
2940 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2941 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
2942 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2943 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2944 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2945 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2946 (void) dseg_addlinenumbertablesize(cd);
2947 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2949 /* generate stub code */
2951 M_STMFD(1<<REG_LR, REG_SP);
2952 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
2954 #if !defined(NDEBUG)
2955 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2956 emit_verbosecall_enter(jd);
2959 /* get function address (this must happen before the stackframeinfo) */
2961 funcdisp = dseg_add_functionptr(cd, f);
2963 #if !defined(WITH_STATIC_CLASSPATH)
2965 codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
2967 if (opt_showdisassemble)
2972 /* Save integer and float argument registers (these are 4
2973 registers, stack is 8-byte aligned). */
2975 M_STMFD(BITMASK_ARGS, REG_SP);
2976 /* TODO: floating point */
2978 /* create native stackframe info */
2980 assert(IS_IMM(4*4 + cd->stackframesize * 4));
2981 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2982 M_MOV(REG_A1, REG_PV);
2983 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize * 4);
2984 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2985 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2986 M_DSEG_BRANCH(disp);
2990 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2993 /* Restore integer and float argument registers (these are 4
2994 registers, stack is 8-byte aligned). */
2996 M_LDMFD(BITMASK_ARGS, REG_SP);
2997 /* TODO: floating point */
2999 /* copy or spill arguments to new locations */
3000 /* ATTENTION: the ARM has only integer argument registers! */
3002 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3003 t = md->paramtypes[i].type;
3005 if (!md->params[i].inmemory) {
3006 s1 = md->params[i].regoff;
3007 s2 = nmd->params[j].regoff;
3009 if (!nmd->params[j].inmemory) {
3010 #if !defined(__ARM_EABI__)
3011 SPLIT_OPEN(t, s2, REG_ITMP1);
3014 if (IS_2_WORD_TYPE(t))
3019 #if !defined(__ARM_EABI__)
3020 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3024 if (IS_2_WORD_TYPE(t))
3025 M_LST(s1, REG_SP, s2);
3027 M_IST(s1, REG_SP, s2);
3031 s1 = md->params[i].regoff + cd->stackframesize * 4;
3032 s2 = nmd->params[j].regoff;
3034 if (IS_2_WORD_TYPE(t)) {
3035 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3036 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3039 M_ILD(REG_ITMP1, REG_SP, s1);
3040 M_IST(REG_ITMP1, REG_SP, s2);
3045 /* put class into second argument register */
3047 if (m->flags & ACC_STATIC) {
3048 disp = dseg_add_address(cd, m->class);
3049 M_DSEG_LOAD(REG_A1, disp);
3052 /* put env into first argument register */
3054 disp = dseg_add_address(cd, _Jv_env);
3055 M_DSEG_LOAD(REG_A0, disp);
3057 /* do the native function call */
3059 M_DSEG_BRANCH(funcdisp);
3062 /* TODO: this is only needed because of the tracer ... do we
3065 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3068 #if !defined(__SOFTFP__)
3069 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3070 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3071 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3072 #if 0 && !defined(NDEBUG)
3073 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3075 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3076 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3077 if (IS_2_WORD_TYPE(md->returntype.type)) {
3078 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3079 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3081 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3082 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3087 #if !defined(NDEBUG)
3088 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3089 emit_verbosecall_exit(jd);
3092 /* remove native stackframe info */
3093 /* TODO: improve this store/load */
3095 M_STMFD(BITMASK_RESULT, REG_SP);
3097 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
3098 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3099 M_DSEG_BRANCH(disp);
3100 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3103 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3104 M_LDMFD(BITMASK_RESULT, REG_SP);
3106 /* finish stub code, but do not yet return to caller */
3108 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
3109 M_LDMFD(1<<REG_LR, REG_SP);
3111 /* check for exception */
3113 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3114 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3116 /* handle exception here */
3118 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3120 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3121 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3122 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3124 /* generate patcher stubs */
3126 emit_patcher_stubs(jd);
3130 /* asm_debug *******************************************************************
3134 *******************************************************************************/
3136 void asm_debug(int a1, int a2, int a3, int a4)
3138 printf("===> i am going to exit after this debugging message!\n");
3139 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3140 vm_abort("leave you now");
3145 * These are local overrides for various environment variables in Emacs.
3146 * Please do not remove this and leave it at the end of the file, where
3147 * Emacs will automagically detect them.
3148 * ---------------------------------------------------------------------
3151 * indent-tabs-mode: t
3155 * vim:noexpandtab:sw=4:ts=4: