1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 #include "vm/jit/arm/arch.h"
38 #include "vm/jit/arm/codegen.h"
40 #include "mm/memory.h"
42 #include "native/localref.h"
43 #include "native/native.h"
45 #include "threads/lock-common.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
52 #include "vm/jit/abi.h"
53 #include "vm/jit/asmpart.h"
54 #include "vm/jit/codegen-common.h"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/emit-common.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/md.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher-common.h"
62 #include "vm/jit/reg.h"
64 #if defined(ENABLE_LSRA)
65 #include "vm/jit/allocator/lsra.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/options.h"
72 /* codegen_emit ****************************************************************
74 Generates machine code.
76 *******************************************************************************/
78 bool codegen_emit(jitdata *jd)
97 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
98 unresolved_method *um;
99 builtintable_entry *bte;
102 unresolved_field *uf;
106 /* get required compiler data */
113 /* prevent compiler warnings */
121 /* space to save used callee saved registers */
123 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
125 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
126 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
127 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
129 spilledregs_num = rd->memuse;
131 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
132 if (checksync && (m->flags & ACC_SYNCHRONIZED))
136 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
138 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
139 only in native stubs. */
140 /* align stack to 8-byte */
142 cd->stackframesize = (cd->stackframesize + 4) & ~4;
144 /* SECTION: Method Header */
145 /* create method header */
147 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
148 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
150 #if defined(ENABLE_THREADS)
151 /* IsSync contains the offset relative to the stack pointer for the
152 argument of monitor_exit used in the exception handler. Since the
153 offset could be zero and give a wrong meaning of the flag it is
157 if (checksync && (m->flags & ACC_SYNCHRONIZED))
158 (void) dseg_add_unique_s4(cd, rd->memuse * 8 + 4);/* IsSync */
161 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
163 /* REMOVEME: We still need it for exception handling in assembler. */
165 if (code_is_leafmethod(code))
166 (void) dseg_add_unique_s4(cd, 1);
168 (void) dseg_add_unique_s4(cd, 0);
170 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
171 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
172 (void) dseg_addlinenumbertablesize(cd);
173 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
175 /* create exception table */
177 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
178 dseg_add_target(cd, ex->start);
179 dseg_add_target(cd, ex->end);
180 dseg_add_target(cd, ex->handler);
181 (void) dseg_add_unique_address(cd, ex->catchtype.any);
184 /* save return address and used callee saved registers */
186 savedregs_bitmask = 0;
188 if (!code_is_leafmethod(code))
189 savedregs_bitmask = (1<<REG_LR);
191 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
192 savedregs_bitmask |= (1<<(rd->savintregs[i]));
195 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
196 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
197 /* TODO: floating-point */
201 if (savedregs_bitmask)
202 M_STMFD(savedregs_bitmask, REG_SP);
204 /* create additional stack frame for spilled variables (if necessary) */
206 if ((cd->stackframesize / 4 - savedregs_num) > 0)
207 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
209 /* take arguments out of register or stack frame */
212 for (i = 0, len = 0; i < md->paramcount; i++) {
213 s1 = md->params[i].regoff;
214 t = md->paramtypes[i].type;
216 varindex = jd->local_map[len * 5 + t];
218 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
220 if (varindex == UNUSED)
225 /* ATTENTION: we use interger registers for all arguments (even float) */
226 #if !defined(ENABLE_SOFTFLOAT)
227 if (IS_INT_LNG_TYPE(t)) {
229 if (!md->params[i].inmemory) {
230 if (!(var->flags & INMEMORY)) {
231 if (IS_2_WORD_TYPE(t))
232 M_LNGMOVE(s1, var->vv.regoff);
234 M_INTMOVE(s1, var->vv.regoff);
237 if (IS_2_WORD_TYPE(t))
238 M_LST(s1, REG_SP, var->vv.regoff);
240 M_IST(s1, REG_SP, var->vv.regoff);
243 else { /* stack arguments */
244 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
245 if (IS_2_WORD_TYPE(t))
246 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
248 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
250 else { /* stack arg -> spilled */
251 /* Reuse Memory Position on Caller Stack */
252 var->vv.regoff = cd->stackframesize + s1;
255 #if !defined(ENABLE_SOFTFLOAT)
258 if (!md->params[i].inmemory) {
259 if (!(var->flags & INMEMORY)) {
260 if (IS_2_WORD_TYPE(t))
261 M_CAST_L2D(s1, var->vv.regoff);
263 M_CAST_I2F(s1, var->vv.regoff);
266 if (IS_2_WORD_TYPE(t))
267 M_LST(s1, REG_SP, var->vv.regoff);
269 M_IST(s1, REG_SP, var->vv.regoff);
273 if (!(var->flags & INMEMORY)) {
274 if (IS_2_WORD_TYPE(t))
275 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
277 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
280 /* Reuse Memory Position on Caller Stack */
281 var->vv.regoff = cd->stackframesize + s1;
285 #endif /* !defined(ENABLE_SOFTFLOAT) */
288 #if defined(ENABLE_THREADS)
289 /* call monitorenter function */
291 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
292 /* stack offset for monitor argument */
296 # if !defined(NDEBUG)
297 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
298 M_STMFD(BITMASK_ARGS, REG_SP);
303 /* get the correct lock object */
305 if (m->flags & ACC_STATIC) {
306 disp = dseg_add_address(cd, &m->class->object.header);
307 M_DSEG_LOAD(REG_A0, disp);
310 emit_nullpointer_check_force(cd, iptr, REG_A0);
313 M_STR(REG_A0, REG_SP, s1);
314 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
316 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
319 # if !defined(NDEBUG)
320 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
321 M_LDMFD(BITMASK_ARGS, REG_SP);
327 /* call trace function */
329 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
330 emit_verbosecall_enter(jd);
333 /* end of header generation */
335 /* create replacement points */
336 REPLACEMENT_POINTS_INIT(cd, jd);
338 /* SECTION: ICMD Code Generation */
339 /* for all basic blocks */
341 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
343 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
345 /* is this basic block reached? */
347 if (bptr->flags < BBREACHED)
350 /* branch resolving */
352 codegen_resolve_branchrefs(cd, bptr);
354 /* handle replacement points */
355 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
357 /* copy interface registers to their destination */
363 #if defined(ENABLE_LSRA)
367 var = VAR(bptr->invars[len]);
368 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
369 if (!(var->flags & INMEMORY))
373 M_INTMOVE(REG_ITMP1, d);
374 emit_store(jd, NULL, var, d);
381 var = VAR(bptr->invars[len]);
383 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
384 d = codegen_reg_of_var(0, var, REG_ITMP1);
385 M_INTMOVE(REG_ITMP1, d);
386 emit_store(jd, NULL, var, d);
389 assert((var->flags & INOUT));
392 #if defined(ENABLE_LSRA)
396 /* for all instructions */
399 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
401 /* add line number */
402 if (iptr->line != currentline) {
403 dseg_addlinenumber(cd, iptr->line);
404 currentline = iptr->line;
407 MCODECHECK(64); /* an instruction usually needs < 64 words */
411 case ICMD_NOP: /* ... ==> ... */
414 /* constant operations ************************************************/
416 case ICMD_ICONST: /* ... ==> ..., constant */
418 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
419 ICONST(d, iptr->sx.val.i);
420 emit_store_dst(jd, iptr, d);
423 case ICMD_ACONST: /* ... ==> ..., constant */
425 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
426 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
427 disp = dseg_add_unique_address(cd, NULL);
429 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
430 iptr->sx.val.c.ref, disp);
432 M_DSEG_LOAD(d, disp);
435 ICONST(d, (u4) iptr->sx.val.anyptr);
437 emit_store_dst(jd, iptr, d);
440 case ICMD_LCONST: /* ... ==> ..., constant */
442 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
443 LCONST(d, iptr->sx.val.l);
444 emit_store_dst(jd, iptr, d);
447 case ICMD_FCONST: /* ... ==> ..., constant */
449 #if defined(ENABLE_SOFTFLOAT)
450 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
451 ICONST(d, iptr->sx.val.i);
452 emit_store_dst(jd, iptr, d);
454 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
455 FCONST(d, iptr->sx.val.f);
456 emit_store_dst(jd, iptr, d);
460 case ICMD_DCONST: /* ... ==> ..., constant */
462 #if defined(ENABLE_SOFTFLOAT)
463 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
464 LCONST(d, iptr->sx.val.l);
465 emit_store_dst(jd, iptr, d);
467 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
468 DCONST(d, iptr->sx.val.d);
469 emit_store_dst(jd, iptr, d);
474 /* load/store/copy/move operations ************************************/
476 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
477 case ICMD_ALOAD: /* op1 = local variable */
481 case ICMD_ISTORE: /* ..., value ==> ... */
492 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
496 /* pop operations *****************************************************/
498 /* attention: double and longs are only one entry in CACAO ICMDs */
500 case ICMD_POP: /* ..., value ==> ... */
501 case ICMD_POP2: /* ..., value, value ==> ... */
506 /* integer operations *************************************************/
508 case ICMD_INT2BYTE: /* ..., 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, 24));
513 M_MOV(d, REG_ASR(d, 24));
514 emit_store_dst(jd, iptr, d);
517 case ICMD_INT2CHAR: /* ..., 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_LSR(d, 16)); /* ATTENTION: char is unsigned */
523 emit_store_dst(jd, iptr, d);
526 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
528 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
529 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
530 M_MOV(d, REG_LSL(s1, 16));
531 M_MOV(d, REG_ASR(d, 16));
532 emit_store_dst(jd, iptr, d);
535 case ICMD_I2L: /* ..., value ==> ..., value */
537 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
538 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
539 M_INTMOVE(s1, GET_LOW_REG(d));
540 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
541 emit_store_dst(jd, iptr, d);
544 case ICMD_L2I: /* ..., value ==> ..., value */
546 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
547 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
549 emit_store_dst(jd, iptr, d);
552 case ICMD_INEG: /* ..., value ==> ..., - value */
554 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
555 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
557 emit_store_dst(jd, iptr, d);
560 case ICMD_LNEG: /* ..., value ==> ..., - value */
562 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
564 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
565 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
566 emit_store_dst(jd, iptr, d);
569 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
571 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
572 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
573 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
575 emit_store_dst(jd, iptr, d);
578 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
580 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
581 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
582 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
583 M_ADD_S(GET_LOW_REG(d), s1, s2);
584 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
585 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
586 M_ADC(GET_HIGH_REG(d), s1, s2);
587 emit_store_dst(jd, iptr, d);
593 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
594 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
596 if (IS_IMM(iptr->sx.val.i)) {
597 M_ADD_IMM(d, s1, iptr->sx.val.i);
598 } else if (IS_IMM(-iptr->sx.val.i)) {
599 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
601 ICONST(REG_ITMP3, iptr->sx.val.i);
602 M_ADD(d, s1, REG_ITMP3);
605 emit_store_dst(jd, iptr, d);
608 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
609 /* sx.val.l = constant */
611 s3 = iptr->sx.val.l & 0xffffffff;
612 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
613 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
615 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
617 ICONST(REG_ITMP3, s3);
618 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
620 s3 = iptr->sx.val.l >> 32;
621 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
623 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
625 ICONST(REG_ITMP3, s3);
626 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
628 emit_store_dst(jd, iptr, d);
631 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
633 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
634 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
635 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
637 emit_store_dst(jd, iptr, d);
640 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
642 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
643 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
644 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
645 M_SUB_S(GET_LOW_REG(d), s1, s2);
646 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
647 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
648 M_SBC(GET_HIGH_REG(d), s1, s2);
649 emit_store_dst(jd, iptr, d);
652 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
653 /* sx.val.i = constant */
655 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
656 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
657 if (IS_IMM(iptr->sx.val.i))
658 M_SUB_IMM(d, s1, iptr->sx.val.i);
660 ICONST(REG_ITMP3, iptr->sx.val.i);
661 M_SUB(d, s1, REG_ITMP3);
663 emit_store_dst(jd, iptr, d);
666 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
667 /* sx.val.l = constant */
669 s3 = iptr->sx.val.l & 0xffffffff;
670 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
671 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
673 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
675 ICONST(REG_ITMP3, s3);
676 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
678 s3 = iptr->sx.val.l >> 32;
679 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
681 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
683 ICONST(REG_ITMP3, s3);
684 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
686 emit_store_dst(jd, iptr, d);
689 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
691 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
692 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
693 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
695 emit_store_dst(jd, iptr, d);
698 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
699 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
701 s1 = emit_load_s1(jd, iptr, REG_A0);
702 s2 = emit_load_s2(jd, iptr, REG_A1);
703 emit_arithmetic_check(cd, iptr, s2);
705 /* move arguments into argument registers */
706 M_INTMOVE(s1, REG_A0);
707 M_INTMOVE(s2, REG_A1);
709 /* call builtin function */
710 bte = iptr->sx.s23.s3.bte;
711 disp = dseg_add_functionptr(cd, bte->fp);
715 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
718 /* move result into destination register */
719 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
720 M_INTMOVE(REG_RESULT, d);
721 emit_store_dst(jd, iptr, d);
724 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
725 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
727 /* move arguments into argument registers */
729 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
730 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
731 /* XXX TODO: only do this if arithmetic check is really done! */
732 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
733 emit_arithmetic_check(cd, iptr, REG_ITMP3);
735 M_LNGMOVE(s1, REG_A0_A1_PACKED);
736 M_LNGMOVE(s2, REG_A2_A3_PACKED);
738 /* call builtin function */
739 bte = iptr->sx.s23.s3.bte;
740 disp = dseg_add_functionptr(cd, bte->fp);
744 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
747 /* move result into destination register */
748 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
749 M_LNGMOVE(REG_RESULT_PACKED, d);
750 emit_store_dst(jd, iptr, d);
753 case ICMD_IMULPOW2: /* ..., 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 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
759 emit_store_dst(jd, iptr, d);
762 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
763 /* sx.val.i = constant */
765 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
766 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
767 /* this rounds towards 0 as java likes it */
768 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
769 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
770 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
771 /* this rounds towards nearest, not java style */
772 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
773 M_ADCMI_IMM(d, d, 0);*/
774 emit_store_dst(jd, iptr, d);
777 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
778 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
780 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
781 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
782 M_MOV_S(REG_ITMP1, s1);
783 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
784 if (IS_IMM(iptr->sx.val.i))
785 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
787 ICONST(REG_ITMP3, iptr->sx.val.i);
788 M_AND(REG_ITMP1, REG_ITMP3, d);
790 M_RSBMI_IMM(d, d, 0);
791 emit_store_dst(jd, iptr, d);
794 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
796 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
797 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
798 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
799 M_AND_IMM(s2, 0x1f, REG_ITMP2);
800 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
801 emit_store_dst(jd, iptr, d);
804 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
806 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
807 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
808 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
809 M_AND_IMM(s2, 0x1f, REG_ITMP2);
810 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
811 emit_store_dst(jd, iptr, d);
814 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
816 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
817 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
818 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
819 M_AND_IMM(s2, 0x1f, REG_ITMP2);
820 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
821 emit_store_dst(jd, iptr, d);
824 case ICMD_ISHLCONST: /* ..., 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_ITMP2);
829 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
830 emit_store_dst(jd, iptr, d);
833 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
834 /* sx.val.i = constant */
836 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
837 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
838 /* we need to check for zero here because arm interprets it as SHR by 32 */
839 if ((iptr->sx.val.i & 0x1f) == 0) {
842 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
844 emit_store_dst(jd, iptr, d);
847 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
848 /* sx.val.i = constant */
850 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
851 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
852 /* we need to check for zero here because arm interprets it as SHR by 32 */
853 if ((iptr->sx.val.i & 0x1f) == 0)
856 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
857 emit_store_dst(jd, iptr, d);
860 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
862 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
863 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
864 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
866 emit_store_dst(jd, iptr, d);
869 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
871 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
872 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
873 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
874 M_AND(s1, s2, GET_LOW_REG(d));
875 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
876 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
877 M_AND(s1, s2, GET_HIGH_REG(d));
878 emit_store_dst(jd, iptr, d);
881 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
883 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
884 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
885 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
887 emit_store_dst(jd, iptr, d);
890 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
892 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
893 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
894 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
895 M_ORR(s1, s2, GET_LOW_REG(d));
896 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
897 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
898 M_ORR(s1, s2, GET_HIGH_REG(d));
899 emit_store_dst(jd, iptr, d);
902 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
904 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
905 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
906 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
908 emit_store_dst(jd, iptr, d);
911 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
913 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
914 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
915 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
916 M_EOR(s1, s2, GET_LOW_REG(d));
917 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
918 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
919 M_EOR(s1, s2, GET_HIGH_REG(d));
920 emit_store_dst(jd, iptr, d);
924 /* floating operations ************************************************/
926 #if !defined(ENABLE_SOFTFLOAT)
928 case ICMD_FNEG: /* ..., value ==> ..., - value */
930 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
931 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
933 emit_store_dst(jd, iptr, d);
936 case ICMD_FADD: /* ..., 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_FSUB: /* ..., 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_FMUL: /* ..., 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 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
964 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
965 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
966 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
968 emit_store_dst(jd, iptr, d);
971 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
975 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
977 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
978 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
979 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
981 emit_store_dst(jd, iptr, d);
985 case ICMD_DNEG: /* ..., value ==> ..., - value */
987 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
988 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
990 emit_store_dst(jd, iptr, d);
993 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
995 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
996 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
997 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
999 emit_store_dst(jd, iptr, d);
1002 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1004 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1005 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1006 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1008 emit_store_dst(jd, iptr, d);
1011 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1013 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1014 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1015 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1017 emit_store_dst(jd, iptr, d);
1020 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1022 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1023 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1024 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1026 emit_store_dst(jd, iptr, d);
1029 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1033 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1035 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1036 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1037 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1039 emit_store_dst(jd, iptr, d);
1043 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1045 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1046 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1048 emit_store_dst(jd, iptr, d);
1051 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1053 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1054 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1056 emit_store_dst(jd, iptr, d);
1059 case ICMD_F2I: /* ..., 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 #if !defined(__VFP_FP__)
1066 /* this checks for NaN; to return zero as Java likes it */
1070 emit_store_dst(jd, iptr, d);
1073 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1075 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1076 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1077 /* this uses round towards zero, as Java likes it */
1079 #if !defined(__VFP_FP__)
1080 /* this checks for NaN; to return zero as Java likes it */
1084 emit_store_dst(jd, iptr, d);
1087 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1089 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1090 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1092 emit_store_dst(jd, iptr, d);
1095 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1097 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1098 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1100 emit_store_dst(jd, iptr, d);
1103 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1105 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1106 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1107 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1110 #if defined(__VFP_FP__)
1111 M_FMSTAT; /* on VFP we need to transfer the flags */
1113 M_SUBGT_IMM(d, d, 1);
1114 M_ADDLT_IMM(d, d, 1);
1115 emit_store_dst(jd, iptr, d);
1118 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1120 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1121 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1122 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1125 #if defined(__VFP_FP__)
1126 M_FMSTAT; /* on VFP we need to transfer the flags */
1128 M_SUBGT_IMM(d, d, 1);
1129 M_ADDLT_IMM(d, d, 1);
1130 emit_store_dst(jd, iptr, d);
1133 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1135 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1136 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1137 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1140 #if defined(__VFP_FP__)
1141 M_FMSTAT; /* on VFP we need to transfer the flags */
1143 M_SUBLT_IMM(d, d, 1);
1144 M_ADDGT_IMM(d, d, 1);
1145 emit_store_dst(jd, iptr, d);
1148 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1150 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1151 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1152 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1155 #if defined(__VFP_FP__)
1156 M_FMSTAT; /* on VFP we need to transfer the flags */
1158 M_SUBLT_IMM(d, d, 1);
1159 M_ADDGT_IMM(d, d, 1);
1160 emit_store_dst(jd, iptr, d);
1163 #endif /* !defined(ENABLE_SOFTFLOAT) */
1166 /* memory operations **************************************************/
1168 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1170 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1171 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1172 /* implicit null-pointer check */
1173 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1174 emit_store_dst(jd, iptr, d);
1177 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1179 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1180 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1181 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1182 /* implicit null-pointer check */
1183 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1184 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1185 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1186 emit_store_dst(jd, iptr, d);
1189 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1191 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1192 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1193 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1194 /* implicit null-pointer check */
1195 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1196 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1197 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1198 emit_store_dst(jd, iptr, d);
1201 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1203 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1204 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1205 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1206 /* implicit null-pointer check */
1207 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1208 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1209 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1210 emit_store_dst(jd, iptr, d);
1213 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1215 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1216 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1217 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1218 /* implicit null-pointer check */
1219 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1220 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1221 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1222 emit_store_dst(jd, iptr, d);
1225 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1227 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1228 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1229 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
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 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1234 emit_store_dst(jd, iptr, d);
1237 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1239 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1240 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1241 /* implicit null-pointer check */
1242 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1243 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1244 #if !defined(ENABLE_SOFTFLOAT)
1245 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1246 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1248 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1249 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1251 emit_store_dst(jd, iptr, d);
1254 case ICMD_DALOAD: /* ..., 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 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1261 #if !defined(ENABLE_SOFTFLOAT)
1262 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1263 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1265 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1266 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1268 emit_store_dst(jd, iptr, d);
1271 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1273 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1274 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1275 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1276 /* implicit null-pointer check */
1277 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1278 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1279 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1280 emit_store_dst(jd, iptr, d);
1283 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1285 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1286 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1287 /* implicit null-pointer check */
1288 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1289 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1290 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1291 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1294 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1296 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1297 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1298 /* implicit null-pointer check */
1299 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1300 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1301 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1302 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1305 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1307 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1308 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1309 /* implicit null-pointer check */
1310 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1311 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1312 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1313 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1316 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1318 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1319 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1320 /* implicit null-pointer check */
1321 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1322 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1323 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1324 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1327 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1329 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1330 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1331 /* implicit null-pointer check */
1332 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1333 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1334 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1335 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1338 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1340 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1341 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1342 /* implicit null-pointer check */
1343 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1344 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1345 #if !defined(ENABLE_SOFTFLOAT)
1346 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1347 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1349 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1350 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1354 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1356 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1357 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1358 /* implicit null-pointer check */
1359 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1360 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1361 #if !defined(ENABLE_SOFTFLOAT)
1362 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1363 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1365 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1366 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1370 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1372 s1 = emit_load_s1(jd, iptr, REG_A0);
1373 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1374 s3 = emit_load_s3(jd, iptr, REG_A1);
1376 /* implicit null-pointer check */
1377 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1379 /* move arguments to argument registers */
1380 M_INTMOVE(s1, REG_A0);
1381 M_INTMOVE(s3, REG_A1);
1383 /* call builtin function */
1384 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1385 M_DSEG_BRANCH(disp);
1388 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1391 /* check resturn value of builtin */
1392 emit_arraystore_check(cd, iptr);
1394 /* finally store address into array */
1395 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1396 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1397 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1398 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1399 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1402 case ICMD_GETSTATIC: /* ... ==> ..., value */
1404 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1405 uf = iptr->sx.s23.s3.uf;
1406 fieldtype = uf->fieldref->parseddesc.fd->type;
1407 disp = dseg_add_unique_address(cd, NULL);
1409 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1412 fi = iptr->sx.s23.s3.fmiref->p.field;
1413 fieldtype = fi->type;
1414 disp = dseg_add_address(cd, fi->value);
1416 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1417 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1422 M_DSEG_LOAD(REG_ITMP3, disp);
1423 switch (fieldtype) {
1425 #if defined(ENABLE_SOFTFLOAT)
1429 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1430 M_ILD_INTERN(d, REG_ITMP3, 0);
1433 #if defined(ENABLE_SOFTFLOAT)
1436 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1437 M_LLD_INTERN(d, REG_ITMP3, 0);
1439 #if !defined(ENABLE_SOFTFLOAT)
1441 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1442 M_FLD_INTERN(d, REG_ITMP3, 0);
1445 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1446 M_DLD_INTERN(d, REG_ITMP3, 0);
1452 emit_store_dst(jd, iptr, d);
1455 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1457 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1458 uf = iptr->sx.s23.s3.uf;
1459 fieldtype = uf->fieldref->parseddesc.fd->type;
1460 disp = dseg_add_unique_address(cd, NULL);
1462 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1465 fi = iptr->sx.s23.s3.fmiref->p.field;
1466 fieldtype = fi->type;
1467 disp = dseg_add_address(cd, fi->value);
1469 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1470 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1475 M_DSEG_LOAD(REG_ITMP3, disp);
1476 switch (fieldtype) {
1478 #if defined(ENABLE_SOFTFLOAT)
1482 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1483 M_IST_INTERN(s1, REG_ITMP3, 0);
1486 #if defined(ENABLE_SOFTFLOAT)
1489 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1490 M_LST_INTERN(s1, REG_ITMP3, 0);
1492 #if !defined(ENABLE_SOFTFLOAT)
1494 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1495 M_FST_INTERN(s1, REG_ITMP3, 0);
1498 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1499 M_DST_INTERN(s1, REG_ITMP3, 0);
1507 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1509 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1510 emit_nullpointer_check(cd, iptr, s1);
1513 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1514 uf = iptr->sx.s23.s3.uf;
1515 fieldtype = uf->fieldref->parseddesc.fd->type;
1519 fi = iptr->sx.s23.s3.fmiref->p.field;
1520 fieldtype = fi->type;
1524 #if !defined(ENABLE_SOFTFLOAT)
1525 /* HACK: softnull checks on floats */
1526 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1527 emit_nullpointer_check_force(cd, iptr, s1);
1530 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1532 uf = iptr->sx.s23.s3.uf;
1534 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1537 switch (fieldtype) {
1539 #if defined(ENABLE_SOFTFLOAT)
1543 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1547 #if defined(ENABLE_SOFTFLOAT)
1550 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1553 #if !defined(ENABLE_SOFTFLOAT)
1555 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1559 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1566 emit_store_dst(jd, iptr, d);
1569 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1571 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1572 emit_nullpointer_check(cd, iptr, s1);
1574 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1575 uf = iptr->sx.s23.s3.uf;
1576 fieldtype = uf->fieldref->parseddesc.fd->type;
1580 fi = iptr->sx.s23.s3.fmiref->p.field;
1581 fieldtype = fi->type;
1585 #if !defined(ENABLE_SOFTFLOAT)
1586 /* HACK: softnull checks on floats */
1587 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1588 emit_nullpointer_check_force(cd, iptr, s1);
1591 switch (fieldtype) {
1593 #if defined(ENABLE_SOFTFLOAT)
1597 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1599 #if defined(ENABLE_SOFTFLOAT)
1600 case TYPE_DBL: /* fall through */
1603 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1605 #if !defined(ENABLE_SOFTFLOAT)
1608 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1615 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1617 uf = iptr->sx.s23.s3.uf;
1619 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1622 switch (fieldtype) {
1624 #if defined(ENABLE_SOFTFLOAT)
1628 M_IST(s2, s1, disp);
1631 #if defined(ENABLE_SOFTFLOAT)
1634 M_LST(s2, s1, disp);
1636 #if !defined(ENABLE_SOFTFLOAT)
1638 M_FST(s2, s1, disp);
1641 M_DST(s2, s1, disp);
1650 /* branch operations **************************************************/
1652 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1654 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1655 M_INTMOVE(s1, REG_ITMP1_XPTR);
1656 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1657 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1658 iptr->sx.s23.s2.uc, 0);
1660 disp = dseg_add_functionptr(cd, asm_handle_exception);
1661 M_DSEG_LOAD(REG_ITMP3, disp);
1662 M_MOV(REG_ITMP2_XPC, REG_PC);
1663 M_MOV(REG_PC, REG_ITMP3);
1664 M_NOP; /* nop ensures that XPC is less than the end */
1665 /* of basic block */
1668 case ICMD_GOTO: /* ... ==> ... */
1671 emit_br(cd, iptr->dst.block);
1674 case ICMD_JSR: /* ... ==> ... */
1676 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1679 case ICMD_IFNULL: /* ..., value ==> ... */
1680 case ICMD_IFNONNULL:
1682 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1684 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1687 case ICMD_IFLT: /* ..., value ==> ... */
1688 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1694 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1695 M_COMPARE(s1, iptr->sx.val.i);
1696 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1699 case ICMD_IF_LEQ: /* ..., value ==> ... */
1701 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1702 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1703 if (iptr->sx.val.l == 0) {
1704 M_ORR_S(s1, s2, REG_ITMP3);
1707 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1708 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1709 M_CMP(s1, REG_ITMP3);*/
1710 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1711 M_CMPEQ(s2, REG_ITMP3);
1713 emit_beq(cd, iptr->dst.block);
1716 case ICMD_IF_LLT: /* ..., value ==> ... */
1718 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1719 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1720 if (iptr->sx.val.l == 0) {
1721 /* if high word is less than zero, the whole long is too */
1723 emit_blt(cd, iptr->dst.block);
1726 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1727 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1728 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1729 M_CMP(s1, REG_ITMP3);*/
1730 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1731 M_MOVGT_IMM(2, REG_ITMP1);
1732 M_MOVEQ_IMM(1, REG_ITMP1);
1734 /* low compare: x=x-1(ifLO) */
1735 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1736 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1737 M_CMP(s2, REG_ITMP3);*/
1738 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1740 /* branch if (x LT 1) */
1741 M_CMP_IMM(REG_ITMP1, 1);
1742 emit_blt(cd, iptr->dst.block);
1746 case ICMD_IF_LLE: /* ..., value ==> ... */
1748 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1749 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1750 if (iptr->sx.val.l == 0) {
1751 /* if high word is less than zero, the whole long is too */
1753 emit_blt(cd, iptr->dst.block);
1755 /* ... otherwise the low word has to be zero (tricky!) */
1757 emit_beq(cd, iptr->dst.block);
1760 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1761 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1762 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1763 M_CMP(s1, REG_ITMP3);*/
1764 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1765 M_MOVGT_IMM(2, REG_ITMP1);
1766 M_MOVEQ_IMM(1, REG_ITMP1);
1768 /* low compare: x=x+1(ifHI) */
1769 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1770 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1771 M_CMP(s2, REG_ITMP3);*/
1772 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1774 /* branch if (x LE 1) */
1775 M_CMP_IMM(REG_ITMP1, 1);
1776 emit_ble(cd, iptr->dst.block);
1780 case ICMD_IF_LGE: /* ..., value ==> ... */
1782 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1783 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1784 if (iptr->sx.val.l == 0) {
1785 /* if high word is greater or equal zero, the whole long is too */
1787 emit_bge(cd, iptr->dst.block);
1790 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1791 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1792 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1793 M_CMP(s1, REG_ITMP3);*/
1794 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1795 M_MOVGT_IMM(2, REG_ITMP1);
1796 M_MOVEQ_IMM(1, REG_ITMP1);
1798 /* low compare: x=x-1(ifLO) */
1799 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1800 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1801 M_CMP(s2, REG_ITMP3);*/
1802 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1804 /* branch if (x GE 1) */
1805 M_CMP_IMM(REG_ITMP1, 1);
1806 emit_bge(cd, iptr->dst.block);
1810 case ICMD_IF_LGT: /* ..., value ==> ... */
1812 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1813 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1815 if (iptr->sx.val.l == 0) {
1816 /* if high word is greater than zero, the whole long is too */
1819 codegen_add_branch_ref(cd, iptr->dst.block);
1821 /* ... or high was zero and low is non zero (tricky!) */
1822 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1823 M_MOVLT_IMM(1, REG_ITMP3);
1824 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1826 codegen_add_branch_ref(cd, iptr->dst.block);
1830 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1831 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1832 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1833 M_CMP(s1, REG_ITMP3);*/
1834 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1835 M_MOVGT_IMM(2, REG_ITMP1);
1836 M_MOVEQ_IMM(1, REG_ITMP1);
1838 /* low compare: x=x+1(ifHI) */
1839 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1840 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1841 M_CMP(s2, REG_ITMP3);*/
1842 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1844 /* branch if (x GT 1) */
1845 M_CMP_IMM(REG_ITMP1, 1);
1846 emit_bgt(cd, iptr->dst.block);
1852 case ICMD_IF_LNE: /* ..., value ==> ... */
1854 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1855 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1856 if (iptr->sx.val.l == 0) {
1857 M_ORR_S(s1, s2, REG_ITMP3);
1860 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1861 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1862 M_CMP(s1, REG_ITMP3);*/
1863 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1864 M_CMPEQ(s2, REG_ITMP3);
1866 emit_bne(cd, iptr->dst.block);
1869 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1870 case ICMD_IF_ICMPNE:
1871 case ICMD_IF_ICMPLT:
1872 case ICMD_IF_ICMPLE:
1873 case ICMD_IF_ICMPGT:
1874 case ICMD_IF_ICMPGE:
1876 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1877 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1879 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1882 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1883 case ICMD_IF_ACMPNE:
1885 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1886 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1888 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1891 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1892 /* op1 = target JavaVM pc */
1894 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1895 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1898 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1899 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1902 emit_beq(cd, iptr->dst.block);
1905 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1906 /* op1 = target JavaVM pc */
1908 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1909 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1912 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1913 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1916 emit_bne(cd, iptr->dst.block);
1919 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1920 /* op1 = target JavaVM pc */
1922 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1923 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1924 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1926 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1927 M_MOVGT_IMM(2, REG_ITMP3);
1928 M_MOVEQ_IMM(1, REG_ITMP3);
1930 /* low compare: x=x-1(ifLO) */
1931 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1932 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1934 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1936 /* branch if (x LT 1) */
1937 M_CMP_IMM(REG_ITMP3, 1);
1938 emit_blt(cd, iptr->dst.block);
1941 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1942 /* op1 = target JavaVM pc */
1944 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1945 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1946 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1948 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1949 M_MOVGT_IMM(2, REG_ITMP3);
1950 M_MOVEQ_IMM(1, REG_ITMP3);
1952 /* low compare: x=x-1(ifLO) */
1953 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1954 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1956 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1958 /* branch if (x LE 1) */
1959 M_CMP_IMM(REG_ITMP3, 1);
1960 emit_ble(cd, iptr->dst.block);
1963 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1964 /* op1 = target JavaVM pc */
1966 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1967 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1968 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1970 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1971 M_MOVGT_IMM(2, REG_ITMP3);
1972 M_MOVEQ_IMM(1, REG_ITMP3);
1974 /* low compare: x=x-1(ifLO) */
1975 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1976 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1978 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1980 /* branch if (x GT 1) */
1981 M_CMP_IMM(REG_ITMP3, 1);
1982 emit_bgt(cd, iptr->dst.block);
1985 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1986 /* op1 = target JavaVM pc */
1988 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1989 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1990 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1992 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1993 M_MOVGT_IMM(2, REG_ITMP3);
1994 M_MOVEQ_IMM(1, REG_ITMP3);
1996 /* low compare: x=x-1(ifLO) */
1997 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1998 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
2000 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2002 /* branch if (x GE 1) */
2003 M_CMP_IMM(REG_ITMP3, 1);
2004 emit_bge(cd, iptr->dst.block);
2007 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2010 branch_target_t *table;
2012 table = iptr->dst.table;
2014 l = iptr->sx.s23.s2.tablelow;
2015 i = iptr->sx.s23.s3.tablehigh;
2017 /* calculate new index (index - low) */
2018 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2020 M_INTMOVE(s1, REG_ITMP1);
2021 } else if (IS_IMM(l)) {
2022 M_SUB_IMM(REG_ITMP1, s1, l);
2024 ICONST(REG_ITMP2, l);
2025 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2028 /* range check (index <= high-low) */
2030 M_COMPARE(REG_ITMP1, i-1);
2031 emit_bugt(cd, table[0].block);
2033 /* build jump table top down and use address of lowest entry */
2038 dseg_add_target(cd, table->block);
2043 /* length of dataseg after last dseg_add_target is used by load */
2044 /* TODO: this loads from data-segment */
2045 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2046 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2049 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2052 lookup_target_t *lookup;
2054 lookup = iptr->dst.lookup;
2056 i = iptr->sx.s23.s2.lookupcount;
2059 MCODECHECK((i<<2)+8);
2060 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2063 M_COMPARE(s1, lookup->value);
2064 emit_beq(cd, lookup->target.block);
2068 /* default branch */
2069 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2073 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2075 #if !defined(ENABLE_SOFTFLOAT)
2076 REPLACEMENT_POINT_RETURN(cd, iptr);
2077 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2078 M_CAST_F2I(s1, REG_RESULT);
2079 goto ICMD_RETURN_do;
2082 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2084 REPLACEMENT_POINT_RETURN(cd, iptr);
2085 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2086 M_INTMOVE(s1, REG_RESULT);
2087 goto ICMD_RETURN_do;
2089 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2091 #if !defined(ENABLE_SOFTFLOAT)
2092 REPLACEMENT_POINT_RETURN(cd, iptr);
2093 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2094 M_CAST_D2L(s1, REG_RESULT_PACKED);
2095 goto ICMD_RETURN_do;
2098 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2100 REPLACEMENT_POINT_RETURN(cd, iptr);
2101 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2102 M_LNGMOVE(s1, REG_RESULT_PACKED);
2103 goto ICMD_RETURN_do;
2105 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2107 REPLACEMENT_POINT_RETURN(cd, iptr);
2108 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2109 M_INTMOVE(s1, REG_RESULT);
2110 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2111 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2112 iptr->sx.s23.s2.uc, 0);
2114 goto ICMD_RETURN_do;
2116 case ICMD_RETURN: /* ... ==> ... */
2118 REPLACEMENT_POINT_RETURN(cd, iptr);
2121 #if !defined(NDEBUG)
2122 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2123 emit_verbosecall_exit(jd);
2126 #if defined(ENABLE_THREADS)
2127 /* call monitorexit function */
2129 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2130 /* stack offset for monitor argument */
2132 s1 = rd->memuse * 8;
2134 /* we need to save the proper return value */
2136 switch (iptr->opc) {
2140 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2142 M_STMFD(BITMASK_RESULT, REG_SP);
2147 M_LDR(REG_A0, REG_SP, s1);
2148 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2149 M_DSEG_BRANCH(disp);
2151 /* we no longer need PV here, no more loading */
2152 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2153 M_RECOMPUTE_PV(s1);*/
2155 switch (iptr->opc) {
2159 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2161 M_LDMFD(BITMASK_RESULT, REG_SP);
2167 /* deallocate stackframe for spilled variables */
2169 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2170 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2172 /* restore callee saved registers + do return */
2174 if (savedregs_bitmask) {
2175 if (!code_is_leafmethod(code)) {
2176 savedregs_bitmask &= ~(1<<REG_LR);
2177 savedregs_bitmask |= (1<<REG_PC);
2179 M_LDMFD(savedregs_bitmask, REG_SP);
2182 /* if LR was not on stack, we need to return manually */
2184 if (code_is_leafmethod(code))
2185 M_MOV(REG_PC, REG_LR);
2188 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2190 bte = iptr->sx.s23.s3.bte;
2192 goto ICMD_INVOKE_do;
2194 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2195 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2196 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2197 case ICMD_INVOKEINTERFACE:
2199 REPLACEMENT_POINT_INVOKE(cd, iptr);
2201 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2203 um = iptr->sx.s23.s3.um;
2204 md = um->methodref->parseddesc.md;
2207 lm = iptr->sx.s23.s3.fmiref->p.method;
2209 md = lm->parseddesc;
2213 /* copy arguments to registers or stack location */
2215 s3 = md->paramcount;
2217 MCODECHECK((s3 << 1) + 64);
2219 for (s3 = s3 - 1; s3 >= 0; s3--) {
2220 var = VAR(iptr->sx.s23.s2.args[s3]);
2221 d = md->params[s3].regoff;
2223 if (var->flags & PREALLOC) /* argument was precolored? */
2226 /* TODO: document me */
2227 #if !defined(ENABLE_SOFTFLOAT)
2228 if (IS_INT_LNG_TYPE(var->type)) {
2229 #endif /* !defined(ENABLE_SOFTFLOAT) */
2230 if (!md->params[s3].inmemory) {
2231 s1 = emit_load(jd, iptr, var, d);
2233 if (IS_2_WORD_TYPE(var->type))
2239 if (IS_2_WORD_TYPE(var->type)) {
2240 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2241 M_LST(s1, REG_SP, d);
2244 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2245 M_IST(s1, REG_SP, d);
2248 #if !defined(ENABLE_SOFTFLOAT)
2251 if (!md->params[s3].inmemory) {
2252 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2253 if (IS_2_WORD_TYPE(var->type))
2259 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2260 if (IS_2_WORD_TYPE(var->type))
2261 M_DST(s1, REG_SP, d);
2263 M_FST(s1, REG_SP, d);
2266 #endif /* !defined(ENABLE_SOFTFLOAT) */
2269 switch (iptr->opc) {
2272 if (bte->stub == NULL) {
2273 disp = dseg_add_functionptr(cd, bte->fp);
2275 disp = dseg_add_functionptr(cd, bte->stub);
2278 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2280 /* generate the actual call */
2282 M_MOV(REG_LR, REG_PC);
2283 M_MOV(REG_PC, REG_PV);
2284 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2288 case ICMD_INVOKESPECIAL:
2289 emit_nullpointer_check(cd, iptr, REG_A0);
2292 case ICMD_INVOKESTATIC:
2294 disp = dseg_add_unique_address(cd, NULL);
2296 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2300 disp = dseg_add_address(cd, lm->stubroutine);
2302 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2304 /* generate the actual call */
2306 M_MOV(REG_LR, REG_PC);
2307 M_MOV(REG_PC, REG_PV);
2308 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2312 case ICMD_INVOKEVIRTUAL:
2314 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2319 s1 = OFFSET(vftbl_t, table[0]) +
2320 sizeof(methodptr) * lm->vftblindex;
2322 /* implicit null-pointer check */
2323 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2324 OFFSET(java_object_t, vftbl));
2325 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2327 /* generate the actual call */
2329 M_MOV(REG_LR, REG_PC);
2330 M_MOV(REG_PC, REG_PV);
2331 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2335 case ICMD_INVOKEINTERFACE:
2337 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2343 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2344 sizeof(methodptr*) * lm->class->index;
2345 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2348 /* implicit null-pointer check */
2349 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2350 OFFSET(java_object_t, vftbl));
2351 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2352 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2354 /* generate the actual call */
2356 M_MOV(REG_LR, REG_PC);
2357 M_MOV(REG_PC, REG_PV);
2358 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2363 /* store size of call code in replacement point */
2364 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2366 /* store return value */
2368 d = md->returntype.type;
2370 #if !defined(__SOFTFP__)
2371 /* TODO: this is only a hack, since we use R0/R1 for float
2372 return! this depends on gcc; it is independent from
2373 our ENABLE_SOFTFLOAT define */
2374 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2375 #if 0 && !defined(NDEBUG)
2376 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2378 /* we cannot use this macro, since it is not defined
2379 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2380 REG_FRESULT, REG_RESULT_TYPED(d)); */
2381 if (IS_2_WORD_TYPE(d)) {
2382 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2383 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2385 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2386 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2391 if (d != TYPE_VOID) {
2392 #if !defined(ENABLE_SOFTFLOAT)
2393 if (IS_INT_LNG_TYPE(d)) {
2394 #endif /* !defined(ENABLE_SOFTFLOAT) */
2395 if (IS_2_WORD_TYPE(d)) {
2396 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2397 M_LNGMOVE(REG_RESULT_PACKED, s1);
2400 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2401 M_INTMOVE(REG_RESULT, s1);
2404 #if !defined(ENABLE_SOFTFLOAT)
2406 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2407 if (IS_2_WORD_TYPE(d))
2408 M_CAST_L2D(REG_RESULT_PACKED, s1);
2410 M_CAST_I2F(REG_RESULT, s1);
2412 #endif /* !defined(ENABLE_SOFTFLOAT) */
2414 emit_store_dst(jd, iptr, s1);
2418 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2420 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2421 /* object type cast-check */
2426 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2431 super = iptr->sx.s23.s3.c.cls;
2432 superindex = super->index;
2435 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2436 CODEGEN_CRITICAL_SECTION_NEW;
2438 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2440 /* if class is not resolved, check which code to call */
2442 if (super == NULL) {
2444 emit_label_beq(cd, BRANCH_LABEL_1);
2446 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2447 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2448 iptr->sx.s23.s3.c.ref, disp);
2450 M_DSEG_LOAD(REG_ITMP2, disp);
2451 disp = dseg_add_s4(cd, ACC_INTERFACE);
2452 M_DSEG_LOAD(REG_ITMP3, disp);
2453 M_TST(REG_ITMP2, REG_ITMP3);
2454 emit_label_beq(cd, BRANCH_LABEL_2);
2457 /* interface checkcast code */
2459 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2460 if ((super == NULL) || !IS_IMM(superindex)) {
2461 disp = dseg_add_unique_s4(cd, superindex);
2463 if (super == NULL) {
2464 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2465 iptr->sx.s23.s3.c.ref, disp);
2469 emit_label_beq(cd, BRANCH_LABEL_3);
2472 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2473 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2475 /* we put unresolved or non-immediate superindices onto dseg */
2476 if ((super == NULL) || !IS_IMM(superindex)) {
2477 /* disp was computed before we added the patcher */
2478 M_DSEG_LOAD(REG_ITMP2, disp);
2479 M_CMP(REG_ITMP3, REG_ITMP2);
2481 assert(IS_IMM(superindex));
2482 M_CMP_IMM(REG_ITMP3, superindex);
2485 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2487 /* if we loaded the superindex out of the dseg above, we do
2488 things differently here! */
2489 if ((super == NULL) || !IS_IMM(superindex)) {
2491 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2493 /* this assumes something */
2494 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2496 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2497 assert(sizeof(methodptr*) == 4);
2498 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2504 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2505 superindex * sizeof(methodptr*);
2509 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2510 M_TST(REG_ITMP3, REG_ITMP3);
2511 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2514 emit_label_br(cd, BRANCH_LABEL_4);
2516 emit_label(cd, BRANCH_LABEL_3);
2519 /* class checkcast code */
2521 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2522 if (super == NULL) {
2523 emit_label(cd, BRANCH_LABEL_2);
2525 disp = dseg_add_unique_address(cd, NULL);
2527 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2528 iptr->sx.s23.s3.c.ref,
2532 disp = dseg_add_address(cd, super->vftbl);
2535 emit_label_beq(cd, BRANCH_LABEL_5);
2538 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2539 M_DSEG_LOAD(REG_ITMP3, disp);
2541 CODEGEN_CRITICAL_SECTION_START;
2543 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2544 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2545 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2546 M_DSEG_LOAD(REG_ITMP3, disp);
2547 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2549 CODEGEN_CRITICAL_SECTION_END;
2551 M_CMP(REG_ITMP2, REG_ITMP3);
2552 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2555 emit_label(cd, BRANCH_LABEL_5);
2558 if (super == NULL) {
2559 emit_label(cd, BRANCH_LABEL_1);
2560 emit_label(cd, BRANCH_LABEL_4);
2563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2566 /* array type cast-check */
2568 s1 = emit_load_s1(jd, iptr, REG_A0);
2569 M_INTMOVE(s1, REG_A0);
2571 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2572 disp = dseg_add_unique_address(cd, NULL);
2574 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2575 iptr->sx.s23.s3.c.ref,
2579 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2581 M_DSEG_LOAD(REG_A1, disp);
2582 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2583 M_DSEG_BRANCH(disp);
2586 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2587 M_RECOMPUTE_PV(disp);
2589 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2590 M_TST(REG_RESULT, REG_RESULT);
2591 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2593 d = codegen_reg_of_dst(jd, iptr, s1);
2597 emit_store_dst(jd, iptr, d);
2600 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2606 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2611 super = iptr->sx.s23.s3.c.cls;
2612 superindex = super->index;
2615 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2616 CODEGEN_CRITICAL_SECTION_NEW;
2618 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2619 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2622 M_MOV(REG_ITMP1, s1);
2626 /* if class is not resolved, check which code to call */
2628 if (super == NULL) {
2632 emit_label_beq(cd, BRANCH_LABEL_1);
2634 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2635 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2636 iptr->sx.s23.s3.c.ref, disp);
2638 M_DSEG_LOAD(REG_ITMP2, disp);
2639 disp = dseg_add_s4(cd, ACC_INTERFACE);
2640 M_DSEG_LOAD(REG_ITMP3, disp);
2641 M_TST(REG_ITMP2, REG_ITMP3);
2642 emit_label_beq(cd, BRANCH_LABEL_2);
2645 /* interface checkcast code */
2647 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2648 if ((super == NULL) || !IS_IMM(superindex)) {
2649 disp = dseg_add_unique_s4(cd, superindex);
2651 if (super == NULL) {
2652 /* If d == REG_ITMP2, then it's destroyed in check
2657 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2658 iptr->sx.s23.s3.c.ref, disp);
2663 emit_label_beq(cd, BRANCH_LABEL_3);
2666 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2667 M_LDR_INTERN(REG_ITMP3,
2668 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2670 /* we put unresolved or non-immediate superindices onto dseg
2671 and do things slightly different */
2672 if ((super == NULL) || !IS_IMM(superindex)) {
2673 /* disp was computed before we added the patcher */
2674 M_DSEG_LOAD(REG_ITMP2, disp);
2675 M_CMP(REG_ITMP3, REG_ITMP2);
2677 if (d == REG_ITMP2) {
2684 /* this assumes something */
2685 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2687 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2688 assert(sizeof(methodptr*) == 4);
2689 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2691 if (d == REG_ITMP2) {
2698 assert(IS_IMM(superindex));
2699 M_CMP_IMM(REG_ITMP3, superindex);
2703 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2704 superindex * sizeof(methodptr*);
2708 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2709 M_TST(REG_ITMP3, REG_ITMP3);
2713 emit_label_br(cd, BRANCH_LABEL_4);
2715 emit_label(cd, BRANCH_LABEL_3);
2718 /* class checkcast code */
2720 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2721 if (super == NULL) {
2722 emit_label(cd, BRANCH_LABEL_2);
2724 disp = dseg_add_unique_address(cd, NULL);
2726 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2727 iptr->sx.s23.s3.c.ref, disp);
2730 disp = dseg_add_address(cd, super->vftbl);
2734 emit_label_beq(cd, BRANCH_LABEL_5);
2737 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2738 M_DSEG_LOAD(REG_ITMP2, disp);
2740 CODEGEN_CRITICAL_SECTION_START;
2742 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2743 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2744 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2746 CODEGEN_CRITICAL_SECTION_END;
2748 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2749 M_CMP(REG_ITMP1, REG_ITMP2);
2750 /* If d == REG_ITMP2, then it's destroyed */
2756 emit_label(cd, BRANCH_LABEL_5);
2759 if (super == NULL) {
2760 emit_label(cd, BRANCH_LABEL_1);
2761 emit_label(cd, BRANCH_LABEL_4);
2766 emit_store_dst(jd, iptr, d);
2769 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2771 /* copy sizes to stack if necessary */
2773 MCODECHECK((iptr->s1.argcount << 1) + 64);
2775 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2777 var = VAR(iptr->sx.s23.s2.args[s1]);
2779 /* copy SAVEDVAR sizes to stack */
2781 if (!(var->flags & PREALLOC)) {
2782 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2783 M_STR(s2, REG_SP, s1 * 4);
2787 /* a0 = dimension count */
2789 assert(IS_IMM(iptr->s1.argcount));
2790 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2792 /* is patcher function set? */
2794 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2795 disp = dseg_add_unique_address(cd, NULL);
2797 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2798 iptr->sx.s23.s3.c.ref, disp);
2801 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2803 /* a1 = arraydescriptor */
2805 M_DSEG_LOAD(REG_A1, disp);
2807 /* a2 = pointer to dimensions = stack pointer */
2809 M_INTMOVE(REG_SP, REG_A2);
2811 /* call builtin_multianewarray here */
2813 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2814 M_DSEG_BRANCH(disp);
2818 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2821 /* check for exception before result assignment */
2823 emit_exception_check(cd, iptr);
2827 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2828 M_INTMOVE(REG_RESULT, d);
2829 emit_store_dst(jd, iptr, d);
2832 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2834 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2835 emit_nullpointer_check(cd, iptr, s1);
2839 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2842 } /* the big switch */
2844 } /* for all instructions */
2846 } /* for all basic blocks */
2848 dseg_createlinenumbertable(cd);
2851 /* generate traps */
2853 emit_patcher_traps(jd);
2855 /* everything's ok */
2861 /* codegen_emit_stub_compiler **************************************************
2863 Emits a stub routine which calls the compiler.
2865 *******************************************************************************/
2867 void codegen_emit_stub_compiler(jitdata *jd)
2872 /* get required compiler data */
2877 /* code for the stub */
2879 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2880 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2884 /* codegen_emit_stub_native ****************************************************
2886 Emits a stub routine which calls a native method.
2888 *******************************************************************************/
2890 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2898 s4 disp, funcdisp, s1, s2;
2900 /* get required compiler data */
2906 /* initialize variables */
2910 /* calculate stackframe size */
2912 cd->stackframesize =
2913 4 + /* return address */
2914 sizeof(stackframeinfo) + /* stackframeinfo */
2915 sizeof(localref_table) + /* localref_table */
2916 nmd->memuse * 4; /* stack arguments */
2918 /* align stack to 8-byte */
2920 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2922 /* create method header */
2924 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2925 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2926 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2927 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2928 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2929 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2930 (void) dseg_addlinenumbertablesize(cd);
2931 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2933 /* generate stub code */
2935 M_STMFD(1<<REG_LR, REG_SP);
2936 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2938 #if !defined(NDEBUG)
2939 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2940 emit_verbosecall_enter(jd);
2943 /* get function address (this must happen before the stackframeinfo) */
2945 funcdisp = dseg_add_functionptr(cd, f);
2948 patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
2950 #if defined(ENABLE_GC_CACAO)
2951 /* Save callee saved integer registers in stackframeinfo (GC may
2952 need to recover them during a collection). */
2954 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo) +
2955 OFFSET(stackframeinfo, intregs);
2957 for (i = 0; i < INT_SAV_CNT; i++)
2958 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2961 /* Save integer and float argument registers (these are 4
2962 registers, stack is 8-byte aligned). */
2964 M_STMFD(BITMASK_ARGS, REG_SP);
2965 /* TODO: floating point */
2967 /* create native stackframe info */
2969 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2970 M_MOV(REG_A1, REG_PV);
2971 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2972 M_DSEG_BRANCH(disp);
2976 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2979 /* remember class argument */
2981 if (m->flags & ACC_STATIC)
2982 M_MOV(REG_ITMP3, REG_RESULT);
2984 /* Restore integer and float argument registers (these are 4
2985 registers, stack is 8-byte aligned). */
2987 M_LDMFD(BITMASK_ARGS, REG_SP);
2988 /* TODO: floating point */
2990 /* copy or spill arguments to new locations */
2991 /* ATTENTION: the ARM has only integer argument registers! */
2993 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2994 t = md->paramtypes[i].type;
2996 if (!md->params[i].inmemory) {
2997 s1 = md->params[i].regoff;
2998 s2 = nmd->params[j].regoff;
3000 if (!nmd->params[j].inmemory) {
3001 #if !defined(__ARM_EABI__)
3002 SPLIT_OPEN(t, s2, REG_ITMP1);
3005 if (IS_2_WORD_TYPE(t))
3010 #if !defined(__ARM_EABI__)
3011 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3015 if (IS_2_WORD_TYPE(t))
3016 M_LST(s1, REG_SP, s2);
3018 M_IST(s1, REG_SP, s2);
3022 s1 = md->params[i].regoff + cd->stackframesize;
3023 s2 = nmd->params[j].regoff;
3025 if (IS_2_WORD_TYPE(t)) {
3026 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3027 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3030 M_ILD(REG_ITMP1, REG_SP, s1);
3031 M_IST(REG_ITMP1, REG_SP, s2);
3036 /* Handle native Java methods. */
3038 if (m->flags & ACC_NATIVE) {
3039 /* put class into second argument register */
3041 if (m->flags & ACC_STATIC)
3042 M_MOV(REG_A1, REG_ITMP3);
3044 /* put env into first argument register */
3046 disp = dseg_add_address(cd, _Jv_env);
3047 M_DSEG_LOAD(REG_A0, disp);
3050 /* do the native function call */
3052 M_DSEG_BRANCH(funcdisp);
3055 /* TODO: this is only needed because of the tracer ... do we
3058 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3061 #if !defined(__SOFTFP__)
3062 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3063 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3064 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3065 #if 0 && !defined(NDEBUG)
3066 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3068 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3069 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3070 if (IS_2_WORD_TYPE(md->returntype.type)) {
3071 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3072 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3074 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3075 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3080 #if !defined(NDEBUG)
3081 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3082 emit_verbosecall_exit(jd);
3085 /* remove native stackframe info */
3086 /* TODO: improve this store/load */
3088 M_STMFD(BITMASK_RESULT, REG_SP);
3090 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3091 M_MOV(REG_A1, REG_PV);
3092 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3093 M_DSEG_BRANCH(disp);
3094 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3097 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3098 M_LDMFD(BITMASK_RESULT, REG_SP);
3100 #if defined(ENABLE_GC_CACAO)
3101 /* restore callee saved int registers from stackframeinfo (GC might have */
3102 /* modified them during a collection). */
3104 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo) +
3105 OFFSET(stackframeinfo, intregs);
3107 for (i = 0; i < INT_SAV_CNT; i++)
3108 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3111 /* finish stub code, but do not yet return to caller */
3113 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3114 M_LDMFD(1<<REG_LR, REG_SP);
3116 /* check for exception */
3118 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3119 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3121 /* handle exception here */
3123 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3125 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3126 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3127 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3129 /* generate patcher stubs */
3131 emit_patcher_traps(jd);
3135 /* asm_debug *******************************************************************
3139 *******************************************************************************/
3141 void asm_debug(int a1, int a2, int a3, int a4)
3143 printf("===> i am going to exit after this debugging message!\n");
3144 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3145 vm_abort("leave you now");
3150 * These are local overrides for various environment variables in Emacs.
3151 * Please do not remove this and leave it at the end of the file, where
3152 * Emacs will automagically detect them.
3153 * ---------------------------------------------------------------------
3156 * indent-tabs-mode: t
3160 * vim:noexpandtab:sw=4:ts=4: