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
25 $Id: codegen.c 8127 2007-06-21 11:55:56Z michi $
39 #include "vm/jit/arm/arch.h"
40 #include "vm/jit/arm/codegen.h"
42 #include "mm/memory.h"
44 #include "native/native.h"
46 #include "threads/lock-common.h"
48 #include "vm/builtin.h"
49 #include "vm/exceptions.h"
50 #include "vm/global.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.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)
99 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
100 unresolved_method *um;
101 builtintable_entry *bte;
104 /* get required compiler data */
111 /* prevent compiler warnings */
119 /* space to save used callee saved registers */
121 savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
122 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
123 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
124 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
126 spilledregs_num = rd->memuse;
128 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
129 if (checksync && (m->flags & ACC_SYNCHRONIZED))
133 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
135 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
136 only in native stubs. */
137 /* align stack to 8-byte */
139 cd->stackframesize = (cd->stackframesize + 4) & ~4;
141 /* SECTION: Method Header */
142 /* create method header */
144 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
145 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
147 #if defined(ENABLE_THREADS)
148 /* IsSync contains the offset relative to the stack pointer for the
149 argument of monitor_exit used in the exception handler. Since the
150 offset could be zero and give a wrong meaning of the flag it is
154 if (checksync && (m->flags & ACC_SYNCHRONIZED))
155 (void) dseg_add_unique_s4(cd, rd->memuse * 8 + 4);/* IsSync */
158 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
160 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
161 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
162 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
163 (void) dseg_addlinenumbertablesize(cd);
164 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
166 /* create exception table */
168 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
169 dseg_add_target(cd, ex->start);
170 dseg_add_target(cd, ex->end);
171 dseg_add_target(cd, ex->handler);
172 (void) dseg_add_unique_address(cd, ex->catchtype.any);
175 /* save return address and used callee saved registers */
177 savedregs_bitmask = 0;
179 if (!jd->isleafmethod)
180 savedregs_bitmask = (1<<REG_LR);
182 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
183 savedregs_bitmask |= (1<<(rd->savintregs[i]));
186 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
187 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
188 /* TODO: floating-point */
192 if (savedregs_bitmask)
193 M_STMFD(savedregs_bitmask, REG_SP);
195 /* create additional stack frame for spilled variables (if necessary) */
197 if ((cd->stackframesize / 4 - savedregs_num) > 0)
198 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
200 /* take arguments out of register or stack frame */
203 for (i = 0, len = 0; i < md->paramcount; i++) {
204 s1 = md->params[i].regoff;
205 t = md->paramtypes[i].type;
207 varindex = jd->local_map[len * 5 + t];
209 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
211 if (varindex == UNUSED)
216 /* ATTENTION: we use interger registers for all arguments (even float) */
217 #if !defined(ENABLE_SOFTFLOAT)
218 if (IS_INT_LNG_TYPE(t)) {
220 if (!md->params[i].inmemory) {
221 if (!(var->flags & INMEMORY)) {
222 if (IS_2_WORD_TYPE(t))
223 M_LNGMOVE(s1, var->vv.regoff);
225 M_INTMOVE(s1, var->vv.regoff);
228 if (IS_2_WORD_TYPE(t))
229 M_LST(s1, REG_SP, var->vv.regoff);
231 M_IST(s1, REG_SP, var->vv.regoff);
234 else { /* stack arguments */
235 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
236 if (IS_2_WORD_TYPE(t))
237 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
239 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
241 else { /* stack arg -> spilled */
242 /* Reuse Memory Position on Caller Stack */
243 var->vv.regoff = cd->stackframesize + s1;
246 #if !defined(ENABLE_SOFTFLOAT)
249 if (!md->params[i].inmemory) {
250 if (!(var->flags & INMEMORY)) {
251 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
254 if (IS_2_WORD_TYPE(t))
255 M_LST(s1, REG_SP, var->vv.regoff);
257 M_IST(s1, REG_SP, var->vv.regoff);
261 if (!(var->flags & INMEMORY)) {
262 if (IS_2_WORD_TYPE(t))
263 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
265 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
268 /* Reuse Memory Position on Caller Stack */
269 var->vv.regoff = cd->stackframesize + s1;
273 #endif /* !defined(ENABLE_SOFTFLOAT) */
276 #if defined(ENABLE_THREADS)
277 /* call monitorenter function */
279 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
280 /* stack offset for monitor argument */
284 # if !defined(NDEBUG)
285 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
286 M_STMFD(BITMASK_ARGS, REG_SP);
291 /* get the correct lock object */
293 if (m->flags & ACC_STATIC) {
294 disp = dseg_add_address(cd, &m->class->object.header);
295 M_DSEG_LOAD(REG_A0, disp);
298 emit_nullpointer_check_force(cd, iptr, REG_A0);
301 M_STR(REG_A0, REG_SP, s1);
302 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
304 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
307 # if !defined(NDEBUG)
308 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
309 M_LDMFD(BITMASK_ARGS, REG_SP);
315 /* call trace function */
317 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
318 emit_verbosecall_enter(jd);
321 /* end of header generation */
323 /* SECTION: ICMD Code Generation */
324 /* for all basic blocks */
326 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
328 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
330 /* is this basic block reached? */
332 if (bptr->flags < BBREACHED)
335 /* branch resolving */
337 codegen_resolve_branchrefs(cd, bptr);
339 /* copy interface registers to their destination */
345 #if defined(ENABLE_LSRA)
349 var = VAR(bptr->invars[len]);
350 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
351 if (!(var->flags & INMEMORY))
355 M_INTMOVE(REG_ITMP1, d);
356 emit_store(jd, NULL, var, d);
363 var = VAR(bptr->invars[len]);
365 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
366 d = codegen_reg_of_var(0, var, REG_ITMP1);
367 M_INTMOVE(REG_ITMP1, d);
368 emit_store(jd, NULL, var, d);
371 assert((var->flags & INOUT));
374 #if defined(ENABLE_LSRA)
378 /* for all instructions */
381 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
383 /* add line number */
384 if (iptr->line != currentline) {
385 dseg_addlinenumber(cd, iptr->line);
386 currentline = iptr->line;
389 MCODECHECK(64); /* an instruction usually needs < 64 words */
393 case ICMD_NOP: /* ... ==> ... */
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 codegen_addpatchref(cd, PATCHER_aconst,
415 if (opt_showdisassemble)
418 M_DSEG_LOAD(d, disp);
421 ICONST(d, (u4) iptr->sx.val.anyptr);
423 emit_store_dst(jd, iptr, d);
426 case ICMD_LCONST: /* ... ==> ..., constant */
428 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
429 LCONST(d, iptr->sx.val.l);
430 emit_store_dst(jd, iptr, d);
433 case ICMD_FCONST: /* ... ==> ..., constant */
435 #if defined(ENABLE_SOFTFLOAT)
436 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
437 ICONST(d, iptr->sx.val.i);
438 emit_store_dst(jd, iptr, d);
440 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
441 FCONST(d, iptr->sx.val.f);
442 emit_store_dst(jd, iptr, d);
446 case ICMD_DCONST: /* ... ==> ..., constant */
448 #if defined(ENABLE_SOFTFLOAT)
449 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
450 LCONST(d, iptr->sx.val.l);
451 emit_store_dst(jd, iptr, d);
453 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
454 DCONST(d, iptr->sx.val.d);
455 emit_store_dst(jd, iptr, d);
460 /* load/store/copy/move operations ************************************/
462 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
463 case ICMD_ALOAD: /* op1 = local variable */
467 case ICMD_ISTORE: /* ..., value ==> ... */
478 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
482 /* pop operations *****************************************************/
484 /* attention: double and longs are only one entry in CACAO ICMDs */
486 case ICMD_POP: /* ..., value ==> ... */
487 case ICMD_POP2: /* ..., value, value ==> ... */
492 /* integer operations *************************************************/
494 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
496 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
497 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
498 M_MOV(d, REG_LSL(s1, 24));
499 M_MOV(d, REG_ASR(d, 24));
500 emit_store_dst(jd, iptr, d);
503 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
505 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
506 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
507 M_MOV(d, REG_LSL(s1, 16));
508 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
509 emit_store_dst(jd, iptr, d);
512 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
514 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
515 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
516 M_MOV(d, REG_LSL(s1, 16));
517 M_MOV(d, REG_ASR(d, 16));
518 emit_store_dst(jd, iptr, d);
521 case ICMD_I2L: /* ..., value ==> ..., value */
523 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
524 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
525 M_INTMOVE(s1, GET_LOW_REG(d));
526 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
527 emit_store_dst(jd, iptr, d);
530 case ICMD_L2I: /* ..., value ==> ..., value */
532 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
533 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
535 emit_store_dst(jd, iptr, d);
538 case ICMD_INEG: /* ..., value ==> ..., - value */
540 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
541 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
543 emit_store_dst(jd, iptr, d);
546 case ICMD_LNEG: /* ..., value ==> ..., - value */
548 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
549 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
550 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
551 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
552 emit_store_dst(jd, iptr, d);
555 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
557 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
558 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
559 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
561 emit_store_dst(jd, iptr, d);
564 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
566 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
567 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
568 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
569 M_ADD_S(GET_LOW_REG(d), s1, s2);
570 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
571 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
572 M_ADC(GET_HIGH_REG(d), s1, s2);
573 emit_store_dst(jd, iptr, d);
579 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
580 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
582 if (IS_IMM(iptr->sx.val.i)) {
583 M_ADD_IMM(d, s1, iptr->sx.val.i);
584 } else if (IS_IMM(-iptr->sx.val.i)) {
585 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
587 ICONST(REG_ITMP3, iptr->sx.val.i);
588 M_ADD(d, s1, REG_ITMP3);
591 emit_store_dst(jd, iptr, d);
594 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
595 /* sx.val.l = constant */
597 s3 = iptr->sx.val.l & 0xffffffff;
598 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
599 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
601 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
603 ICONST(REG_ITMP3, s3);
604 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
606 s3 = iptr->sx.val.l >> 32;
607 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
609 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
611 ICONST(REG_ITMP3, s3);
612 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
614 emit_store_dst(jd, iptr, d);
617 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
619 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
620 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
621 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
623 emit_store_dst(jd, iptr, d);
626 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
628 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
629 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
630 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
631 M_SUB_S(GET_LOW_REG(d), s1, s2);
632 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
633 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
634 M_SBC(GET_HIGH_REG(d), s1, s2);
635 emit_store_dst(jd, iptr, d);
638 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
639 /* sx.val.i = constant */
641 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
642 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
643 if (IS_IMM(iptr->sx.val.i))
644 M_SUB_IMM(d, s1, iptr->sx.val.i);
646 ICONST(REG_ITMP3, iptr->sx.val.i);
647 M_SUB(d, s1, REG_ITMP3);
649 emit_store_dst(jd, iptr, d);
652 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
653 /* sx.val.l = constant */
655 s3 = iptr->sx.val.l & 0xffffffff;
656 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
657 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
659 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
661 ICONST(REG_ITMP3, s3);
662 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
664 s3 = iptr->sx.val.l >> 32;
665 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
667 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
669 ICONST(REG_ITMP3, s3);
670 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
672 emit_store_dst(jd, iptr, d);
675 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
677 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
678 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
679 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
681 emit_store_dst(jd, iptr, d);
684 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
685 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
687 s1 = emit_load_s1(jd, iptr, REG_A0);
688 s2 = emit_load_s2(jd, iptr, REG_A1);
689 emit_arithmetic_check(cd, iptr, s2);
691 /* move arguments into argument registers */
692 M_INTMOVE(s1, REG_A0);
693 M_INTMOVE(s2, REG_A1);
695 /* call builtin function */
696 bte = iptr->sx.s23.s3.bte;
697 disp = dseg_add_functionptr(cd, bte->fp);
701 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
704 /* move result into destination register */
705 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
706 M_INTMOVE(REG_RESULT, d);
707 emit_store_dst(jd, iptr, d);
710 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
711 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
713 /* move arguments into argument registers */
715 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
716 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
717 /* XXX TODO: only do this if arithmetic check is really done! */
718 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
719 emit_arithmetic_check(cd, iptr, REG_ITMP3);
721 M_LNGMOVE(s1, REG_A0_A1_PACKED);
722 M_LNGMOVE(s2, REG_A2_A3_PACKED);
724 /* call builtin function */
725 bte = iptr->sx.s23.s3.bte;
726 disp = dseg_add_functionptr(cd, bte->fp);
730 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
733 /* move result into destination register */
734 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
735 M_LNGMOVE(REG_RESULT_PACKED, d);
736 emit_store_dst(jd, iptr, d);
739 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
740 /* sx.val.i = constant */
742 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
743 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
744 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
745 emit_store_dst(jd, iptr, d);
748 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
749 /* sx.val.i = constant */
751 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
752 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
753 /* this rounds towards 0 as java likes it */
754 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
755 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
756 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
757 /* this rounds towards nearest, not java style */
758 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
759 M_ADCMI_IMM(d, d, 0);*/
760 emit_store_dst(jd, iptr, d);
763 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
764 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
766 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
767 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
768 M_MOV_S(REG_ITMP1, s1);
769 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
770 if (IS_IMM(iptr->sx.val.i))
771 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
773 ICONST(REG_ITMP3, iptr->sx.val.i);
774 M_AND(REG_ITMP1, REG_ITMP3, d);
776 M_RSBMI_IMM(d, d, 0);
777 emit_store_dst(jd, iptr, d);
780 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
782 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
783 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
784 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
785 M_AND_IMM(s2, 0x1f, REG_ITMP2);
786 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
787 emit_store_dst(jd, iptr, d);
790 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
792 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
793 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
794 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
795 M_AND_IMM(s2, 0x1f, REG_ITMP2);
796 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
797 emit_store_dst(jd, iptr, d);
800 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
802 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
803 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
804 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
805 M_AND_IMM(s2, 0x1f, REG_ITMP2);
806 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
807 emit_store_dst(jd, iptr, d);
810 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
811 /* sx.val.i = constant */
813 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
814 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
815 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
816 emit_store_dst(jd, iptr, d);
819 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
820 /* sx.val.i = constant */
822 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
823 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
824 /* we need to check for zero here because arm interprets it as SHR by 32 */
825 if ((iptr->sx.val.i & 0x1f) == 0) {
828 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
830 emit_store_dst(jd, iptr, d);
833 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
834 /* sx.val.i = constant */
836 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
837 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
838 /* we need to check for zero here because arm interprets it as SHR by 32 */
839 if ((iptr->sx.val.i & 0x1f) == 0)
842 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
843 emit_store_dst(jd, iptr, d);
846 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
848 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
849 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
850 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
852 emit_store_dst(jd, iptr, d);
855 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
857 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
858 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
859 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
860 M_AND(s1, s2, GET_LOW_REG(d));
861 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
862 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
863 M_AND(s1, s2, GET_HIGH_REG(d));
864 emit_store_dst(jd, iptr, d);
867 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
869 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
870 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
871 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
873 emit_store_dst(jd, iptr, d);
876 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
878 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
879 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
880 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
881 M_ORR(s1, s2, GET_LOW_REG(d));
882 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
883 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
884 M_ORR(s1, s2, GET_HIGH_REG(d));
885 emit_store_dst(jd, iptr, d);
888 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
890 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
891 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
892 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
894 emit_store_dst(jd, iptr, d);
897 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
899 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
900 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
901 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
902 M_EOR(s1, s2, GET_LOW_REG(d));
903 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
904 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
905 M_EOR(s1, s2, GET_HIGH_REG(d));
906 emit_store_dst(jd, iptr, d);
910 /* floating operations ************************************************/
912 #if !defined(ENABLE_SOFTFLOAT)
914 case ICMD_FNEG: /* ..., value ==> ..., - value */
916 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
917 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
919 emit_store_dst(jd, iptr, d);
922 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
924 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
925 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
926 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
928 emit_store_dst(jd, iptr, d);
931 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
933 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
934 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
935 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
937 emit_store_dst(jd, iptr, d);
940 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
942 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
943 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
944 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
946 emit_store_dst(jd, iptr, d);
949 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
950 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
951 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
952 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
954 emit_store_dst(jd, iptr, d);
957 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
960 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
962 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
963 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
964 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
966 emit_store_dst(jd, iptr, d);
969 case ICMD_DNEG: /* ..., value ==> ..., - value */
971 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
972 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
974 emit_store_dst(jd, iptr, d);
977 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
979 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
980 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
981 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
983 emit_store_dst(jd, iptr, d);
986 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
988 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
989 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
990 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
992 emit_store_dst(jd, iptr, d);
995 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
997 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
998 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
999 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1001 emit_store_dst(jd, iptr, d);
1004 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1006 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1007 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1008 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1010 emit_store_dst(jd, iptr, d);
1013 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1016 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1018 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1019 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1020 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1022 emit_store_dst(jd, iptr, d);
1025 case ICMD_I2F: /* ..., value ==> ..., (float) 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_I2D: /* ..., value ==> ..., (double) value */
1035 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1036 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1038 emit_store_dst(jd, iptr, d);
1041 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1043 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1044 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1045 /* this uses round towards zero, as Java likes it */
1047 /* this checks for NaN; to return zero as Java likes it */
1050 emit_store_dst(jd, iptr, d);
1053 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1055 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1056 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1057 /* this uses round towards zero, as Java likes it */
1059 /* this checks for NaN; to return zero as Java likes it */
1062 emit_store_dst(jd, iptr, d);
1065 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1067 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1068 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1070 emit_store_dst(jd, iptr, d);
1073 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1075 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1076 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1078 emit_store_dst(jd, iptr, d);
1081 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1083 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1084 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1085 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1088 M_SUBGT_IMM(d, d, 1);
1089 M_ADDLT_IMM(d, d, 1);
1090 emit_store_dst(jd, iptr, d);
1093 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1095 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1096 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1097 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1100 M_SUBGT_IMM(d, d, 1);
1101 M_ADDLT_IMM(d, d, 1);
1102 emit_store_dst(jd, iptr, d);
1105 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1107 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1108 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1109 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1112 M_SUBLT_IMM(d, d, 1);
1113 M_ADDGT_IMM(d, d, 1);
1114 emit_store_dst(jd, iptr, d);
1117 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1119 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1120 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1121 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1124 M_SUBLT_IMM(d, d, 1);
1125 M_ADDGT_IMM(d, d, 1);
1126 emit_store_dst(jd, iptr, d);
1129 #endif /* !defined(ENABLE_SOFTFLOAT) */
1132 /* memory operations **************************************************/
1134 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1136 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1137 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1138 /* implicit null-pointer check */
1139 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1140 emit_store_dst(jd, iptr, d);
1143 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1145 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1146 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1147 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1148 /* implicit null-pointer check */
1149 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1150 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1151 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1152 emit_store_dst(jd, iptr, d);
1155 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1157 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1158 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1159 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1160 /* implicit null-pointer check */
1161 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1162 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1163 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1164 emit_store_dst(jd, iptr, d);
1167 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1169 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1170 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1171 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1172 /* implicit null-pointer check */
1173 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1174 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1175 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1176 emit_store_dst(jd, iptr, d);
1179 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1181 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1182 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1183 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1184 /* implicit null-pointer check */
1185 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1186 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1187 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1188 emit_store_dst(jd, iptr, d);
1191 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1193 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1194 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1195 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1196 /* implicit null-pointer check */
1197 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1198 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1199 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1200 emit_store_dst(jd, iptr, d);
1203 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1205 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1206 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1207 /* implicit null-pointer check */
1208 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1209 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1210 #if !defined(ENABLE_SOFTFLOAT)
1211 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1212 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1214 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1215 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1217 emit_store_dst(jd, iptr, d);
1220 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1222 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1223 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1224 /* implicit null-pointer check */
1225 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1226 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1227 #if !defined(ENABLE_SOFTFLOAT)
1228 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1229 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1231 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1232 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1234 emit_store_dst(jd, iptr, d);
1237 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1239 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1240 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1241 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1242 /* implicit null-pointer check */
1243 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1244 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1245 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1246 emit_store_dst(jd, iptr, d);
1249 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1251 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1252 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1253 /* implicit null-pointer check */
1254 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1255 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1256 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1257 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1260 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1262 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1263 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1264 /* implicit null-pointer check */
1265 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1266 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1267 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1268 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1271 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1273 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1274 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1275 /* implicit null-pointer check */
1276 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1277 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1278 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1279 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1282 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1284 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1285 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1286 /* implicit null-pointer check */
1287 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1288 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1289 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1290 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1293 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1295 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1296 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1297 /* implicit null-pointer check */
1298 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1299 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1300 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1301 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1304 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1306 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1307 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1308 /* implicit null-pointer check */
1309 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1310 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1311 #if !defined(ENABLE_SOFTFLOAT)
1312 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1313 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1315 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1316 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1320 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1322 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1323 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1324 /* implicit null-pointer check */
1325 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1326 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1327 #if !defined(ENABLE_SOFTFLOAT)
1328 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1329 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1331 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1332 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1336 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1338 s1 = emit_load_s1(jd, iptr, REG_A0);
1339 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1340 s3 = emit_load_s3(jd, iptr, REG_A1);
1342 /* implicit null-pointer check */
1343 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1345 /* move arguments to argument registers */
1346 M_INTMOVE(s1, REG_A0);
1347 M_INTMOVE(s3, REG_A1);
1349 /* call builtin function */
1350 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1351 M_DSEG_BRANCH(disp);
1354 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1357 /* check resturn value of builtin */
1358 emit_exception_check(cd, iptr);
1360 /* finally store address into array */
1361 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1362 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1363 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1364 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1365 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1368 case ICMD_GETSTATIC: /* ... ==> ..., value */
1370 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1371 unresolved_field *uf = iptr->sx.s23.s3.uf;
1373 fieldtype = uf->fieldref->parseddesc.fd->type;
1375 disp = dseg_add_unique_address(cd, NULL);
1377 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1379 if (opt_showdisassemble)
1383 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1385 fieldtype = fi->type;
1387 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1388 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1390 if (opt_showdisassemble)
1394 disp = dseg_add_address(cd, &(fi->value));
1397 M_DSEG_LOAD(REG_ITMP3, disp);
1398 switch (fieldtype) {
1400 #if defined(ENABLE_SOFTFLOAT)
1404 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1405 M_ILD_INTERN(d, REG_ITMP3, 0);
1408 #if defined(ENABLE_SOFTFLOAT)
1411 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1412 M_LLD_INTERN(d, REG_ITMP3, 0);
1414 #if !defined(ENABLE_SOFTFLOAT)
1416 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1417 M_FLD_INTERN(d, REG_ITMP3, 0);
1420 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1421 M_DLD_INTERN(d, REG_ITMP3, 0);
1427 emit_store_dst(jd, iptr, d);
1430 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1432 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1433 unresolved_field *uf = iptr->sx.s23.s3.uf;
1435 fieldtype = uf->fieldref->parseddesc.fd->type;
1437 disp = dseg_add_unique_address(cd, NULL);
1439 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1441 if (opt_showdisassemble)
1445 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1447 fieldtype = fi->type;
1449 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1450 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1452 if (opt_showdisassemble)
1456 disp = dseg_add_address(cd, &(fi->value));
1459 M_DSEG_LOAD(REG_ITMP3, disp);
1460 switch (fieldtype) {
1462 #if defined(ENABLE_SOFTFLOAT)
1466 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1467 M_IST_INTERN(s1, REG_ITMP3, 0);
1470 #if defined(ENABLE_SOFTFLOAT)
1473 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1474 M_LST_INTERN(s1, REG_ITMP3, 0);
1476 #if !defined(ENABLE_SOFTFLOAT)
1478 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1479 M_FST_INTERN(s1, REG_ITMP3, 0);
1482 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1483 M_DST_INTERN(s1, REG_ITMP3, 0);
1491 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1493 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1494 emit_nullpointer_check(cd, iptr, s1);
1497 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1498 unresolved_field *uf = iptr->sx.s23.s3.uf;
1500 fieldtype = uf->fieldref->parseddesc.fd->type;
1503 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1505 fieldtype = fi->type;
1509 #if !defined(ENABLE_SOFTFLOAT)
1510 /* HACK: softnull checks on floats */
1511 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1512 emit_nullpointer_check_force(cd, iptr, s1);
1515 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1516 unresolved_field *uf = iptr->sx.s23.s3.uf;
1518 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1520 if (opt_showdisassemble)
1526 switch (fieldtype) {
1528 #if defined(ENABLE_SOFTFLOAT)
1532 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1536 #if defined(ENABLE_SOFTFLOAT)
1539 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1542 #if !defined(ENABLE_SOFTFLOAT)
1544 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1548 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1555 emit_store_dst(jd, iptr, d);
1558 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1560 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1561 emit_nullpointer_check(cd, iptr, s1);
1563 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1564 unresolved_field *uf = iptr->sx.s23.s3.uf;
1566 fieldtype = uf->fieldref->parseddesc.fd->type;
1569 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1571 fieldtype = fi->type;
1575 #if !defined(ENABLE_SOFTFLOAT)
1576 /* HACK: softnull checks on floats */
1577 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1578 emit_nullpointer_check_force(cd, iptr, s1);
1581 switch (fieldtype) {
1583 #if defined(ENABLE_SOFTFLOAT)
1587 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1589 #if defined(ENABLE_SOFTFLOAT)
1590 case TYPE_DBL: /* fall through */
1593 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1595 #if !defined(ENABLE_SOFTFLOAT)
1598 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1605 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1606 unresolved_field *uf = iptr->sx.s23.s3.uf;
1608 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1610 if (opt_showdisassemble)
1616 switch (fieldtype) {
1618 #if defined(ENABLE_SOFTFLOAT)
1622 M_IST(s2, s1, disp);
1625 #if defined(ENABLE_SOFTFLOAT)
1628 M_LST(s2, s1, disp);
1630 #if !defined(ENABLE_SOFTFLOAT)
1632 M_FST(s2, s1, disp);
1635 M_DST(s2, s1, disp);
1644 /* branch operations **************************************************/
1646 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1648 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1649 M_INTMOVE(s1, REG_ITMP1_XPTR);
1650 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1651 codegen_addpatchref(cd, PATCHER_athrow_areturn,
1652 iptr->sx.s23.s2.uc, 0);
1654 if (opt_showdisassemble)
1657 disp = dseg_add_functionptr(cd, asm_handle_exception);
1658 M_DSEG_LOAD(REG_ITMP3, disp);
1659 M_MOV(REG_ITMP2_XPC, REG_PC);
1660 M_MOV(REG_PC, REG_ITMP3);
1661 M_NOP; /* nop ensures that XPC is less than the end */
1662 /* of basic block */
1665 case ICMD_GOTO: /* ... ==> ... */
1668 emit_br(cd, iptr->dst.block);
1671 case ICMD_JSR: /* ... ==> ... */
1673 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1676 case ICMD_IFNULL: /* ..., value ==> ... */
1677 case ICMD_IFNONNULL:
1679 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1681 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1684 case ICMD_IFLT: /* ..., value ==> ... */
1685 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1691 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1692 M_COMPARE(s1, iptr->sx.val.i);
1693 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1696 case ICMD_IF_LEQ: /* ..., value ==> ... */
1698 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1699 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1700 if (iptr->sx.val.l == 0) {
1701 M_ORR_S(s1, s2, REG_ITMP3);
1704 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1705 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1706 M_CMP(s1, REG_ITMP3);*/
1707 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1708 M_CMPEQ(s2, REG_ITMP3);
1710 emit_beq(cd, iptr->dst.block);
1713 case ICMD_IF_LLT: /* ..., value ==> ... */
1715 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1716 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1717 if (iptr->sx.val.l == 0) {
1718 /* if high word is less than zero, the whole long is too */
1720 emit_blt(cd, iptr->dst.block);
1723 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1724 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1725 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1726 M_CMP(s1, REG_ITMP3);*/
1727 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1728 M_MOVGT_IMM(2, REG_ITMP1);
1729 M_MOVEQ_IMM(1, REG_ITMP1);
1731 /* low compare: x=x-1(ifLO) */
1732 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1733 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1734 M_CMP(s2, REG_ITMP3);*/
1735 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1737 /* branch if (x LT 1) */
1738 M_CMP_IMM(REG_ITMP1, 1);
1739 emit_blt(cd, iptr->dst.block);
1743 case ICMD_IF_LLE: /* ..., value ==> ... */
1745 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1746 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1747 if (iptr->sx.val.l == 0) {
1748 /* if high word is less than zero, the whole long is too */
1750 emit_blt(cd, iptr->dst.block);
1752 /* ... otherwise the low word has to be zero (tricky!) */
1754 emit_beq(cd, iptr->dst.block);
1757 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1758 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1759 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1760 M_CMP(s1, REG_ITMP3);*/
1761 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1762 M_MOVGT_IMM(2, REG_ITMP1);
1763 M_MOVEQ_IMM(1, REG_ITMP1);
1765 /* low compare: x=x+1(ifHI) */
1766 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1767 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1768 M_CMP(s2, REG_ITMP3);*/
1769 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1771 /* branch if (x LE 1) */
1772 M_CMP_IMM(REG_ITMP1, 1);
1773 emit_ble(cd, iptr->dst.block);
1777 case ICMD_IF_LGE: /* ..., value ==> ... */
1779 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1780 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1781 if (iptr->sx.val.l == 0) {
1782 /* if high word is greater or equal zero, the whole long is too */
1784 emit_bge(cd, iptr->dst.block);
1787 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1788 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1789 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1790 M_CMP(s1, REG_ITMP3);*/
1791 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1792 M_MOVGT_IMM(2, REG_ITMP1);
1793 M_MOVEQ_IMM(1, REG_ITMP1);
1795 /* low compare: x=x-1(ifLO) */
1796 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1797 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1798 M_CMP(s2, REG_ITMP3);*/
1799 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1801 /* branch if (x GE 1) */
1802 M_CMP_IMM(REG_ITMP1, 1);
1803 emit_bge(cd, iptr->dst.block);
1807 case ICMD_IF_LGT: /* ..., value ==> ... */
1809 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1810 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1812 if (iptr->sx.val.l == 0) {
1813 /* if high word is greater than zero, the whole long is too */
1816 codegen_add_branch_ref(cd, iptr->dst.block);
1818 /* ... or high was zero and low is non zero (tricky!) */
1819 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1820 M_MOVLT_IMM(1, REG_ITMP3);
1821 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1823 codegen_add_branch_ref(cd, iptr->dst.block);
1827 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1828 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1829 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1830 M_CMP(s1, REG_ITMP3);*/
1831 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1832 M_MOVGT_IMM(2, REG_ITMP1);
1833 M_MOVEQ_IMM(1, REG_ITMP1);
1835 /* low compare: x=x+1(ifHI) */
1836 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1837 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1838 M_CMP(s2, REG_ITMP3);*/
1839 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1841 /* branch if (x GT 1) */
1842 M_CMP_IMM(REG_ITMP1, 1);
1843 emit_bgt(cd, iptr->dst.block);
1849 case ICMD_IF_LNE: /* ..., value ==> ... */
1851 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1852 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1853 if (iptr->sx.val.l == 0) {
1854 M_ORR_S(s1, s2, REG_ITMP3);
1857 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1858 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1859 M_CMP(s1, REG_ITMP3);*/
1860 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1861 M_CMPEQ(s2, REG_ITMP3);
1863 emit_bne(cd, iptr->dst.block);
1866 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1867 case ICMD_IF_ICMPNE:
1868 case ICMD_IF_ICMPLT:
1869 case ICMD_IF_ICMPLE:
1870 case ICMD_IF_ICMPGT:
1871 case ICMD_IF_ICMPGE:
1873 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1874 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1876 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1879 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1880 case ICMD_IF_ACMPNE:
1882 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1883 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1885 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1888 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1889 /* op1 = target JavaVM pc */
1891 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1892 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1895 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1896 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1899 emit_beq(cd, iptr->dst.block);
1902 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1903 /* op1 = target JavaVM pc */
1905 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1906 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1909 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1910 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1913 emit_bne(cd, iptr->dst.block);
1916 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1917 /* op1 = target JavaVM pc */
1919 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1920 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1921 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1923 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1924 M_MOVGT_IMM(2, REG_ITMP3);
1925 M_MOVEQ_IMM(1, REG_ITMP3);
1927 /* low compare: x=x-1(ifLO) */
1928 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1929 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1931 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1933 /* branch if (x LT 1) */
1934 M_CMP_IMM(REG_ITMP3, 1);
1935 emit_blt(cd, iptr->dst.block);
1938 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1939 /* op1 = target JavaVM pc */
1941 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1942 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1943 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1945 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1946 M_MOVGT_IMM(2, REG_ITMP3);
1947 M_MOVEQ_IMM(1, REG_ITMP3);
1949 /* low compare: x=x-1(ifLO) */
1950 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1951 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1953 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1955 /* branch if (x LE 1) */
1956 M_CMP_IMM(REG_ITMP3, 1);
1957 emit_ble(cd, iptr->dst.block);
1960 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1961 /* op1 = target JavaVM pc */
1963 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1964 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1965 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1967 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1968 M_MOVGT_IMM(2, REG_ITMP3);
1969 M_MOVEQ_IMM(1, REG_ITMP3);
1971 /* low compare: x=x-1(ifLO) */
1972 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1973 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1975 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1977 /* branch if (x GT 1) */
1978 M_CMP_IMM(REG_ITMP3, 1);
1979 emit_bgt(cd, iptr->dst.block);
1982 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1983 /* op1 = target JavaVM pc */
1985 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1986 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1987 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1989 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1990 M_MOVGT_IMM(2, REG_ITMP3);
1991 M_MOVEQ_IMM(1, REG_ITMP3);
1993 /* low compare: x=x-1(ifLO) */
1994 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1995 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1997 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1999 /* branch if (x GE 1) */
2000 M_CMP_IMM(REG_ITMP3, 1);
2001 emit_bge(cd, iptr->dst.block);
2004 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2007 branch_target_t *table;
2009 table = iptr->dst.table;
2011 l = iptr->sx.s23.s2.tablelow;
2012 i = iptr->sx.s23.s3.tablehigh;
2014 /* calculate new index (index - low) */
2015 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2017 M_INTMOVE(s1, REG_ITMP1);
2018 } else if (IS_IMM(l)) {
2019 M_SUB_IMM(REG_ITMP1, s1, l);
2021 ICONST(REG_ITMP2, l);
2022 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2025 /* range check (index <= high-low) */
2027 M_COMPARE(REG_ITMP1, i-1);
2028 emit_bugt(cd, table[0].block);
2030 /* build jump table top down and use address of lowest entry */
2035 dseg_add_target(cd, table->block);
2040 /* length of dataseg after last dseg_add_target is used by load */
2041 /* TODO: this loads from data-segment */
2042 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2043 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2046 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2049 lookup_target_t *lookup;
2051 lookup = iptr->dst.lookup;
2053 i = iptr->sx.s23.s2.lookupcount;
2056 MCODECHECK((i<<2)+8);
2057 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2060 M_COMPARE(s1, lookup->value);
2061 emit_beq(cd, lookup->target.block);
2065 /* default branch */
2066 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2070 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2072 #if !defined(ENABLE_SOFTFLOAT)
2073 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2074 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2075 goto ICMD_RETURN_do;
2078 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2080 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2081 M_INTMOVE(s1, REG_RESULT);
2082 goto ICMD_RETURN_do;
2084 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2086 #if !defined(ENABLE_SOFTFLOAT)
2087 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2088 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2089 goto ICMD_RETURN_do;
2092 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2094 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2095 M_LNGMOVE(s1, REG_RESULT_PACKED);
2096 goto ICMD_RETURN_do;
2098 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2100 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2101 M_INTMOVE(s1, REG_RESULT);
2102 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2103 codegen_addpatchref(cd, PATCHER_athrow_areturn,
2104 iptr->sx.s23.s2.uc, 0);
2106 if (opt_showdisassemble)
2109 goto ICMD_RETURN_do;
2111 case ICMD_RETURN: /* ... ==> ... */
2114 #if !defined(NDEBUG)
2115 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2116 emit_verbosecall_exit(jd);
2119 #if defined(ENABLE_THREADS)
2120 /* call monitorexit function */
2122 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2123 /* stack offset for monitor argument */
2125 s1 = rd->memuse * 8;
2127 /* we need to save the proper return value */
2129 switch (iptr->opc) {
2133 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2135 M_STMFD(BITMASK_RESULT, REG_SP);
2140 M_LDR(REG_A0, REG_SP, s1);
2141 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2142 M_DSEG_BRANCH(disp);
2144 /* we no longer need PV here, no more loading */
2145 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2146 M_RECOMPUTE_PV(s1);*/
2148 switch (iptr->opc) {
2152 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2154 M_LDMFD(BITMASK_RESULT, REG_SP);
2160 /* deallocate stackframe for spilled variables */
2162 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2163 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2165 /* restore callee saved registers + do return */
2167 if (savedregs_bitmask) {
2168 if (!jd->isleafmethod) {
2169 savedregs_bitmask &= ~(1<<REG_LR);
2170 savedregs_bitmask |= (1<<REG_PC);
2172 M_LDMFD(savedregs_bitmask, REG_SP);
2175 /* if LR was not on stack, we need to return manually */
2177 if (jd->isleafmethod)
2178 M_MOV(REG_PC, REG_LR);
2181 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2183 bte = iptr->sx.s23.s3.bte;
2185 goto ICMD_INVOKE_do;
2187 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2188 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2189 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2190 case ICMD_INVOKEINTERFACE:
2192 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2194 um = iptr->sx.s23.s3.um;
2195 md = um->methodref->parseddesc.md;
2198 lm = iptr->sx.s23.s3.fmiref->p.method;
2200 md = lm->parseddesc;
2204 /* copy arguments to registers or stack location */
2206 s3 = md->paramcount;
2208 MCODECHECK((s3 << 1) + 64);
2210 for (s3 = s3 - 1; s3 >= 0; s3--) {
2211 var = VAR(iptr->sx.s23.s2.args[s3]);
2212 d = md->params[s3].regoff;
2214 if (var->flags & PREALLOC) /* argument was precolored? */
2217 /* TODO: document me */
2218 #if !defined(ENABLE_SOFTFLOAT)
2219 if (IS_INT_LNG_TYPE(var->type)) {
2220 #endif /* !defined(ENABLE_SOFTFLOAT) */
2221 if (!md->params[s3].inmemory) {
2222 s1 = emit_load(jd, iptr, var, d);
2224 if (IS_2_WORD_TYPE(var->type))
2230 if (IS_2_WORD_TYPE(var->type)) {
2231 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2232 M_LST(s1, REG_SP, d);
2235 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2236 M_IST(s1, REG_SP, d);
2239 #if !defined(ENABLE_SOFTFLOAT)
2242 if (!md->params[s3].inmemory) {
2243 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2244 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2247 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2248 if (IS_2_WORD_TYPE(var->type))
2249 M_DST(s1, REG_SP, d);
2251 M_FST(s1, REG_SP, d);
2254 #endif /* !defined(ENABLE_SOFTFLOAT) */
2257 switch (iptr->opc) {
2259 disp = dseg_add_functionptr(cd, bte->fp);
2261 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2263 /* generate the actual call */
2265 M_MOV(REG_LR, REG_PC);
2266 M_MOV(REG_PC, REG_PV);
2267 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2270 emit_exception_check(cd, iptr);
2273 case ICMD_INVOKESPECIAL:
2274 emit_nullpointer_check(cd, iptr, REG_A0);
2277 case ICMD_INVOKESTATIC:
2279 disp = dseg_add_unique_address(cd, NULL);
2281 codegen_addpatchref(cd, PATCHER_invokestatic_special,
2284 if (opt_showdisassemble)
2288 disp = dseg_add_address(cd, lm->stubroutine);
2290 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2292 /* generate the actual call */
2294 M_MOV(REG_LR, REG_PC);
2295 M_MOV(REG_PC, REG_PV);
2296 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2300 case ICMD_INVOKEVIRTUAL:
2302 codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
2304 if (opt_showdisassemble)
2310 s1 = OFFSET(vftbl_t, table[0]) +
2311 sizeof(methodptr) * lm->vftblindex;
2313 /* implicit null-pointer check */
2314 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2315 OFFSET(java_objectheader, vftbl));
2316 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2318 /* generate the actual call */
2320 M_MOV(REG_LR, REG_PC);
2321 M_MOV(REG_PC, REG_PV);
2322 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2326 case ICMD_INVOKEINTERFACE:
2328 codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
2330 if (opt_showdisassemble)
2337 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2338 sizeof(methodptr*) * lm->class->index;
2339 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2342 /* implicit null-pointer check */
2343 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2344 OFFSET(java_objectheader, vftbl));
2345 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2346 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2348 /* generate the actual call */
2350 M_MOV(REG_LR, REG_PC);
2351 M_MOV(REG_PC, REG_PV);
2352 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2357 /* store return value */
2359 d = md->returntype.type;
2361 #if !defined(__SOFTFP__)
2362 /* TODO: this is only a hack, since we use R0/R1 for float
2363 return! this depends on gcc; it is independent from
2364 our ENABLE_SOFTFLOAT define */
2365 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2366 #if 0 && !defined(NDEBUG)
2367 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2369 /* we cannot use this macro, since it is not defined
2370 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2371 REG_FRESULT, REG_RESULT_TYPED(d)); */
2372 if (IS_2_WORD_TYPE(d)) {
2373 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2374 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2376 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2377 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2382 if (d != TYPE_VOID) {
2383 #if !defined(ENABLE_SOFTFLOAT)
2384 if (IS_INT_LNG_TYPE(d)) {
2385 #endif /* !defined(ENABLE_SOFTFLOAT) */
2386 if (IS_2_WORD_TYPE(d)) {
2387 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2388 M_LNGMOVE(REG_RESULT_PACKED, s1);
2391 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2392 M_INTMOVE(REG_RESULT, s1);
2395 #if !defined(ENABLE_SOFTFLOAT)
2397 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2398 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2400 #endif /* !defined(ENABLE_SOFTFLOAT) */
2402 emit_store_dst(jd, iptr, s1);
2406 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2408 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2409 /* object type cast-check */
2414 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2419 super = iptr->sx.s23.s3.c.cls;
2420 superindex = super->index;
2423 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2424 CODEGEN_CRITICAL_SECTION_NEW;
2426 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2428 /* if class is not resolved, check which code to call */
2430 if (super == NULL) {
2432 emit_label_beq(cd, BRANCH_LABEL_1);
2434 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2435 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2436 iptr->sx.s23.s3.c.ref, disp);
2438 if (opt_showdisassemble)
2441 M_DSEG_LOAD(REG_ITMP2, disp);
2442 disp = dseg_add_s4(cd, ACC_INTERFACE);
2443 M_DSEG_LOAD(REG_ITMP3, disp);
2444 M_TST(REG_ITMP2, REG_ITMP3);
2445 emit_label_beq(cd, BRANCH_LABEL_2);
2448 /* interface checkcast code */
2450 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2451 if ((super == NULL) || !IS_IMM(superindex)) {
2452 disp = dseg_add_unique_s4(cd, superindex);
2454 if (super == NULL) {
2455 codegen_addpatchref(cd,
2456 PATCHER_checkcast_instanceof_interface,
2457 iptr->sx.s23.s3.c.ref, disp);
2459 if (opt_showdisassemble)
2464 emit_label_beq(cd, BRANCH_LABEL_3);
2467 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2468 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2470 /* we put unresolved or non-immediate superindices onto dseg */
2471 if ((super == NULL) || !IS_IMM(superindex)) {
2472 /* disp was computed before we added the patcher */
2473 M_DSEG_LOAD(REG_ITMP2, disp);
2474 M_CMP(REG_ITMP3, REG_ITMP2);
2476 assert(IS_IMM(superindex));
2477 M_CMP_IMM(REG_ITMP3, superindex);
2480 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2482 /* if we loaded the superindex out of the dseg above, we do
2483 things differently here! */
2484 if ((super == NULL) || !IS_IMM(superindex)) {
2486 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_objectheader, vftbl));
2488 /* this assumes something */
2489 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2491 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2492 assert(sizeof(methodptr*) == 4);
2493 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2499 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2500 superindex * sizeof(methodptr*);
2504 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2505 M_TST(REG_ITMP3, REG_ITMP3);
2506 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2509 emit_label_br(cd, BRANCH_LABEL_4);
2511 emit_label(cd, BRANCH_LABEL_3);
2514 /* class checkcast code */
2516 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2517 if (super == NULL) {
2518 emit_label(cd, BRANCH_LABEL_2);
2520 disp = dseg_add_unique_address(cd, NULL);
2522 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2523 iptr->sx.s23.s3.c.ref,
2526 if (opt_showdisassemble)
2530 disp = dseg_add_address(cd, super->vftbl);
2533 emit_label_beq(cd, BRANCH_LABEL_5);
2536 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2537 M_DSEG_LOAD(REG_ITMP3, disp);
2539 CODEGEN_CRITICAL_SECTION_START;
2541 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2542 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2543 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2544 M_DSEG_LOAD(REG_ITMP3, disp);
2545 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2547 CODEGEN_CRITICAL_SECTION_END;
2549 M_CMP(REG_ITMP2, REG_ITMP3);
2550 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2553 emit_label(cd, BRANCH_LABEL_5);
2556 if (super == NULL) {
2557 emit_label(cd, BRANCH_LABEL_1);
2558 emit_label(cd, BRANCH_LABEL_4);
2561 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2564 /* array type cast-check */
2566 s1 = emit_load_s1(jd, iptr, REG_A0);
2567 M_INTMOVE(s1, REG_A0);
2569 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2570 disp = dseg_add_unique_address(cd, NULL);
2572 codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
2573 iptr->sx.s23.s3.c.ref,
2576 if (opt_showdisassemble)
2580 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2582 M_DSEG_LOAD(REG_A1, disp);
2583 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2584 M_DSEG_BRANCH(disp);
2587 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2588 M_RECOMPUTE_PV(disp);
2590 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2591 M_TST(REG_RESULT, REG_RESULT);
2592 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2594 d = codegen_reg_of_dst(jd, iptr, s1);
2598 emit_store_dst(jd, iptr, d);
2601 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2607 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2612 super = iptr->sx.s23.s3.c.cls;
2613 superindex = super->index;
2616 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2617 CODEGEN_CRITICAL_SECTION_NEW;
2619 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2620 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2623 M_MOV(REG_ITMP1, s1);
2627 /* if class is not resolved, check which code to call */
2629 if (super == NULL) {
2633 emit_label_beq(cd, BRANCH_LABEL_1);
2635 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2636 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2637 iptr->sx.s23.s3.c.ref, disp);
2639 if (opt_showdisassemble)
2642 M_DSEG_LOAD(REG_ITMP2, disp);
2643 disp = dseg_add_s4(cd, ACC_INTERFACE);
2644 M_DSEG_LOAD(REG_ITMP3, disp);
2645 M_TST(REG_ITMP2, REG_ITMP3);
2646 emit_label_beq(cd, BRANCH_LABEL_2);
2649 /* interface checkcast code */
2651 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2652 if ((super == NULL) || !IS_IMM(superindex)) {
2653 disp = dseg_add_unique_s4(cd, superindex);
2655 if (super == NULL) {
2656 /* If d == REG_ITMP2, then it's destroyed in check
2661 codegen_addpatchref(cd,
2662 PATCHER_checkcast_instanceof_interface,
2663 iptr->sx.s23.s3.c.ref, disp);
2665 if (opt_showdisassemble)
2671 emit_label_beq(cd, BRANCH_LABEL_3);
2674 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2675 M_LDR_INTERN(REG_ITMP3,
2676 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2678 /* we put unresolved or non-immediate superindices onto dseg
2679 and do things slightly different */
2680 if ((super == NULL) || !IS_IMM(superindex)) {
2681 /* disp was computed before we added the patcher */
2682 M_DSEG_LOAD(REG_ITMP2, disp);
2683 M_CMP(REG_ITMP3, REG_ITMP2);
2685 if (d == REG_ITMP2) {
2692 /* this assumes something */
2693 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2695 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2696 assert(sizeof(methodptr*) == 4);
2697 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2699 if (d == REG_ITMP2) {
2706 assert(IS_IMM(superindex));
2707 M_CMP_IMM(REG_ITMP3, superindex);
2711 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2712 superindex * sizeof(methodptr*);
2716 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2717 M_TST(REG_ITMP3, REG_ITMP3);
2721 emit_label_br(cd, BRANCH_LABEL_4);
2723 emit_label(cd, BRANCH_LABEL_3);
2726 /* class checkcast code */
2728 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2729 if (super == NULL) {
2730 emit_label(cd, BRANCH_LABEL_2);
2732 disp = dseg_add_unique_address(cd, NULL);
2734 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2735 iptr->sx.s23.s3.c.ref,
2738 if (opt_showdisassemble)
2742 disp = dseg_add_address(cd, super->vftbl);
2746 emit_label_beq(cd, BRANCH_LABEL_5);
2749 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2750 M_DSEG_LOAD(REG_ITMP2, disp);
2752 CODEGEN_CRITICAL_SECTION_START;
2754 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2755 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2756 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2758 CODEGEN_CRITICAL_SECTION_END;
2760 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2761 M_CMP(REG_ITMP1, REG_ITMP2);
2762 /* If d == REG_ITMP2, then it's destroyed */
2768 emit_label(cd, BRANCH_LABEL_5);
2771 if (super == NULL) {
2772 emit_label(cd, BRANCH_LABEL_1);
2773 emit_label(cd, BRANCH_LABEL_4);
2778 emit_store_dst(jd, iptr, d);
2781 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2783 /* copy sizes to stack if necessary */
2785 MCODECHECK((iptr->s1.argcount << 1) + 64);
2787 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2789 var = VAR(iptr->sx.s23.s2.args[s1]);
2791 /* copy SAVEDVAR sizes to stack */
2793 if (!(var->flags & PREALLOC)) {
2794 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2795 M_STR(s2, REG_SP, s1 * 4);
2799 /* a0 = dimension count */
2801 assert(IS_IMM(iptr->s1.argcount));
2802 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2804 /* is patcher function set? */
2806 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2807 disp = dseg_add_unique_address(cd, NULL);
2809 codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
2810 iptr->sx.s23.s3.c.ref, disp);
2812 if (opt_showdisassemble)
2816 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2818 /* a1 = arraydescriptor */
2820 M_DSEG_LOAD(REG_A1, disp);
2822 /* a2 = pointer to dimensions = stack pointer */
2824 M_INTMOVE(REG_SP, REG_A2);
2826 /* call builtin_multianewarray here */
2828 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2829 M_DSEG_BRANCH(disp);
2833 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2836 /* check for exception before result assignment */
2838 emit_exception_check(cd, iptr);
2842 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2843 M_INTMOVE(REG_RESULT, d);
2844 emit_store_dst(jd, iptr, d);
2847 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2849 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2850 emit_nullpointer_check(cd, iptr, s1);
2854 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2857 } /* the big switch */
2859 } /* for all instructions */
2861 } /* for all basic blocks */
2863 dseg_createlinenumbertable(cd);
2866 /* generate stubs */
2868 emit_patcher_stubs(jd);
2870 /* everything's ok */
2876 /* codegen_emit_stub_compiler **************************************************
2878 Emits a stub routine which calls the compiler.
2880 *******************************************************************************/
2882 void codegen_emit_stub_compiler(jitdata *jd)
2887 /* get required compiler data */
2892 /* code for the stub */
2894 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2895 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2899 /* codegen_emit_stub_native ****************************************************
2901 Emits a stub routine which calls a native method.
2903 *******************************************************************************/
2905 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2914 s4 disp, funcdisp, s1, s2;
2916 /* get required compiler data */
2922 /* initialize variables */
2925 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2927 /* calculate stackframe size */
2929 cd->stackframesize =
2930 4 + /* return address */
2931 sizeof(stackframeinfo) + /* stackframeinfo */
2932 sizeof(localref_table) + /* localref_table */
2933 nmd->memuse * 4; /* stack arguments */
2935 /* align stack to 8-byte */
2937 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2939 /* create method header */
2941 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2942 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2943 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2944 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2945 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2946 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2947 (void) dseg_addlinenumbertablesize(cd);
2948 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2950 /* generate stub code */
2952 M_STMFD(1<<REG_LR, REG_SP);
2953 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2955 #if !defined(NDEBUG)
2956 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2957 emit_verbosecall_enter(jd);
2960 /* get function address (this must happen before the stackframeinfo) */
2962 funcdisp = dseg_add_functionptr(cd, f);
2964 #if !defined(WITH_STATIC_CLASSPATH)
2966 codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
2968 if (opt_showdisassemble)
2973 /* Save integer and float argument registers (these are 4
2974 registers, stack is 8-byte aligned). */
2976 M_STMFD(BITMASK_ARGS, REG_SP);
2977 /* TODO: floating point */
2979 /* create native stackframe info */
2981 assert(IS_IMM(4*4 + cd->stackframesize));
2982 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
2983 M_MOV(REG_A1, REG_PV);
2984 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize);
2985 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize - SIZEOF_VOID_P);
2986 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2987 M_DSEG_BRANCH(disp);
2991 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2994 /* Restore integer and float argument registers (these are 4
2995 registers, stack is 8-byte aligned). */
2997 M_LDMFD(BITMASK_ARGS, REG_SP);
2998 /* TODO: floating point */
3000 /* copy or spill arguments to new locations */
3001 /* ATTENTION: the ARM has only integer argument registers! */
3003 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3004 t = md->paramtypes[i].type;
3006 if (!md->params[i].inmemory) {
3007 s1 = md->params[i].regoff;
3008 s2 = nmd->params[j].regoff;
3010 if (!nmd->params[j].inmemory) {
3011 #if !defined(__ARM_EABI__)
3012 SPLIT_OPEN(t, s2, REG_ITMP1);
3015 if (IS_2_WORD_TYPE(t))
3020 #if !defined(__ARM_EABI__)
3021 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3025 if (IS_2_WORD_TYPE(t))
3026 M_LST(s1, REG_SP, s2);
3028 M_IST(s1, REG_SP, s2);
3032 s1 = md->params[i].regoff + cd->stackframesize;
3033 s2 = nmd->params[j].regoff;
3035 if (IS_2_WORD_TYPE(t)) {
3036 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3037 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3040 M_ILD(REG_ITMP1, REG_SP, s1);
3041 M_IST(REG_ITMP1, REG_SP, s2);
3046 /* put class into second argument register */
3048 if (m->flags & ACC_STATIC) {
3049 disp = dseg_add_address(cd, m->class);
3050 M_DSEG_LOAD(REG_A1, disp);
3053 /* put env into first argument register */
3055 disp = dseg_add_address(cd, _Jv_env);
3056 M_DSEG_LOAD(REG_A0, disp);
3058 /* do the native function call */
3060 M_DSEG_BRANCH(funcdisp);
3063 /* TODO: this is only needed because of the tracer ... do we
3066 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3069 #if !defined(__SOFTFP__)
3070 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3071 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3072 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3073 #if 0 && !defined(NDEBUG)
3074 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3076 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3077 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3078 if (IS_2_WORD_TYPE(md->returntype.type)) {
3079 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3080 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3082 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3083 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3088 #if !defined(NDEBUG)
3089 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3090 emit_verbosecall_exit(jd);
3093 /* remove native stackframe info */
3094 /* TODO: improve this store/load */
3096 M_STMFD(BITMASK_RESULT, REG_SP);
3098 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize - SIZEOF_VOID_P);
3099 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3100 M_DSEG_BRANCH(disp);
3101 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3104 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3105 M_LDMFD(BITMASK_RESULT, REG_SP);
3107 /* finish stub code, but do not yet return to caller */
3109 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3110 M_LDMFD(1<<REG_LR, REG_SP);
3112 /* check for exception */
3114 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3115 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3117 /* handle exception here */
3119 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3121 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3122 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3123 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3125 /* generate patcher stubs */
3127 emit_patcher_stubs(jd);
3131 /* asm_debug *******************************************************************
3135 *******************************************************************************/
3137 void asm_debug(int a1, int a2, int a3, int a4)
3139 printf("===> i am going to exit after this debugging message!\n");
3140 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3141 vm_abort("leave you now");
3146 * These are local overrides for various environment variables in Emacs.
3147 * Please do not remove this and leave it at the end of the file, where
3148 * Emacs will automagically detect them.
3149 * ---------------------------------------------------------------------
3152 * indent-tabs-mode: t
3156 * vim:noexpandtab:sw=4:ts=4: