1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 #include "vm/jit/arm/arch.h"
38 #include "vm/jit/arm/codegen.h"
40 #include "mm/memory.h"
42 #include "native/localref.h"
43 #include "native/native.h"
45 #include "threads/lock-common.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
52 #include "vm/jit/abi.h"
53 #include "vm/jit/asmpart.h"
54 #include "vm/jit/codegen-common.h"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/emit-common.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/md.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher-common.h"
62 #include "vm/jit/reg.h"
64 #if defined(ENABLE_LSRA)
65 #include "vm/jit/allocator/lsra.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/options.h"
72 /* codegen_emit ****************************************************************
74 Generates machine code.
76 *******************************************************************************/
78 bool codegen_emit(jitdata *jd)
97 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
98 unresolved_method *um;
99 builtintable_entry *bte;
102 unresolved_field *uf;
106 /* get required compiler data */
113 /* prevent compiler warnings */
121 /* space to save used callee saved registers */
123 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
125 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
126 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
127 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
129 spilledregs_num = rd->memuse;
131 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
132 if (checksync && code_is_synchronized(code))
136 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
138 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
139 only in native stubs. */
140 /* align stack to 8-byte */
142 cd->stackframesize = (cd->stackframesize + 4) & ~4;
144 /* SECTION: Method Header */
145 /* create method header */
147 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
148 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
150 code->synchronizedoffset = rd->memuse * 8;
152 /* REMOVEME: We still need it for exception handling in assembler. */
154 if (code_is_leafmethod(code))
155 (void) dseg_add_unique_s4(cd, 1);
157 (void) dseg_add_unique_s4(cd, 0);
159 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
160 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
161 (void) dseg_addlinenumbertablesize(cd);
162 (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize */
164 /* create exception table */
166 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
167 dseg_add_target(cd, ex->start);
168 dseg_add_target(cd, ex->end);
169 dseg_add_target(cd, ex->handler);
170 (void) dseg_add_unique_address(cd, ex->catchtype.any);
173 /* save return address and used callee saved registers */
175 savedregs_bitmask = 0;
177 if (!code_is_leafmethod(code))
178 savedregs_bitmask = (1<<REG_LR);
180 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
181 savedregs_bitmask |= (1<<(rd->savintregs[i]));
184 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
185 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
186 /* TODO: floating-point */
190 if (savedregs_bitmask)
191 M_STMFD(savedregs_bitmask, REG_SP);
193 /* create additional stack frame for spilled variables (if necessary) */
195 if ((cd->stackframesize / 4 - savedregs_num) > 0)
196 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
198 /* take arguments out of register or stack frame */
201 for (i = 0, len = 0; i < md->paramcount; i++) {
202 s1 = md->params[i].regoff;
203 t = md->paramtypes[i].type;
205 varindex = jd->local_map[len * 5 + t];
207 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
209 if (varindex == UNUSED)
214 /* ATTENTION: we use interger registers for all arguments (even float) */
215 #if !defined(ENABLE_SOFTFLOAT)
216 if (IS_INT_LNG_TYPE(t)) {
218 if (!md->params[i].inmemory) {
219 if (!(var->flags & INMEMORY)) {
220 if (IS_2_WORD_TYPE(t))
221 M_LNGMOVE(s1, var->vv.regoff);
223 M_INTMOVE(s1, var->vv.regoff);
226 if (IS_2_WORD_TYPE(t))
227 M_LST(s1, REG_SP, var->vv.regoff);
229 M_IST(s1, REG_SP, var->vv.regoff);
232 else { /* stack arguments */
233 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
234 if (IS_2_WORD_TYPE(t))
235 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
237 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
239 else { /* stack arg -> spilled */
240 /* Reuse Memory Position on Caller Stack */
241 var->vv.regoff = cd->stackframesize + s1;
244 #if !defined(ENABLE_SOFTFLOAT)
247 if (!md->params[i].inmemory) {
248 if (!(var->flags & INMEMORY)) {
249 if (IS_2_WORD_TYPE(t))
250 M_CAST_L2D(s1, var->vv.regoff);
252 M_CAST_I2F(s1, var->vv.regoff);
255 if (IS_2_WORD_TYPE(t))
256 M_LST(s1, REG_SP, var->vv.regoff);
258 M_IST(s1, REG_SP, var->vv.regoff);
262 if (!(var->flags & INMEMORY)) {
263 if (IS_2_WORD_TYPE(t))
264 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
266 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
269 /* Reuse Memory Position on Caller Stack */
270 var->vv.regoff = cd->stackframesize + s1;
274 #endif /* !defined(ENABLE_SOFTFLOAT) */
277 #if defined(ENABLE_THREADS)
278 /* call monitorenter function */
280 if (checksync && code_is_synchronized(code)) {
281 /* stack offset for monitor argument */
285 # if !defined(NDEBUG)
286 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
287 M_STMFD(BITMASK_ARGS, REG_SP);
292 /* get the correct lock object */
294 if (m->flags & ACC_STATIC) {
295 disp = dseg_add_address(cd, &m->class->object.header);
296 M_DSEG_LOAD(REG_A0, disp);
299 emit_nullpointer_check_force(cd, iptr, REG_A0);
302 M_STR(REG_A0, REG_SP, s1);
303 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
305 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
308 # if !defined(NDEBUG)
309 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
310 M_LDMFD(BITMASK_ARGS, REG_SP);
316 /* call trace function */
318 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
319 emit_verbosecall_enter(jd);
322 /* end of header generation */
324 /* create replacement points */
325 REPLACEMENT_POINTS_INIT(cd, jd);
327 /* SECTION: ICMD Code Generation */
328 /* for all basic blocks */
330 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
332 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
334 /* is this basic block reached? */
336 if (bptr->flags < BBREACHED)
339 /* branch resolving */
341 codegen_resolve_branchrefs(cd, bptr);
343 /* handle replacement points */
344 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
346 /* copy interface registers to their destination */
352 #if defined(ENABLE_LSRA)
356 var = VAR(bptr->invars[len]);
357 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
358 if (!(var->flags & INMEMORY))
362 M_INTMOVE(REG_ITMP1, d);
363 emit_store(jd, NULL, var, d);
370 var = VAR(bptr->invars[len]);
372 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
373 d = codegen_reg_of_var(0, var, REG_ITMP1);
374 M_INTMOVE(REG_ITMP1, d);
375 emit_store(jd, NULL, var, d);
378 assert((var->flags & INOUT));
381 #if defined(ENABLE_LSRA)
385 /* for all instructions */
388 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
390 /* add line number */
391 if (iptr->line != currentline) {
392 dseg_addlinenumber(cd, iptr->line);
393 currentline = iptr->line;
396 MCODECHECK(64); /* an instruction usually needs < 64 words */
400 case ICMD_NOP: /* ... ==> ... */
403 /* constant operations ************************************************/
405 case ICMD_ICONST: /* ... ==> ..., constant */
407 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
408 ICONST(d, iptr->sx.val.i);
409 emit_store_dst(jd, iptr, d);
412 case ICMD_ACONST: /* ... ==> ..., constant */
414 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
415 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
416 disp = dseg_add_unique_address(cd, NULL);
418 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
419 iptr->sx.val.c.ref, disp);
421 M_DSEG_LOAD(d, disp);
424 ICONST(d, (u4) iptr->sx.val.anyptr);
426 emit_store_dst(jd, iptr, d);
429 case ICMD_LCONST: /* ... ==> ..., constant */
431 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
432 LCONST(d, iptr->sx.val.l);
433 emit_store_dst(jd, iptr, d);
436 case ICMD_FCONST: /* ... ==> ..., constant */
438 #if defined(ENABLE_SOFTFLOAT)
439 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
440 ICONST(d, iptr->sx.val.i);
441 emit_store_dst(jd, iptr, d);
443 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
444 FCONST(d, iptr->sx.val.f);
445 emit_store_dst(jd, iptr, d);
449 case ICMD_DCONST: /* ... ==> ..., constant */
451 #if defined(ENABLE_SOFTFLOAT)
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);
456 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
457 DCONST(d, iptr->sx.val.d);
458 emit_store_dst(jd, iptr, d);
463 /* load/store/copy/move operations ************************************/
465 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
466 case ICMD_ALOAD: /* op1 = local variable */
470 case ICMD_ISTORE: /* ..., value ==> ... */
481 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
485 /* pop operations *****************************************************/
487 /* attention: double and longs are only one entry in CACAO ICMDs */
489 case ICMD_POP: /* ..., value ==> ... */
490 case ICMD_POP2: /* ..., value, value ==> ... */
495 /* integer operations *************************************************/
497 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
499 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
500 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
501 M_MOV(d, REG_LSL(s1, 24));
502 M_MOV(d, REG_ASR(d, 24));
503 emit_store_dst(jd, iptr, d);
506 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
508 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
509 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
510 M_MOV(d, REG_LSL(s1, 16));
511 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
512 emit_store_dst(jd, iptr, d);
515 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
517 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
518 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
519 M_MOV(d, REG_LSL(s1, 16));
520 M_MOV(d, REG_ASR(d, 16));
521 emit_store_dst(jd, iptr, d);
524 case ICMD_I2L: /* ..., value ==> ..., value */
526 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
527 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
528 M_INTMOVE(s1, GET_LOW_REG(d));
529 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
530 emit_store_dst(jd, iptr, d);
533 case ICMD_L2I: /* ..., value ==> ..., value */
535 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
536 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
538 emit_store_dst(jd, iptr, d);
541 case ICMD_INEG: /* ..., value ==> ..., - value */
543 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
544 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
546 emit_store_dst(jd, iptr, d);
549 case ICMD_LNEG: /* ..., value ==> ..., - value */
551 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
552 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
553 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
554 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
555 emit_store_dst(jd, iptr, d);
558 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
560 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
561 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
562 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
564 emit_store_dst(jd, iptr, d);
567 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
569 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
570 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
571 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
572 M_ADD_S(GET_LOW_REG(d), s1, s2);
573 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
574 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
575 M_ADC(GET_HIGH_REG(d), s1, s2);
576 emit_store_dst(jd, iptr, d);
582 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
583 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
585 if (IS_IMM(iptr->sx.val.i)) {
586 M_ADD_IMM(d, s1, iptr->sx.val.i);
587 } else if (IS_IMM(-iptr->sx.val.i)) {
588 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
590 ICONST(REG_ITMP3, iptr->sx.val.i);
591 M_ADD(d, s1, REG_ITMP3);
594 emit_store_dst(jd, iptr, d);
597 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
598 /* sx.val.l = constant */
600 s3 = iptr->sx.val.l & 0xffffffff;
601 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
602 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
604 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
606 ICONST(REG_ITMP3, s3);
607 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
609 s3 = iptr->sx.val.l >> 32;
610 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
612 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
614 ICONST(REG_ITMP3, s3);
615 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
617 emit_store_dst(jd, iptr, d);
620 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
622 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
623 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
624 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
626 emit_store_dst(jd, iptr, d);
629 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
631 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
632 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
633 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
634 M_SUB_S(GET_LOW_REG(d), s1, s2);
635 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
636 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
637 M_SBC(GET_HIGH_REG(d), s1, s2);
638 emit_store_dst(jd, iptr, d);
641 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
642 /* sx.val.i = constant */
644 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
645 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
646 if (IS_IMM(iptr->sx.val.i))
647 M_SUB_IMM(d, s1, iptr->sx.val.i);
649 ICONST(REG_ITMP3, iptr->sx.val.i);
650 M_SUB(d, s1, REG_ITMP3);
652 emit_store_dst(jd, iptr, d);
655 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
656 /* sx.val.l = constant */
658 s3 = iptr->sx.val.l & 0xffffffff;
659 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
660 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
662 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
664 ICONST(REG_ITMP3, s3);
665 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
667 s3 = iptr->sx.val.l >> 32;
668 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
670 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
672 ICONST(REG_ITMP3, s3);
673 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
675 emit_store_dst(jd, iptr, d);
678 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
680 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
681 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
682 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
684 emit_store_dst(jd, iptr, d);
687 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
688 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
690 s1 = emit_load_s1(jd, iptr, REG_A0);
691 s2 = emit_load_s2(jd, iptr, REG_A1);
692 emit_arithmetic_check(cd, iptr, s2);
694 /* move arguments into argument registers */
695 M_INTMOVE(s1, REG_A0);
696 M_INTMOVE(s2, REG_A1);
698 /* call builtin function */
699 bte = iptr->sx.s23.s3.bte;
700 disp = dseg_add_functionptr(cd, bte->fp);
704 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
707 /* move result into destination register */
708 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
709 M_INTMOVE(REG_RESULT, d);
710 emit_store_dst(jd, iptr, d);
713 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
714 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
716 /* move arguments into argument registers */
718 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
719 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
720 /* XXX TODO: only do this if arithmetic check is really done! */
721 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
722 emit_arithmetic_check(cd, iptr, REG_ITMP3);
724 M_LNGMOVE(s1, REG_A0_A1_PACKED);
725 M_LNGMOVE(s2, REG_A2_A3_PACKED);
727 /* call builtin function */
728 bte = iptr->sx.s23.s3.bte;
729 disp = dseg_add_functionptr(cd, bte->fp);
733 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
736 /* move result into destination register */
737 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
738 M_LNGMOVE(REG_RESULT_PACKED, d);
739 emit_store_dst(jd, iptr, d);
742 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
743 /* sx.val.i = constant */
745 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
746 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
747 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
748 emit_store_dst(jd, iptr, d);
751 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
752 /* sx.val.i = constant */
754 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
755 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
756 /* this rounds towards 0 as java likes it */
757 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
758 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
759 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
760 /* this rounds towards nearest, not java style */
761 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
762 M_ADCMI_IMM(d, d, 0);*/
763 emit_store_dst(jd, iptr, d);
766 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
767 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
769 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
770 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
771 M_MOV_S(REG_ITMP1, s1);
772 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
773 if (IS_IMM(iptr->sx.val.i))
774 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
776 ICONST(REG_ITMP3, iptr->sx.val.i);
777 M_AND(REG_ITMP1, REG_ITMP3, d);
779 M_RSBMI_IMM(d, d, 0);
780 emit_store_dst(jd, iptr, d);
783 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
785 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
786 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
787 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
788 M_AND_IMM(s2, 0x1f, REG_ITMP2);
789 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
790 emit_store_dst(jd, iptr, d);
793 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
795 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
796 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
797 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
798 M_AND_IMM(s2, 0x1f, REG_ITMP2);
799 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
800 emit_store_dst(jd, iptr, d);
803 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
805 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
806 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
807 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
808 M_AND_IMM(s2, 0x1f, REG_ITMP2);
809 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
810 emit_store_dst(jd, iptr, d);
813 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
814 /* sx.val.i = constant */
816 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
817 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
818 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
819 emit_store_dst(jd, iptr, d);
822 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
823 /* sx.val.i = constant */
825 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
826 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
827 /* we need to check for zero here because arm interprets it as SHR by 32 */
828 if ((iptr->sx.val.i & 0x1f) == 0) {
831 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
833 emit_store_dst(jd, iptr, d);
836 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
837 /* sx.val.i = constant */
839 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
840 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
841 /* we need to check for zero here because arm interprets it as SHR by 32 */
842 if ((iptr->sx.val.i & 0x1f) == 0)
845 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
846 emit_store_dst(jd, iptr, d);
849 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
851 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
852 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
853 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
855 emit_store_dst(jd, iptr, d);
858 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
860 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
861 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
862 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
863 M_AND(s1, s2, GET_LOW_REG(d));
864 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
865 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
866 M_AND(s1, s2, GET_HIGH_REG(d));
867 emit_store_dst(jd, iptr, d);
870 case ICMD_IOR: /* ..., 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_LOR: /* ..., 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_ORR(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_ORR(s1, s2, GET_HIGH_REG(d));
888 emit_store_dst(jd, iptr, d);
891 case ICMD_IXOR: /* ..., 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_LXOR: /* ..., 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_EOR(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_EOR(s1, s2, GET_HIGH_REG(d));
909 emit_store_dst(jd, iptr, d);
913 /* floating operations ************************************************/
915 #if !defined(ENABLE_SOFTFLOAT)
917 case ICMD_FNEG: /* ..., value ==> ..., - value */
919 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
920 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
922 emit_store_dst(jd, iptr, d);
925 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
927 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
928 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
929 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
931 emit_store_dst(jd, iptr, d);
934 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
936 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
937 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
938 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
940 emit_store_dst(jd, iptr, d);
943 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
945 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
946 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
947 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
949 emit_store_dst(jd, iptr, d);
952 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
953 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
954 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
955 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
957 emit_store_dst(jd, iptr, d);
960 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
964 case ICMD_FREM: /* ..., 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);
974 case ICMD_DNEG: /* ..., value ==> ..., - value */
976 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
977 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
979 emit_store_dst(jd, iptr, d);
982 case ICMD_DADD: /* ..., 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_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
993 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
994 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
995 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
997 emit_store_dst(jd, iptr, d);
1000 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
1002 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1003 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1004 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1006 emit_store_dst(jd, iptr, d);
1009 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
1011 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1012 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1013 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1015 emit_store_dst(jd, iptr, d);
1018 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1022 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1024 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1025 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1026 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1028 emit_store_dst(jd, iptr, d);
1032 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1034 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1035 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1037 emit_store_dst(jd, iptr, d);
1040 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1042 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1043 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1045 emit_store_dst(jd, iptr, d);
1048 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1050 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1051 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1052 /* this uses round towards zero, as Java likes it */
1054 #if !defined(__VFP_FP__)
1055 /* this checks for NaN; to return zero as Java likes it */
1059 emit_store_dst(jd, iptr, d);
1062 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1064 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1065 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1066 /* this uses round towards zero, as Java likes it */
1068 #if !defined(__VFP_FP__)
1069 /* this checks for NaN; to return zero as Java likes it */
1073 emit_store_dst(jd, iptr, d);
1076 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1078 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1079 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1081 emit_store_dst(jd, iptr, d);
1084 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1086 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1087 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1089 emit_store_dst(jd, iptr, d);
1092 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1094 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1095 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1096 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1099 #if defined(__VFP_FP__)
1100 M_FMSTAT; /* on VFP we need to transfer the flags */
1102 M_SUBGT_IMM(d, d, 1);
1103 M_ADDLT_IMM(d, d, 1);
1104 emit_store_dst(jd, iptr, d);
1107 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1109 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1110 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1111 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1114 #if defined(__VFP_FP__)
1115 M_FMSTAT; /* on VFP we need to transfer the flags */
1117 M_SUBGT_IMM(d, d, 1);
1118 M_ADDLT_IMM(d, d, 1);
1119 emit_store_dst(jd, iptr, d);
1122 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1124 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1125 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1126 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1129 #if defined(__VFP_FP__)
1130 M_FMSTAT; /* on VFP we need to transfer the flags */
1132 M_SUBLT_IMM(d, d, 1);
1133 M_ADDGT_IMM(d, d, 1);
1134 emit_store_dst(jd, iptr, d);
1137 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1139 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1140 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1141 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1144 #if defined(__VFP_FP__)
1145 M_FMSTAT; /* on VFP we need to transfer the flags */
1147 M_SUBLT_IMM(d, d, 1);
1148 M_ADDGT_IMM(d, d, 1);
1149 emit_store_dst(jd, iptr, d);
1152 #endif /* !defined(ENABLE_SOFTFLOAT) */
1155 /* memory operations **************************************************/
1157 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1159 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1160 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1161 /* implicit null-pointer check */
1162 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1163 emit_store_dst(jd, iptr, d);
1166 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1168 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1169 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1170 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1171 /* implicit null-pointer check */
1172 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1173 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1174 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1175 emit_store_dst(jd, iptr, d);
1178 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1180 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1181 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1182 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1183 /* implicit null-pointer check */
1184 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1185 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1186 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1187 emit_store_dst(jd, iptr, d);
1190 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1192 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1193 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1194 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1195 /* implicit null-pointer check */
1196 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1197 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1198 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1199 emit_store_dst(jd, iptr, d);
1202 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1204 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1205 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1206 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1207 /* implicit null-pointer check */
1208 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1209 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1210 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1211 emit_store_dst(jd, iptr, d);
1214 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1216 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1217 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1218 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1219 /* implicit null-pointer check */
1220 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1221 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1222 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1223 emit_store_dst(jd, iptr, d);
1226 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1228 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1229 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1230 /* implicit null-pointer check */
1231 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1232 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1233 #if !defined(ENABLE_SOFTFLOAT)
1234 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1235 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1237 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1238 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1240 emit_store_dst(jd, iptr, d);
1243 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1245 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1246 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1247 /* implicit null-pointer check */
1248 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1249 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1250 #if !defined(ENABLE_SOFTFLOAT)
1251 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1252 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1254 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1255 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1257 emit_store_dst(jd, iptr, d);
1260 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1262 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1263 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1264 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1265 /* implicit null-pointer check */
1266 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1267 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1268 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1269 emit_store_dst(jd, iptr, d);
1272 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1274 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1275 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1276 /* implicit null-pointer check */
1277 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1278 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1279 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1280 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1283 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1285 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1286 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1287 /* implicit null-pointer check */
1288 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1289 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1290 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1291 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1294 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1296 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1297 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1298 /* implicit null-pointer check */
1299 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1300 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1301 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1302 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1305 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1307 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1308 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1309 /* implicit null-pointer check */
1310 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1311 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1312 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1313 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1316 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1318 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1319 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1320 /* implicit null-pointer check */
1321 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1322 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1323 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1324 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1327 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1329 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1330 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1331 /* implicit null-pointer check */
1332 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1333 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1334 #if !defined(ENABLE_SOFTFLOAT)
1335 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1336 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1338 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1339 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1343 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1345 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1346 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1347 /* implicit null-pointer check */
1348 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1349 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1350 #if !defined(ENABLE_SOFTFLOAT)
1351 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1352 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1354 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1355 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1359 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1361 s1 = emit_load_s1(jd, iptr, REG_A0);
1362 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1363 s3 = emit_load_s3(jd, iptr, REG_A1);
1365 /* implicit null-pointer check */
1366 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1368 /* move arguments to argument registers */
1369 M_INTMOVE(s1, REG_A0);
1370 M_INTMOVE(s3, REG_A1);
1372 /* call builtin function */
1373 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1374 M_DSEG_BRANCH(disp);
1377 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1380 /* check resturn value of builtin */
1381 emit_arraystore_check(cd, iptr);
1383 /* finally store address into array */
1384 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1385 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1386 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1387 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1388 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1391 case ICMD_GETSTATIC: /* ... ==> ..., value */
1393 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1394 uf = iptr->sx.s23.s3.uf;
1395 fieldtype = uf->fieldref->parseddesc.fd->type;
1396 disp = dseg_add_unique_address(cd, NULL);
1398 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1401 fi = iptr->sx.s23.s3.fmiref->p.field;
1402 fieldtype = fi->type;
1403 disp = dseg_add_address(cd, fi->value);
1405 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1406 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1411 M_DSEG_LOAD(REG_ITMP3, disp);
1412 switch (fieldtype) {
1414 #if defined(ENABLE_SOFTFLOAT)
1418 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1419 M_ILD_INTERN(d, REG_ITMP3, 0);
1422 #if defined(ENABLE_SOFTFLOAT)
1425 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1426 M_LLD_INTERN(d, REG_ITMP3, 0);
1428 #if !defined(ENABLE_SOFTFLOAT)
1430 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1431 M_FLD_INTERN(d, REG_ITMP3, 0);
1434 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1435 M_DLD_INTERN(d, REG_ITMP3, 0);
1441 emit_store_dst(jd, iptr, d);
1444 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1446 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1447 uf = iptr->sx.s23.s3.uf;
1448 fieldtype = uf->fieldref->parseddesc.fd->type;
1449 disp = dseg_add_unique_address(cd, NULL);
1451 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1454 fi = iptr->sx.s23.s3.fmiref->p.field;
1455 fieldtype = fi->type;
1456 disp = dseg_add_address(cd, fi->value);
1458 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1459 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1464 M_DSEG_LOAD(REG_ITMP3, disp);
1465 switch (fieldtype) {
1467 #if defined(ENABLE_SOFTFLOAT)
1471 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1472 M_IST_INTERN(s1, REG_ITMP3, 0);
1475 #if defined(ENABLE_SOFTFLOAT)
1478 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1479 M_LST_INTERN(s1, REG_ITMP3, 0);
1481 #if !defined(ENABLE_SOFTFLOAT)
1483 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1484 M_FST_INTERN(s1, REG_ITMP3, 0);
1487 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1488 M_DST_INTERN(s1, REG_ITMP3, 0);
1496 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1498 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1499 emit_nullpointer_check(cd, iptr, s1);
1502 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1503 uf = iptr->sx.s23.s3.uf;
1504 fieldtype = uf->fieldref->parseddesc.fd->type;
1508 fi = iptr->sx.s23.s3.fmiref->p.field;
1509 fieldtype = fi->type;
1513 #if !defined(ENABLE_SOFTFLOAT)
1514 /* HACK: softnull checks on floats */
1515 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1516 emit_nullpointer_check_force(cd, iptr, s1);
1519 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1521 uf = iptr->sx.s23.s3.uf;
1523 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1526 switch (fieldtype) {
1528 #if defined(ENABLE_SOFTFLOAT)
1532 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1536 #if defined(ENABLE_SOFTFLOAT)
1539 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1542 #if !defined(ENABLE_SOFTFLOAT)
1544 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1548 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1555 emit_store_dst(jd, iptr, d);
1558 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1560 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1561 emit_nullpointer_check(cd, iptr, s1);
1563 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1564 uf = iptr->sx.s23.s3.uf;
1565 fieldtype = uf->fieldref->parseddesc.fd->type;
1569 fi = iptr->sx.s23.s3.fmiref->p.field;
1570 fieldtype = fi->type;
1574 #if !defined(ENABLE_SOFTFLOAT)
1575 /* HACK: softnull checks on floats */
1576 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1577 emit_nullpointer_check_force(cd, iptr, s1);
1580 switch (fieldtype) {
1582 #if defined(ENABLE_SOFTFLOAT)
1586 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1588 #if defined(ENABLE_SOFTFLOAT)
1589 case TYPE_DBL: /* fall through */
1592 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1594 #if !defined(ENABLE_SOFTFLOAT)
1597 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1604 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1606 uf = iptr->sx.s23.s3.uf;
1608 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1611 switch (fieldtype) {
1613 #if defined(ENABLE_SOFTFLOAT)
1617 M_IST(s2, s1, disp);
1620 #if defined(ENABLE_SOFTFLOAT)
1623 M_LST(s2, s1, disp);
1625 #if !defined(ENABLE_SOFTFLOAT)
1627 M_FST(s2, s1, disp);
1630 M_DST(s2, s1, disp);
1639 /* branch operations **************************************************/
1641 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1643 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1644 M_INTMOVE(s1, REG_ITMP1_XPTR);
1645 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1646 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1647 iptr->sx.s23.s2.uc, 0);
1649 disp = dseg_add_functionptr(cd, asm_handle_exception);
1650 M_DSEG_LOAD(REG_ITMP3, disp);
1651 M_MOV(REG_ITMP2_XPC, REG_PC);
1652 M_MOV(REG_PC, REG_ITMP3);
1653 M_NOP; /* nop ensures that XPC is less than the end */
1654 /* of basic block */
1657 case ICMD_GOTO: /* ... ==> ... */
1660 emit_br(cd, iptr->dst.block);
1663 case ICMD_JSR: /* ... ==> ... */
1665 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1668 case ICMD_IFNULL: /* ..., value ==> ... */
1669 case ICMD_IFNONNULL:
1671 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1673 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1676 case ICMD_IFLT: /* ..., value ==> ... */
1677 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1683 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1684 M_COMPARE(s1, iptr->sx.val.i);
1685 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1688 case ICMD_IF_LEQ: /* ..., value ==> ... */
1690 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1691 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1692 if (iptr->sx.val.l == 0) {
1693 M_ORR_S(s1, s2, REG_ITMP3);
1696 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1697 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1698 M_CMP(s1, REG_ITMP3);*/
1699 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1700 M_CMPEQ(s2, REG_ITMP3);
1702 emit_beq(cd, iptr->dst.block);
1705 case ICMD_IF_LLT: /* ..., value ==> ... */
1707 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1708 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1709 if (iptr->sx.val.l == 0) {
1710 /* if high word is less than zero, the whole long is too */
1712 emit_blt(cd, iptr->dst.block);
1715 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1716 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1717 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1718 M_CMP(s1, REG_ITMP3);*/
1719 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1720 M_MOVGT_IMM(2, REG_ITMP1);
1721 M_MOVEQ_IMM(1, REG_ITMP1);
1723 /* low compare: x=x-1(ifLO) */
1724 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1725 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1726 M_CMP(s2, REG_ITMP3);*/
1727 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1729 /* branch if (x LT 1) */
1730 M_CMP_IMM(REG_ITMP1, 1);
1731 emit_blt(cd, iptr->dst.block);
1735 case ICMD_IF_LLE: /* ..., 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);
1744 /* ... otherwise the low word has to be zero (tricky!) */
1746 emit_beq(cd, iptr->dst.block);
1749 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1750 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1751 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1752 M_CMP(s1, REG_ITMP3);*/
1753 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1754 M_MOVGT_IMM(2, REG_ITMP1);
1755 M_MOVEQ_IMM(1, REG_ITMP1);
1757 /* low compare: x=x+1(ifHI) */
1758 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1759 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1760 M_CMP(s2, REG_ITMP3);*/
1761 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1763 /* branch if (x LE 1) */
1764 M_CMP_IMM(REG_ITMP1, 1);
1765 emit_ble(cd, iptr->dst.block);
1769 case ICMD_IF_LGE: /* ..., value ==> ... */
1771 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1772 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1773 if (iptr->sx.val.l == 0) {
1774 /* if high word is greater or equal zero, the whole long is too */
1776 emit_bge(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(ifLO) */
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_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1793 /* branch if (x GE 1) */
1794 M_CMP_IMM(REG_ITMP1, 1);
1795 emit_bge(cd, iptr->dst.block);
1799 case ICMD_IF_LGT: /* ..., value ==> ... */
1801 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1802 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1804 if (iptr->sx.val.l == 0) {
1805 /* if high word is greater than zero, the whole long is too */
1808 codegen_add_branch_ref(cd, iptr->dst.block);
1810 /* ... or high was zero and low is non zero (tricky!) */
1811 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1812 M_MOVLT_IMM(1, REG_ITMP3);
1813 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1815 codegen_add_branch_ref(cd, iptr->dst.block);
1819 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1820 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1821 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1822 M_CMP(s1, REG_ITMP3);*/
1823 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1824 M_MOVGT_IMM(2, REG_ITMP1);
1825 M_MOVEQ_IMM(1, REG_ITMP1);
1827 /* low compare: x=x+1(ifHI) */
1828 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1829 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1830 M_CMP(s2, REG_ITMP3);*/
1831 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1833 /* branch if (x GT 1) */
1834 M_CMP_IMM(REG_ITMP1, 1);
1835 emit_bgt(cd, iptr->dst.block);
1841 case ICMD_IF_LNE: /* ..., value ==> ... */
1843 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1844 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1845 if (iptr->sx.val.l == 0) {
1846 M_ORR_S(s1, s2, REG_ITMP3);
1849 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1850 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1851 M_CMP(s1, REG_ITMP3);*/
1852 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1853 M_CMPEQ(s2, REG_ITMP3);
1855 emit_bne(cd, iptr->dst.block);
1858 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1859 case ICMD_IF_ICMPNE:
1860 case ICMD_IF_ICMPLT:
1861 case ICMD_IF_ICMPLE:
1862 case ICMD_IF_ICMPGT:
1863 case ICMD_IF_ICMPGE:
1865 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1866 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1868 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1871 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1872 case ICMD_IF_ACMPNE:
1874 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1875 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1877 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1880 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1881 /* op1 = target JavaVM pc */
1883 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1884 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1887 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1888 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1891 emit_beq(cd, iptr->dst.block);
1894 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1895 /* op1 = target JavaVM pc */
1897 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1898 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1901 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1902 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1905 emit_bne(cd, iptr->dst.block);
1908 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1909 /* op1 = target JavaVM pc */
1911 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1912 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1913 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1915 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1916 M_MOVGT_IMM(2, REG_ITMP3);
1917 M_MOVEQ_IMM(1, REG_ITMP3);
1919 /* low compare: x=x-1(ifLO) */
1920 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1921 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1923 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1925 /* branch if (x LT 1) */
1926 M_CMP_IMM(REG_ITMP3, 1);
1927 emit_blt(cd, iptr->dst.block);
1930 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1931 /* op1 = target JavaVM pc */
1933 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1934 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1935 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1937 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1938 M_MOVGT_IMM(2, REG_ITMP3);
1939 M_MOVEQ_IMM(1, REG_ITMP3);
1941 /* low compare: x=x-1(ifLO) */
1942 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1943 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1945 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1947 /* branch if (x LE 1) */
1948 M_CMP_IMM(REG_ITMP3, 1);
1949 emit_ble(cd, iptr->dst.block);
1952 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1953 /* op1 = target JavaVM pc */
1955 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1956 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1957 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1959 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1960 M_MOVGT_IMM(2, REG_ITMP3);
1961 M_MOVEQ_IMM(1, REG_ITMP3);
1963 /* low compare: x=x-1(ifLO) */
1964 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1965 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1967 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1969 /* branch if (x GT 1) */
1970 M_CMP_IMM(REG_ITMP3, 1);
1971 emit_bgt(cd, iptr->dst.block);
1974 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1975 /* op1 = target JavaVM pc */
1977 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1978 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1979 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1981 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1982 M_MOVGT_IMM(2, REG_ITMP3);
1983 M_MOVEQ_IMM(1, REG_ITMP3);
1985 /* low compare: x=x-1(ifLO) */
1986 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1987 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1989 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1991 /* branch if (x GE 1) */
1992 M_CMP_IMM(REG_ITMP3, 1);
1993 emit_bge(cd, iptr->dst.block);
1996 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1999 branch_target_t *table;
2001 table = iptr->dst.table;
2003 l = iptr->sx.s23.s2.tablelow;
2004 i = iptr->sx.s23.s3.tablehigh;
2006 /* calculate new index (index - low) */
2007 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2009 M_INTMOVE(s1, REG_ITMP1);
2010 } else if (IS_IMM(l)) {
2011 M_SUB_IMM(REG_ITMP1, s1, l);
2013 ICONST(REG_ITMP2, l);
2014 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2017 /* range check (index <= high-low) */
2019 M_COMPARE(REG_ITMP1, i-1);
2020 emit_bugt(cd, table[0].block);
2022 /* build jump table top down and use address of lowest entry */
2027 dseg_add_target(cd, table->block);
2032 /* length of dataseg after last dseg_add_target is used by load */
2033 /* TODO: this loads from data-segment */
2034 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2035 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2038 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2041 lookup_target_t *lookup;
2043 lookup = iptr->dst.lookup;
2045 i = iptr->sx.s23.s2.lookupcount;
2048 MCODECHECK((i<<2)+8);
2049 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2052 M_COMPARE(s1, lookup->value);
2053 emit_beq(cd, lookup->target.block);
2057 /* default branch */
2058 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2062 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2064 #if !defined(ENABLE_SOFTFLOAT)
2065 REPLACEMENT_POINT_RETURN(cd, iptr);
2066 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2067 M_CAST_F2I(s1, REG_RESULT);
2068 goto ICMD_RETURN_do;
2071 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2073 REPLACEMENT_POINT_RETURN(cd, iptr);
2074 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2075 M_INTMOVE(s1, REG_RESULT);
2076 goto ICMD_RETURN_do;
2078 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2080 #if !defined(ENABLE_SOFTFLOAT)
2081 REPLACEMENT_POINT_RETURN(cd, iptr);
2082 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2083 M_CAST_D2L(s1, REG_RESULT_PACKED);
2084 goto ICMD_RETURN_do;
2087 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2089 REPLACEMENT_POINT_RETURN(cd, iptr);
2090 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2091 M_LNGMOVE(s1, REG_RESULT_PACKED);
2092 goto ICMD_RETURN_do;
2094 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2096 REPLACEMENT_POINT_RETURN(cd, iptr);
2097 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2098 M_INTMOVE(s1, REG_RESULT);
2099 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2100 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2101 iptr->sx.s23.s2.uc, 0);
2103 goto ICMD_RETURN_do;
2105 case ICMD_RETURN: /* ... ==> ... */
2107 REPLACEMENT_POINT_RETURN(cd, iptr);
2110 #if !defined(NDEBUG)
2111 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2112 emit_verbosecall_exit(jd);
2115 #if defined(ENABLE_THREADS)
2116 /* call monitorexit function */
2118 if (checksync && code_is_synchronized(code)) {
2119 /* stack offset for monitor argument */
2121 s1 = rd->memuse * 8;
2123 /* we need to save the proper return value */
2125 switch (iptr->opc) {
2129 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2131 M_STMFD(BITMASK_RESULT, REG_SP);
2136 M_LDR(REG_A0, REG_SP, s1);
2137 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2138 M_DSEG_BRANCH(disp);
2140 /* we no longer need PV here, no more loading */
2141 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2142 M_RECOMPUTE_PV(s1);*/
2144 switch (iptr->opc) {
2148 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2150 M_LDMFD(BITMASK_RESULT, REG_SP);
2156 /* deallocate stackframe for spilled variables */
2158 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2159 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2161 /* restore callee saved registers + do return */
2163 if (savedregs_bitmask) {
2164 if (!code_is_leafmethod(code)) {
2165 savedregs_bitmask &= ~(1<<REG_LR);
2166 savedregs_bitmask |= (1<<REG_PC);
2168 M_LDMFD(savedregs_bitmask, REG_SP);
2171 /* if LR was not on stack, we need to return manually */
2173 if (code_is_leafmethod(code))
2174 M_MOV(REG_PC, REG_LR);
2177 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2179 bte = iptr->sx.s23.s3.bte;
2181 goto ICMD_INVOKE_do;
2183 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2184 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2185 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2186 case ICMD_INVOKEINTERFACE:
2188 REPLACEMENT_POINT_INVOKE(cd, iptr);
2190 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2192 um = iptr->sx.s23.s3.um;
2193 md = um->methodref->parseddesc.md;
2196 lm = iptr->sx.s23.s3.fmiref->p.method;
2198 md = lm->parseddesc;
2202 /* copy arguments to registers or stack location */
2204 s3 = md->paramcount;
2206 MCODECHECK((s3 << 1) + 64);
2208 for (s3 = s3 - 1; s3 >= 0; s3--) {
2209 var = VAR(iptr->sx.s23.s2.args[s3]);
2210 d = md->params[s3].regoff;
2212 if (var->flags & PREALLOC) /* argument was precolored? */
2215 /* TODO: document me */
2216 #if !defined(ENABLE_SOFTFLOAT)
2217 if (IS_INT_LNG_TYPE(var->type)) {
2218 #endif /* !defined(ENABLE_SOFTFLOAT) */
2219 if (!md->params[s3].inmemory) {
2220 s1 = emit_load(jd, iptr, var, d);
2222 if (IS_2_WORD_TYPE(var->type))
2228 if (IS_2_WORD_TYPE(var->type)) {
2229 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2230 M_LST(s1, REG_SP, d);
2233 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2234 M_IST(s1, REG_SP, d);
2237 #if !defined(ENABLE_SOFTFLOAT)
2240 if (!md->params[s3].inmemory) {
2241 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2242 if (IS_2_WORD_TYPE(var->type))
2248 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2249 if (IS_2_WORD_TYPE(var->type))
2250 M_DST(s1, REG_SP, d);
2252 M_FST(s1, REG_SP, d);
2255 #endif /* !defined(ENABLE_SOFTFLOAT) */
2258 switch (iptr->opc) {
2261 if (bte->stub == NULL) {
2262 disp = dseg_add_functionptr(cd, bte->fp);
2264 disp = dseg_add_functionptr(cd, bte->stub);
2267 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2269 /* generate the actual call */
2271 M_MOV(REG_LR, REG_PC);
2272 M_MOV(REG_PC, REG_PV);
2273 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2277 case ICMD_INVOKESPECIAL:
2278 emit_nullpointer_check(cd, iptr, REG_A0);
2281 case ICMD_INVOKESTATIC:
2283 disp = dseg_add_unique_address(cd, NULL);
2285 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2289 disp = dseg_add_address(cd, lm->stubroutine);
2291 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
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);
2301 case ICMD_INVOKEVIRTUAL:
2303 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2308 s1 = OFFSET(vftbl_t, table[0]) +
2309 sizeof(methodptr) * lm->vftblindex;
2311 /* implicit null-pointer check */
2312 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2313 OFFSET(java_object_t, vftbl));
2314 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2316 /* generate the actual call */
2318 M_MOV(REG_LR, REG_PC);
2319 M_MOV(REG_PC, REG_PV);
2320 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2324 case ICMD_INVOKEINTERFACE:
2326 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2332 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2333 sizeof(methodptr*) * lm->class->index;
2334 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2337 /* implicit null-pointer check */
2338 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2339 OFFSET(java_object_t, vftbl));
2340 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2341 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2343 /* generate the actual call */
2345 M_MOV(REG_LR, REG_PC);
2346 M_MOV(REG_PC, REG_PV);
2347 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2352 /* store size of call code in replacement point */
2353 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2355 /* store return value */
2357 d = md->returntype.type;
2359 #if !defined(__SOFTFP__)
2360 /* TODO: this is only a hack, since we use R0/R1 for float
2361 return! this depends on gcc; it is independent from
2362 our ENABLE_SOFTFLOAT define */
2363 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2364 #if 0 && !defined(NDEBUG)
2365 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2367 /* we cannot use this macro, since it is not defined
2368 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2369 REG_FRESULT, REG_RESULT_TYPED(d)); */
2370 if (IS_2_WORD_TYPE(d)) {
2371 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2372 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2374 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2375 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2380 if (d != TYPE_VOID) {
2381 #if !defined(ENABLE_SOFTFLOAT)
2382 if (IS_INT_LNG_TYPE(d)) {
2383 #endif /* !defined(ENABLE_SOFTFLOAT) */
2384 if (IS_2_WORD_TYPE(d)) {
2385 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2386 M_LNGMOVE(REG_RESULT_PACKED, s1);
2389 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2390 M_INTMOVE(REG_RESULT, s1);
2393 #if !defined(ENABLE_SOFTFLOAT)
2395 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2396 if (IS_2_WORD_TYPE(d))
2397 M_CAST_L2D(REG_RESULT_PACKED, s1);
2399 M_CAST_I2F(REG_RESULT, s1);
2401 #endif /* !defined(ENABLE_SOFTFLOAT) */
2403 emit_store_dst(jd, iptr, s1);
2407 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2409 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2410 /* object type cast-check */
2415 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2420 super = iptr->sx.s23.s3.c.cls;
2421 superindex = super->index;
2424 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2425 CODEGEN_CRITICAL_SECTION_NEW;
2427 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2429 /* if class is not resolved, check which code to call */
2431 if (super == NULL) {
2433 emit_label_beq(cd, BRANCH_LABEL_1);
2435 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2436 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2437 iptr->sx.s23.s3.c.ref, disp);
2439 M_DSEG_LOAD(REG_ITMP2, disp);
2440 disp = dseg_add_s4(cd, ACC_INTERFACE);
2441 M_DSEG_LOAD(REG_ITMP3, disp);
2442 M_TST(REG_ITMP2, REG_ITMP3);
2443 emit_label_beq(cd, BRANCH_LABEL_2);
2446 /* interface checkcast code */
2448 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2449 if ((super == NULL) || !IS_IMM(superindex)) {
2450 disp = dseg_add_unique_s4(cd, superindex);
2452 if (super == NULL) {
2453 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2454 iptr->sx.s23.s3.c.ref, disp);
2458 emit_label_beq(cd, BRANCH_LABEL_3);
2461 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2462 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2464 /* we put unresolved or non-immediate superindices onto dseg */
2465 if ((super == NULL) || !IS_IMM(superindex)) {
2466 /* disp was computed before we added the patcher */
2467 M_DSEG_LOAD(REG_ITMP2, disp);
2468 M_CMP(REG_ITMP3, REG_ITMP2);
2470 assert(IS_IMM(superindex));
2471 M_CMP_IMM(REG_ITMP3, superindex);
2474 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2476 /* if we loaded the superindex out of the dseg above, we do
2477 things differently here! */
2478 if ((super == NULL) || !IS_IMM(superindex)) {
2480 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2482 /* this assumes something */
2483 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2485 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2486 assert(sizeof(methodptr*) == 4);
2487 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2493 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2494 superindex * sizeof(methodptr*);
2498 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2499 M_TST(REG_ITMP3, REG_ITMP3);
2500 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2503 emit_label_br(cd, BRANCH_LABEL_4);
2505 emit_label(cd, BRANCH_LABEL_3);
2508 /* class checkcast code */
2510 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2511 if (super == NULL) {
2512 emit_label(cd, BRANCH_LABEL_2);
2514 disp = dseg_add_unique_address(cd, NULL);
2516 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2517 iptr->sx.s23.s3.c.ref,
2521 disp = dseg_add_address(cd, super->vftbl);
2524 emit_label_beq(cd, BRANCH_LABEL_5);
2527 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2528 M_DSEG_LOAD(REG_ITMP3, disp);
2530 CODEGEN_CRITICAL_SECTION_START;
2532 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2533 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2534 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2535 M_DSEG_LOAD(REG_ITMP3, disp);
2536 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2538 CODEGEN_CRITICAL_SECTION_END;
2540 M_CMP(REG_ITMP2, REG_ITMP3);
2541 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2544 emit_label(cd, BRANCH_LABEL_5);
2547 if (super == NULL) {
2548 emit_label(cd, BRANCH_LABEL_1);
2549 emit_label(cd, BRANCH_LABEL_4);
2552 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2555 /* array type cast-check */
2557 s1 = emit_load_s1(jd, iptr, REG_A0);
2558 M_INTMOVE(s1, REG_A0);
2560 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2561 disp = dseg_add_unique_address(cd, NULL);
2563 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2564 iptr->sx.s23.s3.c.ref,
2568 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2570 M_DSEG_LOAD(REG_A1, disp);
2571 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2572 M_DSEG_BRANCH(disp);
2575 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2576 M_RECOMPUTE_PV(disp);
2578 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2579 M_TST(REG_RESULT, REG_RESULT);
2580 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2582 d = codegen_reg_of_dst(jd, iptr, s1);
2586 emit_store_dst(jd, iptr, d);
2589 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2595 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2600 super = iptr->sx.s23.s3.c.cls;
2601 superindex = super->index;
2604 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2605 CODEGEN_CRITICAL_SECTION_NEW;
2607 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2608 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2611 M_MOV(REG_ITMP1, s1);
2615 /* if class is not resolved, check which code to call */
2617 if (super == NULL) {
2621 emit_label_beq(cd, BRANCH_LABEL_1);
2623 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2624 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2625 iptr->sx.s23.s3.c.ref, disp);
2627 M_DSEG_LOAD(REG_ITMP2, disp);
2628 disp = dseg_add_s4(cd, ACC_INTERFACE);
2629 M_DSEG_LOAD(REG_ITMP3, disp);
2630 M_TST(REG_ITMP2, REG_ITMP3);
2631 emit_label_beq(cd, BRANCH_LABEL_2);
2634 /* interface checkcast code */
2636 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2637 if ((super == NULL) || !IS_IMM(superindex)) {
2638 disp = dseg_add_unique_s4(cd, superindex);
2640 if (super == NULL) {
2641 /* If d == REG_ITMP2, then it's destroyed in check
2646 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2647 iptr->sx.s23.s3.c.ref, disp);
2652 emit_label_beq(cd, BRANCH_LABEL_3);
2655 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2656 M_LDR_INTERN(REG_ITMP3,
2657 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2659 /* we put unresolved or non-immediate superindices onto dseg
2660 and do things slightly different */
2661 if ((super == NULL) || !IS_IMM(superindex)) {
2662 /* disp was computed before we added the patcher */
2663 M_DSEG_LOAD(REG_ITMP2, disp);
2664 M_CMP(REG_ITMP3, REG_ITMP2);
2666 if (d == REG_ITMP2) {
2673 /* this assumes something */
2674 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2676 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2677 assert(sizeof(methodptr*) == 4);
2678 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2680 if (d == REG_ITMP2) {
2687 assert(IS_IMM(superindex));
2688 M_CMP_IMM(REG_ITMP3, superindex);
2692 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2693 superindex * sizeof(methodptr*);
2697 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2698 M_TST(REG_ITMP3, REG_ITMP3);
2702 emit_label_br(cd, BRANCH_LABEL_4);
2704 emit_label(cd, BRANCH_LABEL_3);
2707 /* class checkcast code */
2709 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2710 if (super == NULL) {
2711 emit_label(cd, BRANCH_LABEL_2);
2713 disp = dseg_add_unique_address(cd, NULL);
2715 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2716 iptr->sx.s23.s3.c.ref, disp);
2719 disp = dseg_add_address(cd, super->vftbl);
2723 emit_label_beq(cd, BRANCH_LABEL_5);
2726 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2727 M_DSEG_LOAD(REG_ITMP2, disp);
2729 CODEGEN_CRITICAL_SECTION_START;
2731 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2732 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2733 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2735 CODEGEN_CRITICAL_SECTION_END;
2737 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2738 M_CMP(REG_ITMP1, REG_ITMP2);
2739 /* If d == REG_ITMP2, then it's destroyed */
2745 emit_label(cd, BRANCH_LABEL_5);
2748 if (super == NULL) {
2749 emit_label(cd, BRANCH_LABEL_1);
2750 emit_label(cd, BRANCH_LABEL_4);
2755 emit_store_dst(jd, iptr, d);
2758 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2760 /* copy sizes to stack if necessary */
2762 MCODECHECK((iptr->s1.argcount << 1) + 64);
2764 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2766 var = VAR(iptr->sx.s23.s2.args[s1]);
2768 /* copy SAVEDVAR sizes to stack */
2770 if (!(var->flags & PREALLOC)) {
2771 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2772 M_STR(s2, REG_SP, s1 * 4);
2776 /* a0 = dimension count */
2778 assert(IS_IMM(iptr->s1.argcount));
2779 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2781 /* is patcher function set? */
2783 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2784 disp = dseg_add_unique_address(cd, NULL);
2786 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2787 iptr->sx.s23.s3.c.ref, disp);
2790 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2792 /* a1 = arraydescriptor */
2794 M_DSEG_LOAD(REG_A1, disp);
2796 /* a2 = pointer to dimensions = stack pointer */
2798 M_INTMOVE(REG_SP, REG_A2);
2800 /* call builtin_multianewarray here */
2802 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2803 M_DSEG_BRANCH(disp);
2807 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2810 /* check for exception before result assignment */
2812 emit_exception_check(cd, iptr);
2816 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2817 M_INTMOVE(REG_RESULT, d);
2818 emit_store_dst(jd, iptr, d);
2821 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2823 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2824 emit_nullpointer_check(cd, iptr, s1);
2828 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2831 } /* the big switch */
2833 } /* for all instructions */
2835 } /* for all basic blocks */
2837 dseg_createlinenumbertable(cd);
2840 /* generate traps */
2842 emit_patcher_traps(jd);
2844 /* everything's ok */
2850 /* codegen_emit_stub_compiler **************************************************
2852 Emits a stub routine which calls the compiler.
2854 *******************************************************************************/
2856 void codegen_emit_stub_compiler(jitdata *jd)
2861 /* get required compiler data */
2866 /* code for the stub */
2868 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2869 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2873 /* codegen_emit_stub_native ****************************************************
2875 Emits a stub routine which calls a native method.
2877 *******************************************************************************/
2879 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2890 /* get required compiler data */
2896 /* initialize variables */
2900 /* calculate stackframe size */
2902 cd->stackframesize =
2903 4 + /* return address */
2904 sizeof(stackframeinfo_t) + /* stackframeinfo */
2905 sizeof(localref_table) + /* localref_table */
2906 nmd->memuse * 4; /* stack arguments */
2908 /* align stack to 8-byte */
2910 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2912 /* create method header */
2914 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2915 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2916 (void) dseg_add_unique_s4(cd, 0); /* IsSync */
2917 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2918 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2919 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2920 (void) dseg_addlinenumbertablesize(cd);
2921 (void) dseg_add_unique_s4(cd, 0); /* ExTableSize */
2923 /* generate stub code */
2925 M_STMFD(1<<REG_LR, REG_SP);
2926 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2928 #if !defined(NDEBUG)
2929 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2930 emit_verbosecall_enter(jd);
2933 #if defined(ENABLE_GC_CACAO)
2934 /* Save callee saved integer registers in stackframeinfo (GC may
2935 need to recover them during a collection). */
2937 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2938 OFFSET(stackframeinfo_t, intregs);
2940 for (i = 0; i < INT_SAV_CNT; i++)
2941 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2944 /* Save integer and float argument registers (these are 4
2945 registers, stack is 8-byte aligned). */
2947 M_STMFD(BITMASK_ARGS, REG_SP);
2948 /* TODO: floating point */
2950 /* create native stackframe info */
2952 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2953 M_MOV(REG_A1, REG_PV);
2954 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2955 M_DSEG_BRANCH(disp);
2959 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2962 /* remember class argument */
2964 if (m->flags & ACC_STATIC)
2965 M_MOV(REG_ITMP3, REG_RESULT);
2967 /* Restore integer and float argument registers (these are 4
2968 registers, stack is 8-byte aligned). */
2970 M_LDMFD(BITMASK_ARGS, REG_SP);
2971 /* TODO: floating point */
2973 /* copy or spill arguments to new locations */
2974 /* ATTENTION: the ARM has only integer argument registers! */
2976 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2977 t = md->paramtypes[i].type;
2979 if (!md->params[i].inmemory) {
2980 s1 = md->params[i].regoff;
2981 s2 = nmd->params[j].regoff;
2983 if (!nmd->params[j].inmemory) {
2984 #if !defined(__ARM_EABI__)
2985 SPLIT_OPEN(t, s2, REG_ITMP1);
2988 if (IS_2_WORD_TYPE(t))
2993 #if !defined(__ARM_EABI__)
2994 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2998 if (IS_2_WORD_TYPE(t))
2999 M_LST(s1, REG_SP, s2);
3001 M_IST(s1, REG_SP, s2);
3005 s1 = md->params[i].regoff + cd->stackframesize;
3006 s2 = nmd->params[j].regoff;
3008 if (IS_2_WORD_TYPE(t)) {
3009 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
3010 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
3013 M_ILD(REG_ITMP1, REG_SP, s1);
3014 M_IST(REG_ITMP1, REG_SP, s2);
3019 /* Handle native Java methods. */
3021 if (m->flags & ACC_NATIVE) {
3022 /* put class into second argument register */
3024 if (m->flags & ACC_STATIC)
3025 M_MOV(REG_A1, REG_ITMP3);
3027 /* put env into first argument register */
3029 disp = dseg_add_address(cd, _Jv_env);
3030 M_DSEG_LOAD(REG_A0, disp);
3033 /* Call the native function. */
3035 disp = dseg_add_functionptr(cd, f);
3036 M_DSEG_BRANCH(disp);
3039 /* TODO: this is only needed because of the tracer ... do we
3042 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3045 #if !defined(__SOFTFP__)
3046 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3047 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3048 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3049 #if 0 && !defined(NDEBUG)
3050 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3052 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3053 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3054 if (IS_2_WORD_TYPE(md->returntype.type)) {
3055 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3056 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3058 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3059 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3064 #if !defined(NDEBUG)
3065 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3066 emit_verbosecall_exit(jd);
3069 /* remove native stackframe info */
3070 /* TODO: improve this store/load */
3072 M_STMFD(BITMASK_RESULT, REG_SP);
3074 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3075 M_MOV(REG_A1, REG_PV);
3076 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3077 M_DSEG_BRANCH(disp);
3078 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3081 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3082 M_LDMFD(BITMASK_RESULT, REG_SP);
3084 #if defined(ENABLE_GC_CACAO)
3085 /* restore callee saved int registers from stackframeinfo (GC might have */
3086 /* modified them during a collection). */
3088 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3089 OFFSET(stackframeinfo_t, intregs);
3091 for (i = 0; i < INT_SAV_CNT; i++)
3092 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3095 /* finish stub code, but do not yet return to caller */
3097 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3098 M_LDMFD(1<<REG_LR, REG_SP);
3100 /* check for exception */
3102 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3103 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3105 /* handle exception here */
3107 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3109 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3110 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3111 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3113 /* generate patcher stubs */
3115 emit_patcher_traps(jd);
3119 /* asm_debug *******************************************************************
3123 *******************************************************************************/
3125 void asm_debug(int a1, int a2, int a3, int a4)
3127 printf("===> i am going to exit after this debugging message!\n");
3128 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3129 vm_abort("leave you now");
3134 * These are local overrides for various environment variables in Emacs.
3135 * Please do not remove this and leave it at the end of the file, where
3136 * Emacs will automagically detect them.
3137 * ---------------------------------------------------------------------
3140 * indent-tabs-mode: t
3144 * vim:noexpandtab:sw=4:ts=4: