-/* jit/alpha/codegen.c - machine code generator for alpha
+/* src/vm/jit/alpha/codegen.c - machine code generator for Alpha
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Institut f. Computersprachen, TU Wien
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
- S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
- J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Authors: Andreas Krall
Reinhard Grafl
- $Id: codegen.c 594 2003-11-09 19:54:50Z twisti $
+ Changes: Joseph Wenninger
+ Christian Thalinger
+ Christian Ullrich
+
+ $Id: codegen.c 3345 2005-10-04 22:14:53Z twisti $
*/
#include <stdio.h>
-#include <signal.h>
-#include "types.h"
-#include "codegen.h"
-#include "jit.h"
-#include "reg.h"
-#include "builtin.h"
-#include "asmpart.h"
-#include "jni.h"
-#include "loader.h"
-#include "tables.h"
-#include "native.h"
-
-/* include independent code generation stuff */
-#include "codegen.inc"
-#include "reg.inc"
-
-
-/* *****************************************************************************
-Datatypes and Register Allocations:
------------------------------------
-
-On 64-bit-machines (like the Alpha) all operands are stored in the
-registers in a 64-bit form, even when the correspondig JavaVM operands
-only need 32 bits. This is done by a canonical representation:
-
-32-bit integers are allways stored as sign-extended 64-bit values (this
-approach is directly supported by the Alpha architecture and is very easy
-to implement).
+#include "config.h"
+#include "vm/types.h"
+
+#include "md.h"
+#include "md-abi.h"
+#include "md-abi.inc"
+
+#include "vm/jit/alpha/arch.h"
+#include "vm/jit/alpha/codegen.h"
+
+#include "cacao/cacao.h"
+#include "native/native.h"
+#include "vm/builtin.h"
+#include "vm/global.h"
+#include "vm/loader.h"
+#include "vm/stringlocal.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
+#include "vm/jit/codegen.inc"
+#include "vm/jit/jit.h"
+
+#if defined(LSRA)
+# include "vm/jit/lsra.h"
+# include "vm/jit/lsra.inc"
+#endif
-32-bit-floats are stored in a 64-bit doubleprecision register by simply
-expanding the exponent and mantissa with zeroes. (also supported by the
-architecture)
+#include "vm/jit/parse.h"
+#include "vm/jit/patcher.h"
+#include "vm/jit/reg.h"
+#include "vm/jit/reg.inc"
-Stackframes:
+/* codegen *********************************************************************
-The calling conventions and the layout of the stack is explained in detail
-in the documention file: calling.doc
+ Generates machine code.
*******************************************************************************/
+void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
+{
+ s4 len, s1, s2, s3, d, disp;
+ ptrint a;
+ s4 parentargs_base;
+ s4 *mcodeptr;
+ stackptr src;
+ varinfo *var;
+ basicblock *bptr;
+ instruction *iptr;
+ exceptiontable *ex;
+ u2 currentline;
+ methodinfo *lm; /* local methodinfo for ICMD_INVOKE* */
+ builtintable_entry *bte;
+ methoddesc *md;
+
+ /* prevent compiler warnings */
+
+ d = 0;
+ currentline = 0;
+ lm = NULL;
+ bte = NULL;
-/* register descripton - array ************************************************/
-
-/* #define REG_RES 0 reserved register for OS or code generator */
-/* #define REG_RET 1 return value register */
-/* #define REG_EXC 2 exception value register (only old jit) */
-/* #define REG_SAV 3 (callee) saved register */
-/* #define REG_TMP 4 scratch temporary register (caller saved) */
-/* #define REG_ARG 5 argument register (caller saved) */
-
-/* #define REG_END -1 last entry in tables */
-
-int nregdescint[] = {
- REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
- REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
- REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
- REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
- REG_END };
-
-/* for use of reserved registers, see comment above */
-
-int nregdescfloat[] = {
- REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
- REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP,
- REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
- REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
- REG_END };
-
-/* for use of reserved registers, see comment above */
-
-
-/* parameter allocation mode */
-
-int nreg_parammode = PARAMMODE_NUMBERED;
-
- /* parameter-registers will be allocated by assigning the
- 1. parameter: int/float-reg 16
- 2. parameter: int/float-reg 17
- 3. parameter: int/float-reg 18 ....
- */
-
-
-/* stackframe-infos ***********************************************************/
-
-int parentargs_base; /* offset in stackframe for the parameter from the caller*/
-
-/* -> see file 'calling.doc' */
-
+ {
+ s4 i, p, t, l;
+ s4 savedregs_num;
-/* additional functions and macros to generate code ***************************/
+ savedregs_num = (m->isleafmethod) ? 0 : 1; /* space to save the RA */
-/* #define BlockPtrOfPC(pc) block+block_index[pc] */
-#define BlockPtrOfPC(pc) ((basicblock *) iptr->target)
+ /* space to save used callee saved registers */
+ savedregs_num += (INT_SAV_CNT - rd->savintreguse);
+ savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
-#ifdef STATISTICS
-#define COUNT_SPILLS count_spills++
-#else
-#define COUNT_SPILLS
-#endif
+ parentargs_base = rd->memuse + savedregs_num;
+#if defined(USE_THREADS) /* space to save argument of monitor_enter */
-/* gen_nullptr_check(objreg) */
+ if (checksync && (m->flags & ACC_SYNCHRONIZED))
+ parentargs_base++;
-#ifdef SOFTNULLPTRCHECK
-#define gen_nullptr_check(objreg) \
- if (checknull) {\
- M_BEQZ((objreg), 0);\
- codegen_addxnullrefs(mcodeptr);\
- }
-#else
-#define gen_nullptr_check(objreg)
#endif
+ /* create method header */
-/* MCODECHECK(icnt) */
-
-#define MCODECHECK(icnt) \
- if((mcodeptr + (icnt)) > mcodeend) mcodeptr = codegen_increase((u1*) mcodeptr)
-
-/* M_INTMOVE:
- generates an integer-move from register a to b.
- if a and b are the same int-register, no code will be generated.
-*/
-
-#define M_INTMOVE(a,b) if(a!=b){M_MOV(a,b);}
-
+ (void) dseg_addaddress(cd, m); /* MethodPointer */
+ (void) dseg_adds4(cd, parentargs_base * 8); /* FrameSize */
-/* M_FLTMOVE:
- generates a floating-point-move from register a to b.
- if a and b are the same float-register, no code will be generated
-*/
+#if defined(USE_THREADS)
-#define M_FLTMOVE(a,b) if(a!=b){M_FMOV(a,b);}
+ /* IsSync contains the offset relative to the stack pointer for the
+ argument of monitor_exit used in the exception handler. Since the
+ offset could be zero and give a wrong meaning of the flag it is
+ offset by one.
+ */
+ if (checksync && (m->flags & ACC_SYNCHRONIZED))
+ (void) dseg_adds4(cd, (rd->memuse + 1) * 8); /* IsSync */
+ else
-/* var_to_reg_xxx:
- this function generates code to fetch data from a pseudo-register
- into a real register.
- If the pseudo-register has actually been assigned to a real
- register, no code will be emitted, since following operations
- can use this register directly.
-
- v: pseudoregister to be fetched from
- tempregnum: temporary register to be used if v is actually spilled to ram
+#endif
- return: the register number, where the operand can be found after
- fetching (this wil be either tempregnum or the register
- number allready given to v)
-*/
+ (void) dseg_adds4(cd, 0); /* IsSync */
+
+ (void) dseg_adds4(cd, m->isleafmethod); /* IsLeaf */
+ (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse);/* IntSave */
+ (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse);/* FltSave */
-#define var_to_reg_int(regnr,v,tempnr) { \
- if ((v)->flags & INMEMORY) \
- {COUNT_SPILLS;M_LLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
- else regnr=(v)->regoff; \
-}
+ dseg_addlinenumbertablesize(cd);
+ (void) dseg_adds4(cd, cd->exceptiontablelength); /* ExTableSize */
-#define var_to_reg_flt(regnr,v,tempnr) { \
- if ((v)->flags & INMEMORY) \
- {COUNT_SPILLS;M_DLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
- else regnr=(v)->regoff; \
-}
+ /* create exception table */
+ for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
+ dseg_addtarget(cd, ex->start);
+ dseg_addtarget(cd, ex->end);
+ dseg_addtarget(cd, ex->handler);
+ (void) dseg_addaddress(cd, ex->catchtype.cls);
+ }
+
+ /* initialize mcode variables */
+
+ mcodeptr = (s4 *) cd->mcodebase;
+ cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
+ MCODECHECK(128 + m->paramcount);
-/* reg_of_var:
- This function determines a register, to which the result of an operation
- should go, when it is ultimatively intended to store the result in
- pseudoregister v.
- If v is assigned to an actual register, this register will be returned.
- Otherwise (when v is spilled) this function returns tempregnum.
- If not already done, regoff and flags are set in the stack location.
-*/
+ /* create stack frame (if necessary) */
-static int reg_of_var(stackptr v, int tempregnum)
-{
- varinfo *var;
-
- switch (v->varkind) {
- case TEMPVAR:
- if (!(v->flags & INMEMORY))
- return(v->regoff);
- break;
- case STACKVAR:
- var = &(interfaces[v->varnum][v->type]);
- v->regoff = var->regoff;
- if (!(var->flags & INMEMORY))
- return(var->regoff);
- break;
- case LOCALVAR:
- var = &(locals[v->varnum][v->type]);
- v->regoff = var->regoff;
- if (!(var->flags & INMEMORY))
- return(var->regoff);
- break;
- case ARGVAR:
- v->regoff = v->varnum;
- if (IS_FLT_DBL_TYPE(v->type)) {
- if (v->varnum < fltreg_argnum) {
- v->regoff = argfltregs[v->varnum];
- return(argfltregs[v->varnum]);
- }
- }
- else
- if (v->varnum < intreg_argnum) {
- v->regoff = argintregs[v->varnum];
- return(argintregs[v->varnum]);
- }
- v->regoff -= intreg_argnum;
- break;
- }
- v->flags |= INMEMORY;
- return tempregnum;
-}
+ if (parentargs_base) {
+ M_LDA(REG_SP, REG_SP, -parentargs_base * 8);
+ }
+ /* save return address and used callee saved registers */
-/* store_reg_to_var_xxx:
- This function generates the code to store the result of an operation
- back into a spilled pseudo-variable.
- If the pseudo-variable has not been spilled in the first place, this
- function will generate nothing.
-
- v ............ Pseudovariable
- tempregnum ... Number of the temporary registers as returned by
- reg_of_var.
-*/
-
-#define store_reg_to_var_int(sptr, tempregnum) { \
- if ((sptr)->flags & INMEMORY) { \
- COUNT_SPILLS; \
- M_LST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
- } \
+ p = parentargs_base;
+ if (!m->isleafmethod) {
+ p--; M_AST(REG_RA, REG_SP, p * 8);
}
-
-#define store_reg_to_var_flt(sptr, tempregnum) { \
- if ((sptr)->flags & INMEMORY) { \
- COUNT_SPILLS; \
- M_DST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
- } \
+ for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
+ p--; M_LST(rd->savintregs[i], REG_SP, p * 8);
+ }
+ for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
+ p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
}
+ /* take arguments out of register or stack frame */
-/* NullPointerException handlers and exception handling initialisation */
-
-typedef struct sigctx_struct {
-
- long sc_onstack; /* sigstack state to restore */
- long sc_mask; /* signal mask to restore */
- long sc_pc; /* pc at time of signal */
- long sc_ps; /* psl to retore */
- long sc_regs[32]; /* processor regs 0 to 31 */
- long sc_ownedfp; /* fp has been used */
- long sc_fpregs[32]; /* fp regs 0 to 31 */
- unsigned long sc_fpcr; /* floating point control register */
- unsigned long sc_fp_control; /* software fpcr */
- /* rest is unused */
- unsigned long sc_reserved1, sc_reserved2;
- unsigned long sc_ssize;
- char *sc_sbase;
- unsigned long sc_traparg_a0;
- unsigned long sc_traparg_a1;
- unsigned long sc_traparg_a2;
- unsigned long sc_fp_trap_pc;
- unsigned long sc_fp_trigger_sum;
- unsigned long sc_fp_trigger_inst;
- unsigned long sc_retcode[2];
-} sigctx_struct;
-
-
-/* NullPointerException signal handler for hardware null pointer check */
-
-void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx)
-{
- sigset_t nsig;
- int instr;
- long faultaddr;
-
- /* Reset signal handler - necessary for SysV, does no harm for BSD */
-
- instr = *((int*)(sigctx->sc_pc));
- faultaddr = sigctx->sc_regs[(instr >> 16) & 0x1f];
-
- if (faultaddr == 0) {
- signal(sig, (void*) catch_NullPointerException); /* reinstall handler */
- sigemptyset(&nsig);
- sigaddset(&nsig, sig);
- sigprocmask(SIG_UNBLOCK, &nsig, NULL); /* unblock signal */
- sigctx->sc_regs[REG_ITMP1_XPTR] =
- (long) proto_java_lang_NullPointerException;
- sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
- sigctx->sc_pc = (long) asm_handle_exception;
- return;
- }
- else {
- faultaddr += (long) ((instr << 16) >> 16);
- fprintf(stderr, "faulting address: 0x%16lx\n", faultaddr);
- panic("Stack overflow");
- }
-}
-
-
-#ifdef __osf__
-
-void init_exceptions(void)
-{
-
-#else /* Linux */
-
-/* Linux on Digital Alpha needs an initialisation of the ieee floating point
- control for IEEE compliant arithmetic (option -mieee of GCC). Under
- Digital Unix this is done automatically.
-*/
+ md = m->parseddesc;
-#include <asm/fpu.h>
+ for (p = 0, l = 0; p < md->paramcount; p++) {
+ t = md->paramtypes[p].type;
+ var = &(rd->locals[l][t]);
+ l++;
+ if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */
+ l++;
+ if (var->type < 0)
+ continue;
+ s1 = md->params[p].regoff;
+ if (IS_INT_LNG_TYPE(t)) { /* integer args */
+ if (!md->params[p].inmemory) { /* register arguments */
+ s2 = rd->argintregs[s1];
+ if (!(var->flags & INMEMORY)) { /* reg arg -> register */
+ M_INTMOVE(s2, var->regoff);
-extern unsigned long ieee_get_fp_control();
-extern void ieee_set_fp_control(unsigned long fp_control);
+ } else { /* reg arg -> spilled */
+ M_LST(s2, REG_SP, var->regoff * 8);
+ }
-void init_exceptions(void)
-{
-/* initialize floating point control */
+ } else { /* stack arguments */
+ if (!(var->flags & INMEMORY)) { /* stack arg -> register */
+ M_LLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
-ieee_set_fp_control(ieee_get_fp_control()
- & ~IEEE_TRAP_ENABLE_INV
- & ~IEEE_TRAP_ENABLE_DZE
-/* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */
- & ~IEEE_TRAP_ENABLE_OVF);
-#endif
+ } else { /* stack arg -> spilled */
+ var->regoff = parentargs_base + s1;
+ }
+ }
- /* install signal handlers we need to convert to exceptions */
+ } else { /* floating args */
+ if (!md->params[p].inmemory) { /* register arguments */
+ s2 = rd->argfltregs[s1];
+ if (!(var->flags & INMEMORY)) { /* reg arg -> register */
+ M_FLTMOVE(s2, var->regoff);
- if (!checknull) {
+ } else { /* reg arg -> spilled */
+ M_DST(s2, REG_SP, var->regoff * 8);
+ }
-#if defined(SIGSEGV)
- signal(SIGSEGV, (void*) catch_NullPointerException);
-#endif
+ } else { /* stack arguments */
+ if (!(var->flags & INMEMORY)) { /* stack-arg -> register */
+ M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
-#if defined(SIGBUS)
- signal(SIGBUS, (void*) catch_NullPointerException);
-#endif
+ } else { /* stack-arg -> spilled */
+ var->regoff = parentargs_base + s1;
+ }
+ }
}
-}
-
-
-/* function gen_mcode **********************************************************
-
- generates machine code
+ } /* end for */
-*******************************************************************************/
-
-#define MethodPointer -8
-#define FrameSize -12
-#define IsSync -16
-#define IsLeaf -20
-#define IntSave -24
-#define FltSave -28
-#define ExTableSize -32
-#define ExTableStart -32
-
-#define ExEntrySize -32
-#define ExStartPC -8
-#define ExEndPC -16
-#define ExHandlerPC -24
-#define ExCatchType -32
-
-void codegen()
-{
- int len, s1, s2, s3, d, bbs;
- s4 a;
- s4 *mcodeptr;
- stackptr src;
- varinfo *var;
- basicblock *bptr;
- instruction *iptr;
- xtable *ex;
-
- {
- int p, pa, t, l, r;
-
- savedregs_num = (isleafmethod) ? 0 : 1; /* space to save the RA */
-
- /* space to save used callee saved registers */
+ /* call monitorenter function */
- savedregs_num += (savintregcnt - maxsavintreguse);
- savedregs_num += (savfltregcnt - maxsavfltreguse);
+#if defined(USE_THREADS)
+ if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+ /* stack offset for monitor argument */
- parentargs_base = maxmemuse + savedregs_num;
+ s1 = rd->memuse;
-#ifdef USE_THREADS /* space to save argument of monitor_enter */
+ if (runverbose) {
+ M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8);
- if (checksync && (method->flags & ACC_SYNCHRONIZED))
- parentargs_base++;
+ for (p = 0; p < INT_ARG_CNT; p++)
+ M_LST(rd->argintregs[p], REG_SP, p * 8);
-#endif
+ for (p = 0; p < FLT_ARG_CNT; p++)
+ M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
- /* create method header */
+ s1 += INT_ARG_CNT + FLT_ARG_CNT;
+ }
- (void) dseg_addaddress(method); /* MethodPointer */
- (void) dseg_adds4(parentargs_base * 8); /* FrameSize */
+ /* decide which monitor enter function to call */
-#ifdef USE_THREADS
+ if (m->flags & ACC_STATIC) {
+ disp = dseg_addaddress(cd, m->class);
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ M_AST(REG_ITMP1, REG_SP, s1 * 8);
+ M_INTMOVE(REG_ITMP1, rd->argintregs[0]);
+ disp = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, disp);
+
+ } else {
+ M_BEQZ(rd->argintregs[0], 0);
+ codegen_addxnullrefs(cd, mcodeptr);
+ M_AST(rd->argintregs[0], REG_SP, s1 * 8);
+ disp = dseg_addaddress(cd, BUILTIN_monitorenter);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, disp);
+ }
- /* IsSync contains the offset relative to the stack pointer for the
- argument of monitor_exit used in the exception handler. Since the
- offset could be zero and give a wrong meaning of the flag it is
- offset by one.
- */
+ if (runverbose) {
+ for (p = 0; p < INT_ARG_CNT; p++)
+ M_LLD(rd->argintregs[p], REG_SP, p * 8);
- if (checksync && (method->flags & ACC_SYNCHRONIZED))
- (void) dseg_adds4((maxmemuse + 1) * 8); /* IsSync */
- else
+ for (p = 0; p < FLT_ARG_CNT; p++)
+ M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
+ M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
+ }
+ }
#endif
- (void) dseg_adds4(0); /* IsSync */
-
- (void) dseg_adds4(isleafmethod); /* IsLeaf */
- (void) dseg_adds4(savintregcnt - maxsavintreguse); /* IntSave */
- (void) dseg_adds4(savfltregcnt - maxsavfltreguse); /* FltSave */
- (void) dseg_adds4(exceptiontablelength); /* ExTableSize */
+ /* call trace function */
- /* create exception table */
+ if (runverbose) {
+ M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
+ M_AST(REG_RA, REG_SP, 1 * 8);
- for (ex = extable; ex != NULL; ex = ex->down) {
+ /* save integer argument registers */
-#ifdef LOOP_DEBUG
- if (ex->start != NULL)
- printf("adding start - %d - ", ex->start->debug_nr);
- else {
- printf("PANIC - start is NULL");
- exit(-1);
- }
-#endif
+ for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
+ M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8);
- dseg_addtarget(ex->start);
+ /* save and copy float arguments into integer registers */
-#ifdef LOOP_DEBUG
- if (ex->end != NULL)
- printf("adding end - %d - ", ex->end->debug_nr);
- else {
- printf("PANIC - end is NULL");
- exit(-1);
- }
-#endif
+ for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
+ t = md->paramtypes[p].type;
- dseg_addtarget(ex->end);
+ if (IS_FLT_DBL_TYPE(t)) {
+ if (IS_2_WORD_TYPE(t)) {
+ M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-#ifdef LOOP_DEBUG
- if (ex->handler != NULL)
- printf("adding handler - %d\n", ex->handler->debug_nr);
- else {
- printf("PANIC - handler is NULL");
- exit(-1);
- }
-#endif
+ } else {
+ M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+ }
- dseg_addtarget(ex->handler);
-
- (void) dseg_addaddress(ex->catchtype);
+ M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+
+ } else {
+ M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+ }
}
-
- /* initialize mcode variables */
-
- mcodeptr = (s4*) mcodebase;
- mcodeend = (s4*) (mcodebase + mcodesize);
- MCODECHECK(128 + mparamcount);
-
- /* create stack frame (if necessary) */
- if (parentargs_base)
- {M_LDA (REG_SP, REG_SP, -parentargs_base * 8);}
-
- /* save return address and used callee saved registers */
+ disp = dseg_addaddress(cd, m);
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ M_AST(REG_ITMP1, REG_SP, 0 * 8);
+ disp = dseg_addaddress(cd, (void *) builtin_trace_args);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, disp);
+ M_ALD(REG_RA, REG_SP, 1 * 8);
- p = parentargs_base;
- if (!isleafmethod)
- {p--; M_AST (REG_RA, REG_SP, 8*p);}
- for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
- {p--; M_LST (savintregs[r], REG_SP, 8 * p);}
- for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
- {p--; M_DST (savfltregs[r], REG_SP, 8 * p);}
-
- /* save monitorenter argument */
-
-#ifdef USE_THREADS
- if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
- if (method->flags & ACC_STATIC) {
- p = dseg_addaddress (class);
- M_ALD(REG_ITMP1, REG_PV, p);
- M_AST(REG_ITMP1, REG_SP, 8 * maxmemuse);
- }
- else {
- M_AST (argintregs[0], REG_SP, 8 * maxmemuse);
- }
- }
-#endif
+ /* restore integer argument registers */
- /* copy argument registers to stack and call trace function with pointer
- to arguments on stack. ToDo: save floating point registers !!!!!!!!!
- */
+ for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
+ M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8);
- if (runverbose) {
- M_LDA (REG_SP, REG_SP, -(14*8));
- M_AST(REG_RA, REG_SP, 1*8);
-
- M_LST(argintregs[0], REG_SP, 2*8);
- M_LST(argintregs[1], REG_SP, 3*8);
- M_LST(argintregs[2], REG_SP, 4*8);
- M_LST(argintregs[3], REG_SP, 5*8);
- M_LST(argintregs[4], REG_SP, 6*8);
- M_LST(argintregs[5], REG_SP, 7*8);
-
- M_DST(argfltregs[0], REG_SP, 8*8);
- M_DST(argfltregs[1], REG_SP, 9*8);
- M_DST(argfltregs[2], REG_SP, 10*8);
- M_DST(argfltregs[3], REG_SP, 11*8);
- M_DST(argfltregs[4], REG_SP, 12*8);
- M_DST(argfltregs[5], REG_SP, 13*8);
-
- p = dseg_addaddress (method);
- M_ALD(REG_ITMP1, REG_PV, p);
- M_AST(REG_ITMP1, REG_SP, 0);
- p = dseg_addaddress ((void*) (builtin_trace_args));
- M_ALD(REG_PV, REG_PV, p);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- M_ALD(REG_RA, REG_SP, 1*8);
-
- M_LLD(argintregs[0], REG_SP, 2*8);
- M_LLD(argintregs[1], REG_SP, 3*8);
- M_LLD(argintregs[2], REG_SP, 4*8);
- M_LLD(argintregs[3], REG_SP, 5*8);
- M_LLD(argintregs[4], REG_SP, 6*8);
- M_LLD(argintregs[5], REG_SP, 7*8);
-
- M_DLD(argfltregs[0], REG_SP, 8*8);
- M_DLD(argfltregs[1], REG_SP, 9*8);
- M_DLD(argfltregs[2], REG_SP, 10*8);
- M_DLD(argfltregs[3], REG_SP, 11*8);
- M_DLD(argfltregs[4], REG_SP, 12*8);
- M_DLD(argfltregs[5], REG_SP, 13*8);
-
- M_LDA (REG_SP, REG_SP, 14*8);
- }
+ /* restore float argument registers */
- /* take arguments out of register or stack frame */
+ for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
+ t = md->paramtypes[p].type;
- for (p = 0, l = 0; p < mparamcount; p++) {
- t = mparamtypes[p];
- var = &(locals[l][t]);
- l++;
- if (IS_2_WORD_TYPE(t)) /* increment local counter for 2 word types */
- l++;
- if (var->type < 0)
- continue;
- r = var->regoff;
- if (IS_INT_LNG_TYPE(t)) { /* integer args */
- if (p < INT_ARG_CNT) { /* register arguments */
- if (!(var->flags & INMEMORY)) /* reg arg -> register */
- {M_INTMOVE (argintregs[p], r);}
- else /* reg arg -> spilled */
- M_LST (argintregs[p], REG_SP, 8 * r);
- }
- else { /* stack arguments */
- pa = p - INT_ARG_CNT;
- if (!(var->flags & INMEMORY)) /* stack arg -> register */
- M_LLD (r, REG_SP, 8 * (parentargs_base + pa));
- else { /* stack arg -> spilled */
- M_LLD (REG_ITMP1, REG_SP, 8 * (parentargs_base + pa));
- M_LST (REG_ITMP1, REG_SP, 8 * r);
- }
- }
- }
- else { /* floating args */
- if (p < FLT_ARG_CNT) { /* register arguments */
- if (!(var->flags & INMEMORY)) /* reg arg -> register */
- {M_FLTMOVE (argfltregs[p], r);}
- else /* reg arg -> spilled */
- M_DST (argfltregs[p], REG_SP, 8 * r);
- }
- else { /* stack arguments */
- pa = p - FLT_ARG_CNT;
- if (!(var->flags & INMEMORY)) /* stack-arg -> register */
- M_DLD (r, REG_SP, 8 * (parentargs_base + pa) );
- else { /* stack-arg -> spilled */
- M_DLD (REG_FTMP1, REG_SP, 8 * (parentargs_base + pa));
- M_DST (REG_FTMP1, REG_SP, 8 * r);
- }
- }
- }
- } /* end for */
+ if (IS_FLT_DBL_TYPE(t)) {
+ if (IS_2_WORD_TYPE(t)) {
+ M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
- /* call trace function */
+ } else {
+ M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+ }
-#if 0
- if (runverbose && !isleafmethod) {
- M_LDA (REG_SP, REG_SP, -8);
- p = dseg_addaddress (method);
- M_ALD(REG_ITMP1, REG_PV, p);
- M_AST(REG_ITMP1, REG_SP, 0);
- p = dseg_addaddress ((void*) (builtin_trace_args));
- M_ALD(REG_PV, REG_PV, p);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- M_LDA(REG_SP, REG_SP, 8);
+ } else {
+ M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+ }
}
-#endif
- /* call monitorenter function */
+ M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT + 2) * 8);
+ }
-#ifdef USE_THREADS
- if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
- p = dseg_addaddress ((void*) (builtin_monitorenter));
- M_ALD(REG_PV, REG_PV, p);
- M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- }
-#endif
}
/* end of header generation */
/* walk through all basic blocks */
- for (/* bbs = block_count, */ bptr = block; /* --bbs >= 0 */ bptr != NULL; bptr = bptr->next) {
- bptr -> mpc = (int)((u1*) mcodeptr - mcodebase);
+ for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
+
+ bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
if (bptr->flags >= BBREACHED) {
{
branchref *brefs;
for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
- gen_resolvebranch((u1*) mcodebase + brefs->branchpos,
+ gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos,
brefs->branchpos, bptr->mpc);
}
}
src = bptr->instack;
len = bptr->indepth;
MCODECHECK(64+len);
+#ifdef LSRA
+ if (opt_lsra) {
while (src != NULL) {
len--;
if ((len == 0) && (bptr->type != BBTYPE_STD)) {
- d = reg_of_var(src, REG_ITMP1);
- M_INTMOVE(REG_ITMP1, d);
- store_reg_to_var_int(src, d);
- }
- else {
- d = reg_of_var(src, REG_IFTMP);
- if ((src->varkind != STACKVAR)) {
- s2 = src->type;
- if (IS_FLT_DBL_TYPE(s2)) {
- if (!(interfaces[len][s2].flags & INMEMORY)) {
- s1 = interfaces[len][s2].regoff;
- M_FLTMOVE(s1,d);
- }
- else {
- M_DLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
+ /* d = reg_of_var(m, src, REG_ITMP1); */
+ if (!(src->flags & INMEMORY))
+ d = src->regoff;
+ else
+ d = REG_ITMP1;
+ M_INTMOVE(REG_ITMP1, d);
+ store_reg_to_var_int(src, d);
+ }
+ src = src->prev;
+ }
+ } else {
+#endif
+ while (src != NULL) {
+ len--;
+ if ((len == 0) && (bptr->type != BBTYPE_STD)) {
+ d = reg_of_var(rd, src, REG_ITMP1);
+ M_INTMOVE(REG_ITMP1, d);
+ store_reg_to_var_int(src, d);
+ } else {
+ d = reg_of_var(rd, src, REG_IFTMP);
+ if ((src->varkind != STACKVAR)) {
+ s2 = src->type;
+ if (IS_FLT_DBL_TYPE(s2)) {
+ if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+ s1 = rd->interfaces[len][s2].regoff;
+ M_FLTMOVE(s1, d);
+ } else {
+ M_DLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
}
- store_reg_to_var_flt(src, d);
+ store_reg_to_var_flt(src, d);
}
- else {
- if (!(interfaces[len][s2].flags & INMEMORY)) {
- s1 = interfaces[len][s2].regoff;
- M_INTMOVE(s1,d);
- }
else {
- M_LLD(d, REG_SP, 8 * interfaces[len][s2].regoff);
+ if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+ s1 = rd->interfaces[len][s2].regoff;
+ M_INTMOVE(s1, d);
+ } else {
+ M_LLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
}
- store_reg_to_var_int(src, d);
+ store_reg_to_var_int(src, d);
}
}
}
- src = src->prev;
+ src = src->prev;
}
+#ifdef LSRA
+ }
+#endif
/* walk through all instructions */
src = bptr->instack;
len = bptr->icount;
- for (iptr = bptr->iinstr;
- len > 0;
- src = iptr->dst, len--, iptr++) {
- MCODECHECK(64); /* an instruction usually needs < 64 words */
- switch (iptr->opc) {
+ for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
+ if (iptr->line != currentline) {
+ dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
+ currentline = iptr->line;
+ }
+
+ MCODECHECK(64); /* an instruction usually needs < 64 words */
+ switch (iptr->opc) {
+
+ case ICMD_INLINE_START:
+ case ICMD_INLINE_END:
+ break;
case ICMD_NOP: /* ... ==> ... */
break;
- case ICMD_NULLCHECKPOP: /* ..., objectref ==> ... */
+ case ICMD_CHECKNULL: /* ..., objectref ==> ..., objectref */
var_to_reg_int(s1, src, REG_ITMP1);
M_BEQZ(s1, 0);
- codegen_addxnullrefs(mcodeptr);
+ codegen_addxnullrefs(cd, mcodeptr);
break;
/* constant operations ************************************************/
-#define ICONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
- else{a=dseg_adds4(c);M_ILD(r,REG_PV,a);}
-
-#define LCONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
- else{a=dseg_adds8(c);M_LLD(r,REG_PV,a);}
-
case ICMD_ICONST: /* ... ==> ..., constant */
/* op1 = 0, val.i = constant */
- d = reg_of_var(iptr->dst, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP1);
ICONST(d, iptr->val.i);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_LCONST: /* ... ==> ..., constant */
/* op1 = 0, val.l = constant */
- d = reg_of_var(iptr->dst, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP1);
LCONST(d, iptr->val.l);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_FCONST: /* ... ==> ..., constant */
/* op1 = 0, val.f = constant */
- d = reg_of_var (iptr->dst, REG_FTMP1);
- a = dseg_addfloat (iptr->val.f);
- M_FLD(d, REG_PV, a);
- store_reg_to_var_flt (iptr->dst, d);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ disp = dseg_addfloat(cd, iptr->val.f);
+ M_FLD(d, REG_PV, disp);
+ store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_DCONST: /* ... ==> ..., constant */
/* op1 = 0, val.d = constant */
- d = reg_of_var (iptr->dst, REG_FTMP1);
- a = dseg_adddouble (iptr->val.d);
- M_DLD(d, REG_PV, a);
- store_reg_to_var_flt (iptr->dst, d);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ disp = dseg_adddouble(cd, iptr->val.d);
+ M_DLD(d, REG_PV, disp);
+ store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_ACONST: /* ... ==> ..., constant */
/* op1 = 0, val.a = constant */
- d = reg_of_var(iptr->dst, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP1);
if (iptr->val.a) {
- a = dseg_addaddress (iptr->val.a);
- M_ALD(d, REG_PV, a);
- }
- else {
+ disp = dseg_addaddress(cd, iptr->val.a);
+ M_ALD(d, REG_PV, disp);
+ } else {
M_INTMOVE(REG_ZERO, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_LLOAD: /* op1 = local variable */
case ICMD_ALOAD:
- d = reg_of_var(iptr->dst, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP1);
if ((iptr->dst->varkind == LOCALVAR) &&
(iptr->dst->varnum == iptr->op1))
break;
- var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
- if (var->flags & INMEMORY)
- M_LLD(d, REG_SP, 8 * var->regoff);
- else
- {M_INTMOVE(var->regoff,d);}
+ var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
+ if (var->flags & INMEMORY) {
+ M_LLD(d, REG_SP, var->regoff * 8);
+ } else {
+ M_INTMOVE(var->regoff, d);
+ }
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_FLOAD: /* ... ==> ..., content of local variable */
case ICMD_DLOAD: /* op1 = local variable */
- d = reg_of_var(iptr->dst, REG_FTMP1);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
if ((iptr->dst->varkind == LOCALVAR) &&
(iptr->dst->varnum == iptr->op1))
break;
- var = &(locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
- if (var->flags & INMEMORY)
- M_DLD(d, REG_SP, 8 * var->regoff);
- else
- {M_FLTMOVE(var->regoff,d);}
+ var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
+ if (var->flags & INMEMORY) {
+ M_DLD(d, REG_SP, var->regoff * 8);
+ } else {
+ M_FLTMOVE(var->regoff, d);
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
if ((src->varkind == LOCALVAR) &&
(src->varnum == iptr->op1))
break;
- var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
+ var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
if (var->flags & INMEMORY) {
var_to_reg_int(s1, src, REG_ITMP1);
- M_LST(s1, REG_SP, 8 * var->regoff);
- }
- else {
+ M_LST(s1, REG_SP, var->regoff * 8);
+ } else {
var_to_reg_int(s1, src, var->regoff);
M_INTMOVE(s1, var->regoff);
- }
+ }
break;
case ICMD_FSTORE: /* ..., value ==> ... */
if ((src->varkind == LOCALVAR) &&
(src->varnum == iptr->op1))
break;
- var = &(locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
+ var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
if (var->flags & INMEMORY) {
var_to_reg_flt(s1, src, REG_FTMP1);
- M_DST(s1, REG_SP, 8 * var->regoff);
- }
- else {
+ M_DST(s1, REG_SP, var->regoff * 8);
+ } else {
var_to_reg_flt(s1, src, var->regoff);
M_FLTMOVE(s1, var->regoff);
- }
+ }
break;
case ICMD_POP2: /* ..., value, value ==> ... */
break;
-#define M_COPY(from,to) \
- d = reg_of_var(to, REG_IFTMP); \
- if ((from->regoff != to->regoff) || \
- ((from->flags ^ to->flags) & INMEMORY)) { \
- if (IS_FLT_DBL_TYPE(from->type)) { \
- var_to_reg_flt(s1, from, d); \
- M_FLTMOVE(s1,d); \
- store_reg_to_var_flt(to, d); \
- }\
- else { \
- var_to_reg_int(s1, from, d); \
- M_INTMOVE(s1,d); \
- store_reg_to_var_int(to, d); \
- }\
- }
-
case ICMD_DUP: /* ..., a ==> ..., a, a */
M_COPY(src, iptr->dst);
break;
case ICMD_DUP_X1: /* ..., a, b ==> ..., b, a, b */
- M_COPY(src, iptr->dst->prev->prev);
+ M_COPY(src, iptr->dst);
+ M_COPY(src->prev, iptr->dst->prev);
+ M_COPY(iptr->dst, iptr->dst->prev->prev);
+ break;
+
+ case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
+
+ M_COPY(src, iptr->dst);
+ M_COPY(src->prev, iptr->dst->prev);
+ M_COPY(src->prev->prev, iptr->dst->prev->prev);
+ M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
+ break;
case ICMD_DUP2: /* ..., a, b ==> ..., a, b, a, b */
case ICMD_DUP2_X1: /* ..., a, b, c ==> ..., b, c, a, b, c */
- M_COPY(src->prev, iptr->dst->prev->prev->prev);
-
- case ICMD_DUP_X2: /* ..., a, b, c ==> ..., c, a, b, c */
-
M_COPY(src, iptr->dst);
M_COPY(src->prev, iptr->dst->prev);
M_COPY(src->prev->prev, iptr->dst->prev->prev);
- M_COPY(src, iptr->dst->prev->prev->prev);
+ M_COPY(iptr->dst, iptr->dst->prev->prev->prev);
+ M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
break;
case ICMD_DUP2_X2: /* ..., a, b, c, d ==> ..., c, d, a, b, c, d */
M_COPY(src->prev, iptr->dst->prev);
M_COPY(src->prev->prev, iptr->dst->prev->prev);
M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
- M_COPY(src, iptr->dst->prev->prev->prev->prev);
- M_COPY(src->prev, iptr->dst->prev->prev->prev->prev->prev);
+ M_COPY(iptr->dst, iptr->dst->prev->prev->prev->prev);
+ M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev->prev);
break;
case ICMD_SWAP: /* ..., a, b ==> ..., b, a */
- M_COPY(src, iptr->dst->prev);
+ M_COPY(src, iptr->dst->prev);
M_COPY(src->prev, iptr->dst);
break;
case ICMD_INEG: /* ..., value ==> ..., - value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_ISUB(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_LNEG: /* ..., value ==> ..., - value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_LSUB(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_I2L: /* ..., value ==> ..., value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_INTMOVE(s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_L2I: /* ..., value ==> ..., value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- M_IADD(s1, REG_ZERO, d );
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_IADD(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_INT2BYTE: /* ..., value ==> ..., value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (has_ext_instr_set) {
M_BSEXT(s1, d);
- }
- else {
+ } else {
M_SLL_IMM(s1, 56, d);
M_SRA_IMM( d, 56, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_INT2CHAR: /* ..., value ==> ..., value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_CZEXT(s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_INT2SHORT: /* ..., value ==> ..., value */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (has_ext_instr_set) {
M_SSEXT(s1, d);
- }
- else {
+ } else {
M_SLL_IMM(s1, 48, d);
M_SRA_IMM( d, 48, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_IADD(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_IADD_IMM(s1, iptr->val.i, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_IADD(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_LADD(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_LADD_IMM(s1, iptr->val.l, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_LADD(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_ISUB(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_ISUB_IMM(s1, iptr->val.i, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_ISUB(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_LSUB(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_LSUB_IMM(s1, iptr->val.l, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_LSUB(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_IMUL(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_IMUL_IMM(s1, iptr->val.i, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_IMUL(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- M_LMUL (s1, s2, d);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_LMUL(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_LMUL_IMM(s1, iptr->val.l, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_LMUL(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
- case ICMD_LDIVPOW2: /* val.i = constant */
-
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- if (iptr->val.i <= 15) {
+ case ICMD_IDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
+ case ICMD_IREM: /* ..., val1, val2 ==> ..., val1 % val2 */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ d = reg_of_var(rd, iptr->dst, REG_RESULT);
+ M_BEQZ(s2, 0);
+ codegen_addxdivrefs(cd, mcodeptr);
+
+ M_MOV(s1, rd->argintregs[0]);
+ M_MOV(s2, rd->argintregs[1]);
+ bte = iptr->val.a;
+ disp = dseg_addaddress(cd, bte->fp);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_IADD(REG_RESULT, REG_ZERO, d); /* sign extend (bugfix for gcc -O2) */
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+
+ case ICMD_LDIV: /* ..., val1, val2 ==> ..., val1 / val2 */
+ case ICMD_LREM: /* ..., val1, val2 ==> ..., val1 % val2 */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ d = reg_of_var(rd, iptr->dst, REG_RESULT);
+ M_BEQZ(s2, 0);
+ codegen_addxdivrefs(cd, mcodeptr);
+
+ M_MOV(s1, rd->argintregs[0]);
+ M_MOV(s2, rd->argintregs[1]);
+ bte = iptr->val.a;
+ disp = dseg_addaddress(cd, bte->fp);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_INTMOVE(REG_RESULT, d);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+
+ case ICMD_IDIVPOW2: /* ..., value ==> ..., value << constant */
+ case ICMD_LDIVPOW2: /* val.i = constant */
+
+ var_to_reg_int(s1, src, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ if (iptr->val.i <= 15) {
M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1);
M_CMOVGE(s1, s1, REG_ITMP2);
- }
- else {
+ } else {
M_SRA_IMM(s1, 63, REG_ITMP2);
M_SRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
M_LADD(s1, REG_ITMP2, REG_ITMP2);
- }
+ }
M_SRA_IMM(REG_ITMP2, iptr->val.i, d);
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_AND_IMM(s2, 0x1f, REG_ITMP3);
M_SLL(s1, REG_ITMP3, d);
M_IADD(d, REG_ZERO, d);
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
M_IADD(d, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_AND_IMM(s2, 0x1f, REG_ITMP3);
M_SRA(s1, REG_ITMP3, d);
store_reg_to_var_int(iptr->dst, d);
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_AND_IMM(s2, 0x1f, REG_ITMP2);
M_IZEXT(s1, d);
M_SRL(d, REG_ITMP2, d);
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_IZEXT(s1, d);
M_SRL_IMM(d, iptr->val.i & 0x1f, d);
M_IADD(d, REG_ZERO, d);
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SLL(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SLL_IMM(s1, iptr->val.i & 0x3f, d);
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SRA(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SRA_IMM(s1, iptr->val.i & 0x3f, d);
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SRL(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_SRL_IMM(s1, iptr->val.i & 0x3f, d);
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_AND(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_AND_IMM(s1, iptr->val.i, d);
- }
- else if (iptr->val.i == 0xffff) {
+ } else if (iptr->val.i == 0xffff) {
M_CZEXT(s1, d);
- }
- else if (iptr->val.i == 0xffffff) {
+ } else if (iptr->val.i == 0xffffff) {
M_ZAPNOT_IMM(s1, 0x07, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_AND(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
+ }
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_AND_IMM(s1, iptr->val.i, d);
M_BGEZ(s1, 3);
M_ISUB(REG_ZERO, s1, d);
M_AND_IMM(d, iptr->val.i, d);
- }
- else if (iptr->val.i == 0xffff) {
+ } else if (iptr->val.i == 0xffff) {
M_CZEXT(s1, d);
M_BGEZ(s1, 3);
M_ISUB(REG_ZERO, s1, d);
M_CZEXT(d, d);
- }
- else if (iptr->val.i == 0xffffff) {
+ } else if (iptr->val.i == 0xffffff) {
M_ZAPNOT_IMM(s1, 0x07, d);
M_BGEZ(s1, 3);
M_ISUB(REG_ZERO, s1, d);
M_ZAPNOT_IMM(d, 0x07, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_AND(s1, REG_ITMP2, d);
M_BGEZ(s1, 3);
M_ISUB(REG_ZERO, s1, d);
M_AND(d, REG_ITMP2, d);
- }
- M_ISUB(REG_ZERO, d, d);
- store_reg_to_var_int(iptr->dst, d);
- break;
-
- case ICMD_IREM0X10001: /* ..., value ==> ..., value % 0x100001 */
-
-/* b = value & 0xffff;
- a = value >> 16;
- a = ((b - a) & 0xffff) + (b < a);
-*/
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- if (s1 == d) {
- M_MOV(s1, REG_ITMP3);
- s1 = REG_ITMP3;
- }
- M_BLTZ(s1, 7);
- M_CZEXT(s1, REG_ITMP2);
- M_SRA_IMM(s1, 16, d);
- M_CMPLT(REG_ITMP2, d, REG_ITMP1);
- M_ISUB(REG_ITMP2, d, d);
- M_CZEXT(d, d);
- M_IADD(d, REG_ITMP1, d);
- M_BR(11 + (s1 == REG_ITMP1));
- M_ISUB(REG_ZERO, s1, REG_ITMP1);
- M_CZEXT(REG_ITMP1, REG_ITMP2);
- M_SRA_IMM(REG_ITMP1, 16, d);
- M_CMPLT(REG_ITMP2, d, REG_ITMP1);
- M_ISUB(REG_ITMP2, d, d);
- M_CZEXT(d, d);
- M_IADD(d, REG_ITMP1, d);
+ }
M_ISUB(REG_ZERO, d, d);
- if (s1 == REG_ITMP1) {
- var_to_reg_int(s1, src, REG_ITMP1);
- }
- M_SLL_IMM(s1, 33, REG_ITMP2);
- M_CMPEQ(REG_ITMP2, REG_ZERO, REG_ITMP2);
- M_ISUB(d, REG_ITMP2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_AND_IMM(s1, iptr->val.l, d);
- }
- else if (iptr->val.l == 0xffffL) {
+ } else if (iptr->val.l == 0xffffL) {
M_CZEXT(s1, d);
- }
- else if (iptr->val.l == 0xffffffL) {
+ } else if (iptr->val.l == 0xffffffL) {
M_ZAPNOT_IMM(s1, 0x07, d);
- }
- else if (iptr->val.l == 0xffffffffL) {
+ } else if (iptr->val.l == 0xffffffffL) {
M_IZEXT(s1, d);
- }
- else if (iptr->val.l == 0xffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffL) {
M_ZAPNOT_IMM(s1, 0x1f, d);
- }
- else if (iptr->val.l == 0xffffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffffL) {
M_ZAPNOT_IMM(s1, 0x3f, d);
- }
- else if (iptr->val.l == 0xffffffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffffffL) {
M_ZAPNOT_IMM(s1, 0x7f, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_AND(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
+ }
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_AND_IMM(s1, iptr->val.l, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_AND_IMM(d, iptr->val.l, d);
- }
- else if (iptr->val.l == 0xffffL) {
+ } else if (iptr->val.l == 0xffffL) {
M_CZEXT(s1, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_CZEXT(d, d);
- }
- else if (iptr->val.l == 0xffffffL) {
+ } else if (iptr->val.l == 0xffffffL) {
M_ZAPNOT_IMM(s1, 0x07, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_ZAPNOT_IMM(d, 0x07, d);
- }
- else if (iptr->val.l == 0xffffffffL) {
+ } else if (iptr->val.l == 0xffffffffL) {
M_IZEXT(s1, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_IZEXT(d, d);
- }
- else if (iptr->val.l == 0xffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffL) {
M_ZAPNOT_IMM(s1, 0x1f, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_ZAPNOT_IMM(d, 0x1f, d);
- }
- else if (iptr->val.l == 0xffffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffffL) {
M_ZAPNOT_IMM(s1, 0x3f, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_ZAPNOT_IMM(d, 0x3f, d);
- }
- else if (iptr->val.l == 0xffffffffffffffL) {
+ } else if (iptr->val.l == 0xffffffffffffffL) {
M_ZAPNOT_IMM(s1, 0x7f, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_ZAPNOT_IMM(d, 0x7f, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_AND(s1, REG_ITMP2, d);
M_BGEZ(s1, 3);
M_LSUB(REG_ZERO, s1, d);
M_AND(d, REG_ITMP2, d);
- }
+ }
M_LSUB(REG_ZERO, d, d);
store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_LREM0X10001:/* ..., value ==> ..., value % 0x10001 */
-
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- if (s1 == d) {
- M_MOV(s1, REG_ITMP3);
- s1 = REG_ITMP3;
- }
- M_CZEXT(s1, REG_ITMP2);
- M_SRA_IMM(s1, 16, d);
- M_CMPLT(REG_ITMP2, d, REG_ITMP1);
- M_LSUB(REG_ITMP2, d, d);
- M_CZEXT(d, d);
- M_LADD(d, REG_ITMP1, d);
- M_LDA(REG_ITMP2, REG_ZERO, -1);
- M_SRL_IMM(REG_ITMP2, 33, REG_ITMP2);
- if (s1 == REG_ITMP1) {
- var_to_reg_int(s1, src, REG_ITMP1);
- }
- M_CMPULT(s1, REG_ITMP2, REG_ITMP2);
- M_BNEZ(REG_ITMP2, 11);
- M_LDA(d, REG_ZERO, -257);
- M_ZAPNOT_IMM(d, 0xcd, d);
- M_LSUB(REG_ZERO, s1, REG_ITMP2);
- M_CMOVGE(s1, s1, REG_ITMP2);
- M_UMULH(REG_ITMP2, d, REG_ITMP2);
- M_SRL_IMM(REG_ITMP2, 16, REG_ITMP2);
- M_LSUB(REG_ZERO, REG_ITMP2, d);
- M_CMOVGE(s1, REG_ITMP2, d);
- M_SLL_IMM(d, 16, REG_ITMP2);
- M_LADD(d, REG_ITMP2, d);
- M_LSUB(s1, d, d);
- store_reg_to_var_int(iptr->dst, d);
- break;
-
case ICMD_IOR: /* ..., val1, val2 ==> ..., val1 | val2 */
case ICMD_LOR:
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_OR( s1,s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_OR_IMM(s1, iptr->val.i, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_OR(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_OR_IMM(s1, iptr->val.l, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_OR(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_XOR(s1, s2, d);
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_XOR_IMM(s1, iptr->val.i, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, iptr->val.i);
M_XOR(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.l = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
M_XOR_IMM(s1, iptr->val.l, d);
- }
- else {
+ } else {
LCONST(REG_ITMP2, iptr->val.l);
M_XOR(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
M_CMPLT(s1, s2, REG_ITMP3);
M_CMPLT(s2, s1, REG_ITMP1);
- M_LSUB (REG_ITMP1, REG_ITMP3, d);
+ M_LSUB(REG_ITMP1, REG_ITMP3, d);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_IINC: /* ..., value ==> ..., value + constant */
/* op1 = variable, val.i = constant */
- var = &(locals[iptr->op1][TYPE_INT]);
+ var = &(rd->locals[iptr->op1][TYPE_INT]);
if (var->flags & INMEMORY) {
s1 = REG_ITMP1;
- M_LLD(s1, REG_SP, 8 * var->regoff);
- }
- else
+ M_LLD(s1, REG_SP, var->regoff * 8);
+ } else
s1 = var->regoff;
if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
M_IADD_IMM(s1, iptr->val.i, s1);
- }
- else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
+ } else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
M_ISUB_IMM(s1, (-iptr->val.i), s1);
- }
- else {
+ } else {
M_LDA (s1, s1, iptr->val.i);
M_IADD(s1, REG_ZERO, s1);
- }
+ }
if (var->flags & INMEMORY)
- M_LST(s1, REG_SP, 8 * var->regoff);
+ M_LST(s1, REG_SP, var->regoff * 8);
break;
case ICMD_FNEG: /* ..., value ==> ..., - value */
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP2);
M_FMOVN(s1, d);
store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_DNEG: /* ..., value ==> ..., - value */
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP2);
M_FMOVN(s1, d);
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_FADD(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_FADDS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_FADDS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_FADDS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_DADD(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_DADDS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_DADDS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_DADDS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_FSUB(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_FSUBS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_FSUBS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_FSUBS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_DSUB(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_DSUBS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_DSUBS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_DSUBS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_FMUL(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_FMULS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_FMULS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_FMULS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
- case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */
+ case ICMD_DMUL: /* ..., val1, val2 ==> ..., val1 *** val2 */
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_DMUL(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_DMULS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_DMULS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_DMULS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_FDIV(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_FDIVS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_FDIVS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_FDIVS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_DDIV(s1, s2, d);
+ } else {
+ if (d == s1 || d == s2) {
+ M_DDIVS(s1, s2, REG_FTMP3);
+ M_TRAPB;
+ M_FMOV(REG_FTMP3, d);
+ } else {
+ M_DDIVS(s1, s2, d);
+ M_TRAPB;
}
- else {
- M_DDIVS(s1, s2, d);
- M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
- case ICMD_FREM: /* ..., val1, val2 ==> ..., val1 % val2 */
-
- var_to_reg_flt(s1, src->prev, REG_FTMP1);
- var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
- if (opt_noieee) {
- M_FDIV(s1,s2, REG_FTMP3);
- M_CVTDL_C(REG_FTMP3, REG_FTMP3); /* round to integer */
- M_CVTLF(REG_FTMP3, REG_FTMP3);
- M_FMUL(REG_FTMP3, s2, REG_FTMP3);
- M_FSUB(s1, REG_FTMP3, d);
- }
- else {
- M_FDIVS(s1,s2, REG_FTMP3);
- M_TRAPB;
- M_CVTDL_CS(REG_FTMP3, REG_FTMP3); /* round to integer */
- M_TRAPB;
- M_CVTLF(REG_FTMP3, REG_FTMP3);
- M_FMULS(REG_FTMP3, s2, REG_FTMP3);
- M_TRAPB;
- M_FSUBS(s1, REG_FTMP3, d);
- M_TRAPB;
- }
- store_reg_to_var_flt(iptr->dst, d);
- break;
-
- case ICMD_DREM: /* ..., val1, val2 ==> ..., val1 % val2 */
-
- var_to_reg_flt(s1, src->prev, REG_FTMP1);
- var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
- if (opt_noieee) {
- M_DDIV(s1,s2, REG_FTMP3);
- M_CVTDL_C(REG_FTMP3, REG_FTMP3); /* round to integer */
- M_CVTLD(REG_FTMP3, REG_FTMP3);
- M_DMUL(REG_FTMP3, s2, REG_FTMP3);
- M_DSUB(s1, REG_FTMP3, d);
- }
- else {
- M_DDIVS(s1,s2, REG_FTMP3);
- M_TRAPB;
- M_CVTDL_CS(REG_FTMP3, REG_FTMP3); /* round to integer */
- M_TRAPB;
- M_CVTLD(REG_FTMP3, REG_FTMP3);
- M_DMULS(REG_FTMP3, s2, REG_FTMP3);
- M_TRAPB;
- M_DSUBS(s1, REG_FTMP3, d);
- M_TRAPB;
- }
- store_reg_to_var_flt(iptr->dst, d);
- break;
-
case ICMD_I2F: /* ..., value ==> ..., (float) value */
case ICMD_L2F:
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
- a = dseg_adddouble(0.0);
- M_LST (s1, REG_PV, a);
- M_DLD (d, REG_PV, a);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+ disp = dseg_adddouble(cd, 0.0);
+ M_LST(s1, REG_PV, disp);
+ M_DLD(d, REG_PV, disp);
M_CVTLF(d, d);
store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_I2D: /* ..., value ==> ..., (double) value */
case ICMD_L2D:
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
- a = dseg_adddouble(0.0);
- M_LST (s1, REG_PV, a);
- M_DLD (d, REG_PV, a);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+ disp = dseg_adddouble(cd, 0.0);
+ M_LST(s1, REG_PV, disp);
+ M_DLD(d, REG_PV, disp);
M_CVTLD(d, d);
store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_F2I: /* ..., value ==> ..., (int) value */
case ICMD_D2I:
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- a = dseg_adddouble(0.0);
- if (opt_noieee) {
- M_CVTDL_C(s1, REG_FTMP1);
- M_CVTLI(REG_FTMP1, REG_FTMP2);
- }
- else {
- M_CVTDL_CS(s1, REG_FTMP1);
- M_TRAPB;
- M_CVTLIS(REG_FTMP1, REG_FTMP2);
- M_TRAPB;
- }
- M_DST (REG_FTMP1, REG_PV, a);
- M_ILD (d, REG_PV, a);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+ disp = dseg_adddouble(cd, 0.0);
+ M_CVTDL_C(s1, REG_FTMP2);
+ M_CVTLI(REG_FTMP2, REG_FTMP3);
+ M_DST(REG_FTMP3, REG_PV, disp);
+ M_ILD(d, REG_PV, disp);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_F2L: /* ..., value ==> ..., (long) value */
case ICMD_D2L:
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- a = dseg_adddouble(0.0);
- if (opt_noieee) {
- M_CVTDL_C(s1, REG_FTMP1);
- }
- else {
- M_CVTDL_CS(s1, REG_FTMP1);
- M_TRAPB;
- }
- M_DST (REG_FTMP1, REG_PV, a);
- M_LLD (d, REG_PV, a);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+ disp = dseg_adddouble(cd, 0.0);
+ M_CVTDL_C(s1, REG_FTMP2);
+ M_DST(REG_FTMP2, REG_PV, disp);
+ M_LLD(d, REG_PV, disp);
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_F2D: /* ..., value ==> ..., (double) value */
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
- M_FLTMOVE(s1, d);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+ M_CVTFDS(s1, d);
+ M_TRAPB;
store_reg_to_var_flt(iptr->dst, d);
break;
- case ICMD_D2F: /* ..., value ==> ..., (double) value */
+ case ICMD_D2F: /* ..., value ==> ..., (float) value */
var_to_reg_flt(s1, src, REG_FTMP1);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP3);
if (opt_noieee) {
M_CVTDF(s1, d);
- }
- else {
+ } else {
M_CVTDFS(s1, d);
M_TRAPB;
- }
+ }
store_reg_to_var_flt(iptr->dst, d);
break;
case ICMD_DCMPL:
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP3);
if (opt_noieee) {
M_LSUB_IMM(REG_ZERO, 1, d);
M_FCMPEQ(s1, s2, REG_FTMP3);
M_FCMPLT(s2, s1, REG_FTMP3);
M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */
M_LADD_IMM(REG_ZERO, 1, d);
- }
- else {
+ } else {
M_LSUB_IMM(REG_ZERO, 1, d);
M_FCMPEQS(s1, s2, REG_FTMP3);
M_TRAPB;
M_TRAPB;
M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */
M_LADD_IMM(REG_ZERO, 1, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_DCMPG:
var_to_reg_flt(s1, src->prev, REG_FTMP1);
var_to_reg_flt(s2, src, REG_FTMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP3);
if (opt_noieee) {
M_LADD_IMM(REG_ZERO, 1, d);
M_FCMPEQ(s1, s2, REG_FTMP3);
M_FCMPLT(s1, s2, REG_FTMP3);
M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */
M_LSUB_IMM(REG_ZERO, 1, d);
- }
- else {
+ } else {
M_LADD_IMM(REG_ZERO, 1, d);
M_FCMPEQS(s1, s2, REG_FTMP3);
M_TRAPB;
M_TRAPB;
M_FBEQZ (REG_FTMP3, 1); /* jump over next instruction */
M_LSUB_IMM(REG_ZERO, 1, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* memory operations **************************************************/
- /* #define gen_bound_check \
- if (checkbounds) {\
- M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
- M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
- M_BEQZ(REG_ITMP3, 0);\
- codegen_addxboundrefs(mcodeptr);\
- }
- */
-
-#define gen_bound_check \
- if (checkbounds) { \
- M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
- M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
- M_BEQZ(REG_ITMP3, 0);\
- codegen_addxboundrefs(mcodeptr); \
- }
-
case ICMD_ARRAYLENGTH: /* ..., arrayref ==> ..., length */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
gen_nullptr_check(s1);
M_ILD(d, s1, OFFSET(java_arrayheader, size));
store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- M_SAADDQ(s2, s1, REG_ITMP1);
- M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+ }
+ if (has_ext_instr_set) {
+ M_LADD (s2, s1, REG_ITMP1);
+ M_BLDU (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
+ M_BSEXT (d, d);
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
+ M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+ M_SRA_IMM(d, 56, d);
+ }
store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- M_S8ADDQ(s2, s1, REG_ITMP1);
- M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+ }
+ if (has_ext_instr_set) {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ } else {
+ M_LADD (s2, s1, REG_ITMP1);
+ M_LADD (s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_EXTWL(REG_ITMP2, REG_ITMP1, d);
+ }
store_reg_to_var_int(iptr->dst, d);
- break;
+ break;
- case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
-
- M_S4ADDQ(s2, s1, REG_ITMP1);
- M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
+ }
+ if (has_ext_instr_set) {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
+ M_SSEXT(d, d);
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
+ M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+ M_SRA_IMM(d, 48, d);
+ }
store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_IALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
M_S4ADDQ(s2, s1, REG_ITMP1);
- M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
- store_reg_to_var_flt(iptr->dst, d);
+ M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
+ store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_LALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_FTMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
M_S8ADDQ(s2, s1, REG_ITMP1);
- M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
- store_reg_to_var_flt(iptr->dst, d);
+ M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+ store_reg_to_var_int(iptr->dst, d);
break;
- case ICMD_CALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_FALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- if (has_ext_instr_set) {
- M_LADD(s2, s1, REG_ITMP1);
- M_LADD(s2, REG_ITMP1, REG_ITMP1);
- M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
- }
- else {
- M_LADD (s2, s1, REG_ITMP1);
- M_LADD (s2, REG_ITMP1, REG_ITMP1);
- M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
- M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
- M_EXTWL(REG_ITMP2, REG_ITMP1, d);
- }
- store_reg_to_var_int(iptr->dst, d);
- break;
+ }
+ M_S4ADDQ(s2, s1, REG_ITMP1);
+ M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+ store_reg_to_var_flt(iptr->dst, d);
+ break;
- case ICMD_SALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_DALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_FTMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- if (has_ext_instr_set) {
- M_LADD(s2, s1, REG_ITMP1);
- M_LADD(s2, REG_ITMP1, REG_ITMP1);
- M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
- M_SSEXT(d, d);
- }
- else {
- M_LADD(s2, s1, REG_ITMP1);
- M_LADD(s2, REG_ITMP1, REG_ITMP1);
- M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
- M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
- M_EXTQH(REG_ITMP2, REG_ITMP1, d);
- M_SRA_IMM(d, 48, d);
- }
- store_reg_to_var_int(iptr->dst, d);
+ }
+ M_S8ADDQ(s2, s1, REG_ITMP1);
+ M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+ store_reg_to_var_flt(iptr->dst, d);
break;
- case ICMD_BALOAD: /* ..., arrayref, index ==> ..., value */
+ case ICMD_AALOAD: /* ..., arrayref, index ==> ..., value */
var_to_reg_int(s1, src->prev, REG_ITMP1);
var_to_reg_int(s2, src, REG_ITMP2);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
+ M_SAADDQ(s2, s1, REG_ITMP1);
+ M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+
+
+ case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
+
+ var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+ var_to_reg_int(s2, src->prev, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
+ var_to_reg_int(s3, src, REG_ITMP3);
if (has_ext_instr_set) {
- M_LADD (s2, s1, REG_ITMP1);
- M_BLDU (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
- M_BSEXT (d, d);
- }
- else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+ } else {
M_LADD(s2, s1, REG_ITMP1);
M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
- M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
- M_EXTQH(REG_ITMP2, REG_ITMP1, d);
- M_SRA_IMM(d, 56, d);
- }
- store_reg_to_var_int(iptr->dst, d);
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+ M_INSBL(s3, REG_ITMP1, REG_ITMP3);
+ M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+ }
break;
-
- case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
+ case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
var_to_reg_int(s2, src->prev, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
var_to_reg_int(s3, src, REG_ITMP3);
- M_SAADDQ(s2, s1, REG_ITMP1);
- M_AST (s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+ if (has_ext_instr_set) {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+ M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+ }
break;
- case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
+ case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
var_to_reg_int(s2, src->prev, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
var_to_reg_int(s3, src, REG_ITMP3);
- M_S8ADDQ(s2, s1, REG_ITMP1);
- M_LST (s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
+ if (has_ext_instr_set) {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_SST(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+ M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+ }
break;
case ICMD_IASTORE: /* ..., arrayref, index, value ==> ... */
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
-
+ }
var_to_reg_int(s3, src, REG_ITMP3);
M_S4ADDQ(s2, s1, REG_ITMP1);
- M_IST (s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+ M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+ break;
+
+ case ICMD_LASTORE: /* ..., arrayref, index, value ==> ... */
+
+ var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+ var_to_reg_int(s2, src->prev, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
+ var_to_reg_int(s3, src, REG_ITMP3);
+ M_S8ADDQ(s2, s1, REG_ITMP1);
+ M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
break;
case ICMD_FASTORE: /* ..., arrayref, index, value ==> ... */
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
var_to_reg_flt(s3, src, REG_FTMP3);
M_S4ADDQ(s2, s1, REG_ITMP1);
- M_FST (s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+ M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
break;
case ICMD_DASTORE: /* ..., arrayref, index, value ==> ... */
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
+ }
var_to_reg_flt(s3, src, REG_FTMP3);
M_S8ADDQ(s2, s1, REG_ITMP1);
- M_DST (s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+ M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
break;
- case ICMD_CASTORE: /* ..., arrayref, index, value ==> ... */
+ case ICMD_AASTORE: /* ..., arrayref, index, value ==> ... */
var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
var_to_reg_int(s2, src->prev, REG_ITMP2);
- if (iptr->op1 == 0) {
+/* if (iptr->op1 == 0) { */
gen_nullptr_check(s1);
gen_bound_check;
- }
+/* } */
var_to_reg_int(s3, src, REG_ITMP3);
+
+ M_MOV(s1, rd->argintregs[0]);
+ M_MOV(s3, rd->argintregs[1]);
+ bte = iptr->val.a;
+ disp = dseg_addaddress(cd, bte->fp);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_BEQZ(REG_RESULT, 0);
+ codegen_addxstorerefs(cd, mcodeptr);
+
+ var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+ var_to_reg_int(s2, src->prev, REG_ITMP2);
+ var_to_reg_int(s3, src, REG_ITMP3);
+ M_SAADDQ(s2, s1, REG_ITMP1);
+ M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+ break;
+
+
+ case ICMD_IASTORECONST: /* ..., arrayref, index ==> ... */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
+ M_S4ADDQ(s2, s1, REG_ITMP1);
+ M_IST(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0]));
+ break;
+
+ case ICMD_LASTORECONST: /* ..., arrayref, index ==> ... */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
+ M_S8ADDQ(s2, s1, REG_ITMP1);
+ M_LST(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0]));
+ break;
+
+ case ICMD_AASTORECONST: /* ..., arrayref, index ==> ... */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
+ M_SAADDQ(s2, s1, REG_ITMP1);
+ M_AST(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+ break;
+
+ case ICMD_BASTORECONST: /* ..., arrayref, index ==> ... */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
+ if (iptr->op1 == 0) {
+ gen_nullptr_check(s1);
+ gen_bound_check;
+ }
if (has_ext_instr_set) {
M_LADD(s2, s1, REG_ITMP1);
- M_LADD(s2, REG_ITMP1, REG_ITMP1);
- M_SST (s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
- }
- else {
- M_LADD (s2, s1, REG_ITMP1);
- M_LADD (s2, REG_ITMP1, REG_ITMP1);
- M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
- M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
- M_INSWL(s3, REG_ITMP1, REG_ITMP3);
- M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
- M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+ M_INSBL(REG_ZERO, REG_ITMP1, REG_ITMP3);
+ M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
M_LST_U(REG_ITMP2, REG_ITMP1, 0);
- }
+ }
break;
- case ICMD_SASTORE: /* ..., arrayref, index, value ==> ... */
+ case ICMD_CASTORECONST: /* ..., arrayref, index ==> ... */
- var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
- var_to_reg_int(s2, src->prev, REG_ITMP2);
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- var_to_reg_int(s3, src, REG_ITMP3);
+ }
if (has_ext_instr_set) {
M_LADD(s2, s1, REG_ITMP1);
M_LADD(s2, REG_ITMP1, REG_ITMP1);
- M_SST (s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
- }
- else {
- M_LADD (s2, s1, REG_ITMP1);
- M_LADD (s2, REG_ITMP1, REG_ITMP1);
- M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
- M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
- M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+ M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0]));
+
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+ M_INSWL(REG_ZERO, REG_ITMP1, REG_ITMP3);
M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
- M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
M_LST_U(REG_ITMP2, REG_ITMP1, 0);
- }
+ }
break;
- case ICMD_BASTORE: /* ..., arrayref, index, value ==> ... */
+ case ICMD_SASTORECONST: /* ..., arrayref, index ==> ... */
- var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
- var_to_reg_int(s2, src->prev, REG_ITMP2);
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ var_to_reg_int(s2, src, REG_ITMP2);
if (iptr->op1 == 0) {
gen_nullptr_check(s1);
gen_bound_check;
- }
- var_to_reg_int(s3, src, REG_ITMP3);
+ }
if (has_ext_instr_set) {
M_LADD(s2, s1, REG_ITMP1);
- M_BST (s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
- }
- else {
- M_LADD (s2, s1, REG_ITMP1);
- M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
- M_LDA (REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
- M_INSBL(s3, REG_ITMP1, REG_ITMP3);
- M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
- M_OR (REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+
+ } else {
+ M_LADD(s2, s1, REG_ITMP1);
+ M_LADD(s2, REG_ITMP1, REG_ITMP1);
+ M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+ M_INSWL(REG_ZERO, REG_ITMP1, REG_ITMP3);
+ M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+ M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
M_LST_U(REG_ITMP2, REG_ITMP1, 0);
- }
+ }
break;
- case ICMD_PUTSTATIC: /* ..., value ==> ... */
+ case ICMD_GETSTATIC: /* ... ==> ..., value */
/* op1 = type, val.a = field address */
- a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
- M_ALD(REG_ITMP1, REG_PV, a);
- switch (iptr->op1) {
- case TYPE_INT:
- var_to_reg_int(s2, src, REG_ITMP2);
- M_IST(s2, REG_ITMP1, 0);
- break;
- case TYPE_LNG:
- var_to_reg_int(s2, src, REG_ITMP2);
- M_LST(s2, REG_ITMP1, 0);
- break;
- case TYPE_ADR:
- var_to_reg_int(s2, src, REG_ITMP2);
- M_AST(s2, REG_ITMP1, 0);
- break;
- case TYPE_FLT:
- var_to_reg_flt(s2, src, REG_FTMP2);
- M_FST(s2, REG_ITMP1, 0);
- break;
- case TYPE_DBL:
- var_to_reg_flt(s2, src, REG_FTMP2);
- M_DST(s2, REG_ITMP1, 0);
- break;
- default: panic ("internal error");
+ if (!iptr->val.a) {
+ disp = dseg_addaddress(cd, 0);
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putstatic,
+ (unresolved_field *) iptr->target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+
+ } else {
+ fieldinfo *fi = iptr->val.a;
+
+ disp = dseg_addaddress(cd, &(fi->value));
+
+ if (!fi->class->initialized) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_clinit, fi->class, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
+ }
+
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ switch (iptr->op1) {
+ case TYPE_INT:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_ILD(d, REG_ITMP1, 0);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_LNG:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_LLD(d, REG_ITMP1, 0);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_ADR:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_ALD(d, REG_ITMP1, 0);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_FLT:
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ M_FLD(d, REG_ITMP1, 0);
+ store_reg_to_var_flt(iptr->dst, d);
+ break;
+ case TYPE_DBL:
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ M_DLD(d, REG_ITMP1, 0);
+ store_reg_to_var_flt(iptr->dst, d);
+ break;
+ }
break;
- case ICMD_GETSTATIC: /* ... ==> ..., value */
+ case ICMD_PUTSTATIC: /* ..., value ==> ... */
/* op1 = type, val.a = field address */
- a = dseg_addaddress (&(((fieldinfo *)(iptr->val.a))->value));
- M_ALD(REG_ITMP1, REG_PV, a);
- switch (iptr->op1) {
- case TYPE_INT:
- d = reg_of_var(iptr->dst, REG_ITMP3);
- M_ILD(d, REG_ITMP1, 0);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_LNG:
- d = reg_of_var(iptr->dst, REG_ITMP3);
- M_LLD(d, REG_ITMP1, 0);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_ADR:
- d = reg_of_var(iptr->dst, REG_ITMP3);
- M_ALD(d, REG_ITMP1, 0);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_FLT:
- d = reg_of_var(iptr->dst, REG_FTMP1);
- M_FLD(d, REG_ITMP1, 0);
- store_reg_to_var_flt(iptr->dst, d);
- break;
- case TYPE_DBL:
- d = reg_of_var(iptr->dst, REG_FTMP1);
- M_DLD(d, REG_ITMP1, 0);
- store_reg_to_var_flt(iptr->dst, d);
- break;
- default: panic ("internal error");
+ if (!iptr->val.a) {
+ disp = dseg_addaddress(cd, 0);
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putstatic,
+ (unresolved_field *) iptr->target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ } else {
+ fieldinfo *fi = iptr->val.a;
+
+ disp = dseg_addaddress(cd, &(fi->value));
+
+ if (!fi->class->initialized) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_clinit, fi->class, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
+ }
+
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ switch (iptr->op1) {
+ case TYPE_INT:
+ var_to_reg_int(s2, src, REG_ITMP2);
+ M_IST(s2, REG_ITMP1, 0);
+ break;
+ case TYPE_LNG:
+ var_to_reg_int(s2, src, REG_ITMP2);
+ M_LST(s2, REG_ITMP1, 0);
+ break;
+ case TYPE_ADR:
+ var_to_reg_int(s2, src, REG_ITMP2);
+ M_AST(s2, REG_ITMP1, 0);
+ break;
+ case TYPE_FLT:
+ var_to_reg_flt(s2, src, REG_FTMP2);
+ M_FST(s2, REG_ITMP1, 0);
+ break;
+ case TYPE_DBL:
+ var_to_reg_flt(s2, src, REG_FTMP2);
+ M_DST(s2, REG_ITMP1, 0);
+ break;
+ }
break;
+ case ICMD_PUTSTATICCONST: /* ... ==> ... */
+ /* val = value (in current instruction) */
+ /* op1 = type, val.a = field address (in */
+ /* following NOP) */
- case ICMD_PUTFIELD: /* ..., value ==> ... */
- /* op1 = type, val.i = field offset */
+ if (!iptr[1].val.a) {
+ disp = dseg_addaddress(cd, 0);
- a = ((fieldinfo *)(iptr->val.a))->offset;
- switch (iptr->op1) {
- case TYPE_INT:
- var_to_reg_int(s1, src->prev, REG_ITMP1);
- var_to_reg_int(s2, src, REG_ITMP2);
- gen_nullptr_check(s1);
- M_IST(s2, s1, a);
- break;
- case TYPE_LNG:
- var_to_reg_int(s1, src->prev, REG_ITMP1);
- var_to_reg_int(s2, src, REG_ITMP2);
- gen_nullptr_check(s1);
- M_LST(s2, s1, a);
- break;
- case TYPE_ADR:
- var_to_reg_int(s1, src->prev, REG_ITMP1);
- var_to_reg_int(s2, src, REG_ITMP2);
- gen_nullptr_check(s1);
- M_AST(s2, s1, a);
- break;
- case TYPE_FLT:
- var_to_reg_int(s1, src->prev, REG_ITMP1);
- var_to_reg_flt(s2, src, REG_FTMP2);
- gen_nullptr_check(s1);
- M_FST(s2, s1, a);
- break;
- case TYPE_DBL:
- var_to_reg_int(s1, src->prev, REG_ITMP1);
- var_to_reg_flt(s2, src, REG_FTMP2);
- gen_nullptr_check(s1);
- M_DST(s2, s1, a);
- break;
- default: panic ("internal error");
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putstatic,
+ (unresolved_field *) iptr[1].target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ } else {
+ fieldinfo *fi = iptr[1].val.a;
+
+ disp = dseg_addaddress(cd, &(fi->value));
+
+ if (!fi->class->initialized) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_clinit, fi->class, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
+ }
+
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ switch (iptr->op1) {
+ case TYPE_INT:
+ M_IST(REG_ZERO, REG_ITMP1, 0);
+ break;
+ case TYPE_LNG:
+ M_LST(REG_ZERO, REG_ITMP1, 0);
+ break;
+ case TYPE_ADR:
+ M_AST(REG_ZERO, REG_ITMP1, 0);
+ break;
+ case TYPE_FLT:
+ M_FST(REG_ZERO, REG_ITMP1, 0);
+ break;
+ case TYPE_DBL:
+ M_DST(REG_ZERO, REG_ITMP1, 0);
+ break;
+ }
break;
+
case ICMD_GETFIELD: /* ... ==> ..., value */
/* op1 = type, val.i = field offset */
- a = ((fieldinfo *)(iptr->val.a))->offset;
+ var_to_reg_int(s1, src, REG_ITMP1);
+ gen_nullptr_check(s1);
+
+ if (!iptr->val.a) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putfield,
+ (unresolved_field *) iptr->target, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ disp = 0;
+
+ } else {
+ disp = ((fieldinfo *) (iptr->val.a))->offset;
+ }
+
switch (iptr->op1) {
- case TYPE_INT:
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- gen_nullptr_check(s1);
- M_ILD(d, s1, a);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_LNG:
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- gen_nullptr_check(s1);
- M_LLD(d, s1, a);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_ADR:
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- gen_nullptr_check(s1);
- M_ALD(d, s1, a);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case TYPE_FLT:
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_FTMP1);
- gen_nullptr_check(s1);
- M_FLD(d, s1, a);
- store_reg_to_var_flt(iptr->dst, d);
- break;
- case TYPE_DBL:
- var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_FTMP1);
- gen_nullptr_check(s1);
- M_DLD(d, s1, a);
- store_reg_to_var_flt(iptr->dst, d);
- break;
- default: panic ("internal error");
- }
+ case TYPE_INT:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_ILD(d, s1, disp);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_LNG:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_LLD(d, s1, disp);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_ADR:
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ M_ALD(d, s1, disp);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+ case TYPE_FLT:
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ M_FLD(d, s1, disp);
+ store_reg_to_var_flt(iptr->dst, d);
+ break;
+ case TYPE_DBL:
+ d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+ M_DLD(d, s1, disp);
+ store_reg_to_var_flt(iptr->dst, d);
+ break;
+ }
break;
+ case ICMD_PUTFIELD: /* ..., objectref, value ==> ... */
+ /* op1 = type, val.a = field address */
+
+ var_to_reg_int(s1, src->prev, REG_ITMP1);
+ gen_nullptr_check(s1);
- /* branch operations **************************************************/
+ if (!IS_FLT_DBL_TYPE(iptr->op1)) {
+ var_to_reg_int(s2, src, REG_ITMP2);
+ } else {
+ var_to_reg_flt(s2, src, REG_FTMP2);
+ }
+
+ if (!iptr->val.a) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putfield,
+ (unresolved_field *) iptr->target, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
-#define ALIGNCODENOP {if((int)((long)mcodeptr&7)){M_NOP;}}
+ disp = 0;
+
+ } else {
+ disp = ((fieldinfo *) (iptr->val.a))->offset;
+ }
+
+ switch (iptr->op1) {
+ case TYPE_INT:
+ M_IST(s2, s1, disp);
+ break;
+ case TYPE_LNG:
+ M_LST(s2, s1, disp);
+ break;
+ case TYPE_ADR:
+ M_AST(s2, s1, disp);
+ break;
+ case TYPE_FLT:
+ M_FST(s2, s1, disp);
+ break;
+ case TYPE_DBL:
+ M_DST(s2, s1, disp);
+ break;
+ }
+ break;
+
+ case ICMD_PUTFIELDCONST: /* ..., objectref ==> ... */
+ /* val = value (in current instruction) */
+ /* op1 = type, val.a = field address (in */
+ /* following NOP) */
+
+ var_to_reg_int(s1, src, REG_ITMP1);
+ gen_nullptr_check(s1);
+
+ if (!iptr[1].val.a) {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_get_putfield,
+ (unresolved_field *) iptr[1].target, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ disp = 0;
+
+ } else {
+ disp = ((fieldinfo *) (iptr[1].val.a))->offset;
+ }
+
+ switch (iptr[1].op1) {
+ case TYPE_INT:
+ M_IST(REG_ZERO, s1, disp);
+ break;
+ case TYPE_LNG:
+ M_LST(REG_ZERO, s1, disp);
+ break;
+ case TYPE_ADR:
+ M_AST(REG_ZERO, s1, disp);
+ break;
+ case TYPE_FLT:
+ M_FST(REG_ZERO, s1, disp);
+ break;
+ case TYPE_DBL:
+ M_DST(REG_ZERO, s1, disp);
+ break;
+ }
+ break;
+
+
+ /* branch operations **************************************************/
case ICMD_ATHROW: /* ..., objectref ==> ... (, objectref) */
var_to_reg_int(s1, src, REG_ITMP1);
M_INTMOVE(s1, REG_ITMP1_XPTR);
- a = dseg_addaddress(asm_handle_exception);
- M_ALD(REG_ITMP2, REG_PV, a);
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP2, REG_PV, disp);
M_JMP(REG_ITMP2_XPC, REG_ITMP2);
M_NOP; /* nop ensures that XPC is less than the end */
/* of basic block */
case ICMD_GOTO: /* ... ==> ... */
/* op1 = target JavaVM pc */
M_BR(0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
ALIGNCODENOP;
break;
/* op1 = target JavaVM pc */
M_BSR(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_RET: /* ... ==> ... */
/* op1 = local variable */
- var = &(locals[iptr->op1][TYPE_ADR]);
+ var = &(rd->locals[iptr->op1][TYPE_ADR]);
if (var->flags & INMEMORY) {
M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff);
M_RET(REG_ZERO, REG_ITMP1);
var_to_reg_int(s1, src, REG_ITMP1);
M_BEQZ(s1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFNONNULL: /* ..., value ==> ... */
var_to_reg_int(s1, src, REG_ITMP1);
M_BNEZ(s1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFEQ: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFLT: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFLE: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFNE: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFGT: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IFGE: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LEQ: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LLT: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LLE: /* ..., value ==> ... */
}
M_BNEZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LNE: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LGT: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_LGE: /* ..., value ==> ... */
}
M_BEQZ(REG_ITMP1, 0);
}
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPEQ: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPEQ(s1, s2, REG_ITMP1);
M_BNEZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPNE: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPEQ(s1, s2, REG_ITMP1);
M_BEQZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPLT: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPLT(s1, s2, REG_ITMP1);
M_BNEZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPGT: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPLE(s1, s2, REG_ITMP1);
M_BEQZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPLE: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPLE(s1, s2, REG_ITMP1);
M_BNEZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
case ICMD_IF_ICMPGE: /* ..., value, value ==> ... */
var_to_reg_int(s2, src, REG_ITMP2);
M_CMPLT(s1, s2, REG_ITMP1);
M_BEQZ(REG_ITMP1, 0);
- codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+ codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
break;
/* (value xx 0) ? IFxx_ICONST : ELSE_ICONST */
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if (iptr[1].opc == ICMD_ELSE_ICONST) {
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPEQ(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPEQ(s1, REG_ZERO, d);
M_XOR_IMM(d, 1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVEQ_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVEQ(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if (iptr[1].opc == ICMD_ELSE_ICONST) {
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPEQ(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPEQ(s1, REG_ZERO, d);
M_XOR_IMM(d, 1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVNE_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVNE(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPLT(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPLE(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVLT_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVLT(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPLE(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPLT(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVGE_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVGE(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPLT(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPLE(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVGT_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVGT(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
/* val.i = constant */
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
s3 = iptr->val.i;
if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
if ((s3 == 1) && (iptr[1].val.i == 0)) {
M_CMPLE(s1, REG_ZERO, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if ((s3 == 0) && (iptr[1].val.i == 1)) {
M_CMPLT(REG_ZERO, s1, d);
store_reg_to_var_int(iptr->dst, d);
break;
- }
+ }
if (s1 == d) {
M_MOV(s1, REG_ITMP1);
s1 = REG_ITMP1;
- }
- ICONST(d, iptr[1].val.i);
}
+ ICONST(d, iptr[1].val.i);
+ }
if ((s3 >= 0) && (s3 <= 255)) {
M_CMOVLE_IMM(s1, s3, d);
- }
- else {
+ } else {
ICONST(REG_ITMP2, s3);
M_CMOVLE(s1, REG_ITMP2, d);
- }
+ }
store_reg_to_var_int(iptr->dst, d);
break;
case ICMD_LRETURN:
case ICMD_ARETURN:
-#ifdef USE_THREADS
- if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
- a = dseg_addaddress ((void*) (builtin_monitorexit));
- M_ALD(REG_PV, REG_PV, a);
- M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- }
-#endif
var_to_reg_int(s1, src, REG_RESULT);
M_INTMOVE(s1, REG_RESULT);
+
goto nowperformreturn;
case ICMD_FRETURN: /* ..., retvalue ==> ... */
case ICMD_DRETURN:
-#ifdef USE_THREADS
- if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
- a = dseg_addaddress ((void*) (builtin_monitorexit));
- M_ALD(REG_PV, REG_PV, a);
- M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- }
-#endif
var_to_reg_flt(s1, src, REG_FRESULT);
M_FLTMOVE(s1, REG_FRESULT);
- goto nowperformreturn;
- case ICMD_RETURN: /* ... ==> ... */
+ goto nowperformreturn;
-#ifdef USE_THREADS
- if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
- a = dseg_addaddress ((void*) (builtin_monitorexit));
- M_ALD(REG_PV, REG_PV, a);
- M_ALD(argintregs[0], REG_SP, 8 * maxmemuse);
- M_JSR(REG_RA, REG_PV);
- M_LDA(REG_PV, REG_RA, -(int)((u1*) mcodeptr - mcodebase));
- }
-#endif
+ case ICMD_RETURN: /* ... ==> ... */
nowperformreturn:
{
- int r, p;
+ s4 i, p;
p = parentargs_base;
+ /* call trace function */
+
+ if (runverbose) {
+ M_LDA(REG_SP, REG_SP, -3 * 8);
+ M_AST(REG_RA, REG_SP, 0 * 8);
+ M_LST(REG_RESULT, REG_SP, 1 * 8);
+ M_DST(REG_FRESULT, REG_SP, 2 * 8);
+
+ disp = dseg_addaddress(cd, m);
+ M_ALD(rd->argintregs[0], REG_PV, disp);
+ M_MOV(REG_RESULT, rd->argintregs[1]);
+ M_FLTMOVE(REG_FRESULT, rd->argfltregs[2]);
+ M_FLTMOVE(REG_FRESULT, rd->argfltregs[3]);
+
+ disp = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_DLD(REG_FRESULT, REG_SP, 2 * 8);
+ M_LLD(REG_RESULT, REG_SP, 1 * 8);
+ M_ALD(REG_RA, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 3 * 8);
+ }
+
+#if defined(USE_THREADS)
+ if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+ s4 disp;
+
+ M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
+
+ switch (iptr->opc) {
+ case ICMD_IRETURN:
+ case ICMD_LRETURN:
+ case ICMD_ARETURN:
+ M_LST(REG_RESULT, REG_SP, rd->memuse * 8);
+ break;
+ case ICMD_FRETURN:
+ case ICMD_DRETURN:
+ M_DST(REG_FRESULT, REG_SP, rd->memuse * 8);
+ break;
+ }
+
+ disp = dseg_addaddress(cd, BUILTIN_monitorexit);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, disp);
+
+ switch (iptr->opc) {
+ case ICMD_IRETURN:
+ case ICMD_LRETURN:
+ case ICMD_ARETURN:
+ M_LLD(REG_RESULT, REG_SP, rd->memuse * 8);
+ break;
+ case ICMD_FRETURN:
+ case ICMD_DRETURN:
+ M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
+ break;
+ }
+ }
+#endif
+
/* restore return address */
- if (!isleafmethod)
- {p--; M_LLD (REG_RA, REG_SP, 8 * p);}
+ if (!m->isleafmethod) {
+ p--; M_LLD(REG_RA, REG_SP, p * 8);
+ }
/* restore saved registers */
- for (r = savintregcnt - 1; r >= maxsavintreguse; r--)
- {p--; M_LLD(savintregs[r], REG_SP, 8 * p);}
- for (r = savfltregcnt - 1; r >= maxsavfltreguse; r--)
- {p--; M_DLD(savfltregs[r], REG_SP, 8 * p);}
+ for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
+ p--; M_LLD(rd->savintregs[i], REG_SP, p * 8);
+ }
+ for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
+ p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8);
+ }
/* deallocate stack */
- if (parentargs_base)
- {M_LDA(REG_SP, REG_SP, parentargs_base*8);}
-
- /* call trace function */
-
- if (runverbose) {
- M_LDA (REG_SP, REG_SP, -24);
- M_AST(REG_RA, REG_SP, 0);
- M_LST(REG_RESULT, REG_SP, 8);
- M_DST(REG_FRESULT, REG_SP,16);
- a = dseg_addaddress (method);
- M_ALD(argintregs[0], REG_PV, a);
- M_MOV(REG_RESULT, argintregs[1]);
- M_FLTMOVE(REG_FRESULT, argfltregs[2]);
- M_FLTMOVE(REG_FRESULT, argfltregs[3]);
- a = dseg_addaddress ((void*) (builtin_displaymethodstop));
- M_ALD(REG_PV, REG_PV, a);
- M_JSR (REG_RA, REG_PV);
- s1 = (int)((u1*) mcodeptr - mcodebase);
- if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1);
- else {
- s4 ml=-s1, mh=0;
- while (ml<-32768) { ml+=65536; mh--; }
- M_LDA (REG_PV, REG_RA, ml );
- M_LDAH (REG_PV, REG_PV, mh );
- }
- M_DLD(REG_FRESULT, REG_SP,16);
- M_LLD(REG_RESULT, REG_SP, 8);
- M_ALD(REG_RA, REG_SP, 0);
- M_LDA (REG_SP, REG_SP, 24);
- }
+ if (parentargs_base) {
+ M_LDA(REG_SP, REG_SP, parentargs_base * 8);
+ }
M_RET(REG_ZERO, REG_RA);
ALIGNCODENOP;
i = s4ptr[2]; /* high */
var_to_reg_int(s1, src, REG_ITMP1);
- if (l == 0)
- {M_INTMOVE(s1, REG_ITMP1);}
- else if (l <= 32768) {
+ if (l == 0) {
+ M_INTMOVE(s1, REG_ITMP1);
+ } else if (l <= 32768) {
M_LDA(REG_ITMP1, s1, -l);
- }
- else {
+ } else {
ICONST(REG_ITMP2, l);
M_ISUB(s1, REG_ITMP2, REG_ITMP1);
- }
+ }
i = i - l + 1;
/* range check */
else {
M_LDA(REG_ITMP2, REG_ZERO, i - 1);
M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
- }
+ }
M_BEQZ(REG_ITMP2, 0);
-
-
- /* codegen_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr); */
- codegen_addreference((basicblock *) tptr[0], mcodeptr);
+ codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
/* build jump table top down and use address of lowest entry */
tptr += i;
while (--i >= 0) {
- /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */
- dseg_addtarget((basicblock *) tptr[0]);
+ dseg_addtarget(cd, (basicblock *) tptr[0]);
--tptr;
- }
+ }
}
/* length of dataseg after last dseg_addtarget is used by load */
M_SAADDQ(REG_ITMP1, REG_PV, REG_ITMP2);
- M_ALD(REG_ITMP2, REG_ITMP2, -dseglen);
+ M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
M_JMP(REG_ZERO, REG_ITMP2);
ALIGNCODENOP;
break;
val = s4ptr[0];
if ((val >= 0) && (val <= 255)) {
M_CMPEQ_IMM(s1, val, REG_ITMP2);
- }
- else {
+ } else {
if ((val >= -32768) && (val <= 32767)) {
M_LDA(REG_ITMP2, REG_ZERO, val);
- }
- else {
- a = dseg_adds4 (val);
- M_ILD(REG_ITMP2, REG_PV, a);
- }
- M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
+ } else {
+ disp = dseg_adds4(cd, val);
+ M_ILD(REG_ITMP2, REG_PV, disp);
}
- M_BNEZ(REG_ITMP2, 0);
- /* codegen_addreference(BlockPtrOfPC(s4ptr[1]), mcodeptr); */
- codegen_addreference((basicblock *) tptr[0], mcodeptr);
+ M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
}
+ M_BNEZ(REG_ITMP2, 0);
+ codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
+ }
M_BR(0);
- /* codegen_addreference(BlockPtrOfPC(l), mcodeptr); */
tptr = (void **) iptr->target;
- codegen_addreference((basicblock *) tptr[0], mcodeptr);
+ codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
ALIGNCODENOP;
break;
}
- case ICMD_BUILTIN3: /* ..., arg1, arg2, arg3 ==> ... */
- /* op1 = return type, val.a = function pointer*/
- s3 = 3;
- goto gen_method;
-
- case ICMD_BUILTIN2: /* ..., arg1, arg2 ==> ... */
- /* op1 = return type, val.a = function pointer*/
- s3 = 2;
- goto gen_method;
+ case ICMD_BUILTIN: /* ..., arg1, arg2, arg3 ==> ... */
+ /* op1 = arg count val.a = builtintable entry */
- case ICMD_BUILTIN1: /* ..., arg1 ==> ... */
- /* op1 = return type, val.a = function pointer*/
- s3 = 1;
+ bte = iptr->val.a;
+ md = bte->md;
goto gen_method;
case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ... */
/* op1 = arg count, val.a = method pointer */
case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
- /* op1 = arg count, val.a = method pointer */
-
- case ICMD_INVOKEVIRTUAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
- /* op1 = arg count, val.a = method pointer */
+ case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer */
+ case ICMD_INVOKEINTERFACE:
- case ICMD_INVOKEINTERFACE:/*.., objectref, [arg1, [arg2 ...]] ==> ... */
- /* op1 = arg count, val.a = method pointer */
+ lm = iptr->val.a;
- s3 = iptr->op1;
+ if (lm)
+ md = lm->parseddesc;
+ else {
+ unresolved_method *um = iptr->target;
+ md = um->methodref->parseddesc.md;
+ }
-gen_method: {
- methodinfo *m;
- classinfo *ci;
+gen_method:
+ s3 = md->paramcount;
MCODECHECK((s3 << 1) + 64);
/* copy arguments to registers or stack location */
- for (; --s3 >= 0; src = src->prev) {
+ for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
if (src->varkind == ARGVAR)
continue;
if (IS_INT_LNG_TYPE(src->type)) {
- if (s3 < INT_ARG_CNT) {
- s1 = argintregs[s3];
+ if (!md->params[s3].inmemory) {
+ s1 = rd->argintregs[md->params[s3].regoff];
var_to_reg_int(d, src, s1);
M_INTMOVE(d, s1);
- }
- else {
+ } else {
var_to_reg_int(d, src, REG_ITMP1);
- M_LST(d, REG_SP, 8 * (s3 - INT_ARG_CNT));
- }
+ M_LST(d, REG_SP, md->params[s3].regoff * 8);
}
- else
- if (s3 < FLT_ARG_CNT) {
- s1 = argfltregs[s3];
+
+ } else {
+ if (!md->params[s3].inmemory) {
+ s1 = rd->argfltregs[md->params[s3].regoff];
var_to_reg_flt(d, src, s1);
M_FLTMOVE(d, s1);
- }
- else {
+ } else {
var_to_reg_flt(d, src, REG_FTMP1);
- M_DST(d, REG_SP, 8 * (s3 - FLT_ARG_CNT));
- }
- } /* end of for */
+ M_DST(d, REG_SP, md->params[s3].regoff * 8);
+ }
+ }
+ }
- m = iptr->val.a;
switch (iptr->opc) {
- case ICMD_BUILTIN3:
- case ICMD_BUILTIN2:
- case ICMD_BUILTIN1:
- a = dseg_addaddress ((void*) (m));
+ case ICMD_BUILTIN:
+ if (iptr->target) {
+ disp = dseg_addaddress(cd, NULL);
+
+ codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target,
+ disp);
- M_ALD(REG_PV, REG_PV, a); /* Pointer to built-in-function */
- d = iptr->op1;
- goto makeactualcall;
+ if (opt_showdisassemble)
+ M_NOP;
- case ICMD_INVOKESTATIC:
- case ICMD_INVOKESPECIAL:
- a = dseg_addaddress (m->stubroutine);
+ } else {
+ disp = dseg_addaddress(cd, bte->fp);
+ }
+
+ d = md->returntype.type;
+
+ M_ALD(REG_PV, REG_PV, disp); /* Pointer to built-in-function */
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
- M_ALD(REG_PV, REG_PV, a ); /* method pointer in r27 */
+ /* if op1 == true, we need to check for an exception */
- d = m->returntype;
- goto makeactualcall;
+ if (iptr->op1 == true) {
+ M_BEQZ(REG_RESULT, 0);
+ codegen_addxexceptionrefs(cd, mcodeptr);
+ }
+ break;
- case ICMD_INVOKEVIRTUAL:
+ case ICMD_INVOKESPECIAL:
+ M_BEQZ(rd->argintregs[0], 0);
+ codegen_addxnullrefs(cd, mcodeptr);
+ /* fall through */
- gen_nullptr_check(argintregs[0]);
- M_ALD(REG_METHODPTR, argintregs[0],
- OFFSET(java_objectheader, vftbl));
- M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl, table[0]) +
- sizeof(methodptr) * m->vftblindex);
+ case ICMD_INVOKESTATIC:
+ if (!lm) {
+ unresolved_method *um = iptr->target;
- d = m->returntype;
- goto makeactualcall;
+ disp = dseg_addaddress(cd, NULL);
- case ICMD_INVOKEINTERFACE:
- ci = m->class;
-
- gen_nullptr_check(argintregs[0]);
- M_ALD(REG_METHODPTR, argintregs[0],
- OFFSET(java_objectheader, vftbl));
- M_ALD(REG_METHODPTR, REG_METHODPTR,
- OFFSET(vftbl, interfacetable[0]) -
- sizeof(methodptr*) * ci->index);
- M_ALD(REG_PV, REG_METHODPTR,
- sizeof(methodptr) * (m - ci->methods));
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_invokestatic_special, um, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
- d = m->returntype;
- goto makeactualcall;
+ d = um->methodref->parseddesc.md->returntype.type;
- default:
- d = 0;
- sprintf (logtext, "Unkown ICMD-Command: %d", iptr->opc);
- error ();
+ } else {
+ disp = dseg_addaddress(cd, lm->stubroutine);
+ d = lm->parseddesc->returntype.type;
}
-makeactualcall:
+ M_ALD(REG_PV, REG_PV, disp); /* method pointer in r27 */
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ break;
- M_JSR (REG_RA, REG_PV);
+ case ICMD_INVOKEVIRTUAL:
+ gen_nullptr_check(rd->argintregs[0]);
- /* recompute pv */
+ if (!lm) {
+ unresolved_method *um = iptr->target;
- s1 = (int)((u1*) mcodeptr - mcodebase);
- if (s1<=32768) M_LDA (REG_PV, REG_RA, -s1);
- else {
- s4 ml=-s1, mh=0;
- while (ml<-32768) { ml+=65536; mh--; }
- M_LDA (REG_PV, REG_RA, ml );
- M_LDAH (REG_PV, REG_PV, mh );
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_invokevirtual, um, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ s1 = 0;
+ d = um->methodref->parseddesc.md->returntype.type;
+
+ } else {
+ s1 = OFFSET(vftbl_t, table[0]) +
+ sizeof(methodptr) * lm->vftblindex;
+ d = lm->parseddesc->returntype.type;
+ }
+
+ M_ALD(REG_METHODPTR, rd->argintregs[0],
+ OFFSET(java_objectheader, vftbl));
+ M_ALD(REG_PV, REG_METHODPTR, s1);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ break;
+
+ case ICMD_INVOKEINTERFACE:
+ gen_nullptr_check(rd->argintregs[0]);
+
+ if (!lm) {
+ unresolved_method *um = iptr->target;
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_invokeinterface, um, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ s1 = 0;
+ s2 = 0;
+ d = um->methodref->parseddesc.md->returntype.type;
+
+ } else {
+ s1 = OFFSET(vftbl_t, interfacetable[0]) -
+ sizeof(methodptr*) * lm->class->index;
+
+ s2 = sizeof(methodptr) * (lm - lm->class->methods);
+
+ d = lm->parseddesc->returntype.type;
}
+
+ M_ALD(REG_METHODPTR, rd->argintregs[0],
+ OFFSET(java_objectheader, vftbl));
+ M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
+ M_ALD(REG_PV, REG_METHODPTR, s2);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ break;
+ }
/* d contains return type */
if (d != TYPE_VOID) {
if (IS_INT_LNG_TYPE(iptr->dst->type)) {
- s1 = reg_of_var(iptr->dst, REG_RESULT);
+ s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
M_INTMOVE(REG_RESULT, s1);
store_reg_to_var_int(iptr->dst, s1);
- }
- else {
- s1 = reg_of_var(iptr->dst, REG_FRESULT);
+ } else {
+ s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
M_FLTMOVE(REG_FRESULT, s1);
store_reg_to_var_flt(iptr->dst, s1);
- }
}
}
break;
- case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
+ case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
/* op1: 0 == array, 1 == class */
/* val.a: (classinfo*) superclass */
-/* superclass is an interface:
- *
- * return (sub != NULL) &&
- * (sub->vftbl->interfacetablelength > super->index) &&
- * (sub->vftbl->interfacetable[-super->index] != NULL);
- *
- * superclass is a class:
- *
- * return ((sub != NULL) && (0
- * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
- * super->vftbl->diffvall));
- */
+ /* superclass is an interface:
+ *
+ * OK if ((sub == NULL) ||
+ * (sub->vftbl->interfacetablelength > super->index) &&
+ * (sub->vftbl->interfacetable[-super->index] != NULL));
+ *
+ * superclass is a class:
+ *
+ * OK if ((sub == NULL) || (0
+ * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
+ * super->vftbl->diffval));
+ */
{
- classinfo *super = (classinfo*) iptr->val.a;
+ classinfo *super;
+ vftbl_t *supervftbl;
+ s4 superindex;
+
+ super = (classinfo *) iptr->val.a;
+
+ if (!super) {
+ superindex = 0;
+ supervftbl = NULL;
+
+ } else {
+ superindex = super->index;
+ supervftbl = super->vftbl;
+ }
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
var_to_reg_int(s1, src, REG_ITMP1);
- d = reg_of_var(iptr->dst, REG_ITMP3);
- if (s1 == d) {
- M_MOV(s1, REG_ITMP1);
- s1 = REG_ITMP1;
+
+ /* calculate interface checkcast code size */
+
+ s2 = 6;
+ if (!super)
+ s2 += opt_showdisassemble ? 1 : 0;
+
+ /* calculate class checkcast code size */
+
+ s3 = 9 /* 8 + (s1 == REG_ITMP1) */;
+ if (!super)
+ s3 += opt_showdisassemble ? 1 : 0;
+
+ /* if class is not resolved, check which code to call */
+
+ if (!super) {
+ M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
+
+ disp = dseg_adds4(cd, 0); /* super->flags */
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_flags,
+ (constant_classref *) iptr->target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ M_ILD(REG_ITMP2, REG_PV, disp);
+ disp = dseg_adds4(cd, ACC_INTERFACE);
+ M_ILD(REG_ITMP3, REG_PV, disp);
+ M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_BEQZ(REG_ITMP2, s2 + 1);
+ }
+
+ /* interface checkcast code */
+
+ if (!super || (super->flags & ACC_INTERFACE)) {
+ if (super) {
+ M_BEQZ(s1, s2);
+
+ } else {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_interface,
+ (constant_classref *) iptr->target, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
- M_CLR(d);
- if (iptr->op1) { /* class/interface */
- if (super->flags & ACC_INTERFACE) { /* interface */
- M_BEQZ(s1, 6);
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
- M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
- M_BLEZ(REG_ITMP2, 2);
- M_ALD(REG_ITMP1, REG_ITMP1,
- OFFSET(vftbl, interfacetable[0]) -
- super->index * sizeof(methodptr*));
- M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */
- }
- else { /* class */
-/*
- s2 = super->vftbl->diffval;
- M_BEQZ(s1, 4 + (s2 > 255));
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
- M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
- if (s2 <= 255)
- M_CMPULE_IMM(REG_ITMP1, s2, d);
- else {
- M_LDA(REG_ITMP2, REG_ZERO, s2);
- M_CMPULE(REG_ITMP1, REG_ITMP2, d);
- }
-*/
- M_BEQZ(s1, 7);
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- a = dseg_addaddress ((void*) super->vftbl);
- M_ALD(REG_ITMP2, REG_PV, a);
- M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
- M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
- M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
- M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
- M_CMPULE(REG_ITMP1, REG_ITMP2, d);
- }
+
+ M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+ M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
+ M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
+ M_BLEZ(REG_ITMP3, 0);
+ codegen_addxcastrefs(cd, mcodeptr);
+ M_ALD(REG_ITMP3, REG_ITMP2,
+ (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+ superindex * sizeof(methodptr*)));
+ M_BEQZ(REG_ITMP3, 0);
+ codegen_addxcastrefs(cd, mcodeptr);
+
+ if (!super)
+ M_BR(s3);
+ }
+
+ /* class checkcast code */
+
+ if (!super || !(super->flags & ACC_INTERFACE)) {
+ disp = dseg_addaddress(cd, supervftbl);
+
+ if (super) {
+ M_BEQZ(s1, s3);
+
+ } else {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_class,
+ (constant_classref *) iptr->target,
+ disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
- else
- panic ("internal error: no inlined array instanceof");
+
+ M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+ M_ALD(REG_ITMP3, REG_PV, disp);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
+ M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
+/* if (s1 != REG_ITMP1) { */
+/* M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
+/* M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */
+/* #if defined(USE_THREADS) && defined(NATIVE_THREADS) */
+/* codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */
+/* #endif */
+/* M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */
+
+/* } else { */
+ M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
+ M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
+/* } */
+ M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3);
+ M_BEQZ(REG_ITMP3, 0);
+ codegen_addxcastrefs(cd, mcodeptr);
}
+ d = reg_of_var(rd, iptr->dst, s1);
+ M_INTMOVE(s1, d);
store_reg_to_var_int(iptr->dst, d);
+ }
break;
- case ICMD_CHECKCAST: /* ..., objectref ==> ..., objectref */
+ case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref */
+ /* op1: 1... resolved, 0... not resolved */
+
+ var_to_reg_int(s1, src, rd->argintregs[0]);
+ M_INTMOVE(s1, rd->argintregs[0]);
+
+ bte = iptr->val.a;
+
+ disp = dseg_addaddress(cd, iptr->target);
+
+ if (!iptr->op1) {
+ codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ a = 0;
+
+ } else {
+ a = (ptrint) bte->fp;
+ }
+
+ M_ALD(rd->argintregs[1], REG_PV, disp);
+
+ disp = dseg_addaddress(cd, a);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_BEQZ(REG_RESULT, 0);
+ codegen_addxcastrefs(cd, mcodeptr);
+
+ var_to_reg_int(s1, src, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, s1);
+ M_INTMOVE(s1, d);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+
+ case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult */
/* op1: 0 == array, 1 == class */
/* val.a: (classinfo*) superclass */
-/* superclass is an interface:
- *
- * OK if ((sub == NULL) ||
- * (sub->vftbl->interfacetablelength > super->index) &&
- * (sub->vftbl->interfacetable[-super->index] != NULL));
- *
- * superclass is a class:
- *
- * OK if ((sub == NULL) || (0
- * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
- * super->vftbl->diffvall));
- */
+ /* superclass is an interface:
+ *
+ * return (sub != NULL) &&
+ * (sub->vftbl->interfacetablelength > super->index) &&
+ * (sub->vftbl->interfacetable[-super->index] != NULL);
+ *
+ * superclass is a class:
+ *
+ * return ((sub != NULL) && (0
+ * <= (sub->vftbl->baseval - super->vftbl->baseval) <=
+ * super->vftbl->diffvall));
+ */
{
- classinfo *super = (classinfo*) iptr->val.a;
+ classinfo *super;
+ vftbl_t *supervftbl;
+ s4 superindex;
+
+ super = (classinfo *) iptr->val.a;
+
+ if (!super) {
+ superindex = 0;
+ supervftbl = NULL;
+
+ } else {
+ superindex = super->index;
+ supervftbl = super->vftbl;
+ }
- d = reg_of_var(iptr->dst, REG_ITMP3);
- var_to_reg_int(s1, src, d);
- if (iptr->op1) { /* class/interface */
- if (super->flags & ACC_INTERFACE) { /* interface */
- M_BEQZ(s1, 6);
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
- M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
- M_BLEZ(REG_ITMP2, 0);
- codegen_addxcastrefs(mcodeptr);
- M_ALD(REG_ITMP2, REG_ITMP1,
- OFFSET(vftbl, interfacetable[0]) -
- super->index * sizeof(methodptr*));
- M_BEQZ(REG_ITMP2, 0);
- codegen_addxcastrefs(mcodeptr);
- }
- else { /* class */
-/*
- s2 = super->vftbl->diffval;
- M_BEQZ(s1, 4 + (s2 != 0) + (s2 > 255));
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
- M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
- if (s2 == 0) {
- M_BNEZ(REG_ITMP1, 0);
- }
- else if (s2 <= 255) {
- M_CMPULE_IMM(REG_ITMP1, s2, REG_ITMP2);
- M_BEQZ(REG_ITMP2, 0);
- }
- else {
- M_LDA(REG_ITMP2, REG_ZERO, s2);
- M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
- M_BEQZ(REG_ITMP2, 0);
- }
-*/
- M_BEQZ(s1, 8 + (d == REG_ITMP3));
- M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
- a = dseg_addaddress ((void*) super->vftbl);
- M_ALD(REG_ITMP2, REG_PV, a);
- M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
- if (d != REG_ITMP3) {
- M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
- M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
- M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
- }
- else {
- M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, baseval));
- M_ISUB(REG_ITMP1, REG_ITMP2, REG_ITMP1);
- M_ALD(REG_ITMP2, REG_PV, a);
- M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
- }
- M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
- M_BEQZ(REG_ITMP2, 0);
- codegen_addxcastrefs(mcodeptr);
- }
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
+ var_to_reg_int(s1, src, REG_ITMP1);
+ d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+ if (s1 == d) {
+ M_MOV(s1, REG_ITMP1);
+ s1 = REG_ITMP1;
+ }
+
+ /* calculate interface instanceof code size */
+
+ s2 = 6;
+ if (!super)
+ s2 += (d == REG_ITMP2 ? 1 : 0) + (opt_showdisassemble ? 1 : 0);
+
+ /* calculate class instanceof code size */
+
+ s3 = 7;
+ if (!super)
+ s3 += (opt_showdisassemble ? 1 : 0);
+
+ /* if class is not resolved, check which code to call */
+
+ if (!super) {
+ M_CLR(d);
+ M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
+
+ disp = dseg_adds4(cd, 0); /* super->flags */
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_flags,
+ (constant_classref *) iptr->target, disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ M_ILD(REG_ITMP3, REG_PV, disp);
+
+ disp = dseg_adds4(cd, ACC_INTERFACE);
+ M_ILD(REG_ITMP2, REG_PV, disp);
+ M_AND(REG_ITMP3, REG_ITMP2, REG_ITMP3);
+ M_BEQZ(REG_ITMP3, s2 + 1);
+ }
+
+ /* interface instanceof code */
+
+ if (!super || (super->flags & ACC_INTERFACE)) {
+ if (super) {
+ M_CLR(d);
+ M_BEQZ(s1, s2);
+
+ } else {
+ /* If d == REG_ITMP2, then it's destroyed in check code */
+ /* above. */
+ if (d == REG_ITMP2)
+ M_CLR(d);
+
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_interface,
+ (constant_classref *) iptr->target, 0);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
- else
- panic ("internal error: no inlined array checkcast");
+
+ M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+ M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
+ M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
+ M_BLEZ(REG_ITMP3, 2);
+ M_ALD(REG_ITMP1, REG_ITMP1,
+ (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+ superindex * sizeof(methodptr*)));
+ M_CMPULT(REG_ZERO, REG_ITMP1, d); /* REG_ITMP1 != 0 */
+
+ if (!super)
+ M_BR(s3);
}
- M_INTMOVE(s1, d);
- store_reg_to_var_int(iptr->dst, d);
- break;
- case ICMD_CHECKASIZE: /* ..., size ==> ..., size */
+ /* class instanceof code */
- var_to_reg_int(s1, src, REG_ITMP1);
- M_BLTZ(s1, 0);
- codegen_addxcheckarefs(mcodeptr);
+ if (!super || !(super->flags & ACC_INTERFACE)) {
+ disp = dseg_addaddress(cd, supervftbl);
+
+ if (super) {
+ M_CLR(d);
+ M_BEQZ(s1, s3);
+
+ } else {
+ codegen_addpatchref(cd, mcodeptr,
+ PATCHER_checkcast_instanceof_class,
+ (constant_classref *) iptr->target,
+ disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+ }
+
+ M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+ M_ALD(REG_ITMP2, REG_PV, disp);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
+ M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
+ M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
+ M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
+#endif
+ M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
+ M_CMPULE(REG_ITMP1, REG_ITMP2, d);
+ }
+ store_reg_to_var_int(iptr->dst, d);
+ }
break;
case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref */
MCODECHECK((iptr->op1 << 1) + 64);
for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
- var_to_reg_int(s2, src, REG_ITMP1);
- M_BLTZ(s2, 0);
- codegen_addxcheckarefs(mcodeptr);
-
- /* copy sizes to stack (argument numbers >= INT_ARG_CNT) */
+ /* copy SAVEDVAR sizes to stack */
if (src->varkind != ARGVAR) {
- M_LST(s2, REG_SP, 8 * (s1 + INT_ARG_CNT));
- }
+ var_to_reg_int(s2, src, REG_ITMP1);
+ M_LST(s2, REG_SP, s1 * 8);
}
+ }
/* a0 = dimension count */
- ICONST(argintregs[0], iptr->op1);
+ ICONST(rd->argintregs[0], iptr->op1);
+
+ /* is patcher function set? */
+
+ if (iptr->target) {
+ disp = dseg_addaddress(cd, 0);
+
+ codegen_addpatchref(cd, mcodeptr,
+ (functionptr) iptr->target, iptr->val.a,
+ disp);
+
+ if (opt_showdisassemble)
+ M_NOP;
+
+ } else {
+ disp = dseg_addaddress(cd, iptr->val.a);
+ }
/* a1 = arraydescriptor */
- a = dseg_addaddress(iptr->val.a);
- M_ALD(argintregs[1], REG_PV, a);
+ M_ALD(rd->argintregs[1], REG_PV, disp);
/* a2 = pointer to dimensions = stack pointer */
- M_INTMOVE(REG_SP, argintregs[2]);
+ M_INTMOVE(REG_SP, rd->argintregs[2]);
- a = dseg_addaddress((void*) (builtin_nmultianewarray));
- M_ALD(REG_PV, REG_PV, a);
+ disp = dseg_addaddress(cd, (void *) BUILTIN_multianewarray);
+ M_ALD(REG_PV, REG_PV, disp);
M_JSR(REG_RA, REG_PV);
- s1 = (int)((u1*) mcodeptr - mcodebase);
- if (s1 <= 32768)
- M_LDA (REG_PV, REG_RA, -s1);
- else {
- s4 ml = -s1, mh = 0;
- while (ml < -32768) {ml += 65536; mh--;}
- M_LDA(REG_PV, REG_RA, ml);
- M_LDAH(REG_PV, REG_PV, mh);
- }
- s1 = reg_of_var(iptr->dst, REG_RESULT);
- M_INTMOVE(REG_RESULT, s1);
- store_reg_to_var_int(iptr->dst, s1);
- break;
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ /* check for exception before result assignment */
- default: sprintf (logtext, "Unknown pseudo command: %d", iptr->opc);
- error();
-
-
+ M_BEQZ(REG_RESULT, 0);
+ codegen_addxexceptionrefs(cd, mcodeptr);
+ d = reg_of_var(rd, iptr->dst, REG_RESULT);
+ M_INTMOVE(REG_RESULT, d);
+ store_reg_to_var_int(iptr->dst, d);
+ break;
+
+ default:
+ throw_cacao_exception_exit(string_java_lang_InternalError,
+ "Unknown ICMD %d", iptr->opc);
} /* switch */
} /* for instruction */
src = bptr->outstack;
len = bptr->outdepth;
MCODECHECK(64+len);
+#ifdef LSRA
+ if (!opt_lsra)
+#endif
while (src) {
len--;
if ((src->varkind != STACKVAR)) {
s2 = src->type;
if (IS_FLT_DBL_TYPE(s2)) {
var_to_reg_flt(s1, src, REG_FTMP1);
- if (!(interfaces[len][s2].flags & INMEMORY)) {
- M_FLTMOVE(s1,interfaces[len][s2].regoff);
+ if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+ M_FLTMOVE(s1,rd->interfaces[len][s2].regoff);
}
else {
- M_DST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
+ M_DST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
}
}
else {
var_to_reg_int(s1, src, REG_ITMP1);
- if (!(interfaces[len][s2].flags & INMEMORY)) {
- M_INTMOVE(s1,interfaces[len][s2].regoff);
+ if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+ M_INTMOVE(s1,rd->interfaces[len][s2].regoff);
}
else {
- M_LST(s1, REG_SP, 8 * interfaces[len][s2].regoff);
+ M_LST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
}
}
}
} /* if (bptr -> flags >= BBREACHED) */
} /* for basic block */
- /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */
+ codegen_createlinenumbertable(cd);
{
- /* generate bound check stubs */
s4 *xcodeptr = NULL;
-
- for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
- if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
- gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos,
- xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+ branchref *bref;
+
+ /* generate ArithmeticException stubs */
+
+ for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
+ if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
continue;
- }
+ }
+
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) mcodeptr - cd->mcodebase);
+
+ MCODECHECK(16);
+
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+
+ if (xcodeptr != NULL) {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
+ xcodeptr = mcodeptr;
+
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+ M_LDA(REG_SP, REG_SP, -1 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+ disp = dseg_addaddress(cd, stacktrace_inline_arithmeticexception);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
- gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos,
- xboundrefs->branchpos, (u1*) mcodeptr - mcodebase);
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 1 * 8);
- MCODECHECK(8);
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_JMP(REG_ZERO, REG_ITMP3);
+ }
+ }
+
+ /* generate ArrayIndexOutOfBoundsException stubs */
+
+ xcodeptr = NULL;
+
+ for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
+ gen_resolvebranch((u1*) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1*) mcodeptr - cd->mcodebase);
+
+ MCODECHECK(18);
- M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
+ /* move index register into REG_ITMP1 */
+
+ M_MOV(bref->reg, REG_ITMP1);
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
if (xcodeptr != NULL) {
- M_BR((xcodeptr-mcodeptr)-1);
- }
- else {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
xcodeptr = mcodeptr;
- a = dseg_addaddress(proto_java_lang_ArrayIndexOutOfBoundsException);
- M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+
+ if (m->isleafmethod)
+ M_MOV(REG_RA, rd->argintregs[2]);
+ else
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+ M_MOV(REG_ITMP1, rd->argintregs[4]);
+
+ M_LDA(REG_SP, REG_SP, -2 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+ if (m->isleafmethod)
+ M_AST(REG_RA, REG_SP, 1 * 8);
- a = dseg_addaddress(asm_handle_exception);
- M_ALD(REG_ITMP3, REG_PV, a);
+ disp = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+ if (m->isleafmethod)
+ M_ALD(REG_RA, REG_SP, 1 * 8);
+
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 2 * 8);
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
M_JMP(REG_ZERO, REG_ITMP3);
- }
}
+ }
- /* generate negative array size check stubs */
+ /* generate ArrayStoreException stubs */
xcodeptr = NULL;
- for (; xcheckarefs != NULL; xcheckarefs = xcheckarefs->next) {
- if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
- gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos,
- xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+ for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
+ if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
continue;
- }
+ }
- gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos,
- xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase);
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) mcodeptr - cd->mcodebase);
- MCODECHECK(8);
+ MCODECHECK(16);
- M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
if (xcodeptr != NULL) {
- M_BR((xcodeptr-mcodeptr)-1);
- }
- else {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
xcodeptr = mcodeptr;
- a = dseg_addaddress(proto_java_lang_NegativeArraySizeException);
- M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+ M_LDA(REG_SP, REG_SP, -1 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+ disp = dseg_addaddress(cd, stacktrace_inline_arraystoreexception);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
- a = dseg_addaddress(asm_handle_exception);
- M_ALD(REG_ITMP3, REG_PV, a);
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 1 * 8);
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
M_JMP(REG_ZERO, REG_ITMP3);
- }
}
+ }
- /* generate cast check stubs */
+ /* generate ClassCastException stubs */
xcodeptr = NULL;
- for (; xcastrefs != NULL; xcastrefs = xcastrefs->next) {
- if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
- gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos,
- xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+ for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
+ if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
continue;
- }
+ }
- gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos,
- xcastrefs->branchpos, (u1*) mcodeptr - mcodebase);
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) mcodeptr - cd->mcodebase);
- MCODECHECK(8);
+ MCODECHECK(18);
- M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
if (xcodeptr != NULL) {
- M_BR((xcodeptr-mcodeptr)-1);
- }
- else {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
xcodeptr = mcodeptr;
- a = dseg_addaddress(proto_java_lang_ClassCastException);
- M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+
+ if (m->isleafmethod)
+ M_MOV(REG_RA, rd->argintregs[2]);
+ else
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+ M_LDA(REG_SP, REG_SP, -2 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
- a = dseg_addaddress(asm_handle_exception);
- M_ALD(REG_ITMP3, REG_PV, a);
+ if (m->isleafmethod)
+ M_AST(REG_RA, REG_SP, 1 * 8);
+ disp = dseg_addaddress(cd, stacktrace_inline_classcastexception);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+ if (m->isleafmethod)
+ M_ALD(REG_RA, REG_SP, 1 * 8);
+
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 2 * 8);
+
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
M_JMP(REG_ZERO, REG_ITMP3);
- }
}
+ }
+
+ /* generate NullPointerException stubs */
+
+ xcodeptr = NULL;
+
+ for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
+ if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
+ continue;
+ }
+
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) mcodeptr - cd->mcodebase);
+
+ MCODECHECK(18);
+
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+
+ if (xcodeptr != NULL) {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
+ xcodeptr = mcodeptr;
+
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+
+ if (m->isleafmethod)
+ M_MOV(REG_RA, rd->argintregs[2]);
+ else
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+ M_LDA(REG_SP, REG_SP, -2 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-#ifdef SOFTNULLPTRCHECK
+ if (m->isleafmethod)
+ M_AST(REG_RA, REG_SP, 1 * 8);
- /* generate null pointer check stubs */
+ disp = dseg_addaddress(cd, stacktrace_inline_nullpointerexception);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+ if (m->isleafmethod)
+ M_ALD(REG_RA, REG_SP, 1 * 8);
+
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 2 * 8);
+
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_JMP(REG_ZERO, REG_ITMP3);
+ }
+ }
+
+ /* generate exception check stubs */
xcodeptr = NULL;
- for (; xnullrefs != NULL; xnullrefs = xnullrefs->next) {
- if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
- gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos,
- xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+ for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
+ if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
continue;
- }
+ }
- gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos,
- xnullrefs->branchpos, (u1*) mcodeptr - mcodebase);
+ gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+ bref->branchpos,
+ (u1 *) mcodeptr - cd->mcodebase);
- MCODECHECK(8);
+ MCODECHECK(16);
- M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
+ M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
if (xcodeptr != NULL) {
- M_BR((xcodeptr-mcodeptr)-1);
- }
- else {
+ disp = xcodeptr - mcodeptr - 1;
+ M_BR(disp);
+
+ } else {
xcodeptr = mcodeptr;
- a = dseg_addaddress(proto_java_lang_NullPointerException);
- M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+ M_MOV(REG_PV, rd->argintregs[0]);
+ M_MOV(REG_SP, rd->argintregs[1]);
+ M_ALD(rd->argintregs[2],
+ REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+ M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+ M_LDA(REG_SP, REG_SP, -1 * 8);
+ M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+ disp = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ M_MOV(REG_RESULT, REG_ITMP1_XPTR);
- a = dseg_addaddress(asm_handle_exception);
- M_ALD(REG_ITMP3, REG_PV, a);
+ M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+ M_LDA(REG_SP, REG_SP, 1 * 8);
+ disp = dseg_addaddress(cd, asm_handle_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp);
M_JMP(REG_ZERO, REG_ITMP3);
- }
}
+ }
+
+ /* generate patcher stub call code */
+
+ {
+ patchref *pref;
+ u4 mcode;
+ s4 *tmpmcodeptr;
+
+ for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
+ /* check code segment size */
+
+ MCODECHECK(30);
+
+ /* Get machine code which is patched back in later. The call is */
+ /* 1 instruction word long. */
+
+ xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
+ mcode = *xcodeptr;
+
+ /* patch in the call to call the following code (done at compile */
+ /* time) */
+
+ tmpmcodeptr = mcodeptr; /* save current mcodeptr */
+ mcodeptr = xcodeptr; /* set mcodeptr to patch position */
+
+ M_BSR(REG_ITMP3, tmpmcodeptr - (xcodeptr + 1));
+
+ mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
+
+ /* create stack frame */
+
+ M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
+ /* move return address onto stack */
+
+ M_AST(REG_ITMP3, REG_SP, 5 * 8);
+
+ /* move pointer to java_objectheader onto stack */
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ /* create a virtual java_objectheader */
+
+ (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
+ disp = dseg_addaddress(cd, NULL); /* vftbl */
+
+ M_LDA(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 4 * 8);
+#else
+ M_AST(REG_ZERO, REG_SP, 4 * 8);
#endif
- }
- codegen_finish((int)((u1*) mcodeptr - mcodebase));
-}
+ /* move machine code onto stack */
+ disp = dseg_adds4(cd, mcode);
+ M_ILD(REG_ITMP3, REG_PV, disp);
+ M_IST(REG_ITMP3, REG_SP, 3 * 8);
-/* redefinition of code generation macros (compiling into array) **************/
+ /* move class/method/field reference onto stack */
-/*
-These macros are newly defined to allow code generation into an array.
-This is necessary, because the original M_.. macros generate code by
-calling 'codegen_adds4' that uses an additional data structure to
-receive the code.
+ disp = dseg_addaddress(cd, pref->ref);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 2 * 8);
-For a faster (but less flexible) version to generate code, these
-macros directly use the (s4* p) - pointer to put the code directly
-in a locally defined array.
-This makes sense only for the stub-generation-routines below.
-*/
+ /* move data segment displacement onto stack */
+
+ disp = dseg_adds4(cd, pref->disp);
+ M_ILD(REG_ITMP3, REG_PV, disp);
+ M_IST(REG_ITMP3, REG_SP, 1 * 8);
+
+ /* move patcher function pointer onto stack */
+
+ disp = dseg_addaddress(cd, pref->patcher);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 0 * 8);
+
+ disp = dseg_addaddress(cd, asm_wrapper_patcher);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_JMP(REG_ZERO, REG_ITMP3);
+ }
+ }
+ }
-#undef M_OP3
-#define M_OP3(op,fu,a,b,c,const) \
- *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<(16-3*(const)))| \
- ((const)<<12)|((fu)<<5)|((c)) )
-#undef M_FOP3
-#define M_FOP3(op,fu,a,b,c) \
- *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<16)|((fu)<<5)|(c) )
-#undef M_BRA
-#define M_BRA(op,a,disp) \
- *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((disp)&0x1fffff) )
-#undef M_MEM
-#define M_MEM(op,a,b,disp) \
- *(p++) = ( (((s4)(op))<<26)|((a)<<21)|((b)<<16)|((disp)&0xffff) )
+ codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
+}
-/* function createcompilerstub *************************************************
+/* createcompilerstub **********************************************************
- creates a stub routine which calls the compiler
+ Creates a stub routine which calls the compiler.
*******************************************************************************/
-#define COMPSTUBSIZE 3
+#define COMPSTUBSIZE 3
-u1 *createcompilerstub (methodinfo *m)
+functionptr createcompilerstub(methodinfo *m)
{
- u8 *s = CNEW (u8, COMPSTUBSIZE); /* memory to hold the stub */
- s4 *p = (s4*) s; /* code generation pointer */
+ u8 *s = CNEW(u8, COMPSTUBSIZE); /* memory to hold the stub */
+ s4 *mcodeptr = (s4 *) s; /* code generation pointer */
/* code for the stub */
- M_ALD (REG_PV, REG_PV, 16); /* load pointer to the compiler */
- M_JMP (0, REG_PV); /* jump to the compiler, return address
+ M_ALD(REG_PV, REG_PV, 16); /* load pointer to the compiler */
+ M_JMP(0, REG_PV); /* jump to the compiler, return address
in reg 0 is used as method pointer */
- s[1] = (u8) m; /* literals to be adressed */
- s[2] = (u8) asm_call_jit_compiler; /* jump directly via PV from above */
+ s[1] = (ptrint) m; /* literals to be adressed */
+ s[2] = (ptrint) asm_call_jit_compiler; /* jump directly via PV from above */
-#ifdef STATISTICS
- count_cstub_len += COMPSTUBSIZE * 8;
+#if defined(STATISTICS)
+ if (opt_stat)
+ count_cstub_len += COMPSTUBSIZE * 8;
#endif
- return (u1*) s;
+ return (functionptr) s;
}
-/* function removecompilerstub *************************************************
+/* createnativestub ************************************************************
- deletes a compilerstub from memory (simply by freeing it)
+ Creates a stub routine which calls a native method.
*******************************************************************************/
-void removecompilerstub (u1 *stub)
+functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
+ registerdata *rd, methoddesc *nmd)
{
- CFREE (stub, COMPSTUBSIZE * 8);
-}
+ s4 *mcodeptr; /* code generation pointer */
+ s4 stackframesize; /* size of stackframe if needed */
+ methoddesc *md;
+ s4 nativeparams;
+ s4 i, j; /* count variables */
+ s4 t;
+ s4 s1, s2, disp;
+ s4 funcdisp; /* displacement of the function */
-/* function: createnativestub **************************************************
+ /* initialize variables */
- creates a stub routine which calls a native method
+ md = m->parseddesc;
+ nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
-*******************************************************************************/
-#define NATIVESTUBSIZE 34
-#define NATIVESTUBOFFSET 8
+ /* calculate stack frame size */
-int runverbosenat = 0;
+ stackframesize =
+ 1 + /* return address */
+ sizeof(stackframeinfo) / SIZEOF_VOID_P +
+ 1 + /* methodinfo for call trace */
+ (md->paramcount > INT_ARG_CNT ? INT_ARG_CNT : md->paramcount) +
+ nmd->memuse;
-u1 *createnativestub (functionptr f, methodinfo *m)
-{
- int disp;
- u8 *s = CNEW (u8, NATIVESTUBSIZE); /* memory to hold the stub */
- u8 *cs = s + NATIVESTUBOFFSET;
- s4 *p = (s4*) (cs); /* code generation pointer */
-
- *(cs-1) = (u8) f; /* address of native method */
- *(cs-2) = (u8) (&exceptionptr); /* address of exceptionptr */
- *(cs-3) = (u8) asm_handle_nat_exception; /* addr of asm exception handler */
- *(cs-4) = (u8) (&env); /* addr of jni_environement */
- *(cs-5) = (u8) asm_builtin_trace;
- *(cs-6) = (u8) m;
- *(cs-7) = (u8) asm_builtin_exittrace;
- *(cs-8) = (u8) builtin_trace_exception;
-
-#if 0
- printf("stub: ");
- utf_display(m->class->name);
- printf(".");
- utf_display(m->name);
- printf(" 0x%p\n", cs);
-#endif
- M_LDA (REG_SP, REG_SP, -8); /* build up stackframe */
- M_AST (REG_RA, REG_SP, 0); /* store return address */
+ /* create method header */
+
+ (void) dseg_addaddress(cd, m); /* MethodPointer */
+ (void) dseg_adds4(cd, stackframesize * 8); /* FrameSize */
+ (void) dseg_adds4(cd, 0); /* IsSync */
+ (void) dseg_adds4(cd, 0); /* IsLeaf */
+ (void) dseg_adds4(cd, 0); /* IntSave */
+ (void) dseg_adds4(cd, 0); /* FltSave */
+ (void) dseg_addlinenumbertablesize(cd);
+ (void) dseg_adds4(cd, 0); /* ExTableSize */
+
+
+ /* initialize mcode variables */
+
+ mcodeptr = (s4 *) cd->mcodebase;
+ cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
+
+
+ /* generate stub code */
+
+ M_LDA(REG_SP, REG_SP, -stackframesize * 8);
+ M_AST(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+
-#if 1
- if (runverbosenat) {
- M_ALD(REG_ITMP1, REG_PV, -6*8);
- M_ALD(REG_PV, REG_PV, -5*8);
+ /* call trace function */
+
+ if (runverbose) {
+ /* save integer argument registers */
+
+ for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+ if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+ M_LST(rd->argintregs[i], REG_SP, j * 8);
+ j++;
+ }
+ }
+
+ /* save and copy float arguments into integer registers */
+
+ for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+ t = md->paramtypes[i].type;
+ if (IS_FLT_DBL_TYPE(t)) {
+ if (IS_2_WORD_TYPE(t)) {
+ M_DST(rd->argfltregs[i], REG_SP, j * 8);
+ M_LLD(rd->argintregs[i], REG_SP, j * 8);
+ } else {
+ M_FST(rd->argfltregs[i], REG_SP, j * 8);
+ M_ILD(rd->argintregs[i], REG_SP, j * 8);
+ }
+ j++;
+ }
+ }
+
+ disp = dseg_addaddress(cd, m);
+ M_ALD(REG_ITMP1, REG_PV, disp);
+ M_AST(REG_ITMP1, REG_SP, 0 * 8);
+ disp = dseg_addaddress(cd, builtin_trace_args);
+ M_ALD(REG_PV, REG_PV, disp);
M_JSR(REG_RA, REG_PV);
- disp = -(int) (p - (s4*) cs)*4;
- M_LDA(REG_PV, REG_RA, disp);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+ if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+ M_LLD(rd->argintregs[i], REG_SP, j * 8);
+ j++;
+ }
+ }
+
+ for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+ t = md->paramtypes[i].type;
+
+ if (IS_FLT_DBL_TYPE(t)) {
+ if (IS_2_WORD_TYPE(t)) {
+ M_DLD(rd->argfltregs[i], REG_SP, j * 8);
+ } else {
+ M_FLD(rd->argfltregs[i], REG_SP, j * 8);
+ }
+ j++;
+ }
+ }
+ }
+
+ /* get function address (this must happen before the stackframeinfo) */
+
+ funcdisp = dseg_addaddress(cd, f);
+
+#if !defined(ENABLE_STATICVM)
+ if (f == NULL) {
+ codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
+
+ if (opt_showdisassemble)
+ M_NOP;
}
#endif
- reg_init(m);
- M_MOV (argintregs[4],argintregs[5]);
- M_FMOV (argfltregs[4],argfltregs[5]);
+ /* save integer and float argument registers */
- M_MOV (argintregs[3],argintregs[4]);
- M_FMOV (argfltregs[3],argfltregs[4]);
+ for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+ if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+ M_LST(rd->argintregs[i], REG_SP, j * 8);
+ j++;
+ }
+ }
- M_MOV (argintregs[2],argintregs[3]);
- M_FMOV (argfltregs[2],argfltregs[3]);
+ for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+ if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+ M_DST(rd->argfltregs[i], REG_SP, j * 8);
+ j++;
+ }
+ }
- M_MOV (argintregs[1],argintregs[2]);
- M_FMOV (argfltregs[1],argfltregs[2]);
+ /* create native stackframe info */
+
+ M_AADD_IMM(REG_SP,
+ stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
+ rd->argintregs[0]);
+ M_MOV(REG_PV, rd->argintregs[1]);
+ M_AADD_IMM(REG_SP, stackframesize * 8, rd->argintregs[2]);
+ M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+ disp = dseg_addaddress(cd, stacktrace_create_native_stackframeinfo);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ /* restore integer and float argument registers */
+
+ for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+ if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+ M_LLD(rd->argintregs[i], REG_SP, j * 8);
+ j++;
+ }
+ }
- M_MOV (argintregs[0],argintregs[1]);
- M_FMOV (argfltregs[0],argfltregs[1]);
-
- M_ALD (argintregs[0], REG_PV, -4*8);/* load adress of jni_environement */
-
- M_ALD (REG_PV, REG_PV, -1*8); /* load adress of native method */
- M_JSR (REG_RA, REG_PV); /* call native method */
-
- disp = -(int) (p - (s4*) cs)*4;
- M_LDA (REG_PV, REG_RA, disp); /* recompute pv from ra */
- M_ALD (REG_ITMP3, REG_PV, -2*8); /* get address of exceptionptr */
-
- M_ALD (REG_ITMP1, REG_ITMP3, 0); /* load exception into reg. itmp1 */
- M_BNEZ (REG_ITMP1,
- 3 + (runverbosenat ? 6 : 0)); /* if no exception then return */
-
-#if 1
- if (runverbosenat) {
- M_ALD(argintregs[0], REG_PV, -6*8);
- M_MOV(REG_RESULT, argintregs[1]);
- M_FMOV(REG_FRESULT, argfltregs[2]);
- M_FMOV(REG_FRESULT, argfltregs[3]);
- M_ALD(REG_PV, REG_PV, -7*8);
- M_JSR(REG_RA, REG_PV);
+ for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+ if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+ M_DLD(rd->argfltregs[i], REG_SP, j * 8);
+ j++;
+ }
}
-#endif
- M_ALD (REG_RA, REG_SP, 0); /* load return address */
- M_LDA (REG_SP, REG_SP, 8); /* remove stackframe */
- M_RET (REG_ZERO, REG_RA); /* return to caller */
-
- M_AST (REG_ZERO, REG_ITMP3, 0); /* store NULL into exceptionptr */
-
-#if 1
- if (runverbosenat) {
- M_LDA(REG_SP, REG_SP, -8);
- M_AST(REG_ITMP1, REG_SP, 0);
- M_MOV(REG_ITMP1, argintregs[0]);
- M_ALD(argintregs[1], REG_PV, -6*8);
- M_ALD(argintregs[2], REG_SP, 0);
- M_CLR(argintregs[3]);
- M_ALD(REG_PV, REG_PV, -8*8);
+ /* copy or spill arguments to new locations */
+
+ for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
+ t = md->paramtypes[i].type;
+
+ if (IS_INT_LNG_TYPE(t)) {
+ if (!md->params[i].inmemory) {
+ s1 = rd->argintregs[md->params[i].regoff];
+
+ if (!nmd->params[j].inmemory) {
+ s2 = rd->argintregs[nmd->params[j].regoff];
+ M_INTMOVE(s1, s2);
+
+ } else {
+ s2 = nmd->params[j].regoff;
+ M_LST(s1, REG_SP, s2 * 8);
+ }
+
+ } else {
+ s1 = md->params[i].regoff + stackframesize;
+ s2 = nmd->params[j].regoff;
+ M_LLD(REG_ITMP1, REG_SP, s1 * 8);
+ M_LST(REG_ITMP1, REG_SP, s2 * 8);
+ }
+
+ } else {
+ if (!md->params[i].inmemory) {
+ s1 = rd->argfltregs[md->params[i].regoff];
+
+ if (!nmd->params[j].inmemory) {
+ s2 = rd->argfltregs[nmd->params[j].regoff];
+ M_FLTMOVE(s1, s2);
+
+ } else {
+ s2 = nmd->params[j].regoff;
+ if (IS_2_WORD_TYPE(t))
+ M_DST(s1, REG_SP, s2 * 8);
+ else
+ M_FST(s1, REG_SP, s2 * 8);
+ }
+
+ } else {
+ s1 = md->params[i].regoff + stackframesize;
+ s2 = nmd->params[j].regoff;
+ M_DLD(REG_FTMP1, REG_SP, s1 * 8);
+ if (IS_2_WORD_TYPE(t))
+ M_DST(REG_FTMP1, REG_SP, s2 * 8);
+ else
+ M_FST(REG_FTMP1, REG_SP, s2 * 8);
+ }
+ }
+ }
+
+ /* put class into second argument register */
+
+ if (m->flags & ACC_STATIC) {
+ disp = dseg_addaddress(cd, m->class);
+ M_ALD(rd->argintregs[1], REG_PV, disp);
+ }
+
+ /* put env into first argument register */
+
+ disp = dseg_addaddress(cd, &env);
+ M_ALD(rd->argintregs[0], REG_PV, disp);
+
+ /* do the native function call */
+
+ M_ALD(REG_PV, REG_PV, funcdisp);
+ M_JSR(REG_RA, REG_PV); /* call native method */
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp); /* recompute pv from ra */
+
+ /* save return value */
+
+ if (IS_INT_LNG_TYPE(md->returntype.type))
+ M_LST(REG_RESULT, REG_SP, 0 * 8);
+ else
+ M_DST(REG_FRESULT, REG_SP, 0 * 8);
+
+ /* remove native stackframe info */
+
+ M_AADD_IMM(REG_SP,
+ stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
+ rd->argintregs[0]);
+ disp = dseg_addaddress(cd, stacktrace_remove_stackframeinfo);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+
+ /* call finished trace */
+
+ if (runverbose) {
+ disp = dseg_addaddress(cd, m);
+ M_ALD(rd->argintregs[0], REG_PV, disp);
+
+ M_MOV(REG_RESULT, rd->argintregs[1]);
+ M_FMOV(REG_FRESULT, rd->argfltregs[2]);
+ M_FMOV(REG_FRESULT, rd->argfltregs[3]);
+
+ disp = dseg_addaddress(cd, builtin_displaymethodstop);
+ M_ALD(REG_PV, REG_PV, disp);
M_JSR(REG_RA, REG_PV);
- disp = -(int) (p - (s4*) cs)*4;
- M_LDA (REG_PV, REG_RA, disp);
- M_ALD(REG_ITMP1, REG_SP, 0);
- M_LDA(REG_SP, REG_SP, 8);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
}
+
+ /* check for exception */
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
+ M_ALD(REG_PV, REG_PV, disp);
+ M_JSR(REG_RA, REG_PV);
+ disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+ M_LDA(REG_PV, REG_RA, -disp);
+ M_MOV(REG_RESULT, REG_ITMP3);
+#else
+ disp = dseg_addaddress(cd, &_exceptionptr);
+ M_ALD(REG_RESULT, REG_PV, disp); /* get address of exceptionptr */
#endif
+ M_ALD(REG_ITMP1, REG_ITMP3, 0); /* load exception into reg. itmp1 */
+
+ /* restore return value */
+
+ if (IS_INT_LNG_TYPE(md->returntype.type))
+ M_LLD(REG_RESULT, REG_SP, 0 * 8);
+ else
+ M_DLD(REG_FRESULT, REG_SP, 0 * 8);
+
+ M_BNEZ(REG_ITMP1, 3); /* if no exception then return */
+
+ M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address */
+ M_LDA(REG_SP, REG_SP, stackframesize * 8);
+ M_RET(REG_ZERO, REG_RA); /* return to caller */
+
+ /* handle exception */
+
+ M_AST(REG_ZERO, REG_ITMP3, 0); /* store NULL into exceptionptr */
- M_ALD (REG_RA, REG_SP, 0); /* load return address */
- M_LDA (REG_SP, REG_SP, 8); /* remove stackframe */
+ M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address */
+ M_LDA(REG_ITMP2, REG_RA, -4); /* move fault address into reg. itmp2 */
- M_LDA (REG_ITMP2, REG_RA, -4); /* move fault address into reg. itmp2 */
+ M_LDA(REG_SP, REG_SP, stackframesize * 8);
- M_ALD (REG_ITMP3, REG_PV, -3*8); /* load asm exception handler address */
- M_JMP (REG_ZERO, REG_ITMP3); /* jump to asm exception handler */
+ disp = dseg_addaddress(cd, asm_handle_nat_exception);
+ M_ALD(REG_ITMP3, REG_PV, disp); /* load asm exception handler address */
+ M_JMP(REG_ZERO, REG_ITMP3); /* jump to asm exception handler */
-#if 0
+
+ /* process patcher calls **************************************************/
+
{
- static int stubprinted;
- if (!stubprinted)
- printf("stubsize: %d/2\n", (int) (p - (s4*) s));
- stubprinted = 1;
- }
-#endif
+ patchref *pref;
+ s4 *xcodeptr;
+ u4 mcode;
+ s4 *tmpmcodeptr;
+
+ /* there can only be one <clinit> ref entry */
+ pref = cd->patchrefs;
+
+ for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
+ /* Get machine code which is patched back in later. The call is */
+ /* 1 instruction word long. */
+
+ xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
+ mcode = (u4) *xcodeptr;
+
+ /* patch in the call to call the following code (done at compile */
+ /* time) */
+
+ tmpmcodeptr = mcodeptr; /* save current mcodeptr */
+ mcodeptr = xcodeptr; /* set mcodeptr to patch position */
+
+ M_BSR(REG_ITMP3, tmpmcodeptr - (xcodeptr + 1));
+
+ mcodeptr = tmpmcodeptr; /* restore the current mcodeptr */
+
+ /* create stack frame */
+
+ M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
+
+ /* move return address onto stack */
+
+ M_AST(REG_ITMP3, REG_SP, 5 * 8);
+
+ /* move pointer to java_objectheader onto stack */
-#ifdef STATISTICS
- count_nstub_len += NATIVESTUBSIZE * 8;
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ /* create a virtual java_objectheader */
+
+ (void) dseg_addaddress(cd, get_dummyLR()); /* monitorPtr */
+ disp = dseg_addaddress(cd, NULL); /* vftbl */
+
+ M_LDA(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 4 * 8);
+#else
+ M_AST(REG_ZERO, REG_SP, 4 * 8);
#endif
- return (u1*) (s + NATIVESTUBOFFSET);
-}
+ /* move machine code onto stack */
-/* function: removenativestub **************************************************
+ disp = dseg_adds4(cd, mcode);
+ M_ILD(REG_ITMP3, REG_PV, disp);
+ M_IST(REG_ITMP3, REG_SP, 3 * 8);
- removes a previously created native-stub from memory
-
-*******************************************************************************/
+ /* move class/method/field reference onto stack */
-void removenativestub (u1 *stub)
-{
- CFREE ((u8*) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8);
+ disp = dseg_addaddress(cd, pref->ref);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 2 * 8);
+
+ /* move data segment displacement onto stack */
+
+ disp = dseg_adds4(cd, pref->disp);
+ M_ILD(REG_ITMP3, REG_PV, disp);
+ M_IST(REG_ITMP3, REG_SP, 1 * 8);
+
+ /* move patcher function pointer onto stack */
+
+ disp = dseg_addaddress(cd, pref->patcher);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_AST(REG_ITMP3, REG_SP, 0 * 8);
+
+ disp = dseg_addaddress(cd, asm_wrapper_patcher);
+ M_ALD(REG_ITMP3, REG_PV, disp);
+ M_JMP(REG_ZERO, REG_ITMP3);
+ }
+ }
+
+ codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
+
+ return m->entrypoint;
}