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 */
390 case ICMD_NOP: /* ... ==> ... */
393 /* constant operations ************************************************/
395 case ICMD_ICONST: /* ... ==> ..., constant */
397 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
398 ICONST(d, iptr->sx.val.i);
399 emit_store_dst(jd, iptr, d);
402 case ICMD_ACONST: /* ... ==> ..., constant */
404 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
405 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
406 disp = dseg_add_unique_address(cd, NULL);
408 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
409 iptr->sx.val.c.ref, disp);
411 M_DSEG_LOAD(d, disp);
414 ICONST(d, (u4) iptr->sx.val.anyptr);
416 emit_store_dst(jd, iptr, d);
419 case ICMD_LCONST: /* ... ==> ..., constant */
421 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
422 LCONST(d, iptr->sx.val.l);
423 emit_store_dst(jd, iptr, d);
426 case ICMD_FCONST: /* ... ==> ..., constant */
428 #if defined(ENABLE_SOFTFLOAT)
429 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
430 ICONST(d, iptr->sx.val.i);
431 emit_store_dst(jd, iptr, d);
433 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
434 FCONST(d, iptr->sx.val.f);
435 emit_store_dst(jd, iptr, d);
439 case ICMD_DCONST: /* ... ==> ..., constant */
441 #if defined(ENABLE_SOFTFLOAT)
442 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
443 LCONST(d, iptr->sx.val.l);
444 emit_store_dst(jd, iptr, d);
446 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
447 DCONST(d, iptr->sx.val.d);
448 emit_store_dst(jd, iptr, d);
453 /* load/store/copy/move operations ************************************/
455 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
456 case ICMD_ALOAD: /* op1 = local variable */
460 case ICMD_ISTORE: /* ..., value ==> ... */
471 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
475 /* pop operations *****************************************************/
477 /* attention: double and longs are only one entry in CACAO ICMDs */
479 case ICMD_POP: /* ..., value ==> ... */
480 case ICMD_POP2: /* ..., value, value ==> ... */
485 /* integer operations *************************************************/
487 case ICMD_INT2BYTE: /* ..., 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, 24));
492 M_MOV(d, REG_ASR(d, 24));
493 emit_store_dst(jd, iptr, d);
496 case ICMD_INT2CHAR: /* ..., 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_LSR(d, 16)); /* ATTENTION: char is unsigned */
502 emit_store_dst(jd, iptr, d);
505 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
507 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
508 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
509 M_MOV(d, REG_LSL(s1, 16));
510 M_MOV(d, REG_ASR(d, 16));
511 emit_store_dst(jd, iptr, d);
514 case ICMD_I2L: /* ..., value ==> ..., value */
516 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
517 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
518 M_INTMOVE(s1, GET_LOW_REG(d));
519 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
520 emit_store_dst(jd, iptr, d);
523 case ICMD_L2I: /* ..., value ==> ..., value */
525 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
526 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
528 emit_store_dst(jd, iptr, d);
531 case ICMD_INEG: /* ..., value ==> ..., - value */
533 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
534 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
536 emit_store_dst(jd, iptr, d);
539 case ICMD_LNEG: /* ..., value ==> ..., - value */
541 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
542 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
543 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
544 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
545 emit_store_dst(jd, iptr, d);
548 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
550 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
551 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
552 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
554 emit_store_dst(jd, iptr, d);
557 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
559 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
560 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
561 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
562 M_ADD_S(GET_LOW_REG(d), s1, s2);
563 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
564 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
565 M_ADC(GET_HIGH_REG(d), s1, s2);
566 emit_store_dst(jd, iptr, d);
572 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
573 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
575 if (IS_IMM(iptr->sx.val.i)) {
576 M_ADD_IMM(d, s1, iptr->sx.val.i);
577 } else if (IS_IMM(-iptr->sx.val.i)) {
578 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
580 ICONST(REG_ITMP3, iptr->sx.val.i);
581 M_ADD(d, s1, REG_ITMP3);
584 emit_store_dst(jd, iptr, d);
587 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
588 /* sx.val.l = constant */
590 s3 = iptr->sx.val.l & 0xffffffff;
591 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
592 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
594 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
596 ICONST(REG_ITMP3, s3);
597 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
599 s3 = iptr->sx.val.l >> 32;
600 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
602 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
604 ICONST(REG_ITMP3, s3);
605 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
607 emit_store_dst(jd, iptr, d);
610 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
612 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
613 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
614 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
616 emit_store_dst(jd, iptr, d);
619 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
621 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
622 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
623 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
624 M_SUB_S(GET_LOW_REG(d), s1, s2);
625 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
626 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
627 M_SBC(GET_HIGH_REG(d), s1, s2);
628 emit_store_dst(jd, iptr, d);
631 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
632 /* sx.val.i = constant */
634 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
635 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
636 if (IS_IMM(iptr->sx.val.i))
637 M_SUB_IMM(d, s1, iptr->sx.val.i);
639 ICONST(REG_ITMP3, iptr->sx.val.i);
640 M_SUB(d, s1, REG_ITMP3);
642 emit_store_dst(jd, iptr, d);
645 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
646 /* sx.val.l = constant */
648 s3 = iptr->sx.val.l & 0xffffffff;
649 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
650 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
652 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
654 ICONST(REG_ITMP3, s3);
655 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
657 s3 = iptr->sx.val.l >> 32;
658 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
660 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
662 ICONST(REG_ITMP3, s3);
663 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
665 emit_store_dst(jd, iptr, d);
668 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
670 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
671 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
672 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
674 emit_store_dst(jd, iptr, d);
677 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
678 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
680 s1 = emit_load_s1(jd, iptr, REG_A0);
681 s2 = emit_load_s2(jd, iptr, REG_A1);
682 emit_arithmetic_check(cd, iptr, s2);
684 /* move arguments into argument registers */
685 M_INTMOVE(s1, REG_A0);
686 M_INTMOVE(s2, REG_A1);
688 /* call builtin function */
689 bte = iptr->sx.s23.s3.bte;
690 disp = dseg_add_functionptr(cd, bte->fp);
694 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
697 /* move result into destination register */
698 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
699 M_INTMOVE(REG_RESULT, d);
700 emit_store_dst(jd, iptr, d);
703 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
704 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
706 /* move arguments into argument registers */
708 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
709 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
710 /* XXX TODO: only do this if arithmetic check is really done! */
711 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
712 emit_arithmetic_check(cd, iptr, REG_ITMP3);
714 M_LNGMOVE(s1, REG_A0_A1_PACKED);
715 M_LNGMOVE(s2, REG_A2_A3_PACKED);
717 /* call builtin function */
718 bte = iptr->sx.s23.s3.bte;
719 disp = dseg_add_functionptr(cd, bte->fp);
723 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
726 /* move result into destination register */
727 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
728 M_LNGMOVE(REG_RESULT_PACKED, d);
729 emit_store_dst(jd, iptr, d);
732 case ICMD_IMULPOW2: /* ..., 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 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
738 emit_store_dst(jd, iptr, d);
741 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
742 /* sx.val.i = constant */
744 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
745 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
746 /* this rounds towards 0 as java likes it */
747 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
748 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
749 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
750 /* this rounds towards nearest, not java style */
751 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
752 M_ADCMI_IMM(d, d, 0);*/
753 emit_store_dst(jd, iptr, d);
756 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
757 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
759 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
760 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
761 M_MOV_S(REG_ITMP1, s1);
762 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
763 if (IS_IMM(iptr->sx.val.i))
764 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
766 ICONST(REG_ITMP3, iptr->sx.val.i);
767 M_AND(REG_ITMP1, REG_ITMP3, d);
769 M_RSBMI_IMM(d, d, 0);
770 emit_store_dst(jd, iptr, d);
773 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
775 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
776 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
777 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
778 M_AND_IMM(s2, 0x1f, REG_ITMP2);
779 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
780 emit_store_dst(jd, iptr, d);
783 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
785 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
786 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
787 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
788 M_AND_IMM(s2, 0x1f, REG_ITMP2);
789 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
790 emit_store_dst(jd, iptr, d);
793 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
795 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
796 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
797 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
798 M_AND_IMM(s2, 0x1f, REG_ITMP2);
799 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
800 emit_store_dst(jd, iptr, d);
803 case ICMD_ISHLCONST: /* ..., 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_ITMP2);
808 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
809 emit_store_dst(jd, iptr, d);
812 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
813 /* sx.val.i = constant */
815 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
816 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
817 /* we need to check for zero here because arm interprets it as SHR by 32 */
818 if ((iptr->sx.val.i & 0x1f) == 0) {
821 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
823 emit_store_dst(jd, iptr, d);
826 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
827 /* sx.val.i = constant */
829 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
830 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
831 /* we need to check for zero here because arm interprets it as SHR by 32 */
832 if ((iptr->sx.val.i & 0x1f) == 0)
835 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
836 emit_store_dst(jd, iptr, d);
839 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
841 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
842 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
843 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
845 emit_store_dst(jd, iptr, d);
848 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
850 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
851 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
852 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
853 M_AND(s1, s2, GET_LOW_REG(d));
854 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
855 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
856 M_AND(s1, s2, GET_HIGH_REG(d));
857 emit_store_dst(jd, iptr, d);
860 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
862 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
863 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
864 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
866 emit_store_dst(jd, iptr, d);
869 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
871 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
872 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
873 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
874 M_ORR(s1, s2, GET_LOW_REG(d));
875 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
876 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
877 M_ORR(s1, s2, GET_HIGH_REG(d));
878 emit_store_dst(jd, iptr, d);
881 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
883 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
884 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
885 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
887 emit_store_dst(jd, iptr, d);
890 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
892 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
893 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
894 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
895 M_EOR(s1, s2, GET_LOW_REG(d));
896 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
897 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
898 M_EOR(s1, s2, GET_HIGH_REG(d));
899 emit_store_dst(jd, iptr, d);
903 /* floating operations ************************************************/
905 #if !defined(ENABLE_SOFTFLOAT)
907 case ICMD_FNEG: /* ..., value ==> ..., - value */
909 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
910 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
912 emit_store_dst(jd, iptr, d);
915 case ICMD_FADD: /* ..., 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_FSUB: /* ..., 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_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
935 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
936 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
937 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
939 emit_store_dst(jd, iptr, d);
942 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
943 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
944 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
945 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
947 emit_store_dst(jd, iptr, d);
950 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
954 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
956 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
957 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
958 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
960 emit_store_dst(jd, iptr, d);
964 case ICMD_DNEG: /* ..., value ==> ..., - value */
966 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
967 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
969 emit_store_dst(jd, iptr, d);
972 case ICMD_DADD: /* ..., 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_DSUB: /* ..., 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_DMUL: /* ..., 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 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1001 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1002 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1003 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1005 emit_store_dst(jd, iptr, d);
1008 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1012 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1014 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1015 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1016 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1018 emit_store_dst(jd, iptr, d);
1022 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1024 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1025 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1027 emit_store_dst(jd, iptr, d);
1030 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1032 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1033 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1035 emit_store_dst(jd, iptr, d);
1038 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1040 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1041 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1042 /* this uses round towards zero, as Java likes it */
1044 #if !defined(__VFP_FP__)
1045 /* this checks for NaN; to return zero as Java likes it */
1049 emit_store_dst(jd, iptr, d);
1052 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1054 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1055 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1056 /* this uses round towards zero, as Java likes it */
1058 #if !defined(__VFP_FP__)
1059 /* this checks for NaN; to return zero as Java likes it */
1063 emit_store_dst(jd, iptr, d);
1066 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1068 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1069 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1071 emit_store_dst(jd, iptr, d);
1074 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1076 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1077 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1079 emit_store_dst(jd, iptr, d);
1082 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1084 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1085 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1086 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1089 #if defined(__VFP_FP__)
1090 M_FMSTAT; /* on VFP we need to transfer the flags */
1092 M_SUBGT_IMM(d, d, 1);
1093 M_ADDLT_IMM(d, d, 1);
1094 emit_store_dst(jd, iptr, d);
1097 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1099 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1100 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1101 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1104 #if defined(__VFP_FP__)
1105 M_FMSTAT; /* on VFP we need to transfer the flags */
1107 M_SUBGT_IMM(d, d, 1);
1108 M_ADDLT_IMM(d, d, 1);
1109 emit_store_dst(jd, iptr, d);
1112 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1114 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1115 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1116 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1119 #if defined(__VFP_FP__)
1120 M_FMSTAT; /* on VFP we need to transfer the flags */
1122 M_SUBLT_IMM(d, d, 1);
1123 M_ADDGT_IMM(d, d, 1);
1124 emit_store_dst(jd, iptr, d);
1127 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1129 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1130 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1131 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1134 #if defined(__VFP_FP__)
1135 M_FMSTAT; /* on VFP we need to transfer the flags */
1137 M_SUBLT_IMM(d, d, 1);
1138 M_ADDGT_IMM(d, d, 1);
1139 emit_store_dst(jd, iptr, d);
1142 #endif /* !defined(ENABLE_SOFTFLOAT) */
1145 /* memory operations **************************************************/
1147 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1149 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1150 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1151 /* implicit null-pointer check */
1152 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1153 emit_store_dst(jd, iptr, d);
1156 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1158 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1159 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1160 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1161 /* implicit null-pointer check */
1162 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1163 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1164 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1165 emit_store_dst(jd, iptr, d);
1168 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1170 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1171 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1172 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1173 /* implicit null-pointer check */
1174 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1175 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1176 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1177 emit_store_dst(jd, iptr, d);
1180 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1182 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1183 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1184 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1185 /* implicit null-pointer check */
1186 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1187 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1188 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1189 emit_store_dst(jd, iptr, d);
1192 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1194 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1195 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1196 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1197 /* implicit null-pointer check */
1198 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1199 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1200 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1201 emit_store_dst(jd, iptr, d);
1204 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1206 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1207 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1208 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1209 /* implicit null-pointer check */
1210 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1211 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1212 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1213 emit_store_dst(jd, iptr, d);
1216 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1218 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1219 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1220 /* implicit null-pointer check */
1221 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1222 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1223 #if !defined(ENABLE_SOFTFLOAT)
1224 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1225 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1227 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1228 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1230 emit_store_dst(jd, iptr, d);
1233 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1235 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1236 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1237 /* implicit null-pointer check */
1238 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1239 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1240 #if !defined(ENABLE_SOFTFLOAT)
1241 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1242 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1244 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1245 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1247 emit_store_dst(jd, iptr, d);
1250 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1252 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1253 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1254 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1255 /* implicit null-pointer check */
1256 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1257 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1258 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1259 emit_store_dst(jd, iptr, d);
1262 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1264 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1265 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1266 /* implicit null-pointer check */
1267 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1268 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1269 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1270 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1273 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1275 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1276 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1277 /* implicit null-pointer check */
1278 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1279 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1280 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1281 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1284 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1286 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1287 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1288 /* implicit null-pointer check */
1289 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1290 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1291 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1292 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1295 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1297 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1298 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1299 /* implicit null-pointer check */
1300 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1301 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1302 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1303 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1306 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1308 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1309 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1310 /* implicit null-pointer check */
1311 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1312 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1313 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1314 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1317 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1319 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1320 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1321 /* implicit null-pointer check */
1322 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1323 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1324 #if !defined(ENABLE_SOFTFLOAT)
1325 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1326 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1328 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1329 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1333 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1335 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1336 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1337 /* implicit null-pointer check */
1338 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1339 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1340 #if !defined(ENABLE_SOFTFLOAT)
1341 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1342 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1344 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1345 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1349 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1351 s1 = emit_load_s1(jd, iptr, REG_A0);
1352 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1353 s3 = emit_load_s3(jd, iptr, REG_A1);
1355 /* implicit null-pointer check */
1356 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1358 /* move arguments to argument registers */
1359 M_INTMOVE(s1, REG_A0);
1360 M_INTMOVE(s3, REG_A1);
1362 /* call builtin function */
1363 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1364 M_DSEG_BRANCH(disp);
1367 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1370 /* check resturn value of builtin */
1371 emit_arraystore_check(cd, iptr);
1373 /* finally store address into array */
1374 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1375 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1376 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1377 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1378 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1381 case ICMD_GETSTATIC: /* ... ==> ..., value */
1383 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1384 uf = iptr->sx.s23.s3.uf;
1385 fieldtype = uf->fieldref->parseddesc.fd->type;
1386 disp = dseg_add_unique_address(cd, NULL);
1388 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1391 fi = iptr->sx.s23.s3.fmiref->p.field;
1392 fieldtype = fi->type;
1393 disp = dseg_add_address(cd, fi->value);
1395 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1396 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1401 M_DSEG_LOAD(REG_ITMP3, disp);
1402 switch (fieldtype) {
1404 #if defined(ENABLE_SOFTFLOAT)
1408 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1409 M_ILD_INTERN(d, REG_ITMP3, 0);
1412 #if defined(ENABLE_SOFTFLOAT)
1415 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1416 M_LLD_INTERN(d, REG_ITMP3, 0);
1418 #if !defined(ENABLE_SOFTFLOAT)
1420 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1421 M_FLD_INTERN(d, REG_ITMP3, 0);
1424 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1425 M_DLD_INTERN(d, REG_ITMP3, 0);
1431 emit_store_dst(jd, iptr, d);
1434 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1436 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1437 uf = iptr->sx.s23.s3.uf;
1438 fieldtype = uf->fieldref->parseddesc.fd->type;
1439 disp = dseg_add_unique_address(cd, NULL);
1441 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1444 fi = iptr->sx.s23.s3.fmiref->p.field;
1445 fieldtype = fi->type;
1446 disp = dseg_add_address(cd, fi->value);
1448 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1449 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1454 M_DSEG_LOAD(REG_ITMP3, disp);
1455 switch (fieldtype) {
1457 #if defined(ENABLE_SOFTFLOAT)
1461 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1462 M_IST_INTERN(s1, REG_ITMP3, 0);
1465 #if defined(ENABLE_SOFTFLOAT)
1468 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1469 M_LST_INTERN(s1, REG_ITMP3, 0);
1471 #if !defined(ENABLE_SOFTFLOAT)
1473 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1474 M_FST_INTERN(s1, REG_ITMP3, 0);
1477 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1478 M_DST_INTERN(s1, REG_ITMP3, 0);
1486 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1488 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1489 emit_nullpointer_check(cd, iptr, s1);
1492 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1493 uf = iptr->sx.s23.s3.uf;
1494 fieldtype = uf->fieldref->parseddesc.fd->type;
1498 fi = iptr->sx.s23.s3.fmiref->p.field;
1499 fieldtype = fi->type;
1503 #if !defined(ENABLE_SOFTFLOAT)
1504 /* HACK: softnull checks on floats */
1505 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1506 emit_nullpointer_check_force(cd, iptr, s1);
1509 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1511 uf = iptr->sx.s23.s3.uf;
1513 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1516 switch (fieldtype) {
1518 #if defined(ENABLE_SOFTFLOAT)
1522 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1526 #if defined(ENABLE_SOFTFLOAT)
1529 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1532 #if !defined(ENABLE_SOFTFLOAT)
1534 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1538 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1545 emit_store_dst(jd, iptr, d);
1548 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1550 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1551 emit_nullpointer_check(cd, iptr, s1);
1553 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1554 uf = iptr->sx.s23.s3.uf;
1555 fieldtype = uf->fieldref->parseddesc.fd->type;
1559 fi = iptr->sx.s23.s3.fmiref->p.field;
1560 fieldtype = fi->type;
1564 #if !defined(ENABLE_SOFTFLOAT)
1565 /* HACK: softnull checks on floats */
1566 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1567 emit_nullpointer_check_force(cd, iptr, s1);
1570 switch (fieldtype) {
1572 #if defined(ENABLE_SOFTFLOAT)
1576 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1578 #if defined(ENABLE_SOFTFLOAT)
1579 case TYPE_DBL: /* fall through */
1582 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1584 #if !defined(ENABLE_SOFTFLOAT)
1587 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1594 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1596 uf = iptr->sx.s23.s3.uf;
1598 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1601 switch (fieldtype) {
1603 #if defined(ENABLE_SOFTFLOAT)
1607 M_IST(s2, s1, disp);
1610 #if defined(ENABLE_SOFTFLOAT)
1613 M_LST(s2, s1, disp);
1615 #if !defined(ENABLE_SOFTFLOAT)
1617 M_FST(s2, s1, disp);
1620 M_DST(s2, s1, disp);
1629 /* branch operations **************************************************/
1631 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1633 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1634 M_INTMOVE(s1, REG_ITMP1_XPTR);
1635 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1636 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1637 iptr->sx.s23.s2.uc, 0);
1639 disp = dseg_add_functionptr(cd, asm_handle_exception);
1640 M_DSEG_LOAD(REG_ITMP3, disp);
1641 M_MOV(REG_ITMP2_XPC, REG_PC);
1642 M_MOV(REG_PC, REG_ITMP3);
1643 M_NOP; /* nop ensures that XPC is less than the end */
1644 /* of basic block */
1647 case ICMD_GOTO: /* ... ==> ... */
1650 emit_br(cd, iptr->dst.block);
1653 case ICMD_JSR: /* ... ==> ... */
1655 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1658 case ICMD_IFNULL: /* ..., value ==> ... */
1659 case ICMD_IFNONNULL:
1661 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1663 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1666 case ICMD_IFLT: /* ..., value ==> ... */
1667 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1673 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1674 M_COMPARE(s1, iptr->sx.val.i);
1675 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1678 case ICMD_IF_LEQ: /* ..., value ==> ... */
1680 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1681 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1682 if (iptr->sx.val.l == 0) {
1683 M_ORR_S(s1, s2, REG_ITMP3);
1686 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1687 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1688 M_CMP(s1, REG_ITMP3);*/
1689 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1690 M_CMPEQ(s2, REG_ITMP3);
1692 emit_beq(cd, iptr->dst.block);
1695 case ICMD_IF_LLT: /* ..., value ==> ... */
1697 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1698 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1699 if (iptr->sx.val.l == 0) {
1700 /* if high word is less than zero, the whole long is too */
1702 emit_blt(cd, iptr->dst.block);
1705 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1706 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1707 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1708 M_CMP(s1, REG_ITMP3);*/
1709 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1710 M_MOVGT_IMM(2, REG_ITMP1);
1711 M_MOVEQ_IMM(1, REG_ITMP1);
1713 /* low compare: x=x-1(ifLO) */
1714 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1715 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1716 M_CMP(s2, REG_ITMP3);*/
1717 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1719 /* branch if (x LT 1) */
1720 M_CMP_IMM(REG_ITMP1, 1);
1721 emit_blt(cd, iptr->dst.block);
1725 case ICMD_IF_LLE: /* ..., value ==> ... */
1727 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1728 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1729 if (iptr->sx.val.l == 0) {
1730 /* if high word is less than zero, the whole long is too */
1732 emit_blt(cd, iptr->dst.block);
1734 /* ... otherwise the low word has to be zero (tricky!) */
1736 emit_beq(cd, iptr->dst.block);
1739 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1740 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1741 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1742 M_CMP(s1, REG_ITMP3);*/
1743 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1744 M_MOVGT_IMM(2, REG_ITMP1);
1745 M_MOVEQ_IMM(1, REG_ITMP1);
1747 /* low compare: x=x+1(ifHI) */
1748 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1749 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1750 M_CMP(s2, REG_ITMP3);*/
1751 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1753 /* branch if (x LE 1) */
1754 M_CMP_IMM(REG_ITMP1, 1);
1755 emit_ble(cd, iptr->dst.block);
1759 case ICMD_IF_LGE: /* ..., value ==> ... */
1761 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1762 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1763 if (iptr->sx.val.l == 0) {
1764 /* if high word is greater or equal zero, the whole long is too */
1766 emit_bge(cd, iptr->dst.block);
1769 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1770 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1771 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1772 M_CMP(s1, REG_ITMP3);*/
1773 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1774 M_MOVGT_IMM(2, REG_ITMP1);
1775 M_MOVEQ_IMM(1, REG_ITMP1);
1777 /* low compare: x=x-1(ifLO) */
1778 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1779 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1780 M_CMP(s2, REG_ITMP3);*/
1781 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1783 /* branch if (x GE 1) */
1784 M_CMP_IMM(REG_ITMP1, 1);
1785 emit_bge(cd, iptr->dst.block);
1789 case ICMD_IF_LGT: /* ..., value ==> ... */
1791 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1792 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1794 if (iptr->sx.val.l == 0) {
1795 /* if high word is greater than zero, the whole long is too */
1798 codegen_add_branch_ref(cd, iptr->dst.block);
1800 /* ... or high was zero and low is non zero (tricky!) */
1801 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1802 M_MOVLT_IMM(1, REG_ITMP3);
1803 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1805 codegen_add_branch_ref(cd, iptr->dst.block);
1809 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1810 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1811 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1812 M_CMP(s1, REG_ITMP3);*/
1813 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1814 M_MOVGT_IMM(2, REG_ITMP1);
1815 M_MOVEQ_IMM(1, REG_ITMP1);
1817 /* low compare: x=x+1(ifHI) */
1818 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1819 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1820 M_CMP(s2, REG_ITMP3);*/
1821 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1823 /* branch if (x GT 1) */
1824 M_CMP_IMM(REG_ITMP1, 1);
1825 emit_bgt(cd, iptr->dst.block);
1831 case ICMD_IF_LNE: /* ..., value ==> ... */
1833 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1834 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1835 if (iptr->sx.val.l == 0) {
1836 M_ORR_S(s1, s2, REG_ITMP3);
1839 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1840 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1841 M_CMP(s1, REG_ITMP3);*/
1842 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1843 M_CMPEQ(s2, REG_ITMP3);
1845 emit_bne(cd, iptr->dst.block);
1848 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1849 case ICMD_IF_ICMPNE:
1850 case ICMD_IF_ICMPLT:
1851 case ICMD_IF_ICMPLE:
1852 case ICMD_IF_ICMPGT:
1853 case ICMD_IF_ICMPGE:
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_ICMPEQ, BRANCH_OPT_NONE);
1861 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1862 case ICMD_IF_ACMPNE:
1864 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1865 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1867 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1870 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1871 /* op1 = target JavaVM pc */
1873 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1874 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1877 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1878 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1881 emit_beq(cd, iptr->dst.block);
1884 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1885 /* op1 = target JavaVM pc */
1887 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1888 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1891 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1892 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1895 emit_bne(cd, iptr->dst.block);
1898 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1899 /* op1 = target JavaVM pc */
1901 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1902 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1903 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1905 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1906 M_MOVGT_IMM(2, REG_ITMP3);
1907 M_MOVEQ_IMM(1, REG_ITMP3);
1909 /* low compare: x=x-1(ifLO) */
1910 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1911 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1913 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1915 /* branch if (x LT 1) */
1916 M_CMP_IMM(REG_ITMP3, 1);
1917 emit_blt(cd, iptr->dst.block);
1920 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1921 /* op1 = target JavaVM pc */
1923 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1924 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1925 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1927 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1928 M_MOVGT_IMM(2, REG_ITMP3);
1929 M_MOVEQ_IMM(1, REG_ITMP3);
1931 /* low compare: x=x-1(ifLO) */
1932 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1933 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1935 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1937 /* branch if (x LE 1) */
1938 M_CMP_IMM(REG_ITMP3, 1);
1939 emit_ble(cd, iptr->dst.block);
1942 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1943 /* op1 = target JavaVM pc */
1945 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1946 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1947 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1949 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1950 M_MOVGT_IMM(2, REG_ITMP3);
1951 M_MOVEQ_IMM(1, REG_ITMP3);
1953 /* low compare: x=x-1(ifLO) */
1954 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1955 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1957 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1959 /* branch if (x GT 1) */
1960 M_CMP_IMM(REG_ITMP3, 1);
1961 emit_bgt(cd, iptr->dst.block);
1964 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1965 /* op1 = target JavaVM pc */
1967 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1968 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1969 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1971 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1972 M_MOVGT_IMM(2, REG_ITMP3);
1973 M_MOVEQ_IMM(1, REG_ITMP3);
1975 /* low compare: x=x-1(ifLO) */
1976 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1977 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1979 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1981 /* branch if (x GE 1) */
1982 M_CMP_IMM(REG_ITMP3, 1);
1983 emit_bge(cd, iptr->dst.block);
1986 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1989 branch_target_t *table;
1991 table = iptr->dst.table;
1993 l = iptr->sx.s23.s2.tablelow;
1994 i = iptr->sx.s23.s3.tablehigh;
1996 /* calculate new index (index - low) */
1997 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1999 M_INTMOVE(s1, REG_ITMP1);
2000 } else if (IS_IMM(l)) {
2001 M_SUB_IMM(REG_ITMP1, s1, l);
2003 ICONST(REG_ITMP2, l);
2004 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2007 /* range check (index <= high-low) */
2009 M_COMPARE(REG_ITMP1, i-1);
2010 emit_bugt(cd, table[0].block);
2012 /* build jump table top down and use address of lowest entry */
2017 dseg_add_target(cd, table->block);
2022 /* length of dataseg after last dseg_add_target is used by load */
2023 /* TODO: this loads from data-segment */
2024 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2025 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2028 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2031 lookup_target_t *lookup;
2033 lookup = iptr->dst.lookup;
2035 i = iptr->sx.s23.s2.lookupcount;
2038 MCODECHECK((i<<2)+8);
2039 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2042 M_COMPARE(s1, lookup->value);
2043 emit_beq(cd, lookup->target.block);
2047 /* default branch */
2048 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2052 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2054 #if !defined(ENABLE_SOFTFLOAT)
2055 REPLACEMENT_POINT_RETURN(cd, iptr);
2056 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2057 M_CAST_F2I(s1, REG_RESULT);
2058 goto ICMD_RETURN_do;
2061 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2063 REPLACEMENT_POINT_RETURN(cd, iptr);
2064 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2065 M_INTMOVE(s1, REG_RESULT);
2066 goto ICMD_RETURN_do;
2068 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2070 #if !defined(ENABLE_SOFTFLOAT)
2071 REPLACEMENT_POINT_RETURN(cd, iptr);
2072 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2073 M_CAST_D2L(s1, REG_RESULT_PACKED);
2074 goto ICMD_RETURN_do;
2077 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2079 REPLACEMENT_POINT_RETURN(cd, iptr);
2080 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2081 M_LNGMOVE(s1, REG_RESULT_PACKED);
2082 goto ICMD_RETURN_do;
2084 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2086 REPLACEMENT_POINT_RETURN(cd, iptr);
2087 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2088 M_INTMOVE(s1, REG_RESULT);
2089 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2090 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2091 iptr->sx.s23.s2.uc, 0);
2093 goto ICMD_RETURN_do;
2095 case ICMD_RETURN: /* ... ==> ... */
2097 REPLACEMENT_POINT_RETURN(cd, iptr);
2100 #if !defined(NDEBUG)
2101 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2102 emit_verbosecall_exit(jd);
2105 #if defined(ENABLE_THREADS)
2106 /* call monitorexit function */
2108 if (checksync && code_is_synchronized(code)) {
2109 /* stack offset for monitor argument */
2111 s1 = rd->memuse * 8;
2113 /* we need to save the proper return value */
2115 switch (iptr->opc) {
2119 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2121 M_STMFD(BITMASK_RESULT, REG_SP);
2126 M_LDR(REG_A0, REG_SP, s1);
2127 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2128 M_DSEG_BRANCH(disp);
2130 /* we no longer need PV here, no more loading */
2131 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2132 M_RECOMPUTE_PV(s1);*/
2134 switch (iptr->opc) {
2138 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2140 M_LDMFD(BITMASK_RESULT, REG_SP);
2146 /* deallocate stackframe for spilled variables */
2148 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2149 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2151 /* restore callee saved registers + do return */
2153 if (savedregs_bitmask) {
2154 if (!code_is_leafmethod(code)) {
2155 savedregs_bitmask &= ~(1<<REG_LR);
2156 savedregs_bitmask |= (1<<REG_PC);
2158 M_LDMFD(savedregs_bitmask, REG_SP);
2161 /* if LR was not on stack, we need to return manually */
2163 if (code_is_leafmethod(code))
2164 M_MOV(REG_PC, REG_LR);
2167 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2169 bte = iptr->sx.s23.s3.bte;
2171 goto ICMD_INVOKE_do;
2173 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2174 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2175 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2176 case ICMD_INVOKEINTERFACE:
2178 REPLACEMENT_POINT_INVOKE(cd, iptr);
2180 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2182 um = iptr->sx.s23.s3.um;
2183 md = um->methodref->parseddesc.md;
2186 lm = iptr->sx.s23.s3.fmiref->p.method;
2188 md = lm->parseddesc;
2192 /* copy arguments to registers or stack location */
2194 s3 = md->paramcount;
2196 MCODECHECK((s3 << 1) + 64);
2198 for (s3 = s3 - 1; s3 >= 0; s3--) {
2199 var = VAR(iptr->sx.s23.s2.args[s3]);
2200 d = md->params[s3].regoff;
2202 if (var->flags & PREALLOC) /* argument was precolored? */
2205 /* TODO: document me */
2206 #if !defined(ENABLE_SOFTFLOAT)
2207 if (IS_INT_LNG_TYPE(var->type)) {
2208 #endif /* !defined(ENABLE_SOFTFLOAT) */
2209 if (!md->params[s3].inmemory) {
2210 s1 = emit_load(jd, iptr, var, d);
2212 if (IS_2_WORD_TYPE(var->type))
2218 if (IS_2_WORD_TYPE(var->type)) {
2219 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2220 M_LST(s1, REG_SP, d);
2223 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2224 M_IST(s1, REG_SP, d);
2227 #if !defined(ENABLE_SOFTFLOAT)
2230 if (!md->params[s3].inmemory) {
2231 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2232 if (IS_2_WORD_TYPE(var->type))
2238 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2239 if (IS_2_WORD_TYPE(var->type))
2240 M_DST(s1, REG_SP, d);
2242 M_FST(s1, REG_SP, d);
2245 #endif /* !defined(ENABLE_SOFTFLOAT) */
2248 switch (iptr->opc) {
2251 if (bte->stub == NULL) {
2252 disp = dseg_add_functionptr(cd, bte->fp);
2254 disp = dseg_add_functionptr(cd, bte->stub);
2257 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2259 /* generate the actual call */
2261 M_MOV(REG_LR, REG_PC);
2262 M_MOV(REG_PC, REG_PV);
2263 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2267 case ICMD_INVOKESPECIAL:
2268 emit_nullpointer_check(cd, iptr, REG_A0);
2271 case ICMD_INVOKESTATIC:
2273 disp = dseg_add_unique_address(cd, NULL);
2275 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2279 disp = dseg_add_address(cd, lm->stubroutine);
2281 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2283 /* generate the actual call */
2285 M_MOV(REG_LR, REG_PC);
2286 M_MOV(REG_PC, REG_PV);
2287 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2291 case ICMD_INVOKEVIRTUAL:
2293 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2298 s1 = OFFSET(vftbl_t, table[0]) +
2299 sizeof(methodptr) * lm->vftblindex;
2301 /* implicit null-pointer check */
2302 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2303 OFFSET(java_object_t, vftbl));
2304 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2306 /* generate the actual call */
2308 M_MOV(REG_LR, REG_PC);
2309 M_MOV(REG_PC, REG_PV);
2310 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2314 case ICMD_INVOKEINTERFACE:
2316 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2322 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2323 sizeof(methodptr*) * lm->class->index;
2324 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2327 /* implicit null-pointer check */
2328 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2329 OFFSET(java_object_t, vftbl));
2330 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2331 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2333 /* generate the actual call */
2335 M_MOV(REG_LR, REG_PC);
2336 M_MOV(REG_PC, REG_PV);
2337 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2342 /* store size of call code in replacement point */
2343 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2345 /* store return value */
2347 d = md->returntype.type;
2349 #if !defined(__SOFTFP__)
2350 /* TODO: this is only a hack, since we use R0/R1 for float
2351 return! this depends on gcc; it is independent from
2352 our ENABLE_SOFTFLOAT define */
2353 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2354 #if 0 && !defined(NDEBUG)
2355 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2357 /* we cannot use this macro, since it is not defined
2358 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2359 REG_FRESULT, REG_RESULT_TYPED(d)); */
2360 if (IS_2_WORD_TYPE(d)) {
2361 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2362 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2364 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2365 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2370 if (d != TYPE_VOID) {
2371 #if !defined(ENABLE_SOFTFLOAT)
2372 if (IS_INT_LNG_TYPE(d)) {
2373 #endif /* !defined(ENABLE_SOFTFLOAT) */
2374 if (IS_2_WORD_TYPE(d)) {
2375 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2376 M_LNGMOVE(REG_RESULT_PACKED, s1);
2379 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2380 M_INTMOVE(REG_RESULT, s1);
2383 #if !defined(ENABLE_SOFTFLOAT)
2385 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2386 if (IS_2_WORD_TYPE(d))
2387 M_CAST_L2D(REG_RESULT_PACKED, s1);
2389 M_CAST_I2F(REG_RESULT, s1);
2391 #endif /* !defined(ENABLE_SOFTFLOAT) */
2393 emit_store_dst(jd, iptr, s1);
2397 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2399 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2400 /* object type cast-check */
2405 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2410 super = iptr->sx.s23.s3.c.cls;
2411 superindex = super->index;
2414 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2415 CODEGEN_CRITICAL_SECTION_NEW;
2417 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2419 /* if class is not resolved, check which code to call */
2421 if (super == NULL) {
2423 emit_label_beq(cd, BRANCH_LABEL_1);
2425 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2426 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2427 iptr->sx.s23.s3.c.ref, disp);
2429 M_DSEG_LOAD(REG_ITMP2, disp);
2430 disp = dseg_add_s4(cd, ACC_INTERFACE);
2431 M_DSEG_LOAD(REG_ITMP3, disp);
2432 M_TST(REG_ITMP2, REG_ITMP3);
2433 emit_label_beq(cd, BRANCH_LABEL_2);
2436 /* interface checkcast code */
2438 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2439 if ((super == NULL) || !IS_IMM(superindex)) {
2440 disp = dseg_add_unique_s4(cd, superindex);
2442 if (super == NULL) {
2443 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2444 iptr->sx.s23.s3.c.ref, disp);
2448 emit_label_beq(cd, BRANCH_LABEL_3);
2451 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2452 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2454 /* we put unresolved or non-immediate superindices onto dseg */
2455 if ((super == NULL) || !IS_IMM(superindex)) {
2456 /* disp was computed before we added the patcher */
2457 M_DSEG_LOAD(REG_ITMP2, disp);
2458 M_CMP(REG_ITMP3, REG_ITMP2);
2460 assert(IS_IMM(superindex));
2461 M_CMP_IMM(REG_ITMP3, superindex);
2464 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2466 /* if we loaded the superindex out of the dseg above, we do
2467 things differently here! */
2468 if ((super == NULL) || !IS_IMM(superindex)) {
2470 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2472 /* this assumes something */
2473 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2475 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2476 assert(sizeof(methodptr*) == 4);
2477 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2483 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2484 superindex * sizeof(methodptr*);
2488 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2489 M_TST(REG_ITMP3, REG_ITMP3);
2490 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2493 emit_label_br(cd, BRANCH_LABEL_4);
2495 emit_label(cd, BRANCH_LABEL_3);
2498 /* class checkcast code */
2500 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2501 if (super == NULL) {
2502 emit_label(cd, BRANCH_LABEL_2);
2504 disp = dseg_add_unique_address(cd, NULL);
2506 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2507 iptr->sx.s23.s3.c.ref,
2511 disp = dseg_add_address(cd, super->vftbl);
2514 emit_label_beq(cd, BRANCH_LABEL_5);
2517 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2518 M_DSEG_LOAD(REG_ITMP3, disp);
2520 CODEGEN_CRITICAL_SECTION_START;
2522 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2523 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2524 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2525 M_DSEG_LOAD(REG_ITMP3, disp);
2526 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2528 CODEGEN_CRITICAL_SECTION_END;
2530 M_CMP(REG_ITMP2, REG_ITMP3);
2531 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2534 emit_label(cd, BRANCH_LABEL_5);
2537 if (super == NULL) {
2538 emit_label(cd, BRANCH_LABEL_1);
2539 emit_label(cd, BRANCH_LABEL_4);
2542 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2545 /* array type cast-check */
2547 s1 = emit_load_s1(jd, iptr, REG_A0);
2548 M_INTMOVE(s1, REG_A0);
2550 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2551 disp = dseg_add_unique_address(cd, NULL);
2553 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2554 iptr->sx.s23.s3.c.ref,
2558 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2560 M_DSEG_LOAD(REG_A1, disp);
2561 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2562 M_DSEG_BRANCH(disp);
2565 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2566 M_RECOMPUTE_PV(disp);
2568 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2569 M_TST(REG_RESULT, REG_RESULT);
2570 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2572 d = codegen_reg_of_dst(jd, iptr, s1);
2576 emit_store_dst(jd, iptr, d);
2579 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2585 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2590 super = iptr->sx.s23.s3.c.cls;
2591 superindex = super->index;
2594 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2595 CODEGEN_CRITICAL_SECTION_NEW;
2597 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2598 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2601 M_MOV(REG_ITMP1, s1);
2605 /* if class is not resolved, check which code to call */
2607 if (super == NULL) {
2611 emit_label_beq(cd, BRANCH_LABEL_1);
2613 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2614 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2615 iptr->sx.s23.s3.c.ref, disp);
2617 M_DSEG_LOAD(REG_ITMP2, disp);
2618 disp = dseg_add_s4(cd, ACC_INTERFACE);
2619 M_DSEG_LOAD(REG_ITMP3, disp);
2620 M_TST(REG_ITMP2, REG_ITMP3);
2621 emit_label_beq(cd, BRANCH_LABEL_2);
2624 /* interface checkcast code */
2626 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2627 if ((super == NULL) || !IS_IMM(superindex)) {
2628 disp = dseg_add_unique_s4(cd, superindex);
2630 if (super == NULL) {
2631 /* If d == REG_ITMP2, then it's destroyed in check
2636 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2637 iptr->sx.s23.s3.c.ref, disp);
2642 emit_label_beq(cd, BRANCH_LABEL_3);
2645 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2646 M_LDR_INTERN(REG_ITMP3,
2647 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2649 /* we put unresolved or non-immediate superindices onto dseg
2650 and do things slightly different */
2651 if ((super == NULL) || !IS_IMM(superindex)) {
2652 /* disp was computed before we added the patcher */
2653 M_DSEG_LOAD(REG_ITMP2, disp);
2654 M_CMP(REG_ITMP3, REG_ITMP2);
2656 if (d == REG_ITMP2) {
2663 /* this assumes something */
2664 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2666 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2667 assert(sizeof(methodptr*) == 4);
2668 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2670 if (d == REG_ITMP2) {
2677 assert(IS_IMM(superindex));
2678 M_CMP_IMM(REG_ITMP3, superindex);
2682 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2683 superindex * sizeof(methodptr*);
2687 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2688 M_TST(REG_ITMP3, REG_ITMP3);
2692 emit_label_br(cd, BRANCH_LABEL_4);
2694 emit_label(cd, BRANCH_LABEL_3);
2697 /* class checkcast code */
2699 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2700 if (super == NULL) {
2701 emit_label(cd, BRANCH_LABEL_2);
2703 disp = dseg_add_unique_address(cd, NULL);
2705 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2706 iptr->sx.s23.s3.c.ref, disp);
2709 disp = dseg_add_address(cd, super->vftbl);
2713 emit_label_beq(cd, BRANCH_LABEL_5);
2716 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2717 M_DSEG_LOAD(REG_ITMP2, disp);
2719 CODEGEN_CRITICAL_SECTION_START;
2721 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2722 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2723 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2725 CODEGEN_CRITICAL_SECTION_END;
2727 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2728 M_CMP(REG_ITMP1, REG_ITMP2);
2729 /* If d == REG_ITMP2, then it's destroyed */
2735 emit_label(cd, BRANCH_LABEL_5);
2738 if (super == NULL) {
2739 emit_label(cd, BRANCH_LABEL_1);
2740 emit_label(cd, BRANCH_LABEL_4);
2745 emit_store_dst(jd, iptr, d);
2748 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2750 /* copy sizes to stack if necessary */
2752 MCODECHECK((iptr->s1.argcount << 1) + 64);
2754 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2756 var = VAR(iptr->sx.s23.s2.args[s1]);
2758 /* copy SAVEDVAR sizes to stack */
2760 if (!(var->flags & PREALLOC)) {
2761 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2762 M_STR(s2, REG_SP, s1 * 4);
2766 /* a0 = dimension count */
2768 assert(IS_IMM(iptr->s1.argcount));
2769 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2771 /* is patcher function set? */
2773 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2774 disp = dseg_add_unique_address(cd, NULL);
2776 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2777 iptr->sx.s23.s3.c.ref, disp);
2780 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2782 /* a1 = arraydescriptor */
2784 M_DSEG_LOAD(REG_A1, disp);
2786 /* a2 = pointer to dimensions = stack pointer */
2788 M_INTMOVE(REG_SP, REG_A2);
2790 /* call builtin_multianewarray here */
2792 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2793 M_DSEG_BRANCH(disp);
2797 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2800 /* check for exception before result assignment */
2802 emit_exception_check(cd, iptr);
2806 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2807 M_INTMOVE(REG_RESULT, d);
2808 emit_store_dst(jd, iptr, d);
2811 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2813 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2814 emit_nullpointer_check(cd, iptr, s1);
2818 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2821 } /* the big switch */
2823 } /* for all instructions */
2825 } /* for all basic blocks */
2827 dseg_createlinenumbertable(cd);
2830 /* generate traps */
2832 emit_patcher_traps(jd);
2834 /* everything's ok */
2840 /* codegen_emit_stub_compiler **************************************************
2842 Emits a stub routine which calls the compiler.
2844 *******************************************************************************/
2846 void codegen_emit_stub_compiler(jitdata *jd)
2851 /* get required compiler data */
2856 /* code for the stub */
2858 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2859 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2863 /* codegen_emit_stub_native ****************************************************
2865 Emits a stub routine which calls a native method.
2867 *******************************************************************************/
2869 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2880 /* get required compiler data */
2886 /* initialize variables */
2890 /* calculate stackframe size */
2892 cd->stackframesize =
2893 4 + /* return address */
2894 sizeof(stackframeinfo_t) + /* stackframeinfo */
2895 sizeof(localref_table) + /* localref_table */
2896 nmd->memuse * 4; /* stack arguments */
2898 /* align stack to 8-byte */
2900 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2902 /* create method header */
2904 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2905 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2906 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2907 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2908 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2909 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2910 (void) dseg_addlinenumbertablesize(cd);
2911 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2913 /* generate stub code */
2915 M_STMFD(1<<REG_LR, REG_SP);
2916 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2918 #if !defined(NDEBUG)
2919 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2920 emit_verbosecall_enter(jd);
2923 #if defined(ENABLE_GC_CACAO)
2924 /* Save callee saved integer registers in stackframeinfo (GC may
2925 need to recover them during a collection). */
2927 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2928 OFFSET(stackframeinfo_t, intregs);
2930 for (i = 0; i < INT_SAV_CNT; i++)
2931 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2934 /* Save integer and float argument registers (these are 4
2935 registers, stack is 8-byte aligned). */
2937 M_STMFD(BITMASK_ARGS, REG_SP);
2938 /* TODO: floating point */
2940 /* create native stackframe info */
2942 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2943 M_MOV(REG_A1, REG_PV);
2944 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2945 M_DSEG_BRANCH(disp);
2949 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2952 /* remember class argument */
2954 if (m->flags & ACC_STATIC)
2955 M_MOV(REG_ITMP3, REG_RESULT);
2957 /* Restore integer and float argument registers (these are 4
2958 registers, stack is 8-byte aligned). */
2960 M_LDMFD(BITMASK_ARGS, REG_SP);
2961 /* TODO: floating point */
2963 /* copy or spill arguments to new locations */
2964 /* ATTENTION: the ARM has only integer argument registers! */
2966 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2967 t = md->paramtypes[i].type;
2969 if (!md->params[i].inmemory) {
2970 s1 = md->params[i].regoff;
2971 s2 = nmd->params[j].regoff;
2973 if (!nmd->params[j].inmemory) {
2974 #if !defined(__ARM_EABI__)
2975 SPLIT_OPEN(t, s2, REG_ITMP1);
2978 if (IS_2_WORD_TYPE(t))
2983 #if !defined(__ARM_EABI__)
2984 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2988 if (IS_2_WORD_TYPE(t))
2989 M_LST(s1, REG_SP, s2);
2991 M_IST(s1, REG_SP, s2);
2995 s1 = md->params[i].regoff + cd->stackframesize;
2996 s2 = nmd->params[j].regoff;
2998 if (IS_2_WORD_TYPE(t)) {
2999 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3000 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3003 M_ILD(REG_ITMP1, REG_SP, s1);
3004 M_IST(REG_ITMP1, REG_SP, s2);
3009 /* Handle native Java methods. */
3011 if (m->flags & ACC_NATIVE) {
3012 /* put class into second argument register */
3014 if (m->flags & ACC_STATIC)
3015 M_MOV(REG_A1, REG_ITMP3);
3017 /* put env into first argument register */
3019 disp = dseg_add_address(cd, _Jv_env);
3020 M_DSEG_LOAD(REG_A0, disp);
3023 /* Call the native function. */
3025 disp = dseg_add_functionptr(cd, f);
3026 M_DSEG_BRANCH(disp);
3029 /* TODO: this is only needed because of the tracer ... do we
3032 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3035 #if !defined(__SOFTFP__)
3036 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3037 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3038 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3039 #if 0 && !defined(NDEBUG)
3040 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3042 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3043 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3044 if (IS_2_WORD_TYPE(md->returntype.type)) {
3045 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3046 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3048 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3049 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3054 #if !defined(NDEBUG)
3055 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3056 emit_verbosecall_exit(jd);
3059 /* remove native stackframe info */
3060 /* TODO: improve this store/load */
3062 M_STMFD(BITMASK_RESULT, REG_SP);
3064 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3065 M_MOV(REG_A1, REG_PV);
3066 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3067 M_DSEG_BRANCH(disp);
3068 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3071 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3072 M_LDMFD(BITMASK_RESULT, REG_SP);
3074 #if defined(ENABLE_GC_CACAO)
3075 /* restore callee saved int registers from stackframeinfo (GC might have */
3076 /* modified them during a collection). */
3078 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3079 OFFSET(stackframeinfo_t, intregs);
3081 for (i = 0; i < INT_SAV_CNT; i++)
3082 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3085 /* finish stub code, but do not yet return to caller */
3087 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3088 M_LDMFD(1<<REG_LR, REG_SP);
3090 /* check for exception */
3092 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3093 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3095 /* handle exception here */
3097 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3099 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3100 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3101 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3103 /* generate patcher stubs */
3105 emit_patcher_traps(jd);
3109 /* asm_debug *******************************************************************
3113 *******************************************************************************/
3115 void asm_debug(int a1, int a2, int a3, int a4)
3117 printf("===> i am going to exit after this debugging message!\n");
3118 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3119 vm_abort("leave you now");
3124 * These are local overrides for various environment variables in Emacs.
3125 * Please do not remove this and leave it at the end of the file, where
3126 * Emacs will automagically detect them.
3127 * ---------------------------------------------------------------------
3130 * indent-tabs-mode: t
3134 * vim:noexpandtab:sw=4:ts=4: