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/linenumbertable.h"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher-common.h"
62 #include "vm/jit/reg.h"
64 #if defined(ENABLE_LSRA)
65 #include "vm/jit/allocator/lsra.h"
68 #include "vmcore/loader.h"
69 #include "vmcore/options.h"
72 /* codegen_emit ****************************************************************
74 Generates machine code.
76 *******************************************************************************/
78 bool codegen_emit(jitdata *jd)
96 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
97 unresolved_method *um;
98 builtintable_entry *bte;
101 unresolved_field *uf;
105 /* get required compiler data */
112 /* prevent compiler warnings */
120 /* space to save used callee saved registers */
122 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
124 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
125 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
126 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
128 spilledregs_num = rd->memuse;
130 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
131 if (checksync && code_is_synchronized(code))
135 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
137 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
138 only in native stubs. */
139 /* align stack to 8-byte */
141 cd->stackframesize = (cd->stackframesize + 4) & ~4;
143 /* SECTION: Method Header */
144 /* create method header */
146 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
147 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
149 code->synchronizedoffset = rd->memuse * 8;
151 /* REMOVEME: We still need it for exception handling in assembler. */
153 if (code_is_leafmethod(code))
154 (void) dseg_add_unique_s4(cd, 1);
156 (void) dseg_add_unique_s4(cd, 0);
158 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
159 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
161 /* save return address and used callee saved registers */
163 savedregs_bitmask = 0;
165 if (!code_is_leafmethod(code))
166 savedregs_bitmask = (1<<REG_LR);
168 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
169 savedregs_bitmask |= (1<<(rd->savintregs[i]));
172 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
173 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
174 /* TODO: floating-point */
178 if (savedregs_bitmask)
179 M_STMFD(savedregs_bitmask, REG_SP);
181 /* create additional stack frame for spilled variables (if necessary) */
183 if ((cd->stackframesize / 4 - savedregs_num) > 0)
184 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
186 /* take arguments out of register or stack frame */
189 for (i = 0, len = 0; i < md->paramcount; i++) {
190 s1 = md->params[i].regoff;
191 t = md->paramtypes[i].type;
193 varindex = jd->local_map[len * 5 + t];
195 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
197 if (varindex == UNUSED)
202 /* ATTENTION: we use interger registers for all arguments (even float) */
203 #if !defined(ENABLE_SOFTFLOAT)
204 if (IS_INT_LNG_TYPE(t)) {
206 if (!md->params[i].inmemory) {
207 if (!(var->flags & INMEMORY)) {
208 if (IS_2_WORD_TYPE(t))
209 M_LNGMOVE(s1, var->vv.regoff);
211 M_INTMOVE(s1, var->vv.regoff);
214 if (IS_2_WORD_TYPE(t))
215 M_LST(s1, REG_SP, var->vv.regoff);
217 M_IST(s1, REG_SP, var->vv.regoff);
220 else { /* stack arguments */
221 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
222 if (IS_2_WORD_TYPE(t))
223 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
225 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
227 else { /* stack arg -> spilled */
228 /* Reuse Memory Position on Caller Stack */
229 var->vv.regoff = cd->stackframesize + s1;
232 #if !defined(ENABLE_SOFTFLOAT)
235 if (!md->params[i].inmemory) {
236 if (!(var->flags & INMEMORY)) {
237 if (IS_2_WORD_TYPE(t))
238 M_CAST_L2D(s1, var->vv.regoff);
240 M_CAST_I2F(s1, var->vv.regoff);
243 if (IS_2_WORD_TYPE(t))
244 M_LST(s1, REG_SP, var->vv.regoff);
246 M_IST(s1, REG_SP, var->vv.regoff);
250 if (!(var->flags & INMEMORY)) {
251 if (IS_2_WORD_TYPE(t))
252 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
254 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
257 /* Reuse Memory Position on Caller Stack */
258 var->vv.regoff = cd->stackframesize + s1;
262 #endif /* !defined(ENABLE_SOFTFLOAT) */
265 #if defined(ENABLE_THREADS)
266 /* call monitorenter function */
268 if (checksync && code_is_synchronized(code)) {
269 /* stack offset for monitor argument */
273 # if !defined(NDEBUG)
274 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
275 M_STMFD(BITMASK_ARGS, REG_SP);
280 /* get the correct lock object */
282 if (m->flags & ACC_STATIC) {
283 disp = dseg_add_address(cd, &m->class->object.header);
284 M_DSEG_LOAD(REG_A0, disp);
287 emit_nullpointer_check_force(cd, iptr, REG_A0);
290 M_STR(REG_A0, REG_SP, s1);
291 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
293 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
296 # if !defined(NDEBUG)
297 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
298 M_LDMFD(BITMASK_ARGS, REG_SP);
304 /* call trace function */
306 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
307 emit_verbosecall_enter(jd);
310 /* end of header generation */
312 /* create replacement points */
313 REPLACEMENT_POINTS_INIT(cd, jd);
315 /* SECTION: ICMD Code Generation */
316 /* for all basic blocks */
318 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
320 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
322 /* is this basic block reached? */
324 if (bptr->flags < BBREACHED)
327 /* branch resolving */
329 codegen_resolve_branchrefs(cd, bptr);
331 /* handle replacement points */
332 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
334 /* copy interface registers to their destination */
340 #if defined(ENABLE_LSRA)
344 var = VAR(bptr->invars[len]);
345 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
346 if (!(var->flags & INMEMORY))
350 M_INTMOVE(REG_ITMP1, d);
351 emit_store(jd, NULL, var, d);
358 var = VAR(bptr->invars[len]);
360 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
361 d = codegen_reg_of_var(0, var, REG_ITMP1);
362 M_INTMOVE(REG_ITMP1, d);
363 emit_store(jd, NULL, var, d);
366 assert((var->flags & INOUT));
369 #if defined(ENABLE_LSRA)
373 /* for all instructions */
376 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
378 /* add line number */
379 if (iptr->line != currentline) {
380 linenumbertable_list_entry_add(cd, iptr->line);
381 currentline = iptr->line;
384 MCODECHECK(64); /* an instruction usually needs < 64 words */
389 case ICMD_NOP: /* ... ==> ... */
390 case ICMD_POP: /* ..., value ==> ... */
391 case ICMD_POP2: /* ..., value, value ==> ... */
394 /* constant operations ************************************************/
396 case ICMD_ICONST: /* ... ==> ..., constant */
398 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
399 ICONST(d, iptr->sx.val.i);
400 emit_store_dst(jd, iptr, d);
403 case ICMD_ACONST: /* ... ==> ..., constant */
405 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
406 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
407 disp = dseg_add_unique_address(cd, NULL);
409 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
410 iptr->sx.val.c.ref, disp);
412 M_DSEG_LOAD(d, disp);
415 ICONST(d, (u4) iptr->sx.val.anyptr);
417 emit_store_dst(jd, iptr, d);
420 case ICMD_LCONST: /* ... ==> ..., constant */
422 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
423 LCONST(d, iptr->sx.val.l);
424 emit_store_dst(jd, iptr, d);
427 case ICMD_FCONST: /* ... ==> ..., constant */
429 #if defined(ENABLE_SOFTFLOAT)
430 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
431 ICONST(d, iptr->sx.val.i);
432 emit_store_dst(jd, iptr, d);
434 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
435 FCONST(d, iptr->sx.val.f);
436 emit_store_dst(jd, iptr, d);
440 case ICMD_DCONST: /* ... ==> ..., constant */
442 #if defined(ENABLE_SOFTFLOAT)
443 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
444 LCONST(d, iptr->sx.val.l);
445 emit_store_dst(jd, iptr, d);
447 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
448 DCONST(d, iptr->sx.val.d);
449 emit_store_dst(jd, iptr, d);
454 /* load/store/copy/move operations ************************************/
456 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
457 case ICMD_ALOAD: /* op1 = local variable */
461 case ICMD_ISTORE: /* ..., value ==> ... */
473 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
478 /* integer operations *************************************************/
480 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
482 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
483 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
484 M_MOV(d, REG_LSL(s1, 24));
485 M_MOV(d, REG_ASR(d, 24));
486 emit_store_dst(jd, iptr, d);
489 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
491 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
492 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
493 M_MOV(d, REG_LSL(s1, 16));
494 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
495 emit_store_dst(jd, iptr, d);
498 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
500 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
501 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
502 M_MOV(d, REG_LSL(s1, 16));
503 M_MOV(d, REG_ASR(d, 16));
504 emit_store_dst(jd, iptr, d);
507 case ICMD_I2L: /* ..., value ==> ..., value */
509 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
510 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
511 M_INTMOVE(s1, GET_LOW_REG(d));
512 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
513 emit_store_dst(jd, iptr, d);
516 case ICMD_L2I: /* ..., value ==> ..., value */
518 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
519 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
521 emit_store_dst(jd, iptr, d);
524 case ICMD_INEG: /* ..., value ==> ..., - value */
526 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
527 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
529 emit_store_dst(jd, iptr, d);
532 case ICMD_LNEG: /* ..., value ==> ..., - value */
534 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
535 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
536 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
537 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
538 emit_store_dst(jd, iptr, d);
541 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
543 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
544 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
545 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
547 emit_store_dst(jd, iptr, d);
550 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
552 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
553 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
554 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
555 M_ADD_S(GET_LOW_REG(d), s1, s2);
556 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
557 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
558 M_ADC(GET_HIGH_REG(d), s1, s2);
559 emit_store_dst(jd, iptr, d);
565 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
566 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
568 if (IS_IMM(iptr->sx.val.i)) {
569 M_ADD_IMM(d, s1, iptr->sx.val.i);
570 } else if (IS_IMM(-iptr->sx.val.i)) {
571 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
573 ICONST(REG_ITMP3, iptr->sx.val.i);
574 M_ADD(d, s1, REG_ITMP3);
577 emit_store_dst(jd, iptr, d);
580 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
581 /* sx.val.l = constant */
583 s3 = iptr->sx.val.l & 0xffffffff;
584 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
585 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
587 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
589 ICONST(REG_ITMP3, s3);
590 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
592 s3 = iptr->sx.val.l >> 32;
593 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
595 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
597 ICONST(REG_ITMP3, s3);
598 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
600 emit_store_dst(jd, iptr, d);
603 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
605 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
606 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
607 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
609 emit_store_dst(jd, iptr, d);
612 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
614 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
615 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
616 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
617 M_SUB_S(GET_LOW_REG(d), s1, s2);
618 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
619 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
620 M_SBC(GET_HIGH_REG(d), s1, s2);
621 emit_store_dst(jd, iptr, d);
624 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
625 /* sx.val.i = constant */
627 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
628 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
629 if (IS_IMM(iptr->sx.val.i))
630 M_SUB_IMM(d, s1, iptr->sx.val.i);
632 ICONST(REG_ITMP3, iptr->sx.val.i);
633 M_SUB(d, s1, REG_ITMP3);
635 emit_store_dst(jd, iptr, d);
638 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
639 /* sx.val.l = constant */
641 s3 = iptr->sx.val.l & 0xffffffff;
642 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
643 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
645 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
647 ICONST(REG_ITMP3, s3);
648 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
650 s3 = iptr->sx.val.l >> 32;
651 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
653 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
655 ICONST(REG_ITMP3, s3);
656 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
658 emit_store_dst(jd, iptr, d);
661 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
663 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
664 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
665 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
667 emit_store_dst(jd, iptr, d);
670 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
671 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
673 s1 = emit_load_s1(jd, iptr, REG_A0);
674 s2 = emit_load_s2(jd, iptr, REG_A1);
675 emit_arithmetic_check(cd, iptr, s2);
677 /* move arguments into argument registers */
678 M_INTMOVE(s1, REG_A0);
679 M_INTMOVE(s2, REG_A1);
681 /* call builtin function */
682 bte = iptr->sx.s23.s3.bte;
683 disp = dseg_add_functionptr(cd, bte->fp);
687 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
690 /* move result into destination register */
691 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
692 M_INTMOVE(REG_RESULT, d);
693 emit_store_dst(jd, iptr, d);
696 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
697 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
699 /* move arguments into argument registers */
701 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
702 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
703 /* XXX TODO: only do this if arithmetic check is really done! */
704 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
705 emit_arithmetic_check(cd, iptr, REG_ITMP3);
707 M_LNGMOVE(s1, REG_A0_A1_PACKED);
708 M_LNGMOVE(s2, REG_A2_A3_PACKED);
710 /* call builtin function */
711 bte = iptr->sx.s23.s3.bte;
712 disp = dseg_add_functionptr(cd, bte->fp);
716 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
719 /* move result into destination register */
720 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
721 M_LNGMOVE(REG_RESULT_PACKED, d);
722 emit_store_dst(jd, iptr, d);
725 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
726 /* sx.val.i = constant */
728 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
729 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
730 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
731 emit_store_dst(jd, iptr, d);
734 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
735 /* sx.val.i = constant */
737 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
738 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
739 /* this rounds towards 0 as java likes it */
740 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
741 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
742 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
743 /* this rounds towards nearest, not java style */
744 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
745 M_ADCMI_IMM(d, d, 0);*/
746 emit_store_dst(jd, iptr, d);
749 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
750 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
752 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
753 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
754 M_MOV_S(REG_ITMP1, s1);
755 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
756 if (IS_IMM(iptr->sx.val.i))
757 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
759 ICONST(REG_ITMP3, iptr->sx.val.i);
760 M_AND(REG_ITMP1, REG_ITMP3, d);
762 M_RSBMI_IMM(d, d, 0);
763 emit_store_dst(jd, iptr, d);
766 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
768 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
769 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
770 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
771 M_AND_IMM(s2, 0x1f, REG_ITMP2);
772 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
773 emit_store_dst(jd, iptr, d);
776 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
778 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
779 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
780 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
781 M_AND_IMM(s2, 0x1f, REG_ITMP2);
782 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
783 emit_store_dst(jd, iptr, d);
786 case ICMD_IUSHR: /* ..., val1, val2 ==> ..., val1 >>> val2 */
788 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
789 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
790 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
791 M_AND_IMM(s2, 0x1f, REG_ITMP2);
792 M_MOV(d, REG_LSR_REG(s1, REG_ITMP2));
793 emit_store_dst(jd, iptr, d);
796 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
797 /* sx.val.i = constant */
799 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
800 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
801 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
802 emit_store_dst(jd, iptr, d);
805 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
806 /* sx.val.i = constant */
808 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
809 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
810 /* we need to check for zero here because arm interprets it as SHR by 32 */
811 if ((iptr->sx.val.i & 0x1f) == 0) {
814 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
816 emit_store_dst(jd, iptr, d);
819 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
820 /* sx.val.i = constant */
822 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
823 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
824 /* we need to check for zero here because arm interprets it as SHR by 32 */
825 if ((iptr->sx.val.i & 0x1f) == 0)
828 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
829 emit_store_dst(jd, iptr, d);
832 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
834 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
835 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
836 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
838 emit_store_dst(jd, iptr, d);
841 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
843 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
844 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
845 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
846 M_AND(s1, s2, GET_LOW_REG(d));
847 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
848 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
849 M_AND(s1, s2, GET_HIGH_REG(d));
850 emit_store_dst(jd, iptr, d);
853 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
855 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
856 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
857 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
859 emit_store_dst(jd, iptr, d);
862 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
864 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
865 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
866 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
867 M_ORR(s1, s2, GET_LOW_REG(d));
868 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
869 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
870 M_ORR(s1, s2, GET_HIGH_REG(d));
871 emit_store_dst(jd, iptr, d);
874 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
876 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
877 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
878 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
880 emit_store_dst(jd, iptr, d);
883 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
885 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
886 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
887 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
888 M_EOR(s1, s2, GET_LOW_REG(d));
889 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
890 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
891 M_EOR(s1, s2, GET_HIGH_REG(d));
892 emit_store_dst(jd, iptr, d);
896 /* floating operations ************************************************/
898 #if !defined(ENABLE_SOFTFLOAT)
900 case ICMD_FNEG: /* ..., value ==> ..., - value */
902 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
903 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
905 emit_store_dst(jd, iptr, d);
908 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
910 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
911 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
912 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
914 emit_store_dst(jd, iptr, d);
917 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
919 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
920 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
921 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
923 emit_store_dst(jd, iptr, d);
926 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
928 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
929 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
930 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
932 emit_store_dst(jd, iptr, d);
935 case ICMD_FDIV: /* ..., 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 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
947 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
949 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
950 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
951 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
953 emit_store_dst(jd, iptr, d);
957 case ICMD_DNEG: /* ..., value ==> ..., - value */
959 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
960 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
962 emit_store_dst(jd, iptr, d);
965 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
967 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
968 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
969 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
971 emit_store_dst(jd, iptr, d);
974 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
976 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
977 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
978 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
980 emit_store_dst(jd, iptr, d);
983 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
985 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
986 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
987 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
989 emit_store_dst(jd, iptr, d);
992 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
994 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
995 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
996 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
998 emit_store_dst(jd, iptr, d);
1001 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1005 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1007 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1008 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1009 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1011 emit_store_dst(jd, iptr, d);
1015 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1017 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1018 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1020 emit_store_dst(jd, iptr, d);
1023 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1025 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1026 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1028 emit_store_dst(jd, iptr, d);
1031 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1033 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1034 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1035 /* this uses round towards zero, as Java likes it */
1037 #if !defined(__VFP_FP__)
1038 /* this checks for NaN; to return zero as Java likes it */
1042 emit_store_dst(jd, iptr, d);
1045 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1047 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1048 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1049 /* this uses round towards zero, as Java likes it */
1051 #if !defined(__VFP_FP__)
1052 /* this checks for NaN; to return zero as Java likes it */
1056 emit_store_dst(jd, iptr, d);
1059 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1061 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1062 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1064 emit_store_dst(jd, iptr, d);
1067 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1069 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1070 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1072 emit_store_dst(jd, iptr, d);
1075 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1077 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1078 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1079 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1082 #if defined(__VFP_FP__)
1083 M_FMSTAT; /* on VFP we need to transfer the flags */
1085 M_SUBGT_IMM(d, d, 1);
1086 M_ADDLT_IMM(d, d, 1);
1087 emit_store_dst(jd, iptr, d);
1090 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1092 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1093 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1094 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1097 #if defined(__VFP_FP__)
1098 M_FMSTAT; /* on VFP we need to transfer the flags */
1100 M_SUBGT_IMM(d, d, 1);
1101 M_ADDLT_IMM(d, d, 1);
1102 emit_store_dst(jd, iptr, d);
1105 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1107 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1108 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1109 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1112 #if defined(__VFP_FP__)
1113 M_FMSTAT; /* on VFP we need to transfer the flags */
1115 M_SUBLT_IMM(d, d, 1);
1116 M_ADDGT_IMM(d, d, 1);
1117 emit_store_dst(jd, iptr, d);
1120 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1122 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1123 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1124 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1127 #if defined(__VFP_FP__)
1128 M_FMSTAT; /* on VFP we need to transfer the flags */
1130 M_SUBLT_IMM(d, d, 1);
1131 M_ADDGT_IMM(d, d, 1);
1132 emit_store_dst(jd, iptr, d);
1135 #endif /* !defined(ENABLE_SOFTFLOAT) */
1138 /* memory operations **************************************************/
1140 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1142 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1143 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1144 /* implicit null-pointer check */
1145 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1146 emit_store_dst(jd, iptr, d);
1149 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1151 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1152 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1153 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1154 /* implicit null-pointer check */
1155 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1156 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1157 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1158 emit_store_dst(jd, iptr, d);
1161 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1163 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1164 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1165 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1166 /* implicit null-pointer check */
1167 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1168 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1169 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1170 emit_store_dst(jd, iptr, d);
1173 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1175 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1176 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1177 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1178 /* implicit null-pointer check */
1179 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1180 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1181 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1182 emit_store_dst(jd, iptr, d);
1185 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1187 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1188 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1189 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1190 /* implicit null-pointer check */
1191 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1192 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1193 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1194 emit_store_dst(jd, iptr, d);
1197 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1199 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1200 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1201 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1202 /* implicit null-pointer check */
1203 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1204 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1205 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1206 emit_store_dst(jd, iptr, d);
1209 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1211 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1212 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1213 /* implicit null-pointer check */
1214 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1215 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1216 #if !defined(ENABLE_SOFTFLOAT)
1217 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1218 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1220 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1221 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1223 emit_store_dst(jd, iptr, d);
1226 case ICMD_DALOAD: /* ..., 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_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1233 #if !defined(ENABLE_SOFTFLOAT)
1234 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1235 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1237 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1238 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1240 emit_store_dst(jd, iptr, d);
1243 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1245 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1246 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1247 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1248 /* implicit null-pointer check */
1249 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1250 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1251 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1252 emit_store_dst(jd, iptr, d);
1255 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1257 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1258 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1259 /* implicit null-pointer check */
1260 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1261 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1262 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1263 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1266 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1268 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1269 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1270 /* implicit null-pointer check */
1271 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1272 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1273 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1274 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1277 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1279 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1280 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1281 /* implicit null-pointer check */
1282 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1283 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1284 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1285 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1288 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1290 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1291 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1292 /* implicit null-pointer check */
1293 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1294 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1295 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1296 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1299 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1301 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1302 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1303 /* implicit null-pointer check */
1304 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1305 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1306 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1307 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1310 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1312 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1313 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1314 /* implicit null-pointer check */
1315 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1316 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1317 #if !defined(ENABLE_SOFTFLOAT)
1318 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1319 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1321 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1322 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1326 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1328 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1329 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1330 /* implicit null-pointer check */
1331 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1332 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1333 #if !defined(ENABLE_SOFTFLOAT)
1334 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1335 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1337 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1338 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1342 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1344 s1 = emit_load_s1(jd, iptr, REG_A0);
1345 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1346 s3 = emit_load_s3(jd, iptr, REG_A1);
1348 /* implicit null-pointer check */
1349 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1351 /* move arguments to argument registers */
1352 M_INTMOVE(s1, REG_A0);
1353 M_INTMOVE(s3, REG_A1);
1355 /* call builtin function */
1356 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1357 M_DSEG_BRANCH(disp);
1360 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1363 /* check resturn value of builtin */
1364 emit_arraystore_check(cd, iptr);
1366 /* finally store address into array */
1367 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1368 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1369 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1370 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1371 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1374 case ICMD_GETSTATIC: /* ... ==> ..., value */
1376 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1377 uf = iptr->sx.s23.s3.uf;
1378 fieldtype = uf->fieldref->parseddesc.fd->type;
1379 disp = dseg_add_unique_address(cd, NULL);
1381 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1384 fi = iptr->sx.s23.s3.fmiref->p.field;
1385 fieldtype = fi->type;
1386 disp = dseg_add_address(cd, fi->value);
1388 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1389 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1394 M_DSEG_LOAD(REG_ITMP3, disp);
1395 switch (fieldtype) {
1397 #if defined(ENABLE_SOFTFLOAT)
1401 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1402 M_ILD_INTERN(d, REG_ITMP3, 0);
1405 #if defined(ENABLE_SOFTFLOAT)
1408 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1409 M_LLD_INTERN(d, REG_ITMP3, 0);
1411 #if !defined(ENABLE_SOFTFLOAT)
1413 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1414 M_FLD_INTERN(d, REG_ITMP3, 0);
1417 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1418 M_DLD_INTERN(d, REG_ITMP3, 0);
1424 emit_store_dst(jd, iptr, d);
1427 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1429 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1430 uf = iptr->sx.s23.s3.uf;
1431 fieldtype = uf->fieldref->parseddesc.fd->type;
1432 disp = dseg_add_unique_address(cd, NULL);
1434 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1437 fi = iptr->sx.s23.s3.fmiref->p.field;
1438 fieldtype = fi->type;
1439 disp = dseg_add_address(cd, fi->value);
1441 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
1442 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1447 M_DSEG_LOAD(REG_ITMP3, disp);
1448 switch (fieldtype) {
1450 #if defined(ENABLE_SOFTFLOAT)
1454 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1455 M_IST_INTERN(s1, REG_ITMP3, 0);
1458 #if defined(ENABLE_SOFTFLOAT)
1461 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1462 M_LST_INTERN(s1, REG_ITMP3, 0);
1464 #if !defined(ENABLE_SOFTFLOAT)
1466 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1467 M_FST_INTERN(s1, REG_ITMP3, 0);
1470 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1471 M_DST_INTERN(s1, REG_ITMP3, 0);
1479 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1481 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1482 emit_nullpointer_check(cd, iptr, s1);
1485 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1486 uf = iptr->sx.s23.s3.uf;
1487 fieldtype = uf->fieldref->parseddesc.fd->type;
1491 fi = iptr->sx.s23.s3.fmiref->p.field;
1492 fieldtype = fi->type;
1496 #if !defined(ENABLE_SOFTFLOAT)
1497 /* HACK: softnull checks on floats */
1498 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1499 emit_nullpointer_check_force(cd, iptr, s1);
1502 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1504 uf = iptr->sx.s23.s3.uf;
1506 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1509 switch (fieldtype) {
1511 #if defined(ENABLE_SOFTFLOAT)
1515 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1519 #if defined(ENABLE_SOFTFLOAT)
1522 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1525 #if !defined(ENABLE_SOFTFLOAT)
1527 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1531 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1538 emit_store_dst(jd, iptr, d);
1541 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1543 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1544 emit_nullpointer_check(cd, iptr, s1);
1546 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1547 uf = iptr->sx.s23.s3.uf;
1548 fieldtype = uf->fieldref->parseddesc.fd->type;
1552 fi = iptr->sx.s23.s3.fmiref->p.field;
1553 fieldtype = fi->type;
1557 #if !defined(ENABLE_SOFTFLOAT)
1558 /* HACK: softnull checks on floats */
1559 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1560 emit_nullpointer_check_force(cd, iptr, s1);
1563 switch (fieldtype) {
1565 #if defined(ENABLE_SOFTFLOAT)
1569 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1571 #if defined(ENABLE_SOFTFLOAT)
1572 case TYPE_DBL: /* fall through */
1575 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1577 #if !defined(ENABLE_SOFTFLOAT)
1580 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1587 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1589 uf = iptr->sx.s23.s3.uf;
1591 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1594 switch (fieldtype) {
1596 #if defined(ENABLE_SOFTFLOAT)
1600 M_IST(s2, s1, disp);
1603 #if defined(ENABLE_SOFTFLOAT)
1606 M_LST(s2, s1, disp);
1608 #if !defined(ENABLE_SOFTFLOAT)
1610 M_FST(s2, s1, disp);
1613 M_DST(s2, s1, disp);
1622 /* branch operations **************************************************/
1624 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1626 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1627 M_INTMOVE(s1, REG_ITMP1_XPTR);
1628 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1629 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1630 iptr->sx.s23.s2.uc, 0);
1632 disp = dseg_add_functionptr(cd, asm_handle_exception);
1633 M_DSEG_LOAD(REG_ITMP3, disp);
1634 M_MOV(REG_ITMP2_XPC, REG_PC);
1635 M_MOV(REG_PC, REG_ITMP3);
1636 M_NOP; /* nop ensures that XPC is less than the end */
1637 /* of basic block */
1640 case ICMD_GOTO: /* ... ==> ... */
1643 emit_br(cd, iptr->dst.block);
1646 case ICMD_JSR: /* ... ==> ... */
1648 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1651 case ICMD_IFNULL: /* ..., value ==> ... */
1652 case ICMD_IFNONNULL:
1654 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1656 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1659 case ICMD_IFLT: /* ..., value ==> ... */
1660 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1666 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1667 M_COMPARE(s1, iptr->sx.val.i);
1668 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1671 case ICMD_IF_LEQ: /* ..., value ==> ... */
1673 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1674 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1675 if (iptr->sx.val.l == 0) {
1676 M_ORR_S(s1, s2, REG_ITMP3);
1679 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1680 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1681 M_CMP(s1, REG_ITMP3);*/
1682 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1683 M_CMPEQ(s2, REG_ITMP3);
1685 emit_beq(cd, iptr->dst.block);
1688 case ICMD_IF_LLT: /* ..., 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 /* if high word is less than zero, the whole long is too */
1695 emit_blt(cd, iptr->dst.block);
1698 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1699 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1700 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1701 M_CMP(s1, REG_ITMP3);*/
1702 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1703 M_MOVGT_IMM(2, REG_ITMP1);
1704 M_MOVEQ_IMM(1, REG_ITMP1);
1706 /* low compare: x=x-1(ifLO) */
1707 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1708 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1709 M_CMP(s2, REG_ITMP3);*/
1710 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1712 /* branch if (x LT 1) */
1713 M_CMP_IMM(REG_ITMP1, 1);
1714 emit_blt(cd, iptr->dst.block);
1718 case ICMD_IF_LLE: /* ..., value ==> ... */
1720 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1721 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1722 if (iptr->sx.val.l == 0) {
1723 /* if high word is less than zero, the whole long is too */
1725 emit_blt(cd, iptr->dst.block);
1727 /* ... otherwise the low word has to be zero (tricky!) */
1729 emit_beq(cd, iptr->dst.block);
1732 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1733 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1734 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1735 M_CMP(s1, REG_ITMP3);*/
1736 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1737 M_MOVGT_IMM(2, REG_ITMP1);
1738 M_MOVEQ_IMM(1, REG_ITMP1);
1740 /* low compare: x=x+1(ifHI) */
1741 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1742 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1743 M_CMP(s2, REG_ITMP3);*/
1744 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1746 /* branch if (x LE 1) */
1747 M_CMP_IMM(REG_ITMP1, 1);
1748 emit_ble(cd, iptr->dst.block);
1752 case ICMD_IF_LGE: /* ..., value ==> ... */
1754 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1755 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1756 if (iptr->sx.val.l == 0) {
1757 /* if high word is greater or equal zero, the whole long is too */
1759 emit_bge(cd, iptr->dst.block);
1762 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1763 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1764 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1765 M_CMP(s1, REG_ITMP3);*/
1766 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1767 M_MOVGT_IMM(2, REG_ITMP1);
1768 M_MOVEQ_IMM(1, REG_ITMP1);
1770 /* low compare: x=x-1(ifLO) */
1771 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1772 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1773 M_CMP(s2, REG_ITMP3);*/
1774 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1776 /* branch if (x GE 1) */
1777 M_CMP_IMM(REG_ITMP1, 1);
1778 emit_bge(cd, iptr->dst.block);
1782 case ICMD_IF_LGT: /* ..., value ==> ... */
1784 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1785 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1787 if (iptr->sx.val.l == 0) {
1788 /* if high word is greater than zero, the whole long is too */
1791 codegen_add_branch_ref(cd, iptr->dst.block);
1793 /* ... or high was zero and low is non zero (tricky!) */
1794 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1795 M_MOVLT_IMM(1, REG_ITMP3);
1796 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1798 codegen_add_branch_ref(cd, iptr->dst.block);
1802 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1803 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1804 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1805 M_CMP(s1, REG_ITMP3);*/
1806 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1807 M_MOVGT_IMM(2, REG_ITMP1);
1808 M_MOVEQ_IMM(1, REG_ITMP1);
1810 /* low compare: x=x+1(ifHI) */
1811 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1812 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1813 M_CMP(s2, REG_ITMP3);*/
1814 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1816 /* branch if (x GT 1) */
1817 M_CMP_IMM(REG_ITMP1, 1);
1818 emit_bgt(cd, iptr->dst.block);
1824 case ICMD_IF_LNE: /* ..., value ==> ... */
1826 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1827 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1828 if (iptr->sx.val.l == 0) {
1829 M_ORR_S(s1, s2, REG_ITMP3);
1832 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1833 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1834 M_CMP(s1, REG_ITMP3);*/
1835 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1836 M_CMPEQ(s2, REG_ITMP3);
1838 emit_bne(cd, iptr->dst.block);
1841 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1842 case ICMD_IF_ICMPNE:
1843 case ICMD_IF_ICMPLT:
1844 case ICMD_IF_ICMPLE:
1845 case ICMD_IF_ICMPGT:
1846 case ICMD_IF_ICMPGE:
1848 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1849 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1851 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1854 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1855 case ICMD_IF_ACMPNE:
1857 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1858 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1860 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1863 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1864 /* op1 = target JavaVM pc */
1866 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1867 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1870 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1871 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1874 emit_beq(cd, iptr->dst.block);
1877 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1878 /* op1 = target JavaVM pc */
1880 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1881 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1884 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1885 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1888 emit_bne(cd, iptr->dst.block);
1891 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1892 /* op1 = target JavaVM pc */
1894 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1895 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1896 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1898 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1899 M_MOVGT_IMM(2, REG_ITMP3);
1900 M_MOVEQ_IMM(1, REG_ITMP3);
1902 /* low compare: x=x-1(ifLO) */
1903 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1904 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1906 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1908 /* branch if (x LT 1) */
1909 M_CMP_IMM(REG_ITMP3, 1);
1910 emit_blt(cd, iptr->dst.block);
1913 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1914 /* op1 = target JavaVM pc */
1916 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1917 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1918 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1920 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1921 M_MOVGT_IMM(2, REG_ITMP3);
1922 M_MOVEQ_IMM(1, REG_ITMP3);
1924 /* low compare: x=x-1(ifLO) */
1925 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1926 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1928 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1930 /* branch if (x LE 1) */
1931 M_CMP_IMM(REG_ITMP3, 1);
1932 emit_ble(cd, iptr->dst.block);
1935 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1936 /* op1 = target JavaVM pc */
1938 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1939 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1940 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1942 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1943 M_MOVGT_IMM(2, REG_ITMP3);
1944 M_MOVEQ_IMM(1, REG_ITMP3);
1946 /* low compare: x=x-1(ifLO) */
1947 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1948 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1950 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1952 /* branch if (x GT 1) */
1953 M_CMP_IMM(REG_ITMP3, 1);
1954 emit_bgt(cd, iptr->dst.block);
1957 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1958 /* op1 = target JavaVM pc */
1960 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1961 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1962 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1964 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1965 M_MOVGT_IMM(2, REG_ITMP3);
1966 M_MOVEQ_IMM(1, REG_ITMP3);
1968 /* low compare: x=x-1(ifLO) */
1969 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1970 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1972 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1974 /* branch if (x GE 1) */
1975 M_CMP_IMM(REG_ITMP3, 1);
1976 emit_bge(cd, iptr->dst.block);
1979 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1982 branch_target_t *table;
1984 table = iptr->dst.table;
1986 l = iptr->sx.s23.s2.tablelow;
1987 i = iptr->sx.s23.s3.tablehigh;
1989 /* calculate new index (index - low) */
1990 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1992 M_INTMOVE(s1, REG_ITMP1);
1993 } else if (IS_IMM(l)) {
1994 M_SUB_IMM(REG_ITMP1, s1, l);
1996 ICONST(REG_ITMP2, l);
1997 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2000 /* range check (index <= high-low) */
2002 M_COMPARE(REG_ITMP1, i-1);
2003 emit_bugt(cd, table[0].block);
2005 /* build jump table top down and use address of lowest entry */
2010 dseg_add_target(cd, table->block);
2015 /* length of dataseg after last dseg_add_target is used by load */
2016 /* TODO: this loads from data-segment */
2017 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2018 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2021 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2024 lookup_target_t *lookup;
2026 lookup = iptr->dst.lookup;
2028 i = iptr->sx.s23.s2.lookupcount;
2031 MCODECHECK((i<<2)+8);
2032 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2035 M_COMPARE(s1, lookup->value);
2036 emit_beq(cd, lookup->target.block);
2040 /* default branch */
2041 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2045 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2047 #if !defined(ENABLE_SOFTFLOAT)
2048 REPLACEMENT_POINT_RETURN(cd, iptr);
2049 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2050 M_CAST_F2I(s1, REG_RESULT);
2051 goto ICMD_RETURN_do;
2054 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2056 REPLACEMENT_POINT_RETURN(cd, iptr);
2057 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2058 M_INTMOVE(s1, REG_RESULT);
2059 goto ICMD_RETURN_do;
2061 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2063 #if !defined(ENABLE_SOFTFLOAT)
2064 REPLACEMENT_POINT_RETURN(cd, iptr);
2065 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2066 M_CAST_D2L(s1, REG_RESULT_PACKED);
2067 goto ICMD_RETURN_do;
2070 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2072 REPLACEMENT_POINT_RETURN(cd, iptr);
2073 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2074 M_LNGMOVE(s1, REG_RESULT_PACKED);
2075 goto ICMD_RETURN_do;
2077 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2079 REPLACEMENT_POINT_RETURN(cd, iptr);
2080 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2081 M_INTMOVE(s1, REG_RESULT);
2082 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2083 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2084 iptr->sx.s23.s2.uc, 0);
2086 goto ICMD_RETURN_do;
2088 case ICMD_RETURN: /* ... ==> ... */
2090 REPLACEMENT_POINT_RETURN(cd, iptr);
2093 #if !defined(NDEBUG)
2094 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2095 emit_verbosecall_exit(jd);
2098 #if defined(ENABLE_THREADS)
2099 /* call monitorexit function */
2101 if (checksync && code_is_synchronized(code)) {
2102 /* stack offset for monitor argument */
2104 s1 = rd->memuse * 8;
2106 /* we need to save the proper return value */
2108 switch (iptr->opc) {
2112 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2114 M_STMFD(BITMASK_RESULT, REG_SP);
2119 M_LDR(REG_A0, REG_SP, s1);
2120 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2121 M_DSEG_BRANCH(disp);
2123 /* we no longer need PV here, no more loading */
2124 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2125 M_RECOMPUTE_PV(s1);*/
2127 switch (iptr->opc) {
2131 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2133 M_LDMFD(BITMASK_RESULT, REG_SP);
2139 /* deallocate stackframe for spilled variables */
2141 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2142 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2144 /* restore callee saved registers + do return */
2146 if (savedregs_bitmask) {
2147 if (!code_is_leafmethod(code)) {
2148 savedregs_bitmask &= ~(1<<REG_LR);
2149 savedregs_bitmask |= (1<<REG_PC);
2151 M_LDMFD(savedregs_bitmask, REG_SP);
2154 /* if LR was not on stack, we need to return manually */
2156 if (code_is_leafmethod(code))
2157 M_MOV(REG_PC, REG_LR);
2160 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2162 bte = iptr->sx.s23.s3.bte;
2164 goto ICMD_INVOKE_do;
2166 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2167 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2168 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2169 case ICMD_INVOKEINTERFACE:
2171 REPLACEMENT_POINT_INVOKE(cd, iptr);
2173 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2175 um = iptr->sx.s23.s3.um;
2176 md = um->methodref->parseddesc.md;
2179 lm = iptr->sx.s23.s3.fmiref->p.method;
2181 md = lm->parseddesc;
2185 /* copy arguments to registers or stack location */
2187 s3 = md->paramcount;
2189 MCODECHECK((s3 << 1) + 64);
2191 for (s3 = s3 - 1; s3 >= 0; s3--) {
2192 var = VAR(iptr->sx.s23.s2.args[s3]);
2193 d = md->params[s3].regoff;
2195 if (var->flags & PREALLOC) /* argument was precolored? */
2198 /* TODO: document me */
2199 #if !defined(ENABLE_SOFTFLOAT)
2200 if (IS_INT_LNG_TYPE(var->type)) {
2201 #endif /* !defined(ENABLE_SOFTFLOAT) */
2202 if (!md->params[s3].inmemory) {
2203 s1 = emit_load(jd, iptr, var, d);
2205 if (IS_2_WORD_TYPE(var->type))
2211 if (IS_2_WORD_TYPE(var->type)) {
2212 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2213 M_LST(s1, REG_SP, d);
2216 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2217 M_IST(s1, REG_SP, d);
2220 #if !defined(ENABLE_SOFTFLOAT)
2223 if (!md->params[s3].inmemory) {
2224 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2225 if (IS_2_WORD_TYPE(var->type))
2231 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2232 if (IS_2_WORD_TYPE(var->type))
2233 M_DST(s1, REG_SP, d);
2235 M_FST(s1, REG_SP, d);
2238 #endif /* !defined(ENABLE_SOFTFLOAT) */
2241 switch (iptr->opc) {
2244 if (bte->stub == NULL) {
2245 disp = dseg_add_functionptr(cd, bte->fp);
2247 disp = dseg_add_functionptr(cd, bte->stub);
2250 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2252 /* generate the actual call */
2254 M_MOV(REG_LR, REG_PC);
2255 M_MOV(REG_PC, REG_PV);
2256 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2260 case ICMD_INVOKESPECIAL:
2261 emit_nullpointer_check(cd, iptr, REG_A0);
2264 case ICMD_INVOKESTATIC:
2266 disp = dseg_add_unique_address(cd, NULL);
2268 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2272 disp = dseg_add_address(cd, lm->stubroutine);
2274 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2276 /* generate the actual call */
2278 M_MOV(REG_LR, REG_PC);
2279 M_MOV(REG_PC, REG_PV);
2280 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2284 case ICMD_INVOKEVIRTUAL:
2286 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2291 s1 = OFFSET(vftbl_t, table[0]) +
2292 sizeof(methodptr) * lm->vftblindex;
2294 /* implicit null-pointer check */
2295 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2296 OFFSET(java_object_t, vftbl));
2297 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2299 /* generate the actual call */
2301 M_MOV(REG_LR, REG_PC);
2302 M_MOV(REG_PC, REG_PV);
2303 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2307 case ICMD_INVOKEINTERFACE:
2309 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2315 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2316 sizeof(methodptr*) * lm->class->index;
2317 s2 = sizeof(methodptr) * (lm - lm->class->methods);
2320 /* implicit null-pointer check */
2321 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2322 OFFSET(java_object_t, vftbl));
2323 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2324 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2326 /* generate the actual call */
2328 M_MOV(REG_LR, REG_PC);
2329 M_MOV(REG_PC, REG_PV);
2330 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2335 /* store size of call code in replacement point */
2336 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2338 /* store return value */
2340 d = md->returntype.type;
2342 #if !defined(__SOFTFP__)
2343 /* TODO: this is only a hack, since we use R0/R1 for float
2344 return! this depends on gcc; it is independent from
2345 our ENABLE_SOFTFLOAT define */
2346 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2347 #if 0 && !defined(NDEBUG)
2348 dolog("BUILTIN that returns float or double (%s.%s)", m->class->name->text, m->name->text);
2350 /* we cannot use this macro, since it is not defined
2351 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2352 REG_FRESULT, REG_RESULT_TYPED(d)); */
2353 if (IS_2_WORD_TYPE(d)) {
2354 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2355 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2357 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2358 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2363 if (d != TYPE_VOID) {
2364 #if !defined(ENABLE_SOFTFLOAT)
2365 if (IS_INT_LNG_TYPE(d)) {
2366 #endif /* !defined(ENABLE_SOFTFLOAT) */
2367 if (IS_2_WORD_TYPE(d)) {
2368 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2369 M_LNGMOVE(REG_RESULT_PACKED, s1);
2372 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2373 M_INTMOVE(REG_RESULT, s1);
2376 #if !defined(ENABLE_SOFTFLOAT)
2378 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2379 if (IS_2_WORD_TYPE(d))
2380 M_CAST_L2D(REG_RESULT_PACKED, s1);
2382 M_CAST_I2F(REG_RESULT, s1);
2384 #endif /* !defined(ENABLE_SOFTFLOAT) */
2386 emit_store_dst(jd, iptr, s1);
2390 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2392 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2393 /* object type cast-check */
2398 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2403 super = iptr->sx.s23.s3.c.cls;
2404 superindex = super->index;
2407 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2408 CODEGEN_CRITICAL_SECTION_NEW;
2410 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2412 /* if class is not resolved, check which code to call */
2414 if (super == NULL) {
2416 emit_label_beq(cd, BRANCH_LABEL_1);
2418 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2419 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2420 iptr->sx.s23.s3.c.ref, disp);
2422 M_DSEG_LOAD(REG_ITMP2, disp);
2423 disp = dseg_add_s4(cd, ACC_INTERFACE);
2424 M_DSEG_LOAD(REG_ITMP3, disp);
2425 M_TST(REG_ITMP2, REG_ITMP3);
2426 emit_label_beq(cd, BRANCH_LABEL_2);
2429 /* interface checkcast code */
2431 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2432 if ((super == NULL) || !IS_IMM(superindex)) {
2433 disp = dseg_add_unique_s4(cd, superindex);
2435 if (super == NULL) {
2436 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2437 iptr->sx.s23.s3.c.ref, disp);
2441 emit_label_beq(cd, BRANCH_LABEL_3);
2444 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2445 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2447 /* we put unresolved or non-immediate superindices onto dseg */
2448 if ((super == NULL) || !IS_IMM(superindex)) {
2449 /* disp was computed before we added the patcher */
2450 M_DSEG_LOAD(REG_ITMP2, disp);
2451 M_CMP(REG_ITMP3, REG_ITMP2);
2453 assert(IS_IMM(superindex));
2454 M_CMP_IMM(REG_ITMP3, superindex);
2457 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2459 /* if we loaded the superindex out of the dseg above, we do
2460 things differently here! */
2461 if ((super == NULL) || !IS_IMM(superindex)) {
2463 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2465 /* this assumes something */
2466 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2468 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2469 assert(sizeof(methodptr*) == 4);
2470 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2476 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2477 superindex * sizeof(methodptr*);
2481 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2482 M_TST(REG_ITMP3, REG_ITMP3);
2483 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2486 emit_label_br(cd, BRANCH_LABEL_4);
2488 emit_label(cd, BRANCH_LABEL_3);
2491 /* class checkcast code */
2493 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2494 if (super == NULL) {
2495 emit_label(cd, BRANCH_LABEL_2);
2497 disp = dseg_add_unique_address(cd, NULL);
2499 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2500 iptr->sx.s23.s3.c.ref,
2504 disp = dseg_add_address(cd, super->vftbl);
2507 emit_label_beq(cd, BRANCH_LABEL_5);
2510 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2511 M_DSEG_LOAD(REG_ITMP3, disp);
2513 CODEGEN_CRITICAL_SECTION_START;
2515 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2516 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2517 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2518 M_DSEG_LOAD(REG_ITMP3, disp);
2519 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2521 CODEGEN_CRITICAL_SECTION_END;
2523 M_CMP(REG_ITMP2, REG_ITMP3);
2524 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2527 emit_label(cd, BRANCH_LABEL_5);
2530 if (super == NULL) {
2531 emit_label(cd, BRANCH_LABEL_1);
2532 emit_label(cd, BRANCH_LABEL_4);
2535 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2538 /* array type cast-check */
2540 s1 = emit_load_s1(jd, iptr, REG_A0);
2541 M_INTMOVE(s1, REG_A0);
2543 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2544 disp = dseg_add_unique_address(cd, NULL);
2546 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2547 iptr->sx.s23.s3.c.ref,
2551 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2553 M_DSEG_LOAD(REG_A1, disp);
2554 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2555 M_DSEG_BRANCH(disp);
2558 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2559 M_RECOMPUTE_PV(disp);
2561 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2562 M_TST(REG_RESULT, REG_RESULT);
2563 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2565 d = codegen_reg_of_dst(jd, iptr, s1);
2569 emit_store_dst(jd, iptr, d);
2572 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2578 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2583 super = iptr->sx.s23.s3.c.cls;
2584 superindex = super->index;
2587 if ((super == NULL) || !(super->flags & ACC_INTERFACE))
2588 CODEGEN_CRITICAL_SECTION_NEW;
2590 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2591 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2594 M_MOV(REG_ITMP1, s1);
2598 /* if class is not resolved, check which code to call */
2600 if (super == NULL) {
2604 emit_label_beq(cd, BRANCH_LABEL_1);
2606 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2607 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2608 iptr->sx.s23.s3.c.ref, disp);
2610 M_DSEG_LOAD(REG_ITMP2, disp);
2611 disp = dseg_add_s4(cd, ACC_INTERFACE);
2612 M_DSEG_LOAD(REG_ITMP3, disp);
2613 M_TST(REG_ITMP2, REG_ITMP3);
2614 emit_label_beq(cd, BRANCH_LABEL_2);
2617 /* interface checkcast code */
2619 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2620 if ((super == NULL) || !IS_IMM(superindex)) {
2621 disp = dseg_add_unique_s4(cd, superindex);
2623 if (super == NULL) {
2624 /* If d == REG_ITMP2, then it's destroyed in check
2629 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2630 iptr->sx.s23.s3.c.ref, disp);
2635 emit_label_beq(cd, BRANCH_LABEL_3);
2638 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2639 M_LDR_INTERN(REG_ITMP3,
2640 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2642 /* we put unresolved or non-immediate superindices onto dseg
2643 and do things slightly different */
2644 if ((super == NULL) || !IS_IMM(superindex)) {
2645 /* disp was computed before we added the patcher */
2646 M_DSEG_LOAD(REG_ITMP2, disp);
2647 M_CMP(REG_ITMP3, REG_ITMP2);
2649 if (d == REG_ITMP2) {
2656 /* this assumes something */
2657 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2659 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2660 assert(sizeof(methodptr*) == 4);
2661 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2663 if (d == REG_ITMP2) {
2670 assert(IS_IMM(superindex));
2671 M_CMP_IMM(REG_ITMP3, superindex);
2675 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2676 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 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2699 iptr->sx.s23.s3.c.ref, disp);
2702 disp = dseg_add_address(cd, super->vftbl);
2706 emit_label_beq(cd, BRANCH_LABEL_5);
2709 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2710 M_DSEG_LOAD(REG_ITMP2, disp);
2712 CODEGEN_CRITICAL_SECTION_START;
2714 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2715 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2716 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2718 CODEGEN_CRITICAL_SECTION_END;
2720 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2721 M_CMP(REG_ITMP1, REG_ITMP2);
2722 /* If d == REG_ITMP2, then it's destroyed */
2728 emit_label(cd, BRANCH_LABEL_5);
2731 if (super == NULL) {
2732 emit_label(cd, BRANCH_LABEL_1);
2733 emit_label(cd, BRANCH_LABEL_4);
2738 emit_store_dst(jd, iptr, d);
2741 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2743 /* copy sizes to stack if necessary */
2745 MCODECHECK((iptr->s1.argcount << 1) + 64);
2747 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2749 var = VAR(iptr->sx.s23.s2.args[s1]);
2751 /* copy SAVEDVAR sizes to stack */
2753 if (!(var->flags & PREALLOC)) {
2754 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2755 M_STR(s2, REG_SP, s1 * 4);
2759 /* a0 = dimension count */
2761 assert(IS_IMM(iptr->s1.argcount));
2762 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2764 /* is patcher function set? */
2766 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2767 disp = dseg_add_unique_address(cd, NULL);
2769 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2770 iptr->sx.s23.s3.c.ref, disp);
2773 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2775 /* a1 = arraydescriptor */
2777 M_DSEG_LOAD(REG_A1, disp);
2779 /* a2 = pointer to dimensions = stack pointer */
2781 M_INTMOVE(REG_SP, REG_A2);
2783 /* call builtin_multianewarray here */
2785 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2786 M_DSEG_BRANCH(disp);
2790 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2793 /* check for exception before result assignment */
2795 emit_exception_check(cd, iptr);
2799 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2800 M_INTMOVE(REG_RESULT, d);
2801 emit_store_dst(jd, iptr, d);
2804 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2806 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2807 emit_nullpointer_check(cd, iptr, s1);
2811 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2814 } /* the big switch */
2816 } /* for all instructions */
2818 } /* for all basic blocks */
2820 /* generate traps */
2822 emit_patcher_traps(jd);
2824 /* everything's ok */
2830 /* codegen_emit_stub_compiler **************************************************
2832 Emits a stub routine which calls the compiler.
2834 *******************************************************************************/
2836 void codegen_emit_stub_compiler(jitdata *jd)
2841 /* get required compiler data */
2846 /* code for the stub */
2848 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2849 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2853 /* codegen_emit_stub_native ****************************************************
2855 Emits a stub routine which calls a native method.
2857 *******************************************************************************/
2859 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2870 /* get required compiler data */
2876 /* initialize variables */
2880 /* calculate stackframe size */
2882 cd->stackframesize =
2883 4 + /* return address */
2884 sizeof(stackframeinfo_t) + /* stackframeinfo */
2885 sizeof(localref_table) + /* localref_table */
2886 nmd->memuse * 4; /* stack arguments */
2888 /* align stack to 8-byte */
2890 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2892 /* create method header */
2894 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2895 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2896 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2897 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2898 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2900 /* generate stub code */
2902 M_STMFD(1<<REG_LR, REG_SP);
2903 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2905 #if !defined(NDEBUG)
2906 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2907 emit_verbosecall_enter(jd);
2910 #if defined(ENABLE_GC_CACAO)
2911 /* Save callee saved integer registers in stackframeinfo (GC may
2912 need to recover them during a collection). */
2914 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2915 OFFSET(stackframeinfo_t, intregs);
2917 for (i = 0; i < INT_SAV_CNT; i++)
2918 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2921 /* Save integer and float argument registers (these are 4
2922 registers, stack is 8-byte aligned). */
2924 M_STMFD(BITMASK_ARGS, REG_SP);
2925 /* TODO: floating point */
2927 /* create native stackframe info */
2929 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2930 M_MOV(REG_A1, REG_PV);
2931 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2932 M_DSEG_BRANCH(disp);
2936 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2939 /* remember class argument */
2941 if (m->flags & ACC_STATIC)
2942 M_MOV(REG_ITMP3, REG_RESULT);
2944 /* Restore integer and float argument registers (these are 4
2945 registers, stack is 8-byte aligned). */
2947 M_LDMFD(BITMASK_ARGS, REG_SP);
2948 /* TODO: floating point */
2950 /* copy or spill arguments to new locations */
2951 /* ATTENTION: the ARM has only integer argument registers! */
2953 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2954 t = md->paramtypes[i].type;
2956 if (!md->params[i].inmemory) {
2957 s1 = md->params[i].regoff;
2958 s2 = nmd->params[j].regoff;
2960 if (!nmd->params[j].inmemory) {
2961 #if !defined(__ARM_EABI__)
2962 SPLIT_OPEN(t, s2, REG_ITMP1);
2965 if (IS_2_WORD_TYPE(t))
2970 #if !defined(__ARM_EABI__)
2971 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2975 if (IS_2_WORD_TYPE(t))
2976 M_LST(s1, REG_SP, s2);
2978 M_IST(s1, REG_SP, s2);
2982 s1 = md->params[i].regoff + cd->stackframesize;
2983 s2 = nmd->params[j].regoff;
2985 if (IS_2_WORD_TYPE(t)) {
2986 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2987 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2990 M_ILD(REG_ITMP1, REG_SP, s1);
2991 M_IST(REG_ITMP1, REG_SP, s2);
2996 /* Handle native Java methods. */
2998 if (m->flags & ACC_NATIVE) {
2999 /* put class into second argument register */
3001 if (m->flags & ACC_STATIC)
3002 M_MOV(REG_A1, REG_ITMP3);
3004 /* put env into first argument register */
3006 disp = dseg_add_address(cd, _Jv_env);
3007 M_DSEG_LOAD(REG_A0, disp);
3010 /* Call the native function. */
3012 disp = dseg_add_functionptr(cd, f);
3013 M_DSEG_BRANCH(disp);
3016 /* TODO: this is only needed because of the tracer ... do we
3019 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3022 #if !defined(__SOFTFP__)
3023 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3024 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3025 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3026 #if 0 && !defined(NDEBUG)
3027 dolog("NATIVESTUB that returns float or double (%s.%s)", m->class->name->text, m->name->text);
3029 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3030 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3031 if (IS_2_WORD_TYPE(md->returntype.type)) {
3032 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3033 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3035 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3036 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3041 #if !defined(NDEBUG)
3042 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3043 emit_verbosecall_exit(jd);
3046 /* remove native stackframe info */
3047 /* TODO: improve this store/load */
3049 M_STMFD(BITMASK_RESULT, REG_SP);
3051 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3052 M_MOV(REG_A1, REG_PV);
3053 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3054 M_DSEG_BRANCH(disp);
3055 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3058 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3059 M_LDMFD(BITMASK_RESULT, REG_SP);
3061 #if defined(ENABLE_GC_CACAO)
3062 /* restore callee saved int registers from stackframeinfo (GC might have */
3063 /* modified them during a collection). */
3065 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3066 OFFSET(stackframeinfo_t, intregs);
3068 for (i = 0; i < INT_SAV_CNT; i++)
3069 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3072 /* finish stub code, but do not yet return to caller */
3074 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3075 M_LDMFD(1<<REG_LR, REG_SP);
3077 /* check for exception */
3079 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3080 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3082 /* handle exception here */
3084 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3086 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3087 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3088 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3092 /* asm_debug *******************************************************************
3096 *******************************************************************************/
3098 void asm_debug(int a1, int a2, int a3, int a4)
3100 printf("===> i am going to exit after this debugging message!\n");
3101 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3102 vm_abort("leave you now");
3107 * These are local overrides for various environment variables in Emacs.
3108 * Please do not remove this and leave it at the end of the file, where
3109 * Emacs will automagically detect them.
3110 * ---------------------------------------------------------------------
3113 * indent-tabs-mode: t
3117 * vim:noexpandtab:sw=4:ts=4: