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 7591 2007-03-28 19:07:32Z twisti $
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 s2 = ARGUMENT_REGS(t, s1); /* get argument register */
223 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
224 if (GET_LOW_REG(var->vv.regoff) == REG_SPLIT || GET_HIGH_REG(var->vv.regoff) == REG_SPLIT) {
225 /* TODO: remove this!!! */
226 dolog("SPLIT in local var: %x>%x (%s.%s)", s2, var->vv.regoff, m->class->name->text, m->name->text);
227 assert(s2 == var->vv.regoff);
230 SPLIT_OPEN(t, s2, REG_ITMP1);
231 SPLIT_LOAD(t, s2, cd->stackframesize);
232 SPLIT_OPEN(t, s3, REG_ITMP1);
234 if (IS_2_WORD_TYPE(t))
239 SPLIT_STORE_AND_CLOSE(t, s3, cd->stackframesize);
241 else { /* reg arg -> spilled */
242 SPLIT_OPEN(t, s2, REG_ITMP1);
243 SPLIT_LOAD(t, s2, cd->stackframesize);
245 if (IS_2_WORD_TYPE(t))
246 M_LST(s2, REG_SP, var->vv.regoff * 4);
248 M_IST(s2, REG_SP, var->vv.regoff * 4);
249 /* no SPLIT_CLOSE here because arg is fully spilled now */
252 else { /* stack arguments */
253 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
254 if (IS_2_WORD_TYPE(t))
255 M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
257 M_ILD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
259 else { /* stack arg -> spilled */
260 /* Reuse Memory Position on Caller Stack */
261 var->vv.regoff = cd->stackframesize + s1;
264 #if !defined(ENABLE_SOFTFLOAT)
265 } else { /* floating args */
266 if (!md->params[i].inmemory) { /* register arguments */
267 s2 = ARGUMENT_REGS(t, s1); /* get argument register */
268 if (!(var->flags & INMEMORY)) { /* reg arg -> register */
269 SPLIT_OPEN(t, s2, REG_ITMP1);
270 SPLIT_LOAD(t, s2, cd->stackframesize);
271 M_CAST_INT_TO_FLT_TYPED(t, s2, var->vv.regoff);
273 else { /* reg arg -> spilled */
274 SPLIT_OPEN(t, s2, REG_ITMP1);
275 SPLIT_LOAD(t, s2, cd->stackframesize);
277 if (IS_2_WORD_TYPE(t))
278 M_LST(s2, REG_SP, var->vv.regoff * 4);
280 M_IST(s2, REG_SP, var->vv.regoff * 4);
281 /* no SPLIT_CLOSE here because arg is fully spilled now */
284 else { /* stack arguments */
285 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
286 if (IS_2_WORD_TYPE(t))
287 M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
289 M_FLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 4);
291 else { /* stack arg -> spilled */
292 /* Reuse Memory Position on Caller Stack */
293 var->vv.regoff = cd->stackframesize + s1;
297 #endif /* !defined(ENABLE_SOFTFLOAT) */
300 #if defined(ENABLE_THREADS)
301 /* call monitorenter function */
303 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
304 /* stack offset for monitor argument */
308 # if !defined(NDEBUG)
309 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
310 M_STMFD(BITMASK_ARGS, REG_SP);
315 /* get the correct lock object */
317 if (m->flags & ACC_STATIC) {
318 disp = dseg_add_address(cd, &m->class->object.header);
319 M_DSEG_LOAD(REG_A0, disp);
322 emit_nullpointer_check_force(cd, iptr, REG_A0);
325 M_STR(REG_A0, REG_SP, s1 * 4);
326 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
328 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
331 # if !defined(NDEBUG)
332 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
333 M_LDMFD(BITMASK_ARGS, REG_SP);
339 /* call trace function */
341 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
342 emit_verbosecall_enter(jd);
345 /* end of header generation */
347 /* SECTION: ICMD Code Generation */
348 /* for all basic blocks */
350 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
352 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
354 /* is this basic block reached? */
356 if (bptr->flags < BBREACHED)
359 /* branch resolving */
361 codegen_resolve_branchrefs(cd, bptr);
363 /* copy interface registers to their destination */
369 #if defined(ENABLE_LSRA)
373 var = VAR(bptr->invars[len]);
374 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
375 if (!(var->flags & INMEMORY))
379 M_INTMOVE(REG_ITMP1, d);
380 emit_store(jd, NULL, var, d);
387 var = VAR(bptr->invars[len]);
389 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
390 d = codegen_reg_of_var(0, var, REG_ITMP1);
391 M_INTMOVE(REG_ITMP1, d);
392 emit_store(jd, NULL, var, d);
395 assert((var->flags & INOUT));
398 #if defined(ENABLE_LSRA)
402 /* for all instructions */
405 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
407 /* add line number */
408 if (iptr->line != currentline) {
409 dseg_addlinenumber(cd, iptr->line);
410 currentline = iptr->line;
413 MCODECHECK(64); /* an instruction usually needs < 64 words */
417 case ICMD_NOP: /* ... ==> ... */
420 /* constant operations ************************************************/
422 case ICMD_ICONST: /* ... ==> ..., constant */
424 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
425 ICONST(d, iptr->sx.val.i);
426 emit_store_dst(jd, iptr, d);
429 case ICMD_ACONST: /* ... ==> ..., constant */
431 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
432 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
433 disp = dseg_add_unique_address(cd, NULL);
435 codegen_addpatchref(cd, PATCHER_aconst,
439 if (opt_showdisassemble)
442 M_DSEG_LOAD(d, disp);
445 ICONST(d, (u4) iptr->sx.val.anyptr);
447 emit_store_dst(jd, iptr, d);
450 case ICMD_LCONST: /* ... ==> ..., constant */
452 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
453 LCONST(d, iptr->sx.val.l);
454 emit_store_dst(jd, iptr, d);
457 case ICMD_FCONST: /* ... ==> ..., constant */
459 #if defined(ENABLE_SOFTFLOAT)
460 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
461 ICONST(d, iptr->sx.val.i);
462 emit_store_dst(jd, iptr, d);
464 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
465 FCONST(d, iptr->sx.val.f);
466 emit_store_dst(jd, iptr, d);
470 case ICMD_DCONST: /* ... ==> ..., constant */
472 #if defined(ENABLE_SOFTFLOAT)
473 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
474 LCONST(d, iptr->sx.val.l);
475 emit_store_dst(jd, iptr, d);
477 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
478 DCONST(d, iptr->sx.val.d);
479 emit_store_dst(jd, iptr, d);
484 /* load/store/copy/move operations ************************************/
486 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
487 case ICMD_ALOAD: /* op1 = local variable */
491 case ICMD_ISTORE: /* ..., value ==> ... */
498 emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
502 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
503 emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
506 /* pop operations *****************************************************/
508 /* attention: double and longs are only one entry in CACAO ICMDs */
510 case ICMD_POP: /* ..., value ==> ... */
511 case ICMD_POP2: /* ..., value, value ==> ... */
516 /* integer operations *************************************************/
518 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
520 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
521 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
522 M_MOV(d, REG_LSL(s1, 24));
523 M_MOV(d, REG_ASR(d, 24));
524 emit_store_dst(jd, iptr, d);
527 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
529 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
530 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
531 M_MOV(d, REG_LSL(s1, 16));
532 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
533 emit_store_dst(jd, iptr, d);
536 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
538 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
539 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
540 M_MOV(d, REG_LSL(s1, 16));
541 M_MOV(d, REG_ASR(d, 16));
542 emit_store_dst(jd, iptr, d);
545 case ICMD_I2L: /* ..., value ==> ..., value */
547 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
548 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
549 M_INTMOVE(s1, GET_LOW_REG(d));
550 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
551 emit_store_dst(jd, iptr, d);
554 case ICMD_L2I: /* ..., value ==> ..., value */
556 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
557 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
559 emit_store_dst(jd, iptr, d);
562 case ICMD_INEG: /* ..., value ==> ..., - value */
564 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
565 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
567 emit_store_dst(jd, iptr, d);
570 case ICMD_LNEG: /* ..., value ==> ..., - value */
572 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
573 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
574 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
575 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
576 emit_store_dst(jd, iptr, d);
579 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
581 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
582 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
583 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
585 emit_store_dst(jd, iptr, d);
588 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
590 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
591 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
592 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
593 M_ADD_S(GET_LOW_REG(d), s1, s2);
594 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
595 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
596 M_ADC(GET_HIGH_REG(d), s1, s2);
597 emit_store_dst(jd, iptr, d);
603 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
604 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
606 if (IS_IMM(iptr->sx.val.i)) {
607 M_ADD_IMM(d, s1, iptr->sx.val.i);
608 } else if (IS_IMM(-iptr->sx.val.i)) {
609 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
611 ICONST(REG_ITMP3, iptr->sx.val.i);
612 M_ADD(d, s1, REG_ITMP3);
615 emit_store_dst(jd, iptr, d);
618 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
619 /* sx.val.l = constant */
621 s3 = iptr->sx.val.l & 0xffffffff;
622 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
623 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
625 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
627 ICONST(REG_ITMP3, s3);
628 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
630 s3 = iptr->sx.val.l >> 32;
631 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
633 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
635 ICONST(REG_ITMP3, s3);
636 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
638 emit_store_dst(jd, iptr, d);
641 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
643 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
644 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
645 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
647 emit_store_dst(jd, iptr, d);
650 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
652 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
653 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
654 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
655 M_SUB_S(GET_LOW_REG(d), s1, s2);
656 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
657 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
658 M_SBC(GET_HIGH_REG(d), s1, s2);
659 emit_store_dst(jd, iptr, d);
662 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
663 /* sx.val.i = constant */
665 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
666 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
667 if (IS_IMM(iptr->sx.val.i))
668 M_SUB_IMM(d, s1, iptr->sx.val.i);
670 ICONST(REG_ITMP3, iptr->sx.val.i);
671 M_SUB(d, s1, REG_ITMP3);
673 emit_store_dst(jd, iptr, d);
676 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
677 /* sx.val.l = constant */
679 s3 = iptr->sx.val.l & 0xffffffff;
680 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
681 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
683 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
685 ICONST(REG_ITMP3, s3);
686 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
688 s3 = iptr->sx.val.l >> 32;
689 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
691 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
693 ICONST(REG_ITMP3, s3);
694 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
696 emit_store_dst(jd, iptr, d);
699 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
701 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
702 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
703 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
705 emit_store_dst(jd, iptr, d);
708 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
709 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
711 s1 = emit_load_s1(jd, iptr, REG_A0);
712 s2 = emit_load_s2(jd, iptr, REG_A1);
713 emit_arithmetic_check(cd, iptr, s2);
715 /* move arguments into argument registers */
716 M_INTMOVE(s1, REG_A0);
717 M_INTMOVE(s2, REG_A1);
719 /* call builtin function */
720 bte = iptr->sx.s23.s3.bte;
721 disp = dseg_add_functionptr(cd, bte->fp);
725 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
728 /* move result into destination register */
729 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
730 M_INTMOVE(REG_RESULT, d);
731 emit_store_dst(jd, iptr, d);
734 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
735 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
737 /* move arguments into argument registers */
739 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
740 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
741 /* XXX TODO: only do this if arithmetic check is really done! */
742 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
743 emit_arithmetic_check(cd, iptr, REG_ITMP3);
745 M_LNGMOVE(s1, REG_A0_A1_PACKED);
746 M_LNGMOVE(s2, REG_A2_A3_PACKED);
748 /* call builtin function */
749 bte = iptr->sx.s23.s3.bte;
750 disp = dseg_add_functionptr(cd, bte->fp);
754 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
757 /* move result into destination register */
758 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
759 M_LNGMOVE(REG_RESULT_PACKED, d);
760 emit_store_dst(jd, iptr, d);
763 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
764 /* sx.val.i = constant */
766 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
767 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
768 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
769 emit_store_dst(jd, iptr, d);
772 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
773 /* sx.val.i = constant */
775 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
776 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
777 /* this rounds towards 0 as java likes it */
778 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
779 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
780 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
781 /* this rounds towards nearest, not java style */
782 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
783 M_ADCMI_IMM(d, d, 0);*/
784 emit_store_dst(jd, iptr, d);
787 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
788 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
790 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
791 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
792 M_MOV_S(REG_ITMP1, s1);
793 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
794 if (IS_IMM(iptr->sx.val.i))
795 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
797 ICONST(REG_ITMP3, iptr->sx.val.i);
798 M_AND(REG_ITMP1, REG_ITMP3, d);
800 M_RSBMI_IMM(d, d, 0);
801 emit_store_dst(jd, iptr, d);
804 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
806 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
807 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
808 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
809 M_AND_IMM(s2, 0x1f, REG_ITMP2);
810 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
811 emit_store_dst(jd, iptr, d);
814 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
816 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
817 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
818 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
819 M_AND_IMM(s2, 0x1f, REG_ITMP2);
820 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
821 emit_store_dst(jd, iptr, d);
824 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
826 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
827 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
828 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
829 M_AND_IMM(s2, 0x1f, REG_ITMP2);
830 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
831 emit_store_dst(jd, iptr, d);
834 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
835 /* sx.val.i = constant */
837 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
838 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
839 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
840 emit_store_dst(jd, iptr, d);
843 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
844 /* sx.val.i = constant */
846 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
847 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
848 /* we need to check for zero here because arm interprets it as SHR by 32 */
849 if ((iptr->sx.val.i & 0x1f) == 0) {
852 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
854 emit_store_dst(jd, iptr, d);
857 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
858 /* sx.val.i = constant */
860 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
861 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
862 /* we need to check for zero here because arm interprets it as SHR by 32 */
863 if ((iptr->sx.val.i & 0x1f) == 0)
866 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
867 emit_store_dst(jd, iptr, d);
870 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
872 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
873 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
874 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
876 emit_store_dst(jd, iptr, d);
879 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
881 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
882 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
883 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
884 M_AND(s1, s2, GET_LOW_REG(d));
885 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
886 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
887 M_AND(s1, s2, GET_HIGH_REG(d));
888 emit_store_dst(jd, iptr, d);
891 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
893 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
894 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
895 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
897 emit_store_dst(jd, iptr, d);
900 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
902 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
903 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
904 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
905 M_ORR(s1, s2, GET_LOW_REG(d));
906 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
907 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
908 M_ORR(s1, s2, GET_HIGH_REG(d));
909 emit_store_dst(jd, iptr, d);
912 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
914 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
915 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
916 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
918 emit_store_dst(jd, iptr, d);
921 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
923 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
924 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
925 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
926 M_EOR(s1, s2, GET_LOW_REG(d));
927 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
928 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
929 M_EOR(s1, s2, GET_HIGH_REG(d));
930 emit_store_dst(jd, iptr, d);
934 /* floating operations ************************************************/
936 #if !defined(ENABLE_SOFTFLOAT)
938 case ICMD_FNEG: /* ..., value ==> ..., - value */
940 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
941 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
943 emit_store_dst(jd, iptr, d);
946 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
948 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
949 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
950 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
952 emit_store_dst(jd, iptr, d);
955 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
957 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
958 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
959 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
961 emit_store_dst(jd, iptr, d);
964 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
966 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
967 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
968 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
970 emit_store_dst(jd, iptr, d);
973 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
974 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
975 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
976 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
978 emit_store_dst(jd, iptr, d);
981 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
984 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
986 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
987 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
988 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
990 emit_store_dst(jd, iptr, d);
993 case ICMD_DNEG: /* ..., value ==> ..., - value */
995 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
996 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
998 emit_store_dst(jd, iptr, d);
1001 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
1003 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1004 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1005 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1007 emit_store_dst(jd, iptr, d);
1010 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
1012 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1013 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1014 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1016 emit_store_dst(jd, iptr, d);
1019 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1021 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1022 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1023 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1025 emit_store_dst(jd, iptr, d);
1028 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1030 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1031 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1032 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1034 emit_store_dst(jd, iptr, d);
1037 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1040 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1042 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1043 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1044 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1046 emit_store_dst(jd, iptr, d);
1049 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1051 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1052 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1054 emit_store_dst(jd, iptr, d);
1057 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1059 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1060 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1062 emit_store_dst(jd, iptr, d);
1065 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1067 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1068 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1069 /* this uses round towards zero, as Java likes it */
1071 /* this checks for NaN; to return zero as Java likes it */
1074 emit_store_dst(jd, iptr, d);
1077 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1079 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1080 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1081 /* this uses round towards zero, as Java likes it */
1083 /* this checks for NaN; to return zero as Java likes it */
1086 emit_store_dst(jd, iptr, d);
1089 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1091 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1092 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1094 emit_store_dst(jd, iptr, d);
1097 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1099 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1100 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1102 emit_store_dst(jd, iptr, d);
1105 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg 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_SUBGT_IMM(d, d, 1);
1113 M_ADDLT_IMM(d, d, 1);
1114 emit_store_dst(jd, iptr, d);
1117 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg 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_SUBGT_IMM(d, d, 1);
1125 M_ADDLT_IMM(d, d, 1);
1126 emit_store_dst(jd, iptr, d);
1129 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1131 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1132 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1133 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1136 M_SUBLT_IMM(d, d, 1);
1137 M_ADDGT_IMM(d, d, 1);
1138 emit_store_dst(jd, iptr, d);
1141 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1143 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1144 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1145 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1148 M_SUBLT_IMM(d, d, 1);
1149 M_ADDGT_IMM(d, d, 1);
1150 emit_store_dst(jd, iptr, d);
1153 #endif /* !defined(ENABLE_SOFTFLOAT) */
1156 /* memory operations **************************************************/
1158 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1160 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1161 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1162 /* implicit null-pointer check */
1163 M_ILD_INTERN(d, s1, OFFSET(java_arrayheader, size));
1164 emit_store_dst(jd, iptr, d);
1167 case ICMD_BALOAD: /* ..., 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, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1175 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1176 emit_store_dst(jd, iptr, d);
1179 case ICMD_CALOAD: /* ..., 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, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1187 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
1188 emit_store_dst(jd, iptr, d);
1191 case ICMD_SALOAD: /* ..., 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_ITMP1);
1196 /* implicit null-pointer check */
1197 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1198 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1199 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1200 emit_store_dst(jd, iptr, d);
1203 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1205 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1206 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1207 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1208 /* implicit null-pointer check */
1209 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1210 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1211 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
1212 emit_store_dst(jd, iptr, d);
1215 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1217 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1218 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1219 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1220 /* implicit null-pointer check */
1221 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1222 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1223 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
1224 emit_store_dst(jd, iptr, d);
1227 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1229 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1230 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1231 /* implicit null-pointer check */
1232 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1233 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1234 #if !defined(ENABLE_SOFTFLOAT)
1235 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1236 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1238 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1239 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1241 emit_store_dst(jd, iptr, d);
1244 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1246 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1247 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1248 /* implicit null-pointer check */
1249 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1250 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1251 #if !defined(ENABLE_SOFTFLOAT)
1252 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1253 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1255 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1256 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
1258 emit_store_dst(jd, iptr, d);
1261 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1263 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1264 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1265 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1266 /* implicit null-pointer check */
1267 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1268 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1269 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1270 emit_store_dst(jd, iptr, d);
1273 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1275 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1276 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1277 /* implicit null-pointer check */
1278 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1279 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1280 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1281 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
1284 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1286 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1287 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1288 /* implicit null-pointer check */
1289 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1290 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1291 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1292 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
1295 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1297 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1298 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1299 /* implicit null-pointer check */
1300 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1301 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1302 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1303 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
1306 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1308 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1309 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1310 /* implicit null-pointer check */
1311 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1312 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1313 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1314 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
1317 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1319 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1320 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1321 /* implicit null-pointer check */
1322 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1323 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1324 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1325 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray, data[0]));
1328 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1330 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1331 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1332 /* implicit null-pointer check */
1333 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1334 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1335 #if !defined(ENABLE_SOFTFLOAT)
1336 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1337 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1339 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1340 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
1344 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1346 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1347 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1348 /* implicit null-pointer check */
1349 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1350 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1351 #if !defined(ENABLE_SOFTFLOAT)
1352 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1353 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1355 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1356 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
1360 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1362 s1 = emit_load_s1(jd, iptr, REG_A0);
1363 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1364 s3 = emit_load_s3(jd, iptr, REG_A1);
1366 /* implicit null-pointer check */
1367 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1369 /* move arguments to argument registers */
1370 M_INTMOVE(s1, REG_A0);
1371 M_INTMOVE(s3, REG_A1);
1373 /* call builtin function */
1374 disp = dseg_add_functionptr(cd, BUILTIN_canstore);
1375 M_DSEG_BRANCH(disp);
1378 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1381 /* check resturn value of builtin */
1382 emit_exception_check(cd, iptr);
1384 /* finally store address into array */
1385 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1386 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1387 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1388 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1389 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
1392 case ICMD_GETSTATIC: /* ... ==> ..., value */
1394 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1395 unresolved_field *uf = iptr->sx.s23.s3.uf;
1397 fieldtype = uf->fieldref->parseddesc.fd->type;
1399 disp = dseg_add_unique_address(cd, NULL);
1401 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1403 if (opt_showdisassemble)
1407 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1409 fieldtype = fi->type;
1411 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1412 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1414 if (opt_showdisassemble)
1418 disp = dseg_add_address(cd, &(fi->value));
1421 M_DSEG_LOAD(REG_ITMP3, disp);
1422 switch (fieldtype) {
1424 #if defined(ENABLE_SOFTFLOAT)
1428 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1429 M_ILD_INTERN(d, REG_ITMP3, 0);
1432 #if defined(ENABLE_SOFTFLOAT)
1435 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1436 M_LLD_INTERN(d, REG_ITMP3, 0);
1438 #if !defined(ENABLE_SOFTFLOAT)
1440 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1441 M_FLD_INTERN(d, REG_ITMP3, 0);
1444 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1445 M_DLD_INTERN(d, REG_ITMP3, 0);
1451 emit_store_dst(jd, iptr, d);
1454 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1456 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1457 unresolved_field *uf = iptr->sx.s23.s3.uf;
1459 fieldtype = uf->fieldref->parseddesc.fd->type;
1461 disp = dseg_add_unique_address(cd, NULL);
1463 codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
1465 if (opt_showdisassemble)
1469 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1471 fieldtype = fi->type;
1473 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1474 codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
1476 if (opt_showdisassemble)
1480 disp = dseg_add_address(cd, &(fi->value));
1483 M_DSEG_LOAD(REG_ITMP3, disp);
1484 switch (fieldtype) {
1486 #if defined(ENABLE_SOFTFLOAT)
1490 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1491 M_IST_INTERN(s1, REG_ITMP3, 0);
1494 #if defined(ENABLE_SOFTFLOAT)
1497 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1498 M_LST_INTERN(s1, REG_ITMP3, 0);
1500 #if !defined(ENABLE_SOFTFLOAT)
1502 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1503 M_FST_INTERN(s1, REG_ITMP3, 0);
1506 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1507 M_DST_INTERN(s1, REG_ITMP3, 0);
1515 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1517 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1518 emit_nullpointer_check(cd, iptr, s1);
1521 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1522 unresolved_field *uf = iptr->sx.s23.s3.uf;
1524 fieldtype = uf->fieldref->parseddesc.fd->type;
1527 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1529 fieldtype = fi->type;
1533 #if !defined(ENABLE_SOFTFLOAT)
1534 /* HACK: softnull checks on floats */
1535 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1536 emit_nullpointer_check_force(cd, iptr, s1);
1539 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1540 unresolved_field *uf = iptr->sx.s23.s3.uf;
1542 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1544 if (opt_showdisassemble)
1550 switch (fieldtype) {
1552 #if defined(ENABLE_SOFTFLOAT)
1556 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1560 #if defined(ENABLE_SOFTFLOAT)
1563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1566 #if !defined(ENABLE_SOFTFLOAT)
1568 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1572 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1579 emit_store_dst(jd, iptr, d);
1582 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1584 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1585 emit_nullpointer_check(cd, iptr, s1);
1587 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1588 unresolved_field *uf = iptr->sx.s23.s3.uf;
1590 fieldtype = uf->fieldref->parseddesc.fd->type;
1593 fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
1595 fieldtype = fi->type;
1599 #if !defined(ENABLE_SOFTFLOAT)
1600 /* HACK: softnull checks on floats */
1601 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1602 emit_nullpointer_check_force(cd, iptr, s1);
1605 switch (fieldtype) {
1607 #if defined(ENABLE_SOFTFLOAT)
1611 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1613 #if defined(ENABLE_SOFTFLOAT)
1614 case TYPE_DBL: /* fall through */
1617 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1619 #if !defined(ENABLE_SOFTFLOAT)
1622 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1629 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1630 unresolved_field *uf = iptr->sx.s23.s3.uf;
1632 codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
1634 if (opt_showdisassemble)
1640 switch (fieldtype) {
1642 #if defined(ENABLE_SOFTFLOAT)
1646 M_IST(s2, s1, disp);
1649 #if defined(ENABLE_SOFTFLOAT)
1652 M_LST(s2, s1, disp);
1654 #if !defined(ENABLE_SOFTFLOAT)
1656 M_FST(s2, s1, disp);
1659 M_DST(s2, s1, disp);
1668 /* branch operations **************************************************/
1670 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1672 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1673 M_INTMOVE(s1, REG_ITMP1_XPTR);
1674 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1675 codegen_addpatchref(cd, PATCHER_athrow_areturn,
1676 iptr->sx.s23.s2.uc, 0);
1678 if (opt_showdisassemble)
1681 disp = dseg_add_functionptr(cd, asm_handle_exception);
1682 M_DSEG_LOAD(REG_ITMP3, disp);
1683 M_MOV(REG_ITMP2_XPC, REG_PC);
1684 M_MOV(REG_PC, REG_ITMP3);
1685 M_NOP; /* nop ensures that XPC is less than the end */
1686 /* of basic block */
1689 case ICMD_GOTO: /* ... ==> ... */
1692 emit_br(cd, iptr->dst.block);
1695 case ICMD_JSR: /* ... ==> ... */
1697 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1700 case ICMD_IFNULL: /* ..., value ==> ... */
1701 case ICMD_IFNONNULL:
1703 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1705 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1708 case ICMD_IFLT: /* ..., value ==> ... */
1709 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1715 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1716 M_COMPARE(s1, iptr->sx.val.i);
1717 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1720 case ICMD_IF_LEQ: /* ..., value ==> ... */
1722 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1723 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1724 if (iptr->sx.val.l == 0) {
1725 M_ORR_S(s1, s2, REG_ITMP3);
1728 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1729 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1730 M_CMP(s1, REG_ITMP3);*/
1731 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1732 M_CMPEQ(s2, REG_ITMP3);
1734 emit_beq(cd, iptr->dst.block);
1737 case ICMD_IF_LLT: /* ..., value ==> ... */
1739 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1740 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1741 if (iptr->sx.val.l == 0) {
1742 /* if high word is less than zero, the whole long is too */
1744 emit_blt(cd, iptr->dst.block);
1747 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1748 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1749 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1750 M_CMP(s1, REG_ITMP3);*/
1751 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1752 M_MOVGT_IMM(2, REG_ITMP1);
1753 M_MOVEQ_IMM(1, REG_ITMP1);
1755 /* low compare: x=x-1(ifLO) */
1756 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1757 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1758 M_CMP(s2, REG_ITMP3);*/
1759 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1761 /* branch if (x LT 1) */
1762 M_CMP_IMM(REG_ITMP1, 1);
1763 emit_blt(cd, iptr->dst.block);
1767 case ICMD_IF_LLE: /* ..., value ==> ... */
1769 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1770 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1771 if (iptr->sx.val.l == 0) {
1772 /* if high word is less than zero, the whole long is too */
1774 emit_blt(cd, iptr->dst.block);
1776 /* ... otherwise the low word has to be zero (tricky!) */
1778 emit_beq(cd, iptr->dst.block);
1781 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1782 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1783 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1784 M_CMP(s1, REG_ITMP3);*/
1785 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1786 M_MOVGT_IMM(2, REG_ITMP1);
1787 M_MOVEQ_IMM(1, REG_ITMP1);
1789 /* low compare: x=x+1(ifHI) */
1790 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1791 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1792 M_CMP(s2, REG_ITMP3);*/
1793 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1795 /* branch if (x LE 1) */
1796 M_CMP_IMM(REG_ITMP1, 1);
1797 emit_ble(cd, iptr->dst.block);
1801 case ICMD_IF_LGE: /* ..., value ==> ... */
1803 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1804 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1805 if (iptr->sx.val.l == 0) {
1806 /* if high word is greater or equal zero, the whole long is too */
1808 emit_bge(cd, iptr->dst.block);
1811 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1812 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1813 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1814 M_CMP(s1, REG_ITMP3);*/
1815 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1816 M_MOVGT_IMM(2, REG_ITMP1);
1817 M_MOVEQ_IMM(1, REG_ITMP1);
1819 /* low compare: x=x-1(ifLO) */
1820 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1821 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1822 M_CMP(s2, REG_ITMP3);*/
1823 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1825 /* branch if (x GE 1) */
1826 M_CMP_IMM(REG_ITMP1, 1);
1827 emit_bge(cd, iptr->dst.block);
1831 case ICMD_IF_LGT: /* ..., value ==> ... */
1833 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1834 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1836 if (iptr->sx.val.l == 0) {
1837 /* if high word is greater than zero, the whole long is too */
1840 codegen_add_branch_ref(cd, iptr->dst.block);
1842 /* ... or high was zero and low is non zero (tricky!) */
1843 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1844 M_MOVLT_IMM(1, REG_ITMP3);
1845 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1847 codegen_add_branch_ref(cd, iptr->dst.block);
1851 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1852 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1853 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1854 M_CMP(s1, REG_ITMP3);*/
1855 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1856 M_MOVGT_IMM(2, REG_ITMP1);
1857 M_MOVEQ_IMM(1, REG_ITMP1);
1859 /* low compare: x=x+1(ifHI) */
1860 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1861 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1862 M_CMP(s2, REG_ITMP3);*/
1863 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1865 /* branch if (x GT 1) */
1866 M_CMP_IMM(REG_ITMP1, 1);
1867 emit_bgt(cd, iptr->dst.block);
1873 case ICMD_IF_LNE: /* ..., value ==> ... */
1875 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1876 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1877 if (iptr->sx.val.l == 0) {
1878 M_ORR_S(s1, s2, REG_ITMP3);
1881 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1882 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1883 M_CMP(s1, REG_ITMP3);*/
1884 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1885 M_CMPEQ(s2, REG_ITMP3);
1887 emit_bne(cd, iptr->dst.block);
1890 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1891 case ICMD_IF_ICMPNE:
1892 case ICMD_IF_ICMPLT:
1893 case ICMD_IF_ICMPLE:
1894 case ICMD_IF_ICMPGT:
1895 case ICMD_IF_ICMPGE:
1897 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1898 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1900 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1903 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1904 case ICMD_IF_ACMPNE:
1906 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1907 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1909 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1912 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1913 /* op1 = target JavaVM pc */
1915 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1916 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1919 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1920 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1923 emit_beq(cd, iptr->dst.block);
1926 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1927 /* op1 = target JavaVM pc */
1929 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1930 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1933 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1934 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1937 emit_bne(cd, iptr->dst.block);
1940 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1941 /* op1 = target JavaVM pc */
1943 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1944 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1945 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1947 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1948 M_MOVGT_IMM(2, REG_ITMP3);
1949 M_MOVEQ_IMM(1, REG_ITMP3);
1951 /* low compare: x=x-1(ifLO) */
1952 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1953 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1955 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1957 /* branch if (x LT 1) */
1958 M_CMP_IMM(REG_ITMP3, 1);
1959 emit_blt(cd, iptr->dst.block);
1962 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1963 /* op1 = target JavaVM pc */
1965 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1966 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1967 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1969 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1970 M_MOVGT_IMM(2, REG_ITMP3);
1971 M_MOVEQ_IMM(1, REG_ITMP3);
1973 /* low compare: x=x-1(ifLO) */
1974 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1975 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1977 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1979 /* branch if (x LE 1) */
1980 M_CMP_IMM(REG_ITMP3, 1);
1981 emit_ble(cd, iptr->dst.block);
1984 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1985 /* op1 = target JavaVM pc */
1987 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1988 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1989 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1991 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1992 M_MOVGT_IMM(2, REG_ITMP3);
1993 M_MOVEQ_IMM(1, REG_ITMP3);
1995 /* low compare: x=x-1(ifLO) */
1996 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1997 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1999 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
2001 /* branch if (x GT 1) */
2002 M_CMP_IMM(REG_ITMP3, 1);
2003 emit_bgt(cd, iptr->dst.block);
2006 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
2007 /* op1 = target JavaVM pc */
2009 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
2010 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
2011 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
2013 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
2014 M_MOVGT_IMM(2, REG_ITMP3);
2015 M_MOVEQ_IMM(1, REG_ITMP3);
2017 /* low compare: x=x-1(ifLO) */
2018 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
2019 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
2021 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
2023 /* branch if (x GE 1) */
2024 M_CMP_IMM(REG_ITMP3, 1);
2025 emit_bge(cd, iptr->dst.block);
2028 case ICMD_TABLESWITCH: /* ..., index ==> ... */
2031 branch_target_t *table;
2033 table = iptr->dst.table;
2035 l = iptr->sx.s23.s2.tablelow;
2036 i = iptr->sx.s23.s3.tablehigh;
2038 /* calculate new index (index - low) */
2039 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2041 M_INTMOVE(s1, REG_ITMP1);
2042 } else if (IS_IMM(l)) {
2043 M_SUB_IMM(REG_ITMP1, s1, l);
2045 ICONST(REG_ITMP2, l);
2046 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2049 /* range check (index <= high-low) */
2051 M_COMPARE(REG_ITMP1, i-1);
2052 emit_bugt(cd, table[0].block);
2054 /* build jump table top down and use address of lowest entry */
2059 dseg_add_target(cd, table->block);
2064 /* length of dataseg after last dseg_add_target is used by load */
2065 /* TODO: this loads from data-segment */
2066 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2067 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2070 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2073 lookup_target_t *lookup;
2075 lookup = iptr->dst.lookup;
2077 i = iptr->sx.s23.s2.lookupcount;
2080 MCODECHECK((i<<2)+8);
2081 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2084 M_COMPARE(s1, lookup->value);
2085 emit_beq(cd, lookup->target.block);
2089 /* default branch */
2090 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2094 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2096 #if !defined(ENABLE_SOFTFLOAT)
2097 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2098 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT);
2099 goto ICMD_RETURN_do;
2102 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2104 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2105 M_INTMOVE(s1, REG_RESULT);
2106 goto ICMD_RETURN_do;
2108 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2110 #if !defined(ENABLE_SOFTFLOAT)
2111 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2112 M_CAST_FLT_TO_INT_TYPED(VAROP(iptr->s1)->type, s1, REG_RESULT_PACKED);
2113 goto ICMD_RETURN_do;
2116 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2118 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2119 M_LNGMOVE(s1, REG_RESULT_PACKED);
2120 goto ICMD_RETURN_do;
2122 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2124 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2125 M_INTMOVE(s1, REG_RESULT);
2126 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2127 codegen_addpatchref(cd, PATCHER_athrow_areturn,
2128 iptr->sx.s23.s2.uc, 0);
2130 if (opt_showdisassemble)
2133 goto ICMD_RETURN_do;
2135 case ICMD_RETURN: /* ... ==> ... */
2138 #if !defined(NDEBUG)
2139 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2140 emit_verbosecall_exit(jd);
2143 #if defined(ENABLE_THREADS)
2144 /* call monitorexit function */
2146 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
2147 /* stack offset for monitor argument */
2151 /* we need to save the proper return value */
2153 switch (iptr->opc) {
2157 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2159 M_STMFD(BITMASK_RESULT, REG_SP);
2164 M_LDR(REG_A0, REG_SP, s1 * 4);
2165 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2166 M_DSEG_BRANCH(disp);
2168 /* we no longer need PV here, no more loading */
2169 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2170 M_RECOMPUTE_PV(s1);*/
2172 switch (iptr->opc) {
2176 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2178 M_LDMFD(BITMASK_RESULT, REG_SP);
2184 /* deallocate stackframe for spilled variables */
2186 if ((cd->stackframesize - savedregs_num) > 0)
2187 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - savedregs_num);
2189 /* restore callee saved registers + do return */
2191 if (savedregs_bitmask) {
2192 if (!jd->isleafmethod) {
2193 savedregs_bitmask &= ~(1<<REG_LR);
2194 savedregs_bitmask |= (1<<REG_PC);
2196 M_LDMFD(savedregs_bitmask, REG_SP);
2199 /* if LR was not on stack, we need to return manually */
2201 if (jd->isleafmethod)
2202 M_MOV(REG_PC, REG_LR);
2205 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2207 bte = iptr->sx.s23.s3.bte;
2209 goto ICMD_INVOKE_do;
2211 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2212 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2213 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2214 case ICMD_INVOKEINTERFACE:
2216 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2218 um = iptr->sx.s23.s3.um;
2219 md = um->methodref->parseddesc.md;
2222 lm = iptr->sx.s23.s3.fmiref->p.method;
2224 md = lm->parseddesc;
2228 /* copy arguments to registers or stack location */
2230 s3 = md->paramcount;
2232 MCODECHECK((s3 << 1) + 64);
2234 for (s3 = s3 - 1; s3 >= 0; s3--) {
2235 var = VAR(iptr->sx.s23.s2.args[s3]);
2237 if (var->flags & PREALLOC) /* argument was precolored? */
2240 /* TODO: document me */
2241 #if !defined(ENABLE_SOFTFLOAT)
2242 if (IS_INT_LNG_TYPE(var->type)) {
2243 #endif /* !defined(ENABLE_SOFTFLOAT) */
2244 if (!md->params[s3].inmemory) {
2245 s1 = ARGUMENT_REGS(var->type, md->params[s3].regoff);
2246 SPLIT_OPEN(var->type, s1, REG_ITMP2);
2247 d = emit_load(jd, iptr, var, s1);
2249 if (IS_2_WORD_TYPE(var->type))
2254 SPLIT_STORE_AND_CLOSE(var->type, s1, 0);
2257 if (IS_2_WORD_TYPE(var->type)) {
2258 d = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2259 M_LST(d, REG_SP, md->params[s3].regoff * 4);
2262 d = emit_load(jd, iptr, var, REG_ITMP1);
2263 M_IST(d, REG_SP, md->params[s3].regoff * 4);
2266 #if !defined(ENABLE_SOFTFLOAT)
2269 if (!md->params[s3].inmemory) {
2270 s1 = ARGUMENT_REGS(var->type, md->params[s3].regoff);
2271 d = emit_load(jd, iptr, var, REG_FTMP1);
2272 SPLIT_OPEN(var->type, s1, REG_ITMP1);
2273 M_CAST_FLT_TO_INT_TYPED(var->type, d, s1);
2274 SPLIT_STORE_AND_CLOSE(var->type, s1, 0);
2277 d = emit_load(jd, iptr, var, REG_FTMP1);
2278 if (IS_2_WORD_TYPE(var->type))
2279 M_DST(d, REG_SP, md->params[s3].regoff * 4);
2281 M_FST(d, REG_SP, md->params[s3].regoff * 4);
2284 #endif /* !defined(ENABLE_SOFTFLOAT) */
2287 switch (iptr->opc) {
2289 disp = dseg_add_functionptr(cd, bte->fp);
2291 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2293 /* generate the actual call */
2295 M_MOV(REG_LR, REG_PC);
2296 M_MOV(REG_PC, REG_PV);
2297 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2300 emit_exception_check(cd, iptr);
2303 case ICMD_INVOKESPECIAL:
2304 emit_nullpointer_check(cd, iptr, REG_A0);
2307 case ICMD_INVOKESTATIC:
2309 disp = dseg_add_unique_address(cd, NULL);
2311 codegen_addpatchref(cd, PATCHER_invokestatic_special,
2314 if (opt_showdisassemble)
2318 disp = dseg_add_address(cd, lm->stubroutine);
2320 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2322 /* generate the actual call */
2324 M_MOV(REG_LR, REG_PC);
2325 M_MOV(REG_PC, REG_PV);
2326 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2330 case ICMD_INVOKEVIRTUAL:
2332 codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
2334 if (opt_showdisassemble)
2340 s1 = OFFSET(vftbl_t, table[0]) +
2341 sizeof(methodptr) * lm->vftblindex;
2343 /* implicit null-pointer check */
2344 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2345 OFFSET(java_objectheader, vftbl));
2346 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
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);
2356 case ICMD_INVOKEINTERFACE:
2358 codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
2360 if (opt_showdisassemble)
2367 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2368 sizeof(methodptr*) * lm->class->index;
2369 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2372 /* implicit null-pointer check */
2373 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2374 OFFSET(java_objectheader, vftbl));
2375 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2376 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2378 /* generate the actual call */
2380 M_MOV(REG_LR, REG_PC);
2381 M_MOV(REG_PC, REG_PV);
2382 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2387 /* store return value */
2389 d = md->returntype.type;
2391 #if !defined(__SOFTFP__)
2392 /* TODO: this is only a hack, since we use R0/R1 for float
2393 return! this depends on gcc; it is independent from
2394 our ENABLE_SOFTFLOAT define */
2395 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2396 #if 0 && !defined(NDEBUG)
2397 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2399 /* we cannot use this macro, since it is not defined
2400 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2401 REG_FRESULT, REG_RESULT_TYPED(d)); */
2402 if (IS_2_WORD_TYPE(d)) {
2403 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2404 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2406 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2407 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2412 if (d != TYPE_VOID) {
2413 #if !defined(ENABLE_SOFTFLOAT)
2414 if (IS_INT_LNG_TYPE(d)) {
2415 #endif /* !defined(ENABLE_SOFTFLOAT) */
2416 if (IS_2_WORD_TYPE(d)) {
2417 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2418 M_LNGMOVE(REG_RESULT_PACKED, s1);
2421 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2422 M_INTMOVE(REG_RESULT, s1);
2425 #if !defined(ENABLE_SOFTFLOAT)
2427 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2428 M_CAST_INT_TO_FLT_TYPED(VAROP(iptr->dst)->type, REG_RESULT_TYPED(VAROP(iptr->dst)->type), s1);
2430 #endif /* !defined(ENABLE_SOFTFLOAT) */
2432 emit_store_dst(jd, iptr, s1);
2436 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2437 /* val.a: (classinfo*) superclass */
2439 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2440 /* object type cast-check */
2445 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2450 super = iptr->sx.s23.s3.c.cls;
2451 superindex = super->index;
2454 #if defined(ENABLE_THREADS)
2455 codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2457 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2459 /* if class is not resolved, check which code to call */
2461 if (super == NULL) {
2463 emit_label_beq(cd, BRANCH_LABEL_1);
2465 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2466 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2467 iptr->sx.s23.s3.c.ref, disp);
2469 if (opt_showdisassemble)
2472 M_DSEG_LOAD(REG_ITMP2, disp);
2473 disp = dseg_add_s4(cd, ACC_INTERFACE);
2474 M_DSEG_LOAD(REG_ITMP3, disp);
2475 M_TST(REG_ITMP2, REG_ITMP3);
2476 emit_label_beq(cd, BRANCH_LABEL_2);
2479 /* interface checkcast code */
2481 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2482 if (super == NULL) {
2483 codegen_addpatchref(cd,
2484 PATCHER_checkcast_instanceof_interface,
2485 iptr->sx.s23.s3.c.ref, 0);
2487 if (opt_showdisassemble)
2492 emit_label_beq(cd, BRANCH_LABEL_3);
2495 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
2496 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2497 assert(IS_IMM(superindex));
2498 M_CMP_IMM(REG_ITMP3, superindex);
2499 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2501 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2502 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);
2538 #if defined(ENABLE_THREADS)
2539 codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
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));
2546 #if defined(ENABLE_THREADS)
2547 codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
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 */
2602 /* val.a: (classinfo*) superclass */
2607 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2612 super = iptr->sx.s23.s3.c.cls;
2613 superindex = super->index;
2616 #if defined(ENABLE_THREADS)
2617 codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
2619 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2620 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2622 M_MOV(REG_ITMP1, s1);
2626 /* if class is not resolved, check which code to call */
2628 if (super == NULL) {
2632 emit_label_beq(cd, BRANCH_LABEL_1);
2634 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2635 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
2636 iptr->sx.s23.s3.c.ref, disp);
2638 if (opt_showdisassemble)
2641 M_DSEG_LOAD(REG_ITMP2, disp);
2642 disp = dseg_add_s4(cd, ACC_INTERFACE);
2643 M_DSEG_LOAD(REG_ITMP3, disp);
2644 M_TST(REG_ITMP2, REG_ITMP3);
2645 emit_label_beq(cd, BRANCH_LABEL_2);
2648 /* interface checkcast code */
2650 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2651 if (super == NULL) {
2652 /* If d == REG_ITMP2, then it's destroyed in check
2657 codegen_addpatchref(cd,
2658 PATCHER_checkcast_instanceof_interface,
2659 iptr->sx.s23.s3.c.ref, 0);
2661 if (opt_showdisassemble)
2667 emit_label_beq(cd, BRANCH_LABEL_3);
2670 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2671 M_LDR_INTERN(REG_ITMP3,
2672 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2673 assert(IS_IMM(superindex));
2674 M_CMP_IMM(REG_ITMP3, superindex);
2677 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2678 superindex * sizeof(methodptr*);
2680 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2681 M_TST(REG_ITMP3, REG_ITMP3);
2685 emit_label_br(cd, BRANCH_LABEL_4);
2687 emit_label(cd, BRANCH_LABEL_3);
2690 /* class checkcast code */
2692 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2693 if (super == NULL) {
2694 emit_label(cd, BRANCH_LABEL_2);
2696 disp = dseg_add_unique_address(cd, NULL);
2698 codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
2699 iptr->sx.s23.s3.c.ref,
2702 if (opt_showdisassemble)
2706 disp = dseg_add_address(cd, super->vftbl);
2710 emit_label_beq(cd, BRANCH_LABEL_5);
2713 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
2714 M_DSEG_LOAD(REG_ITMP2, disp);
2715 #if defined(ENABLE_THREADS)
2716 codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
2718 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2719 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2720 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2721 #if defined(ENABLE_THREADS)
2722 codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
2724 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2725 M_CMP(REG_ITMP1, REG_ITMP2);
2726 /* If d == REG_ITMP2, then it's destroyed */
2732 emit_label(cd, BRANCH_LABEL_5);
2735 if (super == NULL) {
2736 emit_label(cd, BRANCH_LABEL_1);
2737 emit_label(cd, BRANCH_LABEL_4);
2742 emit_store_dst(jd, iptr, d);
2745 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2747 /* copy sizes to stack if necessary */
2749 MCODECHECK((iptr->s1.argcount << 1) + 64);
2751 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2753 var = VAR(iptr->sx.s23.s2.args[s1]);
2755 /* copy SAVEDVAR sizes to stack */
2757 if (!(var->flags & PREALLOC)) {
2758 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2759 M_STR(s2, REG_SP, s1 * 4);
2763 /* a0 = dimension count */
2765 assert(IS_IMM(iptr->s1.argcount));
2766 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2768 /* is patcher function set? */
2770 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2771 disp = dseg_add_unique_address(cd, NULL);
2773 codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
2774 iptr->sx.s23.s3.c.ref, disp);
2776 if (opt_showdisassemble)
2780 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2782 /* a1 = arraydescriptor */
2784 M_DSEG_LOAD(REG_A1, disp);
2786 /* a2 = pointer to dimensions = stack pointer */
2788 M_INTMOVE(REG_SP, REG_A2);
2790 /* call builtin_multianewarray here */
2792 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2793 M_DSEG_BRANCH(disp);
2797 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2800 /* check for exception before result assignment */
2802 emit_exception_check(cd, iptr);
2806 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2807 M_INTMOVE(REG_RESULT, d);
2808 emit_store_dst(jd, iptr, d);
2811 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2813 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2814 emit_nullpointer_check(cd, iptr, s1);
2818 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2821 } /* the big switch */
2823 } /* for all instructions */
2825 } /* for all basic blocks */
2827 dseg_createlinenumbertable(cd);
2830 /* generate stubs */
2832 emit_patcher_stubs(jd);
2834 /* everything's ok */
2840 /* createcompilerstub **********************************************************
2842 creates a stub routine which calls the compiler
2844 *******************************************************************************/
2846 #define COMPILERSTUB_DATASIZE 3 * SIZEOF_VOID_P
2847 #define COMPILERSTUB_CODESIZE 2 * 4
2849 #define COMPILERSTUB_SIZE COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
2852 u1 *createcompilerstub(methodinfo *m)
2854 u1 *s; /* memory to hold the stub */
2857 s4 dumpsize; /* code generation pointer */
2859 s = CNEW(u1, COMPILERSTUB_SIZE);
2861 /* set data pointer and code pointer */
2864 s = s + COMPILERSTUB_DATASIZE;
2866 /* mark start of dump memory area */
2868 dumpsize = dump_size();
2870 cd = DNEW(codegendata);
2873 /* The codeinfo pointer is actually a pointer to the
2874 methodinfo. This fakes a codeinfo structure. */
2876 d[0] = (ptrint) asm_call_jit_compiler;
2878 d[2] = (ptrint) &d[1]; /* fake code->m */
2880 /* code for the stub */
2882 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2883 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2885 #if defined(ENABLE_STATISTICS)
2887 count_cstub_len += COMPILERSTUB_SIZE * 4;
2890 /* release dump area */
2892 dump_release(dumpsize);
2894 /* synchronize instruction and data cache */
2896 md_cacheflush(s, cd->mcodeptr - (u1 *) d);
2902 /* createnativestub ************************************************************
2904 Creates a stub routine which calls a native method.
2906 *******************************************************************************/
2908 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
2918 s4 disp, funcdisp, s1, s2;
2920 /* get required compiler data */
2927 /* initialize variables */
2930 nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
2932 /* calculate stackframe size */
2934 cd->stackframesize =
2935 1 + /* return address */
2936 sizeof(stackframeinfo) / SIZEOF_VOID_P + /* stackframeinfo */
2937 sizeof(localref_table) / SIZEOF_VOID_P + /* localref_table */
2938 nmd->memuse; /* stack arguments */
2940 /* align stack to 8-byte */
2942 cd->stackframesize = (cd->stackframesize + 1) & ~1;
2944 /* create method header */
2946 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2947 (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize */
2948 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2949 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2950 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2951 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2952 (void) dseg_addlinenumbertablesize(cd);
2953 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2955 /* generate stub code */
2957 M_STMFD(1<<REG_LR, REG_SP);
2958 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
2960 #if !defined(NDEBUG)
2961 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2962 emit_verbosecall_enter(jd);
2965 /* get function address (this must happen before the stackframeinfo) */
2967 funcdisp = dseg_add_functionptr(cd, f);
2969 #if !defined(WITH_STATIC_CLASSPATH)
2971 codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
2973 if (opt_showdisassemble)
2978 /* Save integer and float argument registers (these are 4
2979 registers, stack is 8-byte aligned). */
2981 M_STMFD(BITMASK_ARGS, REG_SP);
2982 /* TODO: floating point */
2984 /* create native stackframe info */
2986 assert(IS_IMM(4*4 + cd->stackframesize * 4));
2987 M_ADD_IMM(REG_A0, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2988 M_MOV(REG_A1, REG_PV);
2989 M_ADD_IMM(REG_A2, REG_SP, 4*4 + cd->stackframesize * 4);
2990 M_LDR_INTERN(REG_A3, REG_SP, 4*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
2991 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2992 M_DSEG_BRANCH(disp);
2996 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2999 /* Restore integer and float argument registers (these are 4
3000 registers, stack is 8-byte aligned). */
3002 M_LDMFD(BITMASK_ARGS, REG_SP);
3003 /* TODO: floating point */
3005 /* copy or spill arguments to new locations */
3006 /* ATTENTION: the ARM has only integer argument registers! */
3008 for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
3009 t = md->paramtypes[i].type;
3011 if (!md->params[i].inmemory) {
3012 s1 = ARGUMENT_REGS(t, md->params[i].regoff);
3014 if (!nmd->params[j].inmemory) {
3015 s2 = ARGUMENT_REGS(t, nmd->params[j].regoff);
3017 #if !defined(__ARM_EABI__)
3018 SPLIT_OPEN(t, s1, REG_ITMP1);
3019 SPLIT_LOAD(t, s1, cd->stackframesize);
3020 SPLIT_OPEN(t, s2, REG_ITMP1);
3023 if (IS_2_WORD_TYPE(t))
3028 #if !defined(__ARM_EABI__)
3029 SPLIT_STORE_AND_CLOSE(t, s2, 0);
3033 s2 = nmd->params[j].regoff;
3035 #if !defined(__ARM_EABI__)
3036 SPLIT_OPEN(t, s1, REG_ITMP1);
3037 SPLIT_LOAD(t, s1, cd->stackframesize);
3040 if (IS_2_WORD_TYPE(t))
3041 M_LST(s1, REG_SP, s2 * 4);
3043 M_IST(s1, REG_SP, s2 * 4);
3044 /* no SPLIT_CLOSE here because argument is fully on stack now */
3048 s1 = md->params[i].regoff + cd->stackframesize;
3049 s2 = nmd->params[j].regoff;
3051 if (IS_2_WORD_TYPE(t)) {
3052 M_LLD(REG_ITMP12_PACKED, REG_SP, s1 * 4);
3053 M_LST(REG_ITMP12_PACKED, REG_SP, s2 * 4);
3056 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
3057 M_IST(REG_ITMP1, REG_SP, s2 * 4);
3062 /* put class into second argument register */
3064 if (m->flags & ACC_STATIC) {
3065 disp = dseg_add_address(cd, m->class);
3066 M_DSEG_LOAD(REG_A1, disp);
3069 /* put env into first argument register */
3071 disp = dseg_add_address(cd, _Jv_env);
3072 M_DSEG_LOAD(REG_A0, disp);
3074 /* do the native function call */
3076 M_DSEG_BRANCH(funcdisp);
3079 /* TODO: this is only needed because of the tracer ... do we
3082 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3085 #if !defined(__SOFTFP__)
3086 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3087 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3088 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3089 #if 0 && !defined(NDEBUG)
3090 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3092 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3093 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3094 if (IS_2_WORD_TYPE(md->returntype.type)) {
3095 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3096 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3098 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3099 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3104 #if !defined(NDEBUG)
3105 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3106 emit_verbosecall_exit(jd);
3109 /* remove native stackframe info */
3110 /* TODO: improve this store/load */
3112 M_STMFD(BITMASK_RESULT, REG_SP);
3114 M_ADD_IMM(REG_A0, REG_SP, 2*4 + cd->stackframesize * 4 - SIZEOF_VOID_P);
3115 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3116 M_DSEG_BRANCH(disp);
3117 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3120 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3121 M_LDMFD(BITMASK_RESULT, REG_SP);
3123 /* finish stub code, but do not yet return to caller */
3125 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize - 1);
3126 M_LDMFD(1<<REG_LR, REG_SP);
3128 /* check for exception */
3130 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3131 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3133 /* handle exception here */
3135 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3137 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3138 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3139 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3141 /* generate patcher stubs */
3143 emit_patcher_stubs(jd);
3147 return code->entrypoint;
3151 /* asm_debug *******************************************************************
3155 *******************************************************************************/
3157 void asm_debug(int a1, int a2, int a3, int a4)
3159 printf("===> i am going to exit after this debugging message!\n");
3160 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3161 vm_abort("leave you now");
3166 * These are local overrides for various environment variables in Emacs.
3167 * Please do not remove this and leave it at the end of the file, where
3168 * Emacs will automagically detect them.
3169 * ---------------------------------------------------------------------
3172 * indent-tabs-mode: t
3176 * vim:noexpandtab:sw=4:ts=4: