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 + 1) * 8;
159 /* REMOVEME: We still need it for exception handling in assembler. */
161 if (code_is_leafmethod(code))
162 (void) dseg_add_unique_s4(cd, 1);
164 (void) dseg_add_unique_s4(cd, 0);
166 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
167 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
168 (void) dseg_addlinenumbertablesize(cd);
169 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
171 /* create exception table */
173 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
174 dseg_add_target(cd, ex->start);
175 dseg_add_target(cd, ex->end);
176 dseg_add_target(cd, ex->handler);
177 (void) dseg_add_unique_address(cd, ex->catchtype.any);
180 /* save return address and used callee saved registers */
182 savedregs_bitmask = 0;
184 if (!code_is_leafmethod(code))
185 savedregs_bitmask = (1<<REG_LR);
187 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
188 savedregs_bitmask |= (1<<(rd->savintregs[i]));
191 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
192 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
193 /* TODO: floating-point */
197 if (savedregs_bitmask)
198 M_STMFD(savedregs_bitmask, REG_SP);
200 /* create additional stack frame for spilled variables (if necessary) */
202 if ((cd->stackframesize / 4 - savedregs_num) > 0)
203 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
205 /* take arguments out of register or stack frame */
208 for (i = 0, len = 0; i < md->paramcount; i++) {
209 s1 = md->params[i].regoff;
210 t = md->paramtypes[i].type;
212 varindex = jd->local_map[len * 5 + t];
214 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
216 if (varindex == UNUSED)
221 /* ATTENTION: we use interger registers for all arguments (even float) */
222 #if !defined(ENABLE_SOFTFLOAT)
223 if (IS_INT_LNG_TYPE(t)) {
225 if (!md->params[i].inmemory) {
226 if (!(var->flags & INMEMORY)) {
227 if (IS_2_WORD_TYPE(t))
228 M_LNGMOVE(s1, var->vv.regoff);
230 M_INTMOVE(s1, var->vv.regoff);
233 if (IS_2_WORD_TYPE(t))
234 M_LST(s1, REG_SP, var->vv.regoff);
236 M_IST(s1, REG_SP, var->vv.regoff);
239 else { /* stack arguments */
240 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
241 if (IS_2_WORD_TYPE(t))
242 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
244 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
246 else { /* stack arg -> spilled */
247 /* Reuse Memory Position on Caller Stack */
248 var->vv.regoff = cd->stackframesize + s1;
251 #if !defined(ENABLE_SOFTFLOAT)
254 if (!md->params[i].inmemory) {
255 if (!(var->flags & INMEMORY)) {
256 if (IS_2_WORD_TYPE(t))
257 M_CAST_L2D(s1, var->vv.regoff);
259 M_CAST_I2F(s1, var->vv.regoff);
262 if (IS_2_WORD_TYPE(t))
263 M_LST(s1, REG_SP, var->vv.regoff);
265 M_IST(s1, REG_SP, var->vv.regoff);
269 if (!(var->flags & INMEMORY)) {
270 if (IS_2_WORD_TYPE(t))
271 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
273 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
276 /* Reuse Memory Position on Caller Stack */
277 var->vv.regoff = cd->stackframesize + s1;
281 #endif /* !defined(ENABLE_SOFTFLOAT) */
284 #if defined(ENABLE_THREADS)
285 /* call monitorenter function */
287 if (checksync && code_is_synchronized(code)) {
288 /* stack offset for monitor argument */
292 # if !defined(NDEBUG)
293 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
294 M_STMFD(BITMASK_ARGS, REG_SP);
299 /* get the correct lock object */
301 if (m->flags & ACC_STATIC) {
302 disp = dseg_add_address(cd, &m->class->object.header);
303 M_DSEG_LOAD(REG_A0, disp);
306 emit_nullpointer_check_force(cd, iptr, REG_A0);
309 M_STR(REG_A0, REG_SP, s1);
310 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
312 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
315 # if !defined(NDEBUG)
316 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
317 M_LDMFD(BITMASK_ARGS, REG_SP);
323 /* call trace function */
325 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
326 emit_verbosecall_enter(jd);
329 /* end of header generation */
331 /* create replacement points */
332 REPLACEMENT_POINTS_INIT(cd, jd);
334 /* SECTION: ICMD Code Generation */
335 /* for all basic blocks */
337 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
339 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
341 /* is this basic block reached? */
343 if (bptr->flags < BBREACHED)
346 /* branch resolving */
348 codegen_resolve_branchrefs(cd, bptr);
350 /* handle replacement points */
351 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
353 /* copy interface registers to their destination */
359 #if defined(ENABLE_LSRA)
363 var = VAR(bptr->invars[len]);
364 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
365 if (!(var->flags & INMEMORY))
369 M_INTMOVE(REG_ITMP1, d);
370 emit_store(jd, NULL, var, d);
377 var = VAR(bptr->invars[len]);
379 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
380 d = codegen_reg_of_var(0, var, REG_ITMP1);
381 M_INTMOVE(REG_ITMP1, d);
382 emit_store(jd, NULL, var, d);
385 assert((var->flags & INOUT));
388 #if defined(ENABLE_LSRA)
392 /* for all instructions */
395 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
397 /* add line number */
398 if (iptr->line != currentline) {
399 dseg_addlinenumber(cd, iptr->line);
400 currentline = iptr->line;
403 MCODECHECK(64); /* an instruction usually needs < 64 words */
407 case ICMD_NOP: /* ... ==> ... */
410 /* constant operations ************************************************/
412 case ICMD_ICONST: /* ... ==> ..., constant */
414 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
415 ICONST(d, iptr->sx.val.i);
416 emit_store_dst(jd, iptr, d);
419 case ICMD_ACONST: /* ... ==> ..., constant */
421 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
422 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
423 disp = dseg_add_unique_address(cd, NULL);
425 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
426 iptr->sx.val.c.ref, disp);
428 M_DSEG_LOAD(d, disp);
431 ICONST(d, (u4) iptr->sx.val.anyptr);
433 emit_store_dst(jd, iptr, d);
436 case ICMD_LCONST: /* ... ==> ..., constant */
438 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
439 LCONST(d, iptr->sx.val.l);
440 emit_store_dst(jd, iptr, d);
443 case ICMD_FCONST: /* ... ==> ..., constant */
445 #if defined(ENABLE_SOFTFLOAT)
446 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
447 ICONST(d, iptr->sx.val.i);
448 emit_store_dst(jd, iptr, d);
450 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
451 FCONST(d, iptr->sx.val.f);
452 emit_store_dst(jd, iptr, d);
456 case ICMD_DCONST: /* ... ==> ..., constant */
458 #if defined(ENABLE_SOFTFLOAT)
459 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
460 LCONST(d, iptr->sx.val.l);
461 emit_store_dst(jd, iptr, d);
463 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
464 DCONST(d, iptr->sx.val.d);
465 emit_store_dst(jd, iptr, d);
470 /* load/store/copy/move operations ************************************/
472 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
473 case ICMD_ALOAD: /* op1 = local variable */
477 case ICMD_ISTORE: /* ..., value ==> ... */
488 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
492 /* pop operations *****************************************************/
494 /* attention: double and longs are only one entry in CACAO ICMDs */
496 case ICMD_POP: /* ..., value ==> ... */
497 case ICMD_POP2: /* ..., value, value ==> ... */
502 /* integer operations *************************************************/
504 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
506 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
507 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
508 M_MOV(d, REG_LSL(s1, 24));
509 M_MOV(d, REG_ASR(d, 24));
510 emit_store_dst(jd, iptr, d);
513 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
515 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
516 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
517 M_MOV(d, REG_LSL(s1, 16));
518 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
519 emit_store_dst(jd, iptr, d);
522 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
524 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
525 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
526 M_MOV(d, REG_LSL(s1, 16));
527 M_MOV(d, REG_ASR(d, 16));
528 emit_store_dst(jd, iptr, d);
531 case ICMD_I2L: /* ..., value ==> ..., value */
533 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
534 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
535 M_INTMOVE(s1, GET_LOW_REG(d));
536 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
537 emit_store_dst(jd, iptr, d);
540 case ICMD_L2I: /* ..., value ==> ..., value */
542 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
543 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
545 emit_store_dst(jd, iptr, d);
548 case ICMD_INEG: /* ..., value ==> ..., - value */
550 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
551 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
553 emit_store_dst(jd, iptr, d);
556 case ICMD_LNEG: /* ..., value ==> ..., - value */
558 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
559 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
560 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
561 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
562 emit_store_dst(jd, iptr, d);
565 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
567 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
568 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
569 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
571 emit_store_dst(jd, iptr, d);
574 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
576 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
577 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
578 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
579 M_ADD_S(GET_LOW_REG(d), s1, s2);
580 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
581 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
582 M_ADC(GET_HIGH_REG(d), s1, s2);
583 emit_store_dst(jd, iptr, d);
589 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
590 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
592 if (IS_IMM(iptr->sx.val.i)) {
593 M_ADD_IMM(d, s1, iptr->sx.val.i);
594 } else if (IS_IMM(-iptr->sx.val.i)) {
595 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
597 ICONST(REG_ITMP3, iptr->sx.val.i);
598 M_ADD(d, s1, REG_ITMP3);
601 emit_store_dst(jd, iptr, d);
604 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
605 /* sx.val.l = constant */
607 s3 = iptr->sx.val.l & 0xffffffff;
608 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
609 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
611 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
613 ICONST(REG_ITMP3, s3);
614 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
616 s3 = iptr->sx.val.l >> 32;
617 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
619 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
621 ICONST(REG_ITMP3, s3);
622 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
624 emit_store_dst(jd, iptr, d);
627 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
629 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
630 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
631 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
633 emit_store_dst(jd, iptr, d);
636 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
638 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
639 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
640 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
641 M_SUB_S(GET_LOW_REG(d), s1, s2);
642 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
643 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
644 M_SBC(GET_HIGH_REG(d), s1, s2);
645 emit_store_dst(jd, iptr, d);
648 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
649 /* sx.val.i = constant */
651 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
652 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
653 if (IS_IMM(iptr->sx.val.i))
654 M_SUB_IMM(d, s1, iptr->sx.val.i);
656 ICONST(REG_ITMP3, iptr->sx.val.i);
657 M_SUB(d, s1, REG_ITMP3);
659 emit_store_dst(jd, iptr, d);
662 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
663 /* sx.val.l = constant */
665 s3 = iptr->sx.val.l & 0xffffffff;
666 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
667 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
669 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
671 ICONST(REG_ITMP3, s3);
672 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
674 s3 = iptr->sx.val.l >> 32;
675 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
677 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
679 ICONST(REG_ITMP3, s3);
680 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
682 emit_store_dst(jd, iptr, d);
685 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
687 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
688 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
689 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
691 emit_store_dst(jd, iptr, d);
694 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
695 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
697 s1 = emit_load_s1(jd, iptr, REG_A0);
698 s2 = emit_load_s2(jd, iptr, REG_A1);
699 emit_arithmetic_check(cd, iptr, s2);
701 /* move arguments into argument registers */
702 M_INTMOVE(s1, REG_A0);
703 M_INTMOVE(s2, REG_A1);
705 /* call builtin function */
706 bte = iptr->sx.s23.s3.bte;
707 disp = dseg_add_functionptr(cd, bte->fp);
711 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
714 /* move result into destination register */
715 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
716 M_INTMOVE(REG_RESULT, d);
717 emit_store_dst(jd, iptr, d);
720 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
721 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
723 /* move arguments into argument registers */
725 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
726 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
727 /* XXX TODO: only do this if arithmetic check is really done! */
728 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
729 emit_arithmetic_check(cd, iptr, REG_ITMP3);
731 M_LNGMOVE(s1, REG_A0_A1_PACKED);
732 M_LNGMOVE(s2, REG_A2_A3_PACKED);
734 /* call builtin function */
735 bte = iptr->sx.s23.s3.bte;
736 disp = dseg_add_functionptr(cd, bte->fp);
740 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
743 /* move result into destination register */
744 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
745 M_LNGMOVE(REG_RESULT_PACKED, d);
746 emit_store_dst(jd, iptr, d);
749 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
750 /* sx.val.i = constant */
752 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
753 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
754 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
755 emit_store_dst(jd, iptr, d);
758 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
759 /* sx.val.i = constant */
761 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
762 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
763 /* this rounds towards 0 as java likes it */
764 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
765 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
766 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
767 /* this rounds towards nearest, not java style */
768 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
769 M_ADCMI_IMM(d, d, 0);*/
770 emit_store_dst(jd, iptr, d);
773 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
774 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
776 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
777 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
778 M_MOV_S(REG_ITMP1, s1);
779 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
780 if (IS_IMM(iptr->sx.val.i))
781 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
783 ICONST(REG_ITMP3, iptr->sx.val.i);
784 M_AND(REG_ITMP1, REG_ITMP3, d);
786 M_RSBMI_IMM(d, d, 0);
787 emit_store_dst(jd, iptr, d);
790 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
792 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
793 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
794 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
795 M_AND_IMM(s2, 0x1f, REG_ITMP2);
796 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
797 emit_store_dst(jd, iptr, d);
800 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
802 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
803 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
804 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
805 M_AND_IMM(s2, 0x1f, REG_ITMP2);
806 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
807 emit_store_dst(jd, iptr, d);
810 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
812 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
813 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
814 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
815 M_AND_IMM(s2, 0x1f, REG_ITMP2);
816 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
817 emit_store_dst(jd, iptr, d);
820 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
821 /* sx.val.i = constant */
823 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
824 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
825 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
826 emit_store_dst(jd, iptr, d);
829 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
830 /* sx.val.i = constant */
832 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
833 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
834 /* we need to check for zero here because arm interprets it as SHR by 32 */
835 if ((iptr->sx.val.i & 0x1f) == 0) {
838 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
840 emit_store_dst(jd, iptr, d);
843 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
844 /* sx.val.i = constant */
846 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
847 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
848 /* we need to check for zero here because arm interprets it as SHR by 32 */
849 if ((iptr->sx.val.i & 0x1f) == 0)
852 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
853 emit_store_dst(jd, iptr, d);
856 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
858 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
859 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
860 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
862 emit_store_dst(jd, iptr, d);
865 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
867 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
868 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
869 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
870 M_AND(s1, s2, GET_LOW_REG(d));
871 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
872 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
873 M_AND(s1, s2, GET_HIGH_REG(d));
874 emit_store_dst(jd, iptr, d);
877 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
879 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
880 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
881 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
883 emit_store_dst(jd, iptr, d);
886 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
888 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
889 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
890 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
891 M_ORR(s1, s2, GET_LOW_REG(d));
892 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
893 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
894 M_ORR(s1, s2, GET_HIGH_REG(d));
895 emit_store_dst(jd, iptr, d);
898 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
900 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
901 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
902 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
904 emit_store_dst(jd, iptr, d);
907 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
909 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
910 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
911 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
912 M_EOR(s1, s2, GET_LOW_REG(d));
913 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
914 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
915 M_EOR(s1, s2, GET_HIGH_REG(d));
916 emit_store_dst(jd, iptr, d);
920 /* floating operations ************************************************/
922 #if !defined(ENABLE_SOFTFLOAT)
924 case ICMD_FNEG: /* ..., value ==> ..., - value */
926 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
927 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
929 emit_store_dst(jd, iptr, d);
932 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
934 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
935 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
936 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
938 emit_store_dst(jd, iptr, d);
941 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
943 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
944 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
945 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
947 emit_store_dst(jd, iptr, d);
950 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
952 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
953 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
954 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
956 emit_store_dst(jd, iptr, d);
959 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
960 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
961 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
962 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
964 emit_store_dst(jd, iptr, d);
967 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
971 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
973 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
974 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
975 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
977 emit_store_dst(jd, iptr, d);
981 case ICMD_DNEG: /* ..., value ==> ..., - value */
983 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
984 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
986 emit_store_dst(jd, iptr, d);
989 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
991 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
992 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
993 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
995 emit_store_dst(jd, iptr, d);
998 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1000 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1001 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1002 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1004 emit_store_dst(jd, iptr, d);
1007 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1009 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1010 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1011 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1013 emit_store_dst(jd, iptr, d);
1016 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1018 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1019 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1020 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1022 emit_store_dst(jd, iptr, d);
1025 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1029 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1031 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1032 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1033 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1035 emit_store_dst(jd, iptr, d);
1039 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1041 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1042 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1044 emit_store_dst(jd, iptr, d);
1047 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1049 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1050 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1052 emit_store_dst(jd, iptr, d);
1055 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1057 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1058 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1059 /* this uses round towards zero, as Java likes it */
1061 #if !defined(__VFP_FP__)
1062 /* this checks for NaN; to return zero as Java likes it */
1066 emit_store_dst(jd, iptr, d);
1069 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1071 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1072 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1073 /* this uses round towards zero, as Java likes it */
1075 #if !defined(__VFP_FP__)
1076 /* this checks for NaN; to return zero as Java likes it */
1080 emit_store_dst(jd, iptr, d);
1083 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1085 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1086 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1088 emit_store_dst(jd, iptr, d);
1091 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1093 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1094 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1096 emit_store_dst(jd, iptr, d);
1099 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1101 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1102 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1103 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1106 #if defined(__VFP_FP__)
1107 M_FMSTAT; /* on VFP we need to transfer the flags */
1109 M_SUBGT_IMM(d, d, 1);
1110 M_ADDLT_IMM(d, d, 1);
1111 emit_store_dst(jd, iptr, d);
1114 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1116 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1117 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1118 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1121 #if defined(__VFP_FP__)
1122 M_FMSTAT; /* on VFP we need to transfer the flags */
1124 M_SUBGT_IMM(d, d, 1);
1125 M_ADDLT_IMM(d, d, 1);
1126 emit_store_dst(jd, iptr, d);
1129 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1131 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1132 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1133 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1136 #if defined(__VFP_FP__)
1137 M_FMSTAT; /* on VFP we need to transfer the flags */
1139 M_SUBLT_IMM(d, d, 1);
1140 M_ADDGT_IMM(d, d, 1);
1141 emit_store_dst(jd, iptr, d);
1144 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1146 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1147 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1148 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1151 #if defined(__VFP_FP__)
1152 M_FMSTAT; /* on VFP we need to transfer the flags */
1154 M_SUBLT_IMM(d, d, 1);
1155 M_ADDGT_IMM(d, d, 1);
1156 emit_store_dst(jd, iptr, d);
1159 #endif /* !defined(ENABLE_SOFTFLOAT) */
1162 /* memory operations **************************************************/
1164 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1166 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1167 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1168 /* implicit null-pointer check */
1169 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1170 emit_store_dst(jd, iptr, d);
1173 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1175 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1176 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1177 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1178 /* implicit null-pointer check */
1179 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1180 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1181 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1182 emit_store_dst(jd, iptr, d);
1185 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1187 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1188 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1189 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1190 /* implicit null-pointer check */
1191 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1192 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1193 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1194 emit_store_dst(jd, iptr, d);
1197 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1199 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1200 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1201 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1202 /* implicit null-pointer check */
1203 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1204 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1205 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1206 emit_store_dst(jd, iptr, d);
1209 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1211 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1212 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1213 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1214 /* implicit null-pointer check */
1215 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1216 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1217 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1218 emit_store_dst(jd, iptr, d);
1221 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1223 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1224 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1225 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1226 /* implicit null-pointer check */
1227 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1228 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1229 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1230 emit_store_dst(jd, iptr, d);
1233 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1235 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1236 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1237 /* implicit null-pointer check */
1238 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1239 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1240 #if !defined(ENABLE_SOFTFLOAT)
1241 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1242 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1244 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1245 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1247 emit_store_dst(jd, iptr, d);
1250 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1252 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1253 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1254 /* implicit null-pointer check */
1255 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1256 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1257 #if !defined(ENABLE_SOFTFLOAT)
1258 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1259 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1261 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1262 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1264 emit_store_dst(jd, iptr, d);
1267 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1269 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1270 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1271 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1272 /* implicit null-pointer check */
1273 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1274 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1275 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1276 emit_store_dst(jd, iptr, d);
1279 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1281 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1282 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1283 /* implicit null-pointer check */
1284 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1285 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1286 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1287 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1290 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1292 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1293 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1294 /* implicit null-pointer check */
1295 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1296 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1297 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1298 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1301 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1303 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1304 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1305 /* implicit null-pointer check */
1306 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1307 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1308 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1309 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1312 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1314 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1315 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1316 /* implicit null-pointer check */
1317 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1318 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1319 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1320 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1323 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1325 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1326 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1327 /* implicit null-pointer check */
1328 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1329 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1330 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1331 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1334 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1336 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1337 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1338 /* implicit null-pointer check */
1339 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1340 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1341 #if !defined(ENABLE_SOFTFLOAT)
1342 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1343 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1345 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1346 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1350 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1352 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1353 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1354 /* implicit null-pointer check */
1355 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1356 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1357 #if !defined(ENABLE_SOFTFLOAT)
1358 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1359 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1361 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1362 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1366 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1368 s1 = emit_load_s1(jd, iptr, REG_A0);
1369 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1370 s3 = emit_load_s3(jd, iptr, REG_A1);
1372 /* implicit null-pointer check */
1373 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1375 /* move arguments to argument registers */
1376 M_INTMOVE(s1, REG_A0);
1377 M_INTMOVE(s3, REG_A1);
1379 /* call builtin function */
1380 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1381 M_DSEG_BRANCH(disp);
1384 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1387 /* check resturn value of builtin */
1388 emit_arraystore_check(cd, iptr);
1390 /* finally store address into array */
1391 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1392 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1393 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1394 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1395 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1398 case ICMD_GETSTATIC: /* ... ==> ..., value */
1400 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1401 uf = iptr->sx.s23.s3.uf;
1402 fieldtype = uf->fieldref->parseddesc.fd->type;
1403 disp = dseg_add_unique_address(cd, NULL);
1405 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1408 fi = iptr->sx.s23.s3.fmiref->p.field;
1409 fieldtype = fi->type;
1410 disp = dseg_add_address(cd, fi->value);
1412 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1413 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1418 M_DSEG_LOAD(REG_ITMP3, disp);
1419 switch (fieldtype) {
1421 #if defined(ENABLE_SOFTFLOAT)
1425 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1426 M_ILD_INTERN(d, REG_ITMP3, 0);
1429 #if defined(ENABLE_SOFTFLOAT)
1432 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1433 M_LLD_INTERN(d, REG_ITMP3, 0);
1435 #if !defined(ENABLE_SOFTFLOAT)
1437 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1438 M_FLD_INTERN(d, REG_ITMP3, 0);
1441 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1442 M_DLD_INTERN(d, REG_ITMP3, 0);
1448 emit_store_dst(jd, iptr, d);
1451 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1453 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1454 uf = iptr->sx.s23.s3.uf;
1455 fieldtype = uf->fieldref->parseddesc.fd->type;
1456 disp = dseg_add_unique_address(cd, NULL);
1458 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1461 fi = iptr->sx.s23.s3.fmiref->p.field;
1462 fieldtype = fi->type;
1463 disp = dseg_add_address(cd, fi->value);
1465 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1466 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1471 M_DSEG_LOAD(REG_ITMP3, disp);
1472 switch (fieldtype) {
1474 #if defined(ENABLE_SOFTFLOAT)
1478 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1479 M_IST_INTERN(s1, REG_ITMP3, 0);
1482 #if defined(ENABLE_SOFTFLOAT)
1485 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1486 M_LST_INTERN(s1, REG_ITMP3, 0);
1488 #if !defined(ENABLE_SOFTFLOAT)
1490 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1491 M_FST_INTERN(s1, REG_ITMP3, 0);
1494 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1495 M_DST_INTERN(s1, REG_ITMP3, 0);
1503 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1505 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1506 emit_nullpointer_check(cd, iptr, s1);
1509 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1510 uf = iptr->sx.s23.s3.uf;
1511 fieldtype = uf->fieldref->parseddesc.fd->type;
1515 fi = iptr->sx.s23.s3.fmiref->p.field;
1516 fieldtype = fi->type;
1520 #if !defined(ENABLE_SOFTFLOAT)
1521 /* HACK: softnull checks on floats */
1522 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1523 emit_nullpointer_check_force(cd, iptr, s1);
1526 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1528 uf = iptr->sx.s23.s3.uf;
1530 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1533 switch (fieldtype) {
1535 #if defined(ENABLE_SOFTFLOAT)
1539 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1543 #if defined(ENABLE_SOFTFLOAT)
1546 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1549 #if !defined(ENABLE_SOFTFLOAT)
1551 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1555 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1562 emit_store_dst(jd, iptr, d);
1565 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1567 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1568 emit_nullpointer_check(cd, iptr, s1);
1570 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1571 uf = iptr->sx.s23.s3.uf;
1572 fieldtype = uf->fieldref->parseddesc.fd->type;
1576 fi = iptr->sx.s23.s3.fmiref->p.field;
1577 fieldtype = fi->type;
1581 #if !defined(ENABLE_SOFTFLOAT)
1582 /* HACK: softnull checks on floats */
1583 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1584 emit_nullpointer_check_force(cd, iptr, s1);
1587 switch (fieldtype) {
1589 #if defined(ENABLE_SOFTFLOAT)
1593 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1595 #if defined(ENABLE_SOFTFLOAT)
1596 case TYPE_DBL: /* fall through */
1599 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1601 #if !defined(ENABLE_SOFTFLOAT)
1604 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1611 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1613 uf = iptr->sx.s23.s3.uf;
1615 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1618 switch (fieldtype) {
1620 #if defined(ENABLE_SOFTFLOAT)
1624 M_IST(s2, s1, disp);
1627 #if defined(ENABLE_SOFTFLOAT)
1630 M_LST(s2, s1, disp);
1632 #if !defined(ENABLE_SOFTFLOAT)
1634 M_FST(s2, s1, disp);
1637 M_DST(s2, s1, disp);
1646 /* branch operations **************************************************/
1648 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1650 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1651 M_INTMOVE(s1, REG_ITMP1_XPTR);
1652 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1653 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1654 iptr->sx.s23.s2.uc, 0);
1656 disp = dseg_add_functionptr(cd, asm_handle_exception);
1657 M_DSEG_LOAD(REG_ITMP3, disp);
1658 M_MOV(REG_ITMP2_XPC, REG_PC);
1659 M_MOV(REG_PC, REG_ITMP3);
1660 M_NOP; /* nop ensures that XPC is less than the end */
1661 /* of basic block */
1664 case ICMD_GOTO: /* ... ==> ... */
1667 emit_br(cd, iptr->dst.block);
1670 case ICMD_JSR: /* ... ==> ... */
1672 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1675 case ICMD_IFNULL: /* ..., value ==> ... */
1676 case ICMD_IFNONNULL:
1678 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1680 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1683 case ICMD_IFLT: /* ..., value ==> ... */
1684 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1690 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1691 M_COMPARE(s1, iptr->sx.val.i);
1692 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1695 case ICMD_IF_LEQ: /* ..., value ==> ... */
1697 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1698 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1699 if (iptr->sx.val.l == 0) {
1700 M_ORR_S(s1, s2, REG_ITMP3);
1703 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1704 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1705 M_CMP(s1, REG_ITMP3);*/
1706 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1707 M_CMPEQ(s2, REG_ITMP3);
1709 emit_beq(cd, iptr->dst.block);
1712 case ICMD_IF_LLT: /* ..., value ==> ... */
1714 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1715 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1716 if (iptr->sx.val.l == 0) {
1717 /* if high word is less than zero, the whole long is too */
1719 emit_blt(cd, iptr->dst.block);
1722 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1723 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1724 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1725 M_CMP(s1, REG_ITMP3);*/
1726 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1727 M_MOVGT_IMM(2, REG_ITMP1);
1728 M_MOVEQ_IMM(1, REG_ITMP1);
1730 /* low compare: x=x-1(ifLO) */
1731 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1732 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1733 M_CMP(s2, REG_ITMP3);*/
1734 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1736 /* branch if (x LT 1) */
1737 M_CMP_IMM(REG_ITMP1, 1);
1738 emit_blt(cd, iptr->dst.block);
1742 case ICMD_IF_LLE: /* ..., value ==> ... */
1744 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1745 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1746 if (iptr->sx.val.l == 0) {
1747 /* if high word is less than zero, the whole long is too */
1749 emit_blt(cd, iptr->dst.block);
1751 /* ... otherwise the low word has to be zero (tricky!) */
1753 emit_beq(cd, iptr->dst.block);
1756 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1757 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1758 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1759 M_CMP(s1, REG_ITMP3);*/
1760 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1761 M_MOVGT_IMM(2, REG_ITMP1);
1762 M_MOVEQ_IMM(1, REG_ITMP1);
1764 /* low compare: x=x+1(ifHI) */
1765 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1766 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1767 M_CMP(s2, REG_ITMP3);*/
1768 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1770 /* branch if (x LE 1) */
1771 M_CMP_IMM(REG_ITMP1, 1);
1772 emit_ble(cd, iptr->dst.block);
1776 case ICMD_IF_LGE: /* ..., value ==> ... */
1778 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1779 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1780 if (iptr->sx.val.l == 0) {
1781 /* if high word is greater or equal zero, the whole long is too */
1783 emit_bge(cd, iptr->dst.block);
1786 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1787 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1788 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1789 M_CMP(s1, REG_ITMP3);*/
1790 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1791 M_MOVGT_IMM(2, REG_ITMP1);
1792 M_MOVEQ_IMM(1, REG_ITMP1);
1794 /* low compare: x=x-1(ifLO) */
1795 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1796 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1797 M_CMP(s2, REG_ITMP3);*/
1798 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1800 /* branch if (x GE 1) */
1801 M_CMP_IMM(REG_ITMP1, 1);
1802 emit_bge(cd, iptr->dst.block);
1806 case ICMD_IF_LGT: /* ..., value ==> ... */
1808 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1809 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1811 if (iptr->sx.val.l == 0) {
1812 /* if high word is greater than zero, the whole long is too */
1815 codegen_add_branch_ref(cd, iptr->dst.block);
1817 /* ... or high was zero and low is non zero (tricky!) */
1818 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1819 M_MOVLT_IMM(1, REG_ITMP3);
1820 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1822 codegen_add_branch_ref(cd, iptr->dst.block);
1826 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1827 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1828 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1829 M_CMP(s1, REG_ITMP3);*/
1830 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1831 M_MOVGT_IMM(2, REG_ITMP1);
1832 M_MOVEQ_IMM(1, REG_ITMP1);
1834 /* low compare: x=x+1(ifHI) */
1835 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1836 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1837 M_CMP(s2, REG_ITMP3);*/
1838 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1840 /* branch if (x GT 1) */
1841 M_CMP_IMM(REG_ITMP1, 1);
1842 emit_bgt(cd, iptr->dst.block);
1848 case ICMD_IF_LNE: /* ..., value ==> ... */
1850 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1851 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1852 if (iptr->sx.val.l == 0) {
1853 M_ORR_S(s1, s2, REG_ITMP3);
1856 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1857 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1858 M_CMP(s1, REG_ITMP3);*/
1859 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1860 M_CMPEQ(s2, REG_ITMP3);
1862 emit_bne(cd, iptr->dst.block);
1865 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1866 case ICMD_IF_ICMPNE:
1867 case ICMD_IF_ICMPLT:
1868 case ICMD_IF_ICMPLE:
1869 case ICMD_IF_ICMPGT:
1870 case ICMD_IF_ICMPGE:
1872 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1873 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1875 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1878 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1879 case ICMD_IF_ACMPNE:
1881 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1882 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1884 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1887 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1888 /* op1 = target JavaVM pc */
1890 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1891 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1894 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1895 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1898 emit_beq(cd, iptr->dst.block);
1901 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1902 /* op1 = target JavaVM pc */
1904 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1905 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1908 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1909 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1912 emit_bne(cd, iptr->dst.block);
1915 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1916 /* op1 = target JavaVM pc */
1918 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1919 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1920 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1922 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1923 M_MOVGT_IMM(2, REG_ITMP3);
1924 M_MOVEQ_IMM(1, REG_ITMP3);
1926 /* low compare: x=x-1(ifLO) */
1927 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1928 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1930 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1932 /* branch if (x LT 1) */
1933 M_CMP_IMM(REG_ITMP3, 1);
1934 emit_blt(cd, iptr->dst.block);
1937 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1938 /* op1 = target JavaVM pc */
1940 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1941 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1942 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1944 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1945 M_MOVGT_IMM(2, REG_ITMP3);
1946 M_MOVEQ_IMM(1, REG_ITMP3);
1948 /* low compare: x=x-1(ifLO) */
1949 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1950 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1952 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1954 /* branch if (x LE 1) */
1955 M_CMP_IMM(REG_ITMP3, 1);
1956 emit_ble(cd, iptr->dst.block);
1959 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1960 /* op1 = target JavaVM pc */
1962 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1963 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1964 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1966 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1967 M_MOVGT_IMM(2, REG_ITMP3);
1968 M_MOVEQ_IMM(1, REG_ITMP3);
1970 /* low compare: x=x-1(ifLO) */
1971 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1972 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1974 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1976 /* branch if (x GT 1) */
1977 M_CMP_IMM(REG_ITMP3, 1);
1978 emit_bgt(cd, iptr->dst.block);
1981 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1982 /* op1 = target JavaVM pc */
1984 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1985 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1986 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1988 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1989 M_MOVGT_IMM(2, REG_ITMP3);
1990 M_MOVEQ_IMM(1, REG_ITMP3);
1992 /* low compare: x=x-1(ifLO) */
1993 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1994 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1996 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1998 /* branch if (x GE 1) */
1999 M_CMP_IMM(REG_ITMP3, 1);
2000 emit_bge(cd, iptr->dst.block);
2003 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2006 branch_target_t *table;
2008 table = iptr->dst.table;
2010 l = iptr->sx.s23.s2.tablelow;
2011 i = iptr->sx.s23.s3.tablehigh;
2013 /* calculate new index (index - low) */
2014 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2016 M_INTMOVE(s1, REG_ITMP1);
2017 } else if (IS_IMM(l)) {
2018 M_SUB_IMM(REG_ITMP1, s1, l);
2020 ICONST(REG_ITMP2, l);
2021 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2024 /* range check (index <= high-low) */
2026 M_COMPARE(REG_ITMP1, i-1);
2027 emit_bugt(cd, table[0].block);
2029 /* build jump table top down and use address of lowest entry */
2034 dseg_add_target(cd, table->block);
2039 /* length of dataseg after last dseg_add_target is used by load */
2040 /* TODO: this loads from data-segment */
2041 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2042 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2045 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2048 lookup_target_t *lookup;
2050 lookup = iptr->dst.lookup;
2052 i = iptr->sx.s23.s2.lookupcount;
2055 MCODECHECK((i<<2)+8);
2056 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2059 M_COMPARE(s1, lookup->value);
2060 emit_beq(cd, lookup->target.block);
2064 /* default branch */
2065 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2069 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2071 #if !defined(ENABLE_SOFTFLOAT)
2072 REPLACEMENT_POINT_RETURN(cd, iptr);
2073 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2074 M_CAST_F2I(s1, REG_RESULT);
2075 goto ICMD_RETURN_do;
2078 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2080 REPLACEMENT_POINT_RETURN(cd, iptr);
2081 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2082 M_INTMOVE(s1, REG_RESULT);
2083 goto ICMD_RETURN_do;
2085 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2087 #if !defined(ENABLE_SOFTFLOAT)
2088 REPLACEMENT_POINT_RETURN(cd, iptr);
2089 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2090 M_CAST_D2L(s1, REG_RESULT_PACKED);
2091 goto ICMD_RETURN_do;
2094 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2096 REPLACEMENT_POINT_RETURN(cd, iptr);
2097 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2098 M_LNGMOVE(s1, REG_RESULT_PACKED);
2099 goto ICMD_RETURN_do;
2101 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2103 REPLACEMENT_POINT_RETURN(cd, iptr);
2104 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2105 M_INTMOVE(s1, REG_RESULT);
2106 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2107 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2108 iptr->sx.s23.s2.uc, 0);
2110 goto ICMD_RETURN_do;
2112 case ICMD_RETURN: /* ... ==> ... */
2114 REPLACEMENT_POINT_RETURN(cd, iptr);
2117 #if !defined(NDEBUG)
2118 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2119 emit_verbosecall_exit(jd);
2122 #if defined(ENABLE_THREADS)
2123 /* call monitorexit function */
2125 if (checksync && code_is_synchronized(code)) {
2126 /* stack offset for monitor argument */
2128 s1 = rd->memuse * 8;
2130 /* we need to save the proper return value */
2132 switch (iptr->opc) {
2136 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2138 M_STMFD(BITMASK_RESULT, REG_SP);
2143 M_LDR(REG_A0, REG_SP, s1);
2144 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2145 M_DSEG_BRANCH(disp);
2147 /* we no longer need PV here, no more loading */
2148 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2149 M_RECOMPUTE_PV(s1);*/
2151 switch (iptr->opc) {
2155 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2157 M_LDMFD(BITMASK_RESULT, REG_SP);
2163 /* deallocate stackframe for spilled variables */
2165 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2166 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2168 /* restore callee saved registers + do return */
2170 if (savedregs_bitmask) {
2171 if (!code_is_leafmethod(code)) {
2172 savedregs_bitmask &= ~(1<<REG_LR);
2173 savedregs_bitmask |= (1<<REG_PC);
2175 M_LDMFD(savedregs_bitmask, REG_SP);
2178 /* if LR was not on stack, we need to return manually */
2180 if (code_is_leafmethod(code))
2181 M_MOV(REG_PC, REG_LR);
2184 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2186 bte = iptr->sx.s23.s3.bte;
2188 goto ICMD_INVOKE_do;
2190 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2191 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2192 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2193 case ICMD_INVOKEINTERFACE:
2195 REPLACEMENT_POINT_INVOKE(cd, iptr);
2197 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2199 um = iptr->sx.s23.s3.um;
2200 md = um->methodref->parseddesc.md;
2203 lm = iptr->sx.s23.s3.fmiref->p.method;
2205 md = lm->parseddesc;
2209 /* copy arguments to registers or stack location */
2211 s3 = md->paramcount;
2213 MCODECHECK((s3 << 1) + 64);
2215 for (s3 = s3 - 1; s3 >= 0; s3--) {
2216 var = VAR(iptr->sx.s23.s2.args[s3]);
2217 d = md->params[s3].regoff;
2219 if (var->flags & PREALLOC) /* argument was precolored? */
2222 /* TODO: document me */
2223 #if !defined(ENABLE_SOFTFLOAT)
2224 if (IS_INT_LNG_TYPE(var->type)) {
2225 #endif /* !defined(ENABLE_SOFTFLOAT) */
2226 if (!md->params[s3].inmemory) {
2227 s1 = emit_load(jd, iptr, var, d);
2229 if (IS_2_WORD_TYPE(var->type))
2235 if (IS_2_WORD_TYPE(var->type)) {
2236 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2237 M_LST(s1, REG_SP, d);
2240 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2241 M_IST(s1, REG_SP, d);
2244 #if !defined(ENABLE_SOFTFLOAT)
2247 if (!md->params[s3].inmemory) {
2248 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2249 if (IS_2_WORD_TYPE(var->type))
2255 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2256 if (IS_2_WORD_TYPE(var->type))
2257 M_DST(s1, REG_SP, d);
2259 M_FST(s1, REG_SP, d);
2262 #endif /* !defined(ENABLE_SOFTFLOAT) */
2265 switch (iptr->opc) {
2268 if (bte->stub == NULL) {
2269 disp = dseg_add_functionptr(cd, bte->fp);
2271 disp = dseg_add_functionptr(cd, bte->stub);
2274 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2276 /* generate the actual call */
2278 M_MOV(REG_LR, REG_PC);
2279 M_MOV(REG_PC, REG_PV);
2280 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2284 case ICMD_INVOKESPECIAL:
2285 emit_nullpointer_check(cd, iptr, REG_A0);
2288 case ICMD_INVOKESTATIC:
2290 disp = dseg_add_unique_address(cd, NULL);
2292 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2296 disp = dseg_add_address(cd, lm->stubroutine);
2298 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2300 /* generate the actual call */
2302 M_MOV(REG_LR, REG_PC);
2303 M_MOV(REG_PC, REG_PV);
2304 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2308 case ICMD_INVOKEVIRTUAL:
2310 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2315 s1 = OFFSET(vftbl_t, table[0]) +
2316 sizeof(methodptr) * lm->vftblindex;
2318 /* implicit null-pointer check */
2319 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2320 OFFSET(java_object_t, vftbl));
2321 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2323 /* generate the actual call */
2325 M_MOV(REG_LR, REG_PC);
2326 M_MOV(REG_PC, REG_PV);
2327 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2331 case ICMD_INVOKEINTERFACE:
2333 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2339 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2340 sizeof(methodptr*) * lm->class->index;
2341 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2344 /* implicit null-pointer check */
2345 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2346 OFFSET(java_object_t, vftbl));
2347 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2348 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2350 /* generate the actual call */
2352 M_MOV(REG_LR, REG_PC);
2353 M_MOV(REG_PC, REG_PV);
2354 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2359 /* store size of call code in replacement point */
2360 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2362 /* store return value */
2364 d = md->returntype.type;
2366 #if !defined(__SOFTFP__)
2367 /* TODO: this is only a hack, since we use R0/R1 for float
2368 return! this depends on gcc; it is independent from
2369 our ENABLE_SOFTFLOAT define */
2370 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2371 #if 0 && !defined(NDEBUG)
2372 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2374 /* we cannot use this macro, since it is not defined
2375 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2376 REG_FRESULT, REG_RESULT_TYPED(d)); */
2377 if (IS_2_WORD_TYPE(d)) {
2378 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2379 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2381 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2382 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2387 if (d != TYPE_VOID) {
2388 #if !defined(ENABLE_SOFTFLOAT)
2389 if (IS_INT_LNG_TYPE(d)) {
2390 #endif /* !defined(ENABLE_SOFTFLOAT) */
2391 if (IS_2_WORD_TYPE(d)) {
2392 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2393 M_LNGMOVE(REG_RESULT_PACKED, s1);
2396 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2397 M_INTMOVE(REG_RESULT, s1);
2400 #if !defined(ENABLE_SOFTFLOAT)
2402 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2403 if (IS_2_WORD_TYPE(d))
2404 M_CAST_L2D(REG_RESULT_PACKED, s1);
2406 M_CAST_I2F(REG_RESULT, s1);
2408 #endif /* !defined(ENABLE_SOFTFLOAT) */
2410 emit_store_dst(jd, iptr, s1);
2414 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2416 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2417 /* object type cast-check */
2422 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2427 super = iptr->sx.s23.s3.c.cls;
2428 superindex = super->index;
2431 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2432 CODEGEN_CRITICAL_SECTION_NEW;
2434 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2436 /* if class is not resolved, check which code to call */
2438 if (super == NULL) {
2440 emit_label_beq(cd, BRANCH_LABEL_1);
2442 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2443 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2444 iptr->sx.s23.s3.c.ref, disp);
2446 M_DSEG_LOAD(REG_ITMP2, disp);
2447 disp = dseg_add_s4(cd, ACC_INTERFACE);
2448 M_DSEG_LOAD(REG_ITMP3, disp);
2449 M_TST(REG_ITMP2, REG_ITMP3);
2450 emit_label_beq(cd, BRANCH_LABEL_2);
2453 /* interface checkcast code */
2455 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2456 if ((super == NULL) || !IS_IMM(superindex)) {
2457 disp = dseg_add_unique_s4(cd, superindex);
2459 if (super == NULL) {
2460 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2461 iptr->sx.s23.s3.c.ref, disp);
2465 emit_label_beq(cd, BRANCH_LABEL_3);
2468 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2469 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2471 /* we put unresolved or non-immediate superindices onto dseg */
2472 if ((super == NULL) || !IS_IMM(superindex)) {
2473 /* disp was computed before we added the patcher */
2474 M_DSEG_LOAD(REG_ITMP2, disp);
2475 M_CMP(REG_ITMP3, REG_ITMP2);
2477 assert(IS_IMM(superindex));
2478 M_CMP_IMM(REG_ITMP3, superindex);
2481 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2483 /* if we loaded the superindex out of the dseg above, we do
2484 things differently here! */
2485 if ((super == NULL) || !IS_IMM(superindex)) {
2487 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2489 /* this assumes something */
2490 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2492 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2493 assert(sizeof(methodptr*) == 4);
2494 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2500 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2501 superindex * sizeof(methodptr*);
2505 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2506 M_TST(REG_ITMP3, REG_ITMP3);
2507 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2510 emit_label_br(cd, BRANCH_LABEL_4);
2512 emit_label(cd, BRANCH_LABEL_3);
2515 /* class checkcast code */
2517 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2518 if (super == NULL) {
2519 emit_label(cd, BRANCH_LABEL_2);
2521 disp = dseg_add_unique_address(cd, NULL);
2523 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2524 iptr->sx.s23.s3.c.ref,
2528 disp = dseg_add_address(cd, super->vftbl);
2531 emit_label_beq(cd, BRANCH_LABEL_5);
2534 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2535 M_DSEG_LOAD(REG_ITMP3, disp);
2537 CODEGEN_CRITICAL_SECTION_START;
2539 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2540 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2541 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2542 M_DSEG_LOAD(REG_ITMP3, disp);
2543 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2545 CODEGEN_CRITICAL_SECTION_END;
2547 M_CMP(REG_ITMP2, REG_ITMP3);
2548 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2551 emit_label(cd, BRANCH_LABEL_5);
2554 if (super == NULL) {
2555 emit_label(cd, BRANCH_LABEL_1);
2556 emit_label(cd, BRANCH_LABEL_4);
2559 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2562 /* array type cast-check */
2564 s1 = emit_load_s1(jd, iptr, REG_A0);
2565 M_INTMOVE(s1, REG_A0);
2567 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2568 disp = dseg_add_unique_address(cd, NULL);
2570 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2571 iptr->sx.s23.s3.c.ref,
2575 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2577 M_DSEG_LOAD(REG_A1, disp);
2578 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2579 M_DSEG_BRANCH(disp);
2582 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2583 M_RECOMPUTE_PV(disp);
2585 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2586 M_TST(REG_RESULT, REG_RESULT);
2587 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2589 d = codegen_reg_of_dst(jd, iptr, s1);
2593 emit_store_dst(jd, iptr, d);
2596 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2602 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2607 super = iptr->sx.s23.s3.c.cls;
2608 superindex = super->index;
2611 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2612 CODEGEN_CRITICAL_SECTION_NEW;
2614 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2615 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2618 M_MOV(REG_ITMP1, s1);
2622 /* if class is not resolved, check which code to call */
2624 if (super == NULL) {
2628 emit_label_beq(cd, BRANCH_LABEL_1);
2630 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2631 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2632 iptr->sx.s23.s3.c.ref, disp);
2634 M_DSEG_LOAD(REG_ITMP2, disp);
2635 disp = dseg_add_s4(cd, ACC_INTERFACE);
2636 M_DSEG_LOAD(REG_ITMP3, disp);
2637 M_TST(REG_ITMP2, REG_ITMP3);
2638 emit_label_beq(cd, BRANCH_LABEL_2);
2641 /* interface checkcast code */
2643 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2644 if ((super == NULL) || !IS_IMM(superindex)) {
2645 disp = dseg_add_unique_s4(cd, superindex);
2647 if (super == NULL) {
2648 /* If d == REG_ITMP2, then it's destroyed in check
2653 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2654 iptr->sx.s23.s3.c.ref, disp);
2659 emit_label_beq(cd, BRANCH_LABEL_3);
2662 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2663 M_LDR_INTERN(REG_ITMP3,
2664 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2666 /* we put unresolved or non-immediate superindices onto dseg
2667 and do things slightly different */
2668 if ((super == NULL) || !IS_IMM(superindex)) {
2669 /* disp was computed before we added the patcher */
2670 M_DSEG_LOAD(REG_ITMP2, disp);
2671 M_CMP(REG_ITMP3, REG_ITMP2);
2673 if (d == REG_ITMP2) {
2680 /* this assumes something */
2681 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2683 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2684 assert(sizeof(methodptr*) == 4);
2685 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2687 if (d == REG_ITMP2) {
2694 assert(IS_IMM(superindex));
2695 M_CMP_IMM(REG_ITMP3, superindex);
2699 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2700 superindex * sizeof(methodptr*);
2704 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2705 M_TST(REG_ITMP3, REG_ITMP3);
2709 emit_label_br(cd, BRANCH_LABEL_4);
2711 emit_label(cd, BRANCH_LABEL_3);
2714 /* class checkcast code */
2716 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2717 if (super == NULL) {
2718 emit_label(cd, BRANCH_LABEL_2);
2720 disp = dseg_add_unique_address(cd, NULL);
2722 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2723 iptr->sx.s23.s3.c.ref, disp);
2726 disp = dseg_add_address(cd, super->vftbl);
2730 emit_label_beq(cd, BRANCH_LABEL_5);
2733 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2734 M_DSEG_LOAD(REG_ITMP2, disp);
2736 CODEGEN_CRITICAL_SECTION_START;
2738 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2739 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2740 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2742 CODEGEN_CRITICAL_SECTION_END;
2744 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2745 M_CMP(REG_ITMP1, REG_ITMP2);
2746 /* If d == REG_ITMP2, then it's destroyed */
2752 emit_label(cd, BRANCH_LABEL_5);
2755 if (super == NULL) {
2756 emit_label(cd, BRANCH_LABEL_1);
2757 emit_label(cd, BRANCH_LABEL_4);
2762 emit_store_dst(jd, iptr, d);
2765 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2767 /* copy sizes to stack if necessary */
2769 MCODECHECK((iptr->s1.argcount << 1) + 64);
2771 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2773 var = VAR(iptr->sx.s23.s2.args[s1]);
2775 /* copy SAVEDVAR sizes to stack */
2777 if (!(var->flags & PREALLOC)) {
2778 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2779 M_STR(s2, REG_SP, s1 * 4);
2783 /* a0 = dimension count */
2785 assert(IS_IMM(iptr->s1.argcount));
2786 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2788 /* is patcher function set? */
2790 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2791 disp = dseg_add_unique_address(cd, NULL);
2793 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2794 iptr->sx.s23.s3.c.ref, disp);
2797 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2799 /* a1 = arraydescriptor */
2801 M_DSEG_LOAD(REG_A1, disp);
2803 /* a2 = pointer to dimensions = stack pointer */
2805 M_INTMOVE(REG_SP, REG_A2);
2807 /* call builtin_multianewarray here */
2809 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2810 M_DSEG_BRANCH(disp);
2814 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2817 /* check for exception before result assignment */
2819 emit_exception_check(cd, iptr);
2823 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2824 M_INTMOVE(REG_RESULT, d);
2825 emit_store_dst(jd, iptr, d);
2828 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2830 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2831 emit_nullpointer_check(cd, iptr, s1);
2835 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2838 } /* the big switch */
2840 } /* for all instructions */
2842 } /* for all basic blocks */
2844 dseg_createlinenumbertable(cd);
2847 /* generate traps */
2849 emit_patcher_traps(jd);
2851 /* everything's ok */
2857 /* codegen_emit_stub_compiler **************************************************
2859 Emits a stub routine which calls the compiler.
2861 *******************************************************************************/
2863 void codegen_emit_stub_compiler(jitdata *jd)
2868 /* get required compiler data */
2873 /* code for the stub */
2875 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2876 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2880 /* codegen_emit_stub_native ****************************************************
2882 Emits a stub routine which calls a native method.
2884 *******************************************************************************/
2886 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2897 /* get required compiler data */
2903 /* initialize variables */
2907 /* calculate stackframe size */
2909 cd->stackframesize =
2910 4 + /* return address */
2911 sizeof(stackframeinfo_t) + /* stackframeinfo */
2912 sizeof(localref_table) + /* localref_table */
2913 nmd->memuse * 4; /* stack arguments */
2915 /* align stack to 8-byte */
2917 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2919 /* create method header */
2921 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2922 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2923 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2924 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2925 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2926 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2927 (void) dseg_addlinenumbertablesize(cd);
2928 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2930 /* generate stub code */
2932 M_STMFD(1<<REG_LR, REG_SP);
2933 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2935 #if !defined(NDEBUG)
2936 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2937 emit_verbosecall_enter(jd);
2940 #if defined(ENABLE_GC_CACAO)
2941 /* Save callee saved integer registers in stackframeinfo (GC may
2942 need to recover them during a collection). */
2944 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2945 OFFSET(stackframeinfo_t, intregs);
2947 for (i = 0; i < INT_SAV_CNT; i++)
2948 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2951 /* Save integer and float argument registers (these are 4
2952 registers, stack is 8-byte aligned). */
2954 M_STMFD(BITMASK_ARGS, REG_SP);
2955 /* TODO: floating point */
2957 /* create native stackframe info */
2959 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2960 M_MOV(REG_A1, REG_PV);
2961 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2962 M_DSEG_BRANCH(disp);
2966 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2969 /* remember class argument */
2971 if (m->flags & ACC_STATIC)
2972 M_MOV(REG_ITMP3, REG_RESULT);
2974 /* Restore integer and float argument registers (these are 4
2975 registers, stack is 8-byte aligned). */
2977 M_LDMFD(BITMASK_ARGS, REG_SP);
2978 /* TODO: floating point */
2980 /* copy or spill arguments to new locations */
2981 /* ATTENTION: the ARM has only integer argument registers! */
2983 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2984 t = md->paramtypes[i].type;
2986 if (!md->params[i].inmemory) {
2987 s1 = md->params[i].regoff;
2988 s2 = nmd->params[j].regoff;
2990 if (!nmd->params[j].inmemory) {
2991 #if !defined(__ARM_EABI__)
2992 SPLIT_OPEN(t, s2, REG_ITMP1);
2995 if (IS_2_WORD_TYPE(t))
3000 #if !defined(__ARM_EABI__)
3001 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3005 if (IS_2_WORD_TYPE(t))
3006 M_LST(s1, REG_SP, s2);
3008 M_IST(s1, REG_SP, s2);
3012 s1 = md->params[i].regoff + cd->stackframesize;
3013 s2 = nmd->params[j].regoff;
3015 if (IS_2_WORD_TYPE(t)) {
3016 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3017 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3020 M_ILD(REG_ITMP1, REG_SP, s1);
3021 M_IST(REG_ITMP1, REG_SP, s2);
3026 /* Handle native Java methods. */
3028 if (m->flags & ACC_NATIVE) {
3029 /* put class into second argument register */
3031 if (m->flags & ACC_STATIC)
3032 M_MOV(REG_A1, REG_ITMP3);
3034 /* put env into first argument register */
3036 disp = dseg_add_address(cd, _Jv_env);
3037 M_DSEG_LOAD(REG_A0, disp);
3040 /* Call the native function. */
3042 disp = dseg_add_functionptr(cd, f);
3043 M_DSEG_BRANCH(disp);
3046 /* TODO: this is only needed because of the tracer ... do we
3049 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3052 #if !defined(__SOFTFP__)
3053 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3054 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3055 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3056 #if 0 && !defined(NDEBUG)
3057 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3059 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3060 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3061 if (IS_2_WORD_TYPE(md->returntype.type)) {
3062 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3063 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3065 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3066 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3071 #if !defined(NDEBUG)
3072 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3073 emit_verbosecall_exit(jd);
3076 /* remove native stackframe info */
3077 /* TODO: improve this store/load */
3079 M_STMFD(BITMASK_RESULT, REG_SP);
3081 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3082 M_MOV(REG_A1, REG_PV);
3083 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3084 M_DSEG_BRANCH(disp);
3085 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3088 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3089 M_LDMFD(BITMASK_RESULT, REG_SP);
3091 #if defined(ENABLE_GC_CACAO)
3092 /* restore callee saved int registers from stackframeinfo (GC might have */
3093 /* modified them during a collection). */
3095 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3096 OFFSET(stackframeinfo_t, intregs);
3098 for (i = 0; i < INT_SAV_CNT; i++)
3099 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3102 /* finish stub code, but do not yet return to caller */
3104 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3105 M_LDMFD(1<<REG_LR, REG_SP);
3107 /* check for exception */
3109 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3110 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3112 /* handle exception here */
3114 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3116 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3117 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3118 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3120 /* generate patcher stubs */
3122 emit_patcher_traps(jd);
3126 /* asm_debug *******************************************************************
3130 *******************************************************************************/
3132 void asm_debug(int a1, int a2, int a3, int a4)
3134 printf("===> i am going to exit after this debugging message!\n");
3135 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3136 vm_abort("leave you now");
3141 * These are local overrides for various environment variables in Emacs.
3142 * Please do not remove this and leave it at the end of the file, where
3143 * Emacs will automagically detect them.
3144 * ---------------------------------------------------------------------
3147 * indent-tabs-mode: t
3151 * vim:noexpandtab:sw=4:ts=4: