1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "vm/jit/arm/arch.h"
36 #include "vm/jit/arm/codegen.h"
38 #include "mm/memory.h"
40 #include "native/localref.h"
41 #include "native/native.h"
43 #include "threads/lock-common.h"
45 #include "vm/builtin.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
50 #include "vm/jit/abi.h"
51 #include "vm/jit/asmpart.h"
52 #include "vm/jit/codegen-common.h"
53 #include "vm/jit/dseg.h"
54 #include "vm/jit/emit-common.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/linenumbertable.h"
57 #include "vm/jit/methodheader.h"
58 #include "vm/jit/parse.h"
59 #include "vm/jit/patcher-common.h"
60 #include "vm/jit/reg.h"
62 #if defined(ENABLE_LSRA)
63 #include "vm/jit/allocator/lsra.h"
66 #include "vmcore/loader.h"
67 #include "vmcore/options.h"
70 /* codegen_emit ****************************************************************
72 Generates machine code.
74 *******************************************************************************/
76 bool codegen_emit(jitdata *jd)
94 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
95 unresolved_method *um;
96 builtintable_entry *bte;
103 /* get required compiler data */
110 /* prevent compiler warnings */
118 /* space to save used callee saved registers */
120 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
122 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
123 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
124 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
126 spilledregs_num = rd->memuse;
128 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
129 if (checksync && code_is_synchronized(code))
133 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
135 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
136 only in native stubs. */
137 /* align stack to 8-byte */
139 cd->stackframesize = (cd->stackframesize + 4) & ~4;
141 /* SECTION: Method Header */
142 /* create method header */
144 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
145 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
147 code->synchronizedoffset = rd->memuse * 8;
149 /* REMOVEME: We still need it for exception handling in assembler. */
151 if (code_is_leafmethod(code))
152 (void) dseg_add_unique_s4(cd, 1);
154 (void) dseg_add_unique_s4(cd, 0);
156 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
157 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
159 /* save return address and used callee saved registers */
161 savedregs_bitmask = 0;
163 if (!code_is_leafmethod(code))
164 savedregs_bitmask = (1<<REG_LR);
166 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
167 savedregs_bitmask |= (1<<(rd->savintregs[i]));
170 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
171 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
172 /* TODO: floating-point */
176 if (savedregs_bitmask)
177 M_STMFD(savedregs_bitmask, REG_SP);
179 /* create additional stack frame for spilled variables (if necessary) */
181 if ((cd->stackframesize / 4 - savedregs_num) > 0)
182 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
184 /* take arguments out of register or stack frame */
187 for (i = 0, len = 0; i < md->paramcount; i++) {
188 s1 = md->params[i].regoff;
189 t = md->paramtypes[i].type;
191 varindex = jd->local_map[len * 5 + t];
193 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
195 if (varindex == UNUSED)
200 /* ATTENTION: we use interger registers for all arguments (even float) */
201 #if !defined(ENABLE_SOFTFLOAT)
202 if (IS_INT_LNG_TYPE(t)) {
204 if (!md->params[i].inmemory) {
205 if (!(var->flags & INMEMORY)) {
206 if (IS_2_WORD_TYPE(t))
207 M_LNGMOVE(s1, var->vv.regoff);
209 M_INTMOVE(s1, var->vv.regoff);
212 if (IS_2_WORD_TYPE(t))
213 M_LST(s1, REG_SP, var->vv.regoff);
215 M_IST(s1, REG_SP, var->vv.regoff);
218 else { /* stack arguments */
219 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
220 if (IS_2_WORD_TYPE(t))
221 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
223 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
225 else { /* stack arg -> spilled */
226 /* Reuse Memory Position on Caller Stack */
227 var->vv.regoff = cd->stackframesize + s1;
230 #if !defined(ENABLE_SOFTFLOAT)
233 if (!md->params[i].inmemory) {
234 if (!(var->flags & INMEMORY)) {
235 if (IS_2_WORD_TYPE(t))
236 M_CAST_L2D(s1, var->vv.regoff);
238 M_CAST_I2F(s1, var->vv.regoff);
241 if (IS_2_WORD_TYPE(t))
242 M_LST(s1, REG_SP, var->vv.regoff);
244 M_IST(s1, REG_SP, var->vv.regoff);
248 if (!(var->flags & INMEMORY)) {
249 if (IS_2_WORD_TYPE(t))
250 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
252 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
255 /* Reuse Memory Position on Caller Stack */
256 var->vv.regoff = cd->stackframesize + s1;
260 #endif /* !defined(ENABLE_SOFTFLOAT) */
263 #if defined(ENABLE_THREADS)
264 /* call monitorenter function */
266 if (checksync && code_is_synchronized(code)) {
267 /* stack offset for monitor argument */
271 # if !defined(NDEBUG)
272 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
273 M_STMFD(BITMASK_ARGS, REG_SP);
278 /* get the correct lock object */
280 if (m->flags & ACC_STATIC) {
281 disp = dseg_add_address(cd, &m->clazz->object.header);
282 M_DSEG_LOAD(REG_A0, disp);
285 emit_nullpointer_check_force(cd, iptr, REG_A0);
288 M_STR(REG_A0, REG_SP, s1);
289 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
291 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
294 # if !defined(NDEBUG)
295 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
296 M_LDMFD(BITMASK_ARGS, REG_SP);
302 /* call trace function */
304 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
305 emit_verbosecall_enter(jd);
308 /* end of header generation */
310 /* create replacement points */
311 REPLACEMENT_POINTS_INIT(cd, jd);
313 /* SECTION: ICMD Code Generation */
314 /* for all basic blocks */
316 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
318 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
320 /* is this basic block reached? */
322 if (bptr->flags < BBREACHED)
325 /* branch resolving */
327 codegen_resolve_branchrefs(cd, bptr);
329 /* handle replacement points */
330 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
332 /* copy interface registers to their destination */
338 #if defined(ENABLE_LSRA)
342 var = VAR(bptr->invars[len]);
343 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
344 if (!(var->flags & INMEMORY))
348 M_INTMOVE(REG_ITMP1, d);
349 emit_store(jd, NULL, var, d);
356 var = VAR(bptr->invars[len]);
358 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
359 d = codegen_reg_of_var(0, var, REG_ITMP1);
360 M_INTMOVE(REG_ITMP1, d);
361 emit_store(jd, NULL, var, d);
364 assert((var->flags & INOUT));
367 #if defined(ENABLE_LSRA)
371 /* for all instructions */
374 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
376 /* add line number */
377 if (iptr->line != currentline) {
378 linenumbertable_list_entry_add(cd, iptr->line);
379 currentline = iptr->line;
382 MCODECHECK(64); /* an instruction usually needs < 64 words */
387 case ICMD_NOP: /* ... ==> ... */
388 case ICMD_POP: /* ..., value ==> ... */
389 case ICMD_POP2: /* ..., value, value ==> ... */
392 /* constant operations ************************************************/
394 case ICMD_ICONST: /* ... ==> ..., constant */
396 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
397 ICONST(d, iptr->sx.val.i);
398 emit_store_dst(jd, iptr, d);
401 case ICMD_ACONST: /* ... ==> ..., constant */
403 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
404 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
405 disp = dseg_add_unique_address(cd, NULL);
407 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
408 iptr->sx.val.c.ref, disp);
410 M_DSEG_LOAD(d, disp);
413 ICONST(d, (u4) iptr->sx.val.anyptr);
415 emit_store_dst(jd, iptr, d);
418 case ICMD_LCONST: /* ... ==> ..., constant */
420 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
421 LCONST(d, iptr->sx.val.l);
422 emit_store_dst(jd, iptr, d);
425 case ICMD_FCONST: /* ... ==> ..., constant */
427 #if defined(ENABLE_SOFTFLOAT)
428 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
429 ICONST(d, iptr->sx.val.i);
430 emit_store_dst(jd, iptr, d);
432 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
433 FCONST(d, iptr->sx.val.f);
434 emit_store_dst(jd, iptr, d);
438 case ICMD_DCONST: /* ... ==> ..., constant */
440 #if defined(ENABLE_SOFTFLOAT)
441 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
442 LCONST(d, iptr->sx.val.l);
443 emit_store_dst(jd, iptr, d);
445 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
446 DCONST(d, iptr->sx.val.d);
447 emit_store_dst(jd, iptr, d);
452 /* load/store/copy/move operations ************************************/
454 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
455 case ICMD_ALOAD: /* op1 = local variable */
459 case ICMD_ISTORE: /* ..., value ==> ... */
471 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
476 /* integer operations *************************************************/
478 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
480 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
481 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
482 M_MOV(d, REG_LSL(s1, 24));
483 M_MOV(d, REG_ASR(d, 24));
484 emit_store_dst(jd, iptr, d);
487 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
489 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
490 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
491 M_MOV(d, REG_LSL(s1, 16));
492 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
493 emit_store_dst(jd, iptr, d);
496 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
498 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
499 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
500 M_MOV(d, REG_LSL(s1, 16));
501 M_MOV(d, REG_ASR(d, 16));
502 emit_store_dst(jd, iptr, d);
505 case ICMD_I2L: /* ..., value ==> ..., value */
507 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
508 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
509 M_INTMOVE(s1, GET_LOW_REG(d));
510 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
511 emit_store_dst(jd, iptr, d);
514 case ICMD_L2I: /* ..., value ==> ..., value */
516 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
517 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
519 emit_store_dst(jd, iptr, d);
522 case ICMD_INEG: /* ..., value ==> ..., - value */
524 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
525 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
527 emit_store_dst(jd, iptr, d);
530 case ICMD_LNEG: /* ..., value ==> ..., - value */
532 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
533 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
534 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
535 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
536 emit_store_dst(jd, iptr, d);
539 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
541 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
542 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
543 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
545 emit_store_dst(jd, iptr, d);
548 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
550 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
551 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
552 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
553 M_ADD_S(GET_LOW_REG(d), s1, s2);
554 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
555 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
556 M_ADC(GET_HIGH_REG(d), s1, s2);
557 emit_store_dst(jd, iptr, d);
563 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
564 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
566 if (IS_IMM(iptr->sx.val.i)) {
567 M_ADD_IMM(d, s1, iptr->sx.val.i);
568 } else if (IS_IMM(-iptr->sx.val.i)) {
569 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
571 ICONST(REG_ITMP3, iptr->sx.val.i);
572 M_ADD(d, s1, REG_ITMP3);
575 emit_store_dst(jd, iptr, d);
578 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
579 /* sx.val.l = constant */
581 s3 = iptr->sx.val.l & 0xffffffff;
582 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
583 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
585 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
587 ICONST(REG_ITMP3, s3);
588 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
590 s3 = iptr->sx.val.l >> 32;
591 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
593 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
595 ICONST(REG_ITMP3, s3);
596 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
598 emit_store_dst(jd, iptr, d);
601 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
603 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
604 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
605 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
607 emit_store_dst(jd, iptr, d);
610 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
612 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
613 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
614 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
615 M_SUB_S(GET_LOW_REG(d), s1, s2);
616 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
617 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
618 M_SBC(GET_HIGH_REG(d), s1, s2);
619 emit_store_dst(jd, iptr, d);
622 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
623 /* sx.val.i = constant */
625 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
626 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
627 if (IS_IMM(iptr->sx.val.i))
628 M_SUB_IMM(d, s1, iptr->sx.val.i);
630 ICONST(REG_ITMP3, iptr->sx.val.i);
631 M_SUB(d, s1, REG_ITMP3);
633 emit_store_dst(jd, iptr, d);
636 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
637 /* sx.val.l = constant */
639 s3 = iptr->sx.val.l & 0xffffffff;
640 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
641 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
643 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
645 ICONST(REG_ITMP3, s3);
646 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
648 s3 = iptr->sx.val.l >> 32;
649 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
651 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
653 ICONST(REG_ITMP3, s3);
654 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
656 emit_store_dst(jd, iptr, d);
659 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
661 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
662 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
663 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
665 emit_store_dst(jd, iptr, d);
668 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
669 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
671 s1 = emit_load_s1(jd, iptr, REG_A0);
672 s2 = emit_load_s2(jd, iptr, REG_A1);
673 emit_arithmetic_check(cd, iptr, s2);
675 /* move arguments into argument registers */
676 M_INTMOVE(s1, REG_A0);
677 M_INTMOVE(s2, REG_A1);
679 /* call builtin function */
680 bte = iptr->sx.s23.s3.bte;
681 disp = dseg_add_functionptr(cd, bte->fp);
685 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
688 /* move result into destination register */
689 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
690 M_INTMOVE(REG_RESULT, d);
691 emit_store_dst(jd, iptr, d);
694 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
695 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
697 /* move arguments into argument registers */
699 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
700 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
701 /* XXX TODO: only do this if arithmetic check is really done! */
702 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
703 emit_arithmetic_check(cd, iptr, REG_ITMP3);
705 M_LNGMOVE(s1, REG_A0_A1_PACKED);
706 M_LNGMOVE(s2, REG_A2_A3_PACKED);
708 /* call builtin function */
709 bte = iptr->sx.s23.s3.bte;
710 disp = dseg_add_functionptr(cd, bte->fp);
714 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
717 /* move result into destination register */
718 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
719 M_LNGMOVE(REG_RESULT_PACKED, d);
720 emit_store_dst(jd, iptr, d);
723 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
724 /* sx.val.i = constant */
726 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
727 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
728 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
729 emit_store_dst(jd, iptr, d);
732 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
733 /* sx.val.i = constant */
735 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
736 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
737 /* this rounds towards 0 as java likes it */
738 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
739 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
740 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
741 /* this rounds towards nearest, not java style */
742 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
743 M_ADCMI_IMM(d, d, 0);*/
744 emit_store_dst(jd, iptr, d);
747 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
748 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
750 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
751 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
752 M_MOV_S(REG_ITMP1, s1);
753 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
754 if (IS_IMM(iptr->sx.val.i))
755 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
757 ICONST(REG_ITMP3, iptr->sx.val.i);
758 M_AND(REG_ITMP1, REG_ITMP3, d);
760 M_RSBMI_IMM(d, d, 0);
761 emit_store_dst(jd, iptr, d);
764 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
766 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
767 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
768 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
769 M_AND_IMM(s2, 0x1f, REG_ITMP2);
770 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
771 emit_store_dst(jd, iptr, d);
774 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
776 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
777 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
778 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
779 M_AND_IMM(s2, 0x1f, REG_ITMP2);
780 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
781 emit_store_dst(jd, iptr, d);
784 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
786 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
787 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
788 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
789 M_AND_IMM(s2, 0x1f, REG_ITMP2);
790 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
791 emit_store_dst(jd, iptr, d);
794 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
795 /* sx.val.i = constant */
797 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
798 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
799 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
800 emit_store_dst(jd, iptr, d);
803 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
804 /* sx.val.i = constant */
806 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
807 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
808 /* we need to check for zero here because arm interprets it as SHR by 32 */
809 if ((iptr->sx.val.i & 0x1f) == 0) {
812 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
814 emit_store_dst(jd, iptr, d);
817 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
818 /* sx.val.i = constant */
820 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
821 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
822 /* we need to check for zero here because arm interprets it as SHR by 32 */
823 if ((iptr->sx.val.i & 0x1f) == 0)
826 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
827 emit_store_dst(jd, iptr, d);
830 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
832 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
833 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
834 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
836 emit_store_dst(jd, iptr, d);
839 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
841 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
842 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
843 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
844 M_AND(s1, s2, GET_LOW_REG(d));
845 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
846 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
847 M_AND(s1, s2, GET_HIGH_REG(d));
848 emit_store_dst(jd, iptr, d);
851 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
853 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
854 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
855 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
857 emit_store_dst(jd, iptr, d);
860 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
862 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
863 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
864 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
865 M_ORR(s1, s2, GET_LOW_REG(d));
866 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
867 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
868 M_ORR(s1, s2, GET_HIGH_REG(d));
869 emit_store_dst(jd, iptr, d);
872 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
874 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
875 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
876 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
878 emit_store_dst(jd, iptr, d);
881 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
883 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
884 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
885 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
886 M_EOR(s1, s2, GET_LOW_REG(d));
887 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
888 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
889 M_EOR(s1, s2, GET_HIGH_REG(d));
890 emit_store_dst(jd, iptr, d);
894 /* floating operations ************************************************/
896 #if !defined(ENABLE_SOFTFLOAT)
898 case ICMD_FNEG: /* ..., value ==> ..., - value */
900 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
901 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
903 emit_store_dst(jd, iptr, d);
906 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
908 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
909 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
910 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
912 emit_store_dst(jd, iptr, d);
915 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
917 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
918 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
919 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
921 emit_store_dst(jd, iptr, d);
924 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
926 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
927 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
928 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
930 emit_store_dst(jd, iptr, d);
933 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
934 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
935 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
936 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
938 emit_store_dst(jd, iptr, d);
941 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
945 case ICMD_FREM: /* ..., 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);
955 case ICMD_DNEG: /* ..., value ==> ..., - value */
957 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
958 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
960 emit_store_dst(jd, iptr, d);
963 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
965 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
966 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
967 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
969 emit_store_dst(jd, iptr, d);
972 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
974 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
975 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
976 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
978 emit_store_dst(jd, iptr, d);
981 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
983 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
984 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
985 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
987 emit_store_dst(jd, iptr, d);
990 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
992 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
993 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
994 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
996 emit_store_dst(jd, iptr, d);
999 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1003 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1005 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1006 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1007 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1009 emit_store_dst(jd, iptr, d);
1013 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1015 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1016 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1018 emit_store_dst(jd, iptr, d);
1021 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1023 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1024 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1026 emit_store_dst(jd, iptr, d);
1029 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1031 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1032 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1033 /* this uses round towards zero, as Java likes it */
1035 #if !defined(__VFP_FP__)
1036 /* this checks for NaN; to return zero as Java likes it */
1040 emit_store_dst(jd, iptr, d);
1043 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1045 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1046 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1047 /* this uses round towards zero, as Java likes it */
1049 #if !defined(__VFP_FP__)
1050 /* this checks for NaN; to return zero as Java likes it */
1054 emit_store_dst(jd, iptr, d);
1057 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1059 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1060 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1062 emit_store_dst(jd, iptr, d);
1065 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1067 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1068 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1070 emit_store_dst(jd, iptr, d);
1073 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1075 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1076 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1077 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1080 #if defined(__VFP_FP__)
1081 M_FMSTAT; /* on VFP we need to transfer the flags */
1083 M_SUBGT_IMM(d, d, 1);
1084 M_ADDLT_IMM(d, d, 1);
1085 emit_store_dst(jd, iptr, d);
1088 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1090 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1091 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1092 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1095 #if defined(__VFP_FP__)
1096 M_FMSTAT; /* on VFP we need to transfer the flags */
1098 M_SUBGT_IMM(d, d, 1);
1099 M_ADDLT_IMM(d, d, 1);
1100 emit_store_dst(jd, iptr, d);
1103 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl 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_SUBLT_IMM(d, d, 1);
1114 M_ADDGT_IMM(d, d, 1);
1115 emit_store_dst(jd, iptr, d);
1118 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl 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_SUBLT_IMM(d, d, 1);
1129 M_ADDGT_IMM(d, d, 1);
1130 emit_store_dst(jd, iptr, d);
1133 #endif /* !defined(ENABLE_SOFTFLOAT) */
1136 /* memory operations **************************************************/
1138 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1140 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1141 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1142 /* implicit null-pointer check */
1143 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1144 emit_store_dst(jd, iptr, d);
1147 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1149 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1150 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1151 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1152 /* implicit null-pointer check */
1153 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1154 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1155 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1156 emit_store_dst(jd, iptr, d);
1159 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1161 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1162 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1163 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1164 /* implicit null-pointer check */
1165 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1166 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1167 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1168 emit_store_dst(jd, iptr, d);
1171 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1173 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1174 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1175 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1176 /* implicit null-pointer check */
1177 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1178 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1179 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1180 emit_store_dst(jd, iptr, d);
1183 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1185 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1186 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1187 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1188 /* implicit null-pointer check */
1189 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1190 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1191 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1192 emit_store_dst(jd, iptr, d);
1195 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1197 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1198 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1199 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1200 /* implicit null-pointer check */
1201 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1202 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1203 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1204 emit_store_dst(jd, iptr, d);
1207 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1209 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1210 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1211 /* implicit null-pointer check */
1212 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1213 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1214 #if !defined(ENABLE_SOFTFLOAT)
1215 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1216 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1218 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1219 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1221 emit_store_dst(jd, iptr, d);
1224 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1226 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1227 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1228 /* implicit null-pointer check */
1229 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1230 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1231 #if !defined(ENABLE_SOFTFLOAT)
1232 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1233 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1235 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1236 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1238 emit_store_dst(jd, iptr, d);
1241 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1243 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1244 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1245 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1246 /* implicit null-pointer check */
1247 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1248 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1249 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1250 emit_store_dst(jd, iptr, d);
1253 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1255 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1256 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1257 /* implicit null-pointer check */
1258 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1259 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1260 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1261 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1264 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1266 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1267 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1268 /* implicit null-pointer check */
1269 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1270 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1271 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1272 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1275 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1277 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1278 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1279 /* implicit null-pointer check */
1280 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1281 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1282 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1283 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1286 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1288 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1289 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1290 /* implicit null-pointer check */
1291 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1292 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1293 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1294 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1297 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1299 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1300 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1301 /* implicit null-pointer check */
1302 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1303 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1304 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1305 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1308 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1310 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1311 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1312 /* implicit null-pointer check */
1313 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1314 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1315 #if !defined(ENABLE_SOFTFLOAT)
1316 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1317 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1319 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1320 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1324 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1326 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1327 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1328 /* implicit null-pointer check */
1329 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1330 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1331 #if !defined(ENABLE_SOFTFLOAT)
1332 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1333 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1335 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1336 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1340 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1342 s1 = emit_load_s1(jd, iptr, REG_A0);
1343 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1344 s3 = emit_load_s3(jd, iptr, REG_A1);
1346 /* implicit null-pointer check */
1347 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1349 /* move arguments to argument registers */
1350 M_INTMOVE(s1, REG_A0);
1351 M_INTMOVE(s3, REG_A1);
1353 /* call builtin function */
1354 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1355 M_DSEG_BRANCH(disp);
1358 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1361 /* check resturn value of builtin */
1362 emit_arraystore_check(cd, iptr);
1364 /* finally store address into array */
1365 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1366 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1367 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1368 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1369 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1372 case ICMD_GETSTATIC: /* ... ==> ..., value */
1374 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1375 uf = iptr->sx.s23.s3.uf;
1376 fieldtype = uf->fieldref->parseddesc.fd->type;
1377 disp = dseg_add_unique_address(cd, NULL);
1379 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1382 fi = iptr->sx.s23.s3.fmiref->p.field;
1383 fieldtype = fi->type;
1384 disp = dseg_add_address(cd, fi->value);
1386 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1387 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1392 M_DSEG_LOAD(REG_ITMP3, disp);
1393 switch (fieldtype) {
1395 #if defined(ENABLE_SOFTFLOAT)
1399 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1400 M_ILD_INTERN(d, REG_ITMP3, 0);
1403 #if defined(ENABLE_SOFTFLOAT)
1406 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1407 M_LLD_INTERN(d, REG_ITMP3, 0);
1409 #if !defined(ENABLE_SOFTFLOAT)
1411 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1412 M_FLD_INTERN(d, REG_ITMP3, 0);
1415 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1416 M_DLD_INTERN(d, REG_ITMP3, 0);
1422 emit_store_dst(jd, iptr, d);
1425 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1427 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1428 uf = iptr->sx.s23.s3.uf;
1429 fieldtype = uf->fieldref->parseddesc.fd->type;
1430 disp = dseg_add_unique_address(cd, NULL);
1432 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1435 fi = iptr->sx.s23.s3.fmiref->p.field;
1436 fieldtype = fi->type;
1437 disp = dseg_add_address(cd, fi->value);
1439 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1440 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1445 M_DSEG_LOAD(REG_ITMP3, disp);
1446 switch (fieldtype) {
1448 #if defined(ENABLE_SOFTFLOAT)
1452 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1453 M_IST_INTERN(s1, REG_ITMP3, 0);
1456 #if defined(ENABLE_SOFTFLOAT)
1459 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1460 M_LST_INTERN(s1, REG_ITMP3, 0);
1462 #if !defined(ENABLE_SOFTFLOAT)
1464 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1465 M_FST_INTERN(s1, REG_ITMP3, 0);
1468 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1469 M_DST_INTERN(s1, REG_ITMP3, 0);
1477 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1479 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1480 emit_nullpointer_check(cd, iptr, s1);
1483 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1484 uf = iptr->sx.s23.s3.uf;
1485 fieldtype = uf->fieldref->parseddesc.fd->type;
1489 fi = iptr->sx.s23.s3.fmiref->p.field;
1490 fieldtype = fi->type;
1494 #if !defined(ENABLE_SOFTFLOAT)
1495 /* HACK: softnull checks on floats */
1496 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1497 emit_nullpointer_check_force(cd, iptr, s1);
1500 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1502 uf = iptr->sx.s23.s3.uf;
1504 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1507 switch (fieldtype) {
1509 #if defined(ENABLE_SOFTFLOAT)
1513 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1517 #if defined(ENABLE_SOFTFLOAT)
1520 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1523 #if !defined(ENABLE_SOFTFLOAT)
1525 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1529 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1536 emit_store_dst(jd, iptr, d);
1539 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1541 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1542 emit_nullpointer_check(cd, iptr, s1);
1544 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1545 uf = iptr->sx.s23.s3.uf;
1546 fieldtype = uf->fieldref->parseddesc.fd->type;
1550 fi = iptr->sx.s23.s3.fmiref->p.field;
1551 fieldtype = fi->type;
1555 #if !defined(ENABLE_SOFTFLOAT)
1556 /* HACK: softnull checks on floats */
1557 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1558 emit_nullpointer_check_force(cd, iptr, s1);
1561 switch (fieldtype) {
1563 #if defined(ENABLE_SOFTFLOAT)
1567 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1569 #if defined(ENABLE_SOFTFLOAT)
1570 case TYPE_DBL: /* fall through */
1573 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1575 #if !defined(ENABLE_SOFTFLOAT)
1578 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1585 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1587 uf = iptr->sx.s23.s3.uf;
1589 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1592 switch (fieldtype) {
1594 #if defined(ENABLE_SOFTFLOAT)
1598 M_IST(s2, s1, disp);
1601 #if defined(ENABLE_SOFTFLOAT)
1604 M_LST(s2, s1, disp);
1606 #if !defined(ENABLE_SOFTFLOAT)
1608 M_FST(s2, s1, disp);
1611 M_DST(s2, s1, disp);
1620 /* branch operations **************************************************/
1622 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1624 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1625 M_INTMOVE(s1, REG_ITMP1_XPTR);
1626 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1627 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1628 iptr->sx.s23.s2.uc, 0);
1630 disp = dseg_add_functionptr(cd, asm_handle_exception);
1631 M_DSEG_LOAD(REG_ITMP3, disp);
1632 M_MOV(REG_ITMP2_XPC, REG_PC);
1633 M_MOV(REG_PC, REG_ITMP3);
1634 M_NOP; /* nop ensures that XPC is less than the end */
1635 /* of basic block */
1638 case ICMD_GOTO: /* ... ==> ... */
1641 emit_br(cd, iptr->dst.block);
1644 case ICMD_JSR: /* ... ==> ... */
1646 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1649 case ICMD_IFNULL: /* ..., value ==> ... */
1650 case ICMD_IFNONNULL:
1652 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1654 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1657 case ICMD_IFLT: /* ..., value ==> ... */
1658 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1664 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1665 M_COMPARE(s1, iptr->sx.val.i);
1666 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1669 case ICMD_IF_LEQ: /* ..., value ==> ... */
1671 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1672 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1673 if (iptr->sx.val.l == 0) {
1674 M_ORR_S(s1, s2, REG_ITMP3);
1677 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1678 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1679 M_CMP(s1, REG_ITMP3);*/
1680 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1681 M_CMPEQ(s2, REG_ITMP3);
1683 emit_beq(cd, iptr->dst.block);
1686 case ICMD_IF_LLT: /* ..., value ==> ... */
1688 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1689 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1690 if (iptr->sx.val.l == 0) {
1691 /* if high word is less than zero, the whole long is too */
1693 emit_blt(cd, iptr->dst.block);
1696 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1697 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1698 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1699 M_CMP(s1, REG_ITMP3);*/
1700 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1701 M_MOVGT_IMM(2, REG_ITMP1);
1702 M_MOVEQ_IMM(1, REG_ITMP1);
1704 /* low compare: x=x-1(ifLO) */
1705 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1706 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1707 M_CMP(s2, REG_ITMP3);*/
1708 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1710 /* branch if (x LT 1) */
1711 M_CMP_IMM(REG_ITMP1, 1);
1712 emit_blt(cd, iptr->dst.block);
1716 case ICMD_IF_LLE: /* ..., value ==> ... */
1718 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1719 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1720 if (iptr->sx.val.l == 0) {
1721 /* if high word is less than zero, the whole long is too */
1723 emit_blt(cd, iptr->dst.block);
1725 /* ... otherwise the low word has to be zero (tricky!) */
1727 emit_beq(cd, iptr->dst.block);
1730 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1731 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1732 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1733 M_CMP(s1, REG_ITMP3);*/
1734 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1735 M_MOVGT_IMM(2, REG_ITMP1);
1736 M_MOVEQ_IMM(1, REG_ITMP1);
1738 /* low compare: x=x+1(ifHI) */
1739 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1740 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1741 M_CMP(s2, REG_ITMP3);*/
1742 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1744 /* branch if (x LE 1) */
1745 M_CMP_IMM(REG_ITMP1, 1);
1746 emit_ble(cd, iptr->dst.block);
1750 case ICMD_IF_LGE: /* ..., value ==> ... */
1752 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1753 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1754 if (iptr->sx.val.l == 0) {
1755 /* if high word is greater or equal zero, the whole long is too */
1757 emit_bge(cd, iptr->dst.block);
1760 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1761 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1762 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1763 M_CMP(s1, REG_ITMP3);*/
1764 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1765 M_MOVGT_IMM(2, REG_ITMP1);
1766 M_MOVEQ_IMM(1, REG_ITMP1);
1768 /* low compare: x=x-1(ifLO) */
1769 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1770 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1771 M_CMP(s2, REG_ITMP3);*/
1772 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1774 /* branch if (x GE 1) */
1775 M_CMP_IMM(REG_ITMP1, 1);
1776 emit_bge(cd, iptr->dst.block);
1780 case ICMD_IF_LGT: /* ..., value ==> ... */
1782 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1783 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1785 if (iptr->sx.val.l == 0) {
1786 /* if high word is greater than zero, the whole long is too */
1789 codegen_add_branch_ref(cd, iptr->dst.block);
1791 /* ... or high was zero and low is non zero (tricky!) */
1792 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1793 M_MOVLT_IMM(1, REG_ITMP3);
1794 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1796 codegen_add_branch_ref(cd, iptr->dst.block);
1800 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1801 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1802 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1803 M_CMP(s1, REG_ITMP3);*/
1804 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1805 M_MOVGT_IMM(2, REG_ITMP1);
1806 M_MOVEQ_IMM(1, REG_ITMP1);
1808 /* low compare: x=x+1(ifHI) */
1809 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1810 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1811 M_CMP(s2, REG_ITMP3);*/
1812 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1814 /* branch if (x GT 1) */
1815 M_CMP_IMM(REG_ITMP1, 1);
1816 emit_bgt(cd, iptr->dst.block);
1822 case ICMD_IF_LNE: /* ..., value ==> ... */
1824 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1825 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1826 if (iptr->sx.val.l == 0) {
1827 M_ORR_S(s1, s2, REG_ITMP3);
1830 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1831 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1832 M_CMP(s1, REG_ITMP3);*/
1833 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1834 M_CMPEQ(s2, REG_ITMP3);
1836 emit_bne(cd, iptr->dst.block);
1839 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1840 case ICMD_IF_ICMPNE:
1841 case ICMD_IF_ICMPLT:
1842 case ICMD_IF_ICMPLE:
1843 case ICMD_IF_ICMPGT:
1844 case ICMD_IF_ICMPGE:
1846 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1847 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1849 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1852 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1853 case ICMD_IF_ACMPNE:
1855 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1856 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1858 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1861 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1862 /* op1 = target JavaVM pc */
1864 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1865 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1868 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1869 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1872 emit_beq(cd, iptr->dst.block);
1875 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1876 /* op1 = target JavaVM pc */
1878 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1879 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1882 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1883 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1886 emit_bne(cd, iptr->dst.block);
1889 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1890 /* op1 = target JavaVM pc */
1892 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1893 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1894 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1896 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1897 M_MOVGT_IMM(2, REG_ITMP3);
1898 M_MOVEQ_IMM(1, REG_ITMP3);
1900 /* low compare: x=x-1(ifLO) */
1901 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1902 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1904 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1906 /* branch if (x LT 1) */
1907 M_CMP_IMM(REG_ITMP3, 1);
1908 emit_blt(cd, iptr->dst.block);
1911 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1912 /* op1 = target JavaVM pc */
1914 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1915 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1916 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1918 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1919 M_MOVGT_IMM(2, REG_ITMP3);
1920 M_MOVEQ_IMM(1, REG_ITMP3);
1922 /* low compare: x=x-1(ifLO) */
1923 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1924 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1926 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1928 /* branch if (x LE 1) */
1929 M_CMP_IMM(REG_ITMP3, 1);
1930 emit_ble(cd, iptr->dst.block);
1933 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1934 /* op1 = target JavaVM pc */
1936 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1937 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1938 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1940 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1941 M_MOVGT_IMM(2, REG_ITMP3);
1942 M_MOVEQ_IMM(1, REG_ITMP3);
1944 /* low compare: x=x-1(ifLO) */
1945 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1946 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1948 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1950 /* branch if (x GT 1) */
1951 M_CMP_IMM(REG_ITMP3, 1);
1952 emit_bgt(cd, iptr->dst.block);
1955 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1956 /* op1 = target JavaVM pc */
1958 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1959 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1960 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1962 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1963 M_MOVGT_IMM(2, REG_ITMP3);
1964 M_MOVEQ_IMM(1, REG_ITMP3);
1966 /* low compare: x=x-1(ifLO) */
1967 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1968 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1970 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1972 /* branch if (x GE 1) */
1973 M_CMP_IMM(REG_ITMP3, 1);
1974 emit_bge(cd, iptr->dst.block);
1977 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1980 branch_target_t *table;
1982 table = iptr->dst.table;
1984 l = iptr->sx.s23.s2.tablelow;
1985 i = iptr->sx.s23.s3.tablehigh;
1987 /* calculate new index (index - low) */
1988 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1990 M_INTMOVE(s1, REG_ITMP1);
1991 } else if (IS_IMM(l)) {
1992 M_SUB_IMM(REG_ITMP1, s1, l);
1994 ICONST(REG_ITMP2, l);
1995 M_SUB(REG_ITMP1, s1, REG_ITMP2);
1998 /* range check (index <= high-low) */
2000 M_COMPARE(REG_ITMP1, i-1);
2001 emit_bugt(cd, table[0].block);
2003 /* build jump table top down and use address of lowest entry */
2008 dseg_add_target(cd, table->block);
2013 /* length of dataseg after last dseg_add_target is used by load */
2014 /* TODO: this loads from data-segment */
2015 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2016 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2019 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2022 lookup_target_t *lookup;
2024 lookup = iptr->dst.lookup;
2026 i = iptr->sx.s23.s2.lookupcount;
2029 MCODECHECK((i<<2)+8);
2030 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2033 M_COMPARE(s1, lookup->value);
2034 emit_beq(cd, lookup->target.block);
2038 /* default branch */
2039 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2043 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2045 #if !defined(ENABLE_SOFTFLOAT)
2046 REPLACEMENT_POINT_RETURN(cd, iptr);
2047 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2048 M_CAST_F2I(s1, REG_RESULT);
2049 goto ICMD_RETURN_do;
2052 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2054 REPLACEMENT_POINT_RETURN(cd, iptr);
2055 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2056 M_INTMOVE(s1, REG_RESULT);
2057 goto ICMD_RETURN_do;
2059 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2061 #if !defined(ENABLE_SOFTFLOAT)
2062 REPLACEMENT_POINT_RETURN(cd, iptr);
2063 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2064 M_CAST_D2L(s1, REG_RESULT_PACKED);
2065 goto ICMD_RETURN_do;
2068 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2070 REPLACEMENT_POINT_RETURN(cd, iptr);
2071 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2072 M_LNGMOVE(s1, REG_RESULT_PACKED);
2073 goto ICMD_RETURN_do;
2075 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2077 REPLACEMENT_POINT_RETURN(cd, iptr);
2078 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2079 M_INTMOVE(s1, REG_RESULT);
2080 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2081 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2082 iptr->sx.s23.s2.uc, 0);
2084 goto ICMD_RETURN_do;
2086 case ICMD_RETURN: /* ... ==> ... */
2088 REPLACEMENT_POINT_RETURN(cd, iptr);
2091 #if !defined(NDEBUG)
2092 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2093 emit_verbosecall_exit(jd);
2096 #if defined(ENABLE_THREADS)
2097 /* call monitorexit function */
2099 if (checksync && code_is_synchronized(code)) {
2100 /* stack offset for monitor argument */
2102 s1 = rd->memuse * 8;
2104 /* we need to save the proper return value */
2106 switch (iptr->opc) {
2110 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2112 M_STMFD(BITMASK_RESULT, REG_SP);
2117 M_LDR(REG_A0, REG_SP, s1);
2118 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2119 M_DSEG_BRANCH(disp);
2121 /* we no longer need PV here, no more loading */
2122 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2123 M_RECOMPUTE_PV(s1);*/
2125 switch (iptr->opc) {
2129 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2131 M_LDMFD(BITMASK_RESULT, REG_SP);
2137 /* deallocate stackframe for spilled variables */
2139 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2140 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2142 /* restore callee saved registers + do return */
2144 if (savedregs_bitmask) {
2145 if (!code_is_leafmethod(code)) {
2146 savedregs_bitmask &= ~(1<<REG_LR);
2147 savedregs_bitmask |= (1<<REG_PC);
2149 M_LDMFD(savedregs_bitmask, REG_SP);
2152 /* if LR was not on stack, we need to return manually */
2154 if (code_is_leafmethod(code))
2155 M_MOV(REG_PC, REG_LR);
2158 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2160 bte = iptr->sx.s23.s3.bte;
2162 goto ICMD_INVOKE_do;
2164 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2165 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2166 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2167 case ICMD_INVOKEINTERFACE:
2169 REPLACEMENT_POINT_INVOKE(cd, iptr);
2171 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2173 um = iptr->sx.s23.s3.um;
2174 md = um->methodref->parseddesc.md;
2177 lm = iptr->sx.s23.s3.fmiref->p.method;
2179 md = lm->parseddesc;
2183 /* copy arguments to registers or stack location */
2185 s3 = md->paramcount;
2187 MCODECHECK((s3 << 1) + 64);
2189 for (s3 = s3 - 1; s3 >= 0; s3--) {
2190 var = VAR(iptr->sx.s23.s2.args[s3]);
2191 d = md->params[s3].regoff;
2193 if (var->flags & PREALLOC) /* argument was precolored? */
2196 /* TODO: document me */
2197 #if !defined(ENABLE_SOFTFLOAT)
2198 if (IS_INT_LNG_TYPE(var->type)) {
2199 #endif /* !defined(ENABLE_SOFTFLOAT) */
2200 if (!md->params[s3].inmemory) {
2201 s1 = emit_load(jd, iptr, var, d);
2203 if (IS_2_WORD_TYPE(var->type))
2209 if (IS_2_WORD_TYPE(var->type)) {
2210 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2211 M_LST(s1, REG_SP, d);
2214 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2215 M_IST(s1, REG_SP, d);
2218 #if !defined(ENABLE_SOFTFLOAT)
2221 if (!md->params[s3].inmemory) {
2222 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2223 if (IS_2_WORD_TYPE(var->type))
2229 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2230 if (IS_2_WORD_TYPE(var->type))
2231 M_DST(s1, REG_SP, d);
2233 M_FST(s1, REG_SP, d);
2236 #endif /* !defined(ENABLE_SOFTFLOAT) */
2239 switch (iptr->opc) {
2242 if (bte->stub == NULL) {
2243 disp = dseg_add_functionptr(cd, bte->fp);
2245 disp = dseg_add_functionptr(cd, bte->stub);
2248 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2250 /* generate the actual call */
2252 M_MOV(REG_LR, REG_PC);
2253 M_MOV(REG_PC, REG_PV);
2254 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2258 case ICMD_INVOKESPECIAL:
2259 emit_nullpointer_check(cd, iptr, REG_A0);
2262 case ICMD_INVOKESTATIC:
2264 disp = dseg_add_unique_address(cd, NULL);
2266 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2270 disp = dseg_add_address(cd, lm->stubroutine);
2272 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2274 /* generate the actual call */
2276 M_MOV(REG_LR, REG_PC);
2277 M_MOV(REG_PC, REG_PV);
2278 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2282 case ICMD_INVOKEVIRTUAL:
2284 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2289 s1 = OFFSET(vftbl_t, table[0]) +
2290 sizeof(methodptr) * lm->vftblindex;
2292 /* implicit null-pointer check */
2293 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2294 OFFSET(java_object_t, vftbl));
2295 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
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_INVOKEINTERFACE:
2307 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2313 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2314 sizeof(methodptr*) * lm->clazz->index;
2315 s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
2318 /* implicit null-pointer check */
2319 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2320 OFFSET(java_object_t, vftbl));
2321 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2322 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2324 /* generate the actual call */
2326 M_MOV(REG_LR, REG_PC);
2327 M_MOV(REG_PC, REG_PV);
2328 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2333 /* store size of call code in replacement point */
2334 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2336 /* store return value */
2338 d = md->returntype.type;
2340 #if !defined(__SOFTFP__)
2341 /* TODO: this is only a hack, since we use R0/R1 for float
2342 return! this depends on gcc; it is independent from
2343 our ENABLE_SOFTFLOAT define */
2344 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2345 #if 0 && !defined(NDEBUG)
2346 dolog("BUILTIN that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
2348 /* we cannot use this macro, since it is not defined
2349 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2350 REG_FRESULT, REG_RESULT_TYPED(d)); */
2351 if (IS_2_WORD_TYPE(d)) {
2352 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2353 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2355 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2356 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2361 if (d != TYPE_VOID) {
2362 #if !defined(ENABLE_SOFTFLOAT)
2363 if (IS_INT_LNG_TYPE(d)) {
2364 #endif /* !defined(ENABLE_SOFTFLOAT) */
2365 if (IS_2_WORD_TYPE(d)) {
2366 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2367 M_LNGMOVE(REG_RESULT_PACKED, s1);
2370 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2371 M_INTMOVE(REG_RESULT, s1);
2374 #if !defined(ENABLE_SOFTFLOAT)
2376 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2377 if (IS_2_WORD_TYPE(d))
2378 M_CAST_L2D(REG_RESULT_PACKED, s1);
2380 M_CAST_I2F(REG_RESULT, s1);
2382 #endif /* !defined(ENABLE_SOFTFLOAT) */
2384 emit_store_dst(jd, iptr, s1);
2388 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2390 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2391 /* object type cast-check */
2396 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2401 super = iptr->sx.s23.s3.c.cls;
2402 superindex = super->index;
2405 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2406 CODEGEN_CRITICAL_SECTION_NEW;
2408 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2410 /* if class is not resolved, check which code to call */
2412 if (super == NULL) {
2414 emit_label_beq(cd, BRANCH_LABEL_1);
2416 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2417 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2418 iptr->sx.s23.s3.c.ref, disp);
2420 M_DSEG_LOAD(REG_ITMP2, disp);
2421 disp = dseg_add_s4(cd, ACC_INTERFACE);
2422 M_DSEG_LOAD(REG_ITMP3, disp);
2423 M_TST(REG_ITMP2, REG_ITMP3);
2424 emit_label_beq(cd, BRANCH_LABEL_2);
2427 /* interface checkcast code */
2429 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2430 if ((super == NULL) || !IS_IMM(superindex)) {
2431 disp = dseg_add_unique_s4(cd, superindex);
2433 if (super == NULL) {
2434 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2435 iptr->sx.s23.s3.c.ref, disp);
2439 emit_label_beq(cd, BRANCH_LABEL_3);
2442 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2443 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2445 /* we put unresolved or non-immediate superindices onto dseg */
2446 if ((super == NULL) || !IS_IMM(superindex)) {
2447 /* disp was computed before we added the patcher */
2448 M_DSEG_LOAD(REG_ITMP2, disp);
2449 M_CMP(REG_ITMP3, REG_ITMP2);
2451 assert(IS_IMM(superindex));
2452 M_CMP_IMM(REG_ITMP3, superindex);
2455 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2457 /* if we loaded the superindex out of the dseg above, we do
2458 things differently here! */
2459 if ((super == NULL) || !IS_IMM(superindex)) {
2461 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2463 /* this assumes something */
2464 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2466 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2467 assert(sizeof(methodptr*) == 4);
2468 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2474 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2475 superindex * sizeof(methodptr*);
2479 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2480 M_TST(REG_ITMP3, REG_ITMP3);
2481 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2484 emit_label_br(cd, BRANCH_LABEL_4);
2486 emit_label(cd, BRANCH_LABEL_3);
2489 /* class checkcast code */
2491 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2492 if (super == NULL) {
2493 emit_label(cd, BRANCH_LABEL_2);
2495 disp = dseg_add_unique_address(cd, NULL);
2497 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2498 iptr->sx.s23.s3.c.ref,
2502 disp = dseg_add_address(cd, super->vftbl);
2505 emit_label_beq(cd, BRANCH_LABEL_5);
2508 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2509 M_DSEG_LOAD(REG_ITMP3, disp);
2511 CODEGEN_CRITICAL_SECTION_START;
2513 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2514 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2515 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2516 M_DSEG_LOAD(REG_ITMP3, disp);
2517 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2519 CODEGEN_CRITICAL_SECTION_END;
2521 M_CMP(REG_ITMP2, REG_ITMP3);
2522 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2525 emit_label(cd, BRANCH_LABEL_5);
2528 if (super == NULL) {
2529 emit_label(cd, BRANCH_LABEL_1);
2530 emit_label(cd, BRANCH_LABEL_4);
2533 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2536 /* array type cast-check */
2538 s1 = emit_load_s1(jd, iptr, REG_A0);
2539 M_INTMOVE(s1, REG_A0);
2541 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2542 disp = dseg_add_unique_address(cd, NULL);
2544 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2545 iptr->sx.s23.s3.c.ref,
2549 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2551 M_DSEG_LOAD(REG_A1, disp);
2552 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2553 M_DSEG_BRANCH(disp);
2556 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2557 M_RECOMPUTE_PV(disp);
2559 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2560 M_TST(REG_RESULT, REG_RESULT);
2561 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2563 d = codegen_reg_of_dst(jd, iptr, s1);
2567 emit_store_dst(jd, iptr, d);
2570 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2576 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2581 super = iptr->sx.s23.s3.c.cls;
2582 superindex = super->index;
2585 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2586 CODEGEN_CRITICAL_SECTION_NEW;
2588 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2589 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2592 M_MOV(REG_ITMP1, s1);
2596 /* if class is not resolved, check which code to call */
2598 if (super == NULL) {
2602 emit_label_beq(cd, BRANCH_LABEL_1);
2604 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2605 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2606 iptr->sx.s23.s3.c.ref, disp);
2608 M_DSEG_LOAD(REG_ITMP2, disp);
2609 disp = dseg_add_s4(cd, ACC_INTERFACE);
2610 M_DSEG_LOAD(REG_ITMP3, disp);
2611 M_TST(REG_ITMP2, REG_ITMP3);
2612 emit_label_beq(cd, BRANCH_LABEL_2);
2615 /* interface checkcast code */
2617 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2618 if ((super == NULL) || !IS_IMM(superindex)) {
2619 disp = dseg_add_unique_s4(cd, superindex);
2621 if (super == NULL) {
2622 /* If d == REG_ITMP2, then it's destroyed in check
2627 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2628 iptr->sx.s23.s3.c.ref, disp);
2633 emit_label_beq(cd, BRANCH_LABEL_3);
2636 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2637 M_LDR_INTERN(REG_ITMP3,
2638 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2640 /* we put unresolved or non-immediate superindices onto dseg
2641 and do things slightly different */
2642 if ((super == NULL) || !IS_IMM(superindex)) {
2643 /* disp was computed before we added the patcher */
2644 M_DSEG_LOAD(REG_ITMP2, disp);
2645 M_CMP(REG_ITMP3, REG_ITMP2);
2647 if (d == REG_ITMP2) {
2654 /* this assumes something */
2655 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2657 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2658 assert(sizeof(methodptr*) == 4);
2659 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2661 if (d == REG_ITMP2) {
2668 assert(IS_IMM(superindex));
2669 M_CMP_IMM(REG_ITMP3, superindex);
2673 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2674 superindex * sizeof(methodptr*);
2678 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2679 M_TST(REG_ITMP3, REG_ITMP3);
2683 emit_label_br(cd, BRANCH_LABEL_4);
2685 emit_label(cd, BRANCH_LABEL_3);
2688 /* class checkcast code */
2690 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2691 if (super == NULL) {
2692 emit_label(cd, BRANCH_LABEL_2);
2694 disp = dseg_add_unique_address(cd, NULL);
2696 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2697 iptr->sx.s23.s3.c.ref, disp);
2700 disp = dseg_add_address(cd, super->vftbl);
2704 emit_label_beq(cd, BRANCH_LABEL_5);
2707 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2708 M_DSEG_LOAD(REG_ITMP2, disp);
2710 CODEGEN_CRITICAL_SECTION_START;
2712 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2713 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2714 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2716 CODEGEN_CRITICAL_SECTION_END;
2718 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2719 M_CMP(REG_ITMP1, REG_ITMP2);
2720 /* If d == REG_ITMP2, then it's destroyed */
2726 emit_label(cd, BRANCH_LABEL_5);
2729 if (super == NULL) {
2730 emit_label(cd, BRANCH_LABEL_1);
2731 emit_label(cd, BRANCH_LABEL_4);
2736 emit_store_dst(jd, iptr, d);
2739 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2741 /* copy sizes to stack if necessary */
2743 MCODECHECK((iptr->s1.argcount << 1) + 64);
2745 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2747 var = VAR(iptr->sx.s23.s2.args[s1]);
2749 /* copy SAVEDVAR sizes to stack */
2751 if (!(var->flags & PREALLOC)) {
2752 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2753 M_STR(s2, REG_SP, s1 * 4);
2757 /* a0 = dimension count */
2759 assert(IS_IMM(iptr->s1.argcount));
2760 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2762 /* is patcher function set? */
2764 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2765 disp = dseg_add_unique_address(cd, NULL);
2767 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2768 iptr->sx.s23.s3.c.ref, disp);
2771 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2773 /* a1 = arraydescriptor */
2775 M_DSEG_LOAD(REG_A1, disp);
2777 /* a2 = pointer to dimensions = stack pointer */
2779 M_INTMOVE(REG_SP, REG_A2);
2781 /* call builtin_multianewarray here */
2783 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2784 M_DSEG_BRANCH(disp);
2788 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2791 /* check for exception before result assignment */
2793 emit_exception_check(cd, iptr);
2797 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2798 M_INTMOVE(REG_RESULT, d);
2799 emit_store_dst(jd, iptr, d);
2802 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2804 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2805 emit_nullpointer_check(cd, iptr, s1);
2809 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2812 } /* the big switch */
2814 } /* for all instructions */
2816 } /* for all basic blocks */
2818 /* generate traps */
2820 emit_patcher_traps(jd);
2822 /* everything's ok */
2828 /* codegen_emit_stub_compiler **************************************************
2830 Emits a stub routine which calls the compiler.
2832 *******************************************************************************/
2834 void codegen_emit_stub_compiler(jitdata *jd)
2839 /* get required compiler data */
2844 /* code for the stub */
2846 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2847 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2851 /* codegen_emit_stub_native ****************************************************
2853 Emits a stub routine which calls a native method.
2855 *******************************************************************************/
2857 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2868 /* get required compiler data */
2874 /* initialize variables */
2878 /* calculate stackframe size */
2880 cd->stackframesize =
2881 4 + /* return address */
2882 sizeof(stackframeinfo_t) + /* stackframeinfo */
2883 sizeof(localref_table) + /* localref_table */
2884 nmd->memuse * 4; /* stack arguments */
2886 /* align stack to 8-byte */
2888 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2890 /* create method header */
2892 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2893 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2894 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2895 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2896 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2898 /* generate stub code */
2900 M_STMFD(1<<REG_LR, REG_SP);
2901 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2903 #if !defined(NDEBUG)
2904 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2905 emit_verbosecall_enter(jd);
2908 #if defined(ENABLE_GC_CACAO)
2909 /* Save callee saved integer registers in stackframeinfo (GC may
2910 need to recover them during a collection). */
2912 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2913 OFFSET(stackframeinfo_t, intregs);
2915 for (i = 0; i < INT_SAV_CNT; i++)
2916 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2919 /* Save integer and float argument registers (these are 4
2920 registers, stack is 8-byte aligned). */
2922 M_STMFD(BITMASK_ARGS, REG_SP);
2923 /* TODO: floating point */
2925 /* create native stackframe info */
2927 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2928 M_MOV(REG_A1, REG_PV);
2929 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2930 M_DSEG_BRANCH(disp);
2934 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2937 /* remember class argument */
2939 if (m->flags & ACC_STATIC)
2940 M_MOV(REG_ITMP3, REG_RESULT);
2942 /* Restore integer and float argument registers (these are 4
2943 registers, stack is 8-byte aligned). */
2945 M_LDMFD(BITMASK_ARGS, REG_SP);
2946 /* TODO: floating point */
2948 /* copy or spill arguments to new locations */
2949 /* ATTENTION: the ARM has only integer argument registers! */
2951 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2952 t = md->paramtypes[i].type;
2954 if (!md->params[i].inmemory) {
2955 s1 = md->params[i].regoff;
2956 s2 = nmd->params[j].regoff;
2958 if (!nmd->params[j].inmemory) {
2959 #if !defined(__ARM_EABI__)
2960 SPLIT_OPEN(t, s2, REG_ITMP1);
2963 if (IS_2_WORD_TYPE(t))
2968 #if !defined(__ARM_EABI__)
2969 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2973 if (IS_2_WORD_TYPE(t))
2974 M_LST(s1, REG_SP, s2);
2976 M_IST(s1, REG_SP, s2);
2980 s1 = md->params[i].regoff + cd->stackframesize;
2981 s2 = nmd->params[j].regoff;
2983 if (IS_2_WORD_TYPE(t)) {
2984 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2985 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2988 M_ILD(REG_ITMP1, REG_SP, s1);
2989 M_IST(REG_ITMP1, REG_SP, s2);
2994 /* Handle native Java methods. */
2996 if (m->flags & ACC_NATIVE) {
2997 /* put class into second argument register */
2999 if (m->flags & ACC_STATIC)
3000 M_MOV(REG_A1, REG_ITMP3);
3002 /* put env into first argument register */
3004 disp = dseg_add_address(cd, _Jv_env);
3005 M_DSEG_LOAD(REG_A0, disp);
3008 /* Call the native function. */
3010 disp = dseg_add_functionptr(cd, f);
3011 M_DSEG_BRANCH(disp);
3014 /* TODO: this is only needed because of the tracer ... do we
3017 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3020 #if !defined(__SOFTFP__)
3021 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3022 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3023 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3024 #if 0 && !defined(NDEBUG)
3025 dolog("NATIVESTUB that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
3027 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3028 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3029 if (IS_2_WORD_TYPE(md->returntype.type)) {
3030 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3031 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3033 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3034 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3039 #if !defined(NDEBUG)
3040 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3041 emit_verbosecall_exit(jd);
3044 /* remove native stackframe info */
3045 /* TODO: improve this store/load */
3047 M_STMFD(BITMASK_RESULT, REG_SP);
3049 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3050 M_MOV(REG_A1, REG_PV);
3051 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3052 M_DSEG_BRANCH(disp);
3053 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3056 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3057 M_LDMFD(BITMASK_RESULT, REG_SP);
3059 #if defined(ENABLE_GC_CACAO)
3060 /* restore callee saved int registers from stackframeinfo (GC might have */
3061 /* modified them during a collection). */
3063 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3064 OFFSET(stackframeinfo_t, intregs);
3066 for (i = 0; i < INT_SAV_CNT; i++)
3067 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3070 /* finish stub code, but do not yet return to caller */
3072 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3073 M_LDMFD(1<<REG_LR, REG_SP);
3075 /* check for exception */
3077 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3078 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3080 /* handle exception here */
3082 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3084 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3085 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3086 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3090 /* asm_debug *******************************************************************
3094 *******************************************************************************/
3096 void asm_debug(int a1, int a2, int a3, int a4)
3098 printf("===> i am going to exit after this debugging message!\n");
3099 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3100 vm_abort("leave you now");
3105 * These are local overrides for various environment variables in Emacs.
3106 * Please do not remove this and leave it at the end of the file, where
3107 * Emacs will automagically detect them.
3108 * ---------------------------------------------------------------------
3111 * indent-tabs-mode: t
3115 * vim:noexpandtab:sw=4:ts=4: