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 = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
124 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
125 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
126 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
128 spilledregs_num = rd->memuse;
130 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
131 if (checksync && (m->flags & ACC_SYNCHRONIZED))
135 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
137 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
138 only in native stubs. */
139 /* align stack to 8-byte */
141 cd->stackframesize = (cd->stackframesize + 4) & ~4;
143 /* SECTION: Method Header */
144 /* create method header */
146 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
147 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
149 #if defined(ENABLE_THREADS)
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
156 if (checksync && (m->flags & ACC_SYNCHRONIZED))
157 (void) dseg_add_unique_s4(cd, rd->memuse * 8 + 4);/* IsSync */
160 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
162 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
163 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
164 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
165 (void) dseg_addlinenumbertablesize(cd);
166 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
168 /* create exception table */
170 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
171 dseg_add_target(cd, ex->start);
172 dseg_add_target(cd, ex->end);
173 dseg_add_target(cd, ex->handler);
174 (void) dseg_add_unique_address(cd, ex->catchtype.any);
177 /* save return address and used callee saved registers */
179 savedregs_bitmask = 0;
181 if (!jd->isleafmethod)
182 savedregs_bitmask = (1<<REG_LR);
184 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
185 savedregs_bitmask |= (1<<(rd->savintregs[i]));
188 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
189 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
190 /* TODO: floating-point */
194 if (savedregs_bitmask)
195 M_STMFD(savedregs_bitmask, REG_SP);
197 /* create additional stack frame for spilled variables (if necessary) */
199 if ((cd->stackframesize / 4 - savedregs_num) > 0)
200 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
202 /* take arguments out of register or stack frame */
205 for (i = 0, len = 0; i < md->paramcount; i++) {
206 s1 = md->params[i].regoff;
207 t = md->paramtypes[i].type;
209 varindex = jd->local_map[len * 5 + t];
211 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
213 if (varindex == UNUSED)
218 /* ATTENTION: we use interger registers for all arguments (even float) */
219 #if !defined(ENABLE_SOFTFLOAT)
220 if (IS_INT_LNG_TYPE(t)) {
222 if (!md->params[i].inmemory) {
223 if (!(var->flags & INMEMORY)) {
224 if (IS_2_WORD_TYPE(t))
225 M_LNGMOVE(s1, var->vv.regoff);
227 M_INTMOVE(s1, var->vv.regoff);
230 if (IS_2_WORD_TYPE(t))
231 M_LST(s1, REG_SP, var->vv.regoff);
233 M_IST(s1, REG_SP, var->vv.regoff);
236 else { /* stack arguments */
237 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
238 if (IS_2_WORD_TYPE(t))
239 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
241 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
243 else { /* stack arg -> spilled */
244 /* Reuse Memory Position on Caller Stack */
245 var->vv.regoff = cd->stackframesize + s1;
248 #if !defined(ENABLE_SOFTFLOAT)
251 if (!md->params[i].inmemory) {
252 if (!(var->flags & INMEMORY)) {
253 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
256 if (IS_2_WORD_TYPE(t))
257 M_LST(s1, REG_SP, var->vv.regoff);
259 M_IST(s1, REG_SP, var->vv.regoff);
263 if (!(var->flags & INMEMORY)) {
264 if (IS_2_WORD_TYPE(t))
265 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
267 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
270 /* Reuse Memory Position on Caller Stack */
271 var->vv.regoff = cd->stackframesize + s1;
275 #endif /* !defined(ENABLE_SOFTFLOAT) */
278 #if defined(ENABLE_THREADS)
279 /* call monitorenter function */
281 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
282 /* stack offset for monitor argument */
286 # if !defined(NDEBUG)
287 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
288 M_STMFD(BITMASK_ARGS, REG_SP);
293 /* get the correct lock object */
295 if (m->flags & ACC_STATIC) {
296 disp = dseg_add_address(cd, &m->class->object.header);
297 M_DSEG_LOAD(REG_A0, disp);
300 emit_nullpointer_check_force(cd, iptr, REG_A0);
303 M_STR(REG_A0, REG_SP, s1);
304 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
306 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
309 # if !defined(NDEBUG)
310 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
311 M_LDMFD(BITMASK_ARGS, REG_SP);
317 /* call trace function */
319 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
320 emit_verbosecall_enter(jd);
323 /* end of header generation */
325 /* create replacement points */
326 REPLACEMENT_POINTS_INIT(cd, jd);
328 /* SECTION: ICMD Code Generation */
329 /* for all basic blocks */
331 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
333 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
335 /* is this basic block reached? */
337 if (bptr->flags < BBREACHED)
340 /* branch resolving */
342 codegen_resolve_branchrefs(cd, bptr);
344 /* handle replacement points */
345 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
347 /* copy interface registers to their destination */
353 #if defined(ENABLE_LSRA)
357 var = VAR(bptr->invars[len]);
358 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
359 if (!(var->flags & INMEMORY))
363 M_INTMOVE(REG_ITMP1, d);
364 emit_store(jd, NULL, var, d);
371 var = VAR(bptr->invars[len]);
373 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
374 d = codegen_reg_of_var(0, var, REG_ITMP1);
375 M_INTMOVE(REG_ITMP1, d);
376 emit_store(jd, NULL, var, d);
379 assert((var->flags & INOUT));
382 #if defined(ENABLE_LSRA)
386 /* for all instructions */
389 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
391 /* add line number */
392 if (iptr->line != currentline) {
393 dseg_addlinenumber(cd, iptr->line);
394 currentline = iptr->line;
397 MCODECHECK(64); /* an instruction usually needs < 64 words */
401 case ICMD_NOP: /* ... ==> ... */
404 /* constant operations ************************************************/
406 case ICMD_ICONST: /* ... ==> ..., constant */
408 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
409 ICONST(d, iptr->sx.val.i);
410 emit_store_dst(jd, iptr, d);
413 case ICMD_ACONST: /* ... ==> ..., constant */
415 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
416 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
417 disp = dseg_add_unique_address(cd, NULL);
419 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
420 iptr->sx.val.c.ref, disp);
422 M_DSEG_LOAD(d, disp);
425 ICONST(d, (u4) iptr->sx.val.anyptr);
427 emit_store_dst(jd, iptr, d);
430 case ICMD_LCONST: /* ... ==> ..., constant */
432 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
433 LCONST(d, iptr->sx.val.l);
434 emit_store_dst(jd, iptr, d);
437 case ICMD_FCONST: /* ... ==> ..., constant */
439 #if defined(ENABLE_SOFTFLOAT)
440 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
441 ICONST(d, iptr->sx.val.i);
442 emit_store_dst(jd, iptr, d);
444 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
445 FCONST(d, iptr->sx.val.f);
446 emit_store_dst(jd, iptr, d);
450 case ICMD_DCONST: /* ... ==> ..., constant */
452 #if defined(ENABLE_SOFTFLOAT)
453 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
454 LCONST(d, iptr->sx.val.l);
455 emit_store_dst(jd, iptr, d);
457 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
458 DCONST(d, iptr->sx.val.d);
459 emit_store_dst(jd, iptr, d);
464 /* load/store/copy/move operations ************************************/
466 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
467 case ICMD_ALOAD: /* op1 = local variable */
471 case ICMD_ISTORE: /* ..., value ==> ... */
482 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
486 /* pop operations *****************************************************/
488 /* attention: double and longs are only one entry in CACAO ICMDs */
490 case ICMD_POP: /* ..., value ==> ... */
491 case ICMD_POP2: /* ..., value, value ==> ... */
496 /* integer operations *************************************************/
498 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
500 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
501 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
502 M_MOV(d, REG_LSL(s1, 24));
503 M_MOV(d, REG_ASR(d, 24));
504 emit_store_dst(jd, iptr, d);
507 case ICMD_INT2CHAR: /* ..., 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, 16));
512 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
513 emit_store_dst(jd, iptr, d);
516 case ICMD_INT2SHORT: /* ..., 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_ASR(d, 16));
522 emit_store_dst(jd, iptr, d);
525 case ICMD_I2L: /* ..., value ==> ..., value */
527 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
528 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
529 M_INTMOVE(s1, GET_LOW_REG(d));
530 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
531 emit_store_dst(jd, iptr, d);
534 case ICMD_L2I: /* ..., value ==> ..., value */
536 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
539 emit_store_dst(jd, iptr, d);
542 case ICMD_INEG: /* ..., value ==> ..., - value */
544 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
545 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
547 emit_store_dst(jd, iptr, d);
550 case ICMD_LNEG: /* ..., value ==> ..., - value */
552 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
553 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
554 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
555 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
556 emit_store_dst(jd, iptr, d);
559 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
561 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
562 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
565 emit_store_dst(jd, iptr, d);
568 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
570 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
571 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
572 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
573 M_ADD_S(GET_LOW_REG(d), s1, s2);
574 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
575 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
576 M_ADC(GET_HIGH_REG(d), s1, s2);
577 emit_store_dst(jd, iptr, d);
583 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
584 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
586 if (IS_IMM(iptr->sx.val.i)) {
587 M_ADD_IMM(d, s1, iptr->sx.val.i);
588 } else if (IS_IMM(-iptr->sx.val.i)) {
589 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
591 ICONST(REG_ITMP3, iptr->sx.val.i);
592 M_ADD(d, s1, REG_ITMP3);
595 emit_store_dst(jd, iptr, d);
598 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
599 /* sx.val.l = constant */
601 s3 = iptr->sx.val.l & 0xffffffff;
602 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
603 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
605 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
607 ICONST(REG_ITMP3, s3);
608 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
610 s3 = iptr->sx.val.l >> 32;
611 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
613 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
615 ICONST(REG_ITMP3, s3);
616 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
618 emit_store_dst(jd, iptr, d);
621 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
623 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
624 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
625 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
627 emit_store_dst(jd, iptr, d);
630 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
632 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
633 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
634 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
635 M_SUB_S(GET_LOW_REG(d), s1, s2);
636 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
637 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
638 M_SBC(GET_HIGH_REG(d), s1, s2);
639 emit_store_dst(jd, iptr, d);
642 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
643 /* sx.val.i = constant */
645 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
646 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
647 if (IS_IMM(iptr->sx.val.i))
648 M_SUB_IMM(d, s1, iptr->sx.val.i);
650 ICONST(REG_ITMP3, iptr->sx.val.i);
651 M_SUB(d, s1, REG_ITMP3);
653 emit_store_dst(jd, iptr, d);
656 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
657 /* sx.val.l = constant */
659 s3 = iptr->sx.val.l & 0xffffffff;
660 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
661 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
663 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
665 ICONST(REG_ITMP3, s3);
666 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
668 s3 = iptr->sx.val.l >> 32;
669 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
671 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
673 ICONST(REG_ITMP3, s3);
674 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
676 emit_store_dst(jd, iptr, d);
679 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
681 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
682 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
683 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
685 emit_store_dst(jd, iptr, d);
688 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
689 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
691 s1 = emit_load_s1(jd, iptr, REG_A0);
692 s2 = emit_load_s2(jd, iptr, REG_A1);
693 emit_arithmetic_check(cd, iptr, s2);
695 /* move arguments into argument registers */
696 M_INTMOVE(s1, REG_A0);
697 M_INTMOVE(s2, REG_A1);
699 /* call builtin function */
700 bte = iptr->sx.s23.s3.bte;
701 disp = dseg_add_functionptr(cd, bte->fp);
705 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
708 /* move result into destination register */
709 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
710 M_INTMOVE(REG_RESULT, d);
711 emit_store_dst(jd, iptr, d);
714 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
715 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
717 /* move arguments into argument registers */
719 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
720 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
721 /* XXX TODO: only do this if arithmetic check is really done! */
722 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
723 emit_arithmetic_check(cd, iptr, REG_ITMP3);
725 M_LNGMOVE(s1, REG_A0_A1_PACKED);
726 M_LNGMOVE(s2, REG_A2_A3_PACKED);
728 /* call builtin function */
729 bte = iptr->sx.s23.s3.bte;
730 disp = dseg_add_functionptr(cd, bte->fp);
734 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
737 /* move result into destination register */
738 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
739 M_LNGMOVE(REG_RESULT_PACKED, d);
740 emit_store_dst(jd, iptr, d);
743 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
744 /* sx.val.i = constant */
746 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
747 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
748 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
749 emit_store_dst(jd, iptr, d);
752 case ICMD_IDIVPOW2: /* ..., 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 /* this rounds towards 0 as java likes it */
758 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
759 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
760 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
761 /* this rounds towards nearest, not java style */
762 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
763 M_ADCMI_IMM(d, d, 0);*/
764 emit_store_dst(jd, iptr, d);
767 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
768 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
770 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
771 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
772 M_MOV_S(REG_ITMP1, s1);
773 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
774 if (IS_IMM(iptr->sx.val.i))
775 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
777 ICONST(REG_ITMP3, iptr->sx.val.i);
778 M_AND(REG_ITMP1, REG_ITMP3, d);
780 M_RSBMI_IMM(d, d, 0);
781 emit_store_dst(jd, iptr, d);
784 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
786 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
787 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
788 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
789 M_AND_IMM(s2, 0x1f, REG_ITMP2);
790 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
791 emit_store_dst(jd, iptr, d);
794 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
796 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
797 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
798 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
799 M_AND_IMM(s2, 0x1f, REG_ITMP2);
800 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
801 emit_store_dst(jd, iptr, d);
804 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
806 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
807 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
808 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
809 M_AND_IMM(s2, 0x1f, REG_ITMP2);
810 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
811 emit_store_dst(jd, iptr, d);
814 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
815 /* sx.val.i = constant */
817 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
818 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
819 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
820 emit_store_dst(jd, iptr, d);
823 case ICMD_ISHRCONST: /* ..., 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_ITMP1);
828 /* we need to check for zero here because arm interprets it as SHR by 32 */
829 if ((iptr->sx.val.i & 0x1f) == 0) {
832 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
834 emit_store_dst(jd, iptr, d);
837 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
838 /* sx.val.i = constant */
840 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
841 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
842 /* we need to check for zero here because arm interprets it as SHR by 32 */
843 if ((iptr->sx.val.i & 0x1f) == 0)
846 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
847 emit_store_dst(jd, iptr, d);
850 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
852 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
853 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
854 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
856 emit_store_dst(jd, iptr, d);
859 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
861 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
862 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
863 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
864 M_AND(s1, s2, GET_LOW_REG(d));
865 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
866 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
867 M_AND(s1, s2, GET_HIGH_REG(d));
868 emit_store_dst(jd, iptr, d);
871 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
873 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
874 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
875 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
877 emit_store_dst(jd, iptr, d);
880 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
882 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
883 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
884 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
885 M_ORR(s1, s2, GET_LOW_REG(d));
886 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
887 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
888 M_ORR(s1, s2, GET_HIGH_REG(d));
889 emit_store_dst(jd, iptr, d);
892 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
894 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
895 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
896 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
898 emit_store_dst(jd, iptr, d);
901 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
903 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
904 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
905 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
906 M_EOR(s1, s2, GET_LOW_REG(d));
907 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
908 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
909 M_EOR(s1, s2, GET_HIGH_REG(d));
910 emit_store_dst(jd, iptr, d);
914 /* floating operations ************************************************/
916 #if !defined(ENABLE_SOFTFLOAT)
918 case ICMD_FNEG: /* ..., value ==> ..., - value */
920 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
921 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
923 emit_store_dst(jd, iptr, d);
926 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
928 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
929 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
930 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
932 emit_store_dst(jd, iptr, d);
935 case ICMD_FSUB: /* ..., 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_FMUL: /* ..., 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_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
954 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
955 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
956 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
958 emit_store_dst(jd, iptr, d);
961 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
964 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
966 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
967 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
968 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
970 emit_store_dst(jd, iptr, d);
973 case ICMD_DNEG: /* ..., value ==> ..., - value */
975 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
976 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
978 emit_store_dst(jd, iptr, d);
981 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
983 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
984 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
985 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
987 emit_store_dst(jd, iptr, d);
990 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
992 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
993 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
994 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
996 emit_store_dst(jd, iptr, d);
999 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1001 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1002 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1003 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1005 emit_store_dst(jd, iptr, d);
1008 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1010 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1011 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1012 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1014 emit_store_dst(jd, iptr, d);
1017 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1020 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1022 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1023 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1024 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1026 emit_store_dst(jd, iptr, d);
1029 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1031 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1032 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1034 emit_store_dst(jd, iptr, d);
1037 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1039 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1040 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1042 emit_store_dst(jd, iptr, d);
1045 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1047 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1048 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1049 /* this uses round towards zero, as Java likes it */
1051 /* this checks for NaN; to return zero as Java likes it */
1054 emit_store_dst(jd, iptr, d);
1057 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1059 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1060 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1061 /* this uses round towards zero, as Java likes it */
1063 /* this checks for NaN; to return zero as Java likes it */
1066 emit_store_dst(jd, iptr, d);
1069 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1071 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1072 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1074 emit_store_dst(jd, iptr, d);
1077 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1079 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1080 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1082 emit_store_dst(jd, iptr, d);
1085 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1087 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1088 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1089 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1092 M_SUBGT_IMM(d, d, 1);
1093 M_ADDLT_IMM(d, d, 1);
1094 emit_store_dst(jd, iptr, d);
1097 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1099 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1100 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1101 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1104 M_SUBGT_IMM(d, d, 1);
1105 M_ADDLT_IMM(d, d, 1);
1106 emit_store_dst(jd, iptr, d);
1109 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1111 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1112 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1113 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
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 M_SUBLT_IMM(d, d, 1);
1129 M_ADDGT_IMM(d, d, 1);
1130 emit_store_dst(jd, iptr, d);
1133 #endif /* !defined(ENABLE_SOFTFLOAT) */
1136 /* memory operations **************************************************/
1138 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1140 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1141 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1142 /* implicit null-pointer check */
1143 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1144 emit_store_dst(jd, iptr, d);
1147 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1149 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1150 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1151 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1152 /* implicit null-pointer check */
1153 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1154 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1155 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1156 emit_store_dst(jd, iptr, d);
1159 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1161 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1162 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1163 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1164 /* implicit null-pointer check */
1165 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1166 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1167 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1168 emit_store_dst(jd, iptr, d);
1171 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1173 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1174 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1175 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1176 /* implicit null-pointer check */
1177 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1178 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1179 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1180 emit_store_dst(jd, iptr, d);
1183 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1185 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1186 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1187 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1188 /* implicit null-pointer check */
1189 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1190 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1191 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1192 emit_store_dst(jd, iptr, d);
1195 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1197 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1198 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1199 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1200 /* implicit null-pointer check */
1201 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1202 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1203 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1204 emit_store_dst(jd, iptr, d);
1207 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1209 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1210 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1211 /* implicit null-pointer check */
1212 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1213 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1214 #if !defined(ENABLE_SOFTFLOAT)
1215 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1216 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1218 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1219 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1221 emit_store_dst(jd, iptr, d);
1224 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1226 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1227 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1228 /* implicit null-pointer check */
1229 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1230 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1231 #if !defined(ENABLE_SOFTFLOAT)
1232 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1233 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1235 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1236 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1238 emit_store_dst(jd, iptr, d);
1241 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1243 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1244 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1245 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1246 /* implicit null-pointer check */
1247 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1248 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1249 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1250 emit_store_dst(jd, iptr, d);
1253 case ICMD_BASTORE: /* ..., 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 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1260 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1261 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1264 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1266 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1267 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1268 /* implicit null-pointer check */
1269 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1270 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1271 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1272 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1275 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1277 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1278 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1279 /* implicit null-pointer check */
1280 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1281 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1282 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1283 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1286 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1288 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1289 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1290 /* implicit null-pointer check */
1291 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1292 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1293 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1294 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1297 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1299 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1300 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1301 /* implicit null-pointer check */
1302 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1303 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1304 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1305 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1308 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1310 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1311 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1312 /* implicit null-pointer check */
1313 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1314 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1315 #if !defined(ENABLE_SOFTFLOAT)
1316 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1317 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1319 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1320 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1324 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1326 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1327 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1328 /* implicit null-pointer check */
1329 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1330 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1331 #if !defined(ENABLE_SOFTFLOAT)
1332 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1333 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1335 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1336 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1340 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1342 s1 = emit_load_s1(jd, iptr, REG_A0);
1343 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1344 s3 = emit_load_s3(jd, iptr, REG_A1);
1346 /* implicit null-pointer check */
1347 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1349 /* move arguments to argument registers */
1350 M_INTMOVE(s1, REG_A0);
1351 M_INTMOVE(s3, REG_A1);
1353 /* call builtin function */
1354 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1355 M_DSEG_BRANCH(disp);
1358 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1361 /* check resturn value of builtin */
1362 emit_arraystore_check(cd, iptr);
1364 /* finally store address into array */
1365 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1366 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1367 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1368 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1369 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1372 case ICMD_GETSTATIC: /* ... ==> ..., value */
1374 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1375 uf = iptr->sx.s23.s3.uf;
1376 fieldtype = uf->fieldref->parseddesc.fd->type;
1377 disp = dseg_add_unique_address(cd, NULL);
1379 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1382 fi = iptr->sx.s23.s3.fmiref->p.field;
1383 fieldtype = fi->type;
1384 disp = dseg_add_address(cd, fi->value);
1386 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1387 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1392 M_DSEG_LOAD(REG_ITMP3, disp);
1393 switch (fieldtype) {
1395 #if defined(ENABLE_SOFTFLOAT)
1399 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1400 M_ILD_INTERN(d, REG_ITMP3, 0);
1403 #if defined(ENABLE_SOFTFLOAT)
1406 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1407 M_LLD_INTERN(d, REG_ITMP3, 0);
1409 #if !defined(ENABLE_SOFTFLOAT)
1411 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1412 M_FLD_INTERN(d, REG_ITMP3, 0);
1415 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1416 M_DLD_INTERN(d, REG_ITMP3, 0);
1422 emit_store_dst(jd, iptr, d);
1425 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1427 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1428 uf = iptr->sx.s23.s3.uf;
1429 fieldtype = uf->fieldref->parseddesc.fd->type;
1430 disp = dseg_add_unique_address(cd, NULL);
1432 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1435 fi = iptr->sx.s23.s3.fmiref->p.field;
1436 fieldtype = fi->type;
1437 disp = dseg_add_address(cd, fi->value);
1439 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1440 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1445 M_DSEG_LOAD(REG_ITMP3, disp);
1446 switch (fieldtype) {
1448 #if defined(ENABLE_SOFTFLOAT)
1452 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1453 M_IST_INTERN(s1, REG_ITMP3, 0);
1456 #if defined(ENABLE_SOFTFLOAT)
1459 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1460 M_LST_INTERN(s1, REG_ITMP3, 0);
1462 #if !defined(ENABLE_SOFTFLOAT)
1464 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1465 M_FST_INTERN(s1, REG_ITMP3, 0);
1468 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1469 M_DST_INTERN(s1, REG_ITMP3, 0);
1477 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1479 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1480 emit_nullpointer_check(cd, iptr, s1);
1483 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1484 uf = iptr->sx.s23.s3.uf;
1485 fieldtype = uf->fieldref->parseddesc.fd->type;
1489 fi = iptr->sx.s23.s3.fmiref->p.field;
1490 fieldtype = fi->type;
1494 #if !defined(ENABLE_SOFTFLOAT)
1495 /* HACK: softnull checks on floats */
1496 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1497 emit_nullpointer_check_force(cd, iptr, s1);
1500 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1502 uf = iptr->sx.s23.s3.uf;
1504 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1507 switch (fieldtype) {
1509 #if defined(ENABLE_SOFTFLOAT)
1513 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1517 #if defined(ENABLE_SOFTFLOAT)
1520 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1523 #if !defined(ENABLE_SOFTFLOAT)
1525 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1529 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1536 emit_store_dst(jd, iptr, d);
1539 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1541 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1542 emit_nullpointer_check(cd, iptr, s1);
1544 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1545 uf = iptr->sx.s23.s3.uf;
1546 fieldtype = uf->fieldref->parseddesc.fd->type;
1550 fi = iptr->sx.s23.s3.fmiref->p.field;
1551 fieldtype = fi->type;
1555 #if !defined(ENABLE_SOFTFLOAT)
1556 /* HACK: softnull checks on floats */
1557 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1558 emit_nullpointer_check_force(cd, iptr, s1);
1561 switch (fieldtype) {
1563 #if defined(ENABLE_SOFTFLOAT)
1567 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1569 #if defined(ENABLE_SOFTFLOAT)
1570 case TYPE_DBL: /* fall through */
1573 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1575 #if !defined(ENABLE_SOFTFLOAT)
1578 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1585 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1587 uf = iptr->sx.s23.s3.uf;
1589 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1592 switch (fieldtype) {
1594 #if defined(ENABLE_SOFTFLOAT)
1598 M_IST(s2, s1, disp);
1601 #if defined(ENABLE_SOFTFLOAT)
1604 M_LST(s2, s1, disp);
1606 #if !defined(ENABLE_SOFTFLOAT)
1608 M_FST(s2, s1, disp);
1611 M_DST(s2, s1, disp);
1620 /* branch operations **************************************************/
1622 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1624 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1625 M_INTMOVE(s1, REG_ITMP1_XPTR);
1626 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1627 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1628 iptr->sx.s23.s2.uc, 0);
1630 disp = dseg_add_functionptr(cd, asm_handle_exception);
1631 M_DSEG_LOAD(REG_ITMP3, disp);
1632 M_MOV(REG_ITMP2_XPC, REG_PC);
1633 M_MOV(REG_PC, REG_ITMP3);
1634 M_NOP; /* nop ensures that XPC is less than the end */
1635 /* of basic block */
1638 case ICMD_GOTO: /* ... ==> ... */
1641 emit_br(cd, iptr->dst.block);
1644 case ICMD_JSR: /* ... ==> ... */
1646 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1649 case ICMD_IFNULL: /* ..., value ==> ... */
1650 case ICMD_IFNONNULL:
1652 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1654 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1657 case ICMD_IFLT: /* ..., value ==> ... */
1658 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1664 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1665 M_COMPARE(s1, iptr->sx.val.i);
1666 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1669 case ICMD_IF_LEQ: /* ..., value ==> ... */
1671 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1672 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1673 if (iptr->sx.val.l == 0) {
1674 M_ORR_S(s1, s2, REG_ITMP3);
1677 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1678 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1679 M_CMP(s1, REG_ITMP3);*/
1680 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1681 M_CMPEQ(s2, REG_ITMP3);
1683 emit_beq(cd, iptr->dst.block);
1686 case ICMD_IF_LLT: /* ..., value ==> ... */
1688 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1689 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1690 if (iptr->sx.val.l == 0) {
1691 /* if high word is less than zero, the whole long is too */
1693 emit_blt(cd, iptr->dst.block);
1696 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1697 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1698 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1699 M_CMP(s1, REG_ITMP3);*/
1700 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1701 M_MOVGT_IMM(2, REG_ITMP1);
1702 M_MOVEQ_IMM(1, REG_ITMP1);
1704 /* low compare: x=x-1(ifLO) */
1705 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1706 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1707 M_CMP(s2, REG_ITMP3);*/
1708 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1710 /* branch if (x LT 1) */
1711 M_CMP_IMM(REG_ITMP1, 1);
1712 emit_blt(cd, iptr->dst.block);
1716 case ICMD_IF_LLE: /* ..., value ==> ... */
1718 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1719 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1720 if (iptr->sx.val.l == 0) {
1721 /* if high word is less than zero, the whole long is too */
1723 emit_blt(cd, iptr->dst.block);
1725 /* ... otherwise the low word has to be zero (tricky!) */
1727 emit_beq(cd, iptr->dst.block);
1730 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1731 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1732 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1733 M_CMP(s1, REG_ITMP3);*/
1734 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1735 M_MOVGT_IMM(2, REG_ITMP1);
1736 M_MOVEQ_IMM(1, REG_ITMP1);
1738 /* low compare: x=x+1(ifHI) */
1739 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1740 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1741 M_CMP(s2, REG_ITMP3);*/
1742 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1744 /* branch if (x LE 1) */
1745 M_CMP_IMM(REG_ITMP1, 1);
1746 emit_ble(cd, iptr->dst.block);
1750 case ICMD_IF_LGE: /* ..., value ==> ... */
1752 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1753 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1754 if (iptr->sx.val.l == 0) {
1755 /* if high word is greater or equal zero, the whole long is too */
1757 emit_bge(cd, iptr->dst.block);
1760 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1761 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1762 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1763 M_CMP(s1, REG_ITMP3);*/
1764 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1765 M_MOVGT_IMM(2, REG_ITMP1);
1766 M_MOVEQ_IMM(1, REG_ITMP1);
1768 /* low compare: x=x-1(ifLO) */
1769 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1770 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1771 M_CMP(s2, REG_ITMP3);*/
1772 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1774 /* branch if (x GE 1) */
1775 M_CMP_IMM(REG_ITMP1, 1);
1776 emit_bge(cd, iptr->dst.block);
1780 case ICMD_IF_LGT: /* ..., value ==> ... */
1782 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1783 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1785 if (iptr->sx.val.l == 0) {
1786 /* if high word is greater than zero, the whole long is too */
1789 codegen_add_branch_ref(cd, iptr->dst.block);
1791 /* ... or high was zero and low is non zero (tricky!) */
1792 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1793 M_MOVLT_IMM(1, REG_ITMP3);
1794 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1796 codegen_add_branch_ref(cd, iptr->dst.block);
1800 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1801 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1802 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1803 M_CMP(s1, REG_ITMP3);*/
1804 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1805 M_MOVGT_IMM(2, REG_ITMP1);
1806 M_MOVEQ_IMM(1, REG_ITMP1);
1808 /* low compare: x=x+1(ifHI) */
1809 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1810 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1811 M_CMP(s2, REG_ITMP3);*/
1812 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1814 /* branch if (x GT 1) */
1815 M_CMP_IMM(REG_ITMP1, 1);
1816 emit_bgt(cd, iptr->dst.block);
1822 case ICMD_IF_LNE: /* ..., value ==> ... */
1824 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1825 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1826 if (iptr->sx.val.l == 0) {
1827 M_ORR_S(s1, s2, REG_ITMP3);
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 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1834 M_CMPEQ(s2, REG_ITMP3);
1836 emit_bne(cd, iptr->dst.block);
1839 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1840 case ICMD_IF_ICMPNE:
1841 case ICMD_IF_ICMPLT:
1842 case ICMD_IF_ICMPLE:
1843 case ICMD_IF_ICMPGT:
1844 case ICMD_IF_ICMPGE:
1846 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1847 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1849 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1852 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1853 case ICMD_IF_ACMPNE:
1855 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1856 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1858 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1861 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1862 /* op1 = target JavaVM pc */
1864 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1865 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1868 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1869 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1872 emit_beq(cd, iptr->dst.block);
1875 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1876 /* op1 = target JavaVM pc */
1878 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1879 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1882 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1883 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1886 emit_bne(cd, iptr->dst.block);
1889 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1890 /* op1 = target JavaVM pc */
1892 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1893 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1894 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1896 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1897 M_MOVGT_IMM(2, REG_ITMP3);
1898 M_MOVEQ_IMM(1, REG_ITMP3);
1900 /* low compare: x=x-1(ifLO) */
1901 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1902 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1904 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1906 /* branch if (x LT 1) */
1907 M_CMP_IMM(REG_ITMP3, 1);
1908 emit_blt(cd, iptr->dst.block);
1911 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1912 /* op1 = target JavaVM pc */
1914 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1915 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1916 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1918 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1919 M_MOVGT_IMM(2, REG_ITMP3);
1920 M_MOVEQ_IMM(1, REG_ITMP3);
1922 /* low compare: x=x-1(ifLO) */
1923 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1924 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1926 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1928 /* branch if (x LE 1) */
1929 M_CMP_IMM(REG_ITMP3, 1);
1930 emit_ble(cd, iptr->dst.block);
1933 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1934 /* op1 = target JavaVM pc */
1936 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1937 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1938 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1940 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1941 M_MOVGT_IMM(2, REG_ITMP3);
1942 M_MOVEQ_IMM(1, REG_ITMP3);
1944 /* low compare: x=x-1(ifLO) */
1945 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1946 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1948 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1950 /* branch if (x GT 1) */
1951 M_CMP_IMM(REG_ITMP3, 1);
1952 emit_bgt(cd, iptr->dst.block);
1955 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1956 /* op1 = target JavaVM pc */
1958 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1959 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1960 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1962 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1963 M_MOVGT_IMM(2, REG_ITMP3);
1964 M_MOVEQ_IMM(1, REG_ITMP3);
1966 /* low compare: x=x-1(ifLO) */
1967 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1968 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1970 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1972 /* branch if (x GE 1) */
1973 M_CMP_IMM(REG_ITMP3, 1);
1974 emit_bge(cd, iptr->dst.block);
1977 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1980 branch_target_t *table;
1982 table = iptr->dst.table;
1984 l = iptr->sx.s23.s2.tablelow;
1985 i = iptr->sx.s23.s3.tablehigh;
1987 /* calculate new index (index - low) */
1988 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1990 M_INTMOVE(s1, REG_ITMP1);
1991 } else if (IS_IMM(l)) {
1992 M_SUB_IMM(REG_ITMP1, s1, l);
1994 ICONST(REG_ITMP2, l);
1995 M_SUB(REG_ITMP1, s1, REG_ITMP2);
1998 /* range check (index <= high-low) */
2000 M_COMPARE(REG_ITMP1, i-1);
2001 emit_bugt(cd, table[0].block);
2003 /* build jump table top down and use address of lowest entry */
2008 dseg_add_target(cd, table->block);
2013 /* length of dataseg after last dseg_add_target is used by load */
2014 /* TODO: this loads from data-segment */
2015 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2016 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2019 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2022 lookup_target_t *lookup;
2024 lookup = iptr->dst.lookup;
2026 i = iptr->sx.s23.s2.lookupcount;
2029 MCODECHECK((i<<2)+8);
2030 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2033 M_COMPARE(s1, lookup->value);
2034 emit_beq(cd, lookup->target.block);
2038 /* default branch */
2039 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2043 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2045 #if !defined(ENABLE_SOFTFLOAT)
2046 REPLACEMENT_POINT_RETURN(cd, iptr);
2047 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2048 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2049 goto ICMD_RETURN_do;
2052 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2054 REPLACEMENT_POINT_RETURN(cd, iptr);
2055 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2056 M_INTMOVE(s1, REG_RESULT);
2057 goto ICMD_RETURN_do;
2059 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2061 #if !defined(ENABLE_SOFTFLOAT)
2062 REPLACEMENT_POINT_RETURN(cd, iptr);
2063 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2064 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2065 goto ICMD_RETURN_do;
2068 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2070 REPLACEMENT_POINT_RETURN(cd, iptr);
2071 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2072 M_LNGMOVE(s1, REG_RESULT_PACKED);
2073 goto ICMD_RETURN_do;
2075 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2077 REPLACEMENT_POINT_RETURN(cd, iptr);
2078 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2079 M_INTMOVE(s1, REG_RESULT);
2080 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2081 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2082 iptr->sx.s23.s2.uc, 0);
2084 goto ICMD_RETURN_do;
2086 case ICMD_RETURN: /* ... ==> ... */
2088 REPLACEMENT_POINT_RETURN(cd, iptr);
2091 #if !defined(NDEBUG)
2092 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2093 emit_verbosecall_exit(jd);
2096 #if defined(ENABLE_THREADS)
2097 /* call monitorexit function */
2099 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2100 /* stack offset for monitor argument */
2102 s1 = rd->memuse * 8;
2104 /* we need to save the proper return value */
2106 switch (iptr->opc) {
2110 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2112 M_STMFD(BITMASK_RESULT, REG_SP);
2117 M_LDR(REG_A0, REG_SP, s1);
2118 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2119 M_DSEG_BRANCH(disp);
2121 /* we no longer need PV here, no more loading */
2122 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2123 M_RECOMPUTE_PV(s1);*/
2125 switch (iptr->opc) {
2129 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2131 M_LDMFD(BITMASK_RESULT, REG_SP);
2137 /* deallocate stackframe for spilled variables */
2139 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2140 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2142 /* restore callee saved registers + do return */
2144 if (savedregs_bitmask) {
2145 if (!jd->isleafmethod) {
2146 savedregs_bitmask &= ~(1<<REG_LR);
2147 savedregs_bitmask |= (1<<REG_PC);
2149 M_LDMFD(savedregs_bitmask, REG_SP);
2152 /* if LR was not on stack, we need to return manually */
2154 if (jd->isleafmethod)
2155 M_MOV(REG_PC, REG_LR);
2158 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2160 bte = iptr->sx.s23.s3.bte;
2162 goto ICMD_INVOKE_do;
2164 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2165 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2166 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2167 case ICMD_INVOKEINTERFACE:
2169 REPLACEMENT_POINT_INVOKE(cd, iptr);
2171 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2173 um = iptr->sx.s23.s3.um;
2174 md = um->methodref->parseddesc.md;
2177 lm = iptr->sx.s23.s3.fmiref->p.method;
2179 md = lm->parseddesc;
2183 /* copy arguments to registers or stack location */
2185 s3 = md->paramcount;
2187 MCODECHECK((s3 << 1) + 64);
2189 for (s3 = s3 - 1; s3 >= 0; s3--) {
2190 var = VAR(iptr->sx.s23.s2.args[s3]);
2191 d = md->params[s3].regoff;
2193 if (var->flags & PREALLOC) /* argument was precolored? */
2196 /* TODO: document me */
2197 #if !defined(ENABLE_SOFTFLOAT)
2198 if (IS_INT_LNG_TYPE(var->type)) {
2199 #endif /* !defined(ENABLE_SOFTFLOAT) */
2200 if (!md->params[s3].inmemory) {
2201 s1 = emit_load(jd, iptr, var, d);
2203 if (IS_2_WORD_TYPE(var->type))
2209 if (IS_2_WORD_TYPE(var->type)) {
2210 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2211 M_LST(s1, REG_SP, d);
2214 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2215 M_IST(s1, REG_SP, d);
2218 #if !defined(ENABLE_SOFTFLOAT)
2221 if (!md->params[s3].inmemory) {
2222 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2223 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2226 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2227 if (IS_2_WORD_TYPE(var->type))
2228 M_DST(s1, REG_SP, d);
2230 M_FST(s1, REG_SP, d);
2233 #endif /* !defined(ENABLE_SOFTFLOAT) */
2236 switch (iptr->opc) {
2239 if (bte->stub == NULL) {
2240 disp = dseg_add_functionptr(cd, bte->fp);
2242 disp = dseg_add_functionptr(cd, bte->stub);
2245 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2247 /* generate the actual call */
2249 M_MOV(REG_LR, REG_PC);
2250 M_MOV(REG_PC, REG_PV);
2251 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2255 case ICMD_INVOKESPECIAL:
2256 emit_nullpointer_check(cd, iptr, REG_A0);
2259 case ICMD_INVOKESTATIC:
2261 disp = dseg_add_unique_address(cd, NULL);
2263 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2267 disp = dseg_add_address(cd, lm->stubroutine);
2269 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2271 /* generate the actual call */
2273 M_MOV(REG_LR, REG_PC);
2274 M_MOV(REG_PC, REG_PV);
2275 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2279 case ICMD_INVOKEVIRTUAL:
2281 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2286 s1 = OFFSET(vftbl_t, table[0]) +
2287 sizeof(methodptr) * lm->vftblindex;
2289 /* implicit null-pointer check */
2290 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2291 OFFSET(java_object_t, vftbl));
2292 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2294 /* generate the actual call */
2296 M_MOV(REG_LR, REG_PC);
2297 M_MOV(REG_PC, REG_PV);
2298 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2302 case ICMD_INVOKEINTERFACE:
2304 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2310 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2311 sizeof(methodptr*) * lm->class->index;
2312 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2315 /* implicit null-pointer check */
2316 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2317 OFFSET(java_object_t, vftbl));
2318 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2319 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2321 /* generate the actual call */
2323 M_MOV(REG_LR, REG_PC);
2324 M_MOV(REG_PC, REG_PV);
2325 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2330 /* store size of call code in replacement point */
2331 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2333 /* store return value */
2335 d = md->returntype.type;
2337 #if !defined(__SOFTFP__)
2338 /* TODO: this is only a hack, since we use R0/R1 for float
2339 return! this depends on gcc; it is independent from
2340 our ENABLE_SOFTFLOAT define */
2341 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2342 #if 0 && !defined(NDEBUG)
2343 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2345 /* we cannot use this macro, since it is not defined
2346 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2347 REG_FRESULT, REG_RESULT_TYPED(d)); */
2348 if (IS_2_WORD_TYPE(d)) {
2349 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2350 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2352 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2353 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2358 if (d != TYPE_VOID) {
2359 #if !defined(ENABLE_SOFTFLOAT)
2360 if (IS_INT_LNG_TYPE(d)) {
2361 #endif /* !defined(ENABLE_SOFTFLOAT) */
2362 if (IS_2_WORD_TYPE(d)) {
2363 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2364 M_LNGMOVE(REG_RESULT_PACKED, s1);
2367 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2368 M_INTMOVE(REG_RESULT, s1);
2371 #if !defined(ENABLE_SOFTFLOAT)
2373 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2374 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2376 #endif /* !defined(ENABLE_SOFTFLOAT) */
2378 emit_store_dst(jd, iptr, s1);
2382 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2384 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2385 /* object type cast-check */
2390 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2395 super = iptr->sx.s23.s3.c.cls;
2396 superindex = super->index;
2399 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2400 CODEGEN_CRITICAL_SECTION_NEW;
2402 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2404 /* if class is not resolved, check which code to call */
2406 if (super == NULL) {
2408 emit_label_beq(cd, BRANCH_LABEL_1);
2410 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2411 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2412 iptr->sx.s23.s3.c.ref, disp);
2414 M_DSEG_LOAD(REG_ITMP2, disp);
2415 disp = dseg_add_s4(cd, ACC_INTERFACE);
2416 M_DSEG_LOAD(REG_ITMP3, disp);
2417 M_TST(REG_ITMP2, REG_ITMP3);
2418 emit_label_beq(cd, BRANCH_LABEL_2);
2421 /* interface checkcast code */
2423 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2424 if ((super == NULL) || !IS_IMM(superindex)) {
2425 disp = dseg_add_unique_s4(cd, superindex);
2427 if (super == NULL) {
2428 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2429 iptr->sx.s23.s3.c.ref, disp);
2433 emit_label_beq(cd, BRANCH_LABEL_3);
2436 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2437 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2439 /* we put unresolved or non-immediate superindices onto dseg */
2440 if ((super == NULL) || !IS_IMM(superindex)) {
2441 /* disp was computed before we added the patcher */
2442 M_DSEG_LOAD(REG_ITMP2, disp);
2443 M_CMP(REG_ITMP3, REG_ITMP2);
2445 assert(IS_IMM(superindex));
2446 M_CMP_IMM(REG_ITMP3, superindex);
2449 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2451 /* if we loaded the superindex out of the dseg above, we do
2452 things differently here! */
2453 if ((super == NULL) || !IS_IMM(superindex)) {
2455 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2457 /* this assumes something */
2458 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2460 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2461 assert(sizeof(methodptr*) == 4);
2462 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2468 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2469 superindex * sizeof(methodptr*);
2473 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2474 M_TST(REG_ITMP3, REG_ITMP3);
2475 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2478 emit_label_br(cd, BRANCH_LABEL_4);
2480 emit_label(cd, BRANCH_LABEL_3);
2483 /* class checkcast code */
2485 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2486 if (super == NULL) {
2487 emit_label(cd, BRANCH_LABEL_2);
2489 disp = dseg_add_unique_address(cd, NULL);
2491 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2492 iptr->sx.s23.s3.c.ref,
2496 disp = dseg_add_address(cd, super->vftbl);
2499 emit_label_beq(cd, BRANCH_LABEL_5);
2502 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2503 M_DSEG_LOAD(REG_ITMP3, disp);
2505 CODEGEN_CRITICAL_SECTION_START;
2507 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2508 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2509 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2510 M_DSEG_LOAD(REG_ITMP3, disp);
2511 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2513 CODEGEN_CRITICAL_SECTION_END;
2515 M_CMP(REG_ITMP2, REG_ITMP3);
2516 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2519 emit_label(cd, BRANCH_LABEL_5);
2522 if (super == NULL) {
2523 emit_label(cd, BRANCH_LABEL_1);
2524 emit_label(cd, BRANCH_LABEL_4);
2527 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2530 /* array type cast-check */
2532 s1 = emit_load_s1(jd, iptr, REG_A0);
2533 M_INTMOVE(s1, REG_A0);
2535 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2536 disp = dseg_add_unique_address(cd, NULL);
2538 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2539 iptr->sx.s23.s3.c.ref,
2543 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2545 M_DSEG_LOAD(REG_A1, disp);
2546 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2547 M_DSEG_BRANCH(disp);
2550 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2551 M_RECOMPUTE_PV(disp);
2553 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2554 M_TST(REG_RESULT, REG_RESULT);
2555 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2557 d = codegen_reg_of_dst(jd, iptr, s1);
2561 emit_store_dst(jd, iptr, d);
2564 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2570 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2575 super = iptr->sx.s23.s3.c.cls;
2576 superindex = super->index;
2579 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2580 CODEGEN_CRITICAL_SECTION_NEW;
2582 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2583 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2586 M_MOV(REG_ITMP1, s1);
2590 /* if class is not resolved, check which code to call */
2592 if (super == NULL) {
2596 emit_label_beq(cd, BRANCH_LABEL_1);
2598 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2599 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2600 iptr->sx.s23.s3.c.ref, disp);
2602 M_DSEG_LOAD(REG_ITMP2, disp);
2603 disp = dseg_add_s4(cd, ACC_INTERFACE);
2604 M_DSEG_LOAD(REG_ITMP3, disp);
2605 M_TST(REG_ITMP2, REG_ITMP3);
2606 emit_label_beq(cd, BRANCH_LABEL_2);
2609 /* interface checkcast code */
2611 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2612 if ((super == NULL) || !IS_IMM(superindex)) {
2613 disp = dseg_add_unique_s4(cd, superindex);
2615 if (super == NULL) {
2616 /* If d == REG_ITMP2, then it's destroyed in check
2621 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2622 iptr->sx.s23.s3.c.ref, disp);
2627 emit_label_beq(cd, BRANCH_LABEL_3);
2630 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2631 M_LDR_INTERN(REG_ITMP3,
2632 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2634 /* we put unresolved or non-immediate superindices onto dseg
2635 and do things slightly different */
2636 if ((super == NULL) || !IS_IMM(superindex)) {
2637 /* disp was computed before we added the patcher */
2638 M_DSEG_LOAD(REG_ITMP2, disp);
2639 M_CMP(REG_ITMP3, REG_ITMP2);
2641 if (d == REG_ITMP2) {
2648 /* this assumes something */
2649 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2651 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2652 assert(sizeof(methodptr*) == 4);
2653 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2655 if (d == REG_ITMP2) {
2662 assert(IS_IMM(superindex));
2663 M_CMP_IMM(REG_ITMP3, superindex);
2667 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2668 superindex * sizeof(methodptr*);
2672 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2673 M_TST(REG_ITMP3, REG_ITMP3);
2677 emit_label_br(cd, BRANCH_LABEL_4);
2679 emit_label(cd, BRANCH_LABEL_3);
2682 /* class checkcast code */
2684 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2685 if (super == NULL) {
2686 emit_label(cd, BRANCH_LABEL_2);
2688 disp = dseg_add_unique_address(cd, NULL);
2690 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2691 iptr->sx.s23.s3.c.ref, disp);
2694 disp = dseg_add_address(cd, super->vftbl);
2698 emit_label_beq(cd, BRANCH_LABEL_5);
2701 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2702 M_DSEG_LOAD(REG_ITMP2, disp);
2704 CODEGEN_CRITICAL_SECTION_START;
2706 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2707 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2708 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2710 CODEGEN_CRITICAL_SECTION_END;
2712 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2713 M_CMP(REG_ITMP1, REG_ITMP2);
2714 /* If d == REG_ITMP2, then it's destroyed */
2720 emit_label(cd, BRANCH_LABEL_5);
2723 if (super == NULL) {
2724 emit_label(cd, BRANCH_LABEL_1);
2725 emit_label(cd, BRANCH_LABEL_4);
2730 emit_store_dst(jd, iptr, d);
2733 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2735 /* copy sizes to stack if necessary */
2737 MCODECHECK((iptr->s1.argcount << 1) + 64);
2739 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2741 var = VAR(iptr->sx.s23.s2.args[s1]);
2743 /* copy SAVEDVAR sizes to stack */
2745 if (!(var->flags & PREALLOC)) {
2746 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2747 M_STR(s2, REG_SP, s1 * 4);
2751 /* a0 = dimension count */
2753 assert(IS_IMM(iptr->s1.argcount));
2754 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2756 /* is patcher function set? */
2758 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2759 disp = dseg_add_unique_address(cd, NULL);
2761 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2762 iptr->sx.s23.s3.c.ref, disp);
2765 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2767 /* a1 = arraydescriptor */
2769 M_DSEG_LOAD(REG_A1, disp);
2771 /* a2 = pointer to dimensions = stack pointer */
2773 M_INTMOVE(REG_SP, REG_A2);
2775 /* call builtin_multianewarray here */
2777 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2778 M_DSEG_BRANCH(disp);
2782 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2785 /* check for exception before result assignment */
2787 emit_exception_check(cd, iptr);
2791 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2792 M_INTMOVE(REG_RESULT, d);
2793 emit_store_dst(jd, iptr, d);
2796 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2798 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2799 emit_nullpointer_check(cd, iptr, s1);
2803 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2806 } /* the big switch */
2808 } /* for all instructions */
2810 } /* for all basic blocks */
2812 dseg_createlinenumbertable(cd);
2815 /* generate traps */
2817 emit_patcher_traps(jd);
2819 /* everything's ok */
2825 /* codegen_emit_stub_compiler **************************************************
2827 Emits a stub routine which calls the compiler.
2829 *******************************************************************************/
2831 void codegen_emit_stub_compiler(jitdata *jd)
2836 /* get required compiler data */
2841 /* code for the stub */
2843 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2844 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2848 /* codegen_emit_stub_native ****************************************************
2850 Emits a stub routine which calls a native method.
2852 *******************************************************************************/
2854 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2863 s4 disp, funcdisp, s1, s2;
2865 /* get required compiler data */
2871 /* initialize variables */
2874 nativeparams = (m->flags & ACC_NATIVE) ? 1 : 0;
2875 nativeparams += (m->flags & ACC_STATIC) ? 1 : 0;
2877 /* calculate stackframe size */
2879 cd->stackframesize =
2880 4 + /* return address */
2881 sizeof(stackframeinfo) + /* stackframeinfo */
2882 sizeof(localref_table) + /* localref_table */
2883 nmd->memuse * 4; /* stack arguments */
2885 /* align stack to 8-byte */
2887 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2889 /* create method header */
2891 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2892 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2893 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2894 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2895 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2896 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2897 (void) dseg_addlinenumbertablesize(cd);
2898 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2900 /* generate stub code */
2902 M_STMFD(1<<REG_LR, REG_SP);
2903 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2905 #if !defined(NDEBUG)
2906 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2907 emit_verbosecall_enter(jd);
2910 /* get function address (this must happen before the stackframeinfo) */
2912 funcdisp = dseg_add_functionptr(cd, f);
2915 patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
2917 #if defined(ENABLE_GC_CACAO)
2918 /* Save callee saved integer registers in stackframeinfo (GC may
2919 need to recover them during a collection). */
2921 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo) +
2922 OFFSET(stackframeinfo, intregs);
2924 for (i = 0; i < INT_SAV_CNT; i++)
2925 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2928 /* Save integer and float argument registers (these are 4
2929 registers, stack is 8-byte aligned). */
2931 M_STMFD(BITMASK_ARGS, REG_SP);
2932 /* TODO: floating point */
2934 /* create native stackframe info */
2936 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2937 M_MOV(REG_A1, REG_PV);
2938 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2939 M_DSEG_BRANCH(disp);
2943 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2946 /* remember class argument */
2948 if (m->flags & ACC_STATIC)
2949 M_MOV(REG_ITMP3, REG_RESULT);
2951 /* Restore integer and float argument registers (these are 4
2952 registers, stack is 8-byte aligned). */
2954 M_LDMFD(BITMASK_ARGS, REG_SP);
2955 /* TODO: floating point */
2957 /* copy or spill arguments to new locations */
2958 /* ATTENTION: the ARM has only integer argument registers! */
2960 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
2961 t = md->paramtypes[i].type;
2963 if (!md->params[i].inmemory) {
2964 s1 = md->params[i].regoff;
2965 s2 = nmd->params[j].regoff;
2967 if (!nmd->params[j].inmemory) {
2968 #if !defined(__ARM_EABI__)
2969 SPLIT_OPEN(t, s2, REG_ITMP1);
2972 if (IS_2_WORD_TYPE(t))
2977 #if !defined(__ARM_EABI__)
2978 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2982 if (IS_2_WORD_TYPE(t))
2983 M_LST(s1, REG_SP, s2);
2985 M_IST(s1, REG_SP, s2);
2989 s1 = md->params[i].regoff + cd->stackframesize;
2990 s2 = nmd->params[j].regoff;
2992 if (IS_2_WORD_TYPE(t)) {
2993 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2994 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2997 M_ILD(REG_ITMP1, REG_SP, s1);
2998 M_IST(REG_ITMP1, REG_SP, s2);
3003 /* put class into second argument register */
3005 if (m->flags & ACC_STATIC)
3006 M_MOV(REG_A1, REG_ITMP3);
3008 /* put env into first argument register */
3010 if (m->flags & ACC_NATIVE) {
3011 disp = dseg_add_address(cd, _Jv_env);
3012 M_DSEG_LOAD(REG_A0, disp);
3015 /* do the native function call */
3017 M_DSEG_BRANCH(funcdisp);
3020 /* TODO: this is only needed because of the tracer ... do we
3023 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3026 #if !defined(__SOFTFP__)
3027 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3028 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3029 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3030 #if 0 && !defined(NDEBUG)
3031 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3033 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3034 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3035 if (IS_2_WORD_TYPE(md->returntype.type)) {
3036 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3037 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3039 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3040 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3045 #if !defined(NDEBUG)
3046 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3047 emit_verbosecall_exit(jd);
3050 /* remove native stackframe info */
3051 /* TODO: improve this store/load */
3053 M_STMFD(BITMASK_RESULT, REG_SP);
3055 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3056 M_MOV(REG_A1, REG_PV);
3057 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3058 M_DSEG_BRANCH(disp);
3059 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3062 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3063 M_LDMFD(BITMASK_RESULT, REG_SP);
3065 #if defined(ENABLE_GC_CACAO)
3066 /* restore callee saved int registers from stackframeinfo (GC might have */
3067 /* modified them during a collection). */
3069 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo) +
3070 OFFSET(stackframeinfo, intregs);
3072 for (i = 0; i < INT_SAV_CNT; i++)
3073 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3076 /* finish stub code, but do not yet return to caller */
3078 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3079 M_LDMFD(1<<REG_LR, REG_SP);
3081 /* check for exception */
3083 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3084 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3086 /* handle exception here */
3088 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3090 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3091 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3092 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3094 /* generate patcher stubs */
3096 emit_patcher_traps(jd);
3100 /* asm_debug *******************************************************************
3104 *******************************************************************************/
3106 void asm_debug(int a1, int a2, int a3, int a4)
3108 printf("===> i am going to exit after this debugging message!\n");
3109 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3110 vm_abort("leave you now");
3115 * These are local overrides for various environment variables in Emacs.
3116 * Please do not remove this and leave it at the end of the file, where
3117 * Emacs will automagically detect them.
3118 * ---------------------------------------------------------------------
3121 * indent-tabs-mode: t
3125 * vim:noexpandtab:sw=4:ts=4: