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)
96 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
97 unresolved_method *um;
98 builtintable_entry *bte;
101 unresolved_field *uf;
105 /* get required compiler data */
112 /* prevent compiler warnings */
120 /* space to save used callee saved registers */
122 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
124 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
125 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
126 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
128 spilledregs_num = rd->memuse;
130 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
131 if (checksync && code_is_synchronized(code))
135 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
137 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
138 only in native stubs. */
139 /* align stack to 8-byte */
141 cd->stackframesize = (cd->stackframesize + 4) & ~4;
143 /* SECTION: Method Header */
144 /* create method header */
146 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
147 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
149 code->synchronizedoffset = rd->memuse * 8;
151 /* REMOVEME: We still need it for exception handling in assembler. */
153 if (code_is_leafmethod(code))
154 (void) dseg_add_unique_s4(cd, 1);
156 (void) dseg_add_unique_s4(cd, 0);
158 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
159 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
161 (void) dseg_addlinenumbertablesize(cd);
163 /* save return address and used callee saved registers */
165 savedregs_bitmask = 0;
167 if (!code_is_leafmethod(code))
168 savedregs_bitmask = (1<<REG_LR);
170 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
171 savedregs_bitmask |= (1<<(rd->savintregs[i]));
174 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
175 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
176 /* TODO: floating-point */
180 if (savedregs_bitmask)
181 M_STMFD(savedregs_bitmask, REG_SP);
183 /* create additional stack frame for spilled variables (if necessary) */
185 if ((cd->stackframesize / 4 - savedregs_num) > 0)
186 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
188 /* take arguments out of register or stack frame */
191 for (i = 0, len = 0; i < md->paramcount; i++) {
192 s1 = md->params[i].regoff;
193 t = md->paramtypes[i].type;
195 varindex = jd->local_map[len * 5 + t];
197 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
199 if (varindex == UNUSED)
204 /* ATTENTION: we use interger registers for all arguments (even float) */
205 #if !defined(ENABLE_SOFTFLOAT)
206 if (IS_INT_LNG_TYPE(t)) {
208 if (!md->params[i].inmemory) {
209 if (!(var->flags & INMEMORY)) {
210 if (IS_2_WORD_TYPE(t))
211 M_LNGMOVE(s1, var->vv.regoff);
213 M_INTMOVE(s1, var->vv.regoff);
216 if (IS_2_WORD_TYPE(t))
217 M_LST(s1, REG_SP, var->vv.regoff);
219 M_IST(s1, REG_SP, var->vv.regoff);
222 else { /* stack arguments */
223 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
224 if (IS_2_WORD_TYPE(t))
225 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
227 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
229 else { /* stack arg -> spilled */
230 /* Reuse Memory Position on Caller Stack */
231 var->vv.regoff = cd->stackframesize + s1;
234 #if !defined(ENABLE_SOFTFLOAT)
237 if (!md->params[i].inmemory) {
238 if (!(var->flags & INMEMORY)) {
239 if (IS_2_WORD_TYPE(t))
240 M_CAST_L2D(s1, var->vv.regoff);
242 M_CAST_I2F(s1, var->vv.regoff);
245 if (IS_2_WORD_TYPE(t))
246 M_LST(s1, REG_SP, var->vv.regoff);
248 M_IST(s1, REG_SP, var->vv.regoff);
252 if (!(var->flags & INMEMORY)) {
253 if (IS_2_WORD_TYPE(t))
254 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
256 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
259 /* Reuse Memory Position on Caller Stack */
260 var->vv.regoff = cd->stackframesize + s1;
264 #endif /* !defined(ENABLE_SOFTFLOAT) */
267 #if defined(ENABLE_THREADS)
268 /* call monitorenter function */
270 if (checksync && code_is_synchronized(code)) {
271 /* stack offset for monitor argument */
275 # if !defined(NDEBUG)
276 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
277 M_STMFD(BITMASK_ARGS, REG_SP);
282 /* get the correct lock object */
284 if (m->flags & ACC_STATIC) {
285 disp = dseg_add_address(cd, &m->class->object.header);
286 M_DSEG_LOAD(REG_A0, disp);
289 emit_nullpointer_check_force(cd, iptr, REG_A0);
292 M_STR(REG_A0, REG_SP, s1);
293 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
295 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
298 # if !defined(NDEBUG)
299 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
300 M_LDMFD(BITMASK_ARGS, REG_SP);
306 /* call trace function */
308 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
309 emit_verbosecall_enter(jd);
312 /* end of header generation */
314 /* create replacement points */
315 REPLACEMENT_POINTS_INIT(cd, jd);
317 /* SECTION: ICMD Code Generation */
318 /* for all basic blocks */
320 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
322 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
324 /* is this basic block reached? */
326 if (bptr->flags < BBREACHED)
329 /* branch resolving */
331 codegen_resolve_branchrefs(cd, bptr);
333 /* handle replacement points */
334 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
336 /* copy interface registers to their destination */
342 #if defined(ENABLE_LSRA)
346 var = VAR(bptr->invars[len]);
347 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
348 if (!(var->flags & INMEMORY))
352 M_INTMOVE(REG_ITMP1, d);
353 emit_store(jd, NULL, var, d);
360 var = VAR(bptr->invars[len]);
362 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
363 d = codegen_reg_of_var(0, var, REG_ITMP1);
364 M_INTMOVE(REG_ITMP1, d);
365 emit_store(jd, NULL, var, d);
368 assert((var->flags & INOUT));
371 #if defined(ENABLE_LSRA)
375 /* for all instructions */
378 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
380 /* add line number */
381 if (iptr->line != currentline) {
382 dseg_addlinenumber(cd, iptr->line);
383 currentline = iptr->line;
386 MCODECHECK(64); /* an instruction usually needs < 64 words */
391 case ICMD_NOP: /* ... ==> ... */
392 case ICMD_POP: /* ..., value ==> ... */
393 case ICMD_POP2: /* ..., value, value ==> ... */
396 /* constant operations ************************************************/
398 case ICMD_ICONST: /* ... ==> ..., constant */
400 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
401 ICONST(d, iptr->sx.val.i);
402 emit_store_dst(jd, iptr, d);
405 case ICMD_ACONST: /* ... ==> ..., constant */
407 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
408 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
409 disp = dseg_add_unique_address(cd, NULL);
411 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
412 iptr->sx.val.c.ref, disp);
414 M_DSEG_LOAD(d, disp);
417 ICONST(d, (u4) iptr->sx.val.anyptr);
419 emit_store_dst(jd, iptr, d);
422 case ICMD_LCONST: /* ... ==> ..., constant */
424 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
425 LCONST(d, iptr->sx.val.l);
426 emit_store_dst(jd, iptr, d);
429 case ICMD_FCONST: /* ... ==> ..., constant */
431 #if defined(ENABLE_SOFTFLOAT)
432 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
433 ICONST(d, iptr->sx.val.i);
434 emit_store_dst(jd, iptr, d);
436 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
437 FCONST(d, iptr->sx.val.f);
438 emit_store_dst(jd, iptr, d);
442 case ICMD_DCONST: /* ... ==> ..., constant */
444 #if defined(ENABLE_SOFTFLOAT)
445 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
446 LCONST(d, iptr->sx.val.l);
447 emit_store_dst(jd, iptr, d);
449 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
450 DCONST(d, iptr->sx.val.d);
451 emit_store_dst(jd, iptr, d);
456 /* load/store/copy/move operations ************************************/
458 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
459 case ICMD_ALOAD: /* op1 = local variable */
463 case ICMD_ISTORE: /* ..., value ==> ... */
475 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
480 /* integer operations *************************************************/
482 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
484 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
485 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
486 M_MOV(d, REG_LSL(s1, 24));
487 M_MOV(d, REG_ASR(d, 24));
488 emit_store_dst(jd, iptr, d);
491 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
493 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
494 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
495 M_MOV(d, REG_LSL(s1, 16));
496 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
497 emit_store_dst(jd, iptr, d);
500 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
502 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
503 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
504 M_MOV(d, REG_LSL(s1, 16));
505 M_MOV(d, REG_ASR(d, 16));
506 emit_store_dst(jd, iptr, d);
509 case ICMD_I2L: /* ..., value ==> ..., value */
511 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
512 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
513 M_INTMOVE(s1, GET_LOW_REG(d));
514 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
515 emit_store_dst(jd, iptr, d);
518 case ICMD_L2I: /* ..., value ==> ..., value */
520 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
521 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
523 emit_store_dst(jd, iptr, d);
526 case ICMD_INEG: /* ..., value ==> ..., - value */
528 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
529 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
531 emit_store_dst(jd, iptr, d);
534 case ICMD_LNEG: /* ..., value ==> ..., - value */
536 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
538 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
539 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
540 emit_store_dst(jd, iptr, d);
543 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
545 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
546 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
547 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
549 emit_store_dst(jd, iptr, d);
552 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
554 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
555 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
556 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
557 M_ADD_S(GET_LOW_REG(d), s1, s2);
558 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
559 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
560 M_ADC(GET_HIGH_REG(d), s1, s2);
561 emit_store_dst(jd, iptr, d);
567 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
568 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
570 if (IS_IMM(iptr->sx.val.i)) {
571 M_ADD_IMM(d, s1, iptr->sx.val.i);
572 } else if (IS_IMM(-iptr->sx.val.i)) {
573 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
575 ICONST(REG_ITMP3, iptr->sx.val.i);
576 M_ADD(d, s1, REG_ITMP3);
579 emit_store_dst(jd, iptr, d);
582 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
583 /* sx.val.l = constant */
585 s3 = iptr->sx.val.l & 0xffffffff;
586 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
587 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
589 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
591 ICONST(REG_ITMP3, s3);
592 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
594 s3 = iptr->sx.val.l >> 32;
595 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
597 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
599 ICONST(REG_ITMP3, s3);
600 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
602 emit_store_dst(jd, iptr, d);
605 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
607 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
608 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
609 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
611 emit_store_dst(jd, iptr, d);
614 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
616 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
617 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
618 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
619 M_SUB_S(GET_LOW_REG(d), s1, s2);
620 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
621 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
622 M_SBC(GET_HIGH_REG(d), s1, s2);
623 emit_store_dst(jd, iptr, d);
626 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
627 /* sx.val.i = constant */
629 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
630 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
631 if (IS_IMM(iptr->sx.val.i))
632 M_SUB_IMM(d, s1, iptr->sx.val.i);
634 ICONST(REG_ITMP3, iptr->sx.val.i);
635 M_SUB(d, s1, REG_ITMP3);
637 emit_store_dst(jd, iptr, d);
640 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
641 /* sx.val.l = constant */
643 s3 = iptr->sx.val.l & 0xffffffff;
644 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
645 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
647 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
649 ICONST(REG_ITMP3, s3);
650 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
652 s3 = iptr->sx.val.l >> 32;
653 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
655 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
657 ICONST(REG_ITMP3, s3);
658 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
660 emit_store_dst(jd, iptr, d);
663 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
665 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
666 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
667 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
669 emit_store_dst(jd, iptr, d);
672 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
673 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
675 s1 = emit_load_s1(jd, iptr, REG_A0);
676 s2 = emit_load_s2(jd, iptr, REG_A1);
677 emit_arithmetic_check(cd, iptr, s2);
679 /* move arguments into argument registers */
680 M_INTMOVE(s1, REG_A0);
681 M_INTMOVE(s2, REG_A1);
683 /* call builtin function */
684 bte = iptr->sx.s23.s3.bte;
685 disp = dseg_add_functionptr(cd, bte->fp);
689 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
692 /* move result into destination register */
693 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
694 M_INTMOVE(REG_RESULT, d);
695 emit_store_dst(jd, iptr, d);
698 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
699 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
701 /* move arguments into argument registers */
703 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
704 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
705 /* XXX TODO: only do this if arithmetic check is really done! */
706 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
707 emit_arithmetic_check(cd, iptr, REG_ITMP3);
709 M_LNGMOVE(s1, REG_A0_A1_PACKED);
710 M_LNGMOVE(s2, REG_A2_A3_PACKED);
712 /* call builtin function */
713 bte = iptr->sx.s23.s3.bte;
714 disp = dseg_add_functionptr(cd, bte->fp);
718 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
721 /* move result into destination register */
722 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
723 M_LNGMOVE(REG_RESULT_PACKED, d);
724 emit_store_dst(jd, iptr, d);
727 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
728 /* sx.val.i = constant */
730 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
731 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
732 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
733 emit_store_dst(jd, iptr, d);
736 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
737 /* sx.val.i = constant */
739 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
740 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
741 /* this rounds towards 0 as java likes it */
742 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
743 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
744 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
745 /* this rounds towards nearest, not java style */
746 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
747 M_ADCMI_IMM(d, d, 0);*/
748 emit_store_dst(jd, iptr, d);
751 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
752 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
754 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
755 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
756 M_MOV_S(REG_ITMP1, s1);
757 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
758 if (IS_IMM(iptr->sx.val.i))
759 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
761 ICONST(REG_ITMP3, iptr->sx.val.i);
762 M_AND(REG_ITMP1, REG_ITMP3, d);
764 M_RSBMI_IMM(d, d, 0);
765 emit_store_dst(jd, iptr, d);
768 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
770 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
771 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
772 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
773 M_AND_IMM(s2, 0x1f, REG_ITMP2);
774 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
775 emit_store_dst(jd, iptr, d);
778 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
780 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
781 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
782 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
783 M_AND_IMM(s2, 0x1f, REG_ITMP2);
784 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
785 emit_store_dst(jd, iptr, d);
788 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
790 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
791 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
792 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
793 M_AND_IMM(s2, 0x1f, REG_ITMP2);
794 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
795 emit_store_dst(jd, iptr, d);
798 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
799 /* sx.val.i = constant */
801 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
802 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
803 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
804 emit_store_dst(jd, iptr, d);
807 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
808 /* sx.val.i = constant */
810 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
811 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
812 /* we need to check for zero here because arm interprets it as SHR by 32 */
813 if ((iptr->sx.val.i & 0x1f) == 0) {
816 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
818 emit_store_dst(jd, iptr, d);
821 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
822 /* sx.val.i = constant */
824 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
825 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
826 /* we need to check for zero here because arm interprets it as SHR by 32 */
827 if ((iptr->sx.val.i & 0x1f) == 0)
830 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
831 emit_store_dst(jd, iptr, d);
834 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
836 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
837 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
838 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
840 emit_store_dst(jd, iptr, d);
843 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
845 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
846 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
847 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
848 M_AND(s1, s2, GET_LOW_REG(d));
849 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
850 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
851 M_AND(s1, s2, GET_HIGH_REG(d));
852 emit_store_dst(jd, iptr, d);
855 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
857 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
858 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
859 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
861 emit_store_dst(jd, iptr, d);
864 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
866 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
867 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
868 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
869 M_ORR(s1, s2, GET_LOW_REG(d));
870 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
871 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
872 M_ORR(s1, s2, GET_HIGH_REG(d));
873 emit_store_dst(jd, iptr, d);
876 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
878 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
879 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
880 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
882 emit_store_dst(jd, iptr, d);
885 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
887 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
888 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
889 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
890 M_EOR(s1, s2, GET_LOW_REG(d));
891 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
892 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
893 M_EOR(s1, s2, GET_HIGH_REG(d));
894 emit_store_dst(jd, iptr, d);
898 /* floating operations ************************************************/
900 #if !defined(ENABLE_SOFTFLOAT)
902 case ICMD_FNEG: /* ..., value ==> ..., - value */
904 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
905 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
907 emit_store_dst(jd, iptr, d);
910 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
912 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
913 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
914 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
916 emit_store_dst(jd, iptr, d);
919 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
921 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
922 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
923 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
925 emit_store_dst(jd, iptr, d);
928 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
930 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
931 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
932 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
934 emit_store_dst(jd, iptr, d);
937 case ICMD_FDIV: /* ..., 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 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
949 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
951 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
952 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
953 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
955 emit_store_dst(jd, iptr, d);
959 case ICMD_DNEG: /* ..., value ==> ..., - value */
961 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
962 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
964 emit_store_dst(jd, iptr, d);
967 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
969 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
970 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
971 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
973 emit_store_dst(jd, iptr, d);
976 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
978 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
979 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
980 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
982 emit_store_dst(jd, iptr, d);
985 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
987 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
988 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
989 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
991 emit_store_dst(jd, iptr, d);
994 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
996 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
997 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
998 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1000 emit_store_dst(jd, iptr, d);
1003 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1007 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1009 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1010 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1011 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1013 emit_store_dst(jd, iptr, d);
1017 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1019 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1020 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1022 emit_store_dst(jd, iptr, d);
1025 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1027 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1028 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1030 emit_store_dst(jd, iptr, d);
1033 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1035 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1036 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1037 /* this uses round towards zero, as Java likes it */
1039 #if !defined(__VFP_FP__)
1040 /* this checks for NaN; to return zero as Java likes it */
1044 emit_store_dst(jd, iptr, d);
1047 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1049 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1050 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1051 /* this uses round towards zero, as Java likes it */
1053 #if !defined(__VFP_FP__)
1054 /* this checks for NaN; to return zero as Java likes it */
1058 emit_store_dst(jd, iptr, d);
1061 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1063 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1064 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1066 emit_store_dst(jd, iptr, d);
1069 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1071 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1072 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1074 emit_store_dst(jd, iptr, d);
1077 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1079 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1080 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1081 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1084 #if defined(__VFP_FP__)
1085 M_FMSTAT; /* on VFP we need to transfer the flags */
1087 M_SUBGT_IMM(d, d, 1);
1088 M_ADDLT_IMM(d, d, 1);
1089 emit_store_dst(jd, iptr, d);
1092 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1094 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1095 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1096 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1099 #if defined(__VFP_FP__)
1100 M_FMSTAT; /* on VFP we need to transfer the flags */
1102 M_SUBGT_IMM(d, d, 1);
1103 M_ADDLT_IMM(d, d, 1);
1104 emit_store_dst(jd, iptr, d);
1107 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1109 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1110 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1111 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1114 #if defined(__VFP_FP__)
1115 M_FMSTAT; /* on VFP we need to transfer the flags */
1117 M_SUBLT_IMM(d, d, 1);
1118 M_ADDGT_IMM(d, d, 1);
1119 emit_store_dst(jd, iptr, d);
1122 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1124 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1125 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1126 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1129 #if defined(__VFP_FP__)
1130 M_FMSTAT; /* on VFP we need to transfer the flags */
1132 M_SUBLT_IMM(d, d, 1);
1133 M_ADDGT_IMM(d, d, 1);
1134 emit_store_dst(jd, iptr, d);
1137 #endif /* !defined(ENABLE_SOFTFLOAT) */
1140 /* memory operations **************************************************/
1142 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1144 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1145 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1146 /* implicit null-pointer check */
1147 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1148 emit_store_dst(jd, iptr, d);
1151 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1153 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1154 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1155 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1156 /* implicit null-pointer check */
1157 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1158 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1159 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1160 emit_store_dst(jd, iptr, d);
1163 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1165 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1166 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1167 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1168 /* implicit null-pointer check */
1169 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1170 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1171 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1172 emit_store_dst(jd, iptr, d);
1175 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1177 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1178 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1179 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1180 /* implicit null-pointer check */
1181 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1182 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1183 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1184 emit_store_dst(jd, iptr, d);
1187 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1189 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1190 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1191 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1192 /* implicit null-pointer check */
1193 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1194 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1195 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1196 emit_store_dst(jd, iptr, d);
1199 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1201 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1202 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1203 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1204 /* implicit null-pointer check */
1205 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1206 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1207 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1208 emit_store_dst(jd, iptr, d);
1211 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1213 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1214 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1215 /* implicit null-pointer check */
1216 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1217 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1218 #if !defined(ENABLE_SOFTFLOAT)
1219 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1220 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1222 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1223 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1225 emit_store_dst(jd, iptr, d);
1228 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1230 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1231 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1232 /* implicit null-pointer check */
1233 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1234 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1235 #if !defined(ENABLE_SOFTFLOAT)
1236 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1237 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1239 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1240 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1242 emit_store_dst(jd, iptr, d);
1245 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1247 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1248 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1249 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1250 /* implicit null-pointer check */
1251 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1252 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1253 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1254 emit_store_dst(jd, iptr, d);
1257 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1259 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1260 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1261 /* implicit null-pointer check */
1262 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1263 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1264 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1265 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1268 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1270 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1271 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1272 /* implicit null-pointer check */
1273 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1274 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1275 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1276 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1279 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1281 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1282 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1283 /* implicit null-pointer check */
1284 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1285 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1286 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1287 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1290 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1292 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1293 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1294 /* implicit null-pointer check */
1295 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1296 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1297 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1298 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1301 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1303 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1304 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1305 /* implicit null-pointer check */
1306 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1307 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1308 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1309 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1312 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1314 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1315 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1316 /* implicit null-pointer check */
1317 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1318 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1319 #if !defined(ENABLE_SOFTFLOAT)
1320 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1321 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1323 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1324 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1328 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1330 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1331 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1332 /* implicit null-pointer check */
1333 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1334 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1335 #if !defined(ENABLE_SOFTFLOAT)
1336 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1337 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1339 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1340 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1344 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1346 s1 = emit_load_s1(jd, iptr, REG_A0);
1347 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1348 s3 = emit_load_s3(jd, iptr, REG_A1);
1350 /* implicit null-pointer check */
1351 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1353 /* move arguments to argument registers */
1354 M_INTMOVE(s1, REG_A0);
1355 M_INTMOVE(s3, REG_A1);
1357 /* call builtin function */
1358 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1359 M_DSEG_BRANCH(disp);
1362 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1365 /* check resturn value of builtin */
1366 emit_arraystore_check(cd, iptr);
1368 /* finally store address into array */
1369 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1370 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1371 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1372 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1373 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1376 case ICMD_GETSTATIC: /* ... ==> ..., value */
1378 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1379 uf = iptr->sx.s23.s3.uf;
1380 fieldtype = uf->fieldref->parseddesc.fd->type;
1381 disp = dseg_add_unique_address(cd, NULL);
1383 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1386 fi = iptr->sx.s23.s3.fmiref->p.field;
1387 fieldtype = fi->type;
1388 disp = dseg_add_address(cd, fi->value);
1390 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1391 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1396 M_DSEG_LOAD(REG_ITMP3, disp);
1397 switch (fieldtype) {
1399 #if defined(ENABLE_SOFTFLOAT)
1403 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1404 M_ILD_INTERN(d, REG_ITMP3, 0);
1407 #if defined(ENABLE_SOFTFLOAT)
1410 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1411 M_LLD_INTERN(d, REG_ITMP3, 0);
1413 #if !defined(ENABLE_SOFTFLOAT)
1415 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1416 M_FLD_INTERN(d, REG_ITMP3, 0);
1419 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1420 M_DLD_INTERN(d, REG_ITMP3, 0);
1426 emit_store_dst(jd, iptr, d);
1429 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1431 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1432 uf = iptr->sx.s23.s3.uf;
1433 fieldtype = uf->fieldref->parseddesc.fd->type;
1434 disp = dseg_add_unique_address(cd, NULL);
1436 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1439 fi = iptr->sx.s23.s3.fmiref->p.field;
1440 fieldtype = fi->type;
1441 disp = dseg_add_address(cd, fi->value);
1443 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1444 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1449 M_DSEG_LOAD(REG_ITMP3, disp);
1450 switch (fieldtype) {
1452 #if defined(ENABLE_SOFTFLOAT)
1456 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1457 M_IST_INTERN(s1, REG_ITMP3, 0);
1460 #if defined(ENABLE_SOFTFLOAT)
1463 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1464 M_LST_INTERN(s1, REG_ITMP3, 0);
1466 #if !defined(ENABLE_SOFTFLOAT)
1468 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1469 M_FST_INTERN(s1, REG_ITMP3, 0);
1472 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1473 M_DST_INTERN(s1, REG_ITMP3, 0);
1481 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1483 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1484 emit_nullpointer_check(cd, iptr, s1);
1487 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1488 uf = iptr->sx.s23.s3.uf;
1489 fieldtype = uf->fieldref->parseddesc.fd->type;
1493 fi = iptr->sx.s23.s3.fmiref->p.field;
1494 fieldtype = fi->type;
1498 #if !defined(ENABLE_SOFTFLOAT)
1499 /* HACK: softnull checks on floats */
1500 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1501 emit_nullpointer_check_force(cd, iptr, s1);
1504 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1506 uf = iptr->sx.s23.s3.uf;
1508 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1511 switch (fieldtype) {
1513 #if defined(ENABLE_SOFTFLOAT)
1517 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1521 #if defined(ENABLE_SOFTFLOAT)
1524 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1527 #if !defined(ENABLE_SOFTFLOAT)
1529 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1533 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1540 emit_store_dst(jd, iptr, d);
1543 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1545 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1546 emit_nullpointer_check(cd, iptr, s1);
1548 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1549 uf = iptr->sx.s23.s3.uf;
1550 fieldtype = uf->fieldref->parseddesc.fd->type;
1554 fi = iptr->sx.s23.s3.fmiref->p.field;
1555 fieldtype = fi->type;
1559 #if !defined(ENABLE_SOFTFLOAT)
1560 /* HACK: softnull checks on floats */
1561 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1562 emit_nullpointer_check_force(cd, iptr, s1);
1565 switch (fieldtype) {
1567 #if defined(ENABLE_SOFTFLOAT)
1571 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1573 #if defined(ENABLE_SOFTFLOAT)
1574 case TYPE_DBL: /* fall through */
1577 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1579 #if !defined(ENABLE_SOFTFLOAT)
1582 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1589 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1591 uf = iptr->sx.s23.s3.uf;
1593 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1596 switch (fieldtype) {
1598 #if defined(ENABLE_SOFTFLOAT)
1602 M_IST(s2, s1, disp);
1605 #if defined(ENABLE_SOFTFLOAT)
1608 M_LST(s2, s1, disp);
1610 #if !defined(ENABLE_SOFTFLOAT)
1612 M_FST(s2, s1, disp);
1615 M_DST(s2, s1, disp);
1624 /* branch operations **************************************************/
1626 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1628 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1629 M_INTMOVE(s1, REG_ITMP1_XPTR);
1630 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1631 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1632 iptr->sx.s23.s2.uc, 0);
1634 disp = dseg_add_functionptr(cd, asm_handle_exception);
1635 M_DSEG_LOAD(REG_ITMP3, disp);
1636 M_MOV(REG_ITMP2_XPC, REG_PC);
1637 M_MOV(REG_PC, REG_ITMP3);
1638 M_NOP; /* nop ensures that XPC is less than the end */
1639 /* of basic block */
1642 case ICMD_GOTO: /* ... ==> ... */
1645 emit_br(cd, iptr->dst.block);
1648 case ICMD_JSR: /* ... ==> ... */
1650 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1653 case ICMD_IFNULL: /* ..., value ==> ... */
1654 case ICMD_IFNONNULL:
1656 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1658 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1661 case ICMD_IFLT: /* ..., value ==> ... */
1662 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1668 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1669 M_COMPARE(s1, iptr->sx.val.i);
1670 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1673 case ICMD_IF_LEQ: /* ..., value ==> ... */
1675 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1676 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1677 if (iptr->sx.val.l == 0) {
1678 M_ORR_S(s1, s2, REG_ITMP3);
1681 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1682 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1683 M_CMP(s1, REG_ITMP3);*/
1684 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1685 M_CMPEQ(s2, REG_ITMP3);
1687 emit_beq(cd, iptr->dst.block);
1690 case ICMD_IF_LLT: /* ..., value ==> ... */
1692 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1693 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1694 if (iptr->sx.val.l == 0) {
1695 /* if high word is less than zero, the whole long is too */
1697 emit_blt(cd, iptr->dst.block);
1700 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1701 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1702 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1703 M_CMP(s1, REG_ITMP3);*/
1704 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1705 M_MOVGT_IMM(2, REG_ITMP1);
1706 M_MOVEQ_IMM(1, REG_ITMP1);
1708 /* low compare: x=x-1(ifLO) */
1709 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1710 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1711 M_CMP(s2, REG_ITMP3);*/
1712 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1714 /* branch if (x LT 1) */
1715 M_CMP_IMM(REG_ITMP1, 1);
1716 emit_blt(cd, iptr->dst.block);
1720 case ICMD_IF_LLE: /* ..., value ==> ... */
1722 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1723 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1724 if (iptr->sx.val.l == 0) {
1725 /* if high word is less than zero, the whole long is too */
1727 emit_blt(cd, iptr->dst.block);
1729 /* ... otherwise the low word has to be zero (tricky!) */
1731 emit_beq(cd, iptr->dst.block);
1734 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1735 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1736 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1737 M_CMP(s1, REG_ITMP3);*/
1738 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1739 M_MOVGT_IMM(2, REG_ITMP1);
1740 M_MOVEQ_IMM(1, REG_ITMP1);
1742 /* low compare: x=x+1(ifHI) */
1743 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1744 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1745 M_CMP(s2, REG_ITMP3);*/
1746 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1748 /* branch if (x LE 1) */
1749 M_CMP_IMM(REG_ITMP1, 1);
1750 emit_ble(cd, iptr->dst.block);
1754 case ICMD_IF_LGE: /* ..., value ==> ... */
1756 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1757 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1758 if (iptr->sx.val.l == 0) {
1759 /* if high word is greater or equal zero, the whole long is too */
1761 emit_bge(cd, iptr->dst.block);
1764 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1765 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1766 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1767 M_CMP(s1, REG_ITMP3);*/
1768 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1769 M_MOVGT_IMM(2, REG_ITMP1);
1770 M_MOVEQ_IMM(1, REG_ITMP1);
1772 /* low compare: x=x-1(ifLO) */
1773 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1774 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1775 M_CMP(s2, REG_ITMP3);*/
1776 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1778 /* branch if (x GE 1) */
1779 M_CMP_IMM(REG_ITMP1, 1);
1780 emit_bge(cd, iptr->dst.block);
1784 case ICMD_IF_LGT: /* ..., value ==> ... */
1786 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1787 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1789 if (iptr->sx.val.l == 0) {
1790 /* if high word is greater than zero, the whole long is too */
1793 codegen_add_branch_ref(cd, iptr->dst.block);
1795 /* ... or high was zero and low is non zero (tricky!) */
1796 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1797 M_MOVLT_IMM(1, REG_ITMP3);
1798 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1800 codegen_add_branch_ref(cd, iptr->dst.block);
1804 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1805 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1806 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1807 M_CMP(s1, REG_ITMP3);*/
1808 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1809 M_MOVGT_IMM(2, REG_ITMP1);
1810 M_MOVEQ_IMM(1, REG_ITMP1);
1812 /* low compare: x=x+1(ifHI) */
1813 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1814 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1815 M_CMP(s2, REG_ITMP3);*/
1816 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1818 /* branch if (x GT 1) */
1819 M_CMP_IMM(REG_ITMP1, 1);
1820 emit_bgt(cd, iptr->dst.block);
1826 case ICMD_IF_LNE: /* ..., value ==> ... */
1828 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1829 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1830 if (iptr->sx.val.l == 0) {
1831 M_ORR_S(s1, s2, REG_ITMP3);
1834 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1835 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1836 M_CMP(s1, REG_ITMP3);*/
1837 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1838 M_CMPEQ(s2, REG_ITMP3);
1840 emit_bne(cd, iptr->dst.block);
1843 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1844 case ICMD_IF_ICMPNE:
1845 case ICMD_IF_ICMPLT:
1846 case ICMD_IF_ICMPLE:
1847 case ICMD_IF_ICMPGT:
1848 case ICMD_IF_ICMPGE:
1850 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1851 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1853 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1856 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1857 case ICMD_IF_ACMPNE:
1859 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1860 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1862 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1865 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1866 /* op1 = target JavaVM pc */
1868 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1869 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1872 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1873 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1876 emit_beq(cd, iptr->dst.block);
1879 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1880 /* op1 = target JavaVM pc */
1882 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1883 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1886 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1887 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1890 emit_bne(cd, iptr->dst.block);
1893 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1894 /* op1 = target JavaVM pc */
1896 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1897 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1898 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1900 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1901 M_MOVGT_IMM(2, REG_ITMP3);
1902 M_MOVEQ_IMM(1, REG_ITMP3);
1904 /* low compare: x=x-1(ifLO) */
1905 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1906 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1908 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1910 /* branch if (x LT 1) */
1911 M_CMP_IMM(REG_ITMP3, 1);
1912 emit_blt(cd, iptr->dst.block);
1915 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1916 /* op1 = target JavaVM pc */
1918 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1919 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1920 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1922 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1923 M_MOVGT_IMM(2, REG_ITMP3);
1924 M_MOVEQ_IMM(1, REG_ITMP3);
1926 /* low compare: x=x-1(ifLO) */
1927 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1928 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1930 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1932 /* branch if (x LE 1) */
1933 M_CMP_IMM(REG_ITMP3, 1);
1934 emit_ble(cd, iptr->dst.block);
1937 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1938 /* op1 = target JavaVM pc */
1940 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1941 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1942 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1944 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1945 M_MOVGT_IMM(2, REG_ITMP3);
1946 M_MOVEQ_IMM(1, REG_ITMP3);
1948 /* low compare: x=x-1(ifLO) */
1949 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1950 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1952 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1954 /* branch if (x GT 1) */
1955 M_CMP_IMM(REG_ITMP3, 1);
1956 emit_bgt(cd, iptr->dst.block);
1959 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1960 /* op1 = target JavaVM pc */
1962 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1963 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1964 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1966 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1967 M_MOVGT_IMM(2, REG_ITMP3);
1968 M_MOVEQ_IMM(1, REG_ITMP3);
1970 /* low compare: x=x-1(ifLO) */
1971 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1972 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1974 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1976 /* branch if (x GE 1) */
1977 M_CMP_IMM(REG_ITMP3, 1);
1978 emit_bge(cd, iptr->dst.block);
1981 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1984 branch_target_t *table;
1986 table = iptr->dst.table;
1988 l = iptr->sx.s23.s2.tablelow;
1989 i = iptr->sx.s23.s3.tablehigh;
1991 /* calculate new index (index - low) */
1992 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1994 M_INTMOVE(s1, REG_ITMP1);
1995 } else if (IS_IMM(l)) {
1996 M_SUB_IMM(REG_ITMP1, s1, l);
1998 ICONST(REG_ITMP2, l);
1999 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2002 /* range check (index <= high-low) */
2004 M_COMPARE(REG_ITMP1, i-1);
2005 emit_bugt(cd, table[0].block);
2007 /* build jump table top down and use address of lowest entry */
2012 dseg_add_target(cd, table->block);
2017 /* length of dataseg after last dseg_add_target is used by load */
2018 /* TODO: this loads from data-segment */
2019 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2020 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2023 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2026 lookup_target_t *lookup;
2028 lookup = iptr->dst.lookup;
2030 i = iptr->sx.s23.s2.lookupcount;
2033 MCODECHECK((i<<2)+8);
2034 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2037 M_COMPARE(s1, lookup->value);
2038 emit_beq(cd, lookup->target.block);
2042 /* default branch */
2043 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2047 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2049 #if !defined(ENABLE_SOFTFLOAT)
2050 REPLACEMENT_POINT_RETURN(cd, iptr);
2051 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2052 M_CAST_F2I(s1, REG_RESULT);
2053 goto ICMD_RETURN_do;
2056 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2058 REPLACEMENT_POINT_RETURN(cd, iptr);
2059 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2060 M_INTMOVE(s1, REG_RESULT);
2061 goto ICMD_RETURN_do;
2063 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2065 #if !defined(ENABLE_SOFTFLOAT)
2066 REPLACEMENT_POINT_RETURN(cd, iptr);
2067 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2068 M_CAST_D2L(s1, REG_RESULT_PACKED);
2069 goto ICMD_RETURN_do;
2072 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2074 REPLACEMENT_POINT_RETURN(cd, iptr);
2075 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2076 M_LNGMOVE(s1, REG_RESULT_PACKED);
2077 goto ICMD_RETURN_do;
2079 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2081 REPLACEMENT_POINT_RETURN(cd, iptr);
2082 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2083 M_INTMOVE(s1, REG_RESULT);
2084 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2085 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2086 iptr->sx.s23.s2.uc, 0);
2088 goto ICMD_RETURN_do;
2090 case ICMD_RETURN: /* ... ==> ... */
2092 REPLACEMENT_POINT_RETURN(cd, iptr);
2095 #if !defined(NDEBUG)
2096 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2097 emit_verbosecall_exit(jd);
2100 #if defined(ENABLE_THREADS)
2101 /* call monitorexit function */
2103 if (checksync && code_is_synchronized(code)) {
2104 /* stack offset for monitor argument */
2106 s1 = rd->memuse * 8;
2108 /* we need to save the proper return value */
2110 switch (iptr->opc) {
2114 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2116 M_STMFD(BITMASK_RESULT, REG_SP);
2121 M_LDR(REG_A0, REG_SP, s1);
2122 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2123 M_DSEG_BRANCH(disp);
2125 /* we no longer need PV here, no more loading */
2126 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2127 M_RECOMPUTE_PV(s1);*/
2129 switch (iptr->opc) {
2133 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2135 M_LDMFD(BITMASK_RESULT, REG_SP);
2141 /* deallocate stackframe for spilled variables */
2143 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2144 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2146 /* restore callee saved registers + do return */
2148 if (savedregs_bitmask) {
2149 if (!code_is_leafmethod(code)) {
2150 savedregs_bitmask &= ~(1<<REG_LR);
2151 savedregs_bitmask |= (1<<REG_PC);
2153 M_LDMFD(savedregs_bitmask, REG_SP);
2156 /* if LR was not on stack, we need to return manually */
2158 if (code_is_leafmethod(code))
2159 M_MOV(REG_PC, REG_LR);
2162 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2164 bte = iptr->sx.s23.s3.bte;
2166 goto ICMD_INVOKE_do;
2168 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2169 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2170 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2171 case ICMD_INVOKEINTERFACE:
2173 REPLACEMENT_POINT_INVOKE(cd, iptr);
2175 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2177 um = iptr->sx.s23.s3.um;
2178 md = um->methodref->parseddesc.md;
2181 lm = iptr->sx.s23.s3.fmiref->p.method;
2183 md = lm->parseddesc;
2187 /* copy arguments to registers or stack location */
2189 s3 = md->paramcount;
2191 MCODECHECK((s3 << 1) + 64);
2193 for (s3 = s3 - 1; s3 >= 0; s3--) {
2194 var = VAR(iptr->sx.s23.s2.args[s3]);
2195 d = md->params[s3].regoff;
2197 if (var->flags & PREALLOC) /* argument was precolored? */
2200 /* TODO: document me */
2201 #if !defined(ENABLE_SOFTFLOAT)
2202 if (IS_INT_LNG_TYPE(var->type)) {
2203 #endif /* !defined(ENABLE_SOFTFLOAT) */
2204 if (!md->params[s3].inmemory) {
2205 s1 = emit_load(jd, iptr, var, d);
2207 if (IS_2_WORD_TYPE(var->type))
2213 if (IS_2_WORD_TYPE(var->type)) {
2214 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2215 M_LST(s1, REG_SP, d);
2218 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2219 M_IST(s1, REG_SP, d);
2222 #if !defined(ENABLE_SOFTFLOAT)
2225 if (!md->params[s3].inmemory) {
2226 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2227 if (IS_2_WORD_TYPE(var->type))
2233 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2234 if (IS_2_WORD_TYPE(var->type))
2235 M_DST(s1, REG_SP, d);
2237 M_FST(s1, REG_SP, d);
2240 #endif /* !defined(ENABLE_SOFTFLOAT) */
2243 switch (iptr->opc) {
2246 if (bte->stub == NULL) {
2247 disp = dseg_add_functionptr(cd, bte->fp);
2249 disp = dseg_add_functionptr(cd, bte->stub);
2252 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2254 /* generate the actual call */
2256 M_MOV(REG_LR, REG_PC);
2257 M_MOV(REG_PC, REG_PV);
2258 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2262 case ICMD_INVOKESPECIAL:
2263 emit_nullpointer_check(cd, iptr, REG_A0);
2266 case ICMD_INVOKESTATIC:
2268 disp = dseg_add_unique_address(cd, NULL);
2270 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2274 disp = dseg_add_address(cd, lm->stubroutine);
2276 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2278 /* generate the actual call */
2280 M_MOV(REG_LR, REG_PC);
2281 M_MOV(REG_PC, REG_PV);
2282 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2286 case ICMD_INVOKEVIRTUAL:
2288 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2293 s1 = OFFSET(vftbl_t, table[0]) +
2294 sizeof(methodptr) * lm->vftblindex;
2296 /* implicit null-pointer check */
2297 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2298 OFFSET(java_object_t, vftbl));
2299 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2301 /* generate the actual call */
2303 M_MOV(REG_LR, REG_PC);
2304 M_MOV(REG_PC, REG_PV);
2305 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2309 case ICMD_INVOKEINTERFACE:
2311 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2317 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2318 sizeof(methodptr*) * lm->class->index;
2319 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2322 /* implicit null-pointer check */
2323 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2324 OFFSET(java_object_t, vftbl));
2325 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2326 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2328 /* generate the actual call */
2330 M_MOV(REG_LR, REG_PC);
2331 M_MOV(REG_PC, REG_PV);
2332 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2337 /* store size of call code in replacement point */
2338 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2340 /* store return value */
2342 d = md->returntype.type;
2344 #if !defined(__SOFTFP__)
2345 /* TODO: this is only a hack, since we use R0/R1 for float
2346 return! this depends on gcc; it is independent from
2347 our ENABLE_SOFTFLOAT define */
2348 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2349 #if 0 && !defined(NDEBUG)
2350 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2352 /* we cannot use this macro, since it is not defined
2353 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2354 REG_FRESULT, REG_RESULT_TYPED(d)); */
2355 if (IS_2_WORD_TYPE(d)) {
2356 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2357 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2359 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2360 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2365 if (d != TYPE_VOID) {
2366 #if !defined(ENABLE_SOFTFLOAT)
2367 if (IS_INT_LNG_TYPE(d)) {
2368 #endif /* !defined(ENABLE_SOFTFLOAT) */
2369 if (IS_2_WORD_TYPE(d)) {
2370 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2371 M_LNGMOVE(REG_RESULT_PACKED, s1);
2374 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2375 M_INTMOVE(REG_RESULT, s1);
2378 #if !defined(ENABLE_SOFTFLOAT)
2380 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2381 if (IS_2_WORD_TYPE(d))
2382 M_CAST_L2D(REG_RESULT_PACKED, s1);
2384 M_CAST_I2F(REG_RESULT, s1);
2386 #endif /* !defined(ENABLE_SOFTFLOAT) */
2388 emit_store_dst(jd, iptr, s1);
2392 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2394 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2395 /* object type cast-check */
2400 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2405 super = iptr->sx.s23.s3.c.cls;
2406 superindex = super->index;
2409 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2410 CODEGEN_CRITICAL_SECTION_NEW;
2412 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2414 /* if class is not resolved, check which code to call */
2416 if (super == NULL) {
2418 emit_label_beq(cd, BRANCH_LABEL_1);
2420 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2421 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2422 iptr->sx.s23.s3.c.ref, disp);
2424 M_DSEG_LOAD(REG_ITMP2, disp);
2425 disp = dseg_add_s4(cd, ACC_INTERFACE);
2426 M_DSEG_LOAD(REG_ITMP3, disp);
2427 M_TST(REG_ITMP2, REG_ITMP3);
2428 emit_label_beq(cd, BRANCH_LABEL_2);
2431 /* interface checkcast code */
2433 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2434 if ((super == NULL) || !IS_IMM(superindex)) {
2435 disp = dseg_add_unique_s4(cd, superindex);
2437 if (super == NULL) {
2438 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2439 iptr->sx.s23.s3.c.ref, disp);
2443 emit_label_beq(cd, BRANCH_LABEL_3);
2446 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2447 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2449 /* we put unresolved or non-immediate superindices onto dseg */
2450 if ((super == NULL) || !IS_IMM(superindex)) {
2451 /* disp was computed before we added the patcher */
2452 M_DSEG_LOAD(REG_ITMP2, disp);
2453 M_CMP(REG_ITMP3, REG_ITMP2);
2455 assert(IS_IMM(superindex));
2456 M_CMP_IMM(REG_ITMP3, superindex);
2459 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2461 /* if we loaded the superindex out of the dseg above, we do
2462 things differently here! */
2463 if ((super == NULL) || !IS_IMM(superindex)) {
2465 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2467 /* this assumes something */
2468 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2470 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2471 assert(sizeof(methodptr*) == 4);
2472 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2478 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2479 superindex * sizeof(methodptr*);
2483 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2484 M_TST(REG_ITMP3, REG_ITMP3);
2485 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2488 emit_label_br(cd, BRANCH_LABEL_4);
2490 emit_label(cd, BRANCH_LABEL_3);
2493 /* class checkcast code */
2495 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2496 if (super == NULL) {
2497 emit_label(cd, BRANCH_LABEL_2);
2499 disp = dseg_add_unique_address(cd, NULL);
2501 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2502 iptr->sx.s23.s3.c.ref,
2506 disp = dseg_add_address(cd, super->vftbl);
2509 emit_label_beq(cd, BRANCH_LABEL_5);
2512 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2513 M_DSEG_LOAD(REG_ITMP3, disp);
2515 CODEGEN_CRITICAL_SECTION_START;
2517 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2518 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2519 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2520 M_DSEG_LOAD(REG_ITMP3, disp);
2521 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2523 CODEGEN_CRITICAL_SECTION_END;
2525 M_CMP(REG_ITMP2, REG_ITMP3);
2526 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2529 emit_label(cd, BRANCH_LABEL_5);
2532 if (super == NULL) {
2533 emit_label(cd, BRANCH_LABEL_1);
2534 emit_label(cd, BRANCH_LABEL_4);
2537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2540 /* array type cast-check */
2542 s1 = emit_load_s1(jd, iptr, REG_A0);
2543 M_INTMOVE(s1, REG_A0);
2545 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2546 disp = dseg_add_unique_address(cd, NULL);
2548 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2549 iptr->sx.s23.s3.c.ref,
2553 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2555 M_DSEG_LOAD(REG_A1, disp);
2556 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2557 M_DSEG_BRANCH(disp);
2560 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2561 M_RECOMPUTE_PV(disp);
2563 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2564 M_TST(REG_RESULT, REG_RESULT);
2565 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2567 d = codegen_reg_of_dst(jd, iptr, s1);
2571 emit_store_dst(jd, iptr, d);
2574 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2580 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2585 super = iptr->sx.s23.s3.c.cls;
2586 superindex = super->index;
2589 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2590 CODEGEN_CRITICAL_SECTION_NEW;
2592 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2593 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2596 M_MOV(REG_ITMP1, s1);
2600 /* if class is not resolved, check which code to call */
2602 if (super == NULL) {
2606 emit_label_beq(cd, BRANCH_LABEL_1);
2608 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2609 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2610 iptr->sx.s23.s3.c.ref, disp);
2612 M_DSEG_LOAD(REG_ITMP2, disp);
2613 disp = dseg_add_s4(cd, ACC_INTERFACE);
2614 M_DSEG_LOAD(REG_ITMP3, disp);
2615 M_TST(REG_ITMP2, REG_ITMP3);
2616 emit_label_beq(cd, BRANCH_LABEL_2);
2619 /* interface checkcast code */
2621 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2622 if ((super == NULL) || !IS_IMM(superindex)) {
2623 disp = dseg_add_unique_s4(cd, superindex);
2625 if (super == NULL) {
2626 /* If d == REG_ITMP2, then it's destroyed in check
2631 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2632 iptr->sx.s23.s3.c.ref, disp);
2637 emit_label_beq(cd, BRANCH_LABEL_3);
2640 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2641 M_LDR_INTERN(REG_ITMP3,
2642 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2644 /* we put unresolved or non-immediate superindices onto dseg
2645 and do things slightly different */
2646 if ((super == NULL) || !IS_IMM(superindex)) {
2647 /* disp was computed before we added the patcher */
2648 M_DSEG_LOAD(REG_ITMP2, disp);
2649 M_CMP(REG_ITMP3, REG_ITMP2);
2651 if (d == REG_ITMP2) {
2658 /* this assumes something */
2659 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2661 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2662 assert(sizeof(methodptr*) == 4);
2663 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2665 if (d == REG_ITMP2) {
2672 assert(IS_IMM(superindex));
2673 M_CMP_IMM(REG_ITMP3, superindex);
2677 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2678 superindex * sizeof(methodptr*);
2682 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2683 M_TST(REG_ITMP3, REG_ITMP3);
2687 emit_label_br(cd, BRANCH_LABEL_4);
2689 emit_label(cd, BRANCH_LABEL_3);
2692 /* class checkcast code */
2694 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2695 if (super == NULL) {
2696 emit_label(cd, BRANCH_LABEL_2);
2698 disp = dseg_add_unique_address(cd, NULL);
2700 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2701 iptr->sx.s23.s3.c.ref, disp);
2704 disp = dseg_add_address(cd, super->vftbl);
2708 emit_label_beq(cd, BRANCH_LABEL_5);
2711 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2712 M_DSEG_LOAD(REG_ITMP2, disp);
2714 CODEGEN_CRITICAL_SECTION_START;
2716 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2717 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2718 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2720 CODEGEN_CRITICAL_SECTION_END;
2722 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2723 M_CMP(REG_ITMP1, REG_ITMP2);
2724 /* If d == REG_ITMP2, then it's destroyed */
2730 emit_label(cd, BRANCH_LABEL_5);
2733 if (super == NULL) {
2734 emit_label(cd, BRANCH_LABEL_1);
2735 emit_label(cd, BRANCH_LABEL_4);
2740 emit_store_dst(jd, iptr, d);
2743 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2745 /* copy sizes to stack if necessary */
2747 MCODECHECK((iptr->s1.argcount << 1) + 64);
2749 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2751 var = VAR(iptr->sx.s23.s2.args[s1]);
2753 /* copy SAVEDVAR sizes to stack */
2755 if (!(var->flags & PREALLOC)) {
2756 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2757 M_STR(s2, REG_SP, s1 * 4);
2761 /* a0 = dimension count */
2763 assert(IS_IMM(iptr->s1.argcount));
2764 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2766 /* is patcher function set? */
2768 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2769 disp = dseg_add_unique_address(cd, NULL);
2771 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2772 iptr->sx.s23.s3.c.ref, disp);
2775 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2777 /* a1 = arraydescriptor */
2779 M_DSEG_LOAD(REG_A1, disp);
2781 /* a2 = pointer to dimensions = stack pointer */
2783 M_INTMOVE(REG_SP, REG_A2);
2785 /* call builtin_multianewarray here */
2787 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2788 M_DSEG_BRANCH(disp);
2792 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2795 /* check for exception before result assignment */
2797 emit_exception_check(cd, iptr);
2801 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2802 M_INTMOVE(REG_RESULT, d);
2803 emit_store_dst(jd, iptr, d);
2806 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2808 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2809 emit_nullpointer_check(cd, iptr, s1);
2813 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2816 } /* the big switch */
2818 } /* for all instructions */
2820 } /* for all basic blocks */
2822 dseg_createlinenumbertable(cd);
2825 /* generate traps */
2827 emit_patcher_traps(jd);
2829 /* everything's ok */
2835 /* codegen_emit_stub_compiler **************************************************
2837 Emits a stub routine which calls the compiler.
2839 *******************************************************************************/
2841 void codegen_emit_stub_compiler(jitdata *jd)
2846 /* get required compiler data */
2851 /* code for the stub */
2853 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2854 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2858 /* codegen_emit_stub_native ****************************************************
2860 Emits a stub routine which calls a native method.
2862 *******************************************************************************/
2864 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2875 /* get required compiler data */
2881 /* initialize variables */
2885 /* calculate stackframe size */
2887 cd->stackframesize =
2888 4 + /* return address */
2889 sizeof(stackframeinfo_t) + /* stackframeinfo */
2890 sizeof(localref_table) + /* localref_table */
2891 nmd->memuse * 4; /* stack arguments */
2893 /* align stack to 8-byte */
2895 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2897 /* create method header */
2899 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2900 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2901 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2902 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2903 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2904 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2905 (void) dseg_addlinenumbertablesize(cd);
2906 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2908 /* generate stub code */
2910 M_STMFD(1<<REG_LR, REG_SP);
2911 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2913 #if !defined(NDEBUG)
2914 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2915 emit_verbosecall_enter(jd);
2918 #if defined(ENABLE_GC_CACAO)
2919 /* Save callee saved integer registers in stackframeinfo (GC may
2920 need to recover them during a collection). */
2922 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2923 OFFSET(stackframeinfo_t, intregs);
2925 for (i = 0; i < INT_SAV_CNT; i++)
2926 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2929 /* Save integer and float argument registers (these are 4
2930 registers, stack is 8-byte aligned). */
2932 M_STMFD(BITMASK_ARGS, REG_SP);
2933 /* TODO: floating point */
2935 /* create native stackframe info */
2937 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2938 M_MOV(REG_A1, REG_PV);
2939 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2940 M_DSEG_BRANCH(disp);
2944 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2947 /* remember class argument */
2949 if (m->flags & ACC_STATIC)
2950 M_MOV(REG_ITMP3, REG_RESULT);
2952 /* Restore integer and float argument registers (these are 4
2953 registers, stack is 8-byte aligned). */
2955 M_LDMFD(BITMASK_ARGS, REG_SP);
2956 /* TODO: floating point */
2958 /* copy or spill arguments to new locations */
2959 /* ATTENTION: the ARM has only integer argument registers! */
2961 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2962 t = md->paramtypes[i].type;
2964 if (!md->params[i].inmemory) {
2965 s1 = md->params[i].regoff;
2966 s2 = nmd->params[j].regoff;
2968 if (!nmd->params[j].inmemory) {
2969 #if !defined(__ARM_EABI__)
2970 SPLIT_OPEN(t, s2, REG_ITMP1);
2973 if (IS_2_WORD_TYPE(t))
2978 #if !defined(__ARM_EABI__)
2979 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2983 if (IS_2_WORD_TYPE(t))
2984 M_LST(s1, REG_SP, s2);
2986 M_IST(s1, REG_SP, s2);
2990 s1 = md->params[i].regoff + cd->stackframesize;
2991 s2 = nmd->params[j].regoff;
2993 if (IS_2_WORD_TYPE(t)) {
2994 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2995 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2998 M_ILD(REG_ITMP1, REG_SP, s1);
2999 M_IST(REG_ITMP1, REG_SP, s2);
3004 /* Handle native Java methods. */
3006 if (m->flags & ACC_NATIVE) {
3007 /* put class into second argument register */
3009 if (m->flags & ACC_STATIC)
3010 M_MOV(REG_A1, REG_ITMP3);
3012 /* put env into first argument register */
3014 disp = dseg_add_address(cd, _Jv_env);
3015 M_DSEG_LOAD(REG_A0, disp);
3018 /* Call the native function. */
3020 disp = dseg_add_functionptr(cd, f);
3021 M_DSEG_BRANCH(disp);
3024 /* TODO: this is only needed because of the tracer ... do we
3027 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3030 #if !defined(__SOFTFP__)
3031 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3032 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3033 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3034 #if 0 && !defined(NDEBUG)
3035 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3037 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3038 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3039 if (IS_2_WORD_TYPE(md->returntype.type)) {
3040 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3041 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3043 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3044 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3049 #if !defined(NDEBUG)
3050 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3051 emit_verbosecall_exit(jd);
3054 /* remove native stackframe info */
3055 /* TODO: improve this store/load */
3057 M_STMFD(BITMASK_RESULT, REG_SP);
3059 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3060 M_MOV(REG_A1, REG_PV);
3061 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3062 M_DSEG_BRANCH(disp);
3063 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3066 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3067 M_LDMFD(BITMASK_RESULT, REG_SP);
3069 #if defined(ENABLE_GC_CACAO)
3070 /* restore callee saved int registers from stackframeinfo (GC might have */
3071 /* modified them during a collection). */
3073 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3074 OFFSET(stackframeinfo_t, intregs);
3076 for (i = 0; i < INT_SAV_CNT; i++)
3077 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3080 /* finish stub code, but do not yet return to caller */
3082 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3083 M_LDMFD(1<<REG_LR, REG_SP);
3085 /* check for exception */
3087 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3088 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3090 /* handle exception here */
3092 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3094 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3095 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3096 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3098 /* generate patcher stubs */
3100 emit_patcher_traps(jd);
3104 /* asm_debug *******************************************************************
3108 *******************************************************************************/
3110 void asm_debug(int a1, int a2, int a3, int a4)
3112 printf("===> i am going to exit after this debugging message!\n");
3113 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3114 vm_abort("leave you now");
3119 * These are local overrides for various environment variables in Emacs.
3120 * Please do not remove this and leave it at the end of the file, where
3121 * Emacs will automagically detect them.
3122 * ---------------------------------------------------------------------
3125 * indent-tabs-mode: t
3129 * vim:noexpandtab:sw=4:ts=4: