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.h"
40 #include "native/localref.h"
41 #include "native/native.h"
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.h"
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);
1017 emit_store_dst(jd, iptr, d);
1020 case ICMD_I2D: /* ..., value ==> ..., (double) value */
1022 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1023 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1025 emit_store_dst(jd, iptr, d);
1028 case ICMD_F2I: /* ..., value ==> ..., (int) value */
1030 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1031 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1032 /* this uses round towards zero, as Java likes it */
1034 #if !defined(__VFP_FP__)
1035 /* this checks for NaN; to return zero as Java likes it */
1039 emit_store_dst(jd, iptr, d);
1042 case ICMD_D2I: /* ..., value ==> ..., (int) value */
1044 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1045 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1046 /* this uses round towards zero, as Java likes it */
1048 #if !defined(__VFP_FP__)
1049 /* this checks for NaN; to return zero as Java likes it */
1053 emit_store_dst(jd, iptr, d);
1056 case ICMD_D2F: /* ..., value ==> ..., (float) value */
1058 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1059 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1061 emit_store_dst(jd, iptr, d);
1064 case ICMD_F2D: /* ..., value ==> ..., (double) value */
1066 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1067 d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
1069 emit_store_dst(jd, iptr, d);
1072 case ICMD_FCMPG: /* ..., val1, val2 ==> ..., val1 fcmpg val2 */
1074 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1075 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1076 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1079 #if defined(__VFP_FP__)
1080 M_FMSTAT; /* on VFP we need to transfer the flags */
1082 M_SUBGT_IMM(d, d, 1);
1083 M_ADDLT_IMM(d, d, 1);
1084 emit_store_dst(jd, iptr, d);
1087 case ICMD_DCMPG: /* ..., val1, val2 ==> ..., val1 dcmpg val2 */
1089 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1090 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1091 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1094 #if defined(__VFP_FP__)
1095 M_FMSTAT; /* on VFP we need to transfer the flags */
1097 M_SUBGT_IMM(d, d, 1);
1098 M_ADDLT_IMM(d, d, 1);
1099 emit_store_dst(jd, iptr, d);
1102 case ICMD_FCMPL: /* ..., val1, val2 ==> ..., val1 fcmpl val2 */
1104 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1105 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1106 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1109 #if defined(__VFP_FP__)
1110 M_FMSTAT; /* on VFP we need to transfer the flags */
1112 M_SUBLT_IMM(d, d, 1);
1113 M_ADDGT_IMM(d, d, 1);
1114 emit_store_dst(jd, iptr, d);
1117 case ICMD_DCMPL: /* ..., val1, val2 ==> ..., val1 dcmpl val2 */
1119 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1120 s2 = emit_load_s2(jd, iptr, REG_FTMP2);
1121 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1124 #if defined(__VFP_FP__)
1125 M_FMSTAT; /* on VFP we need to transfer the flags */
1127 M_SUBLT_IMM(d, d, 1);
1128 M_ADDGT_IMM(d, d, 1);
1129 emit_store_dst(jd, iptr, d);
1132 #endif /* !defined(ENABLE_SOFTFLOAT) */
1135 /* memory operations **************************************************/
1137 case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
1139 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1140 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
1141 /* implicit null-pointer check */
1142 M_ILD_INTERN(d, s1, OFFSET(java_array_t, size));
1143 emit_store_dst(jd, iptr, d);
1146 case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
1148 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1149 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1150 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1151 /* implicit null-pointer check */
1152 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1153 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1154 M_LDRSB(d, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1155 emit_store_dst(jd, iptr, d);
1158 case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
1160 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1161 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1162 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1163 /* implicit null-pointer check */
1164 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1165 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1166 M_LDRH(d, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1167 emit_store_dst(jd, iptr, d);
1170 case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
1172 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1173 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1174 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1175 /* implicit null-pointer check */
1176 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1177 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1178 M_LDRSH(d, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1179 emit_store_dst(jd, iptr, d);
1182 case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
1184 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1185 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1186 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1187 /* implicit null-pointer check */
1188 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1189 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1190 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1191 emit_store_dst(jd, iptr, d);
1194 case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
1196 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1197 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1198 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1199 /* implicit null-pointer check */
1200 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1201 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1202 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1203 emit_store_dst(jd, iptr, d);
1206 case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
1208 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1209 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1210 /* implicit null-pointer check */
1211 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1212 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1213 #if !defined(ENABLE_SOFTFLOAT)
1214 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1215 M_FLD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1217 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1218 M_ILD_INTERN(d, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1220 emit_store_dst(jd, iptr, d);
1223 case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
1225 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1226 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1227 /* implicit null-pointer check */
1228 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1229 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1230 #if !defined(ENABLE_SOFTFLOAT)
1231 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1232 M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1234 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1235 M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
1237 emit_store_dst(jd, iptr, d);
1240 case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
1242 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1243 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1244 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1245 /* implicit null-pointer check */
1246 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1247 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1248 M_LDR_INTERN(d, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1249 emit_store_dst(jd, iptr, d);
1252 case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
1254 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1255 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1256 /* implicit null-pointer check */
1257 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1258 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1259 M_ADD(REG_ITMP1, s1, s2); /* REG_ITMP1 = s1 + 1 * s2 */
1260 M_STRB(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
1263 case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
1265 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1266 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1267 /* implicit null-pointer check */
1268 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1269 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1270 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1271 M_STRH(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
1274 case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
1276 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1277 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1278 /* implicit null-pointer check */
1279 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1280 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1281 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 1)); /* REG_ITMP1 = s1 + 2 * s2 */
1282 M_STRH(s3, REG_ITMP1, OFFSET(java_shortarray_t, data[0]));
1285 case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
1287 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1288 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1289 /* implicit null-pointer check */
1290 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1291 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1292 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1293 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
1296 case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
1298 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1299 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1300 /* implicit null-pointer check */
1301 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1302 M_ADD(REG_ITMP3, s1, REG_LSL(s2, 3)); /* REG_ITMP3 = s1 + 8 * s2 */
1303 s3 = emit_load_s3(jd, iptr, REG_ITMP12_PACKED);
1304 M_LST_INTERN(s3, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
1307 case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
1309 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1310 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1311 /* implicit null-pointer check */
1312 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1313 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1314 #if !defined(ENABLE_SOFTFLOAT)
1315 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1316 M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1318 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1319 M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
1323 case ICMD_DASTORE: /* ..., 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, 3)); /* REG_ITMP1 = s1 + 8 * s2 */
1330 #if !defined(ENABLE_SOFTFLOAT)
1331 s3 = emit_load_s3(jd, iptr, REG_FTMP1);
1332 M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1334 s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
1335 M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
1339 case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
1341 s1 = emit_load_s1(jd, iptr, REG_A0);
1342 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1343 s3 = emit_load_s3(jd, iptr, REG_A1);
1345 /* implicit null-pointer check */
1346 emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
1348 /* move arguments to argument registers */
1349 M_INTMOVE(s1, REG_A0);
1350 M_INTMOVE(s3, REG_A1);
1352 /* call builtin function */
1353 disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
1354 M_DSEG_BRANCH(disp);
1357 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
1360 /* check resturn value of builtin */
1361 emit_arraystore_check(cd, iptr);
1363 /* finally store address into array */
1364 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1365 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1366 s3 = emit_load_s3(jd, iptr, REG_ITMP3);
1367 M_ADD(REG_ITMP1, s1, REG_LSL(s2, 2)); /* REG_ITMP1 = s1 + 4 * s2 */
1368 M_STR_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
1371 case ICMD_GETSTATIC: /* ... ==> ..., value */
1373 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1374 uf = iptr->sx.s23.s3.uf;
1375 fieldtype = uf->fieldref->parseddesc.fd->type;
1376 disp = dseg_add_unique_address(cd, NULL);
1378 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1381 fi = iptr->sx.s23.s3.fmiref->p.field;
1382 fieldtype = fi->type;
1383 disp = dseg_add_address(cd, fi->value);
1385 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1386 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1391 M_DSEG_LOAD(REG_ITMP3, disp);
1392 switch (fieldtype) {
1394 #if defined(ENABLE_SOFTFLOAT)
1398 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1399 M_ILD_INTERN(d, REG_ITMP3, 0);
1402 #if defined(ENABLE_SOFTFLOAT)
1405 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1406 M_LLD_INTERN(d, REG_ITMP3, 0);
1408 #if !defined(ENABLE_SOFTFLOAT)
1410 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1411 M_FLD_INTERN(d, REG_ITMP3, 0);
1414 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1415 M_DLD_INTERN(d, REG_ITMP3, 0);
1421 emit_store_dst(jd, iptr, d);
1424 case ICMD_PUTSTATIC: /* ..., value ==> ... */
1426 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1427 uf = iptr->sx.s23.s3.uf;
1428 fieldtype = uf->fieldref->parseddesc.fd->type;
1429 disp = dseg_add_unique_address(cd, NULL);
1431 patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
1434 fi = iptr->sx.s23.s3.fmiref->p.field;
1435 fieldtype = fi->type;
1436 disp = dseg_add_address(cd, fi->value);
1438 if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
1439 patcher_add_patch_ref(jd, PATCHER_initialize_class,
1444 M_DSEG_LOAD(REG_ITMP3, disp);
1445 switch (fieldtype) {
1447 #if defined(ENABLE_SOFTFLOAT)
1451 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1452 M_IST_INTERN(s1, REG_ITMP3, 0);
1455 #if defined(ENABLE_SOFTFLOAT)
1458 s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
1459 M_LST_INTERN(s1, REG_ITMP3, 0);
1461 #if !defined(ENABLE_SOFTFLOAT)
1463 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1464 M_FST_INTERN(s1, REG_ITMP3, 0);
1467 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
1468 M_DST_INTERN(s1, REG_ITMP3, 0);
1476 case ICMD_GETFIELD: /* ..., objectref, value ==> ... */
1478 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1479 emit_nullpointer_check(cd, iptr, s1);
1482 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1483 uf = iptr->sx.s23.s3.uf;
1484 fieldtype = uf->fieldref->parseddesc.fd->type;
1488 fi = iptr->sx.s23.s3.fmiref->p.field;
1489 fieldtype = fi->type;
1493 #if !defined(ENABLE_SOFTFLOAT)
1494 /* HACK: softnull checks on floats */
1495 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1496 emit_nullpointer_check_force(cd, iptr, s1);
1499 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1501 uf = iptr->sx.s23.s3.uf;
1503 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1506 switch (fieldtype) {
1508 #if defined(ENABLE_SOFTFLOAT)
1512 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
1516 #if defined(ENABLE_SOFTFLOAT)
1519 d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
1522 #if !defined(ENABLE_SOFTFLOAT)
1524 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1528 d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
1535 emit_store_dst(jd, iptr, d);
1538 case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
1540 s1 = emit_load_s1(jd, iptr, REG_ITMP3);
1541 emit_nullpointer_check(cd, iptr, s1);
1543 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1544 uf = iptr->sx.s23.s3.uf;
1545 fieldtype = uf->fieldref->parseddesc.fd->type;
1549 fi = iptr->sx.s23.s3.fmiref->p.field;
1550 fieldtype = fi->type;
1554 #if !defined(ENABLE_SOFTFLOAT)
1555 /* HACK: softnull checks on floats */
1556 if (!INSTRUCTION_MUST_CHECK(iptr) && IS_FLT_DBL_TYPE(fieldtype))
1557 emit_nullpointer_check_force(cd, iptr, s1);
1560 switch (fieldtype) {
1562 #if defined(ENABLE_SOFTFLOAT)
1566 s2 = emit_load_s2(jd, iptr, REG_ITMP1);
1568 #if defined(ENABLE_SOFTFLOAT)
1569 case TYPE_DBL: /* fall through */
1572 s2 = emit_load_s2(jd, iptr, REG_ITMP12_PACKED);
1574 #if !defined(ENABLE_SOFTFLOAT)
1577 s2 = emit_load_s2(jd, iptr, REG_FTMP1);
1584 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1586 uf = iptr->sx.s23.s3.uf;
1588 patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
1591 switch (fieldtype) {
1593 #if defined(ENABLE_SOFTFLOAT)
1597 M_IST(s2, s1, disp);
1600 #if defined(ENABLE_SOFTFLOAT)
1603 M_LST(s2, s1, disp);
1605 #if !defined(ENABLE_SOFTFLOAT)
1607 M_FST(s2, s1, disp);
1610 M_DST(s2, s1, disp);
1619 /* branch operations **************************************************/
1621 case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
1623 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1624 M_INTMOVE(s1, REG_ITMP1_XPTR);
1625 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1626 patcher_add_patch_ref(jd, PATCHER_resolve_class,
1627 iptr->sx.s23.s2.uc, 0);
1629 disp = dseg_add_functionptr(cd, asm_handle_exception);
1630 M_DSEG_LOAD(REG_ITMP3, disp);
1631 M_MOV(REG_ITMP2_XPC, REG_PC);
1632 M_MOV(REG_PC, REG_ITMP3);
1633 M_NOP; /* nop ensures that XPC is less than the end */
1634 /* of basic block */
1637 case ICMD_GOTO: /* ... ==> ... */
1640 emit_br(cd, iptr->dst.block);
1643 case ICMD_JSR: /* ... ==> ... */
1645 emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
1648 case ICMD_IFNULL: /* ..., value ==> ... */
1649 case ICMD_IFNONNULL:
1651 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1653 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, BRANCH_OPT_NONE);
1656 case ICMD_IFLT: /* ..., value ==> ... */
1657 case ICMD_IFLE: /* op1 = target JavaVM pc, val.i = constant */
1663 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1664 M_COMPARE(s1, iptr->sx.val.i);
1665 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IFEQ, BRANCH_OPT_NONE);
1668 case ICMD_IF_LEQ: /* ..., value ==> ... */
1670 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1671 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1672 if (iptr->sx.val.l == 0) {
1673 M_ORR_S(s1, s2, REG_ITMP3);
1676 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1677 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1678 M_CMP(s1, REG_ITMP3);*/
1679 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1680 M_CMPEQ(s2, REG_ITMP3);
1682 emit_beq(cd, iptr->dst.block);
1685 case ICMD_IF_LLT: /* ..., value ==> ... */
1687 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1688 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1689 if (iptr->sx.val.l == 0) {
1690 /* if high word is less than zero, the whole long is too */
1692 emit_blt(cd, iptr->dst.block);
1695 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1696 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1697 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1698 M_CMP(s1, REG_ITMP3);*/
1699 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1700 M_MOVGT_IMM(2, REG_ITMP1);
1701 M_MOVEQ_IMM(1, REG_ITMP1);
1703 /* low compare: x=x-1(ifLO) */
1704 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1705 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1706 M_CMP(s2, REG_ITMP3);*/
1707 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1709 /* branch if (x LT 1) */
1710 M_CMP_IMM(REG_ITMP1, 1);
1711 emit_blt(cd, iptr->dst.block);
1715 case ICMD_IF_LLE: /* ..., value ==> ... */
1717 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1718 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1719 if (iptr->sx.val.l == 0) {
1720 /* if high word is less than zero, the whole long is too */
1722 emit_blt(cd, iptr->dst.block);
1724 /* ... otherwise the low word has to be zero (tricky!) */
1726 emit_beq(cd, iptr->dst.block);
1729 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1730 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1731 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1732 M_CMP(s1, REG_ITMP3);*/
1733 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1734 M_MOVGT_IMM(2, REG_ITMP1);
1735 M_MOVEQ_IMM(1, REG_ITMP1);
1737 /* low compare: x=x+1(ifHI) */
1738 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1739 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1740 M_CMP(s2, REG_ITMP3);*/
1741 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1743 /* branch if (x LE 1) */
1744 M_CMP_IMM(REG_ITMP1, 1);
1745 emit_ble(cd, iptr->dst.block);
1749 case ICMD_IF_LGE: /* ..., value ==> ... */
1751 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1752 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1753 if (iptr->sx.val.l == 0) {
1754 /* if high word is greater or equal zero, the whole long is too */
1756 emit_bge(cd, iptr->dst.block);
1759 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1760 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1761 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1762 M_CMP(s1, REG_ITMP3);*/
1763 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1764 M_MOVGT_IMM(2, REG_ITMP1);
1765 M_MOVEQ_IMM(1, REG_ITMP1);
1767 /* low compare: x=x-1(ifLO) */
1768 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1769 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1770 M_CMP(s2, REG_ITMP3);*/
1771 M_SUBLO_IMM(REG_ITMP1, REG_ITMP1, 1);
1773 /* branch if (x GE 1) */
1774 M_CMP_IMM(REG_ITMP1, 1);
1775 emit_bge(cd, iptr->dst.block);
1779 case ICMD_IF_LGT: /* ..., value ==> ... */
1781 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1782 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1784 if (iptr->sx.val.l == 0) {
1785 /* if high word is greater than zero, the whole long is too */
1788 codegen_add_branch_ref(cd, iptr->dst.block);
1790 /* ... or high was zero and low is non zero (tricky!) */
1791 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1792 M_MOVLT_IMM(1, REG_ITMP3);
1793 M_ORR_S(REG_ITMP3, s2, REG_ITMP3);
1795 codegen_add_branch_ref(cd, iptr->dst.block);
1799 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1800 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1801 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1802 M_CMP(s1, REG_ITMP3);*/
1803 M_EOR(REG_ITMP1, REG_ITMP1, REG_ITMP1);
1804 M_MOVGT_IMM(2, REG_ITMP1);
1805 M_MOVEQ_IMM(1, REG_ITMP1);
1807 /* low compare: x=x+1(ifHI) */
1808 M_COMPARE(s2, (iptr->sx.val.l & 0xffffffff));
1809 /*ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1810 M_CMP(s2, REG_ITMP3);*/
1811 M_ADDHI_IMM(REG_ITMP1, REG_ITMP1, 1);
1813 /* branch if (x GT 1) */
1814 M_CMP_IMM(REG_ITMP1, 1);
1815 emit_bgt(cd, iptr->dst.block);
1821 case ICMD_IF_LNE: /* ..., value ==> ... */
1823 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1824 s2 = emit_load_s1_low(jd, iptr, REG_ITMP2);
1825 if (iptr->sx.val.l == 0) {
1826 M_ORR_S(s1, s2, REG_ITMP3);
1829 M_COMPARE(s1, (iptr->sx.val.l >> 32));
1830 /*ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
1831 M_CMP(s1, REG_ITMP3);*/
1832 ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
1833 M_CMPEQ(s2, REG_ITMP3);
1835 emit_bne(cd, iptr->dst.block);
1838 case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
1839 case ICMD_IF_ICMPNE:
1840 case ICMD_IF_ICMPLT:
1841 case ICMD_IF_ICMPLE:
1842 case ICMD_IF_ICMPGT:
1843 case ICMD_IF_ICMPGE:
1845 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1846 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1848 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ICMPEQ, BRANCH_OPT_NONE);
1851 case ICMD_IF_ACMPEQ: /* ..., value, value ==> ... */
1852 case ICMD_IF_ACMPNE:
1854 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1855 s2 = emit_load_s2(jd, iptr, REG_ITMP2);
1857 emit_bcc(cd, iptr->dst.block, iptr->opc - ICMD_IF_ACMPEQ, BRANCH_OPT_NONE);
1860 case ICMD_IF_LCMPEQ: /* ..., value, value ==> ... */
1861 /* op1 = target JavaVM pc */
1863 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1864 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1867 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1868 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1871 emit_beq(cd, iptr->dst.block);
1874 case ICMD_IF_LCMPNE: /* ..., value, value ==> ... */
1875 /* op1 = target JavaVM pc */
1877 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1878 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1881 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1882 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1885 emit_bne(cd, iptr->dst.block);
1888 case ICMD_IF_LCMPLT: /* ..., value, value ==> ... */
1889 /* op1 = target JavaVM pc */
1891 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1892 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1893 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1895 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1896 M_MOVGT_IMM(2, REG_ITMP3);
1897 M_MOVEQ_IMM(1, REG_ITMP3);
1899 /* low compare: x=x-1(ifLO) */
1900 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1901 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1903 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1905 /* branch if (x LT 1) */
1906 M_CMP_IMM(REG_ITMP3, 1);
1907 emit_blt(cd, iptr->dst.block);
1910 case ICMD_IF_LCMPLE: /* ..., value, value ==> ... */
1911 /* op1 = target JavaVM pc */
1913 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1914 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1915 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1917 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1918 M_MOVGT_IMM(2, REG_ITMP3);
1919 M_MOVEQ_IMM(1, REG_ITMP3);
1921 /* low compare: x=x-1(ifLO) */
1922 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1923 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1925 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1927 /* branch if (x LE 1) */
1928 M_CMP_IMM(REG_ITMP3, 1);
1929 emit_ble(cd, iptr->dst.block);
1932 case ICMD_IF_LCMPGT: /* ..., value, value ==> ... */
1933 /* op1 = target JavaVM pc */
1935 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1936 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1937 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1939 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1940 M_MOVGT_IMM(2, REG_ITMP3);
1941 M_MOVEQ_IMM(1, REG_ITMP3);
1943 /* low compare: x=x-1(ifLO) */
1944 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1945 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1947 M_ADDHI_IMM(REG_ITMP3, REG_ITMP3, 1);
1949 /* branch if (x GT 1) */
1950 M_CMP_IMM(REG_ITMP3, 1);
1951 emit_bgt(cd, iptr->dst.block);
1954 case ICMD_IF_LCMPGE: /* ..., value, value ==> ... */
1955 /* op1 = target JavaVM pc */
1957 /* high compare: x=0(ifLT) ; x=1(ifEQ) ; x=2(ifGT) */
1958 s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
1959 s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
1961 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
1962 M_MOVGT_IMM(2, REG_ITMP3);
1963 M_MOVEQ_IMM(1, REG_ITMP3);
1965 /* low compare: x=x-1(ifLO) */
1966 s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
1967 s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
1969 M_SUBLO_IMM(REG_ITMP3, REG_ITMP3, 1);
1971 /* branch if (x GE 1) */
1972 M_CMP_IMM(REG_ITMP3, 1);
1973 emit_bge(cd, iptr->dst.block);
1976 case ICMD_TABLESWITCH: /* ..., index ==> ... */
1979 branch_target_t *table;
1981 table = iptr->dst.table;
1983 l = iptr->sx.s23.s2.tablelow;
1984 i = iptr->sx.s23.s3.tablehigh;
1986 /* calculate new index (index - low) */
1987 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
1989 M_INTMOVE(s1, REG_ITMP1);
1990 } else if (IS_IMM(l)) {
1991 M_SUB_IMM(REG_ITMP1, s1, l);
1993 ICONST(REG_ITMP2, l);
1994 M_SUB(REG_ITMP1, s1, REG_ITMP2);
1997 /* range check (index <= high-low) */
1999 M_COMPARE(REG_ITMP1, i-1);
2000 emit_bugt(cd, table[0].block);
2002 /* build jump table top down and use address of lowest entry */
2007 dseg_add_target(cd, table->block);
2012 /* length of dataseg after last dseg_add_target is used by load */
2013 /* TODO: this loads from data-segment */
2014 M_ADD(REG_ITMP2, REG_PV, REG_LSL(REG_ITMP1, 2));
2015 M_LDR(REG_PC, REG_ITMP2, -(cd->dseglen));
2018 case ICMD_LOOKUPSWITCH: /* ..., key ==> ... */
2021 lookup_target_t *lookup;
2023 lookup = iptr->dst.lookup;
2025 i = iptr->sx.s23.s2.lookupcount;
2028 MCODECHECK((i<<2)+8);
2029 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2032 M_COMPARE(s1, lookup->value);
2033 emit_beq(cd, lookup->target.block);
2037 /* default branch */
2038 emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
2042 case ICMD_FRETURN: /* ..., retvalue ==> ... */
2044 #if !defined(ENABLE_SOFTFLOAT)
2045 REPLACEMENT_POINT_RETURN(cd, iptr);
2046 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2047 M_CAST_F2I(s1, REG_RESULT);
2048 goto ICMD_RETURN_do;
2051 case ICMD_IRETURN: /* ..., retvalue ==> ... */
2053 REPLACEMENT_POINT_RETURN(cd, iptr);
2054 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2055 M_INTMOVE(s1, REG_RESULT);
2056 goto ICMD_RETURN_do;
2058 case ICMD_DRETURN: /* ..., retvalue ==> ... */
2060 #if !defined(ENABLE_SOFTFLOAT)
2061 REPLACEMENT_POINT_RETURN(cd, iptr);
2062 s1 = emit_load_s1(jd, iptr, REG_FTMP1);
2063 M_CAST_D2L(s1, REG_RESULT_PACKED);
2064 goto ICMD_RETURN_do;
2067 case ICMD_LRETURN: /* ..., retvalue ==> ... */
2069 REPLACEMENT_POINT_RETURN(cd, iptr);
2070 s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
2071 M_LNGMOVE(s1, REG_RESULT_PACKED);
2072 goto ICMD_RETURN_do;
2074 case ICMD_ARETURN: /* ..., retvalue ==> ... */
2076 REPLACEMENT_POINT_RETURN(cd, iptr);
2077 s1 = emit_load_s1(jd, iptr, REG_RESULT);
2078 M_INTMOVE(s1, REG_RESULT);
2079 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2080 patcher_add_patch_ref(jd, PATCHER_resolve_class,
2081 iptr->sx.s23.s2.uc, 0);
2083 goto ICMD_RETURN_do;
2085 case ICMD_RETURN: /* ... ==> ... */
2087 REPLACEMENT_POINT_RETURN(cd, iptr);
2090 #if !defined(NDEBUG)
2091 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2092 emit_verbosecall_exit(jd);
2095 #if defined(ENABLE_THREADS)
2096 /* call monitorexit function */
2098 if (checksync && code_is_synchronized(code)) {
2099 /* stack offset for monitor argument */
2101 s1 = rd->memuse * 8;
2103 /* we need to save the proper return value */
2105 switch (iptr->opc) {
2109 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2111 M_STMFD(BITMASK_RESULT, REG_SP);
2116 M_LDR(REG_A0, REG_SP, s1);
2117 disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
2118 M_DSEG_BRANCH(disp);
2120 /* we no longer need PV here, no more loading */
2121 /*s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2122 M_RECOMPUTE_PV(s1);*/
2124 switch (iptr->opc) {
2128 case ICMD_FRETURN: /* XXX TWISTI: is that correct? */
2130 M_LDMFD(BITMASK_RESULT, REG_SP);
2136 /* deallocate stackframe for spilled variables */
2138 if ((cd->stackframesize / 4 - savedregs_num) > 0)
2139 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - savedregs_num);
2141 /* restore callee saved registers + do return */
2143 if (savedregs_bitmask) {
2144 if (!code_is_leafmethod(code)) {
2145 savedregs_bitmask &= ~(1<<REG_LR);
2146 savedregs_bitmask |= (1<<REG_PC);
2148 M_LDMFD(savedregs_bitmask, REG_SP);
2151 /* if LR was not on stack, we need to return manually */
2153 if (code_is_leafmethod(code))
2154 M_MOV(REG_PC, REG_LR);
2157 case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
2159 bte = iptr->sx.s23.s3.bte;
2161 goto ICMD_INVOKE_do;
2163 case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
2164 case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
2165 case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
2166 case ICMD_INVOKEINTERFACE:
2168 REPLACEMENT_POINT_INVOKE(cd, iptr);
2170 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2172 um = iptr->sx.s23.s3.um;
2173 md = um->methodref->parseddesc.md;
2176 lm = iptr->sx.s23.s3.fmiref->p.method;
2178 md = lm->parseddesc;
2182 /* copy arguments to registers or stack location */
2184 s3 = md->paramcount;
2186 MCODECHECK((s3 << 1) + 64);
2188 for (s3 = s3 - 1; s3 >= 0; s3--) {
2189 var = VAR(iptr->sx.s23.s2.args[s3]);
2190 d = md->params[s3].regoff;
2192 if (var->flags & PREALLOC) /* argument was precolored? */
2195 /* TODO: document me */
2196 #if !defined(ENABLE_SOFTFLOAT)
2197 if (IS_INT_LNG_TYPE(var->type)) {
2198 #endif /* !defined(ENABLE_SOFTFLOAT) */
2199 if (!md->params[s3].inmemory) {
2200 s1 = emit_load(jd, iptr, var, d);
2202 if (IS_2_WORD_TYPE(var->type))
2208 if (IS_2_WORD_TYPE(var->type)) {
2209 s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
2210 M_LST(s1, REG_SP, d);
2213 s1 = emit_load(jd, iptr, var, REG_ITMP1);
2214 M_IST(s1, REG_SP, d);
2217 #if !defined(ENABLE_SOFTFLOAT)
2220 if (!md->params[s3].inmemory) {
2221 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2222 if (IS_2_WORD_TYPE(var->type))
2228 s1 = emit_load(jd, iptr, var, REG_FTMP1);
2229 if (IS_2_WORD_TYPE(var->type))
2230 M_DST(s1, REG_SP, d);
2232 M_FST(s1, REG_SP, d);
2235 #endif /* !defined(ENABLE_SOFTFLOAT) */
2238 switch (iptr->opc) {
2241 if (bte->stub == NULL) {
2242 disp = dseg_add_functionptr(cd, bte->fp);
2244 disp = dseg_add_functionptr(cd, bte->stub);
2247 M_DSEG_LOAD(REG_PV, disp); /* pointer to built-in-function */
2249 /* generate the actual call */
2251 M_MOV(REG_LR, REG_PC);
2252 M_MOV(REG_PC, REG_PV);
2253 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2257 case ICMD_INVOKESPECIAL:
2258 emit_nullpointer_check(cd, iptr, REG_A0);
2261 case ICMD_INVOKESTATIC:
2263 disp = dseg_add_unique_address(cd, NULL);
2265 patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
2269 disp = dseg_add_address(cd, lm->stubroutine);
2271 M_DSEG_LOAD(REG_PV, disp); /* Pointer to method */
2273 /* generate the actual call */
2275 M_MOV(REG_LR, REG_PC);
2276 M_MOV(REG_PC, REG_PV);
2277 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2281 case ICMD_INVOKEVIRTUAL:
2283 patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
2288 s1 = OFFSET(vftbl_t, table[0]) +
2289 sizeof(methodptr) * lm->vftblindex;
2291 /* implicit null-pointer check */
2292 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2293 OFFSET(java_object_t, vftbl));
2294 M_LDR_INTERN(REG_PV, REG_METHODPTR, s1);
2296 /* generate the actual call */
2298 M_MOV(REG_LR, REG_PC);
2299 M_MOV(REG_PC, REG_PV);
2300 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2304 case ICMD_INVOKEINTERFACE:
2306 patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
2312 s1 = OFFSET(vftbl_t, interfacetable[0]) -
2313 sizeof(methodptr*) * lm->clazz->index;
2314 s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
2317 /* implicit null-pointer check */
2318 M_LDR_INTERN(REG_METHODPTR, REG_A0,
2319 OFFSET(java_object_t, vftbl));
2320 M_LDR_INTERN(REG_METHODPTR, REG_METHODPTR, s1);
2321 M_LDR_INTERN(REG_PV, REG_METHODPTR, s2);
2323 /* generate the actual call */
2325 M_MOV(REG_LR, REG_PC);
2326 M_MOV(REG_PC, REG_PV);
2327 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2332 /* store size of call code in replacement point */
2333 REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
2335 /* store return value */
2337 d = md->returntype.type;
2339 #if !defined(__SOFTFP__)
2340 /* TODO: this is only a hack, since we use R0/R1 for float
2341 return! this depends on gcc; it is independent from
2342 our ENABLE_SOFTFLOAT define */
2343 if (iptr->opc == ICMD_BUILTIN && d != TYPE_VOID && IS_FLT_DBL_TYPE(d)) {
2344 #if 0 && !defined(NDEBUG)
2345 dolog("BUILTIN that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
2347 /* we cannot use this macro, since it is not defined
2348 in ENABLE_SOFTFLOAT M_CAST_FLT_TO_INT_TYPED(d,
2349 REG_FRESULT, REG_RESULT_TYPED(d)); */
2350 if (IS_2_WORD_TYPE(d)) {
2351 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
2352 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
2354 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
2355 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
2360 if (d != TYPE_VOID) {
2361 #if !defined(ENABLE_SOFTFLOAT)
2362 if (IS_INT_LNG_TYPE(d)) {
2363 #endif /* !defined(ENABLE_SOFTFLOAT) */
2364 if (IS_2_WORD_TYPE(d)) {
2365 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
2366 M_LNGMOVE(REG_RESULT_PACKED, s1);
2369 s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2370 M_INTMOVE(REG_RESULT, s1);
2373 #if !defined(ENABLE_SOFTFLOAT)
2375 s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
2376 if (IS_2_WORD_TYPE(d))
2377 M_CAST_L2D(REG_RESULT_PACKED, s1);
2379 M_CAST_I2F(REG_RESULT, s1);
2381 #endif /* !defined(ENABLE_SOFTFLOAT) */
2383 emit_store_dst(jd, iptr, s1);
2387 case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
2389 if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
2390 /* object type cast-check */
2395 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2400 super = iptr->sx.s23.s3.c.cls;
2401 superindex = super->index;
2404 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2406 /* if class is not resolved, check which code to call */
2408 if (super == NULL) {
2410 emit_label_beq(cd, BRANCH_LABEL_1);
2412 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2413 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2414 iptr->sx.s23.s3.c.ref, disp);
2416 M_DSEG_LOAD(REG_ITMP2, disp);
2417 disp = dseg_add_s4(cd, ACC_INTERFACE);
2418 M_DSEG_LOAD(REG_ITMP3, disp);
2419 M_TST(REG_ITMP2, REG_ITMP3);
2420 emit_label_beq(cd, BRANCH_LABEL_2);
2423 /* interface checkcast code */
2425 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2426 if ((super == NULL) || !IS_IMM(superindex)) {
2427 disp = dseg_add_unique_s4(cd, superindex);
2429 if (super == NULL) {
2430 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2431 iptr->sx.s23.s3.c.ref, disp);
2435 emit_label_beq(cd, BRANCH_LABEL_3);
2438 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2439 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
2441 /* we put unresolved or non-immediate superindices onto dseg */
2442 if ((super == NULL) || !IS_IMM(superindex)) {
2443 /* disp was computed before we added the patcher */
2444 M_DSEG_LOAD(REG_ITMP2, disp);
2445 M_CMP(REG_ITMP3, REG_ITMP2);
2447 assert(IS_IMM(superindex));
2448 M_CMP_IMM(REG_ITMP3, superindex);
2451 emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
2453 /* if we loaded the superindex out of the dseg above, we do
2454 things differently here! */
2455 if ((super == NULL) || !IS_IMM(superindex)) {
2457 M_LDR_INTERN(REG_ITMP3, s1, OFFSET(java_object_t, vftbl));
2459 /* this assumes something */
2460 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2462 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2463 assert(sizeof(methodptr*) == 4);
2464 M_SUB(REG_ITMP2, REG_ITMP3, REG_LSL(REG_ITMP2, 2));
2470 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2471 superindex * sizeof(methodptr*);
2475 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, s2);
2476 M_TST(REG_ITMP3, REG_ITMP3);
2477 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
2480 emit_label_br(cd, BRANCH_LABEL_4);
2482 emit_label(cd, BRANCH_LABEL_3);
2485 /* class checkcast code */
2487 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2488 if (super == NULL) {
2489 emit_label(cd, BRANCH_LABEL_2);
2491 disp = dseg_add_unique_address(cd, NULL);
2493 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2494 iptr->sx.s23.s3.c.ref,
2498 disp = dseg_add_address(cd, super->vftbl);
2501 emit_label_beq(cd, BRANCH_LABEL_5);
2504 M_LDR_INTERN(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
2505 M_DSEG_LOAD(REG_ITMP3, disp);
2507 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
2508 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
2509 M_SUB(REG_ITMP2, REG_ITMP2, REG_ITMP3);
2510 M_DSEG_LOAD(REG_ITMP3, disp);
2511 M_LDR_INTERN(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
2513 M_CMP(REG_ITMP2, REG_ITMP3);
2514 emit_classcast_check(cd, iptr, BRANCH_UGT, 0, s1);
2517 emit_label(cd, BRANCH_LABEL_5);
2520 if (super == NULL) {
2521 emit_label(cd, BRANCH_LABEL_1);
2522 emit_label(cd, BRANCH_LABEL_4);
2525 d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
2528 /* array type cast-check */
2530 s1 = emit_load_s1(jd, iptr, REG_A0);
2531 M_INTMOVE(s1, REG_A0);
2533 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2534 disp = dseg_add_unique_address(cd, NULL);
2536 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2537 iptr->sx.s23.s3.c.ref,
2541 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2543 M_DSEG_LOAD(REG_A1, disp);
2544 disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
2545 M_DSEG_BRANCH(disp);
2548 disp = (s4) (cd->mcodeptr - cd->mcodebase);
2549 M_RECOMPUTE_PV(disp);
2551 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2552 M_TST(REG_RESULT, REG_RESULT);
2553 emit_classcast_check(cd, iptr, BRANCH_EQ, REG_RESULT, s1);
2555 d = codegen_reg_of_dst(jd, iptr, s1);
2559 emit_store_dst(jd, iptr, d);
2562 case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
2568 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2573 super = iptr->sx.s23.s3.c.cls;
2574 superindex = super->index;
2577 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2578 d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
2581 M_MOV(REG_ITMP1, s1);
2585 /* if class is not resolved, check which code to call */
2587 if (super == NULL) {
2591 emit_label_beq(cd, BRANCH_LABEL_1);
2593 disp = dseg_add_unique_s4(cd, 0); /* super->flags */
2594 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
2595 iptr->sx.s23.s3.c.ref, disp);
2597 M_DSEG_LOAD(REG_ITMP2, disp);
2598 disp = dseg_add_s4(cd, ACC_INTERFACE);
2599 M_DSEG_LOAD(REG_ITMP3, disp);
2600 M_TST(REG_ITMP2, REG_ITMP3);
2601 emit_label_beq(cd, BRANCH_LABEL_2);
2604 /* interface checkcast code */
2606 if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
2607 if ((super == NULL) || !IS_IMM(superindex)) {
2608 disp = dseg_add_unique_s4(cd, superindex);
2610 if (super == NULL) {
2611 /* If d == REG_ITMP2, then it's destroyed in check
2616 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_index,
2617 iptr->sx.s23.s3.c.ref, disp);
2622 emit_label_beq(cd, BRANCH_LABEL_3);
2625 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2626 M_LDR_INTERN(REG_ITMP3,
2627 REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
2629 /* we put unresolved or non-immediate superindices onto dseg
2630 and do things slightly different */
2631 if ((super == NULL) || !IS_IMM(superindex)) {
2632 /* disp was computed before we added the patcher */
2633 M_DSEG_LOAD(REG_ITMP2, disp);
2634 M_CMP(REG_ITMP3, REG_ITMP2);
2636 if (d == REG_ITMP2) {
2643 /* this assumes something */
2644 assert(OFFSET(vftbl_t, interfacetable[0]) == 0);
2646 /* this does: REG_ITMP3 - superindex * sizeof(methodptr*) */
2647 assert(sizeof(methodptr*) == 4);
2648 M_SUB(REG_ITMP1, REG_ITMP1, REG_LSL(REG_ITMP2, 2));
2650 if (d == REG_ITMP2) {
2657 assert(IS_IMM(superindex));
2658 M_CMP_IMM(REG_ITMP3, superindex);
2662 s2 = OFFSET(vftbl_t, interfacetable[0]) -
2663 superindex * sizeof(methodptr*);
2667 M_LDR_INTERN(REG_ITMP3, REG_ITMP1, s2);
2668 M_TST(REG_ITMP3, REG_ITMP3);
2672 emit_label_br(cd, BRANCH_LABEL_4);
2674 emit_label(cd, BRANCH_LABEL_3);
2677 /* class checkcast code */
2679 if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
2680 if (super == NULL) {
2681 emit_label(cd, BRANCH_LABEL_2);
2683 disp = dseg_add_unique_address(cd, NULL);
2685 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
2686 iptr->sx.s23.s3.c.ref, disp);
2689 disp = dseg_add_address(cd, super->vftbl);
2693 emit_label_beq(cd, BRANCH_LABEL_5);
2696 M_LDR_INTERN(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
2697 M_DSEG_LOAD(REG_ITMP2, disp);
2699 M_LDR_INTERN(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
2700 M_LDR_INTERN(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
2701 M_LDR_INTERN(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
2703 M_SUB(REG_ITMP1, REG_ITMP1, REG_ITMP3);
2704 M_CMP(REG_ITMP1, REG_ITMP2);
2705 /* If d == REG_ITMP2, then it's destroyed */
2711 emit_label(cd, BRANCH_LABEL_5);
2714 if (super == NULL) {
2715 emit_label(cd, BRANCH_LABEL_1);
2716 emit_label(cd, BRANCH_LABEL_4);
2721 emit_store_dst(jd, iptr, d);
2724 case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
2726 /* copy sizes to stack if necessary */
2728 MCODECHECK((iptr->s1.argcount << 1) + 64);
2730 for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
2732 var = VAR(iptr->sx.s23.s2.args[s1]);
2734 /* copy SAVEDVAR sizes to stack */
2736 if (!(var->flags & PREALLOC)) {
2737 s2 = emit_load(jd, iptr, var, REG_ITMP1);
2738 M_STR(s2, REG_SP, s1 * 4);
2742 /* a0 = dimension count */
2744 assert(IS_IMM(iptr->s1.argcount));
2745 M_MOV_IMM(REG_A0, iptr->s1.argcount);
2747 /* is patcher function set? */
2749 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
2750 disp = dseg_add_unique_address(cd, NULL);
2752 patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
2753 iptr->sx.s23.s3.c.ref, disp);
2756 disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
2758 /* a1 = arraydescriptor */
2760 M_DSEG_LOAD(REG_A1, disp);
2762 /* a2 = pointer to dimensions = stack pointer */
2764 M_INTMOVE(REG_SP, REG_A2);
2766 /* call builtin_multianewarray here */
2768 disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
2769 M_DSEG_BRANCH(disp);
2773 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2776 /* check for exception before result assignment */
2778 emit_exception_check(cd, iptr);
2782 d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
2783 M_INTMOVE(REG_RESULT, d);
2784 emit_store_dst(jd, iptr, d);
2787 case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
2789 s1 = emit_load_s1(jd, iptr, REG_ITMP1);
2790 emit_nullpointer_check(cd, iptr, s1);
2794 exceptions_throw_internalerror("Unknown ICMD %d during code generation",
2797 } /* the big switch */
2799 } /* for all instructions */
2801 } /* for all basic blocks */
2803 /* generate traps */
2805 emit_patcher_traps(jd);
2807 /* everything's ok */
2813 /* codegen_emit_stub_compiler **************************************************
2815 Emits a stub routine which calls the compiler.
2817 *******************************************************************************/
2819 void codegen_emit_stub_compiler(jitdata *jd)
2824 /* get required compiler data */
2829 /* code for the stub */
2831 M_LDR_INTERN(REG_ITMP1, REG_PC, -(2 * 4 + 2 * SIZEOF_VOID_P));
2832 M_LDR_INTERN(REG_PC, REG_PC, -(3 * 4 + 3 * SIZEOF_VOID_P));
2836 /* codegen_emit_stub_native ****************************************************
2838 Emits a stub routine which calls a native method.
2840 *******************************************************************************/
2842 void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
2853 /* get required compiler data */
2859 /* initialize variables */
2863 /* calculate stackframe size */
2865 cd->stackframesize =
2866 4 + /* return address */
2867 sizeof(stackframeinfo_t) + /* stackframeinfo */
2868 sizeof(localref_table) + /* localref_table */
2869 nmd->memuse * 4; /* stack arguments */
2871 /* align stack to 8-byte */
2873 cd->stackframesize = (cd->stackframesize + 4) & ~4;
2875 /* create method header */
2877 (void) dseg_add_unique_address(cd, code); /* CodeinfoPointer */
2878 (void) dseg_add_unique_s4(cd, cd->stackframesize); /* FrameSize */
2879 (void) dseg_add_unique_s4(cd, 0); /* IsLeaf */
2880 (void) dseg_add_unique_s4(cd, 0); /* IntSave */
2881 (void) dseg_add_unique_s4(cd, 0); /* FltSave */
2883 /* generate stub code */
2885 M_STMFD(1<<REG_LR, REG_SP);
2886 M_SUB_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
2888 #if !defined(NDEBUG)
2889 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
2890 emit_verbosecall_enter(jd);
2893 #if defined(ENABLE_GC_CACAO)
2894 /* Save callee saved integer registers in stackframeinfo (GC may
2895 need to recover them during a collection). */
2897 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
2898 OFFSET(stackframeinfo_t, intregs);
2900 for (i = 0; i < INT_SAV_CNT; i++)
2901 M_STR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
2904 /* Save integer and float argument registers (these are 4
2905 registers, stack is 8-byte aligned). */
2907 M_STMFD(BITMASK_ARGS, REG_SP);
2908 /* TODO: floating point */
2910 /* create native stackframe info */
2912 M_ADD_IMM(REG_A0, REG_SP, 4*4);
2913 M_MOV(REG_A1, REG_PV);
2914 disp = dseg_add_functionptr(cd, codegen_start_native_call);
2915 M_DSEG_BRANCH(disp);
2919 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
2922 /* remember class argument */
2924 if (m->flags & ACC_STATIC)
2925 M_MOV(REG_ITMP3, REG_RESULT);
2927 /* Restore integer and float argument registers (these are 4
2928 registers, stack is 8-byte aligned). */
2930 M_LDMFD(BITMASK_ARGS, REG_SP);
2931 /* TODO: floating point */
2933 /* copy or spill arguments to new locations */
2934 /* ATTENTION: the ARM has only integer argument registers! */
2936 for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
2937 t = md->paramtypes[i].type;
2939 if (!md->params[i].inmemory) {
2940 s1 = md->params[i].regoff;
2941 s2 = nmd->params[j].regoff;
2943 if (!nmd->params[j].inmemory) {
2944 #if !defined(__ARM_EABI__)
2945 SPLIT_OPEN(t, s2, REG_ITMP1);
2948 if (IS_2_WORD_TYPE(t))
2953 #if !defined(__ARM_EABI__)
2954 SPLIT_STORE_AND_CLOSE(t, s2, 0);
2958 if (IS_2_WORD_TYPE(t))
2959 M_LST(s1, REG_SP, s2);
2961 M_IST(s1, REG_SP, s2);
2965 s1 = md->params[i].regoff + cd->stackframesize;
2966 s2 = nmd->params[j].regoff;
2968 if (IS_2_WORD_TYPE(t)) {
2969 M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
2970 M_LST(REG_ITMP12_PACKED, REG_SP, s2);
2973 M_ILD(REG_ITMP1, REG_SP, s1);
2974 M_IST(REG_ITMP1, REG_SP, s2);
2979 /* Handle native Java methods. */
2981 if (m->flags & ACC_NATIVE) {
2982 /* put class into second argument register */
2984 if (m->flags & ACC_STATIC)
2985 M_MOV(REG_A1, REG_ITMP3);
2987 /* put env into first argument register */
2989 disp = dseg_add_address(cd, VM_get_jnienv());
2990 M_DSEG_LOAD(REG_A0, disp);
2993 /* Call the native function. */
2995 disp = dseg_add_functionptr(cd, f);
2996 M_DSEG_BRANCH(disp);
2999 /* TODO: this is only needed because of the tracer ... do we
3002 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3005 #if !defined(__SOFTFP__)
3006 /* TODO: this is only a hack, since we use R0/R1 for float return! */
3007 /* this depends on gcc; it is independent from our ENABLE_SOFTFLOAT define */
3008 if (md->returntype.type != TYPE_VOID && IS_FLT_DBL_TYPE(md->returntype.type)) {
3009 #if 0 && !defined(NDEBUG)
3010 dolog("NATIVESTUB that returns float or double (%s.%s)", m->clazz->name->text, m->name->text);
3012 /* we cannot use this macro, since it is not defined in ENABLE_SOFTFLOAT */
3013 /* M_CAST_FLT_TO_INT_TYPED(md->returntype.type, REG_FRESULT, REG_RESULT_TYPED(md->returntype.type)); */
3014 if (IS_2_WORD_TYPE(md->returntype.type)) {
3015 DCD(0xed2d8102); /* stfd f0, [sp, #-8]! */
3016 M_LDRD_UPDATE(REG_RESULT_PACKED, REG_SP, 8);
3018 DCD(0xed2d0101); /* stfs f0, [sp, #-4]!*/
3019 M_LDR_UPDATE(REG_RESULT, REG_SP, 4);
3024 #if !defined(NDEBUG)
3025 if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
3026 emit_verbosecall_exit(jd);
3029 /* remove native stackframe info */
3030 /* TODO: improve this store/load */
3032 M_STMFD(BITMASK_RESULT, REG_SP);
3034 M_ADD_IMM(REG_A0, REG_SP, 2*4);
3035 M_MOV(REG_A1, REG_PV);
3036 disp = dseg_add_functionptr(cd, codegen_finish_native_call);
3037 M_DSEG_BRANCH(disp);
3038 s1 = (s4) (cd->mcodeptr - cd->mcodebase);
3041 M_MOV(REG_ITMP1_XPTR, REG_RESULT);
3042 M_LDMFD(BITMASK_RESULT, REG_SP);
3044 #if defined(ENABLE_GC_CACAO)
3045 /* restore callee saved int registers from stackframeinfo (GC might have */
3046 /* modified them during a collection). */
3048 disp = cd->stackframesize - SIZEOF_VOID_P - sizeof(stackframeinfo_t) +
3049 OFFSET(stackframeinfo_t, intregs);
3051 for (i = 0; i < INT_SAV_CNT; i++)
3052 M_LDR_INTERN(abi_registers_integer_saved[i], REG_SP, disp + i * 4);
3055 /* finish stub code, but do not yet return to caller */
3057 M_ADD_IMM_EXT_MUL4(REG_SP, REG_SP, cd->stackframesize / 4 - 1);
3058 M_LDMFD(1<<REG_LR, REG_SP);
3060 /* check for exception */
3062 M_TST(REG_ITMP1_XPTR, REG_ITMP1_XPTR);
3063 M_MOVEQ(REG_LR, REG_PC); /* if no exception, return to caller */
3065 /* handle exception here */
3067 M_SUB_IMM(REG_ITMP2_XPC, REG_LR, 4);/* move fault address into xpc */
3069 disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
3070 M_DSEG_LOAD(REG_ITMP3, disp); /* load asm exception handler address */
3071 M_MOV(REG_PC, REG_ITMP3); /* jump to asm exception handler */
3075 /* asm_debug *******************************************************************
3079 *******************************************************************************/
3081 void asm_debug(int a1, int a2, int a3, int a4)
3083 printf("===> i am going to exit after this debugging message!\n");
3084 printf("got asm_debug(%p, %p, %p, %p)\n",(void*)a1,(void*)a2,(void*)a3,(void*)a4);
3085 vm_abort("leave you now");
3090 * These are local overrides for various environment variables in Emacs.
3091 * Please do not remove this and leave it at the end of the file, where
3092 * Emacs will automagically detect them.
3093 * ---------------------------------------------------------------------
3096 * indent-tabs-mode: t
3100 * vim:noexpandtab:sw=4:ts=4: