1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: codegen.c 8182 2007-07-05 20:36:16Z michi $
39 #include "vm/jit/arm/arch.h"
40 #include "vm/jit/arm/codegen.h"
42 #include "mm/memory.h"
44 #include "native/native.h"
46 #include "threads/lock-common.h"
48 #include "vm/builtin.h"
49 #include "vm/exceptions.h"
50 #include "vm/global.h"
53 #include "vm/jit/asmpart.h"
54 #include "vm/jit/codegen-common.h"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/emit-common.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/md.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher-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)
99 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
100 unresolved_method *um;
101 builtintable_entry *bte;
104 /* get required compiler data */
111 /* prevent compiler warnings */
119 /* space to save used callee saved registers */
121 savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
122 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
123 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
124 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
126 spilledregs_num = rd->memuse;
128 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
129 if (checksync && (m->flags & ACC_SYNCHRONIZED))
133 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
135 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
136 only in native stubs. */
137 /* align stack to 8-byte */
139 cd->stackframesize = (cd->stackframesize + 4) & ~4;
141 /* SECTION: Method Header */
142 /* create method header */
144 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
145 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
147 #if defined(ENABLE_THREADS)
148 /* IsSync contains the offset relative to the stack pointer for the
149 argument of monitor_exit used in the exception handler. Since the
150 offset could be zero and give a wrong meaning of the flag it is
154 if (checksync && (m->flags & ACC_SYNCHRONIZED))
155 (void) dseg_add_unique_s4(cd, rd->memuse * 8 + 4);/* IsSync */
158 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
160 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
161 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
162 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
163 (void) dseg_addlinenumbertablesize(cd);
164 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
166 /* create exception table */
168 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
169 dseg_add_target(cd, ex->start);
170 dseg_add_target(cd, ex->end);
171 dseg_add_target(cd, ex->handler);
172 (void) dseg_add_unique_address(cd, ex->catchtype.any);
175 /* save return address and used callee saved registers */
177 savedregs_bitmask = 0;
179 if (!jd->isleafmethod)
180 savedregs_bitmask = (1<<REG_LR);
182 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
183 savedregs_bitmask |= (1<<(rd->savintregs[i]));
186 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
187 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
188 /* TODO: floating-point */
192 if (savedregs_bitmask)
193 M_STMFD(savedregs_bitmask, REG_SP);
195 /* create additional stack frame for spilled variables (if necessary) */
197 if ((cd->stackframesize / 4 - savedregs_num) > 0)
198 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
200 /* take arguments out of register or stack frame */
203 for (i = 0, len = 0; i < md->paramcount; i++) {
204 s1 = md->params[i].regoff;
205 t = md->paramtypes[i].type;
207 varindex = jd->local_map[len * 5 + t];
209 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
211 if (varindex == UNUSED)
216 /* ATTENTION: we use interger registers for all arguments (even float) */
217 #if !defined(ENABLE_SOFTFLOAT)
218 if (IS_INT_LNG_TYPE(t)) {
220 if (!md->params[i].inmemory) {
221 if (!(var->flags & INMEMORY)) {
222 if (IS_2_WORD_TYPE(t))
223 M_LNGMOVE(s1, var->vv.regoff);
225 M_INTMOVE(s1, var->vv.regoff);
228 if (IS_2_WORD_TYPE(t))
229 M_LST(s1, REG_SP, var->vv.regoff);
231 M_IST(s1, REG_SP, var->vv.regoff);
234 else { /* stack arguments */
235 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
236 if (IS_2_WORD_TYPE(t))
237 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
239 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
241 else { /* stack arg -> spilled */
242 /* Reuse Memory Position on Caller Stack */
243 var->vv.regoff = cd->stackframesize + s1;
246 #if !defined(ENABLE_SOFTFLOAT)
249 if (!md->params[i].inmemory) {
250 if (!(var->flags & INMEMORY)) {
251 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
254 if (IS_2_WORD_TYPE(t))
255 M_LST(s1, REG_SP, var->vv.regoff);
257 M_IST(s1, REG_SP, var->vv.regoff);
261 if (!(var->flags & INMEMORY)) {
262 if (IS_2_WORD_TYPE(t))
263 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
265 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
268 /* Reuse Memory Position on Caller Stack */
269 var->vv.regoff = cd->stackframesize + s1;
273 #endif /* !defined(ENABLE_SOFTFLOAT) */
276 #if defined(ENABLE_THREADS)
277 /* call monitorenter function */
279 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
280 /* stack offset for monitor argument */
284 # if !defined(NDEBUG)
285 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
286 M_STMFD(BITMASK_ARGS, REG_SP);
291 /* get the correct lock object */
293 if (m->flags & ACC_STATIC) {
294 disp = dseg_add_address(cd, &m->class->object.header);
295 M_DSEG_LOAD(REG_A0, disp);
298 emit_nullpointer_check_force(cd, iptr, REG_A0);
301 M_STR(REG_A0, REG_SP, s1);
302 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
304 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
307 # if !defined(NDEBUG)
308 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
309 M_LDMFD(BITMASK_ARGS, REG_SP);
315 /* call trace function */
317 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
318 emit_verbosecall_enter(jd);
321 /* end of header generation */
323 /* create replacement points */
324 REPLACEMENT_POINTS_INIT(cd, jd);
326 /* SECTION: ICMD Code Generation */
327 /* for all basic blocks */
329 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
331 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
333 /* is this basic block reached? */
335 if (bptr->flags < BBREACHED)
338 /* branch resolving */
340 codegen_resolve_branchrefs(cd, bptr);
342 /* handle replacement points */
343 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
345 /* copy interface registers to their destination */
351 #if defined(ENABLE_LSRA)
355 var = VAR(bptr->invars[len]);
356 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
357 if (!(var->flags & INMEMORY))
361 M_INTMOVE(REG_ITMP1, d);
362 emit_store(jd, NULL, var, d);
369 var = VAR(bptr->invars[len]);
371 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
372 d = codegen_reg_of_var(0, var, REG_ITMP1);
373 M_INTMOVE(REG_ITMP1, d);
374 emit_store(jd, NULL, var, d);
377 assert((var->flags & INOUT));
380 #if defined(ENABLE_LSRA)
384 /* for all instructions */
387 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
389 /* add line number */
390 if (iptr->line != currentline) {
391 dseg_addlinenumber(cd, iptr->line);
392 currentline = iptr->line;
395 MCODECHECK(64); /* an instruction usually needs < 64 words */
399 case ICMD_NOP: /* ... ==> ... */
402 /* constant operations ************************************************/
404 case ICMD_ICONST: /* ... ==> ..., constant */
406 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
407 ICONST(d, iptr->sx.val.i);
408 emit_store_dst(jd, iptr, d);
411 case ICMD_ACONST: /* ... ==> ..., constant */
413 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
414 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
415 disp = dseg_add_unique_address(cd, NULL);
417 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
418 iptr->sx.val.c.ref, disp);
420 if (opt_showdisassemble)
423 M_DSEG_LOAD(d, disp);
426 ICONST(d, (u4) iptr->sx.val.anyptr);
428 emit_store_dst(jd, iptr, d);
431 case ICMD_LCONST: /* ... ==> ..., constant */
433 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
434 LCONST(d, iptr->sx.val.l);
435 emit_store_dst(jd, iptr, d);
438 case ICMD_FCONST: /* ... ==> ..., constant */
440 #if defined(ENABLE_SOFTFLOAT)
441 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
442 ICONST(d, iptr->sx.val.i);
443 emit_store_dst(jd, iptr, d);
445 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
446 FCONST(d, iptr->sx.val.f);
447 emit_store_dst(jd, iptr, d);
451 case ICMD_DCONST: /* ... ==> ..., constant */
453 #if defined(ENABLE_SOFTFLOAT)
454 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
455 LCONST(d, iptr->sx.val.l);
456 emit_store_dst(jd, iptr, d);
458 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
459 DCONST(d, iptr->sx.val.d);
460 emit_store_dst(jd, iptr, d);
465 /* load/store/copy/move operations ************************************/
467 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
468 case ICMD_ALOAD: /* op1 = local variable */
472 case ICMD_ISTORE: /* ..., value ==> ... */
483 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
487 /* pop operations *****************************************************/
489 /* attention: double and longs are only one entry in CACAO ICMDs */
491 case ICMD_POP: /* ..., value ==> ... */
492 case ICMD_POP2: /* ..., value, value ==> ... */
497 /* integer operations *************************************************/
499 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
501 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
502 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
503 M_MOV(d, REG_LSL(s1, 24));
504 M_MOV(d, REG_ASR(d, 24));
505 emit_store_dst(jd, iptr, d);
508 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
510 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
511 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
512 M_MOV(d, REG_LSL(s1, 16));
513 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
514 emit_store_dst(jd, iptr, d);
517 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
519 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
520 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
521 M_MOV(d, REG_LSL(s1, 16));
522 M_MOV(d, REG_ASR(d, 16));
523 emit_store_dst(jd, iptr, d);
526 case ICMD_I2L: /* ..., value ==> ..., value */
528 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
529 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
530 M_INTMOVE(s1, GET_LOW_REG(d));
531 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
532 emit_store_dst(jd, iptr, d);
535 case ICMD_L2I: /* ..., value ==> ..., value */
537 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
538 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
540 emit_store_dst(jd, iptr, d);
543 case ICMD_INEG: /* ..., value ==> ..., - value */
545 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
546 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
548 emit_store_dst(jd, iptr, d);
551 case ICMD_LNEG: /* ..., value ==> ..., - value */
553 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
554 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
555 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
556 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
557 emit_store_dst(jd, iptr, d);
560 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
562 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
563 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
564 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
566 emit_store_dst(jd, iptr, d);
569 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
571 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
572 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
573 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
574 M_ADD_S(GET_LOW_REG(d), s1, s2);
575 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
576 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
577 M_ADC(GET_HIGH_REG(d), s1, s2);
578 emit_store_dst(jd, iptr, d);
584 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
585 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
587 if (IS_IMM(iptr->sx.val.i)) {
588 M_ADD_IMM(d, s1, iptr->sx.val.i);
589 } else if (IS_IMM(-iptr->sx.val.i)) {
590 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
592 ICONST(REG_ITMP3, iptr->sx.val.i);
593 M_ADD(d, s1, REG_ITMP3);
596 emit_store_dst(jd, iptr, d);
599 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
600 /* sx.val.l = constant */
602 s3 = iptr->sx.val.l & 0xffffffff;
603 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
604 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
606 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
608 ICONST(REG_ITMP3, s3);
609 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
611 s3 = iptr->sx.val.l >> 32;
612 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
614 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
616 ICONST(REG_ITMP3, s3);
617 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
619 emit_store_dst(jd, iptr, d);
622 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
624 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
625 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
626 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
628 emit_store_dst(jd, iptr, d);
631 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
633 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
634 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
635 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
636 M_SUB_S(GET_LOW_REG(d), s1, s2);
637 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
638 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
639 M_SBC(GET_HIGH_REG(d), s1, s2);
640 emit_store_dst(jd, iptr, d);
643 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
644 /* sx.val.i = constant */
646 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
647 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
648 if (IS_IMM(iptr->sx.val.i))
649 M_SUB_IMM(d, s1, iptr->sx.val.i);
651 ICONST(REG_ITMP3, iptr->sx.val.i);
652 M_SUB(d, s1, REG_ITMP3);
654 emit_store_dst(jd, iptr, d);
657 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
658 /* sx.val.l = constant */
660 s3 = iptr->sx.val.l & 0xffffffff;
661 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
662 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
664 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
666 ICONST(REG_ITMP3, s3);
667 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
669 s3 = iptr->sx.val.l >> 32;
670 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
672 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
674 ICONST(REG_ITMP3, s3);
675 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
677 emit_store_dst(jd, iptr, d);
680 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
682 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
683 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
684 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
686 emit_store_dst(jd, iptr, d);
689 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
690 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
692 s1 = emit_load_s1(jd, iptr, REG_A0);
693 s2 = emit_load_s2(jd, iptr, REG_A1);
694 emit_arithmetic_check(cd, iptr, s2);
696 /* move arguments into argument registers */
697 M_INTMOVE(s1, REG_A0);
698 M_INTMOVE(s2, REG_A1);
700 /* call builtin function */
701 bte = iptr->sx.s23.s3.bte;
702 disp = dseg_add_functionptr(cd, bte->fp);
706 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
709 /* move result into destination register */
710 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
711 M_INTMOVE(REG_RESULT, d);
712 emit_store_dst(jd, iptr, d);
715 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
716 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
718 /* move arguments into argument registers */
720 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
721 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
722 /* XXX TODO: only do this if arithmetic check is really done! */
723 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
724 emit_arithmetic_check(cd, iptr, REG_ITMP3);
726 M_LNGMOVE(s1, REG_A0_A1_PACKED);
727 M_LNGMOVE(s2, REG_A2_A3_PACKED);
729 /* call builtin function */
730 bte = iptr->sx.s23.s3.bte;
731 disp = dseg_add_functionptr(cd, bte->fp);
735 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
738 /* move result into destination register */
739 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
740 M_LNGMOVE(REG_RESULT_PACKED, d);
741 emit_store_dst(jd, iptr, d);
744 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
745 /* sx.val.i = constant */
747 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
748 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
749 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
750 emit_store_dst(jd, iptr, d);
753 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
754 /* sx.val.i = constant */
756 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
757 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
758 /* this rounds towards 0 as java likes it */
759 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
760 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
761 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
762 /* this rounds towards nearest, not java style */
763 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
764 M_ADCMI_IMM(d, d, 0);*/
765 emit_store_dst(jd, iptr, d);
768 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
769 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
771 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
772 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
773 M_MOV_S(REG_ITMP1, s1);
774 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
775 if (IS_IMM(iptr->sx.val.i))
776 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
778 ICONST(REG_ITMP3, iptr->sx.val.i);
779 M_AND(REG_ITMP1, REG_ITMP3, d);
781 M_RSBMI_IMM(d, d, 0);
782 emit_store_dst(jd, iptr, d);
785 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
787 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
788 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
789 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
790 M_AND_IMM(s2, 0x1f, REG_ITMP2);
791 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
792 emit_store_dst(jd, iptr, d);
795 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
797 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
798 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
799 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
800 M_AND_IMM(s2, 0x1f, REG_ITMP2);
801 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
802 emit_store_dst(jd, iptr, d);
805 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
807 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
808 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
809 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
810 M_AND_IMM(s2, 0x1f, REG_ITMP2);
811 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
812 emit_store_dst(jd, iptr, d);
815 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
816 /* sx.val.i = constant */
818 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
819 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
820 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
821 emit_store_dst(jd, iptr, d);
824 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
825 /* sx.val.i = constant */
827 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
828 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
829 /* we need to check for zero here because arm interprets it as SHR by 32 */
830 if ((iptr->sx.val.i & 0x1f) == 0) {
833 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
835 emit_store_dst(jd, iptr, d);
838 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
839 /* sx.val.i = constant */
841 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
842 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
843 /* we need to check for zero here because arm interprets it as SHR by 32 */
844 if ((iptr->sx.val.i & 0x1f) == 0)
847 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
848 emit_store_dst(jd, iptr, d);
851 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
853 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
854 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
855 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
857 emit_store_dst(jd, iptr, d);
860 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
862 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
863 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
864 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
865 M_AND(s1, s2, GET_LOW_REG(d));
866 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
867 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
868 M_AND(s1, s2, GET_HIGH_REG(d));
869 emit_store_dst(jd, iptr, d);
872 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
874 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
875 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
876 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
878 emit_store_dst(jd, iptr, d);
881 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
883 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
884 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
885 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
886 M_ORR(s1, s2, GET_LOW_REG(d));
887 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
888 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
889 M_ORR(s1, s2, GET_HIGH_REG(d));
890 emit_store_dst(jd, iptr, d);
893 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
895 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
896 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
897 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
899 emit_store_dst(jd, iptr, d);
902 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
904 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
905 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
906 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
907 M_EOR(s1, s2, GET_LOW_REG(d));
908 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
909 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
910 M_EOR(s1, s2, GET_HIGH_REG(d));
911 emit_store_dst(jd, iptr, d);
915 /* floating operations ************************************************/
917 #if !defined(ENABLE_SOFTFLOAT)
919 case ICMD_FNEG: /* ..., value ==> ..., - value */
921 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
922 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
924 emit_store_dst(jd, iptr, d);
927 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
929 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
930 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
931 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
933 emit_store_dst(jd, iptr, d);
936 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
938 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
939 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
940 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
942 emit_store_dst(jd, iptr, d);
945 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
947 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
948 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
949 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
951 emit_store_dst(jd, iptr, d);
954 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
955 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
956 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
957 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
959 emit_store_dst(jd, iptr, d);
962 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
965 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
967 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
968 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
969 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
971 emit_store_dst(jd, iptr, d);
974 case ICMD_DNEG: /* ..., value ==> ..., - value */
976 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
977 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
979 emit_store_dst(jd, iptr, d);
982 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
984 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
985 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
986 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
988 emit_store_dst(jd, iptr, d);
991 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
993 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
994 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
995 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
997 emit_store_dst(jd, iptr, d);
1000 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1002 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1003 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1004 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1006 emit_store_dst(jd, iptr, d);
1009 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1011 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1012 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1013 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1015 emit_store_dst(jd, iptr, d);
1018 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1021 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1023 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1024 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1025 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1027 emit_store_dst(jd, iptr, d);
1030 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1032 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1033 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1035 emit_store_dst(jd, iptr, d);
1038 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1040 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1041 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1043 emit_store_dst(jd, iptr, d);
1046 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1048 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1049 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1050 /* this uses round towards zero, as Java likes it */
1052 /* this checks for NaN; to return zero as Java likes it */
1055 emit_store_dst(jd, iptr, d);
1058 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1060 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1061 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1062 /* this uses round towards zero, as Java likes it */
1064 /* this checks for NaN; to return zero as Java likes it */
1067 emit_store_dst(jd, iptr, d);
1070 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1072 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1073 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1075 emit_store_dst(jd, iptr, d);
1078 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1080 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1081 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1083 emit_store_dst(jd, iptr, d);
1086 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1088 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1089 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1090 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1093 M_SUBGT_IMM(d, d, 1);
1094 M_ADDLT_IMM(d, d, 1);
1095 emit_store_dst(jd, iptr, d);
1098 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1100 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1101 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1102 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1105 M_SUBGT_IMM(d, d, 1);
1106 M_ADDLT_IMM(d, d, 1);
1107 emit_store_dst(jd, iptr, d);
1110 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1112 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1113 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1114 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1117 M_SUBLT_IMM(d, d, 1);
1118 M_ADDGT_IMM(d, d, 1);
1119 emit_store_dst(jd, iptr, d);
1122 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1124 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1125 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1126 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1129 M_SUBLT_IMM(d, d, 1);
1130 M_ADDGT_IMM(d, d, 1);
1131 emit_store_dst(jd, iptr, d);
1134 #endif /* !defined(ENABLE_SOFTFLOAT) */
1137 /* memory operations **************************************************/
1139 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1141 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1142 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1143 /* implicit null-pointer check */
1144 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1145 emit_store_dst(jd, iptr, d);
1148 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1150 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1151 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1152 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1153 /* implicit null-pointer check */
1154 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1155 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1156 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1157 emit_store_dst(jd, iptr, d);
1160 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1162 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1163 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1164 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1165 /* implicit null-pointer check */
1166 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1167 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1168 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1169 emit_store_dst(jd, iptr, d);
1172 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1174 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1175 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1176 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1177 /* implicit null-pointer check */
1178 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1179 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1180 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1181 emit_store_dst(jd, iptr, d);
1184 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1186 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1187 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1188 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1189 /* implicit null-pointer check */
1190 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1191 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1192 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1193 emit_store_dst(jd, iptr, d);
1196 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1198 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1199 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1200 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1201 /* implicit null-pointer check */
1202 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1203 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1204 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1205 emit_store_dst(jd, iptr, d);
1208 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1210 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1211 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1212 /* implicit null-pointer check */
1213 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1214 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1215 #if !defined(ENABLE_SOFTFLOAT)
1216 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1217 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1219 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1220 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1222 emit_store_dst(jd, iptr, d);
1225 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1227 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1228 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1229 /* implicit null-pointer check */
1230 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1231 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1232 #if !defined(ENABLE_SOFTFLOAT)
1233 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1234 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1236 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1237 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1239 emit_store_dst(jd, iptr, d);
1242 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1244 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1245 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1246 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1247 /* implicit null-pointer check */
1248 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1249 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1250 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1251 emit_store_dst(jd, iptr, d);
1254 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1256 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1257 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1258 /* implicit null-pointer check */
1259 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1260 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1261 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1262 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1265 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1267 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1268 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1269 /* implicit null-pointer check */
1270 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1271 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1272 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1273 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1276 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1278 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1279 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1280 /* implicit null-pointer check */
1281 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1282 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1283 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1284 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1287 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1289 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1290 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1291 /* implicit null-pointer check */
1292 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1293 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1294 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1295 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1298 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1300 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1301 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1302 /* implicit null-pointer check */
1303 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1304 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1305 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1306 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1309 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1311 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1312 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1313 /* implicit null-pointer check */
1314 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1315 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1316 #if !defined(ENABLE_SOFTFLOAT)
1317 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1318 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1320 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1321 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1325 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1327 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1328 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1329 /* implicit null-pointer check */
1330 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1331 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1332 #if !defined(ENABLE_SOFTFLOAT)
1333 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1334 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1336 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1337 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1341 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1343 s1 = emit_load_s1(jd, iptr, REG_A0);
1344 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1345 s3 = emit_load_s3(jd, iptr, REG_A1);
1347 /* implicit null-pointer check */
1348 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1350 /* move arguments to argument registers */
1351 M_INTMOVE(s1, REG_A0);
1352 M_INTMOVE(s3, REG_A1);
1354 /* call builtin function */
1355 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1356 M_DSEG_BRANCH(disp);
1359 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1362 /* check resturn value of builtin */
1363 emit_exception_check(cd, iptr);
1365 /* finally store address into array */
1366 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1367 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1368 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1369 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1370 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1373 case ICMD_GETSTATIC: /* ... ==> ..., value */
1375 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1376 unresolved_field *uf = iptr->sx.s23.s3.uf;
1378 fieldtype = uf->fieldref->parseddesc.fd->type;
1380 disp = dseg_add_unique_address(cd, NULL);
1382 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1384 if (opt_showdisassemble)
1388 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1390 fieldtype = fi->type;
1392 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1393 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1396 if (opt_showdisassemble)
1400 disp = dseg_add_address(cd, &(fi->value));
1403 M_DSEG_LOAD(REG_ITMP3, disp);
1404 switch (fieldtype) {
1406 #if defined(ENABLE_SOFTFLOAT)
1410 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1411 M_ILD_INTERN(d, REG_ITMP3, 0);
1414 #if defined(ENABLE_SOFTFLOAT)
1417 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1418 M_LLD_INTERN(d, REG_ITMP3, 0);
1420 #if !defined(ENABLE_SOFTFLOAT)
1422 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1423 M_FLD_INTERN(d, REG_ITMP3, 0);
1426 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1427 M_DLD_INTERN(d, REG_ITMP3, 0);
1433 emit_store_dst(jd, iptr, d);
1436 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1438 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1439 unresolved_field *uf = iptr->sx.s23.s3.uf;
1441 fieldtype = uf->fieldref->parseddesc.fd->type;
1443 disp = dseg_add_unique_address(cd, NULL);
1445 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1447 if (opt_showdisassemble)
1451 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1453 fieldtype = fi->type;
1455 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1456 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1459 if (opt_showdisassemble)
1463 disp = dseg_add_address(cd, &(fi->value));
1466 M_DSEG_LOAD(REG_ITMP3, disp);
1467 switch (fieldtype) {
1469 #if defined(ENABLE_SOFTFLOAT)
1473 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1474 M_IST_INTERN(s1, REG_ITMP3, 0);
1477 #if defined(ENABLE_SOFTFLOAT)
1480 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1481 M_LST_INTERN(s1, REG_ITMP3, 0);
1483 #if !defined(ENABLE_SOFTFLOAT)
1485 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1486 M_FST_INTERN(s1, REG_ITMP3, 0);
1489 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1490 M_DST_INTERN(s1, REG_ITMP3, 0);
1498 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1500 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1501 emit_nullpointer_check(cd, iptr, s1);
1504 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1505 unresolved_field *uf = iptr->sx.s23.s3.uf;
1507 fieldtype = uf->fieldref->parseddesc.fd->type;
1510 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1512 fieldtype = fi->type;
1516 #if !defined(ENABLE_SOFTFLOAT)
1517 /* HACK: softnull checks on floats */
1518 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1519 emit_nullpointer_check_force(cd, iptr, s1);
1522 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1523 unresolved_field *uf = iptr->sx.s23.s3.uf;
1525 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1527 if (opt_showdisassemble)
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 unresolved_field *uf = iptr->sx.s23.s3.uf;
1573 fieldtype = uf->fieldref->parseddesc.fd->type;
1576 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1578 fieldtype = fi->type;
1582 #if !defined(ENABLE_SOFTFLOAT)
1583 /* HACK: softnull checks on floats */
1584 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1585 emit_nullpointer_check_force(cd, iptr, s1);
1588 switch (fieldtype) {
1590 #if defined(ENABLE_SOFTFLOAT)
1594 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1596 #if defined(ENABLE_SOFTFLOAT)
1597 case TYPE_DBL: /* fall through */
1600 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1602 #if !defined(ENABLE_SOFTFLOAT)
1605 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1612 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1613 unresolved_field *uf = iptr->sx.s23.s3.uf;
1615 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1617 if (opt_showdisassemble)
1623 switch (fieldtype) {
1625 #if defined(ENABLE_SOFTFLOAT)
1629 M_IST(s2, s1, disp);
1632 #if defined(ENABLE_SOFTFLOAT)
1635 M_LST(s2, s1, disp);
1637 #if !defined(ENABLE_SOFTFLOAT)
1639 M_FST(s2, s1, disp);
1642 M_DST(s2, s1, disp);
1651 /* branch operations **************************************************/
1653 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1655 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1656 M_INTMOVE(s1, REG_ITMP1_XPTR);
1657 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1658 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1659 iptr->sx.s23.s2.uc, 0);
1661 if (opt_showdisassemble)
1664 disp = dseg_add_functionptr(cd, asm_handle_exception);
1665 M_DSEG_LOAD(REG_ITMP3, disp);
1666 M_MOV(REG_ITMP2_XPC, REG_PC);
1667 M_MOV(REG_PC, REG_ITMP3);
1668 M_NOP; /* nop ensures that XPC is less than the end */
1669 /* of basic block */
1672 case ICMD_GOTO: /* ... ==> ... */
1675 emit_br(cd, iptr->dst.block);
1678 case ICMD_JSR: /* ... ==> ... */
1680 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1683 case ICMD_IFNULL: /* ..., value ==> ... */
1684 case ICMD_IFNONNULL:
1686 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1688 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1691 case ICMD_IFLT: /* ..., value ==> ... */
1692 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1698 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1699 M_COMPARE(s1, iptr->sx.val.i);
1700 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1703 case ICMD_IF_LEQ: /* ..., value ==> ... */
1705 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1706 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1707 if (iptr->sx.val.l == 0) {
1708 M_ORR_S(s1, s2, REG_ITMP3);
1711 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1712 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1713 M_CMP(s1, REG_ITMP3);*/
1714 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1715 M_CMPEQ(s2, REG_ITMP3);
1717 emit_beq(cd, iptr->dst.block);
1720 case ICMD_IF_LLT: /* ..., value ==> ... */
1722 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1723 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1724 if (iptr->sx.val.l == 0) {
1725 /* if high word is less than zero, the whole long is too */
1727 emit_blt(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(ifLO) */
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_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1744 /* branch if (x LT 1) */
1745 M_CMP_IMM(REG_ITMP1, 1);
1746 emit_blt(cd, iptr->dst.block);
1750 case ICMD_IF_LLE: /* ..., 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 less than zero, the whole long is too */
1757 emit_blt(cd, iptr->dst.block);
1759 /* ... otherwise the low word has to be zero (tricky!) */
1761 emit_beq(cd, iptr->dst.block);
1764 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1765 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1766 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1767 M_CMP(s1, REG_ITMP3);*/
1768 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1769 M_MOVGT_IMM(2, REG_ITMP1);
1770 M_MOVEQ_IMM(1, REG_ITMP1);
1772 /* low compare: x=x+1(ifHI) */
1773 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1774 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1775 M_CMP(s2, REG_ITMP3);*/
1776 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1778 /* branch if (x LE 1) */
1779 M_CMP_IMM(REG_ITMP1, 1);
1780 emit_ble(cd, iptr->dst.block);
1784 case ICMD_IF_LGE: /* ..., value ==> ... */
1786 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1787 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1788 if (iptr->sx.val.l == 0) {
1789 /* if high word is greater or equal zero, the whole long is too */
1791 emit_bge(cd, iptr->dst.block);
1794 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1795 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1796 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1797 M_CMP(s1, REG_ITMP3);*/
1798 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1799 M_MOVGT_IMM(2, REG_ITMP1);
1800 M_MOVEQ_IMM(1, REG_ITMP1);
1802 /* low compare: x=x-1(ifLO) */
1803 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1804 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1805 M_CMP(s2, REG_ITMP3);*/
1806 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1808 /* branch if (x GE 1) */
1809 M_CMP_IMM(REG_ITMP1, 1);
1810 emit_bge(cd, iptr->dst.block);
1814 case ICMD_IF_LGT: /* ..., value ==> ... */
1816 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1817 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1819 if (iptr->sx.val.l == 0) {
1820 /* if high word is greater than zero, the whole long is too */
1823 codegen_add_branch_ref(cd, iptr->dst.block);
1825 /* ... or high was zero and low is non zero (tricky!) */
1826 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1827 M_MOVLT_IMM(1, REG_ITMP3);
1828 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1830 codegen_add_branch_ref(cd, iptr->dst.block);
1834 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1835 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1836 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1837 M_CMP(s1, REG_ITMP3);*/
1838 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1839 M_MOVGT_IMM(2, REG_ITMP1);
1840 M_MOVEQ_IMM(1, REG_ITMP1);
1842 /* low compare: x=x+1(ifHI) */
1843 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1844 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1845 M_CMP(s2, REG_ITMP3);*/
1846 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1848 /* branch if (x GT 1) */
1849 M_CMP_IMM(REG_ITMP1, 1);
1850 emit_bgt(cd, iptr->dst.block);
1856 case ICMD_IF_LNE: /* ..., value ==> ... */
1858 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1859 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1860 if (iptr->sx.val.l == 0) {
1861 M_ORR_S(s1, s2, REG_ITMP3);
1864 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1865 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1866 M_CMP(s1, REG_ITMP3);*/
1867 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1868 M_CMPEQ(s2, REG_ITMP3);
1870 emit_bne(cd, iptr->dst.block);
1873 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1874 case ICMD_IF_ICMPNE:
1875 case ICMD_IF_ICMPLT:
1876 case ICMD_IF_ICMPLE:
1877 case ICMD_IF_ICMPGT:
1878 case ICMD_IF_ICMPGE:
1880 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1881 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1883 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1886 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1887 case ICMD_IF_ACMPNE:
1889 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1890 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1892 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1895 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1896 /* op1 = target JavaVM pc */
1898 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1899 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1902 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1903 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1906 emit_beq(cd, iptr->dst.block);
1909 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1910 /* op1 = target JavaVM pc */
1912 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1913 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1916 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1917 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1920 emit_bne(cd, iptr->dst.block);
1923 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1924 /* op1 = target JavaVM pc */
1926 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1927 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1928 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1930 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1931 M_MOVGT_IMM(2, REG_ITMP3);
1932 M_MOVEQ_IMM(1, REG_ITMP3);
1934 /* low compare: x=x-1(ifLO) */
1935 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1936 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1938 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1940 /* branch if (x LT 1) */
1941 M_CMP_IMM(REG_ITMP3, 1);
1942 emit_blt(cd, iptr->dst.block);
1945 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1946 /* op1 = target JavaVM pc */
1948 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1949 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1950 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1952 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1953 M_MOVGT_IMM(2, REG_ITMP3);
1954 M_MOVEQ_IMM(1, REG_ITMP3);
1956 /* low compare: x=x-1(ifLO) */
1957 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1958 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1960 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1962 /* branch if (x LE 1) */
1963 M_CMP_IMM(REG_ITMP3, 1);
1964 emit_ble(cd, iptr->dst.block);
1967 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1968 /* op1 = target JavaVM pc */
1970 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1971 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1972 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1974 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1975 M_MOVGT_IMM(2, REG_ITMP3);
1976 M_MOVEQ_IMM(1, REG_ITMP3);
1978 /* low compare: x=x-1(ifLO) */
1979 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1980 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1982 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1984 /* branch if (x GT 1) */
1985 M_CMP_IMM(REG_ITMP3, 1);
1986 emit_bgt(cd, iptr->dst.block);
1989 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1990 /* op1 = target JavaVM pc */
1992 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1993 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1994 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1996 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1997 M_MOVGT_IMM(2, REG_ITMP3);
1998 M_MOVEQ_IMM(1, REG_ITMP3);
2000 /* low compare: x=x-1(ifLO) */
2001 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
2002 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
2004 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2006 /* branch if (x GE 1) */
2007 M_CMP_IMM(REG_ITMP3, 1);
2008 emit_bge(cd, iptr->dst.block);
2011 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2014 branch_target_t *table;
2016 table = iptr->dst.table;
2018 l = iptr->sx.s23.s2.tablelow;
2019 i = iptr->sx.s23.s3.tablehigh;
2021 /* calculate new index (index - low) */
2022 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2024 M_INTMOVE(s1, REG_ITMP1);
2025 } else if (IS_IMM(l)) {
2026 M_SUB_IMM(REG_ITMP1, s1, l);
2028 ICONST(REG_ITMP2, l);
2029 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2032 /* range check (index <= high-low) */
2034 M_COMPARE(REG_ITMP1, i-1);
2035 emit_bugt(cd, table[0].block);
2037 /* build jump table top down and use address of lowest entry */
2042 dseg_add_target(cd, table->block);
2047 /* length of dataseg after last dseg_add_target is used by load */
2048 /* TODO: this loads from data-segment */
2049 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2050 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2053 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2056 lookup_target_t *lookup;
2058 lookup = iptr->dst.lookup;
2060 i = iptr->sx.s23.s2.lookupcount;
2063 MCODECHECK((i<<2)+8);
2064 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2067 M_COMPARE(s1, lookup->value);
2068 emit_beq(cd, lookup->target.block);
2072 /* default branch */
2073 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2077 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2079 #if !defined(ENABLE_SOFTFLOAT)
2080 REPLACEMENT_POINT_RETURN(cd, iptr);
2081 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2082 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2083 goto ICMD_RETURN_do;
2086 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2088 REPLACEMENT_POINT_RETURN(cd, iptr);
2089 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2090 M_INTMOVE(s1, REG_RESULT);
2091 goto ICMD_RETURN_do;
2093 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2095 #if !defined(ENABLE_SOFTFLOAT)
2096 REPLACEMENT_POINT_RETURN(cd, iptr);
2097 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2098 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2099 goto ICMD_RETURN_do;
2102 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2104 REPLACEMENT_POINT_RETURN(cd, iptr);
2105 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2106 M_LNGMOVE(s1, REG_RESULT_PACKED);
2107 goto ICMD_RETURN_do;
2109 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2111 REPLACEMENT_POINT_RETURN(cd, iptr);
2112 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2113 M_INTMOVE(s1, REG_RESULT);
2114 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2115 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2116 iptr->sx.s23.s2.uc, 0);
2118 if (opt_showdisassemble)
2121 goto ICMD_RETURN_do;
2123 case ICMD_RETURN: /* ... ==> ... */
2125 REPLACEMENT_POINT_RETURN(cd, iptr);
2128 #if !defined(NDEBUG)
2129 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2130 emit_verbosecall_exit(jd);
2133 #if defined(ENABLE_THREADS)
2134 /* call monitorexit function */
2136 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2137 /* stack offset for monitor argument */
2139 s1 = rd->memuse * 8;
2141 /* we need to save the proper return value */
2143 switch (iptr->opc) {
2147 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2149 M_STMFD(BITMASK_RESULT, REG_SP);
2154 M_LDR(REG_A0, REG_SP, s1);
2155 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2156 M_DSEG_BRANCH(disp);
2158 /* we no longer need PV here, no more loading */
2159 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2160 M_RECOMPUTE_PV(s1);*/
2162 switch (iptr->opc) {
2166 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2168 M_LDMFD(BITMASK_RESULT, REG_SP);
2174 /* deallocate stackframe for spilled variables */
2176 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2177 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2179 /* restore callee saved registers + do return */
2181 if (savedregs_bitmask) {
2182 if (!jd->isleafmethod) {
2183 savedregs_bitmask &= ~(1<<REG_LR);
2184 savedregs_bitmask |= (1<<REG_PC);
2186 M_LDMFD(savedregs_bitmask, REG_SP);
2189 /* if LR was not on stack, we need to return manually */
2191 if (jd->isleafmethod)
2192 M_MOV(REG_PC, REG_LR);
2195 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2197 bte = iptr->sx.s23.s3.bte;
2199 goto ICMD_INVOKE_do;
2201 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2202 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2203 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2204 case ICMD_INVOKEINTERFACE:
2206 REPLACEMENT_POINT_INVOKE(cd, iptr);
2208 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2210 um = iptr->sx.s23.s3.um;
2211 md = um->methodref->parseddesc.md;
2214 lm = iptr->sx.s23.s3.fmiref->p.method;
2216 md = lm->parseddesc;
2220 /* copy arguments to registers or stack location */
2222 s3 = md->paramcount;
2224 MCODECHECK((s3 << 1) + 64);
2226 for (s3 = s3 - 1; s3 >= 0; s3--) {
2227 var = VAR(iptr->sx.s23.s2.args[s3]);
2228 d = md->params[s3].regoff;
2230 if (var->flags & PREALLOC) /* argument was precolored? */
2233 /* TODO: document me */
2234 #if !defined(ENABLE_SOFTFLOAT)
2235 if (IS_INT_LNG_TYPE(var->type)) {
2236 #endif /* !defined(ENABLE_SOFTFLOAT) */
2237 if (!md->params[s3].inmemory) {
2238 s1 = emit_load(jd, iptr, var, d);
2240 if (IS_2_WORD_TYPE(var->type))
2246 if (IS_2_WORD_TYPE(var->type)) {
2247 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2248 M_LST(s1, REG_SP, d);
2251 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2252 M_IST(s1, REG_SP, d);
2255 #if !defined(ENABLE_SOFTFLOAT)
2258 if (!md->params[s3].inmemory) {
2259 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2260 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2263 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2264 if (IS_2_WORD_TYPE(var->type))
2265 M_DST(s1, REG_SP, d);
2267 M_FST(s1, REG_SP, d);
2270 #endif /* !defined(ENABLE_SOFTFLOAT) */
2273 switch (iptr->opc) {
2275 disp = dseg_add_functionptr(cd, bte->fp);
2277 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2279 /* generate the actual call */
2281 M_MOV(REG_LR, REG_PC);
2282 M_MOV(REG_PC, REG_PV);
2283 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2286 emit_exception_check(cd, iptr);
2289 case ICMD_INVOKESPECIAL:
2290 emit_nullpointer_check(cd, iptr, REG_A0);
2293 case ICMD_INVOKESTATIC:
2295 disp = dseg_add_unique_address(cd, NULL);
2297 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2300 if (opt_showdisassemble)
2304 disp = dseg_add_address(cd, lm->stubroutine);
2306 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2308 /* generate the actual call */
2310 M_MOV(REG_LR, REG_PC);
2311 M_MOV(REG_PC, REG_PV);
2312 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2316 case ICMD_INVOKEVIRTUAL:
2318 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2320 if (opt_showdisassemble)
2326 s1 = OFFSET(vftbl_t, table[0]) +
2327 sizeof(methodptr) * lm->vftblindex;
2329 /* implicit null-pointer check */
2330 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2331 OFFSET(java_objectheader, vftbl));
2332 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2334 /* generate the actual call */
2336 M_MOV(REG_LR, REG_PC);
2337 M_MOV(REG_PC, REG_PV);
2338 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2342 case ICMD_INVOKEINTERFACE:
2344 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2346 if (opt_showdisassemble)
2353 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2354 sizeof(methodptr*) * lm->class->index;
2355 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2358 /* implicit null-pointer check */
2359 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2360 OFFSET(java_objectheader, vftbl));
2361 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2362 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2364 /* generate the actual call */
2366 M_MOV(REG_LR, REG_PC);
2367 M_MOV(REG_PC, REG_PV);
2368 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2373 /* store size of call code in replacement point */
2374 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2376 /* store return value */
2378 d = md->returntype.type;
2380 #if !defined(__SOFTFP__)
2381 /* TODO: this is only a hack, since we use R0/R1 for float
2382 return! this depends on gcc; it is independent from
2383 our ENABLE_SOFTFLOAT define */
2384 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2385 #if 0 && !defined(NDEBUG)
2386 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2388 /* we cannot use this macro, since it is not defined
2389 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2390 REG_FRESULT, REG_RESULT_TYPED(d)); */
2391 if (IS_2_WORD_TYPE(d)) {
2392 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2393 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2395 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2396 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2401 if (d != TYPE_VOID) {
2402 #if !defined(ENABLE_SOFTFLOAT)
2403 if (IS_INT_LNG_TYPE(d)) {
2404 #endif /* !defined(ENABLE_SOFTFLOAT) */
2405 if (IS_2_WORD_TYPE(d)) {
2406 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2407 M_LNGMOVE(REG_RESULT_PACKED, s1);
2410 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2411 M_INTMOVE(REG_RESULT, s1);
2414 #if !defined(ENABLE_SOFTFLOAT)
2416 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2417 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2419 #endif /* !defined(ENABLE_SOFTFLOAT) */
2421 emit_store_dst(jd, iptr, s1);
2425 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2427 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2428 /* object type cast-check */
2433 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2438 super = iptr->sx.s23.s3.c.cls;
2439 superindex = super->index;
2442 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2443 CODEGEN_CRITICAL_SECTION_NEW;
2445 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2447 /* if class is not resolved, check which code to call */
2449 if (super == NULL) {
2451 emit_label_beq(cd, BRANCH_LABEL_1);
2453 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2454 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2455 iptr->sx.s23.s3.c.ref, disp);
2457 if (opt_showdisassemble)
2460 M_DSEG_LOAD(REG_ITMP2, disp);
2461 disp = dseg_add_s4(cd, ACC_INTERFACE);
2462 M_DSEG_LOAD(REG_ITMP3, disp);
2463 M_TST(REG_ITMP2, REG_ITMP3);
2464 emit_label_beq(cd, BRANCH_LABEL_2);
2467 /* interface checkcast code */
2469 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2470 if ((super == NULL) || !IS_IMM(superindex)) {
2471 disp = dseg_add_unique_s4(cd, superindex);
2473 if (super == NULL) {
2474 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2475 iptr->sx.s23.s3.c.ref, disp);
2477 if (opt_showdisassemble)
2482 emit_label_beq(cd, BRANCH_LABEL_3);
2485 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2486 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2488 /* we put unresolved or non-immediate superindices onto dseg */
2489 if ((super == NULL) || !IS_IMM(superindex)) {
2490 /* disp was computed before we added the patcher */
2491 M_DSEG_LOAD(REG_ITMP2, disp);
2492 M_CMP(REG_ITMP3, REG_ITMP2);
2494 assert(IS_IMM(superindex));
2495 M_CMP_IMM(REG_ITMP3, superindex);
2498 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2500 /* if we loaded the superindex out of the dseg above, we do
2501 things differently here! */
2502 if ((super == NULL) || !IS_IMM(superindex)) {
2504 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_objectheader, vftbl));
2506 /* this assumes something */
2507 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2509 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2510 assert(sizeof(methodptr*) == 4);
2511 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2517 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2518 superindex * sizeof(methodptr*);
2522 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2523 M_TST(REG_ITMP3, REG_ITMP3);
2524 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2527 emit_label_br(cd, BRANCH_LABEL_4);
2529 emit_label(cd, BRANCH_LABEL_3);
2532 /* class checkcast code */
2534 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2535 if (super == NULL) {
2536 emit_label(cd, BRANCH_LABEL_2);
2538 disp = dseg_add_unique_address(cd, NULL);
2540 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2541 iptr->sx.s23.s3.c.ref,
2544 if (opt_showdisassemble)
2548 disp = dseg_add_address(cd, super->vftbl);
2551 emit_label_beq(cd, BRANCH_LABEL_5);
2554 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2555 M_DSEG_LOAD(REG_ITMP3, disp);
2557 CODEGEN_CRITICAL_SECTION_START;
2559 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2560 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2561 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2562 M_DSEG_LOAD(REG_ITMP3, disp);
2563 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2565 CODEGEN_CRITICAL_SECTION_END;
2567 M_CMP(REG_ITMP2, REG_ITMP3);
2568 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2571 emit_label(cd, BRANCH_LABEL_5);
2574 if (super == NULL) {
2575 emit_label(cd, BRANCH_LABEL_1);
2576 emit_label(cd, BRANCH_LABEL_4);
2579 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2582 /* array type cast-check */
2584 s1 = emit_load_s1(jd, iptr, REG_A0);
2585 M_INTMOVE(s1, REG_A0);
2587 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2588 disp = dseg_add_unique_address(cd, NULL);
2590 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2591 iptr->sx.s23.s3.c.ref,
2594 if (opt_showdisassemble)
2598 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2600 M_DSEG_LOAD(REG_A1, disp);
2601 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2602 M_DSEG_BRANCH(disp);
2605 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2606 M_RECOMPUTE_PV(disp);
2608 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2609 M_TST(REG_RESULT, REG_RESULT);
2610 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2612 d = codegen_reg_of_dst(jd, iptr, s1);
2616 emit_store_dst(jd, iptr, d);
2619 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2625 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2630 super = iptr->sx.s23.s3.c.cls;
2631 superindex = super->index;
2634 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2635 CODEGEN_CRITICAL_SECTION_NEW;
2637 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2638 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2641 M_MOV(REG_ITMP1, s1);
2645 /* if class is not resolved, check which code to call */
2647 if (super == NULL) {
2651 emit_label_beq(cd, BRANCH_LABEL_1);
2653 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2654 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2655 iptr->sx.s23.s3.c.ref, disp);
2657 if (opt_showdisassemble)
2660 M_DSEG_LOAD(REG_ITMP2, disp);
2661 disp = dseg_add_s4(cd, ACC_INTERFACE);
2662 M_DSEG_LOAD(REG_ITMP3, disp);
2663 M_TST(REG_ITMP2, REG_ITMP3);
2664 emit_label_beq(cd, BRANCH_LABEL_2);
2667 /* interface checkcast code */
2669 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2670 if ((super == NULL) || !IS_IMM(superindex)) {
2671 disp = dseg_add_unique_s4(cd, superindex);
2673 if (super == NULL) {
2674 /* If d == REG_ITMP2, then it's destroyed in check
2679 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2680 iptr->sx.s23.s3.c.ref, disp);
2682 if (opt_showdisassemble)
2688 emit_label_beq(cd, BRANCH_LABEL_3);
2691 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2692 M_LDR_INTERN(REG_ITMP3,
2693 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2695 /* we put unresolved or non-immediate superindices onto dseg
2696 and do things slightly different */
2697 if ((super == NULL) || !IS_IMM(superindex)) {
2698 /* disp was computed before we added the patcher */
2699 M_DSEG_LOAD(REG_ITMP2, disp);
2700 M_CMP(REG_ITMP3, REG_ITMP2);
2702 if (d == REG_ITMP2) {
2709 /* this assumes something */
2710 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2712 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2713 assert(sizeof(methodptr*) == 4);
2714 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2716 if (d == REG_ITMP2) {
2723 assert(IS_IMM(superindex));
2724 M_CMP_IMM(REG_ITMP3, superindex);
2728 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2729 superindex * sizeof(methodptr*);
2733 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2734 M_TST(REG_ITMP3, REG_ITMP3);
2738 emit_label_br(cd, BRANCH_LABEL_4);
2740 emit_label(cd, BRANCH_LABEL_3);
2743 /* class checkcast code */
2745 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2746 if (super == NULL) {
2747 emit_label(cd, BRANCH_LABEL_2);
2749 disp = dseg_add_unique_address(cd, NULL);
2751 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2752 iptr->sx.s23.s3.c.ref, disp);
2754 if (opt_showdisassemble)
2758 disp = dseg_add_address(cd, super->vftbl);
2762 emit_label_beq(cd, BRANCH_LABEL_5);
2765 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2766 M_DSEG_LOAD(REG_ITMP2, disp);
2768 CODEGEN_CRITICAL_SECTION_START;
2770 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2771 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2772 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2774 CODEGEN_CRITICAL_SECTION_END;
2776 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2777 M_CMP(REG_ITMP1, REG_ITMP2);
2778 /* If d == REG_ITMP2, then it's destroyed */
2784 emit_label(cd, BRANCH_LABEL_5);
2787 if (super == NULL) {
2788 emit_label(cd, BRANCH_LABEL_1);
2789 emit_label(cd, BRANCH_LABEL_4);
2794 emit_store_dst(jd, iptr, d);
2797 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2799 /* copy sizes to stack if necessary */
2801 MCODECHECK((iptr->s1.argcount << 1) + 64);
2803 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2805 var = VAR(iptr->sx.s23.s2.args[s1]);
2807 /* copy SAVEDVAR sizes to stack */
2809 if (!(var->flags & PREALLOC)) {
2810 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2811 M_STR(s2, REG_SP, s1 * 4);
2815 /* a0 = dimension count */
2817 assert(IS_IMM(iptr->s1.argcount));
2818 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2820 /* is patcher function set? */
2822 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2823 disp = dseg_add_unique_address(cd, NULL);
2825 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2826 iptr->sx.s23.s3.c.ref, disp);
2828 if (opt_showdisassemble)
2832 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2834 /* a1 = arraydescriptor */
2836 M_DSEG_LOAD(REG_A1, disp);
2838 /* a2 = pointer to dimensions = stack pointer */
2840 M_INTMOVE(REG_SP, REG_A2);
2842 /* call builtin_multianewarray here */
2844 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2845 M_DSEG_BRANCH(disp);
2849 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2852 /* check for exception before result assignment */
2854 emit_exception_check(cd, iptr);
2858 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2859 M_INTMOVE(REG_RESULT, d);
2860 emit_store_dst(jd, iptr, d);
2863 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2865 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2866 emit_nullpointer_check(cd, iptr, s1);
2870 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2873 } /* the big switch */
2875 } /* for all instructions */
2877 } /* for all basic blocks */
2879 dseg_createlinenumbertable(cd);
2882 /* generate stubs */
2884 emit_patcher_traps(jd);
2885 REPLACEMENT_EMIT_STUBS(jd);
2887 /* everything's ok */
2893 /* codegen_emit_stub_compiler **************************************************
2895 Emits a stub routine which calls the compiler.
2897 *******************************************************************************/
2899 void codegen_emit_stub_compiler(jitdata *jd)
2904 /* get required compiler data */
2909 /* code for the stub */
2911 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2912 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2916 /* codegen_emit_stub_native ****************************************************
2918 Emits a stub routine which calls a native method.
2920 *******************************************************************************/
2922 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2931 s4 disp, funcdisp, s1, s2;
2933 /* get required compiler data */
2939 /* initialize variables */
2942 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2944 /* calculate stackframe size */
2946 cd->stackframesize =
2947 4 + /* return address */
2948 sizeof(stackframeinfo) + /* stackframeinfo */
2949 sizeof(localref_table) + /* localref_table */
2950 nmd->memuse * 4; /* stack arguments */
2952 /* align stack to 8-byte */
2954 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2956 /* create method header */
2958 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2959 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2960 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2961 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2962 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2963 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2964 (void) dseg_addlinenumbertablesize(cd);
2965 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2967 /* generate stub code */
2969 M_STMFD(1<<REG_LR, REG_SP);
2970 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2972 #if !defined(NDEBUG)
2973 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2974 emit_verbosecall_enter(jd);
2977 /* get function address (this must happen before the stackframeinfo) */
2979 funcdisp = dseg_add_functionptr(cd, f);
2981 #if !defined(WITH_STATIC_CLASSPATH)
2983 patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
2985 if (opt_showdisassemble)
2990 /* Save integer and float argument registers (these are 4
2991 registers, stack is 8-byte aligned). */
2993 M_STMFD(BITMASK_ARGS, REG_SP);
2994 /* TODO: floating point */
2996 /* create native stackframe info */
2998 assert(IS_IMM(4*4 + cd->stackframesize));
2999 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
3000 M_MOV(REG_A1, REG_PV);
3001 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize);
3002 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
3003 disp = dseg_add_functionptr(cd, codegen_start_native_call);
3004 M_DSEG_BRANCH(disp);
3008 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3011 /* Restore integer and float argument registers (these are 4
3012 registers, stack is 8-byte aligned). */
3014 M_LDMFD(BITMASK_ARGS, REG_SP);
3015 /* TODO: floating point */
3017 /* copy or spill arguments to new locations */
3018 /* ATTENTION: the ARM has only integer argument registers! */
3020 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3021 t = md->paramtypes[i].type;
3023 if (!md->params[i].inmemory) {
3024 s1 = md->params[i].regoff;
3025 s2 = nmd->params[j].regoff;
3027 if (!nmd->params[j].inmemory) {
3028 #if !defined(__ARM_EABI__)
3029 SPLIT_OPEN(t, s2, REG_ITMP1);
3032 if (IS_2_WORD_TYPE(t))
3037 #if !defined(__ARM_EABI__)
3038 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3042 if (IS_2_WORD_TYPE(t))
3043 M_LST(s1, REG_SP, s2);
3045 M_IST(s1, REG_SP, s2);
3049 s1 = md->params[i].regoff + cd->stackframesize;
3050 s2 = nmd->params[j].regoff;
3052 if (IS_2_WORD_TYPE(t)) {
3053 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3054 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3057 M_ILD(REG_ITMP1, REG_SP, s1);
3058 M_IST(REG_ITMP1, REG_SP, s2);
3063 /* put class into second argument register */
3065 if (m->flags & ACC_STATIC) {
3066 disp = dseg_add_address(cd, m->class);
3067 M_DSEG_LOAD(REG_A1, disp);
3070 /* put env into first argument register */
3072 disp = dseg_add_address(cd, _Jv_env);
3073 M_DSEG_LOAD(REG_A0, disp);
3075 /* do the native function call */
3077 M_DSEG_BRANCH(funcdisp);
3080 /* TODO: this is only needed because of the tracer ... do we
3083 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3086 #if !defined(__SOFTFP__)
3087 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3088 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3089 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3090 #if 0 && !defined(NDEBUG)
3091 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3093 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3094 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3095 if (IS_2_WORD_TYPE(md->returntype.type)) {
3096 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3097 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3099 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3100 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3105 #if !defined(NDEBUG)
3106 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3107 emit_verbosecall_exit(jd);
3110 /* remove native stackframe info */
3111 /* TODO: improve this store/load */
3113 M_STMFD(BITMASK_RESULT, REG_SP);
3115 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize - SIZEOF_VOID_P);
3116 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3117 M_DSEG_BRANCH(disp);
3118 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3121 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3122 M_LDMFD(BITMASK_RESULT, REG_SP);
3124 /* finish stub code, but do not yet return to caller */
3126 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3127 M_LDMFD(1<<REG_LR, REG_SP);
3129 /* check for exception */
3131 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3132 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3134 /* handle exception here */
3136 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3138 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3139 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3140 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3142 /* generate patcher stubs */
3144 emit_patcher_traps(jd);
3148 /* asm_debug *******************************************************************
3152 *******************************************************************************/
3154 void asm_debug(int a1, int a2, int a3, int a4)
3156 printf("===> i am going to exit after this debugging message!\n");
3157 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3158 vm_abort("leave you now");
3163 * These are local overrides for various environment variables in Emacs.
3164 * Please do not remove this and leave it at the end of the file, where
3165 * Emacs will automagically detect them.
3166 * ---------------------------------------------------------------------
3169 * indent-tabs-mode: t
3173 * vim:noexpandtab:sw=4:ts=4: