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
37 #include "vm/jit/arm/arch.h"
38 #include "vm/jit/arm/codegen.h"
40 #include "mm/memory.h"
42 #include "native/localref.h"
43 #include "native/native.h"
45 #include "threads/lock-common.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
52 #include "vm/jit/abi.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/linenumbertable.h"
59 #include "vm/jit/md.h"
60 #include "vm/jit/methodheader.h"
61 #include "vm/jit/parse.h"
62 #include "vm/jit/patcher-common.h"
63 #include "vm/jit/reg.h"
65 #if defined(ENABLE_LSRA)
66 #include "vm/jit/allocator/lsra.h"
69 #include "vmcore/loader.h"
70 #include "vmcore/options.h"
73 /* codegen_emit ****************************************************************
75 Generates machine code.
77 *******************************************************************************/
79 bool codegen_emit(jitdata *jd)
97 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
98 unresolved_method *um;
99 builtintable_entry *bte;
102 unresolved_field *uf;
106 /* get required compiler data */
113 /* prevent compiler warnings */
121 /* space to save used callee saved registers */
123 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
125 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
126 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
127 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
129 spilledregs_num = rd->memuse;
131 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
132 if (checksync && code_is_synchronized(code))
136 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
138 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
139 only in native stubs. */
140 /* align stack to 8-byte */
142 cd->stackframesize = (cd->stackframesize + 4) & ~4;
144 /* SECTION: Method Header */
145 /* create method header */
147 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
148 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
150 code->synchronizedoffset = rd->memuse * 8;
152 /* REMOVEME: We still need it for exception handling in assembler. */
154 if (code_is_leafmethod(code))
155 (void) dseg_add_unique_s4(cd, 1);
157 (void) dseg_add_unique_s4(cd, 0);
159 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
160 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
162 /* save return address and used callee saved registers */
164 savedregs_bitmask = 0;
166 if (!code_is_leafmethod(code))
167 savedregs_bitmask = (1<<REG_LR);
169 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
170 savedregs_bitmask |= (1<<(rd->savintregs[i]));
173 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
174 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
175 /* TODO: floating-point */
179 if (savedregs_bitmask)
180 M_STMFD(savedregs_bitmask, REG_SP);
182 /* create additional stack frame for spilled variables (if necessary) */
184 if ((cd->stackframesize / 4 - savedregs_num) > 0)
185 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
187 /* take arguments out of register or stack frame */
190 for (i = 0, len = 0; i < md->paramcount; i++) {
191 s1 = md->params[i].regoff;
192 t = md->paramtypes[i].type;
194 varindex = jd->local_map[len * 5 + t];
196 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
198 if (varindex == UNUSED)
203 /* ATTENTION: we use interger registers for all arguments (even float) */
204 #if !defined(ENABLE_SOFTFLOAT)
205 if (IS_INT_LNG_TYPE(t)) {
207 if (!md->params[i].inmemory) {
208 if (!(var->flags & INMEMORY)) {
209 if (IS_2_WORD_TYPE(t))
210 M_LNGMOVE(s1, var->vv.regoff);
212 M_INTMOVE(s1, var->vv.regoff);
215 if (IS_2_WORD_TYPE(t))
216 M_LST(s1, REG_SP, var->vv.regoff);
218 M_IST(s1, REG_SP, var->vv.regoff);
221 else { /* stack arguments */
222 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
223 if (IS_2_WORD_TYPE(t))
224 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
226 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
228 else { /* stack arg -> spilled */
229 /* Reuse Memory Position on Caller Stack */
230 var->vv.regoff = cd->stackframesize + s1;
233 #if !defined(ENABLE_SOFTFLOAT)
236 if (!md->params[i].inmemory) {
237 if (!(var->flags & INMEMORY)) {
238 if (IS_2_WORD_TYPE(t))
239 M_CAST_L2D(s1, var->vv.regoff);
241 M_CAST_I2F(s1, var->vv.regoff);
244 if (IS_2_WORD_TYPE(t))
245 M_LST(s1, REG_SP, var->vv.regoff);
247 M_IST(s1, REG_SP, var->vv.regoff);
251 if (!(var->flags & INMEMORY)) {
252 if (IS_2_WORD_TYPE(t))
253 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
255 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
258 /* Reuse Memory Position on Caller Stack */
259 var->vv.regoff = cd->stackframesize + s1;
263 #endif /* !defined(ENABLE_SOFTFLOAT) */
266 #if defined(ENABLE_THREADS)
267 /* call monitorenter function */
269 if (checksync && code_is_synchronized(code)) {
270 /* stack offset for monitor argument */
274 # if !defined(NDEBUG)
275 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
276 M_STMFD(BITMASK_ARGS, REG_SP);
281 /* get the correct lock object */
283 if (m->flags & ACC_STATIC) {
284 disp = dseg_add_address(cd, &m->class->object.header);
285 M_DSEG_LOAD(REG_A0, disp);
288 emit_nullpointer_check_force(cd, iptr, REG_A0);
291 M_STR(REG_A0, REG_SP, s1);
292 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
294 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
297 # if !defined(NDEBUG)
298 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
299 M_LDMFD(BITMASK_ARGS, REG_SP);
305 /* call trace function */
307 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
308 emit_verbosecall_enter(jd);
311 /* end of header generation */
313 /* create replacement points */
314 REPLACEMENT_POINTS_INIT(cd, jd);
316 /* SECTION: ICMD Code Generation */
317 /* for all basic blocks */
319 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
321 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
323 /* is this basic block reached? */
325 if (bptr->flags < BBREACHED)
328 /* branch resolving */
330 codegen_resolve_branchrefs(cd, bptr);
332 /* handle replacement points */
333 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
335 /* copy interface registers to their destination */
341 #if defined(ENABLE_LSRA)
345 var = VAR(bptr->invars[len]);
346 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
347 if (!(var->flags & INMEMORY))
351 M_INTMOVE(REG_ITMP1, d);
352 emit_store(jd, NULL, var, d);
359 var = VAR(bptr->invars[len]);
361 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
362 d = codegen_reg_of_var(0, var, REG_ITMP1);
363 M_INTMOVE(REG_ITMP1, d);
364 emit_store(jd, NULL, var, d);
367 assert((var->flags & INOUT));
370 #if defined(ENABLE_LSRA)
374 /* for all instructions */
377 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
379 /* add line number */
380 if (iptr->line != currentline) {
381 linenumbertable_list_entry_add(cd, iptr->line);
382 currentline = iptr->line;
385 MCODECHECK(64); /* an instruction usually needs < 64 words */
390 case ICMD_NOP: /* ... ==> ... */
391 case ICMD_POP: /* ..., value ==> ... */
392 case ICMD_POP2: /* ..., value, value ==> ... */
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 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
411 iptr->sx.val.c.ref, disp);
413 M_DSEG_LOAD(d, disp);
416 ICONST(d, (u4) iptr->sx.val.anyptr);
418 emit_store_dst(jd, iptr, d);
421 case ICMD_LCONST: /* ... ==> ..., constant */
423 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
424 LCONST(d, iptr->sx.val.l);
425 emit_store_dst(jd, iptr, d);
428 case ICMD_FCONST: /* ... ==> ..., constant */
430 #if defined(ENABLE_SOFTFLOAT)
431 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
432 ICONST(d, iptr->sx.val.i);
433 emit_store_dst(jd, iptr, d);
435 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
436 FCONST(d, iptr->sx.val.f);
437 emit_store_dst(jd, iptr, d);
441 case ICMD_DCONST: /* ... ==> ..., constant */
443 #if defined(ENABLE_SOFTFLOAT)
444 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
445 LCONST(d, iptr->sx.val.l);
446 emit_store_dst(jd, iptr, d);
448 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
449 DCONST(d, iptr->sx.val.d);
450 emit_store_dst(jd, iptr, d);
455 /* load/store/copy/move operations ************************************/
457 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
458 case ICMD_ALOAD: /* op1 = local variable */
462 case ICMD_ISTORE: /* ..., value ==> ... */
474 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
479 /* integer operations *************************************************/
481 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
483 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
484 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
485 M_MOV(d, REG_LSL(s1, 24));
486 M_MOV(d, REG_ASR(d, 24));
487 emit_store_dst(jd, iptr, d);
490 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
492 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
493 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
494 M_MOV(d, REG_LSL(s1, 16));
495 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
496 emit_store_dst(jd, iptr, d);
499 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
501 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
502 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
503 M_MOV(d, REG_LSL(s1, 16));
504 M_MOV(d, REG_ASR(d, 16));
505 emit_store_dst(jd, iptr, d);
508 case ICMD_I2L: /* ..., value ==> ..., value */
510 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
511 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
512 M_INTMOVE(s1, GET_LOW_REG(d));
513 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
514 emit_store_dst(jd, iptr, d);
517 case ICMD_L2I: /* ..., value ==> ..., value */
519 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
520 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
522 emit_store_dst(jd, iptr, d);
525 case ICMD_INEG: /* ..., value ==> ..., - value */
527 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
528 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
530 emit_store_dst(jd, iptr, d);
533 case ICMD_LNEG: /* ..., value ==> ..., - value */
535 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
536 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
537 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
538 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
539 emit_store_dst(jd, iptr, d);
542 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
544 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
545 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
546 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
548 emit_store_dst(jd, iptr, d);
551 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
553 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
554 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
555 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
556 M_ADD_S(GET_LOW_REG(d), s1, s2);
557 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
558 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
559 M_ADC(GET_HIGH_REG(d), s1, s2);
560 emit_store_dst(jd, iptr, d);
566 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
567 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
569 if (IS_IMM(iptr->sx.val.i)) {
570 M_ADD_IMM(d, s1, iptr->sx.val.i);
571 } else if (IS_IMM(-iptr->sx.val.i)) {
572 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
574 ICONST(REG_ITMP3, iptr->sx.val.i);
575 M_ADD(d, s1, REG_ITMP3);
578 emit_store_dst(jd, iptr, d);
581 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
582 /* sx.val.l = constant */
584 s3 = iptr->sx.val.l & 0xffffffff;
585 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
586 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
588 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
590 ICONST(REG_ITMP3, s3);
591 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
593 s3 = iptr->sx.val.l >> 32;
594 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
596 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
598 ICONST(REG_ITMP3, s3);
599 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
601 emit_store_dst(jd, iptr, d);
604 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
606 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
607 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
608 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
610 emit_store_dst(jd, iptr, d);
613 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
615 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
616 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
617 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
618 M_SUB_S(GET_LOW_REG(d), s1, s2);
619 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
620 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
621 M_SBC(GET_HIGH_REG(d), s1, s2);
622 emit_store_dst(jd, iptr, d);
625 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
626 /* sx.val.i = constant */
628 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
629 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
630 if (IS_IMM(iptr->sx.val.i))
631 M_SUB_IMM(d, s1, iptr->sx.val.i);
633 ICONST(REG_ITMP3, iptr->sx.val.i);
634 M_SUB(d, s1, REG_ITMP3);
636 emit_store_dst(jd, iptr, d);
639 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
640 /* sx.val.l = constant */
642 s3 = iptr->sx.val.l & 0xffffffff;
643 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
644 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
646 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
648 ICONST(REG_ITMP3, s3);
649 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
651 s3 = iptr->sx.val.l >> 32;
652 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
654 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
656 ICONST(REG_ITMP3, s3);
657 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
659 emit_store_dst(jd, iptr, d);
662 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
664 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
665 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
666 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
668 emit_store_dst(jd, iptr, d);
671 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
672 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
674 s1 = emit_load_s1(jd, iptr, REG_A0);
675 s2 = emit_load_s2(jd, iptr, REG_A1);
676 emit_arithmetic_check(cd, iptr, s2);
678 /* move arguments into argument registers */
679 M_INTMOVE(s1, REG_A0);
680 M_INTMOVE(s2, REG_A1);
682 /* call builtin function */
683 bte = iptr->sx.s23.s3.bte;
684 disp = dseg_add_functionptr(cd, bte->fp);
688 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
691 /* move result into destination register */
692 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
693 M_INTMOVE(REG_RESULT, d);
694 emit_store_dst(jd, iptr, d);
697 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
698 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
700 /* move arguments into argument registers */
702 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
703 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
704 /* XXX TODO: only do this if arithmetic check is really done! */
705 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
706 emit_arithmetic_check(cd, iptr, REG_ITMP3);
708 M_LNGMOVE(s1, REG_A0_A1_PACKED);
709 M_LNGMOVE(s2, REG_A2_A3_PACKED);
711 /* call builtin function */
712 bte = iptr->sx.s23.s3.bte;
713 disp = dseg_add_functionptr(cd, bte->fp);
717 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
720 /* move result into destination register */
721 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
722 M_LNGMOVE(REG_RESULT_PACKED, d);
723 emit_store_dst(jd, iptr, d);
726 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
727 /* sx.val.i = constant */
729 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
730 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
731 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
732 emit_store_dst(jd, iptr, d);
735 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
736 /* sx.val.i = constant */
738 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
739 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
740 /* this rounds towards 0 as java likes it */
741 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
742 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
743 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
744 /* this rounds towards nearest, not java style */
745 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
746 M_ADCMI_IMM(d, d, 0);*/
747 emit_store_dst(jd, iptr, d);
750 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
751 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
753 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
754 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
755 M_MOV_S(REG_ITMP1, s1);
756 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
757 if (IS_IMM(iptr->sx.val.i))
758 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
760 ICONST(REG_ITMP3, iptr->sx.val.i);
761 M_AND(REG_ITMP1, REG_ITMP3, d);
763 M_RSBMI_IMM(d, d, 0);
764 emit_store_dst(jd, iptr, d);
767 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
769 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
770 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
771 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
772 M_AND_IMM(s2, 0x1f, REG_ITMP2);
773 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
774 emit_store_dst(jd, iptr, d);
777 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
779 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
780 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
781 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
782 M_AND_IMM(s2, 0x1f, REG_ITMP2);
783 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
784 emit_store_dst(jd, iptr, d);
787 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
789 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
790 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
791 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
792 M_AND_IMM(s2, 0x1f, REG_ITMP2);
793 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
794 emit_store_dst(jd, iptr, d);
797 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
798 /* sx.val.i = constant */
800 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
801 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
802 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
803 emit_store_dst(jd, iptr, d);
806 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
807 /* sx.val.i = constant */
809 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
810 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
811 /* we need to check for zero here because arm interprets it as SHR by 32 */
812 if ((iptr->sx.val.i & 0x1f) == 0) {
815 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
817 emit_store_dst(jd, iptr, d);
820 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
821 /* sx.val.i = constant */
823 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
824 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
825 /* we need to check for zero here because arm interprets it as SHR by 32 */
826 if ((iptr->sx.val.i & 0x1f) == 0)
829 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
830 emit_store_dst(jd, iptr, d);
833 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
835 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
836 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
837 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
839 emit_store_dst(jd, iptr, d);
842 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
844 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
845 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
846 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
847 M_AND(s1, s2, GET_LOW_REG(d));
848 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
849 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
850 M_AND(s1, s2, GET_HIGH_REG(d));
851 emit_store_dst(jd, iptr, d);
854 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
856 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
857 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
858 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
860 emit_store_dst(jd, iptr, d);
863 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
865 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
866 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
867 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
868 M_ORR(s1, s2, GET_LOW_REG(d));
869 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
870 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
871 M_ORR(s1, s2, GET_HIGH_REG(d));
872 emit_store_dst(jd, iptr, d);
875 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
877 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
878 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
879 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
881 emit_store_dst(jd, iptr, d);
884 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
886 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
887 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
888 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
889 M_EOR(s1, s2, GET_LOW_REG(d));
890 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
891 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
892 M_EOR(s1, s2, GET_HIGH_REG(d));
893 emit_store_dst(jd, iptr, d);
897 /* floating operations ************************************************/
899 #if !defined(ENABLE_SOFTFLOAT)
901 case ICMD_FNEG: /* ..., value ==> ..., - value */
903 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
904 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
906 emit_store_dst(jd, iptr, d);
909 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
911 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
912 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
913 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
915 emit_store_dst(jd, iptr, d);
918 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
920 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
921 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
922 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
924 emit_store_dst(jd, iptr, d);
927 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
929 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
930 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
931 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
933 emit_store_dst(jd, iptr, d);
936 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
937 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
938 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
939 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
941 emit_store_dst(jd, iptr, d);
944 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
948 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
950 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
951 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
952 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
954 emit_store_dst(jd, iptr, d);
958 case ICMD_DNEG: /* ..., value ==> ..., - value */
960 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
961 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
963 emit_store_dst(jd, iptr, d);
966 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
968 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
969 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
970 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
972 emit_store_dst(jd, iptr, d);
975 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
977 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
978 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
979 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
981 emit_store_dst(jd, iptr, d);
984 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
986 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
987 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
988 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
990 emit_store_dst(jd, iptr, d);
993 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
995 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
996 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
997 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
999 emit_store_dst(jd, iptr, d);
1002 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1006 case ICMD_DREM: /* ..., 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);
1016 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1018 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1019 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1021 emit_store_dst(jd, iptr, d);
1024 case ICMD_I2D: /* ..., value ==> ..., (double) 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_F2I: /* ..., value ==> ..., (int) value */
1034 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1035 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1036 /* this uses round towards zero, as Java likes it */
1038 #if !defined(__VFP_FP__)
1039 /* this checks for NaN; to return zero as Java likes it */
1043 emit_store_dst(jd, iptr, d);
1046 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1048 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1049 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1050 /* this uses round towards zero, as Java likes it */
1052 #if !defined(__VFP_FP__)
1053 /* this checks for NaN; to return zero as Java likes it */
1057 emit_store_dst(jd, iptr, d);
1060 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1062 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1063 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1065 emit_store_dst(jd, iptr, d);
1068 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1070 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1071 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1073 emit_store_dst(jd, iptr, d);
1076 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1078 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1079 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1080 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1083 #if defined(__VFP_FP__)
1084 M_FMSTAT; /* on VFP we need to transfer the flags */
1086 M_SUBGT_IMM(d, d, 1);
1087 M_ADDLT_IMM(d, d, 1);
1088 emit_store_dst(jd, iptr, d);
1091 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1093 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1094 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1095 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1098 #if defined(__VFP_FP__)
1099 M_FMSTAT; /* on VFP we need to transfer the flags */
1101 M_SUBGT_IMM(d, d, 1);
1102 M_ADDLT_IMM(d, d, 1);
1103 emit_store_dst(jd, iptr, d);
1106 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1108 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1109 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1110 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1113 #if defined(__VFP_FP__)
1114 M_FMSTAT; /* on VFP we need to transfer the flags */
1116 M_SUBLT_IMM(d, d, 1);
1117 M_ADDGT_IMM(d, d, 1);
1118 emit_store_dst(jd, iptr, d);
1121 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1123 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1124 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1125 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1128 #if defined(__VFP_FP__)
1129 M_FMSTAT; /* on VFP we need to transfer the flags */
1131 M_SUBLT_IMM(d, d, 1);
1132 M_ADDGT_IMM(d, d, 1);
1133 emit_store_dst(jd, iptr, d);
1136 #endif /* !defined(ENABLE_SOFTFLOAT) */
1139 /* memory operations **************************************************/
1141 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1143 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1144 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1145 /* implicit null-pointer check */
1146 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1147 emit_store_dst(jd, iptr, d);
1150 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1152 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1153 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1154 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1155 /* implicit null-pointer check */
1156 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1157 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1158 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1159 emit_store_dst(jd, iptr, d);
1162 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1164 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1165 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1166 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1167 /* implicit null-pointer check */
1168 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1169 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1170 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1171 emit_store_dst(jd, iptr, d);
1174 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1176 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1177 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1178 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1179 /* implicit null-pointer check */
1180 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1181 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1182 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1183 emit_store_dst(jd, iptr, d);
1186 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1188 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1189 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1190 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1191 /* implicit null-pointer check */
1192 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1193 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1194 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1195 emit_store_dst(jd, iptr, d);
1198 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1200 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1201 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1202 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1203 /* implicit null-pointer check */
1204 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1205 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1206 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1207 emit_store_dst(jd, iptr, d);
1210 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1212 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1213 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1214 /* implicit null-pointer check */
1215 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1216 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1217 #if !defined(ENABLE_SOFTFLOAT)
1218 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1219 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1221 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1222 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1224 emit_store_dst(jd, iptr, d);
1227 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1229 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1230 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1231 /* implicit null-pointer check */
1232 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1233 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1234 #if !defined(ENABLE_SOFTFLOAT)
1235 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1236 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1238 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1239 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1241 emit_store_dst(jd, iptr, d);
1244 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1246 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1247 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1248 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1249 /* implicit null-pointer check */
1250 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1251 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1252 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1253 emit_store_dst(jd, iptr, d);
1256 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1258 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1259 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1260 /* implicit null-pointer check */
1261 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1262 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1263 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1264 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1267 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1269 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1270 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1271 /* implicit null-pointer check */
1272 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1273 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1274 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1275 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1278 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1280 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1281 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1282 /* implicit null-pointer check */
1283 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1284 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1285 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1286 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1289 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1291 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1292 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1293 /* implicit null-pointer check */
1294 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1295 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1296 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1297 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1300 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1302 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1303 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1304 /* implicit null-pointer check */
1305 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1306 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1307 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1308 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1311 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1313 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1314 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1315 /* implicit null-pointer check */
1316 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1317 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1318 #if !defined(ENABLE_SOFTFLOAT)
1319 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1320 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1322 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1323 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1327 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1329 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1330 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1331 /* implicit null-pointer check */
1332 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1333 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1334 #if !defined(ENABLE_SOFTFLOAT)
1335 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1336 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1338 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1339 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1343 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1345 s1 = emit_load_s1(jd, iptr, REG_A0);
1346 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1347 s3 = emit_load_s3(jd, iptr, REG_A1);
1349 /* implicit null-pointer check */
1350 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1352 /* move arguments to argument registers */
1353 M_INTMOVE(s1, REG_A0);
1354 M_INTMOVE(s3, REG_A1);
1356 /* call builtin function */
1357 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1358 M_DSEG_BRANCH(disp);
1361 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1364 /* check resturn value of builtin */
1365 emit_arraystore_check(cd, iptr);
1367 /* finally store address into array */
1368 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1369 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1370 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1371 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1372 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1375 case ICMD_GETSTATIC: /* ... ==> ..., value */
1377 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1378 uf = iptr->sx.s23.s3.uf;
1379 fieldtype = uf->fieldref->parseddesc.fd->type;
1380 disp = dseg_add_unique_address(cd, NULL);
1382 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1385 fi = iptr->sx.s23.s3.fmiref->p.field;
1386 fieldtype = fi->type;
1387 disp = dseg_add_address(cd, fi->value);
1389 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1390 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1395 M_DSEG_LOAD(REG_ITMP3, disp);
1396 switch (fieldtype) {
1398 #if defined(ENABLE_SOFTFLOAT)
1402 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1403 M_ILD_INTERN(d, REG_ITMP3, 0);
1406 #if defined(ENABLE_SOFTFLOAT)
1409 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1410 M_LLD_INTERN(d, REG_ITMP3, 0);
1412 #if !defined(ENABLE_SOFTFLOAT)
1414 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1415 M_FLD_INTERN(d, REG_ITMP3, 0);
1418 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1419 M_DLD_INTERN(d, REG_ITMP3, 0);
1425 emit_store_dst(jd, iptr, d);
1428 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1430 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1431 uf = iptr->sx.s23.s3.uf;
1432 fieldtype = uf->fieldref->parseddesc.fd->type;
1433 disp = dseg_add_unique_address(cd, NULL);
1435 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1438 fi = iptr->sx.s23.s3.fmiref->p.field;
1439 fieldtype = fi->type;
1440 disp = dseg_add_address(cd, fi->value);
1442 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1443 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1448 M_DSEG_LOAD(REG_ITMP3, disp);
1449 switch (fieldtype) {
1451 #if defined(ENABLE_SOFTFLOAT)
1455 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1456 M_IST_INTERN(s1, REG_ITMP3, 0);
1459 #if defined(ENABLE_SOFTFLOAT)
1462 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1463 M_LST_INTERN(s1, REG_ITMP3, 0);
1465 #if !defined(ENABLE_SOFTFLOAT)
1467 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1468 M_FST_INTERN(s1, REG_ITMP3, 0);
1471 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1472 M_DST_INTERN(s1, REG_ITMP3, 0);
1480 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1482 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1483 emit_nullpointer_check(cd, iptr, s1);
1486 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1487 uf = iptr->sx.s23.s3.uf;
1488 fieldtype = uf->fieldref->parseddesc.fd->type;
1492 fi = iptr->sx.s23.s3.fmiref->p.field;
1493 fieldtype = fi->type;
1497 #if !defined(ENABLE_SOFTFLOAT)
1498 /* HACK: softnull checks on floats */
1499 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1500 emit_nullpointer_check_force(cd, iptr, s1);
1503 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1505 uf = iptr->sx.s23.s3.uf;
1507 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1510 switch (fieldtype) {
1512 #if defined(ENABLE_SOFTFLOAT)
1516 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1520 #if defined(ENABLE_SOFTFLOAT)
1523 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1526 #if !defined(ENABLE_SOFTFLOAT)
1528 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1532 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1539 emit_store_dst(jd, iptr, d);
1542 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1544 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1545 emit_nullpointer_check(cd, iptr, s1);
1547 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1548 uf = iptr->sx.s23.s3.uf;
1549 fieldtype = uf->fieldref->parseddesc.fd->type;
1553 fi = iptr->sx.s23.s3.fmiref->p.field;
1554 fieldtype = fi->type;
1558 #if !defined(ENABLE_SOFTFLOAT)
1559 /* HACK: softnull checks on floats */
1560 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1561 emit_nullpointer_check_force(cd, iptr, s1);
1564 switch (fieldtype) {
1566 #if defined(ENABLE_SOFTFLOAT)
1570 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1572 #if defined(ENABLE_SOFTFLOAT)
1573 case TYPE_DBL: /* fall through */
1576 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1578 #if !defined(ENABLE_SOFTFLOAT)
1581 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1588 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1590 uf = iptr->sx.s23.s3.uf;
1592 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1595 switch (fieldtype) {
1597 #if defined(ENABLE_SOFTFLOAT)
1601 M_IST(s2, s1, disp);
1604 #if defined(ENABLE_SOFTFLOAT)
1607 M_LST(s2, s1, disp);
1609 #if !defined(ENABLE_SOFTFLOAT)
1611 M_FST(s2, s1, disp);
1614 M_DST(s2, s1, disp);
1623 /* branch operations **************************************************/
1625 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1627 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1628 M_INTMOVE(s1, REG_ITMP1_XPTR);
1629 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1630 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1631 iptr->sx.s23.s2.uc, 0);
1633 disp = dseg_add_functionptr(cd, asm_handle_exception);
1634 M_DSEG_LOAD(REG_ITMP3, disp);
1635 M_MOV(REG_ITMP2_XPC, REG_PC);
1636 M_MOV(REG_PC, REG_ITMP3);
1637 M_NOP; /* nop ensures that XPC is less than the end */
1638 /* of basic block */
1641 case ICMD_GOTO: /* ... ==> ... */
1644 emit_br(cd, iptr->dst.block);
1647 case ICMD_JSR: /* ... ==> ... */
1649 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1652 case ICMD_IFNULL: /* ..., value ==> ... */
1653 case ICMD_IFNONNULL:
1655 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1657 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1660 case ICMD_IFLT: /* ..., value ==> ... */
1661 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1667 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1668 M_COMPARE(s1, iptr->sx.val.i);
1669 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1672 case ICMD_IF_LEQ: /* ..., value ==> ... */
1674 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1675 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1676 if (iptr->sx.val.l == 0) {
1677 M_ORR_S(s1, s2, REG_ITMP3);
1680 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1681 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1682 M_CMP(s1, REG_ITMP3);*/
1683 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1684 M_CMPEQ(s2, REG_ITMP3);
1686 emit_beq(cd, iptr->dst.block);
1689 case ICMD_IF_LLT: /* ..., value ==> ... */
1691 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1692 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1693 if (iptr->sx.val.l == 0) {
1694 /* if high word is less than zero, the whole long is too */
1696 emit_blt(cd, iptr->dst.block);
1699 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1700 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1701 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1702 M_CMP(s1, REG_ITMP3);*/
1703 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1704 M_MOVGT_IMM(2, REG_ITMP1);
1705 M_MOVEQ_IMM(1, REG_ITMP1);
1707 /* low compare: x=x-1(ifLO) */
1708 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1709 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1710 M_CMP(s2, REG_ITMP3);*/
1711 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1713 /* branch if (x LT 1) */
1714 M_CMP_IMM(REG_ITMP1, 1);
1715 emit_blt(cd, iptr->dst.block);
1719 case ICMD_IF_LLE: /* ..., value ==> ... */
1721 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1722 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1723 if (iptr->sx.val.l == 0) {
1724 /* if high word is less than zero, the whole long is too */
1726 emit_blt(cd, iptr->dst.block);
1728 /* ... otherwise the low word has to be zero (tricky!) */
1730 emit_beq(cd, iptr->dst.block);
1733 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1734 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1735 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1736 M_CMP(s1, REG_ITMP3);*/
1737 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1738 M_MOVGT_IMM(2, REG_ITMP1);
1739 M_MOVEQ_IMM(1, REG_ITMP1);
1741 /* low compare: x=x+1(ifHI) */
1742 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1743 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1744 M_CMP(s2, REG_ITMP3);*/
1745 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1747 /* branch if (x LE 1) */
1748 M_CMP_IMM(REG_ITMP1, 1);
1749 emit_ble(cd, iptr->dst.block);
1753 case ICMD_IF_LGE: /* ..., value ==> ... */
1755 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1756 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1757 if (iptr->sx.val.l == 0) {
1758 /* if high word is greater or equal zero, the whole long is too */
1760 emit_bge(cd, iptr->dst.block);
1763 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1764 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1765 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1766 M_CMP(s1, REG_ITMP3);*/
1767 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1768 M_MOVGT_IMM(2, REG_ITMP1);
1769 M_MOVEQ_IMM(1, REG_ITMP1);
1771 /* low compare: x=x-1(ifLO) */
1772 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1773 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1774 M_CMP(s2, REG_ITMP3);*/
1775 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1777 /* branch if (x GE 1) */
1778 M_CMP_IMM(REG_ITMP1, 1);
1779 emit_bge(cd, iptr->dst.block);
1783 case ICMD_IF_LGT: /* ..., value ==> ... */
1785 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1786 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1788 if (iptr->sx.val.l == 0) {
1789 /* if high word is greater than zero, the whole long is too */
1792 codegen_add_branch_ref(cd, iptr->dst.block);
1794 /* ... or high was zero and low is non zero (tricky!) */
1795 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1796 M_MOVLT_IMM(1, REG_ITMP3);
1797 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1799 codegen_add_branch_ref(cd, iptr->dst.block);
1803 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1804 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1805 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1806 M_CMP(s1, REG_ITMP3);*/
1807 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1808 M_MOVGT_IMM(2, REG_ITMP1);
1809 M_MOVEQ_IMM(1, REG_ITMP1);
1811 /* low compare: x=x+1(ifHI) */
1812 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1813 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1814 M_CMP(s2, REG_ITMP3);*/
1815 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1817 /* branch if (x GT 1) */
1818 M_CMP_IMM(REG_ITMP1, 1);
1819 emit_bgt(cd, iptr->dst.block);
1825 case ICMD_IF_LNE: /* ..., value ==> ... */
1827 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1828 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1829 if (iptr->sx.val.l == 0) {
1830 M_ORR_S(s1, s2, REG_ITMP3);
1833 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1834 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1835 M_CMP(s1, REG_ITMP3);*/
1836 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1837 M_CMPEQ(s2, REG_ITMP3);
1839 emit_bne(cd, iptr->dst.block);
1842 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1843 case ICMD_IF_ICMPNE:
1844 case ICMD_IF_ICMPLT:
1845 case ICMD_IF_ICMPLE:
1846 case ICMD_IF_ICMPGT:
1847 case ICMD_IF_ICMPGE:
1849 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1850 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1852 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1855 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1856 case ICMD_IF_ACMPNE:
1858 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1859 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1861 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1864 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1865 /* op1 = target JavaVM pc */
1867 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1868 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1871 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1872 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1875 emit_beq(cd, iptr->dst.block);
1878 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1879 /* op1 = target JavaVM pc */
1881 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1882 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1885 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1886 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1889 emit_bne(cd, iptr->dst.block);
1892 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1893 /* op1 = target JavaVM pc */
1895 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1896 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1897 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1899 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1900 M_MOVGT_IMM(2, REG_ITMP3);
1901 M_MOVEQ_IMM(1, REG_ITMP3);
1903 /* low compare: x=x-1(ifLO) */
1904 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1905 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1907 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1909 /* branch if (x LT 1) */
1910 M_CMP_IMM(REG_ITMP3, 1);
1911 emit_blt(cd, iptr->dst.block);
1914 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1915 /* op1 = target JavaVM pc */
1917 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1918 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1919 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1921 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1922 M_MOVGT_IMM(2, REG_ITMP3);
1923 M_MOVEQ_IMM(1, REG_ITMP3);
1925 /* low compare: x=x-1(ifLO) */
1926 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1927 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1929 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1931 /* branch if (x LE 1) */
1932 M_CMP_IMM(REG_ITMP3, 1);
1933 emit_ble(cd, iptr->dst.block);
1936 case ICMD_IF_LCMPGT: /* ..., 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_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1953 /* branch if (x GT 1) */
1954 M_CMP_IMM(REG_ITMP3, 1);
1955 emit_bgt(cd, iptr->dst.block);
1958 case ICMD_IF_LCMPGE: /* ..., 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_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1975 /* branch if (x GE 1) */
1976 M_CMP_IMM(REG_ITMP3, 1);
1977 emit_bge(cd, iptr->dst.block);
1980 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1983 branch_target_t *table;
1985 table = iptr->dst.table;
1987 l = iptr->sx.s23.s2.tablelow;
1988 i = iptr->sx.s23.s3.tablehigh;
1990 /* calculate new index (index - low) */
1991 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1993 M_INTMOVE(s1, REG_ITMP1);
1994 } else if (IS_IMM(l)) {
1995 M_SUB_IMM(REG_ITMP1, s1, l);
1997 ICONST(REG_ITMP2, l);
1998 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2001 /* range check (index <= high-low) */
2003 M_COMPARE(REG_ITMP1, i-1);
2004 emit_bugt(cd, table[0].block);
2006 /* build jump table top down and use address of lowest entry */
2011 dseg_add_target(cd, table->block);
2016 /* length of dataseg after last dseg_add_target is used by load */
2017 /* TODO: this loads from data-segment */
2018 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2019 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2022 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2025 lookup_target_t *lookup;
2027 lookup = iptr->dst.lookup;
2029 i = iptr->sx.s23.s2.lookupcount;
2032 MCODECHECK((i<<2)+8);
2033 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2036 M_COMPARE(s1, lookup->value);
2037 emit_beq(cd, lookup->target.block);
2041 /* default branch */
2042 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2046 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2048 #if !defined(ENABLE_SOFTFLOAT)
2049 REPLACEMENT_POINT_RETURN(cd, iptr);
2050 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2051 M_CAST_F2I(s1, REG_RESULT);
2052 goto ICMD_RETURN_do;
2055 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2057 REPLACEMENT_POINT_RETURN(cd, iptr);
2058 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2059 M_INTMOVE(s1, REG_RESULT);
2060 goto ICMD_RETURN_do;
2062 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2064 #if !defined(ENABLE_SOFTFLOAT)
2065 REPLACEMENT_POINT_RETURN(cd, iptr);
2066 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2067 M_CAST_D2L(s1, REG_RESULT_PACKED);
2068 goto ICMD_RETURN_do;
2071 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2073 REPLACEMENT_POINT_RETURN(cd, iptr);
2074 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2075 M_LNGMOVE(s1, REG_RESULT_PACKED);
2076 goto ICMD_RETURN_do;
2078 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2080 REPLACEMENT_POINT_RETURN(cd, iptr);
2081 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2082 M_INTMOVE(s1, REG_RESULT);
2083 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2084 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2085 iptr->sx.s23.s2.uc, 0);
2087 goto ICMD_RETURN_do;
2089 case ICMD_RETURN: /* ... ==> ... */
2091 REPLACEMENT_POINT_RETURN(cd, iptr);
2094 #if !defined(NDEBUG)
2095 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2096 emit_verbosecall_exit(jd);
2099 #if defined(ENABLE_THREADS)
2100 /* call monitorexit function */
2102 if (checksync && code_is_synchronized(code)) {
2103 /* stack offset for monitor argument */
2105 s1 = rd->memuse * 8;
2107 /* we need to save the proper return value */
2109 switch (iptr->opc) {
2113 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2115 M_STMFD(BITMASK_RESULT, REG_SP);
2120 M_LDR(REG_A0, REG_SP, s1);
2121 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2122 M_DSEG_BRANCH(disp);
2124 /* we no longer need PV here, no more loading */
2125 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2126 M_RECOMPUTE_PV(s1);*/
2128 switch (iptr->opc) {
2132 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2134 M_LDMFD(BITMASK_RESULT, REG_SP);
2140 /* deallocate stackframe for spilled variables */
2142 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2143 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2145 /* restore callee saved registers + do return */
2147 if (savedregs_bitmask) {
2148 if (!code_is_leafmethod(code)) {
2149 savedregs_bitmask &= ~(1<<REG_LR);
2150 savedregs_bitmask |= (1<<REG_PC);
2152 M_LDMFD(savedregs_bitmask, REG_SP);
2155 /* if LR was not on stack, we need to return manually */
2157 if (code_is_leafmethod(code))
2158 M_MOV(REG_PC, REG_LR);
2161 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2163 bte = iptr->sx.s23.s3.bte;
2165 goto ICMD_INVOKE_do;
2167 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2168 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2169 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2170 case ICMD_INVOKEINTERFACE:
2172 REPLACEMENT_POINT_INVOKE(cd, iptr);
2174 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2176 um = iptr->sx.s23.s3.um;
2177 md = um->methodref->parseddesc.md;
2180 lm = iptr->sx.s23.s3.fmiref->p.method;
2182 md = lm->parseddesc;
2186 /* copy arguments to registers or stack location */
2188 s3 = md->paramcount;
2190 MCODECHECK((s3 << 1) + 64);
2192 for (s3 = s3 - 1; s3 >= 0; s3--) {
2193 var = VAR(iptr->sx.s23.s2.args[s3]);
2194 d = md->params[s3].regoff;
2196 if (var->flags & PREALLOC) /* argument was precolored? */
2199 /* TODO: document me */
2200 #if !defined(ENABLE_SOFTFLOAT)
2201 if (IS_INT_LNG_TYPE(var->type)) {
2202 #endif /* !defined(ENABLE_SOFTFLOAT) */
2203 if (!md->params[s3].inmemory) {
2204 s1 = emit_load(jd, iptr, var, d);
2206 if (IS_2_WORD_TYPE(var->type))
2212 if (IS_2_WORD_TYPE(var->type)) {
2213 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2214 M_LST(s1, REG_SP, d);
2217 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2218 M_IST(s1, REG_SP, d);
2221 #if !defined(ENABLE_SOFTFLOAT)
2224 if (!md->params[s3].inmemory) {
2225 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2226 if (IS_2_WORD_TYPE(var->type))
2232 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2233 if (IS_2_WORD_TYPE(var->type))
2234 M_DST(s1, REG_SP, d);
2236 M_FST(s1, REG_SP, d);
2239 #endif /* !defined(ENABLE_SOFTFLOAT) */
2242 switch (iptr->opc) {
2245 if (bte->stub == NULL) {
2246 disp = dseg_add_functionptr(cd, bte->fp);
2248 disp = dseg_add_functionptr(cd, bte->stub);
2251 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2253 /* generate the actual call */
2255 M_MOV(REG_LR, REG_PC);
2256 M_MOV(REG_PC, REG_PV);
2257 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2261 case ICMD_INVOKESPECIAL:
2262 emit_nullpointer_check(cd, iptr, REG_A0);
2265 case ICMD_INVOKESTATIC:
2267 disp = dseg_add_unique_address(cd, NULL);
2269 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2273 disp = dseg_add_address(cd, lm->stubroutine);
2275 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2277 /* generate the actual call */
2279 M_MOV(REG_LR, REG_PC);
2280 M_MOV(REG_PC, REG_PV);
2281 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2285 case ICMD_INVOKEVIRTUAL:
2287 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2292 s1 = OFFSET(vftbl_t, table[0]) +
2293 sizeof(methodptr) * lm->vftblindex;
2295 /* implicit null-pointer check */
2296 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2297 OFFSET(java_object_t, vftbl));
2298 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2300 /* generate the actual call */
2302 M_MOV(REG_LR, REG_PC);
2303 M_MOV(REG_PC, REG_PV);
2304 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2308 case ICMD_INVOKEINTERFACE:
2310 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2316 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2317 sizeof(methodptr*) * lm->class->index;
2318 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2321 /* implicit null-pointer check */
2322 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2323 OFFSET(java_object_t, vftbl));
2324 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2325 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2327 /* generate the actual call */
2329 M_MOV(REG_LR, REG_PC);
2330 M_MOV(REG_PC, REG_PV);
2331 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2336 /* store size of call code in replacement point */
2337 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2339 /* store return value */
2341 d = md->returntype.type;
2343 #if !defined(__SOFTFP__)
2344 /* TODO: this is only a hack, since we use R0/R1 for float
2345 return! this depends on gcc; it is independent from
2346 our ENABLE_SOFTFLOAT define */
2347 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2348 #if 0 && !defined(NDEBUG)
2349 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2351 /* we cannot use this macro, since it is not defined
2352 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2353 REG_FRESULT, REG_RESULT_TYPED(d)); */
2354 if (IS_2_WORD_TYPE(d)) {
2355 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2356 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2358 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2359 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2364 if (d != TYPE_VOID) {
2365 #if !defined(ENABLE_SOFTFLOAT)
2366 if (IS_INT_LNG_TYPE(d)) {
2367 #endif /* !defined(ENABLE_SOFTFLOAT) */
2368 if (IS_2_WORD_TYPE(d)) {
2369 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2370 M_LNGMOVE(REG_RESULT_PACKED, s1);
2373 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2374 M_INTMOVE(REG_RESULT, s1);
2377 #if !defined(ENABLE_SOFTFLOAT)
2379 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2380 if (IS_2_WORD_TYPE(d))
2381 M_CAST_L2D(REG_RESULT_PACKED, s1);
2383 M_CAST_I2F(REG_RESULT, s1);
2385 #endif /* !defined(ENABLE_SOFTFLOAT) */
2387 emit_store_dst(jd, iptr, s1);
2391 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2393 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2394 /* object type cast-check */
2399 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2404 super = iptr->sx.s23.s3.c.cls;
2405 superindex = super->index;
2408 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2409 CODEGEN_CRITICAL_SECTION_NEW;
2411 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2413 /* if class is not resolved, check which code to call */
2415 if (super == NULL) {
2417 emit_label_beq(cd, BRANCH_LABEL_1);
2419 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2420 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2421 iptr->sx.s23.s3.c.ref, disp);
2423 M_DSEG_LOAD(REG_ITMP2, disp);
2424 disp = dseg_add_s4(cd, ACC_INTERFACE);
2425 M_DSEG_LOAD(REG_ITMP3, disp);
2426 M_TST(REG_ITMP2, REG_ITMP3);
2427 emit_label_beq(cd, BRANCH_LABEL_2);
2430 /* interface checkcast code */
2432 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2433 if ((super == NULL) || !IS_IMM(superindex)) {
2434 disp = dseg_add_unique_s4(cd, superindex);
2436 if (super == NULL) {
2437 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2438 iptr->sx.s23.s3.c.ref, disp);
2442 emit_label_beq(cd, BRANCH_LABEL_3);
2445 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2446 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2448 /* we put unresolved or non-immediate superindices onto dseg */
2449 if ((super == NULL) || !IS_IMM(superindex)) {
2450 /* disp was computed before we added the patcher */
2451 M_DSEG_LOAD(REG_ITMP2, disp);
2452 M_CMP(REG_ITMP3, REG_ITMP2);
2454 assert(IS_IMM(superindex));
2455 M_CMP_IMM(REG_ITMP3, superindex);
2458 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2460 /* if we loaded the superindex out of the dseg above, we do
2461 things differently here! */
2462 if ((super == NULL) || !IS_IMM(superindex)) {
2464 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2466 /* this assumes something */
2467 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2469 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2470 assert(sizeof(methodptr*) == 4);
2471 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2477 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2478 superindex * sizeof(methodptr*);
2482 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2483 M_TST(REG_ITMP3, REG_ITMP3);
2484 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2487 emit_label_br(cd, BRANCH_LABEL_4);
2489 emit_label(cd, BRANCH_LABEL_3);
2492 /* class checkcast code */
2494 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2495 if (super == NULL) {
2496 emit_label(cd, BRANCH_LABEL_2);
2498 disp = dseg_add_unique_address(cd, NULL);
2500 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2501 iptr->sx.s23.s3.c.ref,
2505 disp = dseg_add_address(cd, super->vftbl);
2508 emit_label_beq(cd, BRANCH_LABEL_5);
2511 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2512 M_DSEG_LOAD(REG_ITMP3, disp);
2514 CODEGEN_CRITICAL_SECTION_START;
2516 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2517 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2518 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2519 M_DSEG_LOAD(REG_ITMP3, disp);
2520 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2522 CODEGEN_CRITICAL_SECTION_END;
2524 M_CMP(REG_ITMP2, REG_ITMP3);
2525 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2528 emit_label(cd, BRANCH_LABEL_5);
2531 if (super == NULL) {
2532 emit_label(cd, BRANCH_LABEL_1);
2533 emit_label(cd, BRANCH_LABEL_4);
2536 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2539 /* array type cast-check */
2541 s1 = emit_load_s1(jd, iptr, REG_A0);
2542 M_INTMOVE(s1, REG_A0);
2544 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2545 disp = dseg_add_unique_address(cd, NULL);
2547 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2548 iptr->sx.s23.s3.c.ref,
2552 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2554 M_DSEG_LOAD(REG_A1, disp);
2555 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2556 M_DSEG_BRANCH(disp);
2559 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2560 M_RECOMPUTE_PV(disp);
2562 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2563 M_TST(REG_RESULT, REG_RESULT);
2564 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2566 d = codegen_reg_of_dst(jd, iptr, s1);
2570 emit_store_dst(jd, iptr, d);
2573 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2579 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2584 super = iptr->sx.s23.s3.c.cls;
2585 superindex = super->index;
2588 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2589 CODEGEN_CRITICAL_SECTION_NEW;
2591 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2592 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2595 M_MOV(REG_ITMP1, s1);
2599 /* if class is not resolved, check which code to call */
2601 if (super == NULL) {
2605 emit_label_beq(cd, BRANCH_LABEL_1);
2607 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2608 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2609 iptr->sx.s23.s3.c.ref, disp);
2611 M_DSEG_LOAD(REG_ITMP2, disp);
2612 disp = dseg_add_s4(cd, ACC_INTERFACE);
2613 M_DSEG_LOAD(REG_ITMP3, disp);
2614 M_TST(REG_ITMP2, REG_ITMP3);
2615 emit_label_beq(cd, BRANCH_LABEL_2);
2618 /* interface checkcast code */
2620 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2621 if ((super == NULL) || !IS_IMM(superindex)) {
2622 disp = dseg_add_unique_s4(cd, superindex);
2624 if (super == NULL) {
2625 /* If d == REG_ITMP2, then it's destroyed in check
2630 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2631 iptr->sx.s23.s3.c.ref, disp);
2636 emit_label_beq(cd, BRANCH_LABEL_3);
2639 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2640 M_LDR_INTERN(REG_ITMP3,
2641 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2643 /* we put unresolved or non-immediate superindices onto dseg
2644 and do things slightly different */
2645 if ((super == NULL) || !IS_IMM(superindex)) {
2646 /* disp was computed before we added the patcher */
2647 M_DSEG_LOAD(REG_ITMP2, disp);
2648 M_CMP(REG_ITMP3, REG_ITMP2);
2650 if (d == REG_ITMP2) {
2657 /* this assumes something */
2658 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2660 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2661 assert(sizeof(methodptr*) == 4);
2662 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2664 if (d == REG_ITMP2) {
2671 assert(IS_IMM(superindex));
2672 M_CMP_IMM(REG_ITMP3, superindex);
2676 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2677 superindex * sizeof(methodptr*);
2681 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2682 M_TST(REG_ITMP3, REG_ITMP3);
2686 emit_label_br(cd, BRANCH_LABEL_4);
2688 emit_label(cd, BRANCH_LABEL_3);
2691 /* class checkcast code */
2693 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2694 if (super == NULL) {
2695 emit_label(cd, BRANCH_LABEL_2);
2697 disp = dseg_add_unique_address(cd, NULL);
2699 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2700 iptr->sx.s23.s3.c.ref, disp);
2703 disp = dseg_add_address(cd, super->vftbl);
2707 emit_label_beq(cd, BRANCH_LABEL_5);
2710 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2711 M_DSEG_LOAD(REG_ITMP2, disp);
2713 CODEGEN_CRITICAL_SECTION_START;
2715 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2716 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2717 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2719 CODEGEN_CRITICAL_SECTION_END;
2721 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2722 M_CMP(REG_ITMP1, REG_ITMP2);
2723 /* If d == REG_ITMP2, then it's destroyed */
2729 emit_label(cd, BRANCH_LABEL_5);
2732 if (super == NULL) {
2733 emit_label(cd, BRANCH_LABEL_1);
2734 emit_label(cd, BRANCH_LABEL_4);
2739 emit_store_dst(jd, iptr, d);
2742 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2744 /* copy sizes to stack if necessary */
2746 MCODECHECK((iptr->s1.argcount << 1) + 64);
2748 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2750 var = VAR(iptr->sx.s23.s2.args[s1]);
2752 /* copy SAVEDVAR sizes to stack */
2754 if (!(var->flags & PREALLOC)) {
2755 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2756 M_STR(s2, REG_SP, s1 * 4);
2760 /* a0 = dimension count */
2762 assert(IS_IMM(iptr->s1.argcount));
2763 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2765 /* is patcher function set? */
2767 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2768 disp = dseg_add_unique_address(cd, NULL);
2770 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2771 iptr->sx.s23.s3.c.ref, disp);
2774 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2776 /* a1 = arraydescriptor */
2778 M_DSEG_LOAD(REG_A1, disp);
2780 /* a2 = pointer to dimensions = stack pointer */
2782 M_INTMOVE(REG_SP, REG_A2);
2784 /* call builtin_multianewarray here */
2786 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2787 M_DSEG_BRANCH(disp);
2791 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2794 /* check for exception before result assignment */
2796 emit_exception_check(cd, iptr);
2800 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2801 M_INTMOVE(REG_RESULT, d);
2802 emit_store_dst(jd, iptr, d);
2805 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2807 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2808 emit_nullpointer_check(cd, iptr, s1);
2812 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2815 } /* the big switch */
2817 } /* for all instructions */
2819 } /* for all basic blocks */
2821 /* generate traps */
2823 emit_patcher_traps(jd);
2825 /* everything's ok */
2831 /* codegen_emit_stub_compiler **************************************************
2833 Emits a stub routine which calls the compiler.
2835 *******************************************************************************/
2837 void codegen_emit_stub_compiler(jitdata *jd)
2842 /* get required compiler data */
2847 /* code for the stub */
2849 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2850 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2854 /* codegen_emit_stub_native ****************************************************
2856 Emits a stub routine which calls a native method.
2858 *******************************************************************************/
2860 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2871 /* get required compiler data */
2877 /* initialize variables */
2881 /* calculate stackframe size */
2883 cd->stackframesize =
2884 4 + /* return address */
2885 sizeof(stackframeinfo_t) + /* stackframeinfo */
2886 sizeof(localref_table) + /* localref_table */
2887 nmd->memuse * 4; /* stack arguments */
2889 /* align stack to 8-byte */
2891 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2893 /* create method header */
2895 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2896 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2897 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2898 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2899 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2901 /* generate stub code */
2903 M_STMFD(1<<REG_LR, REG_SP);
2904 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2906 #if !defined(NDEBUG)
2907 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2908 emit_verbosecall_enter(jd);
2911 #if defined(ENABLE_GC_CACAO)
2912 /* Save callee saved integer registers in stackframeinfo (GC may
2913 need to recover them during a collection). */
2915 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2916 OFFSET(stackframeinfo_t, intregs);
2918 for (i = 0; i < INT_SAV_CNT; i++)
2919 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2922 /* Save integer and float argument registers (these are 4
2923 registers, stack is 8-byte aligned). */
2925 M_STMFD(BITMASK_ARGS, REG_SP);
2926 /* TODO: floating point */
2928 /* create native stackframe info */
2930 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2931 M_MOV(REG_A1, REG_PV);
2932 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2933 M_DSEG_BRANCH(disp);
2937 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2940 /* remember class argument */
2942 if (m->flags & ACC_STATIC)
2943 M_MOV(REG_ITMP3, REG_RESULT);
2945 /* Restore integer and float argument registers (these are 4
2946 registers, stack is 8-byte aligned). */
2948 M_LDMFD(BITMASK_ARGS, REG_SP);
2949 /* TODO: floating point */
2951 /* copy or spill arguments to new locations */
2952 /* ATTENTION: the ARM has only integer argument registers! */
2954 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2955 t = md->paramtypes[i].type;
2957 if (!md->params[i].inmemory) {
2958 s1 = md->params[i].regoff;
2959 s2 = nmd->params[j].regoff;
2961 if (!nmd->params[j].inmemory) {
2962 #if !defined(__ARM_EABI__)
2963 SPLIT_OPEN(t, s2, REG_ITMP1);
2966 if (IS_2_WORD_TYPE(t))
2971 #if !defined(__ARM_EABI__)
2972 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2976 if (IS_2_WORD_TYPE(t))
2977 M_LST(s1, REG_SP, s2);
2979 M_IST(s1, REG_SP, s2);
2983 s1 = md->params[i].regoff + cd->stackframesize;
2984 s2 = nmd->params[j].regoff;
2986 if (IS_2_WORD_TYPE(t)) {
2987 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2988 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2991 M_ILD(REG_ITMP1, REG_SP, s1);
2992 M_IST(REG_ITMP1, REG_SP, s2);
2997 /* Handle native Java methods. */
2999 if (m->flags & ACC_NATIVE) {
3000 /* put class into second argument register */
3002 if (m->flags & ACC_STATIC)
3003 M_MOV(REG_A1, REG_ITMP3);
3005 /* put env into first argument register */
3007 disp = dseg_add_address(cd, _Jv_env);
3008 M_DSEG_LOAD(REG_A0, disp);
3011 /* Call the native function. */
3013 disp = dseg_add_functionptr(cd, f);
3014 M_DSEG_BRANCH(disp);
3017 /* TODO: this is only needed because of the tracer ... do we
3020 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3023 #if !defined(__SOFTFP__)
3024 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3025 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3026 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3027 #if 0 && !defined(NDEBUG)
3028 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3030 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3031 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3032 if (IS_2_WORD_TYPE(md->returntype.type)) {
3033 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3034 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3036 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3037 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3042 #if !defined(NDEBUG)
3043 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3044 emit_verbosecall_exit(jd);
3047 /* remove native stackframe info */
3048 /* TODO: improve this store/load */
3050 M_STMFD(BITMASK_RESULT, REG_SP);
3052 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3053 M_MOV(REG_A1, REG_PV);
3054 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3055 M_DSEG_BRANCH(disp);
3056 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3059 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3060 M_LDMFD(BITMASK_RESULT, REG_SP);
3062 #if defined(ENABLE_GC_CACAO)
3063 /* restore callee saved int registers from stackframeinfo (GC might have */
3064 /* modified them during a collection). */
3066 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3067 OFFSET(stackframeinfo_t, intregs);
3069 for (i = 0; i < INT_SAV_CNT; i++)
3070 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3073 /* finish stub code, but do not yet return to caller */
3075 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3076 M_LDMFD(1<<REG_LR, REG_SP);
3078 /* check for exception */
3080 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3081 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3083 /* handle exception here */
3085 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3087 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3088 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3089 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3093 /* asm_debug *******************************************************************
3097 *******************************************************************************/
3099 void asm_debug(int a1, int a2, int a3, int a4)
3101 printf("===> i am going to exit after this debugging message!\n");
3102 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3103 vm_abort("leave you now");
3108 * These are local overrides for various environment variables in Emacs.
3109 * Please do not remove this and leave it at the end of the file, where
3110 * Emacs will automagically detect them.
3111 * ---------------------------------------------------------------------
3114 * indent-tabs-mode: t
3118 * vim:noexpandtab:sw=4:ts=4: