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/md.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher-common.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)
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 /* IsSync contains the offset relative to the stack pointer for the
151 argument of monitor_exit used in the exception handler. Since the
152 offset could be zero and give a wrong meaning of the flag it is
155 /* XXX Remove this "offset by one". */
157 code->synchronizedoffset = rd->memuse * 8 + 4;
159 /* REMOVEME dummy IsSync */
160 (void) dseg_add_unique_s4(cd, 0);
162 /* REMOVEME: We still need it for exception handling in assembler. */
164 if (code_is_leafmethod(code))
165 (void) dseg_add_unique_s4(cd, 1);
167 (void) dseg_add_unique_s4(cd, 0);
169 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
170 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
171 (void) dseg_addlinenumbertablesize(cd);
172 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
174 /* create exception table */
176 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
177 dseg_add_target(cd, ex->start);
178 dseg_add_target(cd, ex->end);
179 dseg_add_target(cd, ex->handler);
180 (void) dseg_add_unique_address(cd, ex->catchtype.any);
183 /* save return address and used callee saved registers */
185 savedregs_bitmask = 0;
187 if (!code_is_leafmethod(code))
188 savedregs_bitmask = (1<<REG_LR);
190 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
191 savedregs_bitmask |= (1<<(rd->savintregs[i]));
194 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
195 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
196 /* TODO: floating-point */
200 if (savedregs_bitmask)
201 M_STMFD(savedregs_bitmask, REG_SP);
203 /* create additional stack frame for spilled variables (if necessary) */
205 if ((cd->stackframesize / 4 - savedregs_num) > 0)
206 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
208 /* take arguments out of register or stack frame */
211 for (i = 0, len = 0; i < md->paramcount; i++) {
212 s1 = md->params[i].regoff;
213 t = md->paramtypes[i].type;
215 varindex = jd->local_map[len * 5 + t];
217 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
219 if (varindex == UNUSED)
224 /* ATTENTION: we use interger registers for all arguments (even float) */
225 #if !defined(ENABLE_SOFTFLOAT)
226 if (IS_INT_LNG_TYPE(t)) {
228 if (!md->params[i].inmemory) {
229 if (!(var->flags & INMEMORY)) {
230 if (IS_2_WORD_TYPE(t))
231 M_LNGMOVE(s1, var->vv.regoff);
233 M_INTMOVE(s1, var->vv.regoff);
236 if (IS_2_WORD_TYPE(t))
237 M_LST(s1, REG_SP, var->vv.regoff);
239 M_IST(s1, REG_SP, var->vv.regoff);
242 else { /* stack arguments */
243 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
244 if (IS_2_WORD_TYPE(t))
245 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
247 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
249 else { /* stack arg -> spilled */
250 /* Reuse Memory Position on Caller Stack */
251 var->vv.regoff = cd->stackframesize + s1;
254 #if !defined(ENABLE_SOFTFLOAT)
257 if (!md->params[i].inmemory) {
258 if (!(var->flags & INMEMORY)) {
259 if (IS_2_WORD_TYPE(t))
260 M_CAST_L2D(s1, var->vv.regoff);
262 M_CAST_I2F(s1, var->vv.regoff);
265 if (IS_2_WORD_TYPE(t))
266 M_LST(s1, REG_SP, var->vv.regoff);
268 M_IST(s1, REG_SP, var->vv.regoff);
272 if (!(var->flags & INMEMORY)) {
273 if (IS_2_WORD_TYPE(t))
274 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
276 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
279 /* Reuse Memory Position on Caller Stack */
280 var->vv.regoff = cd->stackframesize + s1;
284 #endif /* !defined(ENABLE_SOFTFLOAT) */
287 #if defined(ENABLE_THREADS)
288 /* call monitorenter function */
290 if (checksync && code_is_synchronized(code)) {
291 /* stack offset for monitor argument */
295 # if !defined(NDEBUG)
296 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
297 M_STMFD(BITMASK_ARGS, REG_SP);
302 /* get the correct lock object */
304 if (m->flags & ACC_STATIC) {
305 disp = dseg_add_address(cd, &m->class->object.header);
306 M_DSEG_LOAD(REG_A0, disp);
309 emit_nullpointer_check_force(cd, iptr, REG_A0);
312 M_STR(REG_A0, REG_SP, s1);
313 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
315 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
318 # if !defined(NDEBUG)
319 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
320 M_LDMFD(BITMASK_ARGS, REG_SP);
326 /* call trace function */
328 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
329 emit_verbosecall_enter(jd);
332 /* end of header generation */
334 /* create replacement points */
335 REPLACEMENT_POINTS_INIT(cd, jd);
337 /* SECTION: ICMD Code Generation */
338 /* for all basic blocks */
340 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
342 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
344 /* is this basic block reached? */
346 if (bptr->flags < BBREACHED)
349 /* branch resolving */
351 codegen_resolve_branchrefs(cd, bptr);
353 /* handle replacement points */
354 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
356 /* copy interface registers to their destination */
362 #if defined(ENABLE_LSRA)
366 var = VAR(bptr->invars[len]);
367 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
368 if (!(var->flags & INMEMORY))
372 M_INTMOVE(REG_ITMP1, d);
373 emit_store(jd, NULL, var, d);
380 var = VAR(bptr->invars[len]);
382 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
383 d = codegen_reg_of_var(0, var, REG_ITMP1);
384 M_INTMOVE(REG_ITMP1, d);
385 emit_store(jd, NULL, var, d);
388 assert((var->flags & INOUT));
391 #if defined(ENABLE_LSRA)
395 /* for all instructions */
398 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
400 /* add line number */
401 if (iptr->line != currentline) {
402 dseg_addlinenumber(cd, iptr->line);
403 currentline = iptr->line;
406 MCODECHECK(64); /* an instruction usually needs < 64 words */
410 case ICMD_NOP: /* ... ==> ... */
413 /* constant operations ************************************************/
415 case ICMD_ICONST: /* ... ==> ..., constant */
417 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
418 ICONST(d, iptr->sx.val.i);
419 emit_store_dst(jd, iptr, d);
422 case ICMD_ACONST: /* ... ==> ..., constant */
424 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
425 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
426 disp = dseg_add_unique_address(cd, NULL);
428 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
429 iptr->sx.val.c.ref, disp);
431 M_DSEG_LOAD(d, disp);
434 ICONST(d, (u4) iptr->sx.val.anyptr);
436 emit_store_dst(jd, iptr, d);
439 case ICMD_LCONST: /* ... ==> ..., constant */
441 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
442 LCONST(d, iptr->sx.val.l);
443 emit_store_dst(jd, iptr, d);
446 case ICMD_FCONST: /* ... ==> ..., constant */
448 #if defined(ENABLE_SOFTFLOAT)
449 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
450 ICONST(d, iptr->sx.val.i);
451 emit_store_dst(jd, iptr, d);
453 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
454 FCONST(d, iptr->sx.val.f);
455 emit_store_dst(jd, iptr, d);
459 case ICMD_DCONST: /* ... ==> ..., constant */
461 #if defined(ENABLE_SOFTFLOAT)
462 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
463 LCONST(d, iptr->sx.val.l);
464 emit_store_dst(jd, iptr, d);
466 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
467 DCONST(d, iptr->sx.val.d);
468 emit_store_dst(jd, iptr, d);
473 /* load/store/copy/move operations ************************************/
475 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
476 case ICMD_ALOAD: /* op1 = local variable */
480 case ICMD_ISTORE: /* ..., value ==> ... */
491 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
495 /* pop operations *****************************************************/
497 /* attention: double and longs are only one entry in CACAO ICMDs */
499 case ICMD_POP: /* ..., value ==> ... */
500 case ICMD_POP2: /* ..., value, value ==> ... */
505 /* integer operations *************************************************/
507 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
509 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
510 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
511 M_MOV(d, REG_LSL(s1, 24));
512 M_MOV(d, REG_ASR(d, 24));
513 emit_store_dst(jd, iptr, d);
516 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
518 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
519 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
520 M_MOV(d, REG_LSL(s1, 16));
521 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
522 emit_store_dst(jd, iptr, d);
525 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
527 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
528 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
529 M_MOV(d, REG_LSL(s1, 16));
530 M_MOV(d, REG_ASR(d, 16));
531 emit_store_dst(jd, iptr, d);
534 case ICMD_I2L: /* ..., value ==> ..., value */
536 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
538 M_INTMOVE(s1, GET_LOW_REG(d));
539 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
540 emit_store_dst(jd, iptr, d);
543 case ICMD_L2I: /* ..., value ==> ..., value */
545 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
546 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
548 emit_store_dst(jd, iptr, d);
551 case ICMD_INEG: /* ..., value ==> ..., - value */
553 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
554 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
556 emit_store_dst(jd, iptr, d);
559 case ICMD_LNEG: /* ..., value ==> ..., - value */
561 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
562 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
563 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
564 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
565 emit_store_dst(jd, iptr, d);
568 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
570 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
571 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
572 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
574 emit_store_dst(jd, iptr, d);
577 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
579 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
580 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
581 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
582 M_ADD_S(GET_LOW_REG(d), s1, s2);
583 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
584 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
585 M_ADC(GET_HIGH_REG(d), s1, s2);
586 emit_store_dst(jd, iptr, d);
592 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
593 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
595 if (IS_IMM(iptr->sx.val.i)) {
596 M_ADD_IMM(d, s1, iptr->sx.val.i);
597 } else if (IS_IMM(-iptr->sx.val.i)) {
598 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
600 ICONST(REG_ITMP3, iptr->sx.val.i);
601 M_ADD(d, s1, REG_ITMP3);
604 emit_store_dst(jd, iptr, d);
607 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
608 /* sx.val.l = constant */
610 s3 = iptr->sx.val.l & 0xffffffff;
611 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
612 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
614 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
616 ICONST(REG_ITMP3, s3);
617 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
619 s3 = iptr->sx.val.l >> 32;
620 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
622 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
624 ICONST(REG_ITMP3, s3);
625 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
627 emit_store_dst(jd, iptr, d);
630 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
632 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
633 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
634 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
636 emit_store_dst(jd, iptr, d);
639 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
641 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
642 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
643 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
644 M_SUB_S(GET_LOW_REG(d), s1, s2);
645 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
646 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
647 M_SBC(GET_HIGH_REG(d), s1, s2);
648 emit_store_dst(jd, iptr, d);
651 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
652 /* sx.val.i = constant */
654 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
655 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
656 if (IS_IMM(iptr->sx.val.i))
657 M_SUB_IMM(d, s1, iptr->sx.val.i);
659 ICONST(REG_ITMP3, iptr->sx.val.i);
660 M_SUB(d, s1, REG_ITMP3);
662 emit_store_dst(jd, iptr, d);
665 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
666 /* sx.val.l = constant */
668 s3 = iptr->sx.val.l & 0xffffffff;
669 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
670 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
672 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
674 ICONST(REG_ITMP3, s3);
675 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
677 s3 = iptr->sx.val.l >> 32;
678 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
680 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
682 ICONST(REG_ITMP3, s3);
683 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
685 emit_store_dst(jd, iptr, d);
688 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
690 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
691 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
692 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
694 emit_store_dst(jd, iptr, d);
697 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
698 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
700 s1 = emit_load_s1(jd, iptr, REG_A0);
701 s2 = emit_load_s2(jd, iptr, REG_A1);
702 emit_arithmetic_check(cd, iptr, s2);
704 /* move arguments into argument registers */
705 M_INTMOVE(s1, REG_A0);
706 M_INTMOVE(s2, REG_A1);
708 /* call builtin function */
709 bte = iptr->sx.s23.s3.bte;
710 disp = dseg_add_functionptr(cd, bte->fp);
714 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
717 /* move result into destination register */
718 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
719 M_INTMOVE(REG_RESULT, d);
720 emit_store_dst(jd, iptr, d);
723 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
724 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
726 /* move arguments into argument registers */
728 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
729 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
730 /* XXX TODO: only do this if arithmetic check is really done! */
731 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
732 emit_arithmetic_check(cd, iptr, REG_ITMP3);
734 M_LNGMOVE(s1, REG_A0_A1_PACKED);
735 M_LNGMOVE(s2, REG_A2_A3_PACKED);
737 /* call builtin function */
738 bte = iptr->sx.s23.s3.bte;
739 disp = dseg_add_functionptr(cd, bte->fp);
743 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
746 /* move result into destination register */
747 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
748 M_LNGMOVE(REG_RESULT_PACKED, d);
749 emit_store_dst(jd, iptr, d);
752 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
753 /* sx.val.i = constant */
755 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
756 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
757 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
758 emit_store_dst(jd, iptr, d);
761 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
762 /* sx.val.i = constant */
764 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
765 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
766 /* this rounds towards 0 as java likes it */
767 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
768 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
769 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
770 /* this rounds towards nearest, not java style */
771 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
772 M_ADCMI_IMM(d, d, 0);*/
773 emit_store_dst(jd, iptr, d);
776 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
777 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
779 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
780 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
781 M_MOV_S(REG_ITMP1, s1);
782 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
783 if (IS_IMM(iptr->sx.val.i))
784 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
786 ICONST(REG_ITMP3, iptr->sx.val.i);
787 M_AND(REG_ITMP1, REG_ITMP3, d);
789 M_RSBMI_IMM(d, d, 0);
790 emit_store_dst(jd, iptr, d);
793 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
795 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
796 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
797 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
798 M_AND_IMM(s2, 0x1f, REG_ITMP2);
799 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
800 emit_store_dst(jd, iptr, d);
803 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
805 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
806 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
807 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
808 M_AND_IMM(s2, 0x1f, REG_ITMP2);
809 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
810 emit_store_dst(jd, iptr, d);
813 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
815 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
816 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
817 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
818 M_AND_IMM(s2, 0x1f, REG_ITMP2);
819 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
820 emit_store_dst(jd, iptr, d);
823 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
824 /* sx.val.i = constant */
826 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
827 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
828 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
829 emit_store_dst(jd, iptr, d);
832 case ICMD_ISHRCONST: /* ..., 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_ASR(s1, iptr->sx.val.i & 0x1f));
843 emit_store_dst(jd, iptr, d);
846 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
847 /* sx.val.i = constant */
849 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
850 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
851 /* we need to check for zero here because arm interprets it as SHR by 32 */
852 if ((iptr->sx.val.i & 0x1f) == 0)
855 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
856 emit_store_dst(jd, iptr, d);
859 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
861 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
862 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
863 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
865 emit_store_dst(jd, iptr, d);
868 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
870 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
871 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
872 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
873 M_AND(s1, s2, GET_LOW_REG(d));
874 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
875 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
876 M_AND(s1, s2, GET_HIGH_REG(d));
877 emit_store_dst(jd, iptr, d);
880 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
882 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
883 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
884 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
886 emit_store_dst(jd, iptr, d);
889 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
891 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
892 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
893 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
894 M_ORR(s1, s2, GET_LOW_REG(d));
895 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
896 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
897 M_ORR(s1, s2, GET_HIGH_REG(d));
898 emit_store_dst(jd, iptr, d);
901 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
903 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
904 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
905 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
907 emit_store_dst(jd, iptr, d);
910 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
912 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
913 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
914 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
915 M_EOR(s1, s2, GET_LOW_REG(d));
916 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
917 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
918 M_EOR(s1, s2, GET_HIGH_REG(d));
919 emit_store_dst(jd, iptr, d);
923 /* floating operations ************************************************/
925 #if !defined(ENABLE_SOFTFLOAT)
927 case ICMD_FNEG: /* ..., value ==> ..., - value */
929 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
930 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
932 emit_store_dst(jd, iptr, d);
935 case ICMD_FADD: /* ..., 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 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
946 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
947 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
948 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
950 emit_store_dst(jd, iptr, d);
953 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
955 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
956 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
957 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
959 emit_store_dst(jd, iptr, d);
962 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
963 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
964 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
965 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
967 emit_store_dst(jd, iptr, d);
970 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
974 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
976 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
977 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
978 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
980 emit_store_dst(jd, iptr, d);
984 case ICMD_DNEG: /* ..., value ==> ..., - value */
986 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
987 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
989 emit_store_dst(jd, iptr, d);
992 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
994 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
995 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
996 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
998 emit_store_dst(jd, iptr, d);
1001 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1003 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1004 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1005 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1007 emit_store_dst(jd, iptr, d);
1010 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1012 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1013 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1014 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1016 emit_store_dst(jd, iptr, d);
1019 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1021 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1022 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1023 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1025 emit_store_dst(jd, iptr, d);
1028 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1032 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1034 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1035 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1036 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1038 emit_store_dst(jd, iptr, d);
1042 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1044 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1045 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1047 emit_store_dst(jd, iptr, d);
1050 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1052 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1053 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1055 emit_store_dst(jd, iptr, d);
1058 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1060 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1061 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1062 /* this uses round towards zero, as Java likes it */
1064 #if !defined(__VFP_FP__)
1065 /* this checks for NaN; to return zero as Java likes it */
1069 emit_store_dst(jd, iptr, d);
1072 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1074 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1075 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1076 /* this uses round towards zero, as Java likes it */
1078 #if !defined(__VFP_FP__)
1079 /* this checks for NaN; to return zero as Java likes it */
1083 emit_store_dst(jd, iptr, d);
1086 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1088 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1089 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1091 emit_store_dst(jd, iptr, d);
1094 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1096 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1097 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1099 emit_store_dst(jd, iptr, d);
1102 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1104 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1105 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1106 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1109 #if defined(__VFP_FP__)
1110 M_FMSTAT; /* on VFP we need to transfer the flags */
1112 M_SUBGT_IMM(d, d, 1);
1113 M_ADDLT_IMM(d, d, 1);
1114 emit_store_dst(jd, iptr, d);
1117 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1119 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1120 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1121 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1124 #if defined(__VFP_FP__)
1125 M_FMSTAT; /* on VFP we need to transfer the flags */
1127 M_SUBGT_IMM(d, d, 1);
1128 M_ADDLT_IMM(d, d, 1);
1129 emit_store_dst(jd, iptr, d);
1132 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1134 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1135 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1136 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1139 #if defined(__VFP_FP__)
1140 M_FMSTAT; /* on VFP we need to transfer the flags */
1142 M_SUBLT_IMM(d, d, 1);
1143 M_ADDGT_IMM(d, d, 1);
1144 emit_store_dst(jd, iptr, d);
1147 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1149 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1150 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1151 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1154 #if defined(__VFP_FP__)
1155 M_FMSTAT; /* on VFP we need to transfer the flags */
1157 M_SUBLT_IMM(d, d, 1);
1158 M_ADDGT_IMM(d, d, 1);
1159 emit_store_dst(jd, iptr, d);
1162 #endif /* !defined(ENABLE_SOFTFLOAT) */
1165 /* memory operations **************************************************/
1167 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1169 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1170 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1171 /* implicit null-pointer check */
1172 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1173 emit_store_dst(jd, iptr, d);
1176 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1178 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1179 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1180 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1181 /* implicit null-pointer check */
1182 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1183 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1184 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1185 emit_store_dst(jd, iptr, d);
1188 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1190 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1191 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1192 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1193 /* implicit null-pointer check */
1194 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1195 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1196 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1197 emit_store_dst(jd, iptr, d);
1200 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1202 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1203 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1204 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1205 /* implicit null-pointer check */
1206 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1207 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1208 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1209 emit_store_dst(jd, iptr, d);
1212 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1214 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1215 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1216 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1217 /* implicit null-pointer check */
1218 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1219 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1220 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1221 emit_store_dst(jd, iptr, d);
1224 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1226 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1227 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1228 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1229 /* implicit null-pointer check */
1230 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1231 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1232 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1233 emit_store_dst(jd, iptr, d);
1236 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1238 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1239 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1240 /* implicit null-pointer check */
1241 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1242 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1243 #if !defined(ENABLE_SOFTFLOAT)
1244 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1245 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1247 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1248 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1250 emit_store_dst(jd, iptr, d);
1253 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1255 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1256 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1257 /* implicit null-pointer check */
1258 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1259 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1260 #if !defined(ENABLE_SOFTFLOAT)
1261 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1262 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1264 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1265 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1267 emit_store_dst(jd, iptr, d);
1270 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1272 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1273 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1274 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1275 /* implicit null-pointer check */
1276 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1277 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1278 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1279 emit_store_dst(jd, iptr, d);
1282 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1284 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1285 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1286 /* implicit null-pointer check */
1287 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1288 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1289 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1290 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1293 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1295 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1296 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1297 /* implicit null-pointer check */
1298 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1299 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1300 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1301 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1304 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1306 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1307 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1308 /* implicit null-pointer check */
1309 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1310 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1311 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1312 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1315 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1317 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1318 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1319 /* implicit null-pointer check */
1320 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1321 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1322 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1323 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1326 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1328 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1329 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1330 /* implicit null-pointer check */
1331 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1332 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1333 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1334 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1337 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1339 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1340 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1341 /* implicit null-pointer check */
1342 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1343 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1344 #if !defined(ENABLE_SOFTFLOAT)
1345 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1346 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1348 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1349 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1353 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1355 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1356 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1357 /* implicit null-pointer check */
1358 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1359 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1360 #if !defined(ENABLE_SOFTFLOAT)
1361 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1362 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1364 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1365 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1369 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1371 s1 = emit_load_s1(jd, iptr, REG_A0);
1372 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1373 s3 = emit_load_s3(jd, iptr, REG_A1);
1375 /* implicit null-pointer check */
1376 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1378 /* move arguments to argument registers */
1379 M_INTMOVE(s1, REG_A0);
1380 M_INTMOVE(s3, REG_A1);
1382 /* call builtin function */
1383 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1384 M_DSEG_BRANCH(disp);
1387 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1390 /* check resturn value of builtin */
1391 emit_arraystore_check(cd, iptr);
1393 /* finally store address into array */
1394 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1395 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1396 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1397 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1398 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1401 case ICMD_GETSTATIC: /* ... ==> ..., value */
1403 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1404 uf = iptr->sx.s23.s3.uf;
1405 fieldtype = uf->fieldref->parseddesc.fd->type;
1406 disp = dseg_add_unique_address(cd, NULL);
1408 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1411 fi = iptr->sx.s23.s3.fmiref->p.field;
1412 fieldtype = fi->type;
1413 disp = dseg_add_address(cd, fi->value);
1415 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1416 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1421 M_DSEG_LOAD(REG_ITMP3, disp);
1422 switch (fieldtype) {
1424 #if defined(ENABLE_SOFTFLOAT)
1428 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1429 M_ILD_INTERN(d, REG_ITMP3, 0);
1432 #if defined(ENABLE_SOFTFLOAT)
1435 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1436 M_LLD_INTERN(d, REG_ITMP3, 0);
1438 #if !defined(ENABLE_SOFTFLOAT)
1440 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1441 M_FLD_INTERN(d, REG_ITMP3, 0);
1444 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1445 M_DLD_INTERN(d, REG_ITMP3, 0);
1451 emit_store_dst(jd, iptr, d);
1454 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1456 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1457 uf = iptr->sx.s23.s3.uf;
1458 fieldtype = uf->fieldref->parseddesc.fd->type;
1459 disp = dseg_add_unique_address(cd, NULL);
1461 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1464 fi = iptr->sx.s23.s3.fmiref->p.field;
1465 fieldtype = fi->type;
1466 disp = dseg_add_address(cd, fi->value);
1468 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1469 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1474 M_DSEG_LOAD(REG_ITMP3, disp);
1475 switch (fieldtype) {
1477 #if defined(ENABLE_SOFTFLOAT)
1481 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1482 M_IST_INTERN(s1, REG_ITMP3, 0);
1485 #if defined(ENABLE_SOFTFLOAT)
1488 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1489 M_LST_INTERN(s1, REG_ITMP3, 0);
1491 #if !defined(ENABLE_SOFTFLOAT)
1493 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1494 M_FST_INTERN(s1, REG_ITMP3, 0);
1497 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1498 M_DST_INTERN(s1, REG_ITMP3, 0);
1506 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1508 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1509 emit_nullpointer_check(cd, iptr, s1);
1512 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1513 uf = iptr->sx.s23.s3.uf;
1514 fieldtype = uf->fieldref->parseddesc.fd->type;
1518 fi = iptr->sx.s23.s3.fmiref->p.field;
1519 fieldtype = fi->type;
1523 #if !defined(ENABLE_SOFTFLOAT)
1524 /* HACK: softnull checks on floats */
1525 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1526 emit_nullpointer_check_force(cd, iptr, s1);
1529 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1531 uf = iptr->sx.s23.s3.uf;
1533 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1536 switch (fieldtype) {
1538 #if defined(ENABLE_SOFTFLOAT)
1542 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1546 #if defined(ENABLE_SOFTFLOAT)
1549 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1552 #if !defined(ENABLE_SOFTFLOAT)
1554 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1558 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1565 emit_store_dst(jd, iptr, d);
1568 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1570 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1571 emit_nullpointer_check(cd, iptr, s1);
1573 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1574 uf = iptr->sx.s23.s3.uf;
1575 fieldtype = uf->fieldref->parseddesc.fd->type;
1579 fi = iptr->sx.s23.s3.fmiref->p.field;
1580 fieldtype = fi->type;
1584 #if !defined(ENABLE_SOFTFLOAT)
1585 /* HACK: softnull checks on floats */
1586 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1587 emit_nullpointer_check_force(cd, iptr, s1);
1590 switch (fieldtype) {
1592 #if defined(ENABLE_SOFTFLOAT)
1596 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1598 #if defined(ENABLE_SOFTFLOAT)
1599 case TYPE_DBL: /* fall through */
1602 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1604 #if !defined(ENABLE_SOFTFLOAT)
1607 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1614 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1616 uf = iptr->sx.s23.s3.uf;
1618 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1621 switch (fieldtype) {
1623 #if defined(ENABLE_SOFTFLOAT)
1627 M_IST(s2, s1, disp);
1630 #if defined(ENABLE_SOFTFLOAT)
1633 M_LST(s2, s1, disp);
1635 #if !defined(ENABLE_SOFTFLOAT)
1637 M_FST(s2, s1, disp);
1640 M_DST(s2, s1, disp);
1649 /* branch operations **************************************************/
1651 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1653 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1654 M_INTMOVE(s1, REG_ITMP1_XPTR);
1655 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1656 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1657 iptr->sx.s23.s2.uc, 0);
1659 disp = dseg_add_functionptr(cd, asm_handle_exception);
1660 M_DSEG_LOAD(REG_ITMP3, disp);
1661 M_MOV(REG_ITMP2_XPC, REG_PC);
1662 M_MOV(REG_PC, REG_ITMP3);
1663 M_NOP; /* nop ensures that XPC is less than the end */
1664 /* of basic block */
1667 case ICMD_GOTO: /* ... ==> ... */
1670 emit_br(cd, iptr->dst.block);
1673 case ICMD_JSR: /* ... ==> ... */
1675 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1678 case ICMD_IFNULL: /* ..., value ==> ... */
1679 case ICMD_IFNONNULL:
1681 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1683 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1686 case ICMD_IFLT: /* ..., value ==> ... */
1687 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1693 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1694 M_COMPARE(s1, iptr->sx.val.i);
1695 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1698 case ICMD_IF_LEQ: /* ..., value ==> ... */
1700 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1701 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1702 if (iptr->sx.val.l == 0) {
1703 M_ORR_S(s1, s2, REG_ITMP3);
1706 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1707 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1708 M_CMP(s1, REG_ITMP3);*/
1709 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1710 M_CMPEQ(s2, REG_ITMP3);
1712 emit_beq(cd, iptr->dst.block);
1715 case ICMD_IF_LLT: /* ..., value ==> ... */
1717 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1718 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1719 if (iptr->sx.val.l == 0) {
1720 /* if high word is less than zero, the whole long is too */
1722 emit_blt(cd, iptr->dst.block);
1725 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1726 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1727 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1728 M_CMP(s1, REG_ITMP3);*/
1729 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1730 M_MOVGT_IMM(2, REG_ITMP1);
1731 M_MOVEQ_IMM(1, REG_ITMP1);
1733 /* low compare: x=x-1(ifLO) */
1734 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1735 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1736 M_CMP(s2, REG_ITMP3);*/
1737 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1739 /* branch if (x LT 1) */
1740 M_CMP_IMM(REG_ITMP1, 1);
1741 emit_blt(cd, iptr->dst.block);
1745 case ICMD_IF_LLE: /* ..., value ==> ... */
1747 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1748 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1749 if (iptr->sx.val.l == 0) {
1750 /* if high word is less than zero, the whole long is too */
1752 emit_blt(cd, iptr->dst.block);
1754 /* ... otherwise the low word has to be zero (tricky!) */
1756 emit_beq(cd, iptr->dst.block);
1759 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1760 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1761 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1762 M_CMP(s1, REG_ITMP3);*/
1763 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1764 M_MOVGT_IMM(2, REG_ITMP1);
1765 M_MOVEQ_IMM(1, REG_ITMP1);
1767 /* low compare: x=x+1(ifHI) */
1768 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1769 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1770 M_CMP(s2, REG_ITMP3);*/
1771 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1773 /* branch if (x LE 1) */
1774 M_CMP_IMM(REG_ITMP1, 1);
1775 emit_ble(cd, iptr->dst.block);
1779 case ICMD_IF_LGE: /* ..., value ==> ... */
1781 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1782 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1783 if (iptr->sx.val.l == 0) {
1784 /* if high word is greater or equal zero, the whole long is too */
1786 emit_bge(cd, iptr->dst.block);
1789 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1790 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1791 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1792 M_CMP(s1, REG_ITMP3);*/
1793 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1794 M_MOVGT_IMM(2, REG_ITMP1);
1795 M_MOVEQ_IMM(1, REG_ITMP1);
1797 /* low compare: x=x-1(ifLO) */
1798 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1799 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1800 M_CMP(s2, REG_ITMP3);*/
1801 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1803 /* branch if (x GE 1) */
1804 M_CMP_IMM(REG_ITMP1, 1);
1805 emit_bge(cd, iptr->dst.block);
1809 case ICMD_IF_LGT: /* ..., value ==> ... */
1811 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1812 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1814 if (iptr->sx.val.l == 0) {
1815 /* if high word is greater than zero, the whole long is too */
1818 codegen_add_branch_ref(cd, iptr->dst.block);
1820 /* ... or high was zero and low is non zero (tricky!) */
1821 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1822 M_MOVLT_IMM(1, REG_ITMP3);
1823 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1825 codegen_add_branch_ref(cd, iptr->dst.block);
1829 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1830 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1831 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1832 M_CMP(s1, REG_ITMP3);*/
1833 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1834 M_MOVGT_IMM(2, REG_ITMP1);
1835 M_MOVEQ_IMM(1, REG_ITMP1);
1837 /* low compare: x=x+1(ifHI) */
1838 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1839 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1840 M_CMP(s2, REG_ITMP3);*/
1841 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1843 /* branch if (x GT 1) */
1844 M_CMP_IMM(REG_ITMP1, 1);
1845 emit_bgt(cd, iptr->dst.block);
1851 case ICMD_IF_LNE: /* ..., value ==> ... */
1853 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1854 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1855 if (iptr->sx.val.l == 0) {
1856 M_ORR_S(s1, s2, REG_ITMP3);
1859 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1860 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1861 M_CMP(s1, REG_ITMP3);*/
1862 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1863 M_CMPEQ(s2, REG_ITMP3);
1865 emit_bne(cd, iptr->dst.block);
1868 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1869 case ICMD_IF_ICMPNE:
1870 case ICMD_IF_ICMPLT:
1871 case ICMD_IF_ICMPLE:
1872 case ICMD_IF_ICMPGT:
1873 case ICMD_IF_ICMPGE:
1875 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1876 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1878 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1881 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1882 case ICMD_IF_ACMPNE:
1884 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1885 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1887 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1890 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1891 /* op1 = target JavaVM pc */
1893 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1894 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1897 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1898 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1901 emit_beq(cd, iptr->dst.block);
1904 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1905 /* op1 = target JavaVM pc */
1907 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1908 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1911 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1912 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1915 emit_bne(cd, iptr->dst.block);
1918 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1919 /* op1 = target JavaVM pc */
1921 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1922 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1923 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1925 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1926 M_MOVGT_IMM(2, REG_ITMP3);
1927 M_MOVEQ_IMM(1, REG_ITMP3);
1929 /* low compare: x=x-1(ifLO) */
1930 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1931 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1933 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1935 /* branch if (x LT 1) */
1936 M_CMP_IMM(REG_ITMP3, 1);
1937 emit_blt(cd, iptr->dst.block);
1940 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1941 /* op1 = target JavaVM pc */
1943 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1944 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1945 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1947 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1948 M_MOVGT_IMM(2, REG_ITMP3);
1949 M_MOVEQ_IMM(1, REG_ITMP3);
1951 /* low compare: x=x-1(ifLO) */
1952 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1953 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1955 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1957 /* branch if (x LE 1) */
1958 M_CMP_IMM(REG_ITMP3, 1);
1959 emit_ble(cd, iptr->dst.block);
1962 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1963 /* op1 = target JavaVM pc */
1965 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1966 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1967 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1969 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1970 M_MOVGT_IMM(2, REG_ITMP3);
1971 M_MOVEQ_IMM(1, REG_ITMP3);
1973 /* low compare: x=x-1(ifLO) */
1974 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1975 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1977 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1979 /* branch if (x GT 1) */
1980 M_CMP_IMM(REG_ITMP3, 1);
1981 emit_bgt(cd, iptr->dst.block);
1984 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1985 /* op1 = target JavaVM pc */
1987 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1988 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1989 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1991 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1992 M_MOVGT_IMM(2, REG_ITMP3);
1993 M_MOVEQ_IMM(1, REG_ITMP3);
1995 /* low compare: x=x-1(ifLO) */
1996 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1997 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1999 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2001 /* branch if (x GE 1) */
2002 M_CMP_IMM(REG_ITMP3, 1);
2003 emit_bge(cd, iptr->dst.block);
2006 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2009 branch_target_t *table;
2011 table = iptr->dst.table;
2013 l = iptr->sx.s23.s2.tablelow;
2014 i = iptr->sx.s23.s3.tablehigh;
2016 /* calculate new index (index - low) */
2017 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2019 M_INTMOVE(s1, REG_ITMP1);
2020 } else if (IS_IMM(l)) {
2021 M_SUB_IMM(REG_ITMP1, s1, l);
2023 ICONST(REG_ITMP2, l);
2024 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2027 /* range check (index <= high-low) */
2029 M_COMPARE(REG_ITMP1, i-1);
2030 emit_bugt(cd, table[0].block);
2032 /* build jump table top down and use address of lowest entry */
2037 dseg_add_target(cd, table->block);
2042 /* length of dataseg after last dseg_add_target is used by load */
2043 /* TODO: this loads from data-segment */
2044 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2045 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2048 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2051 lookup_target_t *lookup;
2053 lookup = iptr->dst.lookup;
2055 i = iptr->sx.s23.s2.lookupcount;
2058 MCODECHECK((i<<2)+8);
2059 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2062 M_COMPARE(s1, lookup->value);
2063 emit_beq(cd, lookup->target.block);
2067 /* default branch */
2068 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2072 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2074 #if !defined(ENABLE_SOFTFLOAT)
2075 REPLACEMENT_POINT_RETURN(cd, iptr);
2076 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2077 M_CAST_F2I(s1, REG_RESULT);
2078 goto ICMD_RETURN_do;
2081 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2083 REPLACEMENT_POINT_RETURN(cd, iptr);
2084 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2085 M_INTMOVE(s1, REG_RESULT);
2086 goto ICMD_RETURN_do;
2088 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2090 #if !defined(ENABLE_SOFTFLOAT)
2091 REPLACEMENT_POINT_RETURN(cd, iptr);
2092 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2093 M_CAST_D2L(s1, REG_RESULT_PACKED);
2094 goto ICMD_RETURN_do;
2097 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2099 REPLACEMENT_POINT_RETURN(cd, iptr);
2100 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2101 M_LNGMOVE(s1, REG_RESULT_PACKED);
2102 goto ICMD_RETURN_do;
2104 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2106 REPLACEMENT_POINT_RETURN(cd, iptr);
2107 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2108 M_INTMOVE(s1, REG_RESULT);
2109 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2110 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2111 iptr->sx.s23.s2.uc, 0);
2113 goto ICMD_RETURN_do;
2115 case ICMD_RETURN: /* ... ==> ... */
2117 REPLACEMENT_POINT_RETURN(cd, iptr);
2120 #if !defined(NDEBUG)
2121 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2122 emit_verbosecall_exit(jd);
2125 #if defined(ENABLE_THREADS)
2126 /* call monitorexit function */
2128 if (checksync && code_is_synchronized(code)) {
2129 /* stack offset for monitor argument */
2131 s1 = rd->memuse * 8;
2133 /* we need to save the proper return value */
2135 switch (iptr->opc) {
2139 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2141 M_STMFD(BITMASK_RESULT, REG_SP);
2146 M_LDR(REG_A0, REG_SP, s1);
2147 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2148 M_DSEG_BRANCH(disp);
2150 /* we no longer need PV here, no more loading */
2151 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2152 M_RECOMPUTE_PV(s1);*/
2154 switch (iptr->opc) {
2158 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2160 M_LDMFD(BITMASK_RESULT, REG_SP);
2166 /* deallocate stackframe for spilled variables */
2168 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2169 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2171 /* restore callee saved registers + do return */
2173 if (savedregs_bitmask) {
2174 if (!code_is_leafmethod(code)) {
2175 savedregs_bitmask &= ~(1<<REG_LR);
2176 savedregs_bitmask |= (1<<REG_PC);
2178 M_LDMFD(savedregs_bitmask, REG_SP);
2181 /* if LR was not on stack, we need to return manually */
2183 if (code_is_leafmethod(code))
2184 M_MOV(REG_PC, REG_LR);
2187 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2189 bte = iptr->sx.s23.s3.bte;
2191 goto ICMD_INVOKE_do;
2193 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2194 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2195 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2196 case ICMD_INVOKEINTERFACE:
2198 REPLACEMENT_POINT_INVOKE(cd, iptr);
2200 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2202 um = iptr->sx.s23.s3.um;
2203 md = um->methodref->parseddesc.md;
2206 lm = iptr->sx.s23.s3.fmiref->p.method;
2208 md = lm->parseddesc;
2212 /* copy arguments to registers or stack location */
2214 s3 = md->paramcount;
2216 MCODECHECK((s3 << 1) + 64);
2218 for (s3 = s3 - 1; s3 >= 0; s3--) {
2219 var = VAR(iptr->sx.s23.s2.args[s3]);
2220 d = md->params[s3].regoff;
2222 if (var->flags & PREALLOC) /* argument was precolored? */
2225 /* TODO: document me */
2226 #if !defined(ENABLE_SOFTFLOAT)
2227 if (IS_INT_LNG_TYPE(var->type)) {
2228 #endif /* !defined(ENABLE_SOFTFLOAT) */
2229 if (!md->params[s3].inmemory) {
2230 s1 = emit_load(jd, iptr, var, d);
2232 if (IS_2_WORD_TYPE(var->type))
2238 if (IS_2_WORD_TYPE(var->type)) {
2239 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2240 M_LST(s1, REG_SP, d);
2243 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2244 M_IST(s1, REG_SP, d);
2247 #if !defined(ENABLE_SOFTFLOAT)
2250 if (!md->params[s3].inmemory) {
2251 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2252 if (IS_2_WORD_TYPE(var->type))
2258 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2259 if (IS_2_WORD_TYPE(var->type))
2260 M_DST(s1, REG_SP, d);
2262 M_FST(s1, REG_SP, d);
2265 #endif /* !defined(ENABLE_SOFTFLOAT) */
2268 switch (iptr->opc) {
2271 if (bte->stub == NULL) {
2272 disp = dseg_add_functionptr(cd, bte->fp);
2274 disp = dseg_add_functionptr(cd, bte->stub);
2277 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2279 /* generate the actual call */
2281 M_MOV(REG_LR, REG_PC);
2282 M_MOV(REG_PC, REG_PV);
2283 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2287 case ICMD_INVOKESPECIAL:
2288 emit_nullpointer_check(cd, iptr, REG_A0);
2291 case ICMD_INVOKESTATIC:
2293 disp = dseg_add_unique_address(cd, NULL);
2295 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2299 disp = dseg_add_address(cd, lm->stubroutine);
2301 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2303 /* generate the actual call */
2305 M_MOV(REG_LR, REG_PC);
2306 M_MOV(REG_PC, REG_PV);
2307 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2311 case ICMD_INVOKEVIRTUAL:
2313 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2318 s1 = OFFSET(vftbl_t, table[0]) +
2319 sizeof(methodptr) * lm->vftblindex;
2321 /* implicit null-pointer check */
2322 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2323 OFFSET(java_object_t, vftbl));
2324 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2326 /* generate the actual call */
2328 M_MOV(REG_LR, REG_PC);
2329 M_MOV(REG_PC, REG_PV);
2330 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2334 case ICMD_INVOKEINTERFACE:
2336 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2342 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2343 sizeof(methodptr*) * lm->class->index;
2344 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2347 /* implicit null-pointer check */
2348 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2349 OFFSET(java_object_t, vftbl));
2350 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2351 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2353 /* generate the actual call */
2355 M_MOV(REG_LR, REG_PC);
2356 M_MOV(REG_PC, REG_PV);
2357 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2362 /* store size of call code in replacement point */
2363 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2365 /* store return value */
2367 d = md->returntype.type;
2369 #if !defined(__SOFTFP__)
2370 /* TODO: this is only a hack, since we use R0/R1 for float
2371 return! this depends on gcc; it is independent from
2372 our ENABLE_SOFTFLOAT define */
2373 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2374 #if 0 && !defined(NDEBUG)
2375 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2377 /* we cannot use this macro, since it is not defined
2378 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2379 REG_FRESULT, REG_RESULT_TYPED(d)); */
2380 if (IS_2_WORD_TYPE(d)) {
2381 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2382 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2384 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2385 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2390 if (d != TYPE_VOID) {
2391 #if !defined(ENABLE_SOFTFLOAT)
2392 if (IS_INT_LNG_TYPE(d)) {
2393 #endif /* !defined(ENABLE_SOFTFLOAT) */
2394 if (IS_2_WORD_TYPE(d)) {
2395 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2396 M_LNGMOVE(REG_RESULT_PACKED, s1);
2399 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2400 M_INTMOVE(REG_RESULT, s1);
2403 #if !defined(ENABLE_SOFTFLOAT)
2405 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2406 if (IS_2_WORD_TYPE(d))
2407 M_CAST_L2D(REG_RESULT_PACKED, s1);
2409 M_CAST_I2F(REG_RESULT, s1);
2411 #endif /* !defined(ENABLE_SOFTFLOAT) */
2413 emit_store_dst(jd, iptr, s1);
2417 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2419 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2420 /* object type cast-check */
2425 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2430 super = iptr->sx.s23.s3.c.cls;
2431 superindex = super->index;
2434 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2435 CODEGEN_CRITICAL_SECTION_NEW;
2437 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2439 /* if class is not resolved, check which code to call */
2441 if (super == NULL) {
2443 emit_label_beq(cd, BRANCH_LABEL_1);
2445 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2446 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2447 iptr->sx.s23.s3.c.ref, disp);
2449 M_DSEG_LOAD(REG_ITMP2, disp);
2450 disp = dseg_add_s4(cd, ACC_INTERFACE);
2451 M_DSEG_LOAD(REG_ITMP3, disp);
2452 M_TST(REG_ITMP2, REG_ITMP3);
2453 emit_label_beq(cd, BRANCH_LABEL_2);
2456 /* interface checkcast code */
2458 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2459 if ((super == NULL) || !IS_IMM(superindex)) {
2460 disp = dseg_add_unique_s4(cd, superindex);
2462 if (super == NULL) {
2463 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2464 iptr->sx.s23.s3.c.ref, disp);
2468 emit_label_beq(cd, BRANCH_LABEL_3);
2471 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2472 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2474 /* we put unresolved or non-immediate superindices onto dseg */
2475 if ((super == NULL) || !IS_IMM(superindex)) {
2476 /* disp was computed before we added the patcher */
2477 M_DSEG_LOAD(REG_ITMP2, disp);
2478 M_CMP(REG_ITMP3, REG_ITMP2);
2480 assert(IS_IMM(superindex));
2481 M_CMP_IMM(REG_ITMP3, superindex);
2484 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2486 /* if we loaded the superindex out of the dseg above, we do
2487 things differently here! */
2488 if ((super == NULL) || !IS_IMM(superindex)) {
2490 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2492 /* this assumes something */
2493 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2495 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2496 assert(sizeof(methodptr*) == 4);
2497 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2503 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2504 superindex * sizeof(methodptr*);
2508 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2509 M_TST(REG_ITMP3, REG_ITMP3);
2510 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2513 emit_label_br(cd, BRANCH_LABEL_4);
2515 emit_label(cd, BRANCH_LABEL_3);
2518 /* class checkcast code */
2520 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2521 if (super == NULL) {
2522 emit_label(cd, BRANCH_LABEL_2);
2524 disp = dseg_add_unique_address(cd, NULL);
2526 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2527 iptr->sx.s23.s3.c.ref,
2531 disp = dseg_add_address(cd, super->vftbl);
2534 emit_label_beq(cd, BRANCH_LABEL_5);
2537 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2538 M_DSEG_LOAD(REG_ITMP3, disp);
2540 CODEGEN_CRITICAL_SECTION_START;
2542 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2543 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2544 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2545 M_DSEG_LOAD(REG_ITMP3, disp);
2546 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2548 CODEGEN_CRITICAL_SECTION_END;
2550 M_CMP(REG_ITMP2, REG_ITMP3);
2551 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2554 emit_label(cd, BRANCH_LABEL_5);
2557 if (super == NULL) {
2558 emit_label(cd, BRANCH_LABEL_1);
2559 emit_label(cd, BRANCH_LABEL_4);
2562 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2565 /* array type cast-check */
2567 s1 = emit_load_s1(jd, iptr, REG_A0);
2568 M_INTMOVE(s1, REG_A0);
2570 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2571 disp = dseg_add_unique_address(cd, NULL);
2573 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2574 iptr->sx.s23.s3.c.ref,
2578 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2580 M_DSEG_LOAD(REG_A1, disp);
2581 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2582 M_DSEG_BRANCH(disp);
2585 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2586 M_RECOMPUTE_PV(disp);
2588 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2589 M_TST(REG_RESULT, REG_RESULT);
2590 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2592 d = codegen_reg_of_dst(jd, iptr, s1);
2596 emit_store_dst(jd, iptr, d);
2599 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2605 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2610 super = iptr->sx.s23.s3.c.cls;
2611 superindex = super->index;
2614 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2615 CODEGEN_CRITICAL_SECTION_NEW;
2617 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2618 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2621 M_MOV(REG_ITMP1, s1);
2625 /* if class is not resolved, check which code to call */
2627 if (super == NULL) {
2631 emit_label_beq(cd, BRANCH_LABEL_1);
2633 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2634 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2635 iptr->sx.s23.s3.c.ref, disp);
2637 M_DSEG_LOAD(REG_ITMP2, disp);
2638 disp = dseg_add_s4(cd, ACC_INTERFACE);
2639 M_DSEG_LOAD(REG_ITMP3, disp);
2640 M_TST(REG_ITMP2, REG_ITMP3);
2641 emit_label_beq(cd, BRANCH_LABEL_2);
2644 /* interface checkcast code */
2646 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2647 if ((super == NULL) || !IS_IMM(superindex)) {
2648 disp = dseg_add_unique_s4(cd, superindex);
2650 if (super == NULL) {
2651 /* If d == REG_ITMP2, then it's destroyed in check
2656 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2657 iptr->sx.s23.s3.c.ref, disp);
2662 emit_label_beq(cd, BRANCH_LABEL_3);
2665 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2666 M_LDR_INTERN(REG_ITMP3,
2667 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2669 /* we put unresolved or non-immediate superindices onto dseg
2670 and do things slightly different */
2671 if ((super == NULL) || !IS_IMM(superindex)) {
2672 /* disp was computed before we added the patcher */
2673 M_DSEG_LOAD(REG_ITMP2, disp);
2674 M_CMP(REG_ITMP3, REG_ITMP2);
2676 if (d == REG_ITMP2) {
2683 /* this assumes something */
2684 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2686 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2687 assert(sizeof(methodptr*) == 4);
2688 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2690 if (d == REG_ITMP2) {
2697 assert(IS_IMM(superindex));
2698 M_CMP_IMM(REG_ITMP3, superindex);
2702 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2703 superindex * sizeof(methodptr*);
2707 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2708 M_TST(REG_ITMP3, REG_ITMP3);
2712 emit_label_br(cd, BRANCH_LABEL_4);
2714 emit_label(cd, BRANCH_LABEL_3);
2717 /* class checkcast code */
2719 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2720 if (super == NULL) {
2721 emit_label(cd, BRANCH_LABEL_2);
2723 disp = dseg_add_unique_address(cd, NULL);
2725 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2726 iptr->sx.s23.s3.c.ref, disp);
2729 disp = dseg_add_address(cd, super->vftbl);
2733 emit_label_beq(cd, BRANCH_LABEL_5);
2736 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2737 M_DSEG_LOAD(REG_ITMP2, disp);
2739 CODEGEN_CRITICAL_SECTION_START;
2741 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2742 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2743 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2745 CODEGEN_CRITICAL_SECTION_END;
2747 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2748 M_CMP(REG_ITMP1, REG_ITMP2);
2749 /* If d == REG_ITMP2, then it's destroyed */
2755 emit_label(cd, BRANCH_LABEL_5);
2758 if (super == NULL) {
2759 emit_label(cd, BRANCH_LABEL_1);
2760 emit_label(cd, BRANCH_LABEL_4);
2765 emit_store_dst(jd, iptr, d);
2768 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2770 /* copy sizes to stack if necessary */
2772 MCODECHECK((iptr->s1.argcount << 1) + 64);
2774 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2776 var = VAR(iptr->sx.s23.s2.args[s1]);
2778 /* copy SAVEDVAR sizes to stack */
2780 if (!(var->flags & PREALLOC)) {
2781 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2782 M_STR(s2, REG_SP, s1 * 4);
2786 /* a0 = dimension count */
2788 assert(IS_IMM(iptr->s1.argcount));
2789 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2791 /* is patcher function set? */
2793 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2794 disp = dseg_add_unique_address(cd, NULL);
2796 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2797 iptr->sx.s23.s3.c.ref, disp);
2800 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2802 /* a1 = arraydescriptor */
2804 M_DSEG_LOAD(REG_A1, disp);
2806 /* a2 = pointer to dimensions = stack pointer */
2808 M_INTMOVE(REG_SP, REG_A2);
2810 /* call builtin_multianewarray here */
2812 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2813 M_DSEG_BRANCH(disp);
2817 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2820 /* check for exception before result assignment */
2822 emit_exception_check(cd, iptr);
2826 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2827 M_INTMOVE(REG_RESULT, d);
2828 emit_store_dst(jd, iptr, d);
2831 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2833 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2834 emit_nullpointer_check(cd, iptr, s1);
2838 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2841 } /* the big switch */
2843 } /* for all instructions */
2845 } /* for all basic blocks */
2847 dseg_createlinenumbertable(cd);
2850 /* generate traps */
2852 emit_patcher_traps(jd);
2854 /* everything's ok */
2860 /* codegen_emit_stub_compiler **************************************************
2862 Emits a stub routine which calls the compiler.
2864 *******************************************************************************/
2866 void codegen_emit_stub_compiler(jitdata *jd)
2871 /* get required compiler data */
2876 /* code for the stub */
2878 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2879 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2883 /* codegen_emit_stub_native ****************************************************
2885 Emits a stub routine which calls a native method.
2887 *******************************************************************************/
2889 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2900 /* get required compiler data */
2906 /* initialize variables */
2910 /* calculate stackframe size */
2912 cd->stackframesize =
2913 4 + /* return address */
2914 sizeof(stackframeinfo_t) + /* stackframeinfo */
2915 sizeof(localref_table) + /* localref_table */
2916 nmd->memuse * 4; /* stack arguments */
2918 /* align stack to 8-byte */
2920 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2922 /* create method header */
2924 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2925 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2926 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2927 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2928 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2929 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2930 (void) dseg_addlinenumbertablesize(cd);
2931 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2933 /* generate stub code */
2935 M_STMFD(1<<REG_LR, REG_SP);
2936 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2938 #if !defined(NDEBUG)
2939 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2940 emit_verbosecall_enter(jd);
2943 #if defined(ENABLE_GC_CACAO)
2944 /* Save callee saved integer registers in stackframeinfo (GC may
2945 need to recover them during a collection). */
2947 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2948 OFFSET(stackframeinfo_t, intregs);
2950 for (i = 0; i < INT_SAV_CNT; i++)
2951 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2954 /* Save integer and float argument registers (these are 4
2955 registers, stack is 8-byte aligned). */
2957 M_STMFD(BITMASK_ARGS, REG_SP);
2958 /* TODO: floating point */
2960 /* create native stackframe info */
2962 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2963 M_MOV(REG_A1, REG_PV);
2964 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2965 M_DSEG_BRANCH(disp);
2969 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2972 /* remember class argument */
2974 if (m->flags & ACC_STATIC)
2975 M_MOV(REG_ITMP3, REG_RESULT);
2977 /* Restore integer and float argument registers (these are 4
2978 registers, stack is 8-byte aligned). */
2980 M_LDMFD(BITMASK_ARGS, REG_SP);
2981 /* TODO: floating point */
2983 /* copy or spill arguments to new locations */
2984 /* ATTENTION: the ARM has only integer argument registers! */
2986 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2987 t = md->paramtypes[i].type;
2989 if (!md->params[i].inmemory) {
2990 s1 = md->params[i].regoff;
2991 s2 = nmd->params[j].regoff;
2993 if (!nmd->params[j].inmemory) {
2994 #if !defined(__ARM_EABI__)
2995 SPLIT_OPEN(t, s2, REG_ITMP1);
2998 if (IS_2_WORD_TYPE(t))
3003 #if !defined(__ARM_EABI__)
3004 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3008 if (IS_2_WORD_TYPE(t))
3009 M_LST(s1, REG_SP, s2);
3011 M_IST(s1, REG_SP, s2);
3015 s1 = md->params[i].regoff + cd->stackframesize;
3016 s2 = nmd->params[j].regoff;
3018 if (IS_2_WORD_TYPE(t)) {
3019 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3020 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3023 M_ILD(REG_ITMP1, REG_SP, s1);
3024 M_IST(REG_ITMP1, REG_SP, s2);
3029 /* Handle native Java methods. */
3031 if (m->flags & ACC_NATIVE) {
3032 /* put class into second argument register */
3034 if (m->flags & ACC_STATIC)
3035 M_MOV(REG_A1, REG_ITMP3);
3037 /* put env into first argument register */
3039 disp = dseg_add_address(cd, _Jv_env);
3040 M_DSEG_LOAD(REG_A0, disp);
3043 /* Call the native function. */
3045 disp = dseg_add_functionptr(cd, f);
3046 M_DSEG_BRANCH(disp);
3049 /* TODO: this is only needed because of the tracer ... do we
3052 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3055 #if !defined(__SOFTFP__)
3056 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3057 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3058 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3059 #if 0 && !defined(NDEBUG)
3060 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3062 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3063 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3064 if (IS_2_WORD_TYPE(md->returntype.type)) {
3065 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3066 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3068 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3069 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3074 #if !defined(NDEBUG)
3075 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3076 emit_verbosecall_exit(jd);
3079 /* remove native stackframe info */
3080 /* TODO: improve this store/load */
3082 M_STMFD(BITMASK_RESULT, REG_SP);
3084 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3085 M_MOV(REG_A1, REG_PV);
3086 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3087 M_DSEG_BRANCH(disp);
3088 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3091 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3092 M_LDMFD(BITMASK_RESULT, REG_SP);
3094 #if defined(ENABLE_GC_CACAO)
3095 /* restore callee saved int registers from stackframeinfo (GC might have */
3096 /* modified them during a collection). */
3098 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3099 OFFSET(stackframeinfo_t, intregs);
3101 for (i = 0; i < INT_SAV_CNT; i++)
3102 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3105 /* finish stub code, but do not yet return to caller */
3107 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3108 M_LDMFD(1<<REG_LR, REG_SP);
3110 /* check for exception */
3112 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3113 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3115 /* handle exception here */
3117 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3119 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3120 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3121 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3123 /* generate patcher stubs */
3125 emit_patcher_traps(jd);
3129 /* asm_debug *******************************************************************
3133 *******************************************************************************/
3135 void asm_debug(int a1, int a2, int a3, int a4)
3137 printf("===> i am going to exit after this debugging message!\n");
3138 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3139 vm_abort("leave you now");
3144 * These are local overrides for various environment variables in Emacs.
3145 * Please do not remove this and leave it at the end of the file, where
3146 * Emacs will automagically detect them.
3147 * ---------------------------------------------------------------------
3150 * indent-tabs-mode: t
3154 * vim:noexpandtab:sw=4:ts=4: