1 /* src/vm/jit/arm/codegen.c - machine code generator for Arm
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "vm/jit/arm/arch.h"
36 #include "vm/jit/arm/codegen.h"
38 #include "mm/memory.hpp"
40 #include "native/localref.hpp"
41 #include "native/native.hpp"
43 #include "threads/lock.hpp"
45 #include "vm/jit/builtin.hpp"
46 #include "vm/exceptions.hpp"
47 #include "vm/global.h"
48 #include "vm/loader.hpp"
49 #include "vm/options.h"
52 #include "vm/jit/abi.h"
53 #include "vm/jit/asmpart.h"
54 #include "vm/jit/codegen-common.hpp"
55 #include "vm/jit/dseg.h"
56 #include "vm/jit/emit-common.hpp"
57 #include "vm/jit/jit.hpp"
58 #include "vm/jit/linenumbertable.hpp"
59 #include "vm/jit/methodheader.h"
60 #include "vm/jit/parse.hpp"
61 #include "vm/jit/patcher-common.hpp"
62 #include "vm/jit/reg.h"
64 #if defined(ENABLE_LSRA)
65 #include "vm/jit/allocator/lsra.h"
69 /* codegen_emit ****************************************************************
71 Generates machine code.
73 *******************************************************************************/
75 bool codegen_emit(jitdata *jd)
93 methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
94 unresolved_method *um;
95 builtintable_entry *bte;
102 /* get required compiler data */
109 /* prevent compiler warnings */
117 /* space to save used callee saved registers */
119 savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the LR */
121 savedregs_num += (INT_SAV_CNT - rd->savintreguse);
122 /*savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);*/
123 assert((FLT_SAV_CNT - rd->savfltreguse) == 0);
125 spilledregs_num = rd->memuse;
127 #if defined(ENABLE_THREADS) /* space to save argument of monitor_enter */
128 if (checksync && code_is_synchronized(code))
132 cd->stackframesize = spilledregs_num * 8 + savedregs_num * 4;
134 /* XXX QUICK FIX: We shouldn't align the stack in Java code, but
135 only in native stubs. */
136 /* align stack to 8-byte */
138 cd->stackframesize = (cd->stackframesize + 4) & ~4;
140 /* SECTION: Method Header */
141 /* create method header */
143 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
144 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
146 code->synchronizedoffset = rd->memuse * 8;
148 /* REMOVEME: We still need it for exception handling in assembler. */
150 if (code_is_leafmethod(code))
151 (void) dseg_add_unique_s4(cd, 1);
153 (void) dseg_add_unique_s4(cd, 0);
155 (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
156 (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
158 /* save return address and used callee saved registers */
160 savedregs_bitmask = 0;
162 if (!code_is_leafmethod(code))
163 savedregs_bitmask = (1<<REG_LR);
165 for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--)
166 savedregs_bitmask |= (1<<(rd->savintregs[i]));
169 for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
170 log_text("!!! CODEGEN: floating-point callee saved registers are not saved to stack (SEVERE! STACK IS MESSED UP!)");
171 /* TODO: floating-point */
175 if (savedregs_bitmask)
176 M_STMFD(savedregs_bitmask, REG_SP);
178 /* create additional stack frame for spilled variables (if necessary) */
180 if ((cd->stackframesize / 4 - savedregs_num) > 0)
181 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
183 /* take arguments out of register or stack frame */
186 for (i = 0, len = 0; i < md->paramcount; i++) {
187 s1 = md->params[i].regoff;
188 t = md->paramtypes[i].type;
190 varindex = jd->local_map[len * 5 + t];
192 len += (IS_2_WORD_TYPE(t)) ? 2 : 1; /* 2 word type arguments */
194 if (varindex == UNUSED)
199 /* ATTENTION: we use interger registers for all arguments (even float) */
200 #if !defined(ENABLE_SOFTFLOAT)
201 if (IS_INT_LNG_TYPE(t)) {
203 if (!md->params[i].inmemory) {
204 if (!(var->flags & INMEMORY)) {
205 if (IS_2_WORD_TYPE(t))
206 M_LNGMOVE(s1, var->vv.regoff);
208 M_INTMOVE(s1, var->vv.regoff);
211 if (IS_2_WORD_TYPE(t))
212 M_LST(s1, REG_SP, var->vv.regoff);
214 M_IST(s1, REG_SP, var->vv.regoff);
217 else { /* stack arguments */
218 if (!(var->flags & INMEMORY)) { /* stack arg -> register */
219 if (IS_2_WORD_TYPE(t))
220 M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
222 M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
224 else { /* stack arg -> spilled */
225 /* Reuse Memory Position on Caller Stack */
226 var->vv.regoff = cd->stackframesize + s1;
229 #if !defined(ENABLE_SOFTFLOAT)
232 if (!md->params[i].inmemory) {
233 if (!(var->flags & INMEMORY)) {
234 if (IS_2_WORD_TYPE(t))
235 M_CAST_L2D(s1, var->vv.regoff);
237 M_CAST_I2F(s1, var->vv.regoff);
240 if (IS_2_WORD_TYPE(t))
241 M_LST(s1, REG_SP, var->vv.regoff);
243 M_IST(s1, REG_SP, var->vv.regoff);
247 if (!(var->flags & INMEMORY)) {
248 if (IS_2_WORD_TYPE(t))
249 M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
251 M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1);
254 /* Reuse Memory Position on Caller Stack */
255 var->vv.regoff = cd->stackframesize + s1;
259 #endif /* !defined(ENABLE_SOFTFLOAT) */
262 #if defined(ENABLE_THREADS)
263 /* call monitorenter function */
265 if (checksync && code_is_synchronized(code)) {
266 /* stack offset for monitor argument */
270 # if !defined(NDEBUG)
271 if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
272 M_STMFD(BITMASK_ARGS, REG_SP);
277 /* get the correct lock object */
279 if (m->flags & ACC_STATIC) {
280 disp = dseg_add_address(cd, &m->clazz->object.header);
281 M_DSEG_LOAD(REG_A0, disp);
284 emit_nullpointer_check_force(cd, iptr, REG_A0);
287 M_STR(REG_A0, REG_SP, s1);
288 disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
290 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
293 # if !defined(NDEBUG)
294 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
295 M_LDMFD(BITMASK_ARGS, REG_SP);
301 /* call trace function */
303 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
304 emit_verbosecall_enter(jd);
307 /* end of header generation */
309 /* create replacement points */
310 REPLACEMENT_POINTS_INIT(cd, jd);
312 /* SECTION: ICMD Code Generation */
313 /* for all basic blocks */
315 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
317 bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
319 /* is this basic block reached? */
321 if (bptr->flags < BBREACHED)
324 /* branch resolving */
326 codegen_resolve_branchrefs(cd, bptr);
328 /* handle replacement points */
329 REPLACEMENT_POINT_BLOCK_START(cd, bptr);
331 /* copy interface registers to their destination */
337 #if defined(ENABLE_LSRA)
341 var = VAR(bptr->invars[len]);
342 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
343 if (!(var->flags & INMEMORY))
347 M_INTMOVE(REG_ITMP1, d);
348 emit_store(jd, NULL, var, d);
355 var = VAR(bptr->invars[len]);
357 if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
358 d = codegen_reg_of_var(0, var, REG_ITMP1);
359 M_INTMOVE(REG_ITMP1, d);
360 emit_store(jd, NULL, var, d);
363 assert((var->flags & INOUT));
366 #if defined(ENABLE_LSRA)
370 /* for all instructions */
373 for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
375 /* add line number */
376 if (iptr->line != currentline) {
377 linenumbertable_list_entry_add(cd, iptr->line);
378 currentline = iptr->line;
381 MCODECHECK(64); /* an instruction usually needs < 64 words */
386 case ICMD_NOP: /* ... ==> ... */
387 case ICMD_POP: /* ..., value ==> ... */
388 case ICMD_POP2: /* ..., value, value ==> ... */
391 /* constant operations ************************************************/
393 case ICMD_ICONST: /* ... ==> ..., constant */
395 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
396 ICONST(d, iptr->sx.val.i);
397 emit_store_dst(jd, iptr, d);
400 case ICMD_ACONST: /* ... ==> ..., constant */
402 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
403 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
404 disp = dseg_add_unique_address(cd, NULL);
406 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
407 iptr->sx.val.c.ref, disp);
409 M_DSEG_LOAD(d, disp);
412 ICONST(d, (u4) iptr->sx.val.anyptr);
414 emit_store_dst(jd, iptr, d);
417 case ICMD_LCONST: /* ... ==> ..., constant */
419 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
420 LCONST(d, iptr->sx.val.l);
421 emit_store_dst(jd, iptr, d);
424 case ICMD_FCONST: /* ... ==> ..., constant */
426 #if defined(ENABLE_SOFTFLOAT)
427 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
428 ICONST(d, iptr->sx.val.i);
429 emit_store_dst(jd, iptr, d);
431 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
432 FCONST(d, iptr->sx.val.f);
433 emit_store_dst(jd, iptr, d);
437 case ICMD_DCONST: /* ... ==> ..., constant */
439 #if defined(ENABLE_SOFTFLOAT)
440 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
441 LCONST(d, iptr->sx.val.l);
442 emit_store_dst(jd, iptr, d);
444 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
445 DCONST(d, iptr->sx.val.d);
446 emit_store_dst(jd, iptr, d);
451 /* load/store/copy/move operations ************************************/
453 case ICMD_ILOAD: /* ... ==> ..., content of local variable */
454 case ICMD_ALOAD: /* op1 = local variable */
458 case ICMD_ISTORE: /* ..., value ==> ... */
470 if (!(iptr->flags.bits & INS_FLAG_RETADDR))
475 /* integer operations *************************************************/
477 case ICMD_INT2BYTE: /* ..., value ==> ..., value */
479 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
480 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
481 M_MOV(d, REG_LSL(s1, 24));
482 M_MOV(d, REG_ASR(d, 24));
483 emit_store_dst(jd, iptr, d);
486 case ICMD_INT2CHAR: /* ..., value ==> ..., value */
488 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
489 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
490 M_MOV(d, REG_LSL(s1, 16));
491 M_MOV(d, REG_LSR(d, 16)); /* ATTENTION: char is unsigned */
492 emit_store_dst(jd, iptr, d);
495 case ICMD_INT2SHORT: /* ..., value ==> ..., value */
497 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
498 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
499 M_MOV(d, REG_LSL(s1, 16));
500 M_MOV(d, REG_ASR(d, 16));
501 emit_store_dst(jd, iptr, d);
504 case ICMD_I2L: /* ..., value ==> ..., value */
506 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
507 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
508 M_INTMOVE(s1, GET_LOW_REG(d));
509 M_MOV(GET_HIGH_REG(d), REG_ASR(s1, 31));
510 emit_store_dst(jd, iptr, d);
513 case ICMD_L2I: /* ..., value ==> ..., value */
515 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
516 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
518 emit_store_dst(jd, iptr, d);
521 case ICMD_INEG: /* ..., value ==> ..., - value */
523 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
524 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
526 emit_store_dst(jd, iptr, d);
529 case ICMD_LNEG: /* ..., value ==> ..., - value */
531 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
532 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
533 M_RSB_IMMS(GET_LOW_REG(d), GET_LOW_REG(s1), 0);
534 M_RSC_IMM(GET_HIGH_REG(d), GET_HIGH_REG(s1), 0);
535 emit_store_dst(jd, iptr, d);
538 case ICMD_IADD: /* ..., val1, val2 ==> ..., val1 + val2 */
540 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
541 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
542 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
544 emit_store_dst(jd, iptr, d);
547 case ICMD_LADD: /* ..., val1, val2 ==> ..., val1 + val2 */
549 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
550 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
551 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
552 M_ADD_S(GET_LOW_REG(d), s1, s2);
553 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
554 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
555 M_ADC(GET_HIGH_REG(d), s1, s2);
556 emit_store_dst(jd, iptr, d);
562 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
563 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
565 if (IS_IMM(iptr->sx.val.i)) {
566 M_ADD_IMM(d, s1, iptr->sx.val.i);
567 } else if (IS_IMM(-iptr->sx.val.i)) {
568 M_SUB_IMM(d, s1, (-iptr->sx.val.i));
570 ICONST(REG_ITMP3, iptr->sx.val.i);
571 M_ADD(d, s1, REG_ITMP3);
574 emit_store_dst(jd, iptr, d);
577 case ICMD_LADDCONST: /* ..., value ==> ..., value + constant */
578 /* sx.val.l = constant */
580 s3 = iptr->sx.val.l & 0xffffffff;
581 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
582 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
584 M_ADD_IMMS(GET_LOW_REG(d), s1, s3);
586 ICONST(REG_ITMP3, s3);
587 M_ADD_S(GET_LOW_REG(d), s1, REG_ITMP3);
589 s3 = iptr->sx.val.l >> 32;
590 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
592 M_ADC_IMM(GET_HIGH_REG(d), s1, s3);
594 ICONST(REG_ITMP3, s3);
595 M_ADC(GET_HIGH_REG(d), s1, REG_ITMP3);
597 emit_store_dst(jd, iptr, d);
600 case ICMD_ISUB: /* ..., val1, val2 ==> ..., val1 - val2 */
602 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
603 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
604 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
606 emit_store_dst(jd, iptr, d);
609 case ICMD_LSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
611 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
612 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
613 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
614 M_SUB_S(GET_LOW_REG(d), s1, s2);
615 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
616 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
617 M_SBC(GET_HIGH_REG(d), s1, s2);
618 emit_store_dst(jd, iptr, d);
621 case ICMD_ISUBCONST: /* ..., value ==> ..., value + constant */
622 /* sx.val.i = constant */
624 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
625 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
626 if (IS_IMM(iptr->sx.val.i))
627 M_SUB_IMM(d, s1, iptr->sx.val.i);
629 ICONST(REG_ITMP3, iptr->sx.val.i);
630 M_SUB(d, s1, REG_ITMP3);
632 emit_store_dst(jd, iptr, d);
635 case ICMD_LSUBCONST: /* ..., value ==> ..., value - constant */
636 /* sx.val.l = constant */
638 s3 = iptr->sx.val.l & 0xffffffff;
639 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
640 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
642 M_SUB_IMMS(GET_LOW_REG(d), s1, s3);
644 ICONST(REG_ITMP3, s3);
645 M_SUB_S(GET_LOW_REG(d), s1, REG_ITMP3);
647 s3 = iptr->sx.val.l >> 32;
648 s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
650 M_SBC_IMM(GET_HIGH_REG(d), s1, s3);
652 ICONST(REG_ITMP3, s3);
653 M_SBC(GET_HIGH_REG(d), s1, REG_ITMP3);
655 emit_store_dst(jd, iptr, d);
658 case ICMD_IMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
660 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
661 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
662 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
664 emit_store_dst(jd, iptr, d);
667 case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
668 case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
670 s1 = emit_load_s1(jd, iptr, REG_A0);
671 s2 = emit_load_s2(jd, iptr, REG_A1);
672 emit_arithmetic_check(cd, iptr, s2);
674 /* move arguments into argument registers */
675 M_INTMOVE(s1, REG_A0);
676 M_INTMOVE(s2, REG_A1);
678 /* call builtin function */
679 bte = iptr->sx.s23.s3.bte;
680 disp = dseg_add_functionptr(cd, bte->fp);
684 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
687 /* move result into destination register */
688 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
689 M_INTMOVE(REG_RESULT, d);
690 emit_store_dst(jd, iptr, d);
693 case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
694 case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
696 /* move arguments into argument registers */
698 s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
699 s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
700 /* XXX TODO: only do this if arithmetic check is really done! */
701 M_ORR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
702 emit_arithmetic_check(cd, iptr, REG_ITMP3);
704 M_LNGMOVE(s1, REG_A0_A1_PACKED);
705 M_LNGMOVE(s2, REG_A2_A3_PACKED);
707 /* call builtin function */
708 bte = iptr->sx.s23.s3.bte;
709 disp = dseg_add_functionptr(cd, bte->fp);
713 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
716 /* move result into destination register */
717 d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
718 M_LNGMOVE(REG_RESULT_PACKED, d);
719 emit_store_dst(jd, iptr, d);
722 case ICMD_IMULPOW2: /* ..., value ==> ..., value * (2 ^ constant) */
723 /* sx.val.i = constant */
725 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
726 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
727 M_MOV(d, REG_LSL(s1, iptr->sx.val.i));
728 emit_store_dst(jd, iptr, d);
731 case ICMD_IDIVPOW2: /* ..., value ==> ..., value / (2 ^ constant) */
732 /* sx.val.i = constant */
734 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
735 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
736 /* this rounds towards 0 as java likes it */
737 M_MOV(REG_ITMP3, REG_ASR(s1, 31));
738 M_ADD(REG_ITMP3, s1, REG_LSR(REG_ITMP3, 32 - iptr->sx.val.i));
739 M_MOV(d, REG_ASR(REG_ITMP3, iptr->sx.val.i));
740 /* this rounds towards nearest, not java style */
741 /*M_MOV_S(d, REG_ASR(s1, iptr->sx.val.i));
742 M_ADCMI_IMM(d, d, 0);*/
743 emit_store_dst(jd, iptr, d);
746 case ICMD_IREMPOW2: /* ..., value ==> ..., value % constant */
747 /* sx.val.i = constant [ (2 ^ x) - 1 ] */
749 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
750 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
751 M_MOV_S(REG_ITMP1, s1);
752 M_RSBMI_IMM(REG_ITMP1, REG_ITMP1, 0);
753 if (IS_IMM(iptr->sx.val.i))
754 M_AND_IMM(REG_ITMP1, iptr->sx.val.i, d);
756 ICONST(REG_ITMP3, iptr->sx.val.i);
757 M_AND(REG_ITMP1, REG_ITMP3, d);
759 M_RSBMI_IMM(d, d, 0);
760 emit_store_dst(jd, iptr, d);
763 case ICMD_ISHL: /* ..., val1, val2 ==> ..., val1 << val2 */
765 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
766 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
767 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
768 M_AND_IMM(s2, 0x1f, REG_ITMP2);
769 M_MOV(d, REG_LSL_REG(s1, REG_ITMP2));
770 emit_store_dst(jd, iptr, d);
773 case ICMD_ISHR: /* ..., val1, val2 ==> ..., val1 >> val2 */
775 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
776 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
777 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
778 M_AND_IMM(s2, 0x1f, REG_ITMP2);
779 M_MOV(d, REG_ASR_REG(s1, REG_ITMP2));
780 emit_store_dst(jd, iptr, d);
783 case ICMD_IUSHR: /* ..., 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_LSR_REG(s1, REG_ITMP2));
790 emit_store_dst(jd, iptr, d);
793 case ICMD_ISHLCONST: /* ..., value ==> ..., value << constant */
794 /* sx.val.i = constant */
796 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
797 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
798 M_MOV(d, REG_LSL(s1, iptr->sx.val.i & 0x1f));
799 emit_store_dst(jd, iptr, d);
802 case ICMD_ISHRCONST: /* ..., value ==> ..., value >> constant */
803 /* sx.val.i = constant */
805 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
806 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
807 /* we need to check for zero here because arm interprets it as SHR by 32 */
808 if ((iptr->sx.val.i & 0x1f) == 0) {
811 M_MOV(d, REG_ASR(s1, iptr->sx.val.i & 0x1f));
813 emit_store_dst(jd, iptr, d);
816 case ICMD_IUSHRCONST: /* ..., value ==> ..., value >>> constant */
817 /* sx.val.i = constant */
819 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
820 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
821 /* we need to check for zero here because arm interprets it as SHR by 32 */
822 if ((iptr->sx.val.i & 0x1f) == 0)
825 M_MOV(d, REG_LSR(s1, iptr->sx.val.i & 0x1f));
826 emit_store_dst(jd, iptr, d);
829 case ICMD_IAND: /* ..., val1, val2 ==> ..., val1 & val2 */
831 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
832 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
833 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
835 emit_store_dst(jd, iptr, d);
838 case ICMD_LAND: /* ..., val1, val2 ==> ..., val1 & val2 */
840 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
841 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
842 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
843 M_AND(s1, s2, GET_LOW_REG(d));
844 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
845 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
846 M_AND(s1, s2, GET_HIGH_REG(d));
847 emit_store_dst(jd, iptr, d);
850 case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
852 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
853 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
854 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
856 emit_store_dst(jd, iptr, d);
859 case ICMD_LOR: /* ..., val1, val2 ==> ..., val1 | val2 */
861 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
862 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
863 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
864 M_ORR(s1, s2, GET_LOW_REG(d));
865 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
866 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
867 M_ORR(s1, s2, GET_HIGH_REG(d));
868 emit_store_dst(jd, iptr, d);
871 case ICMD_IXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
873 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
874 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
875 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
877 emit_store_dst(jd, iptr, d);
880 case ICMD_LXOR: /* ..., val1, val2 ==> ..., val1 ^ val2 */
882 s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
883 s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
884 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
885 M_EOR(s1, s2, GET_LOW_REG(d));
886 s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
887 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
888 M_EOR(s1, s2, GET_HIGH_REG(d));
889 emit_store_dst(jd, iptr, d);
893 /* floating operations ************************************************/
895 #if !defined(ENABLE_SOFTFLOAT)
897 case ICMD_FNEG: /* ..., value ==> ..., - value */
899 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
900 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
902 emit_store_dst(jd, iptr, d);
905 case ICMD_FADD: /* ..., val1, val2 ==> ..., val1 + val2 */
907 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
908 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
909 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
911 emit_store_dst(jd, iptr, d);
914 case ICMD_FSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
916 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
917 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
918 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
920 emit_store_dst(jd, iptr, d);
923 case ICMD_FMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
925 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
926 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
927 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
929 emit_store_dst(jd, iptr, d);
932 case ICMD_FDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
933 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
934 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
935 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
937 emit_store_dst(jd, iptr, d);
940 /* ATTENTION: Jave does not want IEEE behaviour in FREM, do
944 case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
946 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
947 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
948 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
950 emit_store_dst(jd, iptr, d);
954 case ICMD_DNEG: /* ..., value ==> ..., - value */
956 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
957 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
959 emit_store_dst(jd, iptr, d);
962 case ICMD_DADD: /* ..., val1, val2 ==> ..., val1 + val2 */
964 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
965 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
966 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
968 emit_store_dst(jd, iptr, d);
971 case ICMD_DSUB: /* ..., val1, val2 ==> ..., val1 - val2 */
973 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
974 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
975 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
977 emit_store_dst(jd, iptr, d);
980 case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 * val2 */
982 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
983 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
984 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
986 emit_store_dst(jd, iptr, d);
989 case ICMD_DDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
991 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
992 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
993 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
995 emit_store_dst(jd, iptr, d);
998 /* ATTENTION: Jave does not want IEEE behaviour in DREM, do
1002 case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
1004 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1005 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1006 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1008 emit_store_dst(jd, iptr, d);
1012 case ICMD_I2F: /* ..., value ==> ..., (float) value */
1014 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1015 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1016 #if defined(__VFP_FP__)
1022 emit_store_dst(jd, iptr, d);
1025 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1027 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1028 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1029 #if defined(__VFP_FP__)
1035 emit_store_dst(jd, iptr, d);
1038 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1040 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1041 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1042 #if defined(__VFP_FP__)
1043 M_CVTFI(s1, REG_FTMP2);
1044 M_FMRS(REG_FTMP2, d);
1046 /* this uses round towards zero, as Java likes it */
1048 /* this checks for NaN; to return zero as Java likes it */
1052 emit_store_dst(jd, iptr, d);
1055 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1057 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1058 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1059 #if defined(__VFP_FP__)
1060 M_CVTDI(s1, REG_FTMP2);
1061 M_FMRS(REG_FTMP2, d);
1063 /* this uses round towards zero, as Java likes it */
1065 /* this checks for NaN; to return zero as Java likes it */
1069 emit_store_dst(jd, iptr, d);
1072 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1074 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1075 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1077 emit_store_dst(jd, iptr, d);
1080 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1082 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1083 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1085 emit_store_dst(jd, iptr, d);
1088 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1090 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1091 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1092 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1095 #if defined(__VFP_FP__)
1096 M_FMSTAT; /* on VFP we need to transfer the flags */
1098 M_SUBGT_IMM(d, d, 1);
1099 M_ADDLT_IMM(d, d, 1);
1100 emit_store_dst(jd, iptr, d);
1103 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1105 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1106 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1107 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1110 #if defined(__VFP_FP__)
1111 M_FMSTAT; /* on VFP we need to transfer the flags */
1113 M_SUBGT_IMM(d, d, 1);
1114 M_ADDLT_IMM(d, d, 1);
1115 emit_store_dst(jd, iptr, d);
1118 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1120 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1121 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1122 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1125 #if defined(__VFP_FP__)
1126 M_FMSTAT; /* on VFP we need to transfer the flags */
1128 M_SUBLT_IMM(d, d, 1);
1129 M_ADDGT_IMM(d, d, 1);
1130 emit_store_dst(jd, iptr, d);
1133 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1135 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1136 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1137 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1140 #if defined(__VFP_FP__)
1141 M_FMSTAT; /* on VFP we need to transfer the flags */
1143 M_SUBLT_IMM(d, d, 1);
1144 M_ADDGT_IMM(d, d, 1);
1145 emit_store_dst(jd, iptr, d);
1148 #endif /* !defined(ENABLE_SOFTFLOAT) */
1151 /* memory operations **************************************************/
1153 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1155 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1156 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1157 /* implicit null-pointer check */
1158 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1159 emit_store_dst(jd, iptr, d);
1162 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1164 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1165 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1166 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1167 /* implicit null-pointer check */
1168 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1169 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1170 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1171 emit_store_dst(jd, iptr, d);
1174 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1176 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1177 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1178 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1179 /* implicit null-pointer check */
1180 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1181 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1182 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1183 emit_store_dst(jd, iptr, d);
1186 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1188 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1189 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1190 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1191 /* implicit null-pointer check */
1192 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1193 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1194 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1195 emit_store_dst(jd, iptr, d);
1198 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1200 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1201 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1202 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1203 /* implicit null-pointer check */
1204 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1205 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1206 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1207 emit_store_dst(jd, iptr, d);
1210 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1212 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1213 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1214 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1215 /* implicit null-pointer check */
1216 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1217 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1218 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1219 emit_store_dst(jd, iptr, d);
1222 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1224 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1225 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1226 /* implicit null-pointer check */
1227 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1228 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1229 #if !defined(ENABLE_SOFTFLOAT)
1230 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1231 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1233 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1234 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1236 emit_store_dst(jd, iptr, d);
1239 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1241 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1242 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1243 /* implicit null-pointer check */
1244 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1245 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1246 #if !defined(ENABLE_SOFTFLOAT)
1247 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1248 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1250 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1251 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1253 emit_store_dst(jd, iptr, d);
1256 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1258 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1259 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1260 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1261 /* implicit null-pointer check */
1262 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1263 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1264 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1265 emit_store_dst(jd, iptr, d);
1268 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1270 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1271 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1272 /* implicit null-pointer check */
1273 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1274 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1275 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1276 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1279 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1281 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1282 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1283 /* implicit null-pointer check */
1284 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1285 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1286 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1287 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1290 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1292 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1293 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1294 /* implicit null-pointer check */
1295 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1296 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1297 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1298 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1301 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1303 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1304 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1305 /* implicit null-pointer check */
1306 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1307 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1308 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1309 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1312 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1314 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1315 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1316 /* implicit null-pointer check */
1317 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1318 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1319 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1320 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1323 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1325 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1326 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1327 /* implicit null-pointer check */
1328 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1329 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1330 #if !defined(ENABLE_SOFTFLOAT)
1331 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1332 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1334 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1335 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1339 case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
1341 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1342 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1343 /* implicit null-pointer check */
1344 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1345 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1346 #if !defined(ENABLE_SOFTFLOAT)
1347 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1348 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1350 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1351 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1355 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1357 s1 = emit_load_s1(jd, iptr, REG_A0);
1358 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1359 s3 = emit_load_s3(jd, iptr, REG_A1);
1361 /* implicit null-pointer check */
1362 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1364 /* move arguments to argument registers */
1365 M_INTMOVE(s1, REG_A0);
1366 M_INTMOVE(s3, REG_A1);
1368 /* call builtin function */
1369 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1370 M_DSEG_BRANCH(disp);
1373 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1376 /* check resturn value of builtin */
1377 emit_arraystore_check(cd, iptr);
1379 /* finally store address into array */
1380 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1381 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1382 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1383 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1384 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1387 case ICMD_GETSTATIC: /* ... ==> ..., value */
1389 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1390 uf = iptr->sx.s23.s3.uf;
1391 fieldtype = uf->fieldref->parseddesc.fd->type;
1392 disp = dseg_add_unique_address(cd, NULL);
1394 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1397 fi = iptr->sx.s23.s3.fmiref->p.field;
1398 fieldtype = fi->type;
1399 disp = dseg_add_address(cd, fi->value);
1401 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1402 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1407 M_DSEG_LOAD(REG_ITMP3, disp);
1408 switch (fieldtype) {
1410 #if defined(ENABLE_SOFTFLOAT)
1414 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1415 M_ILD_INTERN(d, REG_ITMP3, 0);
1418 #if defined(ENABLE_SOFTFLOAT)
1421 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1422 M_LLD_INTERN(d, REG_ITMP3, 0);
1424 #if !defined(ENABLE_SOFTFLOAT)
1426 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1427 M_FLD_INTERN(d, REG_ITMP3, 0);
1430 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1431 M_DLD_INTERN(d, REG_ITMP3, 0);
1437 emit_store_dst(jd, iptr, d);
1440 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1442 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1443 uf = iptr->sx.s23.s3.uf;
1444 fieldtype = uf->fieldref->parseddesc.fd->type;
1445 disp = dseg_add_unique_address(cd, NULL);
1447 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1450 fi = iptr->sx.s23.s3.fmiref->p.field;
1451 fieldtype = fi->type;
1452 disp = dseg_add_address(cd, fi->value);
1454 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1455 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1460 M_DSEG_LOAD(REG_ITMP3, disp);
1461 switch (fieldtype) {
1463 #if defined(ENABLE_SOFTFLOAT)
1467 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1468 M_IST_INTERN(s1, REG_ITMP3, 0);
1471 #if defined(ENABLE_SOFTFLOAT)
1474 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1475 M_LST_INTERN(s1, REG_ITMP3, 0);
1477 #if !defined(ENABLE_SOFTFLOAT)
1479 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1480 M_FST_INTERN(s1, REG_ITMP3, 0);
1483 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1484 M_DST_INTERN(s1, REG_ITMP3, 0);
1492 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1494 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1495 emit_nullpointer_check(cd, iptr, s1);
1498 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1499 uf = iptr->sx.s23.s3.uf;
1500 fieldtype = uf->fieldref->parseddesc.fd->type;
1504 fi = iptr->sx.s23.s3.fmiref->p.field;
1505 fieldtype = fi->type;
1509 #if !defined(ENABLE_SOFTFLOAT)
1510 /* HACK: softnull checks on floats */
1511 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1512 emit_nullpointer_check_force(cd, iptr, s1);
1515 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1517 uf = iptr->sx.s23.s3.uf;
1519 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1522 switch (fieldtype) {
1524 #if defined(ENABLE_SOFTFLOAT)
1528 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1532 #if defined(ENABLE_SOFTFLOAT)
1535 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1538 #if !defined(ENABLE_SOFTFLOAT)
1540 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1544 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1551 emit_store_dst(jd, iptr, d);
1554 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1556 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1557 emit_nullpointer_check(cd, iptr, s1);
1559 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1560 uf = iptr->sx.s23.s3.uf;
1561 fieldtype = uf->fieldref->parseddesc.fd->type;
1565 fi = iptr->sx.s23.s3.fmiref->p.field;
1566 fieldtype = fi->type;
1570 #if !defined(ENABLE_SOFTFLOAT)
1571 /* HACK: softnull checks on floats */
1572 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1573 emit_nullpointer_check_force(cd, iptr, s1);
1576 switch (fieldtype) {
1578 #if defined(ENABLE_SOFTFLOAT)
1582 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1584 #if defined(ENABLE_SOFTFLOAT)
1585 case TYPE_DBL: /* fall through */
1588 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1590 #if !defined(ENABLE_SOFTFLOAT)
1593 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1600 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1602 uf = iptr->sx.s23.s3.uf;
1604 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1607 switch (fieldtype) {
1609 #if defined(ENABLE_SOFTFLOAT)
1613 M_IST(s2, s1, disp);
1616 #if defined(ENABLE_SOFTFLOAT)
1619 M_LST(s2, s1, disp);
1621 #if !defined(ENABLE_SOFTFLOAT)
1623 M_FST(s2, s1, disp);
1626 M_DST(s2, s1, disp);
1635 /* branch operations **************************************************/
1637 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1639 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1640 M_INTMOVE(s1, REG_ITMP1_XPTR);
1641 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1642 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1643 iptr->sx.s23.s2.uc, 0);
1645 disp = dseg_add_functionptr(cd, asm_handle_exception);
1646 M_DSEG_LOAD(REG_ITMP3, disp);
1647 M_MOV(REG_ITMP2_XPC, REG_PC);
1648 M_MOV(REG_PC, REG_ITMP3);
1649 M_NOP; /* nop ensures that XPC is less than the end */
1650 /* of basic block */
1653 case ICMD_GOTO: /* ... ==> ... */
1656 emit_br(cd, iptr->dst.block);
1659 case ICMD_JSR: /* ... ==> ... */
1661 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1664 case ICMD_IFNULL: /* ..., value ==> ... */
1665 case ICMD_IFNONNULL:
1667 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1669 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1672 case ICMD_IFLT: /* ..., value ==> ... */
1673 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1679 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1680 M_COMPARE(s1, iptr->sx.val.i);
1681 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1684 case ICMD_IF_LEQ: /* ..., value ==> ... */
1686 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1687 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1688 if (iptr->sx.val.l == 0) {
1689 M_ORR_S(s1, s2, REG_ITMP3);
1692 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1693 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1694 M_CMP(s1, REG_ITMP3);*/
1695 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1696 M_CMPEQ(s2, REG_ITMP3);
1698 emit_beq(cd, iptr->dst.block);
1701 case ICMD_IF_LLT: /* ..., value ==> ... */
1703 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1704 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1705 if (iptr->sx.val.l == 0) {
1706 /* if high word is less than zero, the whole long is too */
1708 emit_blt(cd, iptr->dst.block);
1711 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1712 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1713 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1714 M_CMP(s1, REG_ITMP3);*/
1715 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1716 M_MOVGT_IMM(2, REG_ITMP1);
1717 M_MOVEQ_IMM(1, REG_ITMP1);
1719 /* low compare: x=x-1(ifLO) */
1720 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1721 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1722 M_CMP(s2, REG_ITMP3);*/
1723 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1725 /* branch if (x LT 1) */
1726 M_CMP_IMM(REG_ITMP1, 1);
1727 emit_blt(cd, iptr->dst.block);
1731 case ICMD_IF_LLE: /* ..., value ==> ... */
1733 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1734 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1735 if (iptr->sx.val.l == 0) {
1736 /* if high word is less than zero, the whole long is too */
1738 emit_blt(cd, iptr->dst.block);
1740 /* ... otherwise the low word has to be zero (tricky!) */
1742 emit_beq(cd, iptr->dst.block);
1745 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1746 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1747 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1748 M_CMP(s1, REG_ITMP3);*/
1749 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1750 M_MOVGT_IMM(2, REG_ITMP1);
1751 M_MOVEQ_IMM(1, REG_ITMP1);
1753 /* low compare: x=x+1(ifHI) */
1754 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1755 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1756 M_CMP(s2, REG_ITMP3);*/
1757 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1759 /* branch if (x LE 1) */
1760 M_CMP_IMM(REG_ITMP1, 1);
1761 emit_ble(cd, iptr->dst.block);
1765 case ICMD_IF_LGE: /* ..., value ==> ... */
1767 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1768 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1769 if (iptr->sx.val.l == 0) {
1770 /* if high word is greater or equal zero, the whole long is too */
1772 emit_bge(cd, iptr->dst.block);
1775 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1776 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1777 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1778 M_CMP(s1, REG_ITMP3);*/
1779 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1780 M_MOVGT_IMM(2, REG_ITMP1);
1781 M_MOVEQ_IMM(1, REG_ITMP1);
1783 /* low compare: x=x-1(ifLO) */
1784 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1785 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1786 M_CMP(s2, REG_ITMP3);*/
1787 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1789 /* branch if (x GE 1) */
1790 M_CMP_IMM(REG_ITMP1, 1);
1791 emit_bge(cd, iptr->dst.block);
1795 case ICMD_IF_LGT: /* ..., value ==> ... */
1797 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1798 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1800 if (iptr->sx.val.l == 0) {
1801 /* if high word is greater than zero, the whole long is too */
1804 codegen_add_branch_ref(cd, iptr->dst.block);
1806 /* ... or high was zero and low is non zero (tricky!) */
1807 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1808 M_MOVLT_IMM(1, REG_ITMP3);
1809 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1811 codegen_add_branch_ref(cd, iptr->dst.block);
1815 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1816 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1817 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1818 M_CMP(s1, REG_ITMP3);*/
1819 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1820 M_MOVGT_IMM(2, REG_ITMP1);
1821 M_MOVEQ_IMM(1, REG_ITMP1);
1823 /* low compare: x=x+1(ifHI) */
1824 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1825 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1826 M_CMP(s2, REG_ITMP3);*/
1827 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1829 /* branch if (x GT 1) */
1830 M_CMP_IMM(REG_ITMP1, 1);
1831 emit_bgt(cd, iptr->dst.block);
1837 case ICMD_IF_LNE: /* ..., value ==> ... */
1839 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1840 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1841 if (iptr->sx.val.l == 0) {
1842 M_ORR_S(s1, s2, REG_ITMP3);
1845 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1846 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1847 M_CMP(s1, REG_ITMP3);*/
1848 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1849 M_CMPEQ(s2, REG_ITMP3);
1851 emit_bne(cd, iptr->dst.block);
1854 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1855 case ICMD_IF_ICMPNE:
1856 case ICMD_IF_ICMPLT:
1857 case ICMD_IF_ICMPLE:
1858 case ICMD_IF_ICMPGT:
1859 case ICMD_IF_ICMPGE:
1861 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1862 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1864 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1867 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1868 case ICMD_IF_ACMPNE:
1870 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1871 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1873 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1876 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1877 /* op1 = target JavaVM pc */
1879 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1880 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1883 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1884 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1887 emit_beq(cd, iptr->dst.block);
1890 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1891 /* op1 = target JavaVM pc */
1893 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1894 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1897 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1898 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1901 emit_bne(cd, iptr->dst.block);
1904 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1905 /* op1 = target JavaVM pc */
1907 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1908 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1909 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1911 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1912 M_MOVGT_IMM(2, REG_ITMP3);
1913 M_MOVEQ_IMM(1, REG_ITMP3);
1915 /* low compare: x=x-1(ifLO) */
1916 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1917 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1919 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1921 /* branch if (x LT 1) */
1922 M_CMP_IMM(REG_ITMP3, 1);
1923 emit_blt(cd, iptr->dst.block);
1926 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1927 /* op1 = target JavaVM pc */
1929 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1930 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1931 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1933 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1934 M_MOVGT_IMM(2, REG_ITMP3);
1935 M_MOVEQ_IMM(1, REG_ITMP3);
1937 /* low compare: x=x-1(ifLO) */
1938 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1939 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1941 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1943 /* branch if (x LE 1) */
1944 M_CMP_IMM(REG_ITMP3, 1);
1945 emit_ble(cd, iptr->dst.block);
1948 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1949 /* op1 = target JavaVM pc */
1951 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1952 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1953 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1955 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1956 M_MOVGT_IMM(2, REG_ITMP3);
1957 M_MOVEQ_IMM(1, REG_ITMP3);
1959 /* low compare: x=x-1(ifLO) */
1960 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1961 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1963 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1965 /* branch if (x GT 1) */
1966 M_CMP_IMM(REG_ITMP3, 1);
1967 emit_bgt(cd, iptr->dst.block);
1970 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1971 /* op1 = target JavaVM pc */
1973 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1974 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1975 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1977 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1978 M_MOVGT_IMM(2, REG_ITMP3);
1979 M_MOVEQ_IMM(1, REG_ITMP3);
1981 /* low compare: x=x-1(ifLO) */
1982 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1983 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1985 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1987 /* branch if (x GE 1) */
1988 M_CMP_IMM(REG_ITMP3, 1);
1989 emit_bge(cd, iptr->dst.block);
1992 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1995 branch_target_t *table;
1997 table = iptr->dst.table;
1999 l = iptr->sx.s23.s2.tablelow;
2000 i = iptr->sx.s23.s3.tablehigh;
2002 /* calculate new index (index - low) */
2003 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2005 M_INTMOVE(s1, REG_ITMP1);
2006 } else if (IS_IMM(l)) {
2007 M_SUB_IMM(REG_ITMP1, s1, l);
2009 ICONST(REG_ITMP2, l);
2010 M_SUB(REG_ITMP1, s1, REG_ITMP2);
2013 /* range check (index <= high-low) */
2015 M_COMPARE(REG_ITMP1, i-1);
2016 emit_bugt(cd, table[0].block);
2018 /* build jump table top down and use address of lowest entry */
2023 dseg_add_target(cd, table->block);
2028 /* length of dataseg after last dseg_add_target is used by load */
2029 /* TODO: this loads from data-segment */
2030 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2031 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2034 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2037 lookup_target_t *lookup;
2039 lookup = iptr->dst.lookup;
2041 i = iptr->sx.s23.s2.lookupcount;
2044 MCODECHECK((i<<2)+8);
2045 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2048 M_COMPARE(s1, lookup->value);
2049 emit_beq(cd, lookup->target.block);
2053 /* default branch */
2054 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2058 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2060 #if !defined(ENABLE_SOFTFLOAT)
2061 REPLACEMENT_POINT_RETURN(cd, iptr);
2062 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2063 M_CAST_F2I(s1, REG_RESULT);
2064 goto ICMD_RETURN_do;
2067 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2069 REPLACEMENT_POINT_RETURN(cd, iptr);
2070 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2071 M_INTMOVE(s1, REG_RESULT);
2072 goto ICMD_RETURN_do;
2074 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2076 #if !defined(ENABLE_SOFTFLOAT)
2077 REPLACEMENT_POINT_RETURN(cd, iptr);
2078 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2079 M_CAST_D2L(s1, REG_RESULT_PACKED);
2080 goto ICMD_RETURN_do;
2083 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2085 REPLACEMENT_POINT_RETURN(cd, iptr);
2086 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2087 M_LNGMOVE(s1, REG_RESULT_PACKED);
2088 goto ICMD_RETURN_do;
2090 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2092 REPLACEMENT_POINT_RETURN(cd, iptr);
2093 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2094 M_INTMOVE(s1, REG_RESULT);
2095 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2096 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2097 iptr->sx.s23.s2.uc, 0);
2099 goto ICMD_RETURN_do;
2101 case ICMD_RETURN: /* ... ==> ... */
2103 REPLACEMENT_POINT_RETURN(cd, iptr);
2106 #if !defined(NDEBUG)
2107 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2108 emit_verbosecall_exit(jd);
2111 #if defined(ENABLE_THREADS)
2112 /* call monitorexit function */
2114 if (checksync && code_is_synchronized(code)) {
2115 /* stack offset for monitor argument */
2117 s1 = rd->memuse * 8;
2119 /* we need to save the proper return value */
2121 switch (iptr->opc) {
2125 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2127 M_STMFD(BITMASK_RESULT, REG_SP);
2132 M_LDR(REG_A0, REG_SP, s1);
2133 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2134 M_DSEG_BRANCH(disp);
2136 /* we no longer need PV here, no more loading */
2137 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2138 M_RECOMPUTE_PV(s1);*/
2140 switch (iptr->opc) {
2144 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2146 M_LDMFD(BITMASK_RESULT, REG_SP);
2152 /* deallocate stackframe for spilled variables */
2154 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2155 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2157 /* restore callee saved registers + do return */
2159 if (savedregs_bitmask) {
2160 if (!code_is_leafmethod(code)) {
2161 savedregs_bitmask &= ~(1<<REG_LR);
2162 savedregs_bitmask |= (1<<REG_PC);
2164 M_LDMFD(savedregs_bitmask, REG_SP);
2167 /* if LR was not on stack, we need to return manually */
2169 if (code_is_leafmethod(code))
2170 M_MOV(REG_PC, REG_LR);
2173 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2175 bte = iptr->sx.s23.s3.bte;
2177 goto ICMD_INVOKE_do;
2179 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2180 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2181 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2182 case ICMD_INVOKEINTERFACE:
2184 REPLACEMENT_POINT_INVOKE(cd, iptr);
2186 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2188 um = iptr->sx.s23.s3.um;
2189 md = um->methodref->parseddesc.md;
2192 lm = iptr->sx.s23.s3.fmiref->p.method;
2194 md = lm->parseddesc;
2198 /* copy arguments to registers or stack location */
2200 s3 = md->paramcount;
2202 MCODECHECK((s3 << 1) + 64);
2204 for (s3 = s3 - 1; s3 >= 0; s3--) {
2205 var = VAR(iptr->sx.s23.s2.args[s3]);
2206 d = md->params[s3].regoff;
2208 if (var->flags & PREALLOC) /* argument was precolored? */
2211 /* TODO: document me */
2212 #if !defined(ENABLE_SOFTFLOAT)
2213 if (IS_INT_LNG_TYPE(var->type)) {
2214 #endif /* !defined(ENABLE_SOFTFLOAT) */
2215 if (!md->params[s3].inmemory) {
2216 s1 = emit_load(jd, iptr, var, d);
2218 if (IS_2_WORD_TYPE(var->type))
2224 if (IS_2_WORD_TYPE(var->type)) {
2225 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2226 M_LST(s1, REG_SP, d);
2229 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2230 M_IST(s1, REG_SP, d);
2233 #if !defined(ENABLE_SOFTFLOAT)
2236 if (!md->params[s3].inmemory) {
2237 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2238 if (IS_2_WORD_TYPE(var->type))
2244 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2245 if (IS_2_WORD_TYPE(var->type))
2246 M_DST(s1, REG_SP, d);
2248 M_FST(s1, REG_SP, d);
2251 #endif /* !defined(ENABLE_SOFTFLOAT) */
2254 switch (iptr->opc) {
2257 if (bte->stub == NULL) {
2258 disp = dseg_add_functionptr(cd, bte->fp);
2260 disp = dseg_add_functionptr(cd, bte->stub);
2263 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2265 /* generate the actual call */
2267 M_MOV(REG_LR, REG_PC);
2268 M_MOV(REG_PC, REG_PV);
2269 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2273 case ICMD_INVOKESPECIAL:
2274 emit_nullpointer_check(cd, iptr, REG_A0);
2277 case ICMD_INVOKESTATIC:
2279 disp = dseg_add_unique_address(cd, NULL);
2281 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2285 disp = dseg_add_address(cd, lm->stubroutine);
2287 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2289 /* generate the actual call */
2291 M_MOV(REG_LR, REG_PC);
2292 M_MOV(REG_PC, REG_PV);
2293 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2297 case ICMD_INVOKEVIRTUAL:
2299 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2304 s1 = OFFSET(vftbl_t, table[0]) +
2305 sizeof(methodptr) * lm->vftblindex;
2307 /* implicit null-pointer check */
2308 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2309 OFFSET(java_object_t, vftbl));
2310 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2312 /* generate the actual call */
2314 M_MOV(REG_LR, REG_PC);
2315 M_MOV(REG_PC, REG_PV);
2316 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2320 case ICMD_INVOKEINTERFACE:
2322 int32_t disp = dseg_add_unique_s4(cd, 0);
2323 int32_t disp2 = dseg_add_unique_s4(cd, 0);
2325 // XXX We need two displacements.
2326 assert(disp2 == disp - 4);
2327 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, disp);
2329 // The following instruction MUST NOT change a0 because of the implicit NPE check.
2330 M_LDR_INTERN(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
2333 assert(REG_ITMP1 != REG_METHODPTR);
2334 assert(REG_ITMP2 == REG_METHODPTR);
2335 assert(REG_ITMP3 != REG_METHODPTR);
2337 M_DSEG_LOAD(REG_ITMP1, disp);
2338 M_LDR_REG(REG_METHODPTR, REG_METHODPTR, REG_ITMP1);
2340 M_DSEG_LOAD(REG_ITMP3, disp2);
2341 M_ADD(REG_METHODPTR, REG_METHODPTR, REG_ITMP3);
2343 // This must be a load with displacement,
2344 // otherwise the JIT method address patching does
2345 // not work anymore (see md_jit_method_patch_address).
2346 M_LDR_INTERN(REG_PV, REG_METHODPTR, 0);
2349 s1 = OFFSET(vftbl_t, interfacetable[0]) - sizeof(methodptr*) * lm->clazz->index;
2350 s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
2352 // The following instruction MUST NOT change a0 because of the implicit NPE check.
2353 M_LDR_INTERN(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
2354 M_LDR(REG_METHODPTR, REG_METHODPTR, s1);
2355 M_LDR(REG_PV, REG_METHODPTR, s2);
2358 // Generate the actual call.
2359 M_MOV(REG_LR, REG_PC);
2360 M_MOV(REG_PC, REG_PV);
2361 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2366 /* store size of call code in replacement point */
2367 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2369 /* store return value */
2371 d = md->returntype.type;
2373 #if !defined(__SOFTFP__)
2374 /* TODO: this is only a hack, since we use R0/R1 for float
2375 return! this depends on gcc; it is independent from
2376 our ENABLE_SOFTFLOAT define */
2377 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2378 #if 0 && !defined(NDEBUG)
2379 dolog("BUILTIN that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
2381 /* we cannot use this macro, since it is not defined
2382 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2383 REG_FRESULT, REG_RESULT_TYPED(d)); */
2384 if (IS_2_WORD_TYPE(d)) {
2385 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2386 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2388 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2389 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2394 if (d != TYPE_VOID) {
2395 #if !defined(ENABLE_SOFTFLOAT)
2396 if (IS_INT_LNG_TYPE(d)) {
2397 #endif /* !defined(ENABLE_SOFTFLOAT) */
2398 if (IS_2_WORD_TYPE(d)) {
2399 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2400 M_LNGMOVE(REG_RESULT_PACKED, s1);
2403 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2404 M_INTMOVE(REG_RESULT, s1);
2407 #if !defined(ENABLE_SOFTFLOAT)
2409 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2410 if (IS_2_WORD_TYPE(d))
2411 M_CAST_L2D(REG_RESULT_PACKED, s1);
2413 M_CAST_I2F(REG_RESULT, s1);
2415 #endif /* !defined(ENABLE_SOFTFLOAT) */
2417 emit_store_dst(jd, iptr, s1);
2421 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2423 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2424 /* object type cast-check */
2429 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2434 super = iptr->sx.s23.s3.c.cls;
2435 superindex = super->index;
2438 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2440 /* if class is not resolved, check which code to call */
2442 if (super == NULL) {
2444 emit_label_beq(cd, BRANCH_LABEL_1);
2446 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2447 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2448 iptr->sx.s23.s3.c.ref, disp);
2450 M_DSEG_LOAD(REG_ITMP2, disp);
2451 disp = dseg_add_s4(cd, ACC_INTERFACE);
2452 M_DSEG_LOAD(REG_ITMP3, disp);
2453 M_TST(REG_ITMP2, REG_ITMP3);
2454 emit_label_beq(cd, BRANCH_LABEL_2);
2457 /* interface checkcast code */
2459 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2460 if ((super == NULL) || !IS_IMM(superindex)) {
2461 disp = dseg_add_unique_s4(cd, superindex);
2463 if (super == NULL) {
2464 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2465 iptr->sx.s23.s3.c.ref, disp);
2469 emit_label_beq(cd, BRANCH_LABEL_3);
2472 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2473 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2475 /* we put unresolved or non-immediate superindices onto dseg */
2476 if ((super == NULL) || !IS_IMM(superindex)) {
2477 /* disp was computed before we added the patcher */
2478 M_DSEG_LOAD(REG_ITMP2, disp);
2479 M_CMP(REG_ITMP3, REG_ITMP2);
2481 assert(IS_IMM(superindex));
2482 M_CMP_IMM(REG_ITMP3, superindex);
2485 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2487 /* if we loaded the superindex out of the dseg above, we do
2488 things differently here! */
2489 if ((super == NULL) || !IS_IMM(superindex)) {
2491 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2493 /* this assumes something */
2494 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2496 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2497 assert(sizeof(methodptr*) == 4);
2498 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2504 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2505 superindex * sizeof(methodptr*);
2509 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2510 M_TST(REG_ITMP3, REG_ITMP3);
2511 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2514 emit_label_br(cd, BRANCH_LABEL_4);
2516 emit_label(cd, BRANCH_LABEL_3);
2519 /* class checkcast code */
2521 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2522 if (super == NULL) {
2523 emit_label(cd, BRANCH_LABEL_2);
2525 disp = dseg_add_unique_address(cd, NULL);
2527 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2528 iptr->sx.s23.s3.c.ref,
2532 disp = dseg_add_address(cd, super->vftbl);
2535 emit_label_beq(cd, BRANCH_LABEL_5);
2538 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2539 M_DSEG_LOAD(REG_ITMP3, disp);
2541 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2542 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2543 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2544 M_DSEG_LOAD(REG_ITMP3, disp);
2545 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2547 M_CMP(REG_ITMP2, REG_ITMP3);
2548 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2551 emit_label(cd, BRANCH_LABEL_5);
2554 if (super == NULL) {
2555 emit_label(cd, BRANCH_LABEL_1);
2556 emit_label(cd, BRANCH_LABEL_4);
2559 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2562 /* array type cast-check */
2564 s1 = emit_load_s1(jd, iptr, REG_A0);
2565 M_INTMOVE(s1, REG_A0);
2567 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2568 disp = dseg_add_unique_address(cd, NULL);
2570 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2571 iptr->sx.s23.s3.c.ref,
2575 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2577 M_DSEG_LOAD(REG_A1, disp);
2578 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2579 M_DSEG_BRANCH(disp);
2582 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2583 M_RECOMPUTE_PV(disp);
2585 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2586 M_TST(REG_RESULT, REG_RESULT);
2587 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2589 d = codegen_reg_of_dst(jd, iptr, s1);
2593 emit_store_dst(jd, iptr, d);
2596 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2602 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2607 super = iptr->sx.s23.s3.c.cls;
2608 superindex = super->index;
2611 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2612 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2615 M_MOV(REG_ITMP1, s1);
2619 /* if class is not resolved, check which code to call */
2621 if (super == NULL) {
2625 emit_label_beq(cd, BRANCH_LABEL_1);
2627 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2628 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2629 iptr->sx.s23.s3.c.ref, disp);
2631 M_DSEG_LOAD(REG_ITMP2, disp);
2632 disp = dseg_add_s4(cd, ACC_INTERFACE);
2633 M_DSEG_LOAD(REG_ITMP3, disp);
2634 M_TST(REG_ITMP2, REG_ITMP3);
2635 emit_label_beq(cd, BRANCH_LABEL_2);
2638 /* interface checkcast code */
2640 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2641 if ((super == NULL) || !IS_IMM(superindex)) {
2642 disp = dseg_add_unique_s4(cd, superindex);
2644 if (super == NULL) {
2645 /* If d == REG_ITMP2, then it's destroyed in check
2650 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2651 iptr->sx.s23.s3.c.ref, disp);
2656 emit_label_beq(cd, BRANCH_LABEL_3);
2659 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2660 M_LDR_INTERN(REG_ITMP3,
2661 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2663 /* we put unresolved or non-immediate superindices onto dseg
2664 and do things slightly different */
2665 if ((super == NULL) || !IS_IMM(superindex)) {
2666 /* disp was computed before we added the patcher */
2667 M_DSEG_LOAD(REG_ITMP2, disp);
2668 M_CMP(REG_ITMP3, REG_ITMP2);
2670 if (d == REG_ITMP2) {
2677 /* this assumes something */
2678 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2680 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2681 assert(sizeof(methodptr*) == 4);
2682 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2684 if (d == REG_ITMP2) {
2691 assert(IS_IMM(superindex));
2692 M_CMP_IMM(REG_ITMP3, superindex);
2696 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2697 superindex * sizeof(methodptr*);
2701 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2702 M_TST(REG_ITMP3, REG_ITMP3);
2706 emit_label_br(cd, BRANCH_LABEL_4);
2708 emit_label(cd, BRANCH_LABEL_3);
2711 /* class checkcast code */
2713 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2714 if (super == NULL) {
2715 emit_label(cd, BRANCH_LABEL_2);
2717 disp = dseg_add_unique_address(cd, NULL);
2719 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2720 iptr->sx.s23.s3.c.ref, disp);
2723 disp = dseg_add_address(cd, super->vftbl);
2727 emit_label_beq(cd, BRANCH_LABEL_5);
2730 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2731 M_DSEG_LOAD(REG_ITMP2, disp);
2733 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2734 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2735 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
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 /* generate traps */
2839 emit_patcher_traps(jd);
2841 /* everything's ok */
2847 /* codegen_emit_stub_native ****************************************************
2849 Emits a stub routine which calls a native method.
2851 *******************************************************************************/
2853 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2864 /* get required compiler data */
2870 /* initialize variables */
2874 /* calculate stackframe size */
2876 cd->stackframesize =
2877 4 + /* return address */
2878 sizeof(stackframeinfo_t) + /* stackframeinfo */
2879 sizeof(localref_table) + /* localref_table */
2880 nmd->memuse * 4; /* stack arguments */
2882 /* align stack to 8-byte */
2884 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2886 /* create method header */
2888 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2889 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2890 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2891 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2892 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2894 /* generate stub code */
2896 M_STMFD(1<<REG_LR, REG_SP);
2897 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2899 #if !defined(NDEBUG)
2900 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2901 emit_verbosecall_enter(jd);
2904 #if defined(ENABLE_GC_CACAO)
2905 /* Save callee saved integer registers in stackframeinfo (GC may
2906 need to recover them during a collection). */
2908 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2909 OFFSET(stackframeinfo_t, intregs);
2911 for (i = 0; i < INT_SAV_CNT; i++)
2912 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2915 /* Save integer and float argument registers (these are 4
2916 registers, stack is 8-byte aligned). */
2918 M_STMFD(BITMASK_ARGS, REG_SP);
2919 /* TODO: floating point */
2921 /* create native stackframe info */
2923 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2924 M_MOV(REG_A1, REG_PV);
2925 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2926 M_DSEG_BRANCH(disp);
2930 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2933 /* remember class argument */
2935 if (m->flags & ACC_STATIC)
2936 M_MOV(REG_ITMP3, REG_RESULT);
2938 /* Restore integer and float argument registers (these are 4
2939 registers, stack is 8-byte aligned). */
2941 M_LDMFD(BITMASK_ARGS, REG_SP);
2942 /* TODO: floating point */
2944 /* copy or spill arguments to new locations */
2945 /* ATTENTION: the ARM has only integer argument registers! */
2947 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2948 t = md->paramtypes[i].type;
2950 if (!md->params[i].inmemory) {
2951 s1 = md->params[i].regoff;
2952 s2 = nmd->params[j].regoff;
2954 if (!nmd->params[j].inmemory) {
2955 #if !defined(__ARM_EABI__)
2956 SPLIT_OPEN(t, s2, REG_ITMP1);
2959 if (IS_2_WORD_TYPE(t))
2964 #if !defined(__ARM_EABI__)
2965 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2969 if (IS_2_WORD_TYPE(t))
2970 M_LST(s1, REG_SP, s2);
2972 M_IST(s1, REG_SP, s2);
2976 s1 = md->params[i].regoff + cd->stackframesize;
2977 s2 = nmd->params[j].regoff;
2979 if (IS_2_WORD_TYPE(t)) {
2980 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2981 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2984 M_ILD(REG_ITMP1, REG_SP, s1);
2985 M_IST(REG_ITMP1, REG_SP, s2);
2990 /* Handle native Java methods. */
2992 if (m->flags & ACC_NATIVE) {
2993 /* put class into second argument register */
2995 if (m->flags & ACC_STATIC)
2996 M_MOV(REG_A1, REG_ITMP3);
2998 /* put env into first argument register */
3000 disp = dseg_add_address(cd, VM_get_jnienv());
3001 M_DSEG_LOAD(REG_A0, disp);
3004 /* Call the native function. */
3006 disp = dseg_add_functionptr(cd, f);
3007 M_DSEG_BRANCH(disp);
3010 /* TODO: this is only needed because of the tracer ... do we
3013 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3016 #if !defined(__SOFTFP__)
3017 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3018 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3019 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3020 #if 0 && !defined(NDEBUG)
3021 dolog("NATIVESTUB that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
3023 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3024 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3025 if (IS_2_WORD_TYPE(md->returntype.type)) {
3026 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3027 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3029 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3030 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3035 #if !defined(NDEBUG)
3036 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3037 emit_verbosecall_exit(jd);
3040 /* remove native stackframe info */
3041 /* TODO: improve this store/load */
3043 M_STMFD(BITMASK_RESULT, REG_SP);
3045 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3046 M_MOV(REG_A1, REG_PV);
3047 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3048 M_DSEG_BRANCH(disp);
3049 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3052 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3053 M_LDMFD(BITMASK_RESULT, REG_SP);
3055 #if defined(ENABLE_GC_CACAO)
3056 /* restore callee saved int registers from stackframeinfo (GC might have */
3057 /* modified them during a collection). */
3059 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3060 OFFSET(stackframeinfo_t, intregs);
3062 for (i = 0; i < INT_SAV_CNT; i++)
3063 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3066 /* finish stub code, but do not yet return to caller */
3068 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3069 M_LDMFD(1<<REG_LR, REG_SP);
3071 /* check for exception */
3073 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3074 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3076 /* handle exception here */
3078 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3080 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3081 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3082 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3086 /* asm_debug *******************************************************************
3090 *******************************************************************************/
3092 void asm_debug(int a1, int a2, int a3, int a4)
3094 printf("===> i am going to exit after this debugging message!\n");
3095 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3096 vm_abort("leave you now");
3101 * These are local overrides for various environment variables in Emacs.
3102 * Please do not remove this and leave it at the end of the file, where
3103 * Emacs will automagically detect them.
3104 * ---------------------------------------------------------------------
3107 * indent-tabs-mode: t
3111 * vim:noexpandtab:sw=4:ts=4: