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/asmpart.h"
53 #include "vm/jit/codegen-common.h"
54 #include "vm/jit/dseg.h"
55 #include "vm/jit/emit-common.h"
56 #include "vm/jit/jit.h"
57 #include "vm/jit/md.h"
58 #include "vm/jit/methodheader.h"
59 #include "vm/jit/parse.h"
60 #include "vm/jit/patcher-common.h"
61 #include "vm/jit/reg.h"
63 #if defined(ENABLE_LSRA)
64 #include "vm/jit/allocator/lsra.h"
67 #include "vmcore/loader.h"
68 #include "vmcore/options.h"
71 /* codegen_emit ****************************************************************
73 Generates machine code.
75 *******************************************************************************/
77 bool codegen_emit(jitdata *jd)
96 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
97 unresolved_method *um;
98 builtintable_entry *bte;
101 unresolved_field *uf;
105 /* get required compiler data */
112 /* prevent compiler warnings */
120 /* space to save used callee saved registers */
122 savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
123 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
124 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
125 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
127 spilledregs_num = rd->memuse;
129 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
130 if (checksync && (m->flags & ACC_SYNCHRONIZED))
134 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
136 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
137 only in native stubs. */
138 /* align stack to 8-byte */
140 cd->stackframesize = (cd->stackframesize + 4) & ~4;
142 /* SECTION: Method Header */
143 /* create method header */
145 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
146 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
148 #if defined(ENABLE_THREADS)
149 /* IsSync contains the offset relative to the stack pointer for the
150 argument of monitor_exit used in the exception handler. Since the
151 offset could be zero and give a wrong meaning of the flag it is
155 if (checksync && (m->flags & ACC_SYNCHRONIZED))
156 (void) dseg_add_unique_s4(cd, rd->memuse * 8 + 4);/* IsSync */
159 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
161 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
162 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
163 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
164 (void) dseg_addlinenumbertablesize(cd);
165 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
167 /* create exception table */
169 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
170 dseg_add_target(cd, ex->start);
171 dseg_add_target(cd, ex->end);
172 dseg_add_target(cd, ex->handler);
173 (void) dseg_add_unique_address(cd, ex->catchtype.any);
176 /* save return address and used callee saved registers */
178 savedregs_bitmask = 0;
180 if (!jd->isleafmethod)
181 savedregs_bitmask = (1<<REG_LR);
183 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
184 savedregs_bitmask |= (1<<(rd->savintregs[i]));
187 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
188 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
189 /* TODO: floating-point */
193 if (savedregs_bitmask)
194 M_STMFD(savedregs_bitmask, REG_SP);
196 /* create additional stack frame for spilled variables (if necessary) */
198 if ((cd->stackframesize / 4 - savedregs_num) > 0)
199 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
201 /* take arguments out of register or stack frame */
204 for (i = 0, len = 0; i < md->paramcount; i++) {
205 s1 = md->params[i].regoff;
206 t = md->paramtypes[i].type;
208 varindex = jd->local_map[len * 5 + t];
210 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
212 if (varindex == UNUSED)
217 /* ATTENTION: we use interger registers for all arguments (even float) */
218 #if !defined(ENABLE_SOFTFLOAT)
219 if (IS_INT_LNG_TYPE(t)) {
221 if (!md->params[i].inmemory) {
222 if (!(var->flags & INMEMORY)) {
223 if (IS_2_WORD_TYPE(t))
224 M_LNGMOVE(s1, var->vv.regoff);
226 M_INTMOVE(s1, var->vv.regoff);
229 if (IS_2_WORD_TYPE(t))
230 M_LST(s1, REG_SP, var->vv.regoff);
232 M_IST(s1, REG_SP, var->vv.regoff);
235 else { /* stack arguments */
236 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
237 if (IS_2_WORD_TYPE(t))
238 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
240 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
242 else { /* stack arg -> spilled */
243 /* Reuse Memory Position on Caller Stack */
244 var->vv.regoff = cd->stackframesize + s1;
247 #if !defined(ENABLE_SOFTFLOAT)
250 if (!md->params[i].inmemory) {
251 if (!(var->flags & INMEMORY)) {
252 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
255 if (IS_2_WORD_TYPE(t))
256 M_LST(s1, REG_SP, var->vv.regoff);
258 M_IST(s1, REG_SP, var->vv.regoff);
262 if (!(var->flags & INMEMORY)) {
263 if (IS_2_WORD_TYPE(t))
264 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
266 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
269 /* Reuse Memory Position on Caller Stack */
270 var->vv.regoff = cd->stackframesize + s1;
274 #endif /* !defined(ENABLE_SOFTFLOAT) */
277 #if defined(ENABLE_THREADS)
278 /* call monitorenter function */
280 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
281 /* stack offset for monitor argument */
285 # if !defined(NDEBUG)
286 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
287 M_STMFD(BITMASK_ARGS, REG_SP);
292 /* get the correct lock object */
294 if (m->flags & ACC_STATIC) {
295 disp = dseg_add_address(cd, &m->class->object.header);
296 M_DSEG_LOAD(REG_A0, disp);
299 emit_nullpointer_check_force(cd, iptr, REG_A0);
302 M_STR(REG_A0, REG_SP, s1);
303 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
305 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
308 # if !defined(NDEBUG)
309 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
310 M_LDMFD(BITMASK_ARGS, REG_SP);
316 /* call trace function */
318 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
319 emit_verbosecall_enter(jd);
322 /* end of header generation */
324 /* create replacement points */
325 REPLACEMENT_POINTS_INIT(cd, jd);
327 /* SECTION: ICMD Code Generation */
328 /* for all basic blocks */
330 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
332 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
334 /* is this basic block reached? */
336 if (bptr->flags < BBREACHED)
339 /* branch resolving */
341 codegen_resolve_branchrefs(cd, bptr);
343 /* handle replacement points */
344 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
346 /* copy interface registers to their destination */
352 #if defined(ENABLE_LSRA)
356 var = VAR(bptr->invars[len]);
357 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
358 if (!(var->flags & INMEMORY))
362 M_INTMOVE(REG_ITMP1, d);
363 emit_store(jd, NULL, var, d);
370 var = VAR(bptr->invars[len]);
372 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
373 d = codegen_reg_of_var(0, var, REG_ITMP1);
374 M_INTMOVE(REG_ITMP1, d);
375 emit_store(jd, NULL, var, d);
378 assert((var->flags & INOUT));
381 #if defined(ENABLE_LSRA)
385 /* for all instructions */
388 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
390 /* add line number */
391 if (iptr->line != currentline) {
392 dseg_addlinenumber(cd, iptr->line);
393 currentline = iptr->line;
396 MCODECHECK(64); /* an instruction usually needs < 64 words */
400 case ICMD_NOP: /* ... ==> ... */
403 /* constant operations ************************************************/
405 case ICMD_ICONST: /* ... ==> ..., constant */
407 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
408 ICONST(d, iptr->sx.val.i);
409 emit_store_dst(jd, iptr, d);
412 case ICMD_ACONST: /* ... ==> ..., constant */
414 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
415 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
416 disp = dseg_add_unique_address(cd, NULL);
418 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
419 iptr->sx.val.c.ref, disp);
421 if (opt_showdisassemble)
424 M_DSEG_LOAD(d, disp);
427 ICONST(d, (u4) iptr->sx.val.anyptr);
429 emit_store_dst(jd, iptr, d);
432 case ICMD_LCONST: /* ... ==> ..., constant */
434 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
435 LCONST(d, iptr->sx.val.l);
436 emit_store_dst(jd, iptr, d);
439 case ICMD_FCONST: /* ... ==> ..., constant */
441 #if defined(ENABLE_SOFTFLOAT)
442 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
443 ICONST(d, iptr->sx.val.i);
444 emit_store_dst(jd, iptr, d);
446 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
447 FCONST(d, iptr->sx.val.f);
448 emit_store_dst(jd, iptr, d);
452 case ICMD_DCONST: /* ... ==> ..., constant */
454 #if defined(ENABLE_SOFTFLOAT)
455 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
456 LCONST(d, iptr->sx.val.l);
457 emit_store_dst(jd, iptr, d);
459 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
460 DCONST(d, iptr->sx.val.d);
461 emit_store_dst(jd, iptr, d);
466 /* load/store/copy/move operations ************************************/
468 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
469 case ICMD_ALOAD: /* op1 = local variable */
473 case ICMD_ISTORE: /* ..., value ==> ... */
484 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
488 /* pop operations *****************************************************/
490 /* attention: double and longs are only one entry in CACAO ICMDs */
492 case ICMD_POP: /* ..., value ==> ... */
493 case ICMD_POP2: /* ..., value, value ==> ... */
498 /* integer operations *************************************************/
500 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
502 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
503 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
504 M_MOV(d, REG_LSL(s1, 24));
505 M_MOV(d, REG_ASR(d, 24));
506 emit_store_dst(jd, iptr, d);
509 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
511 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
512 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
513 M_MOV(d, REG_LSL(s1, 16));
514 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
515 emit_store_dst(jd, iptr, d);
518 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
520 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
521 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
522 M_MOV(d, REG_LSL(s1, 16));
523 M_MOV(d, REG_ASR(d, 16));
524 emit_store_dst(jd, iptr, d);
527 case ICMD_I2L: /* ..., value ==> ..., value */
529 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
530 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
531 M_INTMOVE(s1, GET_LOW_REG(d));
532 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
533 emit_store_dst(jd, iptr, d);
536 case ICMD_L2I: /* ..., value ==> ..., value */
538 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
539 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
541 emit_store_dst(jd, iptr, d);
544 case ICMD_INEG: /* ..., value ==> ..., - value */
546 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
547 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
549 emit_store_dst(jd, iptr, d);
552 case ICMD_LNEG: /* ..., value ==> ..., - value */
554 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
555 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
556 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
557 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
558 emit_store_dst(jd, iptr, d);
561 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
563 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
564 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
565 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
567 emit_store_dst(jd, iptr, d);
570 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
572 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
573 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
574 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
575 M_ADD_S(GET_LOW_REG(d), s1, s2);
576 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
577 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
578 M_ADC(GET_HIGH_REG(d), s1, s2);
579 emit_store_dst(jd, iptr, d);
585 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
586 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
588 if (IS_IMM(iptr->sx.val.i)) {
589 M_ADD_IMM(d, s1, iptr->sx.val.i);
590 } else if (IS_IMM(-iptr->sx.val.i)) {
591 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
593 ICONST(REG_ITMP3, iptr->sx.val.i);
594 M_ADD(d, s1, REG_ITMP3);
597 emit_store_dst(jd, iptr, d);
600 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
601 /* sx.val.l = constant */
603 s3 = iptr->sx.val.l & 0xffffffff;
604 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
605 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
607 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
609 ICONST(REG_ITMP3, s3);
610 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
612 s3 = iptr->sx.val.l >> 32;
613 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
615 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
617 ICONST(REG_ITMP3, s3);
618 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
620 emit_store_dst(jd, iptr, d);
623 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
625 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
626 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
627 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
629 emit_store_dst(jd, iptr, d);
632 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
634 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
635 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
636 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
637 M_SUB_S(GET_LOW_REG(d), s1, s2);
638 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
639 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
640 M_SBC(GET_HIGH_REG(d), s1, s2);
641 emit_store_dst(jd, iptr, d);
644 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
645 /* sx.val.i = constant */
647 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
648 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
649 if (IS_IMM(iptr->sx.val.i))
650 M_SUB_IMM(d, s1, iptr->sx.val.i);
652 ICONST(REG_ITMP3, iptr->sx.val.i);
653 M_SUB(d, s1, REG_ITMP3);
655 emit_store_dst(jd, iptr, d);
658 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
659 /* sx.val.l = constant */
661 s3 = iptr->sx.val.l & 0xffffffff;
662 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
663 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
665 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
667 ICONST(REG_ITMP3, s3);
668 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
670 s3 = iptr->sx.val.l >> 32;
671 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
673 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
675 ICONST(REG_ITMP3, s3);
676 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
678 emit_store_dst(jd, iptr, d);
681 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
683 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
684 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
685 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
687 emit_store_dst(jd, iptr, d);
690 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
691 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
693 s1 = emit_load_s1(jd, iptr, REG_A0);
694 s2 = emit_load_s2(jd, iptr, REG_A1);
695 emit_arithmetic_check(cd, iptr, s2);
697 /* move arguments into argument registers */
698 M_INTMOVE(s1, REG_A0);
699 M_INTMOVE(s2, REG_A1);
701 /* call builtin function */
702 bte = iptr->sx.s23.s3.bte;
703 disp = dseg_add_functionptr(cd, bte->fp);
707 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
710 /* move result into destination register */
711 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
712 M_INTMOVE(REG_RESULT, d);
713 emit_store_dst(jd, iptr, d);
716 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
717 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
719 /* move arguments into argument registers */
721 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
722 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
723 /* XXX TODO: only do this if arithmetic check is really done! */
724 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
725 emit_arithmetic_check(cd, iptr, REG_ITMP3);
727 M_LNGMOVE(s1, REG_A0_A1_PACKED);
728 M_LNGMOVE(s2, REG_A2_A3_PACKED);
730 /* call builtin function */
731 bte = iptr->sx.s23.s3.bte;
732 disp = dseg_add_functionptr(cd, bte->fp);
736 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
739 /* move result into destination register */
740 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
741 M_LNGMOVE(REG_RESULT_PACKED, d);
742 emit_store_dst(jd, iptr, d);
745 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
746 /* sx.val.i = constant */
748 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
749 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
750 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
751 emit_store_dst(jd, iptr, d);
754 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
755 /* sx.val.i = constant */
757 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
758 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
759 /* this rounds towards 0 as java likes it */
760 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
761 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
762 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
763 /* this rounds towards nearest, not java style */
764 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
765 M_ADCMI_IMM(d, d, 0);*/
766 emit_store_dst(jd, iptr, d);
769 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
770 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
772 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
773 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
774 M_MOV_S(REG_ITMP1, s1);
775 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
776 if (IS_IMM(iptr->sx.val.i))
777 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
779 ICONST(REG_ITMP3, iptr->sx.val.i);
780 M_AND(REG_ITMP1, REG_ITMP3, d);
782 M_RSBMI_IMM(d, d, 0);
783 emit_store_dst(jd, iptr, d);
786 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
788 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
789 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
790 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
791 M_AND_IMM(s2, 0x1f, REG_ITMP2);
792 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
793 emit_store_dst(jd, iptr, d);
796 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
798 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
799 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
800 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
801 M_AND_IMM(s2, 0x1f, REG_ITMP2);
802 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
803 emit_store_dst(jd, iptr, d);
806 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
808 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
809 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
810 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
811 M_AND_IMM(s2, 0x1f, REG_ITMP2);
812 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
813 emit_store_dst(jd, iptr, d);
816 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
817 /* sx.val.i = constant */
819 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
820 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
821 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
822 emit_store_dst(jd, iptr, d);
825 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
826 /* sx.val.i = constant */
828 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
829 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
830 /* we need to check for zero here because arm interprets it as SHR by 32 */
831 if ((iptr->sx.val.i & 0x1f) == 0) {
834 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
836 emit_store_dst(jd, iptr, d);
839 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
840 /* sx.val.i = constant */
842 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
843 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
844 /* we need to check for zero here because arm interprets it as SHR by 32 */
845 if ((iptr->sx.val.i & 0x1f) == 0)
848 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
849 emit_store_dst(jd, iptr, d);
852 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
854 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
855 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
856 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
858 emit_store_dst(jd, iptr, d);
861 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
863 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
864 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
865 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
866 M_AND(s1, s2, GET_LOW_REG(d));
867 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
868 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
869 M_AND(s1, s2, GET_HIGH_REG(d));
870 emit_store_dst(jd, iptr, d);
873 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
875 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
876 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
877 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
879 emit_store_dst(jd, iptr, d);
882 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
884 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
885 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
886 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
887 M_ORR(s1, s2, GET_LOW_REG(d));
888 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
889 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
890 M_ORR(s1, s2, GET_HIGH_REG(d));
891 emit_store_dst(jd, iptr, d);
894 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
896 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
897 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
898 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
900 emit_store_dst(jd, iptr, d);
903 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
905 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
906 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
907 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
908 M_EOR(s1, s2, GET_LOW_REG(d));
909 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
910 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
911 M_EOR(s1, s2, GET_HIGH_REG(d));
912 emit_store_dst(jd, iptr, d);
916 /* floating operations ************************************************/
918 #if !defined(ENABLE_SOFTFLOAT)
920 case ICMD_FNEG: /* ..., value ==> ..., - value */
922 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
923 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
925 emit_store_dst(jd, iptr, d);
928 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
930 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
931 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
932 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
934 emit_store_dst(jd, iptr, d);
937 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
939 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
940 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
941 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
943 emit_store_dst(jd, iptr, d);
946 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
948 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
949 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
950 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
952 emit_store_dst(jd, iptr, d);
955 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
956 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
957 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
958 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
960 emit_store_dst(jd, iptr, d);
963 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
966 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
968 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
969 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
970 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
972 emit_store_dst(jd, iptr, d);
975 case ICMD_DNEG: /* ..., value ==> ..., - value */
977 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
978 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
980 emit_store_dst(jd, iptr, d);
983 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
985 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
986 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
987 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
989 emit_store_dst(jd, iptr, d);
992 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
994 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
995 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
996 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
998 emit_store_dst(jd, iptr, d);
1001 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1003 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1004 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1005 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1007 emit_store_dst(jd, iptr, d);
1010 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1012 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1013 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1014 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1016 emit_store_dst(jd, iptr, d);
1019 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1022 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1024 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1025 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1026 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1028 emit_store_dst(jd, iptr, d);
1031 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1033 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1034 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1036 emit_store_dst(jd, iptr, d);
1039 case ICMD_I2D: /* ..., value ==> ..., (double) 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_F2I: /* ..., value ==> ..., (int) value */
1049 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1050 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1051 /* this uses round towards zero, as Java likes it */
1053 /* this checks for NaN; to return zero as Java likes it */
1056 emit_store_dst(jd, iptr, d);
1059 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1061 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1062 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1063 /* this uses round towards zero, as Java likes it */
1065 /* this checks for NaN; to return zero as Java likes it */
1068 emit_store_dst(jd, iptr, d);
1071 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1073 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1074 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1076 emit_store_dst(jd, iptr, d);
1079 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1081 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1082 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1084 emit_store_dst(jd, iptr, d);
1087 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1089 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1090 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1091 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1094 M_SUBGT_IMM(d, d, 1);
1095 M_ADDLT_IMM(d, d, 1);
1096 emit_store_dst(jd, iptr, d);
1099 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg 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 M_SUBGT_IMM(d, d, 1);
1107 M_ADDLT_IMM(d, d, 1);
1108 emit_store_dst(jd, iptr, d);
1111 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1113 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1114 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1115 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1118 M_SUBLT_IMM(d, d, 1);
1119 M_ADDGT_IMM(d, d, 1);
1120 emit_store_dst(jd, iptr, d);
1123 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1125 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1126 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1127 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1130 M_SUBLT_IMM(d, d, 1);
1131 M_ADDGT_IMM(d, d, 1);
1132 emit_store_dst(jd, iptr, d);
1135 #endif /* !defined(ENABLE_SOFTFLOAT) */
1138 /* memory operations **************************************************/
1140 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1142 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1143 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1144 /* implicit null-pointer check */
1145 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1146 emit_store_dst(jd, iptr, d);
1149 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1151 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1152 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1153 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1154 /* implicit null-pointer check */
1155 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1156 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1157 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1158 emit_store_dst(jd, iptr, d);
1161 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1163 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1164 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1165 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1166 /* implicit null-pointer check */
1167 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1168 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1169 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1170 emit_store_dst(jd, iptr, d);
1173 case ICMD_SALOAD: /* ..., 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, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1181 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1182 emit_store_dst(jd, iptr, d);
1185 case ICMD_IALOAD: /* ..., 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, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1193 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1194 emit_store_dst(jd, iptr, d);
1197 case ICMD_LALOAD: /* ..., 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_ITMP12_PACKED);
1202 /* implicit null-pointer check */
1203 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1204 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1205 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1206 emit_store_dst(jd, iptr, d);
1209 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1211 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1212 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1213 /* implicit null-pointer check */
1214 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1215 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1216 #if !defined(ENABLE_SOFTFLOAT)
1217 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1218 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1220 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1221 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1223 emit_store_dst(jd, iptr, d);
1226 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1228 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1229 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1230 /* implicit null-pointer check */
1231 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1232 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1233 #if !defined(ENABLE_SOFTFLOAT)
1234 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1235 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1237 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1238 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1240 emit_store_dst(jd, iptr, d);
1243 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1245 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1246 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1247 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1248 /* implicit null-pointer check */
1249 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1250 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1251 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1252 emit_store_dst(jd, iptr, d);
1255 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1257 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1258 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1259 /* implicit null-pointer check */
1260 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1261 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1262 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1263 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1266 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1268 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1269 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1270 /* implicit null-pointer check */
1271 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1272 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1273 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1274 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1277 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1279 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1280 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1281 /* implicit null-pointer check */
1282 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1283 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1284 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1285 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1288 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1290 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1291 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1292 /* implicit null-pointer check */
1293 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1294 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1295 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1296 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1299 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1301 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1302 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1303 /* implicit null-pointer check */
1304 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1305 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1306 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1307 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1310 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1312 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1313 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1314 /* implicit null-pointer check */
1315 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1316 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1317 #if !defined(ENABLE_SOFTFLOAT)
1318 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1319 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1321 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1322 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1326 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1328 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1329 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1330 /* implicit null-pointer check */
1331 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1332 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1333 #if !defined(ENABLE_SOFTFLOAT)
1334 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1335 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1337 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1338 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1342 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1344 s1 = emit_load_s1(jd, iptr, REG_A0);
1345 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1346 s3 = emit_load_s3(jd, iptr, REG_A1);
1348 /* implicit null-pointer check */
1349 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1351 /* move arguments to argument registers */
1352 M_INTMOVE(s1, REG_A0);
1353 M_INTMOVE(s3, REG_A1);
1355 /* call builtin function */
1356 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1357 M_DSEG_BRANCH(disp);
1360 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1363 /* check resturn value of builtin */
1364 emit_exception_check(cd, iptr);
1366 /* finally store address into array */
1367 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1368 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1369 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1370 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1371 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1374 case ICMD_GETSTATIC: /* ... ==> ..., value */
1376 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1377 uf = iptr->sx.s23.s3.uf;
1378 fieldtype = uf->fieldref->parseddesc.fd->type;
1379 disp = dseg_add_unique_address(cd, NULL);
1381 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1383 if (opt_showdisassemble)
1387 fi = iptr->sx.s23.s3.fmiref->p.field;
1388 fieldtype = fi->type;
1389 disp = dseg_add_address(cd, fi->value);
1391 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1392 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1395 if (opt_showdisassemble)
1400 M_DSEG_LOAD(REG_ITMP3, disp);
1401 switch (fieldtype) {
1403 #if defined(ENABLE_SOFTFLOAT)
1407 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1408 M_ILD_INTERN(d, REG_ITMP3, 0);
1411 #if defined(ENABLE_SOFTFLOAT)
1414 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1415 M_LLD_INTERN(d, REG_ITMP3, 0);
1417 #if !defined(ENABLE_SOFTFLOAT)
1419 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1420 M_FLD_INTERN(d, REG_ITMP3, 0);
1423 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1424 M_DLD_INTERN(d, REG_ITMP3, 0);
1430 emit_store_dst(jd, iptr, d);
1433 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1435 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1436 uf = iptr->sx.s23.s3.uf;
1437 fieldtype = uf->fieldref->parseddesc.fd->type;
1438 disp = dseg_add_unique_address(cd, NULL);
1440 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1442 if (opt_showdisassemble)
1446 fi = iptr->sx.s23.s3.fmiref->p.field;
1447 fieldtype = fi->type;
1448 disp = dseg_add_address(cd, fi->value);
1450 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1451 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1454 if (opt_showdisassemble)
1459 M_DSEG_LOAD(REG_ITMP3, disp);
1460 switch (fieldtype) {
1462 #if defined(ENABLE_SOFTFLOAT)
1466 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1467 M_IST_INTERN(s1, REG_ITMP3, 0);
1470 #if defined(ENABLE_SOFTFLOAT)
1473 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1474 M_LST_INTERN(s1, REG_ITMP3, 0);
1476 #if !defined(ENABLE_SOFTFLOAT)
1478 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1479 M_FST_INTERN(s1, REG_ITMP3, 0);
1482 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1483 M_DST_INTERN(s1, REG_ITMP3, 0);
1491 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1493 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1494 emit_nullpointer_check(cd, iptr, s1);
1497 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1498 uf = iptr->sx.s23.s3.uf;
1499 fieldtype = uf->fieldref->parseddesc.fd->type;
1503 fi = iptr->sx.s23.s3.fmiref->p.field;
1504 fieldtype = fi->type;
1508 #if !defined(ENABLE_SOFTFLOAT)
1509 /* HACK: softnull checks on floats */
1510 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1511 emit_nullpointer_check_force(cd, iptr, s1);
1514 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1516 uf = iptr->sx.s23.s3.uf;
1518 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1520 if (opt_showdisassemble)
1524 switch (fieldtype) {
1526 #if defined(ENABLE_SOFTFLOAT)
1530 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1534 #if defined(ENABLE_SOFTFLOAT)
1537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1540 #if !defined(ENABLE_SOFTFLOAT)
1542 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1546 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1553 emit_store_dst(jd, iptr, d);
1556 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1558 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1559 emit_nullpointer_check(cd, iptr, s1);
1561 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1562 uf = iptr->sx.s23.s3.uf;
1563 fieldtype = uf->fieldref->parseddesc.fd->type;
1567 fi = iptr->sx.s23.s3.fmiref->p.field;
1568 fieldtype = fi->type;
1572 #if !defined(ENABLE_SOFTFLOAT)
1573 /* HACK: softnull checks on floats */
1574 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1575 emit_nullpointer_check_force(cd, iptr, s1);
1578 switch (fieldtype) {
1580 #if defined(ENABLE_SOFTFLOAT)
1584 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1586 #if defined(ENABLE_SOFTFLOAT)
1587 case TYPE_DBL: /* fall through */
1590 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1592 #if !defined(ENABLE_SOFTFLOAT)
1595 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1602 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1604 uf = iptr->sx.s23.s3.uf;
1606 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1608 if (opt_showdisassemble)
1612 switch (fieldtype) {
1614 #if defined(ENABLE_SOFTFLOAT)
1618 M_IST(s2, s1, disp);
1621 #if defined(ENABLE_SOFTFLOAT)
1624 M_LST(s2, s1, disp);
1626 #if !defined(ENABLE_SOFTFLOAT)
1628 M_FST(s2, s1, disp);
1631 M_DST(s2, s1, disp);
1640 /* branch operations **************************************************/
1642 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1644 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1645 M_INTMOVE(s1, REG_ITMP1_XPTR);
1646 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1647 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1648 iptr->sx.s23.s2.uc, 0);
1650 if (opt_showdisassemble)
1653 disp = dseg_add_functionptr(cd, asm_handle_exception);
1654 M_DSEG_LOAD(REG_ITMP3, disp);
1655 M_MOV(REG_ITMP2_XPC, REG_PC);
1656 M_MOV(REG_PC, REG_ITMP3);
1657 M_NOP; /* nop ensures that XPC is less than the end */
1658 /* of basic block */
1661 case ICMD_GOTO: /* ... ==> ... */
1664 emit_br(cd, iptr->dst.block);
1667 case ICMD_JSR: /* ... ==> ... */
1669 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1672 case ICMD_IFNULL: /* ..., value ==> ... */
1673 case ICMD_IFNONNULL:
1675 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1677 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1680 case ICMD_IFLT: /* ..., value ==> ... */
1681 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1687 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1688 M_COMPARE(s1, iptr->sx.val.i);
1689 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1692 case ICMD_IF_LEQ: /* ..., value ==> ... */
1694 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1695 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1696 if (iptr->sx.val.l == 0) {
1697 M_ORR_S(s1, s2, REG_ITMP3);
1700 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1701 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1702 M_CMP(s1, REG_ITMP3);*/
1703 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1704 M_CMPEQ(s2, REG_ITMP3);
1706 emit_beq(cd, iptr->dst.block);
1709 case ICMD_IF_LLT: /* ..., value ==> ... */
1711 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1712 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1713 if (iptr->sx.val.l == 0) {
1714 /* if high word is less than zero, the whole long is too */
1716 emit_blt(cd, iptr->dst.block);
1719 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1720 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1721 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1722 M_CMP(s1, REG_ITMP3);*/
1723 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1724 M_MOVGT_IMM(2, REG_ITMP1);
1725 M_MOVEQ_IMM(1, REG_ITMP1);
1727 /* low compare: x=x-1(ifLO) */
1728 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1729 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1730 M_CMP(s2, REG_ITMP3);*/
1731 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1733 /* branch if (x LT 1) */
1734 M_CMP_IMM(REG_ITMP1, 1);
1735 emit_blt(cd, iptr->dst.block);
1739 case ICMD_IF_LLE: /* ..., value ==> ... */
1741 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1742 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1743 if (iptr->sx.val.l == 0) {
1744 /* if high word is less than zero, the whole long is too */
1746 emit_blt(cd, iptr->dst.block);
1748 /* ... otherwise the low word has to be zero (tricky!) */
1750 emit_beq(cd, iptr->dst.block);
1753 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1754 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1755 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1756 M_CMP(s1, REG_ITMP3);*/
1757 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1758 M_MOVGT_IMM(2, REG_ITMP1);
1759 M_MOVEQ_IMM(1, REG_ITMP1);
1761 /* low compare: x=x+1(ifHI) */
1762 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1763 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1764 M_CMP(s2, REG_ITMP3);*/
1765 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1767 /* branch if (x LE 1) */
1768 M_CMP_IMM(REG_ITMP1, 1);
1769 emit_ble(cd, iptr->dst.block);
1773 case ICMD_IF_LGE: /* ..., value ==> ... */
1775 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1776 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1777 if (iptr->sx.val.l == 0) {
1778 /* if high word is greater or equal zero, the whole long is too */
1780 emit_bge(cd, iptr->dst.block);
1783 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1784 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1785 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1786 M_CMP(s1, REG_ITMP3);*/
1787 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1788 M_MOVGT_IMM(2, REG_ITMP1);
1789 M_MOVEQ_IMM(1, REG_ITMP1);
1791 /* low compare: x=x-1(ifLO) */
1792 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1793 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1794 M_CMP(s2, REG_ITMP3);*/
1795 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1797 /* branch if (x GE 1) */
1798 M_CMP_IMM(REG_ITMP1, 1);
1799 emit_bge(cd, iptr->dst.block);
1803 case ICMD_IF_LGT: /* ..., value ==> ... */
1805 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1806 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1808 if (iptr->sx.val.l == 0) {
1809 /* if high word is greater than zero, the whole long is too */
1812 codegen_add_branch_ref(cd, iptr->dst.block);
1814 /* ... or high was zero and low is non zero (tricky!) */
1815 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1816 M_MOVLT_IMM(1, REG_ITMP3);
1817 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1819 codegen_add_branch_ref(cd, iptr->dst.block);
1823 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1824 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1825 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1826 M_CMP(s1, REG_ITMP3);*/
1827 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1828 M_MOVGT_IMM(2, REG_ITMP1);
1829 M_MOVEQ_IMM(1, REG_ITMP1);
1831 /* low compare: x=x+1(ifHI) */
1832 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1833 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1834 M_CMP(s2, REG_ITMP3);*/
1835 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1837 /* branch if (x GT 1) */
1838 M_CMP_IMM(REG_ITMP1, 1);
1839 emit_bgt(cd, iptr->dst.block);
1845 case ICMD_IF_LNE: /* ..., value ==> ... */
1847 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1848 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1849 if (iptr->sx.val.l == 0) {
1850 M_ORR_S(s1, s2, REG_ITMP3);
1853 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1854 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1855 M_CMP(s1, REG_ITMP3);*/
1856 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1857 M_CMPEQ(s2, REG_ITMP3);
1859 emit_bne(cd, iptr->dst.block);
1862 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1863 case ICMD_IF_ICMPNE:
1864 case ICMD_IF_ICMPLT:
1865 case ICMD_IF_ICMPLE:
1866 case ICMD_IF_ICMPGT:
1867 case ICMD_IF_ICMPGE:
1869 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1870 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1872 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1875 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1876 case ICMD_IF_ACMPNE:
1878 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1879 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1881 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1884 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1885 /* op1 = target JavaVM pc */
1887 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1888 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1891 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1892 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1895 emit_beq(cd, iptr->dst.block);
1898 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1899 /* op1 = target JavaVM pc */
1901 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1902 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1905 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1906 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1909 emit_bne(cd, iptr->dst.block);
1912 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1913 /* op1 = target JavaVM pc */
1915 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1916 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1917 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1919 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1920 M_MOVGT_IMM(2, REG_ITMP3);
1921 M_MOVEQ_IMM(1, REG_ITMP3);
1923 /* low compare: x=x-1(ifLO) */
1924 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1925 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1927 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1929 /* branch if (x LT 1) */
1930 M_CMP_IMM(REG_ITMP3, 1);
1931 emit_blt(cd, iptr->dst.block);
1934 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1935 /* op1 = target JavaVM pc */
1937 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1938 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1939 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1941 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1942 M_MOVGT_IMM(2, REG_ITMP3);
1943 M_MOVEQ_IMM(1, REG_ITMP3);
1945 /* low compare: x=x-1(ifLO) */
1946 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1947 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1949 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1951 /* branch if (x LE 1) */
1952 M_CMP_IMM(REG_ITMP3, 1);
1953 emit_ble(cd, iptr->dst.block);
1956 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1957 /* op1 = target JavaVM pc */
1959 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1960 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1961 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1963 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1964 M_MOVGT_IMM(2, REG_ITMP3);
1965 M_MOVEQ_IMM(1, REG_ITMP3);
1967 /* low compare: x=x-1(ifLO) */
1968 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1969 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1971 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1973 /* branch if (x GT 1) */
1974 M_CMP_IMM(REG_ITMP3, 1);
1975 emit_bgt(cd, iptr->dst.block);
1978 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1979 /* op1 = target JavaVM pc */
1981 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1982 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1983 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1985 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1986 M_MOVGT_IMM(2, REG_ITMP3);
1987 M_MOVEQ_IMM(1, REG_ITMP3);
1989 /* low compare: x=x-1(ifLO) */
1990 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1991 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1993 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1995 /* branch if (x GE 1) */
1996 M_CMP_IMM(REG_ITMP3, 1);
1997 emit_bge(cd, iptr->dst.block);
2000 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2003 branch_target_t *table;
2005 table = iptr->dst.table;
2007 l = iptr->sx.s23.s2.tablelow;
2008 i = iptr->sx.s23.s3.tablehigh;
2010 /* calculate new index (index - low) */
2011 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2013 M_INTMOVE(s1, REG_ITMP1);
2014 } else if (IS_IMM(l)) {
2015 M_SUB_IMM(REG_ITMP1, s1, l);
2017 ICONST(REG_ITMP2, l);
2018 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2021 /* range check (index <= high-low) */
2023 M_COMPARE(REG_ITMP1, i-1);
2024 emit_bugt(cd, table[0].block);
2026 /* build jump table top down and use address of lowest entry */
2031 dseg_add_target(cd, table->block);
2036 /* length of dataseg after last dseg_add_target is used by load */
2037 /* TODO: this loads from data-segment */
2038 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2039 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2042 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2045 lookup_target_t *lookup;
2047 lookup = iptr->dst.lookup;
2049 i = iptr->sx.s23.s2.lookupcount;
2052 MCODECHECK((i<<2)+8);
2053 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2056 M_COMPARE(s1, lookup->value);
2057 emit_beq(cd, lookup->target.block);
2061 /* default branch */
2062 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2066 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2068 #if !defined(ENABLE_SOFTFLOAT)
2069 REPLACEMENT_POINT_RETURN(cd, iptr);
2070 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2071 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2072 goto ICMD_RETURN_do;
2075 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2077 REPLACEMENT_POINT_RETURN(cd, iptr);
2078 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2079 M_INTMOVE(s1, REG_RESULT);
2080 goto ICMD_RETURN_do;
2082 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2084 #if !defined(ENABLE_SOFTFLOAT)
2085 REPLACEMENT_POINT_RETURN(cd, iptr);
2086 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2087 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2088 goto ICMD_RETURN_do;
2091 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2093 REPLACEMENT_POINT_RETURN(cd, iptr);
2094 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2095 M_LNGMOVE(s1, REG_RESULT_PACKED);
2096 goto ICMD_RETURN_do;
2098 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2100 REPLACEMENT_POINT_RETURN(cd, iptr);
2101 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2102 M_INTMOVE(s1, REG_RESULT);
2103 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2104 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2105 iptr->sx.s23.s2.uc, 0);
2107 if (opt_showdisassemble)
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 && (m->flags & ACC_SYNCHRONIZED)) {
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 (!jd->isleafmethod) {
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 (jd->isleafmethod)
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 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2252 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2253 if (IS_2_WORD_TYPE(var->type))
2254 M_DST(s1, REG_SP, d);
2256 M_FST(s1, REG_SP, d);
2259 #endif /* !defined(ENABLE_SOFTFLOAT) */
2262 switch (iptr->opc) {
2264 disp = dseg_add_functionptr(cd, bte->fp);
2266 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2268 /* generate the actual call */
2270 M_MOV(REG_LR, REG_PC);
2271 M_MOV(REG_PC, REG_PV);
2272 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2275 emit_exception_check(cd, iptr);
2278 case ICMD_INVOKESPECIAL:
2279 emit_nullpointer_check(cd, iptr, REG_A0);
2282 case ICMD_INVOKESTATIC:
2284 disp = dseg_add_unique_address(cd, NULL);
2286 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2289 if (opt_showdisassemble)
2293 disp = dseg_add_address(cd, lm->stubroutine);
2295 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2297 /* generate the actual call */
2299 M_MOV(REG_LR, REG_PC);
2300 M_MOV(REG_PC, REG_PV);
2301 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2305 case ICMD_INVOKEVIRTUAL:
2307 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2309 if (opt_showdisassemble)
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);
2335 if (opt_showdisassemble)
2342 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2343 sizeof(methodptr*) * lm->class->index;
2344 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2347 /* implicit null-pointer check */
2348 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2349 OFFSET(java_object_t, vftbl));
2350 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2351 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2353 /* generate the actual call */
2355 M_MOV(REG_LR, REG_PC);
2356 M_MOV(REG_PC, REG_PV);
2357 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2362 /* store size of call code in replacement point */
2363 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2365 /* store return value */
2367 d = md->returntype.type;
2369 #if !defined(__SOFTFP__)
2370 /* TODO: this is only a hack, since we use R0/R1 for float
2371 return! this depends on gcc; it is independent from
2372 our ENABLE_SOFTFLOAT define */
2373 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2374 #if 0 && !defined(NDEBUG)
2375 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2377 /* we cannot use this macro, since it is not defined
2378 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2379 REG_FRESULT, REG_RESULT_TYPED(d)); */
2380 if (IS_2_WORD_TYPE(d)) {
2381 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2382 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2384 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2385 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2390 if (d != TYPE_VOID) {
2391 #if !defined(ENABLE_SOFTFLOAT)
2392 if (IS_INT_LNG_TYPE(d)) {
2393 #endif /* !defined(ENABLE_SOFTFLOAT) */
2394 if (IS_2_WORD_TYPE(d)) {
2395 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2396 M_LNGMOVE(REG_RESULT_PACKED, s1);
2399 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2400 M_INTMOVE(REG_RESULT, s1);
2403 #if !defined(ENABLE_SOFTFLOAT)
2405 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2406 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), 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 if (opt_showdisassemble)
2449 M_DSEG_LOAD(REG_ITMP2, disp);
2450 disp = dseg_add_s4(cd, ACC_INTERFACE);
2451 M_DSEG_LOAD(REG_ITMP3, disp);
2452 M_TST(REG_ITMP2, REG_ITMP3);
2453 emit_label_beq(cd, BRANCH_LABEL_2);
2456 /* interface checkcast code */
2458 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2459 if ((super == NULL) || !IS_IMM(superindex)) {
2460 disp = dseg_add_unique_s4(cd, superindex);
2462 if (super == NULL) {
2463 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2464 iptr->sx.s23.s3.c.ref, disp);
2466 if (opt_showdisassemble)
2471 emit_label_beq(cd, BRANCH_LABEL_3);
2474 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2475 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2477 /* we put unresolved or non-immediate superindices onto dseg */
2478 if ((super == NULL) || !IS_IMM(superindex)) {
2479 /* disp was computed before we added the patcher */
2480 M_DSEG_LOAD(REG_ITMP2, disp);
2481 M_CMP(REG_ITMP3, REG_ITMP2);
2483 assert(IS_IMM(superindex));
2484 M_CMP_IMM(REG_ITMP3, superindex);
2487 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2489 /* if we loaded the superindex out of the dseg above, we do
2490 things differently here! */
2491 if ((super == NULL) || !IS_IMM(superindex)) {
2493 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2495 /* this assumes something */
2496 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2498 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2499 assert(sizeof(methodptr*) == 4);
2500 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2506 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2507 superindex * sizeof(methodptr*);
2511 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2512 M_TST(REG_ITMP3, REG_ITMP3);
2513 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2516 emit_label_br(cd, BRANCH_LABEL_4);
2518 emit_label(cd, BRANCH_LABEL_3);
2521 /* class checkcast code */
2523 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2524 if (super == NULL) {
2525 emit_label(cd, BRANCH_LABEL_2);
2527 disp = dseg_add_unique_address(cd, NULL);
2529 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2530 iptr->sx.s23.s3.c.ref,
2533 if (opt_showdisassemble)
2537 disp = dseg_add_address(cd, super->vftbl);
2540 emit_label_beq(cd, BRANCH_LABEL_5);
2543 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2544 M_DSEG_LOAD(REG_ITMP3, disp);
2546 CODEGEN_CRITICAL_SECTION_START;
2548 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2549 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2550 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2551 M_DSEG_LOAD(REG_ITMP3, disp);
2552 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2554 CODEGEN_CRITICAL_SECTION_END;
2556 M_CMP(REG_ITMP2, REG_ITMP3);
2557 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2560 emit_label(cd, BRANCH_LABEL_5);
2563 if (super == NULL) {
2564 emit_label(cd, BRANCH_LABEL_1);
2565 emit_label(cd, BRANCH_LABEL_4);
2568 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2571 /* array type cast-check */
2573 s1 = emit_load_s1(jd, iptr, REG_A0);
2574 M_INTMOVE(s1, REG_A0);
2576 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2577 disp = dseg_add_unique_address(cd, NULL);
2579 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2580 iptr->sx.s23.s3.c.ref,
2583 if (opt_showdisassemble)
2587 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2589 M_DSEG_LOAD(REG_A1, disp);
2590 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2591 M_DSEG_BRANCH(disp);
2594 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2595 M_RECOMPUTE_PV(disp);
2597 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2598 M_TST(REG_RESULT, REG_RESULT);
2599 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2601 d = codegen_reg_of_dst(jd, iptr, s1);
2605 emit_store_dst(jd, iptr, d);
2608 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2614 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2619 super = iptr->sx.s23.s3.c.cls;
2620 superindex = super->index;
2623 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2624 CODEGEN_CRITICAL_SECTION_NEW;
2626 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2627 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2630 M_MOV(REG_ITMP1, s1);
2634 /* if class is not resolved, check which code to call */
2636 if (super == NULL) {
2640 emit_label_beq(cd, BRANCH_LABEL_1);
2642 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2643 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2644 iptr->sx.s23.s3.c.ref, disp);
2646 if (opt_showdisassemble)
2649 M_DSEG_LOAD(REG_ITMP2, disp);
2650 disp = dseg_add_s4(cd, ACC_INTERFACE);
2651 M_DSEG_LOAD(REG_ITMP3, disp);
2652 M_TST(REG_ITMP2, REG_ITMP3);
2653 emit_label_beq(cd, BRANCH_LABEL_2);
2656 /* interface checkcast code */
2658 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2659 if ((super == NULL) || !IS_IMM(superindex)) {
2660 disp = dseg_add_unique_s4(cd, superindex);
2662 if (super == NULL) {
2663 /* If d == REG_ITMP2, then it's destroyed in check
2668 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2669 iptr->sx.s23.s3.c.ref, disp);
2671 if (opt_showdisassemble)
2677 emit_label_beq(cd, BRANCH_LABEL_3);
2680 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2681 M_LDR_INTERN(REG_ITMP3,
2682 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2684 /* we put unresolved or non-immediate superindices onto dseg
2685 and do things slightly different */
2686 if ((super == NULL) || !IS_IMM(superindex)) {
2687 /* disp was computed before we added the patcher */
2688 M_DSEG_LOAD(REG_ITMP2, disp);
2689 M_CMP(REG_ITMP3, REG_ITMP2);
2691 if (d == REG_ITMP2) {
2698 /* this assumes something */
2699 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2701 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2702 assert(sizeof(methodptr*) == 4);
2703 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2705 if (d == REG_ITMP2) {
2712 assert(IS_IMM(superindex));
2713 M_CMP_IMM(REG_ITMP3, superindex);
2717 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2718 superindex * sizeof(methodptr*);
2722 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2723 M_TST(REG_ITMP3, REG_ITMP3);
2727 emit_label_br(cd, BRANCH_LABEL_4);
2729 emit_label(cd, BRANCH_LABEL_3);
2732 /* class checkcast code */
2734 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2735 if (super == NULL) {
2736 emit_label(cd, BRANCH_LABEL_2);
2738 disp = dseg_add_unique_address(cd, NULL);
2740 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2741 iptr->sx.s23.s3.c.ref, disp);
2743 if (opt_showdisassemble)
2747 disp = dseg_add_address(cd, super->vftbl);
2751 emit_label_beq(cd, BRANCH_LABEL_5);
2754 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2755 M_DSEG_LOAD(REG_ITMP2, disp);
2757 CODEGEN_CRITICAL_SECTION_START;
2759 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2760 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2761 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2763 CODEGEN_CRITICAL_SECTION_END;
2765 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2766 M_CMP(REG_ITMP1, REG_ITMP2);
2767 /* If d == REG_ITMP2, then it's destroyed */
2773 emit_label(cd, BRANCH_LABEL_5);
2776 if (super == NULL) {
2777 emit_label(cd, BRANCH_LABEL_1);
2778 emit_label(cd, BRANCH_LABEL_4);
2783 emit_store_dst(jd, iptr, d);
2786 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2788 /* copy sizes to stack if necessary */
2790 MCODECHECK((iptr->s1.argcount << 1) + 64);
2792 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2794 var = VAR(iptr->sx.s23.s2.args[s1]);
2796 /* copy SAVEDVAR sizes to stack */
2798 if (!(var->flags & PREALLOC)) {
2799 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2800 M_STR(s2, REG_SP, s1 * 4);
2804 /* a0 = dimension count */
2806 assert(IS_IMM(iptr->s1.argcount));
2807 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2809 /* is patcher function set? */
2811 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2812 disp = dseg_add_unique_address(cd, NULL);
2814 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2815 iptr->sx.s23.s3.c.ref, disp);
2817 if (opt_showdisassemble)
2821 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2823 /* a1 = arraydescriptor */
2825 M_DSEG_LOAD(REG_A1, disp);
2827 /* a2 = pointer to dimensions = stack pointer */
2829 M_INTMOVE(REG_SP, REG_A2);
2831 /* call builtin_multianewarray here */
2833 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2834 M_DSEG_BRANCH(disp);
2838 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2841 /* check for exception before result assignment */
2843 emit_exception_check(cd, iptr);
2847 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2848 M_INTMOVE(REG_RESULT, d);
2849 emit_store_dst(jd, iptr, d);
2852 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2854 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2855 emit_nullpointer_check(cd, iptr, s1);
2859 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2862 } /* the big switch */
2864 } /* for all instructions */
2866 } /* for all basic blocks */
2868 dseg_createlinenumbertable(cd);
2871 /* generate traps */
2873 emit_patcher_traps(jd);
2875 /* everything's ok */
2881 /* codegen_emit_stub_compiler **************************************************
2883 Emits a stub routine which calls the compiler.
2885 *******************************************************************************/
2887 void codegen_emit_stub_compiler(jitdata *jd)
2892 /* get required compiler data */
2897 /* code for the stub */
2899 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2900 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2904 /* codegen_emit_stub_native ****************************************************
2906 Emits a stub routine which calls a native method.
2908 *******************************************************************************/
2910 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2919 s4 disp, funcdisp, s1, s2;
2921 /* get required compiler data */
2927 /* initialize variables */
2930 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2932 /* calculate stackframe size */
2934 cd->stackframesize =
2935 4 + /* return address */
2936 sizeof(stackframeinfo) + /* stackframeinfo */
2937 sizeof(localref_table) + /* localref_table */
2938 nmd->memuse * 4; /* stack arguments */
2940 /* align stack to 8-byte */
2942 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2944 /* create method header */
2946 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2947 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2948 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2949 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2950 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2951 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2952 (void) dseg_addlinenumbertablesize(cd);
2953 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2955 /* generate stub code */
2957 M_STMFD(1<<REG_LR, REG_SP);
2958 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2960 #if !defined(NDEBUG)
2961 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2962 emit_verbosecall_enter(jd);
2965 /* get function address (this must happen before the stackframeinfo) */
2967 funcdisp = dseg_add_functionptr(cd, f);
2969 #if !defined(WITH_STATIC_CLASSPATH)
2971 patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
2973 if (opt_showdisassemble)
2978 /* Save integer and float argument registers (these are 4
2979 registers, stack is 8-byte aligned). */
2981 M_STMFD(BITMASK_ARGS, REG_SP);
2982 /* TODO: floating point */
2984 /* create native stackframe info */
2986 assert(IS_IMM(4*4 + cd->stackframesize));
2987 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
2988 M_MOV(REG_A1, REG_PV);
2989 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize);
2990 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
2991 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2992 M_DSEG_BRANCH(disp);
2996 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2999 /* Restore integer and float argument registers (these are 4
3000 registers, stack is 8-byte aligned). */
3002 M_LDMFD(BITMASK_ARGS, REG_SP);
3003 /* TODO: floating point */
3005 /* copy or spill arguments to new locations */
3006 /* ATTENTION: the ARM has only integer argument registers! */
3008 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3009 t = md->paramtypes[i].type;
3011 if (!md->params[i].inmemory) {
3012 s1 = md->params[i].regoff;
3013 s2 = nmd->params[j].regoff;
3015 if (!nmd->params[j].inmemory) {
3016 #if !defined(__ARM_EABI__)
3017 SPLIT_OPEN(t, s2, REG_ITMP1);
3020 if (IS_2_WORD_TYPE(t))
3025 #if !defined(__ARM_EABI__)
3026 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3030 if (IS_2_WORD_TYPE(t))
3031 M_LST(s1, REG_SP, s2);
3033 M_IST(s1, REG_SP, s2);
3037 s1 = md->params[i].regoff + cd->stackframesize;
3038 s2 = nmd->params[j].regoff;
3040 if (IS_2_WORD_TYPE(t)) {
3041 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3042 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3045 M_ILD(REG_ITMP1, REG_SP, s1);
3046 M_IST(REG_ITMP1, REG_SP, s2);
3051 /* put class into second argument register */
3053 if (m->flags & ACC_STATIC) {
3054 disp = dseg_add_address(cd, m->class);
3055 M_DSEG_LOAD(REG_A1, disp);
3058 /* put env into first argument register */
3060 disp = dseg_add_address(cd, _Jv_env);
3061 M_DSEG_LOAD(REG_A0, disp);
3063 /* do the native function call */
3065 M_DSEG_BRANCH(funcdisp);
3068 /* TODO: this is only needed because of the tracer ... do we
3071 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3074 #if !defined(__SOFTFP__)
3075 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3076 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3077 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3078 #if 0 && !defined(NDEBUG)
3079 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3081 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3082 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3083 if (IS_2_WORD_TYPE(md->returntype.type)) {
3084 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3085 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3087 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3088 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3093 #if !defined(NDEBUG)
3094 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3095 emit_verbosecall_exit(jd);
3098 /* remove native stackframe info */
3099 /* TODO: improve this store/load */
3101 M_STMFD(BITMASK_RESULT, REG_SP);
3103 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize - SIZEOF_VOID_P);
3104 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3105 M_DSEG_BRANCH(disp);
3106 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3109 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3110 M_LDMFD(BITMASK_RESULT, REG_SP);
3112 /* finish stub code, but do not yet return to caller */
3114 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3115 M_LDMFD(1<<REG_LR, REG_SP);
3117 /* check for exception */
3119 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3120 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3122 /* handle exception here */
3124 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3126 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3127 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3128 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3130 /* generate patcher stubs */
3132 emit_patcher_traps(jd);
3136 /* asm_debug *******************************************************************
3140 *******************************************************************************/
3142 void asm_debug(int a1, int a2, int a3, int a4)
3144 printf("===> i am going to exit after this debugging message!\n");
3145 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3146 vm_abort("leave you now");
3151 * These are local overrides for various environment variables in Emacs.
3152 * Please do not remove this and leave it at the end of the file, where
3153 * Emacs will automagically detect them.
3154 * ---------------------------------------------------------------------
3157 * indent-tabs-mode: t
3161 * vim:noexpandtab:sw=4:ts=4: