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 7766 2007-04-19 13:24:48Z 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 #if defined(ENABLE_THREADS)
47 # include "threads/native/lock.h"
50 #include "vm/builtin.h"
51 #include "vm/exceptions.h"
52 #include "vm/global.h"
55 #include "vm/jit/asmpart.h"
56 #include "vm/jit/codegen-common.h"
57 #include "vm/jit/dseg.h"
58 #include "vm/jit/emit-common.h"
59 #include "vm/jit/jit.h"
60 #include "vm/jit/md.h"
61 #include "vm/jit/methodheader.h"
62 #include "vm/jit/parse.h"
63 #include "vm/jit/patcher.h"
64 #include "vm/jit/reg.h"
66 #if defined(ENABLE_LSRA)
67 #include "vm/jit/allocator/lsra.h"
70 #include "vmcore/loader.h"
71 #include "vmcore/options.h"
74 /* codegen_emit ****************************************************************
76 Generates machine code.
78 *******************************************************************************/
80 bool codegen_emit(jitdata *jd)
101 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
102 unresolved_method *um;
103 builtintable_entry *bte;
106 /* get required compiler data */
113 /* prevent compiler warnings */
121 /* space to save used callee saved registers */
123 savedregs_num = (jd->isleafmethod) ? 0 : 1; /* space to save the LR */
124 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
125 savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
127 spilledregs_num = rd->memuse;
129 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
130 if (checksync && (m->flags & ACC_SYNCHRONIZED))
134 cd->stackframesize = spilledregs_num + savedregs_num;
136 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
137 only in native stubs. */
138 /* align stack to 8-byte */
140 cd->stackframesize = (cd->stackframesize + 1) & ~1;
142 /* SECTION: Method Header */
143 /* create method header */
145 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
146 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
148 #if defined(ENABLE_THREADS)
149 /* IsSync contains the offset relative to the stack pointer for the
150 argument of monitor_exit used in the exception handler. Since the
151 offset could be zero and give a wrong meaning of the flag it is
155 if (checksync && (m->flags & ACC_SYNCHRONIZED))
156 (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 4);/* IsSync */
159 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
161 (void) dseg_add_unique_s4(cd, jd->isleafmethod); /* IsLeaf */
162 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
163 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
164 (void) dseg_addlinenumbertablesize(cd);
165 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
167 /* create exception table */
169 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
170 dseg_add_target(cd, ex->start);
171 dseg_add_target(cd, ex->end);
172 dseg_add_target(cd, ex->handler);
173 (void) dseg_add_unique_address(cd, ex->catchtype.any);
176 /* save return address and used callee saved registers */
178 savedregs_bitmask = 0;
180 if (!jd->isleafmethod)
181 savedregs_bitmask = (1<<REG_LR);
183 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
184 savedregs_bitmask |= (1<<(rd->savintregs[i]));
187 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
188 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
189 /* TODO: floating-point */
193 if (savedregs_bitmask)
194 M_STMFD(savedregs_bitmask, REG_SP);
196 /* create additional stack frame for spilled variables (if necessary) */
198 if ((cd->stackframesize - savedregs_num) > 0)
199 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
201 /* take arguments out of register or stack frame */
204 for (i = 0, len = 0; i < md->paramcount; i++) {
205 s1 = md->params[i].regoff;
206 t = md->paramtypes[i].type;
208 varindex = jd->local_map[len * 5 + t];
210 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
212 if (varindex == UNUSED)
217 /* ATTENTION: we use interger registers for all arguments (even float) */
218 #if !defined(ENABLE_SOFTFLOAT)
219 if (IS_INT_LNG_TYPE(t)) { /* integer args */
221 if (!md->params[i].inmemory) { /* register arguments */
222 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
223 if (GET_LOW_REG(var->vv.regoff) == REG_SPLIT || GET_HIGH_REG(var->vv.regoff) == REG_SPLIT) {
224 /* TODO: remove this!!! */
225 dolog("SPLIT in local var: %x>%x (%s.%s)", s1, var->vv.regoff, m->class->name->text, m->name->text);
226 assert(s1 == var->vv.regoff);
229 SPLIT_OPEN(t, s1, REG_ITMP1);
230 SPLIT_LOAD(t, s1, cd->stackframesize);
231 SPLIT_OPEN(t, s3, REG_ITMP1);
233 if (IS_2_WORD_TYPE(t))
238 SPLIT_STORE_AND_CLOSE(t, s3, cd->stackframesize);
240 else { /* reg arg -> spilled */
241 SPLIT_OPEN(t, s1, REG_ITMP1);
242 SPLIT_LOAD(t, s1, cd->stackframesize);
244 if (IS_2_WORD_TYPE(t))
245 M_LST(s1, REG_SP, var->vv.regoff * 4);
247 M_IST(s1, REG_SP, var->vv.regoff * 4);
248 /* no SPLIT_CLOSE here because arg is fully spilled now */
251 else { /* stack arguments */
252 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
253 if (IS_2_WORD_TYPE(t))
254 M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
256 M_ILD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
258 else { /* stack arg -> spilled */
259 /* Reuse Memory Position on Caller Stack */
260 var->vv.regoff = cd->stackframesize + s1;
263 #if !defined(ENABLE_SOFTFLOAT)
264 } else { /* floating args */
265 if (!md->params[i].inmemory) { /* register arguments */
266 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
267 SPLIT_OPEN(t, s1, REG_ITMP1);
268 SPLIT_LOAD(t, s1, cd->stackframesize);
269 M_CAST_INT_TO_FLT_TYPED(t, s1, var->vv.regoff);
271 else { /* reg arg -> spilled */
272 SPLIT_OPEN(t, s1, REG_ITMP1);
273 SPLIT_LOAD(t, s1, cd->stackframesize);
275 if (IS_2_WORD_TYPE(t))
276 M_LST(s1, REG_SP, var->vv.regoff * 4);
278 M_IST(s1, REG_SP, var->vv.regoff * 4);
279 /* no SPLIT_CLOSE here because arg is fully spilled now */
282 else { /* stack arguments */
283 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
284 if (IS_2_WORD_TYPE(t))
285 M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
287 M_FLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
289 else { /* stack arg -> spilled */
290 /* Reuse Memory Position on Caller Stack */
291 var->vv.regoff = cd->stackframesize + s1;
295 #endif /* !defined(ENABLE_SOFTFLOAT) */
298 #if defined(ENABLE_THREADS)
299 /* call monitorenter function */
301 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
302 /* stack offset for monitor argument */
306 # if !defined(NDEBUG)
307 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
308 M_STMFD(BITMASK_ARGS, REG_SP);
313 /* get the correct lock object */
315 if (m->flags & ACC_STATIC) {
316 disp = dseg_add_address(cd, &m->class->object.header);
317 M_DSEG_LOAD(REG_A0, disp);
320 emit_nullpointer_check_force(cd, iptr, REG_A0);
323 M_STR(REG_A0, REG_SP, s1 * 4);
324 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
326 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
329 # if !defined(NDEBUG)
330 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
331 M_LDMFD(BITMASK_ARGS, REG_SP);
337 /* call trace function */
339 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
340 emit_verbosecall_enter(jd);
343 /* end of header generation */
345 /* SECTION: ICMD Code Generation */
346 /* for all basic blocks */
348 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
350 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
352 /* is this basic block reached? */
354 if (bptr->flags < BBREACHED)
357 /* branch resolving */
359 codegen_resolve_branchrefs(cd, bptr);
361 /* copy interface registers to their destination */
367 #if defined(ENABLE_LSRA)
371 var = VAR(bptr->invars[len]);
372 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
373 if (!(var->flags & INMEMORY))
377 M_INTMOVE(REG_ITMP1, d);
378 emit_store(jd, NULL, var, d);
385 var = VAR(bptr->invars[len]);
387 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
388 d = codegen_reg_of_var(0, var, REG_ITMP1);
389 M_INTMOVE(REG_ITMP1, d);
390 emit_store(jd, NULL, var, d);
393 assert((var->flags & INOUT));
396 #if defined(ENABLE_LSRA)
400 /* for all instructions */
403 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
405 /* add line number */
406 if (iptr->line != currentline) {
407 dseg_addlinenumber(cd, iptr->line);
408 currentline = iptr->line;
411 MCODECHECK(64); /* an instruction usually needs < 64 words */
415 case ICMD_NOP: /* ... ==> ... */
418 /* constant operations ************************************************/
420 case ICMD_ICONST: /* ... ==> ..., constant */
422 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
423 ICONST(d, iptr->sx.val.i);
424 emit_store_dst(jd, iptr, d);
427 case ICMD_ACONST: /* ... ==> ..., constant */
429 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
430 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
431 disp = dseg_add_unique_address(cd, NULL);
433 codegen_addpatchref(cd, PATCHER_aconst,
437 if (opt_showdisassemble)
440 M_DSEG_LOAD(d, disp);
443 ICONST(d, (u4) iptr->sx.val.anyptr);
445 emit_store_dst(jd, iptr, d);
448 case ICMD_LCONST: /* ... ==> ..., constant */
450 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
451 LCONST(d, iptr->sx.val.l);
452 emit_store_dst(jd, iptr, d);
455 case ICMD_FCONST: /* ... ==> ..., constant */
457 #if defined(ENABLE_SOFTFLOAT)
458 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
459 ICONST(d, iptr->sx.val.i);
460 emit_store_dst(jd, iptr, d);
462 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
463 FCONST(d, iptr->sx.val.f);
464 emit_store_dst(jd, iptr, d);
468 case ICMD_DCONST: /* ... ==> ..., constant */
470 #if defined(ENABLE_SOFTFLOAT)
471 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
472 LCONST(d, iptr->sx.val.l);
473 emit_store_dst(jd, iptr, d);
475 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
476 DCONST(d, iptr->sx.val.d);
477 emit_store_dst(jd, iptr, d);
482 /* load/store/copy/move operations ************************************/
484 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
485 case ICMD_ALOAD: /* op1 = local variable */
489 case ICMD_ISTORE: /* ..., value ==> ... */
500 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
504 /* pop operations *****************************************************/
506 /* attention: double and longs are only one entry in CACAO ICMDs */
508 case ICMD_POP: /* ..., value ==> ... */
509 case ICMD_POP2: /* ..., value, value ==> ... */
514 /* integer operations *************************************************/
516 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
518 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
519 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
520 M_MOV(d, REG_LSL(s1, 24));
521 M_MOV(d, REG_ASR(d, 24));
522 emit_store_dst(jd, iptr, d);
525 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
527 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
528 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
529 M_MOV(d, REG_LSL(s1, 16));
530 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
531 emit_store_dst(jd, iptr, d);
534 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
536 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
537 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
538 M_MOV(d, REG_LSL(s1, 16));
539 M_MOV(d, REG_ASR(d, 16));
540 emit_store_dst(jd, iptr, d);
543 case ICMD_I2L: /* ..., value ==> ..., value */
545 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
546 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
547 M_INTMOVE(s1, GET_LOW_REG(d));
548 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
549 emit_store_dst(jd, iptr, d);
552 case ICMD_L2I: /* ..., value ==> ..., value */
554 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
555 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
557 emit_store_dst(jd, iptr, d);
560 case ICMD_INEG: /* ..., value ==> ..., - value */
562 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
565 emit_store_dst(jd, iptr, d);
568 case ICMD_LNEG: /* ..., value ==> ..., - value */
570 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
571 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
572 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
573 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
574 emit_store_dst(jd, iptr, d);
577 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
579 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
580 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
581 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
583 emit_store_dst(jd, iptr, d);
586 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
588 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
589 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
590 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
591 M_ADD_S(GET_LOW_REG(d), s1, s2);
592 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
593 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
594 M_ADC(GET_HIGH_REG(d), s1, s2);
595 emit_store_dst(jd, iptr, d);
601 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
602 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
604 if (IS_IMM(iptr->sx.val.i)) {
605 M_ADD_IMM(d, s1, iptr->sx.val.i);
606 } else if (IS_IMM(-iptr->sx.val.i)) {
607 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
609 ICONST(REG_ITMP3, iptr->sx.val.i);
610 M_ADD(d, s1, REG_ITMP3);
613 emit_store_dst(jd, iptr, d);
616 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
617 /* sx.val.l = constant */
619 s3 = iptr->sx.val.l & 0xffffffff;
620 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
621 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
623 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
625 ICONST(REG_ITMP3, s3);
626 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
628 s3 = iptr->sx.val.l >> 32;
629 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
631 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
633 ICONST(REG_ITMP3, s3);
634 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
636 emit_store_dst(jd, iptr, d);
639 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
641 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
642 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
643 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
645 emit_store_dst(jd, iptr, d);
648 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
650 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
651 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
652 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
653 M_SUB_S(GET_LOW_REG(d), s1, s2);
654 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
655 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
656 M_SBC(GET_HIGH_REG(d), s1, s2);
657 emit_store_dst(jd, iptr, d);
660 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
661 /* sx.val.i = constant */
663 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
664 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
665 if (IS_IMM(iptr->sx.val.i))
666 M_SUB_IMM(d, s1, iptr->sx.val.i);
668 ICONST(REG_ITMP3, iptr->sx.val.i);
669 M_SUB(d, s1, REG_ITMP3);
671 emit_store_dst(jd, iptr, d);
674 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
675 /* sx.val.l = constant */
677 s3 = iptr->sx.val.l & 0xffffffff;
678 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
679 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
681 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
683 ICONST(REG_ITMP3, s3);
684 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
686 s3 = iptr->sx.val.l >> 32;
687 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
689 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
691 ICONST(REG_ITMP3, s3);
692 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
694 emit_store_dst(jd, iptr, d);
697 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
699 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
700 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
701 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
703 emit_store_dst(jd, iptr, d);
706 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
707 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
709 s1 = emit_load_s1(jd, iptr, REG_A0);
710 s2 = emit_load_s2(jd, iptr, REG_A1);
711 emit_arithmetic_check(cd, iptr, s2);
713 /* move arguments into argument registers */
714 M_INTMOVE(s1, REG_A0);
715 M_INTMOVE(s2, REG_A1);
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);
728 M_INTMOVE(REG_RESULT, d);
729 emit_store_dst(jd, iptr, d);
732 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
733 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
735 /* move arguments into argument registers */
737 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
738 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
739 /* XXX TODO: only do this if arithmetic check is really done! */
740 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
741 emit_arithmetic_check(cd, iptr, REG_ITMP3);
743 M_LNGMOVE(s1, REG_A0_A1_PACKED);
744 M_LNGMOVE(s2, REG_A2_A3_PACKED);
746 /* call builtin function */
747 bte = iptr->sx.s23.s3.bte;
748 disp = dseg_add_functionptr(cd, bte->fp);
752 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
755 /* move result into destination register */
756 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
757 M_LNGMOVE(REG_RESULT_PACKED, d);
758 emit_store_dst(jd, iptr, d);
761 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
762 /* sx.val.i = constant */
764 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
765 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
766 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
767 emit_store_dst(jd, iptr, d);
770 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
771 /* sx.val.i = constant */
773 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
774 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
775 /* this rounds towards 0 as java likes it */
776 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
777 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
778 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
779 /* this rounds towards nearest, not java style */
780 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
781 M_ADCMI_IMM(d, d, 0);*/
782 emit_store_dst(jd, iptr, d);
785 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
786 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
788 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
789 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
790 M_MOV_S(REG_ITMP1, s1);
791 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
792 if (IS_IMM(iptr->sx.val.i))
793 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
795 ICONST(REG_ITMP3, iptr->sx.val.i);
796 M_AND(REG_ITMP1, REG_ITMP3, d);
798 M_RSBMI_IMM(d, d, 0);
799 emit_store_dst(jd, iptr, d);
802 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
804 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
805 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
806 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
807 M_AND_IMM(s2, 0x1f, REG_ITMP2);
808 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
809 emit_store_dst(jd, iptr, d);
812 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
814 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
815 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
816 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
817 M_AND_IMM(s2, 0x1f, REG_ITMP2);
818 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
819 emit_store_dst(jd, iptr, d);
822 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
824 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
825 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
826 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
827 M_AND_IMM(s2, 0x1f, REG_ITMP2);
828 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
829 emit_store_dst(jd, iptr, d);
832 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
833 /* sx.val.i = constant */
835 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
836 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
837 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
838 emit_store_dst(jd, iptr, d);
841 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
842 /* sx.val.i = constant */
844 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
845 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
846 /* we need to check for zero here because arm interprets it as SHR by 32 */
847 if ((iptr->sx.val.i & 0x1f) == 0) {
850 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
852 emit_store_dst(jd, iptr, d);
855 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
856 /* sx.val.i = constant */
858 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
859 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
860 /* we need to check for zero here because arm interprets it as SHR by 32 */
861 if ((iptr->sx.val.i & 0x1f) == 0)
864 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
865 emit_store_dst(jd, iptr, d);
868 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
870 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
871 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
872 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
874 emit_store_dst(jd, iptr, d);
877 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
879 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
880 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
881 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
882 M_AND(s1, s2, GET_LOW_REG(d));
883 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
884 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
885 M_AND(s1, s2, GET_HIGH_REG(d));
886 emit_store_dst(jd, iptr, d);
889 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
891 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
892 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
893 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
895 emit_store_dst(jd, iptr, d);
898 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
900 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
901 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
902 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
903 M_ORR(s1, s2, GET_LOW_REG(d));
904 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
905 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
906 M_ORR(s1, s2, GET_HIGH_REG(d));
907 emit_store_dst(jd, iptr, d);
910 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
912 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
913 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
914 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
916 emit_store_dst(jd, iptr, d);
919 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
921 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
922 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
923 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
924 M_EOR(s1, s2, GET_LOW_REG(d));
925 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
926 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
927 M_EOR(s1, s2, GET_HIGH_REG(d));
928 emit_store_dst(jd, iptr, d);
932 /* floating operations ************************************************/
934 #if !defined(ENABLE_SOFTFLOAT)
936 case ICMD_FNEG: /* ..., value ==> ..., - value */
938 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
939 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
941 emit_store_dst(jd, iptr, d);
944 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
946 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
947 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
948 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
950 emit_store_dst(jd, iptr, d);
953 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
955 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
956 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
957 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
959 emit_store_dst(jd, iptr, d);
962 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
964 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
965 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
966 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
968 emit_store_dst(jd, iptr, d);
971 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
972 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
973 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
974 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
976 emit_store_dst(jd, iptr, d);
979 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
982 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
984 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
985 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
986 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
988 emit_store_dst(jd, iptr, d);
991 case ICMD_DNEG: /* ..., value ==> ..., - value */
993 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
994 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
996 emit_store_dst(jd, iptr, d);
999 case ICMD_DADD: /* ..., 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 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1010 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1011 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1012 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1014 emit_store_dst(jd, iptr, d);
1017 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1019 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1020 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1021 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1023 emit_store_dst(jd, iptr, d);
1026 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1028 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1029 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1030 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1032 emit_store_dst(jd, iptr, d);
1035 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1038 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1040 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1041 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1042 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1044 emit_store_dst(jd, iptr, d);
1047 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1049 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1050 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1052 emit_store_dst(jd, iptr, d);
1055 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1057 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1058 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1060 emit_store_dst(jd, iptr, d);
1063 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1065 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1066 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1067 /* this uses round towards zero, as Java likes it */
1069 /* this checks for NaN; to return zero as Java likes it */
1072 emit_store_dst(jd, iptr, d);
1075 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1077 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1078 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1079 /* this uses round towards zero, as Java likes it */
1081 /* this checks for NaN; to return zero as Java likes it */
1084 emit_store_dst(jd, iptr, d);
1087 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1089 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1090 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1092 emit_store_dst(jd, iptr, d);
1095 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1097 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1098 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1100 emit_store_dst(jd, iptr, d);
1103 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1105 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1106 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1107 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1110 M_SUBGT_IMM(d, d, 1);
1111 M_ADDLT_IMM(d, d, 1);
1112 emit_store_dst(jd, iptr, d);
1115 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1117 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1118 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1119 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1122 M_SUBGT_IMM(d, d, 1);
1123 M_ADDLT_IMM(d, d, 1);
1124 emit_store_dst(jd, iptr, d);
1127 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl 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 M_SUBLT_IMM(d, d, 1);
1135 M_ADDGT_IMM(d, d, 1);
1136 emit_store_dst(jd, iptr, d);
1139 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1141 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1142 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1143 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1146 M_SUBLT_IMM(d, d, 1);
1147 M_ADDGT_IMM(d, d, 1);
1148 emit_store_dst(jd, iptr, d);
1151 #endif /* !defined(ENABLE_SOFTFLOAT) */
1154 /* memory operations **************************************************/
1156 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1158 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1159 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1160 /* implicit null-pointer check */
1161 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1162 emit_store_dst(jd, iptr, d);
1165 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1167 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1168 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1169 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1170 /* implicit null-pointer check */
1171 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1172 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1173 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1174 emit_store_dst(jd, iptr, d);
1177 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1179 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1180 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1181 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1182 /* implicit null-pointer check */
1183 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1184 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1185 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1186 emit_store_dst(jd, iptr, d);
1189 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1191 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1192 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1193 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1194 /* implicit null-pointer check */
1195 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1196 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1197 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1198 emit_store_dst(jd, iptr, d);
1201 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1203 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1204 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1205 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1206 /* implicit null-pointer check */
1207 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1208 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1209 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1210 emit_store_dst(jd, iptr, d);
1213 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1215 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1216 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1217 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1218 /* implicit null-pointer check */
1219 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1220 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1221 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1222 emit_store_dst(jd, iptr, d);
1225 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1227 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1228 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1229 /* implicit null-pointer check */
1230 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1231 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1232 #if !defined(ENABLE_SOFTFLOAT)
1233 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1234 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1236 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1237 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1239 emit_store_dst(jd, iptr, d);
1242 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1244 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1245 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1246 /* implicit null-pointer check */
1247 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1248 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1249 #if !defined(ENABLE_SOFTFLOAT)
1250 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1251 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1253 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1254 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1256 emit_store_dst(jd, iptr, d);
1259 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1261 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1262 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1263 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1264 /* implicit null-pointer check */
1265 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1266 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1267 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1268 emit_store_dst(jd, iptr, d);
1271 case ICMD_BASTORE: /* ..., 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, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1279 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1282 case ICMD_CASTORE: /* ..., 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, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1290 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1293 case ICMD_SASTORE: /* ..., 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 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1300 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1301 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1304 case ICMD_IASTORE: /* ..., 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 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1311 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1312 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1315 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1317 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1318 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1319 /* implicit null-pointer check */
1320 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1321 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1322 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1323 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1326 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1328 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1329 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1330 /* implicit null-pointer check */
1331 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1332 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1333 #if !defined(ENABLE_SOFTFLOAT)
1334 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1335 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1337 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1338 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1342 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1344 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1345 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1346 /* implicit null-pointer check */
1347 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1348 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1349 #if !defined(ENABLE_SOFTFLOAT)
1350 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1351 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1353 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1354 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1358 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1360 s1 = emit_load_s1(jd, iptr, REG_A0);
1361 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1362 s3 = emit_load_s3(jd, iptr, REG_A1);
1364 /* implicit null-pointer check */
1365 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1367 /* move arguments to argument registers */
1368 M_INTMOVE(s1, REG_A0);
1369 M_INTMOVE(s3, REG_A1);
1371 /* call builtin function */
1372 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1373 M_DSEG_BRANCH(disp);
1376 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1379 /* check resturn value of builtin */
1380 emit_exception_check(cd, iptr);
1382 /* finally store address into array */
1383 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1384 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1385 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1386 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1387 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1390 case ICMD_GETSTATIC: /* ... ==> ..., value */
1392 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1393 unresolved_field *uf = iptr->sx.s23.s3.uf;
1395 fieldtype = uf->fieldref->parseddesc.fd->type;
1397 disp = dseg_add_unique_address(cd, NULL);
1399 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1401 if (opt_showdisassemble)
1405 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1407 fieldtype = fi->type;
1409 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1410 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1412 if (opt_showdisassemble)
1416 disp = dseg_add_address(cd, &(fi->value));
1419 M_DSEG_LOAD(REG_ITMP3, disp);
1420 switch (fieldtype) {
1422 #if defined(ENABLE_SOFTFLOAT)
1426 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1427 M_ILD_INTERN(d, REG_ITMP3, 0);
1430 #if defined(ENABLE_SOFTFLOAT)
1433 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1434 M_LLD_INTERN(d, REG_ITMP3, 0);
1436 #if !defined(ENABLE_SOFTFLOAT)
1438 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1439 M_FLD_INTERN(d, REG_ITMP3, 0);
1442 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1443 M_DLD_INTERN(d, REG_ITMP3, 0);
1449 emit_store_dst(jd, iptr, d);
1452 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1454 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1455 unresolved_field *uf = iptr->sx.s23.s3.uf;
1457 fieldtype = uf->fieldref->parseddesc.fd->type;
1459 disp = dseg_add_unique_address(cd, NULL);
1461 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1463 if (opt_showdisassemble)
1467 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1469 fieldtype = fi->type;
1471 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1472 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1474 if (opt_showdisassemble)
1478 disp = dseg_add_address(cd, &(fi->value));
1481 M_DSEG_LOAD(REG_ITMP3, disp);
1482 switch (fieldtype) {
1484 #if defined(ENABLE_SOFTFLOAT)
1488 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1489 M_IST_INTERN(s1, REG_ITMP3, 0);
1492 #if defined(ENABLE_SOFTFLOAT)
1495 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1496 M_LST_INTERN(s1, REG_ITMP3, 0);
1498 #if !defined(ENABLE_SOFTFLOAT)
1500 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1501 M_FST_INTERN(s1, REG_ITMP3, 0);
1504 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1505 M_DST_INTERN(s1, REG_ITMP3, 0);
1513 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1515 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1516 emit_nullpointer_check(cd, iptr, s1);
1519 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1520 unresolved_field *uf = iptr->sx.s23.s3.uf;
1522 fieldtype = uf->fieldref->parseddesc.fd->type;
1525 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1527 fieldtype = fi->type;
1531 #if !defined(ENABLE_SOFTFLOAT)
1532 /* HACK: softnull checks on floats */
1533 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1534 emit_nullpointer_check_force(cd, iptr, s1);
1537 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1538 unresolved_field *uf = iptr->sx.s23.s3.uf;
1540 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1542 if (opt_showdisassemble)
1548 switch (fieldtype) {
1550 #if defined(ENABLE_SOFTFLOAT)
1554 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1558 #if defined(ENABLE_SOFTFLOAT)
1561 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1564 #if !defined(ENABLE_SOFTFLOAT)
1566 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1570 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1577 emit_store_dst(jd, iptr, d);
1580 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1582 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1583 emit_nullpointer_check(cd, iptr, s1);
1585 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1586 unresolved_field *uf = iptr->sx.s23.s3.uf;
1588 fieldtype = uf->fieldref->parseddesc.fd->type;
1591 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1593 fieldtype = fi->type;
1597 #if !defined(ENABLE_SOFTFLOAT)
1598 /* HACK: softnull checks on floats */
1599 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1600 emit_nullpointer_check_force(cd, iptr, s1);
1603 switch (fieldtype) {
1605 #if defined(ENABLE_SOFTFLOAT)
1609 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1611 #if defined(ENABLE_SOFTFLOAT)
1612 case TYPE_DBL: /* fall through */
1615 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1617 #if !defined(ENABLE_SOFTFLOAT)
1620 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1627 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1628 unresolved_field *uf = iptr->sx.s23.s3.uf;
1630 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1632 if (opt_showdisassemble)
1638 switch (fieldtype) {
1640 #if defined(ENABLE_SOFTFLOAT)
1644 M_IST(s2, s1, disp);
1647 #if defined(ENABLE_SOFTFLOAT)
1650 M_LST(s2, s1, disp);
1652 #if !defined(ENABLE_SOFTFLOAT)
1654 M_FST(s2, s1, disp);
1657 M_DST(s2, s1, disp);
1666 /* branch operations **************************************************/
1668 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1670 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1671 M_INTMOVE(s1, REG_ITMP1_XPTR);
1672 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1673 codegen_addpatchref(cd, PATCHER_athrow_areturn,
1674 iptr->sx.s23.s2.uc, 0);
1676 if (opt_showdisassemble)
1679 disp = dseg_add_functionptr(cd, asm_handle_exception);
1680 M_DSEG_LOAD(REG_ITMP3, disp);
1681 M_MOV(REG_ITMP2_XPC, REG_PC);
1682 M_MOV(REG_PC, REG_ITMP3);
1683 M_NOP; /* nop ensures that XPC is less than the end */
1684 /* of basic block */
1687 case ICMD_GOTO: /* ... ==> ... */
1690 emit_br(cd, iptr->dst.block);
1693 case ICMD_JSR: /* ... ==> ... */
1695 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1698 case ICMD_IFNULL: /* ..., value ==> ... */
1699 case ICMD_IFNONNULL:
1701 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1703 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1706 case ICMD_IFLT: /* ..., value ==> ... */
1707 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1713 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1714 M_COMPARE(s1, iptr->sx.val.i);
1715 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1718 case ICMD_IF_LEQ: /* ..., value ==> ... */
1720 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1721 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1722 if (iptr->sx.val.l == 0) {
1723 M_ORR_S(s1, s2, REG_ITMP3);
1726 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1727 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1728 M_CMP(s1, REG_ITMP3);*/
1729 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1730 M_CMPEQ(s2, REG_ITMP3);
1732 emit_beq(cd, iptr->dst.block);
1735 case ICMD_IF_LLT: /* ..., value ==> ... */
1737 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1738 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1739 if (iptr->sx.val.l == 0) {
1740 /* if high word is less than zero, the whole long is too */
1742 emit_blt(cd, iptr->dst.block);
1745 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1746 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1747 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1748 M_CMP(s1, REG_ITMP3);*/
1749 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1750 M_MOVGT_IMM(2, REG_ITMP1);
1751 M_MOVEQ_IMM(1, REG_ITMP1);
1753 /* low compare: x=x-1(ifLO) */
1754 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1755 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1756 M_CMP(s2, REG_ITMP3);*/
1757 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1759 /* branch if (x LT 1) */
1760 M_CMP_IMM(REG_ITMP1, 1);
1761 emit_blt(cd, iptr->dst.block);
1765 case ICMD_IF_LLE: /* ..., value ==> ... */
1767 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1768 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1769 if (iptr->sx.val.l == 0) {
1770 /* if high word is less than zero, the whole long is too */
1772 emit_blt(cd, iptr->dst.block);
1774 /* ... otherwise the low word has to be zero (tricky!) */
1776 emit_beq(cd, iptr->dst.block);
1779 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1780 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1781 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1782 M_CMP(s1, REG_ITMP3);*/
1783 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1784 M_MOVGT_IMM(2, REG_ITMP1);
1785 M_MOVEQ_IMM(1, REG_ITMP1);
1787 /* low compare: x=x+1(ifHI) */
1788 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1789 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1790 M_CMP(s2, REG_ITMP3);*/
1791 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1793 /* branch if (x LE 1) */
1794 M_CMP_IMM(REG_ITMP1, 1);
1795 emit_ble(cd, iptr->dst.block);
1799 case ICMD_IF_LGE: /* ..., value ==> ... */
1801 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1802 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1803 if (iptr->sx.val.l == 0) {
1804 /* if high word is greater or equal zero, the whole long is too */
1806 emit_bge(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(ifLO) */
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_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1823 /* branch if (x GE 1) */
1824 M_CMP_IMM(REG_ITMP1, 1);
1825 emit_bge(cd, iptr->dst.block);
1829 case ICMD_IF_LGT: /* ..., value ==> ... */
1831 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1832 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1834 if (iptr->sx.val.l == 0) {
1835 /* if high word is greater than zero, the whole long is too */
1838 codegen_add_branch_ref(cd, iptr->dst.block);
1840 /* ... or high was zero and low is non zero (tricky!) */
1841 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1842 M_MOVLT_IMM(1, REG_ITMP3);
1843 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1845 codegen_add_branch_ref(cd, iptr->dst.block);
1849 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1850 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1851 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1852 M_CMP(s1, REG_ITMP3);*/
1853 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1854 M_MOVGT_IMM(2, REG_ITMP1);
1855 M_MOVEQ_IMM(1, REG_ITMP1);
1857 /* low compare: x=x+1(ifHI) */
1858 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1859 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1860 M_CMP(s2, REG_ITMP3);*/
1861 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1863 /* branch if (x GT 1) */
1864 M_CMP_IMM(REG_ITMP1, 1);
1865 emit_bgt(cd, iptr->dst.block);
1871 case ICMD_IF_LNE: /* ..., value ==> ... */
1873 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1874 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1875 if (iptr->sx.val.l == 0) {
1876 M_ORR_S(s1, s2, REG_ITMP3);
1879 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1880 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1881 M_CMP(s1, REG_ITMP3);*/
1882 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1883 M_CMPEQ(s2, REG_ITMP3);
1885 emit_bne(cd, iptr->dst.block);
1888 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1889 case ICMD_IF_ICMPNE:
1890 case ICMD_IF_ICMPLT:
1891 case ICMD_IF_ICMPLE:
1892 case ICMD_IF_ICMPGT:
1893 case ICMD_IF_ICMPGE:
1895 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1896 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1898 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1901 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1902 case ICMD_IF_ACMPNE:
1904 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1905 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1907 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1910 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1911 /* op1 = target JavaVM pc */
1913 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1914 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1917 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1918 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1921 emit_beq(cd, iptr->dst.block);
1924 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1925 /* op1 = target JavaVM pc */
1927 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1928 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1931 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1932 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1935 emit_bne(cd, iptr->dst.block);
1938 case ICMD_IF_LCMPLT: /* ..., 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_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1955 /* branch if (x LT 1) */
1956 M_CMP_IMM(REG_ITMP3, 1);
1957 emit_blt(cd, iptr->dst.block);
1960 case ICMD_IF_LCMPLE: /* ..., 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 LE 1) */
1978 M_CMP_IMM(REG_ITMP3, 1);
1979 emit_ble(cd, iptr->dst.block);
1982 case ICMD_IF_LCMPGT: /* ..., 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_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1999 /* branch if (x GT 1) */
2000 M_CMP_IMM(REG_ITMP3, 1);
2001 emit_bgt(cd, iptr->dst.block);
2004 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
2005 /* op1 = target JavaVM pc */
2007 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
2008 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
2009 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
2011 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
2012 M_MOVGT_IMM(2, REG_ITMP3);
2013 M_MOVEQ_IMM(1, REG_ITMP3);
2015 /* low compare: x=x-1(ifLO) */
2016 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
2017 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
2019 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2021 /* branch if (x GE 1) */
2022 M_CMP_IMM(REG_ITMP3, 1);
2023 emit_bge(cd, iptr->dst.block);
2026 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2029 branch_target_t *table;
2031 table = iptr->dst.table;
2033 l = iptr->sx.s23.s2.tablelow;
2034 i = iptr->sx.s23.s3.tablehigh;
2036 /* calculate new index (index - low) */
2037 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2039 M_INTMOVE(s1, REG_ITMP1);
2040 } else if (IS_IMM(l)) {
2041 M_SUB_IMM(REG_ITMP1, s1, l);
2043 ICONST(REG_ITMP2, l);
2044 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2047 /* range check (index <= high-low) */
2049 M_COMPARE(REG_ITMP1, i-1);
2050 emit_bugt(cd, table[0].block);
2052 /* build jump table top down and use address of lowest entry */
2057 dseg_add_target(cd, table->block);
2062 /* length of dataseg after last dseg_add_target is used by load */
2063 /* TODO: this loads from data-segment */
2064 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2065 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2068 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2071 lookup_target_t *lookup;
2073 lookup = iptr->dst.lookup;
2075 i = iptr->sx.s23.s2.lookupcount;
2078 MCODECHECK((i<<2)+8);
2079 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2082 M_COMPARE(s1, lookup->value);
2083 emit_beq(cd, lookup->target.block);
2087 /* default branch */
2088 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2092 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2094 #if !defined(ENABLE_SOFTFLOAT)
2095 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2096 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2097 goto ICMD_RETURN_do;
2100 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2102 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2103 M_INTMOVE(s1, REG_RESULT);
2104 goto ICMD_RETURN_do;
2106 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2108 #if !defined(ENABLE_SOFTFLOAT)
2109 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2110 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2111 goto ICMD_RETURN_do;
2114 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2116 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2117 M_LNGMOVE(s1, REG_RESULT_PACKED);
2118 goto ICMD_RETURN_do;
2120 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2122 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2123 M_INTMOVE(s1, REG_RESULT);
2124 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2125 codegen_addpatchref(cd, PATCHER_athrow_areturn,
2126 iptr->sx.s23.s2.uc, 0);
2128 if (opt_showdisassemble)
2131 goto ICMD_RETURN_do;
2133 case ICMD_RETURN: /* ... ==> ... */
2136 #if !defined(NDEBUG)
2137 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2138 emit_verbosecall_exit(jd);
2141 #if defined(ENABLE_THREADS)
2142 /* call monitorexit function */
2144 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2145 /* stack offset for monitor argument */
2149 /* we need to save the proper return value */
2151 switch (iptr->opc) {
2155 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2157 M_STMFD(BITMASK_RESULT, REG_SP);
2162 M_LDR(REG_A0, REG_SP, s1 * 4);
2163 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2164 M_DSEG_BRANCH(disp);
2166 /* we no longer need PV here, no more loading */
2167 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2168 M_RECOMPUTE_PV(s1);*/
2170 switch (iptr->opc) {
2174 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2176 M_LDMFD(BITMASK_RESULT, REG_SP);
2182 /* deallocate stackframe for spilled variables */
2184 if ((cd->stackframesize - savedregs_num) > 0)
2185 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
2187 /* restore callee saved registers + do return */
2189 if (savedregs_bitmask) {
2190 if (!jd->isleafmethod) {
2191 savedregs_bitmask &= ~(1<<REG_LR);
2192 savedregs_bitmask |= (1<<REG_PC);
2194 M_LDMFD(savedregs_bitmask, REG_SP);
2197 /* if LR was not on stack, we need to return manually */
2199 if (jd->isleafmethod)
2200 M_MOV(REG_PC, REG_LR);
2203 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2205 bte = iptr->sx.s23.s3.bte;
2207 goto ICMD_INVOKE_do;
2209 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2210 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2211 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2212 case ICMD_INVOKEINTERFACE:
2214 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2216 um = iptr->sx.s23.s3.um;
2217 md = um->methodref->parseddesc.md;
2220 lm = iptr->sx.s23.s3.fmiref->p.method;
2222 md = lm->parseddesc;
2226 /* copy arguments to registers or stack location */
2228 s3 = md->paramcount;
2230 MCODECHECK((s3 << 1) + 64);
2232 for (s3 = s3 - 1; s3 >= 0; s3--) {
2233 var = VAR(iptr->sx.s23.s2.args[s3]);
2234 d = md->params[s3].regoff;
2236 if (var->flags & PREALLOC) /* argument was precolored? */
2239 /* TODO: document me */
2240 #if !defined(ENABLE_SOFTFLOAT)
2241 if (IS_INT_LNG_TYPE(var->type)) {
2242 #endif /* !defined(ENABLE_SOFTFLOAT) */
2243 if (!md->params[s3].inmemory) {
2244 SPLIT_OPEN(var->type, s1, REG_ITMP2);
2245 s1 = emit_load(jd, iptr, var, d);
2247 if (IS_2_WORD_TYPE(var->type))
2252 SPLIT_STORE_AND_CLOSE(var->type, d, 0);
2255 if (IS_2_WORD_TYPE(var->type)) {
2256 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2257 M_LST(s1, REG_SP, d * 4);
2260 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2261 M_IST(s1, REG_SP, d * 4);
2264 #if !defined(ENABLE_SOFTFLOAT)
2267 if (!md->params[s3].inmemory) {
2268 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2269 SPLIT_OPEN(var->type, d, REG_ITMP1);
2270 M_CAST_FLT_TO_INT_TYPED(var->type, s1, d);
2271 SPLIT_STORE_AND_CLOSE(var->type, d, 0);
2274 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2275 if (IS_2_WORD_TYPE(var->type))
2276 M_DST(s1, REG_SP, d * 4);
2278 M_FST(s1, REG_SP, d * 4);
2281 #endif /* !defined(ENABLE_SOFTFLOAT) */
2284 switch (iptr->opc) {
2286 disp = dseg_add_functionptr(cd, bte->fp);
2288 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2290 /* generate the actual call */
2292 M_MOV(REG_LR, REG_PC);
2293 M_MOV(REG_PC, REG_PV);
2294 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2297 emit_exception_check(cd, iptr);
2300 case ICMD_INVOKESPECIAL:
2301 emit_nullpointer_check(cd, iptr, REG_A0);
2304 case ICMD_INVOKESTATIC:
2306 disp = dseg_add_unique_address(cd, NULL);
2308 codegen_addpatchref(cd, PATCHER_invokestatic_special,
2311 if (opt_showdisassemble)
2315 disp = dseg_add_address(cd, lm->stubroutine);
2317 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2319 /* generate the actual call */
2321 M_MOV(REG_LR, REG_PC);
2322 M_MOV(REG_PC, REG_PV);
2323 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2327 case ICMD_INVOKEVIRTUAL:
2329 codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
2331 if (opt_showdisassemble)
2337 s1 = OFFSET(vftbl_t, table[0]) +
2338 sizeof(methodptr) * lm->vftblindex;
2340 /* implicit null-pointer check */
2341 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2342 OFFSET(java_objectheader, vftbl));
2343 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2345 /* generate the actual call */
2347 M_MOV(REG_LR, REG_PC);
2348 M_MOV(REG_PC, REG_PV);
2349 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2353 case ICMD_INVOKEINTERFACE:
2355 codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
2357 if (opt_showdisassemble)
2364 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2365 sizeof(methodptr*) * lm->class->index;
2366 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2369 /* implicit null-pointer check */
2370 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2371 OFFSET(java_objectheader, vftbl));
2372 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2373 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2375 /* generate the actual call */
2377 M_MOV(REG_LR, REG_PC);
2378 M_MOV(REG_PC, REG_PV);
2379 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2384 /* store return value */
2386 d = md->returntype.type;
2388 #if !defined(__SOFTFP__)
2389 /* TODO: this is only a hack, since we use R0/R1 for float
2390 return! this depends on gcc; it is independent from
2391 our ENABLE_SOFTFLOAT define */
2392 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2393 #if 0 && !defined(NDEBUG)
2394 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2396 /* we cannot use this macro, since it is not defined
2397 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2398 REG_FRESULT, REG_RESULT_TYPED(d)); */
2399 if (IS_2_WORD_TYPE(d)) {
2400 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2401 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2403 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2404 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2409 if (d != TYPE_VOID) {
2410 #if !defined(ENABLE_SOFTFLOAT)
2411 if (IS_INT_LNG_TYPE(d)) {
2412 #endif /* !defined(ENABLE_SOFTFLOAT) */
2413 if (IS_2_WORD_TYPE(d)) {
2414 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2415 M_LNGMOVE(REG_RESULT_PACKED, s1);
2418 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2419 M_INTMOVE(REG_RESULT, s1);
2422 #if !defined(ENABLE_SOFTFLOAT)
2424 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2425 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2427 #endif /* !defined(ENABLE_SOFTFLOAT) */
2429 emit_store_dst(jd, iptr, s1);
2433 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2434 /* val.a: (classinfo*) superclass */
2436 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2437 /* object type cast-check */
2442 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2447 super = iptr->sx.s23.s3.c.cls;
2448 superindex = super->index;
2451 #if defined(ENABLE_THREADS)
2452 codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2454 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2456 /* if class is not resolved, check which code to call */
2458 if (super == NULL) {
2460 emit_label_beq(cd, BRANCH_LABEL_1);
2462 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2463 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2464 iptr->sx.s23.s3.c.ref, disp);
2466 if (opt_showdisassemble)
2469 M_DSEG_LOAD(REG_ITMP2, disp);
2470 disp = dseg_add_s4(cd, ACC_INTERFACE);
2471 M_DSEG_LOAD(REG_ITMP3, disp);
2472 M_TST(REG_ITMP2, REG_ITMP3);
2473 emit_label_beq(cd, BRANCH_LABEL_2);
2476 /* interface checkcast code */
2478 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2479 if (super == NULL) {
2480 codegen_addpatchref(cd,
2481 PATCHER_checkcast_instanceof_interface,
2482 iptr->sx.s23.s3.c.ref, 0);
2484 if (opt_showdisassemble)
2489 emit_label_beq(cd, BRANCH_LABEL_3);
2492 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2493 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2494 assert(IS_IMM(superindex));
2495 M_CMP_IMM(REG_ITMP3, superindex);
2496 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2498 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2499 superindex * sizeof(methodptr*);
2501 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2502 M_TST(REG_ITMP3, REG_ITMP3);
2503 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2506 emit_label_br(cd, BRANCH_LABEL_4);
2508 emit_label(cd, BRANCH_LABEL_3);
2511 /* class checkcast code */
2513 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2514 if (super == NULL) {
2515 emit_label(cd, BRANCH_LABEL_2);
2517 disp = dseg_add_unique_address(cd, NULL);
2519 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2520 iptr->sx.s23.s3.c.ref,
2523 if (opt_showdisassemble)
2527 disp = dseg_add_address(cd, super->vftbl);
2530 emit_label_beq(cd, BRANCH_LABEL_5);
2533 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2534 M_DSEG_LOAD(REG_ITMP3, disp);
2535 #if defined(ENABLE_THREADS)
2536 codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
2538 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2539 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2540 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2541 M_DSEG_LOAD(REG_ITMP3, disp);
2542 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2543 #if defined(ENABLE_THREADS)
2544 codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
2546 M_CMP(REG_ITMP2, REG_ITMP3);
2547 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2550 emit_label(cd, BRANCH_LABEL_5);
2553 if (super == NULL) {
2554 emit_label(cd, BRANCH_LABEL_1);
2555 emit_label(cd, BRANCH_LABEL_4);
2558 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2561 /* array type cast-check */
2563 s1 = emit_load_s1(jd, iptr, REG_A0);
2564 M_INTMOVE(s1, REG_A0);
2566 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2567 disp = dseg_add_unique_address(cd, NULL);
2569 codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
2570 iptr->sx.s23.s3.c.ref,
2573 if (opt_showdisassemble)
2577 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2579 M_DSEG_LOAD(REG_A1, disp);
2580 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2581 M_DSEG_BRANCH(disp);
2584 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2585 M_RECOMPUTE_PV(disp);
2587 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2588 M_TST(REG_RESULT, REG_RESULT);
2589 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2591 d = codegen_reg_of_dst(jd, iptr, s1);
2595 emit_store_dst(jd, iptr, d);
2598 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2599 /* val.a: (classinfo*) superclass */
2604 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2609 super = iptr->sx.s23.s3.c.cls;
2610 superindex = super->index;
2613 #if defined(ENABLE_THREADS)
2614 codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2616 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2617 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2619 M_MOV(REG_ITMP1, s1);
2623 /* if class is not resolved, check which code to call */
2625 if (super == NULL) {
2629 emit_label_beq(cd, BRANCH_LABEL_1);
2631 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2632 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2633 iptr->sx.s23.s3.c.ref, disp);
2635 if (opt_showdisassemble)
2638 M_DSEG_LOAD(REG_ITMP2, disp);
2639 disp = dseg_add_s4(cd, ACC_INTERFACE);
2640 M_DSEG_LOAD(REG_ITMP3, disp);
2641 M_TST(REG_ITMP2, REG_ITMP3);
2642 emit_label_beq(cd, BRANCH_LABEL_2);
2645 /* interface checkcast code */
2647 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2648 if (super == NULL) {
2649 /* If d == REG_ITMP2, then it's destroyed in check
2654 codegen_addpatchref(cd,
2655 PATCHER_checkcast_instanceof_interface,
2656 iptr->sx.s23.s3.c.ref, 0);
2658 if (opt_showdisassemble)
2664 emit_label_beq(cd, BRANCH_LABEL_3);
2667 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2668 M_LDR_INTERN(REG_ITMP3,
2669 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2670 assert(IS_IMM(superindex));
2671 M_CMP_IMM(REG_ITMP3, superindex);
2674 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2675 superindex * sizeof(methodptr*);
2677 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2678 M_TST(REG_ITMP3, REG_ITMP3);
2682 emit_label_br(cd, BRANCH_LABEL_4);
2684 emit_label(cd, BRANCH_LABEL_3);
2687 /* class checkcast code */
2689 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2690 if (super == NULL) {
2691 emit_label(cd, BRANCH_LABEL_2);
2693 disp = dseg_add_unique_address(cd, NULL);
2695 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2696 iptr->sx.s23.s3.c.ref,
2699 if (opt_showdisassemble)
2703 disp = dseg_add_address(cd, super->vftbl);
2707 emit_label_beq(cd, BRANCH_LABEL_5);
2710 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2711 M_DSEG_LOAD(REG_ITMP2, disp);
2712 #if defined(ENABLE_THREADS)
2713 codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
2715 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2716 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2717 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2718 #if defined(ENABLE_THREADS)
2719 codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
2721 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2722 M_CMP(REG_ITMP1, REG_ITMP2);
2723 /* If d == REG_ITMP2, then it's destroyed */
2729 emit_label(cd, BRANCH_LABEL_5);
2732 if (super == NULL) {
2733 emit_label(cd, BRANCH_LABEL_1);
2734 emit_label(cd, BRANCH_LABEL_4);
2739 emit_store_dst(jd, iptr, d);
2742 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2744 /* copy sizes to stack if necessary */
2746 MCODECHECK((iptr->s1.argcount << 1) + 64);
2748 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2750 var = VAR(iptr->sx.s23.s2.args[s1]);
2752 /* copy SAVEDVAR sizes to stack */
2754 if (!(var->flags & PREALLOC)) {
2755 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2756 M_STR(s2, REG_SP, s1 * 4);
2760 /* a0 = dimension count */
2762 assert(IS_IMM(iptr->s1.argcount));
2763 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2765 /* is patcher function set? */
2767 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2768 disp = dseg_add_unique_address(cd, NULL);
2770 codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
2771 iptr->sx.s23.s3.c.ref, disp);
2773 if (opt_showdisassemble)
2777 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2779 /* a1 = arraydescriptor */
2781 M_DSEG_LOAD(REG_A1, disp);
2783 /* a2 = pointer to dimensions = stack pointer */
2785 M_INTMOVE(REG_SP, REG_A2);
2787 /* call builtin_multianewarray here */
2789 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2790 M_DSEG_BRANCH(disp);
2794 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2797 /* check for exception before result assignment */
2799 emit_exception_check(cd, iptr);
2803 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2804 M_INTMOVE(REG_RESULT, d);
2805 emit_store_dst(jd, iptr, d);
2808 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2810 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2811 emit_nullpointer_check(cd, iptr, s1);
2815 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2818 } /* the big switch */
2820 } /* for all instructions */
2822 } /* for all basic blocks */
2824 dseg_createlinenumbertable(cd);
2827 /* generate stubs */
2829 emit_patcher_stubs(jd);
2831 /* everything's ok */
2837 /* codegen_emit_stub_compiler **************************************************
2839 Emits a stub routine which calls the compiler.
2841 *******************************************************************************/
2843 void codegen_emit_stub_compiler(jitdata *jd)
2848 /* get required compiler data */
2853 /* code for the stub */
2855 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2856 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2860 /* codegen_emit_stub_native ****************************************************
2862 Emits a stub routine which calls a native method.
2864 *******************************************************************************/
2866 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
2875 s4 disp, funcdisp, s1, s2;
2877 /* get required compiler data */
2883 /* initialize variables */
2886 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2888 /* calculate stackframe size */
2890 cd->stackframesize =
2891 1 + /* return address */
2892 sizeof(stackframeinfo) / SIZEOF_VOID_P + /* stackframeinfo */
2893 sizeof(localref_table) / SIZEOF_VOID_P + /* localref_table */
2894 nmd->memuse; /* stack arguments */
2896 /* align stack to 8-byte */
2898 cd->stackframesize = (cd->stackframesize + 1) & ~1;
2900 /* create method header */
2902 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2903 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
2904 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2905 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2906 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2907 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2908 (void) dseg_addlinenumbertablesize(cd);
2909 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2911 /* generate stub code */
2913 M_STMFD(1<<REG_LR, REG_SP);
2914 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
2916 #if !defined(NDEBUG)
2917 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2918 emit_verbosecall_enter(jd);
2921 /* get function address (this must happen before the stackframeinfo) */
2923 funcdisp = dseg_add_functionptr(cd, f);
2925 #if !defined(WITH_STATIC_CLASSPATH)
2927 codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
2929 if (opt_showdisassemble)
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 assert(IS_IMM(4*4 + cd->stackframesize * 4));
2943 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2944 M_MOV(REG_A1, REG_PV);
2945 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize * 4);
2946 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2947 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2948 M_DSEG_BRANCH(disp);
2952 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2955 /* Restore integer and float argument registers (these are 4
2956 registers, stack is 8-byte aligned). */
2958 M_LDMFD(BITMASK_ARGS, REG_SP);
2959 /* TODO: floating point */
2961 /* copy or spill arguments to new locations */
2962 /* ATTENTION: the ARM has only integer argument registers! */
2964 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
2965 t = md->paramtypes[i].type;
2967 if (!md->params[i].inmemory) {
2968 s1 = md->params[i].regoff;
2969 s2 = nmd->params[j].regoff;
2971 if (!nmd->params[j].inmemory) {
2972 #if !defined(__ARM_EABI__)
2973 SPLIT_OPEN(t, s1, REG_ITMP1);
2974 SPLIT_LOAD(t, s1, cd->stackframesize);
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 !defined(__ARM_EABI__)
2989 SPLIT_OPEN(t, s1, REG_ITMP1);
2990 SPLIT_LOAD(t, s1, cd->stackframesize);
2993 if (IS_2_WORD_TYPE(t))
2994 M_LST(s1, REG_SP, s2 * 4);
2996 M_IST(s1, REG_SP, s2 * 4);
2997 /* no SPLIT_CLOSE here because argument is fully on stack now */
3001 s1 = md->params[i].regoff + cd->stackframesize;
3002 s2 = nmd->params[j].regoff;
3004 if (IS_2_WORD_TYPE(t)) {
3005 M_LLD(REG_ITMP12_PACKED, REG_SP, s1 * 4);
3006 M_LST(REG_ITMP12_PACKED, REG_SP, s2 * 4);
3009 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
3010 M_IST(REG_ITMP1, REG_SP, s2 * 4);
3015 /* put class into second argument register */
3017 if (m->flags & ACC_STATIC) {
3018 disp = dseg_add_address(cd, m->class);
3019 M_DSEG_LOAD(REG_A1, disp);
3022 /* put env into first argument register */
3024 disp = dseg_add_address(cd, _Jv_env);
3025 M_DSEG_LOAD(REG_A0, disp);
3027 /* do the native function call */
3029 M_DSEG_BRANCH(funcdisp);
3032 /* TODO: this is only needed because of the tracer ... do we
3035 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3038 #if !defined(__SOFTFP__)
3039 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3040 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3041 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3042 #if 0 && !defined(NDEBUG)
3043 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3045 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3046 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3047 if (IS_2_WORD_TYPE(md->returntype.type)) {
3048 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3049 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3051 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3052 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3057 #if !defined(NDEBUG)
3058 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3059 emit_verbosecall_exit(jd);
3062 /* remove native stackframe info */
3063 /* TODO: improve this store/load */
3065 M_STMFD(BITMASK_RESULT, REG_SP);
3067 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
3068 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3069 M_DSEG_BRANCH(disp);
3070 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3073 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3074 M_LDMFD(BITMASK_RESULT, REG_SP);
3076 /* finish stub code, but do not yet return to caller */
3078 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
3079 M_LDMFD(1<<REG_LR, REG_SP);
3081 /* check for exception */
3083 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3084 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3086 /* handle exception here */
3088 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3090 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3091 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3092 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3094 /* generate patcher stubs */
3096 emit_patcher_stubs(jd);
3100 /* asm_debug *******************************************************************
3104 *******************************************************************************/
3106 void asm_debug(int a1, int a2, int a3, int a4)
3108 printf("===> i am going to exit after this debugging message!\n");
3109 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3110 vm_abort("leave you now");
3115 * These are local overrides for various environment variables in Emacs.
3116 * Please do not remove this and leave it at the end of the file, where
3117 * Emacs will automagically detect them.
3118 * ---------------------------------------------------------------------
3121 * indent-tabs-mode: t
3125 * vim:noexpandtab:sw=4:ts=4: