* Removed all Id tags.
[cacao.git] / src / vm / jit / mips / codegen.c
index cf0174e5a04ff8002f825b1515f845c78990eb74..01f0c30027544525d76041631cfc21ed9fd6826f 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/mips/codegen.c - machine code generator for MIPS
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 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
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Andreas Krall
-            Reinhard Grafl
-
-   Changes: Christian Thalinger
-            Christian Ullrich
-            Edwin Steiner
-
-   Contains the codegenerator for an MIPS (R4000 or higher) processor.
-   This module generates MIPS machine code for a sequence of
-   intermediate code commands (ICMDs).
-
-   $Id: codegen.c 5331 2006-09-05 19:06:22Z edwin $
-
 */
 
 
 
 #include "vm/types.h"
 
-#include "md.h"
 #include "md-abi.h"
 
 #include "vm/jit/mips/arch.h"
 #include "vm/jit/mips/codegen.h"
 
+#include "mm/memory.h"
+
+#include "native/localref.h"
 #include "native/native.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/lock.h"
-#endif
+#include "threads/lock-common.h"
 
 #include "vm/builtin.h"
-#include "vm/class.h"
 #include "vm/exceptions.h"
-#include "vm/options.h"
-#include "vm/stringlocal.h"
 #include "vm/vm.h"
+
+#include "vm/jit/abi.h"
 #include "vm/jit/asmpart.h"
 #include "vm/jit/codegen-common.h"
 #include "vm/jit/dseg.h"
-#include "vm/jit/emit.h"
+#include "vm/jit/emit-common.h"
 #include "vm/jit/jit.h"
-#include "vm/jit/patcher.h"
+#include "vm/jit/md.h"
+#include "vm/jit/patcher-common.h"
 #include "vm/jit/reg.h"
 #include "vm/jit/replace.h"
 
 # include "vm/jit/allocator/lsra.h"
 #endif
 
+#include "vmcore/class.h"
+#include "vmcore/options.h"
+
 
-/* codegen *********************************************************************
+/* codegen_emit ****************************************************************
 
    Generates machine code.
 
 *******************************************************************************/
 
-bool codegen(jitdata *jd)
+bool codegen_emit(jitdata *jd)
 {
        methodinfo         *m;
        codeinfo           *code;
        codegendata        *cd;
        registerdata       *rd;
        s4                  len, s1, s2, s3, d, disp;
-       ptrint              a;
-       stackptr            src;
        varinfo            *var;
        basicblock         *bptr;
        instruction        *iptr;
-       exceptiontable     *ex;
+       exception_entry    *ex;
        u2                  currentline;
+       constant_classref  *cr;
+       unresolved_class   *uc;
        methodinfo         *lm;             /* local methodinfo for ICMD_INVOKE*  */
+       unresolved_method  *um;
        builtintable_entry *bte;
        methoddesc         *md;
-       rplpoint           *replacementpoint;
+       fieldinfo          *fi;
+       unresolved_field   *uf;
+       s4                  fieldtype;
+       s4                  varindex;
 
        /* get required compiler data */
 
@@ -111,6 +103,17 @@ bool codegen(jitdata *jd)
        cd   = jd->cd;
        rd   = jd->rd;
 
+       /* prevent compiler warnings */
+
+       s1          = 0;
+       d           = 0;
+       fieldtype   = 0;
+       lm          = NULL;
+       um          = NULL;
+       bte         = NULL;
+       currentline = 0;
+       uf          = NULL;
+
        {
        s4 i, p, t, l;
        s4 savedregs_num;
@@ -127,8 +130,14 @@ bool codegen(jitdata *jd)
 #if defined(ENABLE_THREADS)
        /* space to save argument of monitor_enter */
 
-       if (checksync && (m->flags & ACC_SYNCHRONIZED))
+       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+# if SIZEOF_VOID_P == 8
                cd->stackframesize++;
+# else
+               rd->memuse++;
+               cd->stackframesize += 2;
+# endif
+       }
 #endif
 
        /* keep stack 16-byte aligned */
@@ -138,11 +147,8 @@ bool codegen(jitdata *jd)
 
        /* create method header */
 
-#if SIZEOF_VOID_P == 4
-       (void) dseg_addaddress(cd, code);                      /* Filler          */
-#endif
-       (void) dseg_addaddress(cd, code);                      /* CodeinfoPointer */
-       (void) dseg_adds4(cd, cd->stackframesize * 8);         /* FrameSize       */
+       (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
 
 #if defined(ENABLE_THREADS)
        /* IsSync contains the offset relative to the stack pointer for the
@@ -152,24 +158,24 @@ bool codegen(jitdata *jd)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4(cd, (rd->memuse + 1) * 8);       /* IsSync          */
+               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8); /* IsSync        */
        else
 #endif
-               (void) dseg_adds4(cd, 0);                          /* IsSync          */
+               (void) dseg_add_unique_s4(cd, 0);                  /* IsSync          */
                                               
-       (void) dseg_adds4(cd, jd->isleafmethod);               /* IsLeaf          */
-       (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave         */
-       (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave         */
+       (void) dseg_add_unique_s4(cd, jd->isleafmethod);       /* IsLeaf          */
+       (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
+       (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
        dseg_addlinenumbertablesize(cd);
-       (void) dseg_adds4(cd, cd->exceptiontablelength);       /* ExTableSize     */
+       (void) dseg_add_unique_s4(cd, jd->exceptiontablelength); /* ExTableSize   */
 
        /* 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);
+       for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
+               dseg_add_target(cd, ex->start);
+               dseg_add_target(cd, ex->end);
+               dseg_add_target(cd, ex->handler);
+               (void) dseg_add_unique_address(cd, ex->catchtype.any);
        }
        
        /* create stack frame (if necessary) */
@@ -196,56 +202,83 @@ bool codegen(jitdata *jd)
 
        for (p = 0, l = 0; p < md->paramcount; p++) {
                t = md->paramtypes[p].type;
-               var = &(rd->locals[l][t]);
+
+               varindex = jd->local_map[l * 5 + 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 (varindex == UNUSED)
+                       continue;
+
+               var = VAR(varindex);
+               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);
-                               } else {                             /* reg arg -> spilled    */
-                                       M_LST(s2, REG_SP, var->regoff * 8);
-                               }
-
-                       } else {                                 /* stack arguments       */
-                               if (!(var->flags & INMEMORY)) {      /* stack arg -> register */
-                                       M_LLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 8);
-                               } else {                             /* stack arg -> spilled  */
-                                       var->regoff = cd->stackframesize + s1;
+#if SIZEOF_VOID_P == 8
+                               if (!(var->flags & INMEMORY))
+                                       M_INTMOVE(s1, var->vv.regoff);
+                               else
+                                       M_LST(s1, REG_SP, var->vv.regoff);
+#else
+                               if (!(var->flags & INMEMORY)) {
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_LNGMOVE(s1, var->vv.regoff);
+                                       else
+                                               M_INTMOVE(s1, var->vv.regoff);
+                               }
+                               else {
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_LST(s1, REG_SP, var->vv.regoff);
+                                       else
+                                               M_IST(s1, REG_SP, var->vv.regoff);
                                }
+#endif
+                       }
+                       else {                                   /* stack arguments       */
+                               if (!(var->flags & INMEMORY)) {
+#if SIZEOF_VOID_P == 8
+                                       M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+#else
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+                                       else
+                                               M_ILD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+#endif
+                               }
+                               else
+                                       var->vv.regoff = cd->stackframesize * 8 + s1;
                        }
-
-               } else {                                     /* floating args         */
-                       if (!md->params[p].inmemory) {           /* register arguments    */
-                               s2 = rd->argfltregs[s1];
-                               if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
+               }
+               else {                                       /* floating args         */
+                       if (!md->params[p].inmemory) {
+                               if (!(var->flags & INMEMORY)) {
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DMOV(s2, var->regoff);
+                                               M_DBLMOVE(s1, var->vv.regoff);
                                        else
-                                               M_FMOV(s2, var->regoff);
-                               } else {                                         /* reg arg -> spilled    */
+                                               M_FLTMOVE(s1, var->vv.regoff);
+                               }
+                               else {
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DST(s2, REG_SP, var->regoff * 8);
+                                               M_DST(s1, REG_SP, var->vv.regoff);
                                        else
-                                               M_FST(s2, REG_SP, var->regoff * 8);
+                                               M_FST(s1, REG_SP, var->vv.regoff);
                                }
-
-                       } else {                                 /* stack arguments       */
-                               if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
+                       }
+                       else {
+                               if (!(var->flags & INMEMORY)) {
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 8);
+                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
                                        else
-                                               M_FLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 8);
-                               } else                               /* stack-arg -> spilled  */
-                                       var->regoff = cd->stackframesize + s1;
+                                               M_FLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+                               }
+                               else
+                                       var->vv.regoff = cd->stackframesize * 8 + s1;
                        }
                }
-       } /* end for */
+       }
 
        /* call monitorenter function */
 
@@ -260,10 +293,10 @@ bool codegen(jitdata *jd)
                        M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8);
 
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_LST(rd->argintregs[p], REG_SP, p * 8);
+                               M_AST(abi_registers_integer_argument[p], REG_SP, p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
+                               M_DST(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
 
                        s1 += INT_ARG_CNT + FLT_ARG_CNT;
                }
@@ -272,26 +305,29 @@ bool codegen(jitdata *jd)
                /* get correct lock object */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_addaddress(cd, &m->class->object.header);
-                       M_ALD(rd->argintregs[0], REG_PV, p);
+                       disp = dseg_add_address(cd, &m->class->object.header);
+                       M_ALD(REG_A0, REG_PV, disp);
+                       disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
                }
                else {
-                       M_BEQZ(rd->argintregs[0], 0);
-                       codegen_add_nullpointerexception_ref(cd);
+/*                     emit_nullpointer_check(cd, iptr, REG_A0); */
+                       M_BNEZ(REG_A0, 2);
+                       disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
+                       M_ALD(REG_ITMP3, REG_PV, disp);                   /* branch delay */
+                       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
                }
 
-               p = dseg_addaddress(cd, LOCK_monitor_enter);
-               M_ALD(REG_ITMP3, REG_PV, p);
                M_JSR(REG_RA, REG_ITMP3);
-               M_AST(rd->argintregs[0], REG_SP, s1 * 8);         /* branch delay */
+               M_AST(REG_A0, REG_SP, s1 * 8);                        /* branch delay */
 
 # if !defined(NDEBUG)
                if (opt_verbosecall) {
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_LLD(rd->argintregs[p], REG_SP, p * 8);
+                               M_ALD(abi_registers_integer_argument[p], REG_SP, p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
+                               M_DLD(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
 
 
                        M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
@@ -299,142 +335,114 @@ bool codegen(jitdata *jd)
 # endif
        }
 #endif
+       }
 
 #if !defined(NDEBUG)
        if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
                emit_verbosecall_enter(jd);
 #endif
 
-       }
-
        /* end of header generation */
 
-       replacementpoint = jd->code->rplpoints;
+       /* create replacement points */
+
+       REPLACEMENT_POINTS_INIT(cd, jd);
 
        /* walk through all basic blocks */
 
-       for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
+       for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next) {
 
                /* handle replacement points */
 
-               if (bptr->bitflags & BBFLAG_REPLACEMENT && bptr->flags >= BBREACHED) {
-
-                       /* 8-byte align pc */
-                       if ((ptrint) cd->mcodeptr & 4) {
-                               M_NOP;
-                       }
-                       
-                       replacementpoint->pc = (u1*)(ptrint) (cd->mcodeptr - cd->mcodebase);
-                       replacementpoint++;
-
-                       assert(cd->lastmcodeptr <= cd->mcodeptr);
-                       cd->lastmcodeptr = cd->mcodeptr + 2 * 4;       /* br + delay slot */
-               }
+               REPLACEMENT_POINT_BLOCK_START(cd, bptr);
 
                /* store relative start of block */
 
                bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
 
                if (bptr->flags >= BBREACHED) {
-
                        /* branch resolving */
-                       {
-                               branchref *bref;
-                               for (bref = bptr->branchrefs; bref != NULL; bref = bref->next) {
-                                       gen_resolvebranch(cd->mcodebase + bref->branchpos, 
-                                                                         bref->branchpos,
-                                                                         bptr->mpc);
-                               }
-                       }
+
+                       codegen_resolve_branchrefs(cd, bptr);
 
                /* copy interface registers to their destination */
 
-               src = bptr->instack;
                len = bptr->indepth;
                MCODECHECK(64+len);
 #if defined(ENABLE_LSRA)
                if (opt_lsra) {
-               while (src != NULL) {
+               while (len) {
                        len--;
-                       if ((len == 0) && (bptr->type != BBTYPE_STD)) {
+                       src = bptr->invars[len];
+                       if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
                                        /*                              d = reg_of_var(m, src, REG_ITMP1); */
                                        if (!(src->flags & INMEMORY))
-                                               d= src->regoff;
+                                               d = src->vv.regoff;
                                        else
-                                               d=REG_ITMP1;
+                                               d = REG_ITMP1;
                                        M_INTMOVE(REG_ITMP1, d);
                                        emit_store(jd, NULL, src, d);
                                }
-                               src = src->prev;
                        }
                } else {
 #endif
-               while (src != NULL) {
+               while (len) {
                        len--;
-                       if ((len == 0) && (bptr->type != BBTYPE_STD)) {
-                               d = codegen_reg_of_var(rd, 0, src, REG_ITMP1);
+                       var = VAR(bptr->invars[len]);
+                       if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
+                               d = codegen_reg_of_var(0, var, REG_ITMP1);
                                M_INTMOVE(REG_ITMP1, d);
-                               emit_store(jd, NULL, src, d);
-
-                       } else {
-                               d = codegen_reg_of_var(rd, 0, src, REG_IFTMP);
-                               if ((src->varkind != STACKVAR)) {
-                                       s2 = src->type;
-                                       s1 = rd->interfaces[len][s2].regoff;
-                                       if (IS_FLT_DBL_TYPE(s2)) {
-                                               if (rd->interfaces[len][s2].flags & INMEMORY) {
-                                                       if (IS_2_WORD_TYPE(s2))
-                                                               M_DLD(d, REG_SP, s1 * 8);
-                                                       else
-                                                               M_FLD(d, REG_SP, s1 * 8);
-
-                                               } else {
-                                                       if (IS_2_WORD_TYPE(s2))
-                                                               M_DMOV(s1, d);
-                                                       else
-                                                               M_FMOV(s1, d);
-                                               }
-
-                                       } else {
-                                               if (rd->interfaces[len][s2].flags & INMEMORY)
-                                                       M_LLD(d, REG_SP, s1 * 8);
-                                               else
-                                                       M_INTMOVE(s1,d);
-                                       }
-
-                                       emit_store(jd, NULL, src, d);
-                               }
+                               emit_store(jd, NULL, var, d);
+                       } 
+                       else {
+                               assert((var->flags & INOUT));
                        }
-                       src = src->prev;
                }
 #if defined(ENABLE_LSRA)
                }
 #endif
                /* walk through all instructions */
                
-               src = bptr->instack;
                len = bptr->icount;
-               currentline = 0;
+/*             currentline = 0; */
 
-               for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
+               for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
                        if (iptr->line != currentline) {
                                dseg_addlinenumber(cd, iptr->line);
                                currentline = iptr->line;
                        }
 
-                       MCODECHECK(64);   /* an instruction usually needs < 64 words      */
+               MCODECHECK(64);       /* an instruction usually needs < 64 words      */
 
-                       switch (iptr->opc) {
+               switch (iptr->opc) {
 
                case ICMD_NOP:        /* ...  ==> ...                                 */
+               case ICMD_POP:        /* ..., value  ==> ...                          */
+               case ICMD_POP2:       /* ..., value, value  ==> ...                   */
+                       break;
+
+               case ICMD_INLINE_START:
+
+                       REPLACEMENT_POINT_INLINE_START(cd, iptr);
+                       break;
+
+               case ICMD_INLINE_BODY:
+
+                       REPLACEMENT_POINT_INLINE_BODY(cd, iptr);
+                       dseg_addlinenumber_inline_start(cd, iptr);
+                       dseg_addlinenumber(cd, iptr->line);
+                       break;
+
+               case ICMD_INLINE_END:
+
+                       dseg_addlinenumber_inline_end(cd, iptr);
+                       dseg_addlinenumber(cd, iptr->line);
                        break;
 
                case ICMD_CHECKNULL:  /* ..., objectref  ==> ..., objectref           */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       M_BEQZ(s1, 0);
-                       codegen_add_nullpointerexception_ref(cd);
-                       M_NOP;
+                       emit_nullpointer_check(cd, iptr, s1);
                        break;
 
                /* constant operations ************************************************/
@@ -448,7 +456,11 @@ bool codegen(jitdata *jd)
 
                case ICMD_LCONST:     /* ...  ==> ..., constant                       */
 
+#if SIZEOF_VOID_P == 8
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+#endif
                        LCONST(d, iptr->sx.val.l);
                        emit_store_dst(jd, iptr, d);
                        break;
@@ -456,7 +468,7 @@ bool codegen(jitdata *jd)
                case ICMD_FCONST:     /* ...  ==> ..., constant                       */
 
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       disp = dseg_addfloat(cd, iptr->sx.val.f);
+                       disp = dseg_add_float(cd, iptr->sx.val.f);
                        M_FLD(d, REG_PV, disp);
                        emit_store_dst(jd, iptr, d);
                        break;
@@ -464,7 +476,7 @@ bool codegen(jitdata *jd)
                case ICMD_DCONST:     /* ...  ==> ..., constant                       */
 
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       disp = dseg_adddouble(cd, iptr->sx.val.d);
+                       disp = dseg_add_double(cd, iptr->sx.val.d);
                        M_DLD(d, REG_PV, disp);
                        emit_store_dst(jd, iptr, d);
                        break;
@@ -474,23 +486,19 @@ bool codegen(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               disp = dseg_addaddress(cd, NULL);
+                               cr   = iptr->sx.val.c.ref;
+                               disp = dseg_add_unique_address(cd, cr);
 
-                               codegen_addpatchref(cd, PATCHER_aconst,
-                                                                       iptr->sx.val.c.ref,
-                                                                   disp);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
+                                                                         cr, disp);
 
                                M_ALD(d, REG_PV, disp);
-
-                       else {
-                               if (iptr->sx.val.anyptr == NULL) {
+                       }
+                       else {
+                               if (iptr->sx.val.anyptr == NULL)
                                        M_INTMOVE(REG_ZERO, d);
-                               else {
-                                       disp = dseg_addaddress(cd, iptr->sx.val.anyptr);
+                               else {
+                                       disp = dseg_add_address(cd, iptr->sx.val.anyptr);
                                        M_ALD(d, REG_PV, disp);
                                }
                        }
@@ -498,229 +506,26 @@ bool codegen(jitdata *jd)
                        break;
 
 
-               /* load/store operations **********************************************/
+               /* load/store/copy/move operations ************************************/
 
                case ICMD_ILOAD:      /* ...  ==> ..., content of local variable      */
-                                     /* s1.localindex = local variable                         */
-
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
-                       if ((iptr->dst.var->varkind == LOCALVAR) &&
-                           (iptr->dst.var->varnum == iptr->s1.localindex))
-                               break;
-                       var = &(rd->locals[iptr->s1.localindex][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-#if SIZEOF_VOID_P == 8
-                               M_LLD(d, REG_SP, var->regoff * 8);
-#else
-                               M_ILD(d, REG_SP, var->regoff * 8);
-#endif
-                       else
-                               M_INTMOVE(var->regoff,d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_LLOAD:      /* ...  ==> ..., content of local variable      */
-                                     /* s1.localindex = local variable                         */
-
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
-                       if ((iptr->dst.var->varkind == LOCALVAR) &&
-                           (iptr->dst.var->varnum == iptr->s1.localindex))
-                               break;
-                       var = &(rd->locals[iptr->s1.localindex][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_LLD(d, REG_SP, var->regoff * 8);
-                       else
-                               M_INTMOVE(var->regoff,d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_ALOAD:      /* ...  ==> ..., content of local variable      */
-                                     /* s1.localindex = local variable                         */
-
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
-                       if ((iptr->dst.var->varkind == LOCALVAR) &&
-                           (iptr->dst.var->varnum == iptr->s1.localindex))
-                               break;
-                       var = &(rd->locals[iptr->s1.localindex][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_ALD(d, REG_SP, var->regoff * 8);
-                       else
-                               M_INTMOVE(var->regoff,d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
-                                     /* s1.localindex = local variable                         */
-
-                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       if ((iptr->dst.var->varkind == LOCALVAR) &&
-                           (iptr->dst.var->varnum == iptr->s1.localindex))
-                               break;
-                       var = &(rd->locals[iptr->s1.localindex][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_FLD(d, REG_SP, var->regoff * 8);
-                       else
-                               M_FMOV(var->regoff, d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_DLOAD:      /* ...  ==> ..., content of local variable      */
-                                     /* s1.localindex = local variable                         */
-
-                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       if ((iptr->dst.var->varkind == LOCALVAR) &&
-                           (iptr->dst.var->varnum == iptr->s1.localindex))
-                               break;
-                       var = &(rd->locals[iptr->s1.localindex][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_DLD(d, REG_SP, var->regoff * 8);
-                       else
-                               M_DMOV(var->regoff, d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-
+               case ICMD_LLOAD:
+               case ICMD_ALOAD:
+               case ICMD_FLOAD:
+               case ICMD_DLOAD:
                case ICMD_ISTORE:     /* ..., value  ==> ...                          */
-                                     /* dst.localindex = local variable                         */
-
-                       if ((iptr->s1.var->varkind == LOCALVAR) &&
-                           (iptr->s1.var->varnum == iptr->dst.localindex))
-                               break;
-                       var = &(rd->locals[iptr->dst.localindex][iptr->opc - ICMD_ISTORE]);
-                       if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-#if SIZEOF_VOID_P == 8
-                               M_LST(s1, REG_SP, var->regoff * 8);
-#else
-                               M_IST(s1, REG_SP, var->regoff * 8);
-#endif
-                       } else {
-                               s1 = emit_load_s1(jd, iptr, var->regoff);
-                               M_INTMOVE(s1, var->regoff);
-                       }
-                       break;
-
-               case ICMD_LSTORE:     /* ..., value  ==> ...                          */
-                                     /* dst.localindex = local variable                         */
-
-                       if ((iptr->s1.var->varkind == LOCALVAR) &&
-                           (iptr->s1.var->varnum == iptr->dst.localindex))
-                               break;
-                       var = &(rd->locals[iptr->dst.localindex][iptr->opc - ICMD_ISTORE]);
-                       if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                               M_LST(s1, REG_SP, var->regoff * 8);
-                       } else {
-                               s1 = emit_load_s1(jd, iptr, var->regoff);
-                               M_INTMOVE(s1, var->regoff);
-                       }
-                       break;
-
-               case ICMD_ASTORE:     /* ..., value  ==> ...                          */
-                                     /* dst.localindex = local variable                         */
-
-                       if ((iptr->s1.var->varkind == LOCALVAR) &&
-                           (iptr->s1.var->varnum == iptr->dst.localindex))
-                               break;
-                       var = &(rd->locals[iptr->dst.localindex][iptr->opc - ICMD_ISTORE]);
-                       if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                               M_AST(s1, REG_SP, var->regoff * 8);
-                       } else {
-                               s1 = emit_load_s1(jd, iptr, var->regoff);
-                               M_INTMOVE(s1, var->regoff);
-                       }
-                       break;
-
-               case ICMD_FSTORE:     /* ..., value  ==> ...                          */
-                                     /* dst.localindex = local variable                         */
-
-                       if ((iptr->s1.var->varkind == LOCALVAR) &&
-                           (iptr->s1.var->varnum == iptr->dst.localindex))
-                               break;
-                       var = &(rd->locals[iptr->dst.localindex][iptr->opc - ICMD_ISTORE]);
-                       if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                               M_FST(s1, REG_SP, var->regoff * 8);
-                       } else {
-                               s1 = emit_load_s1(jd, iptr, var->regoff);
-                               M_FMOV(s1, var->regoff);
-                       }
-                       break;
-
-               case ICMD_DSTORE:     /* ..., value  ==> ...                          */
-                                     /* dst.localindex = local variable                         */
-
-                       if ((iptr->s1.var->varkind == LOCALVAR) &&
-                           (iptr->s1.var->varnum == iptr->dst.localindex))
-                               break;
-                       var = &(rd->locals[iptr->dst.localindex][iptr->opc - ICMD_ISTORE]);
-                       if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                               M_DST(s1, REG_SP, var->regoff * 8);
-                       } else {
-                               s1 = emit_load_s1(jd, iptr, var->regoff);
-                               M_DMOV(s1, var->regoff);
-                       }
-                       break;
-
-
-               /* pop/dup/swap operations ********************************************/
-
-               /* attention: double and longs are only one entry in CACAO ICMDs      */
-
-               case ICMD_POP:        /* ..., value  ==> ...                          */
-               case ICMD_POP2:       /* ..., value, value  ==> ...                   */
-                       break;
-
-               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);
-                       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                */
-
-                       M_COPY(src,       iptr->dst);
-                       M_COPY(src->prev, iptr->dst->prev);
-                       break;
+               case ICMD_LSTORE:
+               case ICMD_FSTORE:
+               case ICMD_DSTORE:
+               case ICMD_COPY:
+               case ICMD_MOVE:
 
-               case ICMD_DUP2_X1:    /* ..., a, b, c ==> ..., b, 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);
-                       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,                   iptr->dst);
-                       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(iptr->dst,             iptr->dst->prev->prev->prev->prev);
-                       M_COPY(iptr->dst->prev,       iptr->dst->prev->prev->prev->prev->prev);
+                       emit_copy(jd, iptr);
                        break;
 
-               case ICMD_SWAP:       /* ..., a, b ==> ..., b, a                      */
-
-                       M_COPY(src,       iptr->dst->prev);
-                       M_COPY(src->prev, iptr->dst);
+               case ICMD_ASTORE:
+                       if (!(iptr->flags.bits & INS_FLAG_RETADDR))
+                               emit_copy(jd, iptr);
                        break;
 
 
@@ -736,25 +541,46 @@ bool codegen(jitdata *jd)
 
                case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_LSUB(REG_ZERO, s1, d);
+#else
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_ISUB(REG_ZERO, GET_LOW_REG(s1), GET_LOW_REG(d));
+                       M_ISUB(REG_ZERO, GET_HIGH_REG(s1), GET_HIGH_REG(d));
+                       M_CMPULT(REG_ZERO, GET_LOW_REG(d), REG_ITMP3);
+                       M_ISUB(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+#if SIZEOF_VOID_P == 8
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_INTMOVE(s1, d);
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_INTMOVE(s1, GET_LOW_REG(d));
+                       M_ISRA_IMM(GET_LOW_REG(d), 31, GET_HIGH_REG(d));
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_L2I:        /* ..., value  ==> ..., value                   */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       M_ISLL_IMM(s1, 0, d );
+                       M_ISLL_IMM(s1, 0, d);
+#else
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_INTMOVE(GET_LOW_REG(s1), d);
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -762,8 +588,13 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+#if SIZEOF_VOID_P == 8
                        M_LSLL_IMM(s1, 56, d);
                        M_LSRA_IMM( d, 56, d);
+#else
+                       M_ISLL_IMM(s1, 24, d);
+                       M_ISRA_IMM( d, 24, d);
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -771,7 +602,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-            M_CZEXT(s1, d);
+                       M_AND_IMM(s1, 0xffff, d);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -779,8 +610,13 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+#if SIZEOF_VOID_P == 8
                        M_LSLL_IMM(s1, 48, d);
                        M_LSRA_IMM( d, 48, d);
+#else
+                       M_ISLL_IMM(s1, 16, d);
+                       M_ISRA_IMM( d, 16, d);
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -794,14 +630,15 @@ bool codegen(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
+               case ICMD_IINC:
                case ICMD_IADDCONST:  /* ..., value  ==> ..., value + constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767)) {
+                       if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767))
                                M_IADD_IMM(s1, iptr->sx.val.i, d);
-                       else {
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
                                M_IADD(s1, REG_ITMP2, d);
                        }
@@ -810,24 +647,68 @@ bool codegen(jitdata *jd)
 
                case ICMD_LADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_LADD(s1, s2, d);
+#else
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_IADD(s1, s2, GET_HIGH_REG(d));
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                       s2 = emit_load_s2_low(jd, iptr, GET_LOW_REG(REG_ITMP12_PACKED));
+                       if (s1 == GET_LOW_REG(d)) {
+                               M_MOV(s1, REG_ITMP3);
+                               s1 = REG_ITMP3;
+                       }
+                       M_IADD(s1, s2, GET_LOW_REG(d));
+                       M_CMPULT(GET_LOW_REG(d), s1, REG_ITMP3);
+                       M_IADD(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_LADDCONST:  /* ..., value  ==> ..., value + constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.l >= -32768) && (iptr->sx.val.l <= 32767)) {
+                       if ((iptr->sx.val.l >= -32768) && (iptr->sx.val.l <= 32767))
                                M_LADD_IMM(s1, iptr->sx.val.l, d);
-                       else {
+                       else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
                                M_LADD(s1, REG_ITMP2, d);
                        }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 32767)) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_IADD_IMM(GET_LOW_REG(s1), iptr->sx.val.l, GET_LOW_REG(d));
+                               M_CMPULT_IMM(GET_LOW_REG(d), iptr->sx.val.l, REG_ITMP3);
+                               M_IADD(GET_HIGH_REG(s1), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+                       else if ((iptr->sx.val.l >= (-32768 + 1)) && (iptr->sx.val.l < 0)) {
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP2);
+                               M_ISUB_IMM(s1, -(iptr->sx.val.l), GET_LOW_REG(d));
+                               M_CMPULT_IMM(GET_LOW_REG(d), iptr->sx.val.l, REG_ITMP3);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                               M_ISUB_IMM(s1, 1, GET_HIGH_REG(d));
+                               M_IADD(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+                       else {
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_IADD(s1, REG_ITMP2, GET_LOW_REG(d));
+                               M_CMPULT(GET_LOW_REG(d), s1, REG_ITMP3);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                               M_IADD(s1, REG_ITMP3, GET_HIGH_REG(d));
+                               ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
+                               M_IADD(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -841,13 +722,13 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_ISUBCONST:  /* ..., value  ==> ..., value + constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.i >= -32767) && (iptr->sx.val.i <= 32768)) {
+                       if ((iptr->sx.val.i >= -32767) && (iptr->sx.val.i <= 32768))
                                M_IADD_IMM(s1, -iptr->sx.val.i, d);
-                       else {
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
                                M_ISUB(s1, REG_ITMP2, d);
                        }
@@ -856,24 +737,69 @@ bool codegen(jitdata *jd)
 
                case ICMD_LSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_LSUB(s1, s2, d);
+#else
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_ISUB(s1, s2, GET_HIGH_REG(d));
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
+                       M_CMPULT(s1, s2, REG_ITMP3);
+                       M_ISUB(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+                       /* if s1 is equal to REG_ITMP3 we have to reload it, since
+                          the CMPULT instruction destroyed it */
+                       if (s1 == REG_ITMP3)
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                       M_ISUB(s1, s2, GET_LOW_REG(d));
+
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_LSUBCONST:  /* ..., value  ==> ..., value - constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.l >= -32767) && (iptr->sx.val.l <= 32768)) {
+                       if ((iptr->sx.val.l >= -32767) && (iptr->sx.val.l <= 32768))
                                M_LADD_IMM(s1, -iptr->sx.val.l, d);
-                       else {
+                       else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
                                M_LSUB(s1, REG_ITMP2, d);
                        }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 32768)) {
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP2);
+                               M_ISUB_IMM(s1, iptr->sx.val.l, GET_LOW_REG(d));
+                               M_CMPULT_IMM(GET_LOW_REG(d), -(iptr->sx.val.l), REG_ITMP3);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                               M_ISUB_IMM(s1, 1, GET_HIGH_REG(d));
+                               M_IADD(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+                       else if ((iptr->sx.val.l >= -32767) && (iptr->sx.val.l < 0)) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_IADD_IMM(GET_LOW_REG(s1), -(iptr->sx.val.l), GET_LOW_REG(d));
+                               M_CMPULT_IMM(GET_LOW_REG(d), -(iptr->sx.val.l), REG_ITMP3);
+                               M_IADD(GET_HIGH_REG(s1), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+                       else {
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_ISUB(s1, REG_ITMP2, GET_LOW_REG(d));
+                               M_CMPULT(s1, REG_ITMP2, REG_ITMP3);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                               M_ISUB(s1, REG_ITMP3, GET_HIGH_REG(d));
+                               ICONST(REG_ITMP3, iptr->sx.val.l >> 32);
+                               M_ISUB(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+                       }
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -890,7 +816,7 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_IMULCONST:  /* ..., value  ==> ..., value * constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
@@ -904,6 +830,7 @@ bool codegen(jitdata *jd)
 
                case ICMD_LMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
@@ -911,11 +838,33 @@ bool codegen(jitdata *jd)
                        M_MFLO(d);
                        M_NOP;
                        M_NOP;
+#else
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_IMUL(s2, s1);
+                       M_MFLO(REG_ITMP3);
+                       M_NOP;
+                       M_NOP;
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_IMULU(s2, s1);
+                       M_MFHI(GET_HIGH_REG(d));
+                       M_MFLO(GET_LOW_REG(d));
+                       M_NOP;
+                       M_NOP;
+                       M_IADD(GET_HIGH_REG(d), REG_ITMP3, REG_ITMP3);
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_IMUL(s1, s2);
+                       M_MFLO(s2);
+                       /* XXX do we need nops here? */
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_LMULCONST:  /* ..., value  ==> ..., value * constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
@@ -932,7 +881,7 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       gen_div_check(s2);
+                       emit_arithmetic_check(cd, iptr, s2);
                        M_IDIV(s1, s2);
                        M_MFLO(d);
                        M_NOP;
@@ -940,27 +889,29 @@ bool codegen(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
-               case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       gen_div_check(s2);
-                       M_LDIV(s1, s2);
-                       M_MFLO(d);
+                       emit_arithmetic_check(cd, iptr, s2);
+                       M_IDIV(s1, s2);
+                       M_MFHI(d);
                        M_NOP;
                        M_NOP;
                        emit_store_dst(jd, iptr, d);
                        break;
 
-               case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+#if SIZEOF_VOID_P == 8
+
+               case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       gen_div_check(s2);
-                       M_IDIV(s1, s2);
-                       M_MFHI(d);
+                       emit_arithmetic_check(cd, iptr, s2);
+                       M_LDIV(s1, s2);
+                       M_MFLO(d);
                        M_NOP;
                        M_NOP;
                        emit_store_dst(jd, iptr, d);
@@ -971,7 +922,7 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       gen_div_check(s2);
+                       emit_arithmetic_check(cd, iptr, s2);
                        M_LDIV(s1, s2);
                        M_MFHI(d);
                        M_NOP;
@@ -979,8 +930,85 @@ bool codegen(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
+#else /* SIZEOF_VOID_P == 8 */
+
+               case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+
+                       s1 = emit_load_s1(jd, iptr, REG_A0_A1_PACKED);
+                       s2 = emit_load_s2(jd, iptr, REG_A2_A3_PACKED);
+
+                       /* XXX TODO: only do this if arithmetic check is really done! */
+                       M_OR(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
+                       emit_arithmetic_check(cd, iptr, REG_ITMP3);
+
+                       M_LNGMOVE(s1, REG_A0_A1_PACKED);
+                       M_LNGMOVE(s2, REG_A2_A3_PACKED);
+
+                       bte = iptr->sx.s23.s3.bte;
+                       disp = dseg_add_functionptr(cd, bte->fp);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JSR(REG_RA, REG_ITMP3);
+                       M_NOP;
+
+                       d = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
+                       M_LNGMOVE(REG_RESULT_PACKED, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+#endif /* SIZEOF_VOID_P == 8 */
+
                case ICMD_IDIVPOW2:   /* ..., value  ==> ..., value << constant       */
-               case ICMD_LDIVPOW2:   /* val.i = constant                             */
+                                     /* val.i = constant                             */
+                                     
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+#if SIZEOF_VOID_P == 8
+                       M_LSRA_IMM(s1, 63, REG_ITMP2);
+                       M_LSRL_IMM(REG_ITMP2, 64 - iptr->sx.val.i, REG_ITMP2);
+                       M_LADD(s1, REG_ITMP2, REG_ITMP2);
+                       M_LSRA_IMM(REG_ITMP2, iptr->sx.val.i, d);
+#else
+                       M_ISRA_IMM(s1, 31, REG_ITMP2);
+                       M_ISRL_IMM(REG_ITMP2, 32 - iptr->sx.val.i, REG_ITMP2);
+                       M_IADD(s1, REG_ITMP2, REG_ITMP2);
+                       M_ISRA_IMM(REG_ITMP2, iptr->sx.val.i, d);
+#endif
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_IREMPOW2:   /* ..., value  ==> ..., value % constant        */
+                                     /* val.i = constant                             */
+
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       if (s1 == d) {
+                               M_MOV(s1, REG_ITMP1);
+                               s1 = REG_ITMP1;
+                       }
+                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
+                               M_AND_IMM(s1, iptr->sx.val.i, d);
+                               M_BGEZ(s1, 4);
+                               M_NOP;
+                               M_ISUB(REG_ZERO, s1, d);
+                               M_AND_IMM(d, iptr->sx.val.i, d);
+                       }
+                       else {
+                               ICONST(REG_ITMP2, iptr->sx.val.i);
+                               M_AND(s1, REG_ITMP2, d);
+                               M_BGEZ(s1, 4);
+                               M_NOP;
+                               M_ISUB(REG_ZERO, s1, d);
+                               M_AND(d, REG_ITMP2, d);
+                       }
+                       M_ISUB(REG_ZERO, d, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+#if SIZEOF_VOID_P == 8
+
+               case ICMD_LDIVPOW2:   /* ..., value  ==> ..., value << constant       */
+                                     /* val.i = constant                             */
                                      
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
@@ -991,6 +1019,36 @@ bool codegen(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
+               case ICMD_LREMPOW2:   /* ..., value  ==> ..., value % constant        */
+                                     /* val.l = constant                             */
+
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       if (s1 == d) {
+                               M_MOV(s1, REG_ITMP1);
+                               s1 = REG_ITMP1;
+                       }
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                               M_AND_IMM(s1, iptr->sx.val.l, d);
+                               M_BGEZ(s1, 4);
+                               M_NOP;
+                               M_LSUB(REG_ZERO, s1, d);
+                               M_AND_IMM(d, iptr->sx.val.l, d);
+                       }
+                       else {
+                               LCONST(REG_ITMP2, iptr->sx.val.l);
+                               M_AND(s1, REG_ITMP2, d);
+                               M_BGEZ(s1, 4);
+                               M_NOP;
+                               M_LSUB(REG_ZERO, s1, d);
+                               M_AND(d, REG_ITMP2, d);
+                       }
+                       M_LSUB(REG_ZERO, d, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+#endif /* SIZEOF_VOID_P == 8 */
+
                case ICMD_ISHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
@@ -1047,13 +1105,43 @@ bool codegen(jitdata *jd)
 
                case ICMD_LSHL:       /* ..., val1, val2  ==> ..., val1 << val2       */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_LSLL(s1, s2, d);
+#else
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+
+                       M_ISLL(s2, 26, REG_ITMP1);
+                       M_BGEZ(REG_ITMP1, 3);
+                       M_NOP;
+
+                       M_ISLL(GET_LOW_REG(s1), s2, GET_HIGH_REG(d));
+                       M_BR(7);
+                       M_MOV(REG_ZERO, GET_LOW_REG(d));                    /* delay slot */
+
+#if 1
+                       M_ISLL(GET_LOW_REG(s1), s2, GET_LOW_REG(d));
+#endif
+                       M_BEQZ(REG_ITMP1, 4);
+                       M_ISLL(GET_HIGH_REG(s1), s2, GET_HIGH_REG(d));      /* delay slot */
+
+                       M_ISUB(s2, REG_ZERO, REG_ITMP3);
+                       M_ISRL(GET_LOW_REG(s1), REG_ITMP3, REG_ITMP3);
+                       M_OR(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
+
+#if 0
+                       M_ISLL(GET_LOW_REG(s1), s2, GET_LOW_REG(d));
+#endif
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
+#if SIZEOF_VOID_P == 8
+
                case ICMD_LSHLCONST:  /* ..., value  ==> ..., value << constant       */
                                      /* sx.val.i = constant                             */
 
@@ -1099,8 +1187,9 @@ bool codegen(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
+#endif /* SIZEOF_VOID_P == 8 */
+
                case ICMD_IAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
-               case ICMD_LAND:
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
@@ -1110,127 +1199,141 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_IANDCONST:  /* ..., value  ==> ..., value & constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
+                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff))
                                M_AND_IMM(s1, iptr->sx.val.i, d);
-                       else {
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
                                M_AND(s1, REG_ITMP2, d);
                        }
                        emit_store_dst(jd, iptr, d);
                        break;
 
-               case ICMD_IREMPOW2:   /* ..., value  ==> ..., value % constant        */
-                                     /* sx.val.i = constant                             */
+               case ICMD_LAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (s1 == d) {
-                               M_MOV(s1, REG_ITMP1);
-                               s1 = REG_ITMP1;
-                       }
-                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
-                               M_AND_IMM(s1, iptr->sx.val.i, d);
-                               M_BGEZ(s1, 4);
-                               M_NOP;
-                               M_ISUB(REG_ZERO, s1, d);
-                               M_AND_IMM(d, iptr->sx.val.i, d);
-                       } else {
-                               ICONST(REG_ITMP2, iptr->sx.val.i);
-                               M_AND(s1, REG_ITMP2, d);
-                               M_BGEZ(s1, 4);
-                               M_NOP;
-                               M_ISUB(REG_ZERO, s1, d);
-                               M_AND(d, REG_ITMP2, d);
-                       }
-                       M_ISUB(REG_ZERO, d, d);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
+                       M_AND(s1, s2, d);
+#else
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_AND(s1, s2, GET_LOW_REG(d));
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
+                       M_AND(s1, s2, GET_HIGH_REG(d));
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_LANDCONST:  /* ..., value  ==> ..., value & constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff))
                                M_AND_IMM(s1, iptr->sx.val.l, d);
-                       else {
+                       else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
                                M_AND(s1, REG_ITMP2, d);
                        }
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_LREMPOW2:   /* ..., value  ==> ..., value % constant        */
-                                     /* sx.val.l = constant                             */
-
-                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (s1 == d) {
-                               M_MOV(s1, REG_ITMP1);
-                               s1 = REG_ITMP1;
-                       }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
                        if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
-                               M_AND_IMM(s1, iptr->sx.val.l, d);
-                               M_BGEZ(s1, 4);
-                               M_NOP;
-                               M_LSUB(REG_ZERO, s1, d);
-                               M_AND_IMM(d, iptr->sx.val.l, d);
-                       } else {
-                               LCONST(REG_ITMP2, iptr->sx.val.l);
-                               M_AND(s1, REG_ITMP2, d);
-                               M_BGEZ(s1, 4);
-                               M_NOP;
-                               M_LSUB(REG_ZERO, s1, d);
-                               M_AND(d, REG_ITMP2, d);
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_AND_IMM(GET_LOW_REG(s1), iptr->sx.val.l, GET_LOW_REG(d));
+                               M_AND_IMM(GET_HIGH_REG(s1), 0, GET_HIGH_REG(d));
                        }
-                       M_LSUB(REG_ZERO, d, d);
+                       else {
+                               LCONST(REG_ITMP12_PACKED, iptr->sx.val.l);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_AND(s1, GET_LOW_REG(REG_ITMP12_PACKED), GET_LOW_REG(d));
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
+                               M_AND(s1, GET_HIGH_REG(REG_ITMP12_PACKED), GET_HIGH_REG(d));
+                       }
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_IOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
-               case ICMD_LOR:
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       M_OR(s1,s2, d);
+                       M_OR(s1, s2, d);
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_IORCONST:   /* ..., value  ==> ..., value | constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
+                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff))
                                M_OR_IMM(s1, iptr->sx.val.i, d);
-                       else {
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
                                M_OR(s1, REG_ITMP2, d);
                        }
                        emit_store_dst(jd, iptr, d);
                        break;
 
+               case ICMD_LOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
+
+#if SIZEOF_VOID_P == 8
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_OR(s1, s2, d);
+#else
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_OR(s1, s2, GET_LOW_REG(d));
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
+                       M_OR(s1, s2, GET_HIGH_REG(d));
+#endif
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LORCONST:   /* ..., value  ==> ..., value | constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff))
                                M_OR_IMM(s1, iptr->sx.val.l, d);
-                       else {
+                       else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
                                M_OR(s1, REG_ITMP2, d);
                        }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_OR_IMM(GET_LOW_REG(s1), iptr->sx.val.l, GET_LOW_REG(d));
+                               M_OR_IMM(GET_HIGH_REG(s1), 0, GET_HIGH_REG(d));
+                       }
+                       else {
+                               LCONST(REG_ITMP12_PACKED, iptr->sx.val.l);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_OR(s1, GET_LOW_REG(REG_ITMP12_PACKED), GET_LOW_REG(d));
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
+                               M_OR(s1, GET_HIGH_REG(REG_ITMP12_PACKED), GET_HIGH_REG(d));
+                       }
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_IXOR:       /* ..., val1, val2  ==> ..., val1 ^ val2        */
-               case ICMD_LXOR:
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
@@ -1240,61 +1343,97 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_IXORCONST:  /* ..., value  ==> ..., value ^ constant        */
-                                     /* sx.val.i = constant                             */
+                                     /* sx.val.i = constant                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff)) {
+                       if ((iptr->sx.val.i >= 0) && (iptr->sx.val.i <= 0xffff))
                                M_XOR_IMM(s1, iptr->sx.val.i, d);
-                       else {
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
                                M_XOR(s1, REG_ITMP2, d);
                        }
                        emit_store_dst(jd, iptr, d);
                        break;
 
+               case ICMD_LXOR:       /* ..., val1, val2  ==> ..., val1 ^ val2        */
+
+#if SIZEOF_VOID_P == 8
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_XOR(s1, s2, d);
+#else
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_XOR(s1, s2, GET_LOW_REG(d));
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
+                       M_XOR(s1, s2, GET_HIGH_REG(d));
+#endif
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LXORCONST:  /* ..., value  ==> ..., value ^ constant        */
-                                     /* sx.val.l = constant                             */
+                                     /* sx.val.l = constant                          */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff))
                                M_XOR_IMM(s1, iptr->sx.val.l, d);
-                       else {
+                       else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
                                M_XOR(s1, REG_ITMP2, d);
                        }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       if ((iptr->sx.val.l >= 0) && (iptr->sx.val.l <= 0xffff)) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_XOR_IMM(GET_LOW_REG(s1), iptr->sx.val.l, GET_LOW_REG(d));
+                               M_XOR_IMM(GET_HIGH_REG(s1), 0, GET_HIGH_REG(d));
+                       }
+                       else {
+                               LCONST(REG_ITMP12_PACKED, iptr->sx.val.l);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_XOR(s1, GET_LOW_REG(REG_ITMP12_PACKED), GET_LOW_REG(d));
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
+                               M_XOR(s1, GET_HIGH_REG(REG_ITMP12_PACKED), GET_HIGH_REG(d));
+                       }
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
 
                case ICMD_LCMP:       /* ..., val1, val2  ==> ..., val1 cmp val2      */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP3);
                        M_CMPLT(s2, s1, REG_ITMP1);
                        M_LSUB(REG_ITMP1, REG_ITMP3, d);
+#else
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       M_CMPLT(s2, s1, REG_ITMP1);
+                       M_ISUB(REG_ITMP1, REG_ITMP3, d);
+                       M_BNEZ(d, 4);
+                       M_NOP;
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_CMPULT(s1, s2, REG_ITMP3);
+                       M_CMPULT(s2, s1, REG_ITMP1);
+                       M_ISUB(REG_ITMP1, REG_ITMP3, d);
+#endif
                        emit_store_dst(jd, iptr, d);
                        break;
 
 
-               case ICMD_IINC:       /* ..., value  ==> ..., value + constant        */
-                                     /* s1.localindex = variable, sx.val.i = constant             */
-
-                       var = &(rd->locals[iptr->s1.localindex][TYPE_INT]);
-                       if (var->flags & INMEMORY) {
-                               s1 = REG_ITMP1;
-                               M_LLD(s1, REG_SP, var->regoff * 8);
-                       } else
-                               s1 = var->regoff;
-                       M_IADD_IMM(s1, iptr->sx.val.i, s1);
-                       if (var->flags & INMEMORY)
-                               M_LST(s1, REG_SP, var->regoff * 8);
-                       break;
-
-
                /* floating operations ************************************************/
 
                case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
@@ -1490,7 +1629,8 @@ bool codegen(jitdata *jd)
                        M_CVTDF(s1, d);
                        emit_store_dst(jd, iptr, d);
                        break;
-               
+
+#if SUPPORT_FLOAT_CMP
                case ICMD_FCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
 
                        s1 = emit_load_s1(jd, iptr, REG_FTMP1);
@@ -1498,15 +1638,33 @@ bool codegen(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
                        M_FCMPULEF(s1, s2);
                        M_FBT(3);
-                       M_LADD_IMM(REG_ZERO, 1, d);
+                       M_AADD_IMM(REG_ZERO, 1, d);
+                       M_BR(4);
+                       M_NOP;
+                       M_FCMPEQF(s1, s2);
+                       M_ASUB_IMM(REG_ZERO, 1, d);
+                       M_CMOVT(REG_ZERO, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
+
+                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
+                       M_FCMPOLTF(s1, s2);
+                       M_FBF(3);
+                       M_ASUB_IMM(REG_ZERO, 1, d);
                        M_BR(4);
                        M_NOP;
                        M_FCMPEQF(s1, s2);
-                       M_LSUB_IMM(REG_ZERO, 1, d);
+                       M_AADD_IMM(REG_ZERO, 1, d);
                        M_CMOVT(REG_ZERO, d);
                        emit_store_dst(jd, iptr, d);
                        break;
+#endif
 
+#if SUPPORT_DOUBLE_CMP
                case ICMD_DCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpl val2    */
 
                        s1 = emit_load_s1(jd, iptr, REG_FTMP1);
@@ -1514,46 +1672,31 @@ bool codegen(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
                        M_FCMPULED(s1, s2);
                        M_FBT(3);
-                       M_LADD_IMM(REG_ZERO, 1, d);
+                       M_AADD_IMM(REG_ZERO, 1, d);
                        M_BR(4);
                        M_NOP;
                        M_FCMPEQD(s1, s2);
-                       M_LSUB_IMM(REG_ZERO, 1, d);
+                       M_ASUB_IMM(REG_ZERO, 1, d);
                        M_CMOVT(REG_ZERO, d);
                        emit_store_dst(jd, iptr, d);
                        break;
                        
-               case ICMD_FCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
+               case ICMD_DCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
 
                        s1 = emit_load_s1(jd, iptr, REG_FTMP1);
                        s2 = emit_load_s2(jd, iptr, REG_FTMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
-                       M_FCMPOLTF(s1, s2);
+                       M_FCMPOLTD(s1, s2);
                        M_FBF(3);
-                       M_LSUB_IMM(REG_ZERO, 1, d);
-                       M_BR(4);
-                       M_NOP;
-                       M_FCMPEQF(s1, s2);
-                       M_LADD_IMM(REG_ZERO, 1, d);
-                       M_CMOVT(REG_ZERO, d);
-                       emit_store_dst(jd, iptr, d);
-                       break;
-
-               case ICMD_DCMPG:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
-                       M_FCMPOLTD(s1, s2);
-                       M_FBF(3);
-                       M_LSUB_IMM(REG_ZERO, 1, d);
+                       M_ASUB_IMM(REG_ZERO, 1, d);
                        M_BR(4);
                        M_NOP;
                        M_FCMPEQD(s1, s2);
-                       M_LADD_IMM(REG_ZERO, 1, d);
+                       M_AADD_IMM(REG_ZERO, 1, d);
                        M_CMOVT(REG_ZERO, d);
                        emit_store_dst(jd, iptr, d);
                        break;
+#endif
 
 
                /* memory operations **************************************************/
@@ -1562,8 +1705,8 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       gen_nullptr_check(s1);
-                       M_ILD(d, s1, OFFSET(java_arrayheader, size));
+                       /* implicit null-pointer check */
+                       M_ILD(d, s1, OFFSET(java_array_t, size));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1572,12 +1715,10 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP3);
-                       M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray, data[0]));
+                       /* implicit null-pointer check */
+                       M_BLDS(d, REG_ITMP3, OFFSET(java_bytearray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1586,13 +1727,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP3);
                        M_AADD(s2, REG_ITMP3, REG_ITMP3);
-                       M_SLDU(d, REG_ITMP3, OFFSET(java_chararray, data[0]));
+                       /* implicit null-pointer check */
+                       M_SLDU(d, REG_ITMP3, OFFSET(java_chararray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;                  
 
@@ -1601,13 +1740,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP3);
                        M_AADD(s2, REG_ITMP3, REG_ITMP3);
-                       M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_SLDS(d, REG_ITMP3, OFFSET(java_shortarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1616,13 +1753,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 2, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
-                       M_ILD(d, REG_ITMP3, OFFSET(java_intarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_ILD_INTERN(d, REG_ITMP3, OFFSET(java_intarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1630,14 +1765,16 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+#if SIZEOF_VOID_P == 8
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+#else
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+#endif
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 3, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
-                       M_LLD(d, REG_ITMP3, OFFSET(java_longarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_LLD_INTERN(d, REG_ITMP3, OFFSET(java_longarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1646,13 +1783,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 2, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
-                       M_FLD(d, REG_ITMP3, OFFSET(java_floatarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_FLD_INTERN(d, REG_ITMP3, OFFSET(java_floatarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1661,13 +1796,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 3, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
-                       M_DLD(d, REG_ITMP3, OFFSET(java_doublearray, data[0]));
+                       /* implicit null-pointer check */
+                       M_DLD_INTERN(d, REG_ITMP3, OFFSET(java_doublearray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1676,13 +1809,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP3);
                        M_AADD(REG_ITMP3, s1, REG_ITMP3);
-                       M_ALD(d, REG_ITMP3, OFFSET(java_objectarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_ALD_INTERN(d, REG_ITMP3, OFFSET(java_objectarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1691,13 +1822,11 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       /* implicit null-pointer check */
+                       M_BST(s3, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
                        break;
 
                case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1705,70 +1834,64 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP1);
                        M_AADD(s2, REG_ITMP1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       /* implicit null-pointer check */
+                       M_SST(s3, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
                        break;
 
                case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 2, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_IST_INTERN(s3, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
                        break;
 
                case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 3, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
+#if SIZEOF_VOID_P == 8
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
+#else
+                       s3 = emit_load_s3(jd, iptr, REG_ITMP23_PACKED);
+#endif
+                       /* implicit null-pointer check */
+                       M_LST_INTERN(s3, REG_ITMP1, OFFSET(java_longarray_t, data[0]));
                        break;
 
                case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 2, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP1);
-                       M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_FST_INTERN(s3, REG_ITMP1, OFFSET(java_floatarray_t, data[0]));
                        break;
 
                case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 3, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP1);
-                       M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+                       /* implicit null-pointer check */
+                       M_DST_INTERN(s3, REG_ITMP1, OFFSET(java_doublearray_t, data[0]));
                        break;
 
 
@@ -1776,29 +1899,24 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
 
-                       M_MOV(s1, rd->argintregs[0]);
-                       M_MOV(s3, rd->argintregs[1]);
-                       disp = dseg_addaddress(cd, BUILTIN_canstore);
+                       M_INTMOVE(s1, REG_A0);
+                       M_INTMOVE(s3, REG_A1);
+                       disp = dseg_add_functionptr(cd, BUILTIN_canstore);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_JSR(REG_RA, REG_ITMP3);
                        M_NOP;
-
-                       M_BEQZ(REG_RESULT, 0);
-                       codegen_add_arraystoreexception_ref(cd);
-                       M_NOP;
+                       emit_exception_check(cd, iptr);
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_AST_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_AST_INTERN(s3, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
                        break;
 
 
@@ -1806,12 +1924,10 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP1);
-                       M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       /* implicit null-pointer check */
+                       M_BST(REG_ZERO, REG_ITMP1, OFFSET(java_bytearray_t, data[0]));
                        break;
 
                case ICMD_CASTORECONST:   /* ..., arrayref, index  ==> ...            */
@@ -1819,153 +1935,133 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_AADD(s2, s1, REG_ITMP1);
                        M_AADD(s2, REG_ITMP1, REG_ITMP1);
-                       M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       /* implicit null-pointer check */
+                       M_SST(REG_ZERO, REG_ITMP1, OFFSET(java_chararray_t, data[0]));
                        break;
 
                case ICMD_IASTORECONST:   /* ..., arrayref, index  ==> ...            */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 2, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
-                       M_IST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_IST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_intarray_t, data[0]));
                        break;
 
                case ICMD_LASTORECONST:   /* ..., arrayref, index  ==> ...            */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, 3, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
-                       M_LST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       /* implicit null-pointer check */
+#if SIZEOF_VOID_P == 8
+                       M_LST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_longarray_t, data[0]));
+#else
+                       M_LST_INTERN(PACK_REGS(REG_ZERO, REG_ZERO), REG_ITMP1, OFFSET(java_longarray_t, data[0]));
+#endif
                        break;
 
                case ICMD_AASTORECONST:   /* ..., arrayref, index  ==> ...            */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       if (INSTRUCTION_MUST_CHECK(iptr)) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                       }
+                       emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_ASLL_IMM(s2, POINTERSHIFT, REG_ITMP2);
                        M_AADD(REG_ITMP2, s1, REG_ITMP1);
-                       M_AST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       /* implicit null-pointer check */
+                       M_AST_INTERN(REG_ZERO, REG_ITMP1, OFFSET(java_objectarray_t, data[0]));
                        break;
 
 
                case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = dseg_add_unique_address(cd, uf);
 
-                               disp = dseg_addaddress(cd, NULL);
-
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
-                                                                       iptr->sx.s23.s3.uf, disp);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                       } else {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
-
-                               disp = dseg_addaddress(cd, &(fi->value));
-
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
+                               patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
+                               fieldtype = fi->type;
+                               disp      = dseg_add_address(cd, fi->value);
 
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
-                               }
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class,
+                                                                                 fi->class, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
+
                        switch (fieldtype) {
                        case TYPE_INT:
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                                M_ILD_INTERN(d, REG_ITMP1, 0);
-                               emit_store_dst(jd, iptr, d);
                                break;
                        case TYPE_LNG:
+#if SIZEOF_VOID_P == 8
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+#else
+                               d = codegen_reg_of_dst(jd, iptr, REG_ITMP23_PACKED);
+#endif
                                M_LLD_INTERN(d, REG_ITMP1, 0);
-                               emit_store_dst(jd, iptr, d);
                                break;
                        case TYPE_ADR:
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                                M_ALD_INTERN(d, REG_ITMP1, 0);
-                               emit_store_dst(jd, iptr, d);
                                break;
                        case TYPE_FLT:
                                d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
                                M_FLD_INTERN(d, REG_ITMP1, 0);
-                               emit_store_dst(jd, iptr, d);
                                break;
                        case TYPE_DBL:                          
                                d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
                                M_DLD_INTERN(d, REG_ITMP1, 0);
-                               emit_store_dst(jd, iptr, d);
                                break;
                        }
+                       emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = dseg_add_unique_address(cd, uf);
 
-                               disp = dseg_addaddress(cd, NULL);
-
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
-                                                                       iptr->sx.s23.s3.uf, disp);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                       } else {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
-
-                               disp = dseg_addaddress(cd, &(fi->value));
-
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
+                               patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
+                               fieldtype = fi->type;
+                               disp      = dseg_add_address(cd, fi->value);
 
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
-                               }
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class,
+                                                                                 fi->class, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
+
                        switch (fieldtype) {
                        case TYPE_INT:
                                s1 = emit_load_s1(jd, iptr, REG_ITMP2);
                                M_IST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_LNG:
+#if SIZEOF_VOID_P == 8
                                s1 = emit_load_s1(jd, iptr, REG_ITMP2);
+#else
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP23_PACKED);
+#endif
                                M_LST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_ADR:
@@ -1984,41 +2080,26 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_PUTSTATICCONST: /* ...  ==> ...                             */
-                                         /* val = value (in current instruction)     */
-                                         /* following NOP)                           */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = dseg_add_unique_address(cd, uf);
 
-                               disp = dseg_addaddress(cd, NULL);
-
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
-                                                                       uf, disp);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                       } else {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
-
+                               patcher_add_patch_ref(jd, PATCHER_get_putstatic, uf, disp);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
+                               disp      = dseg_add_address(cd, fi->value);
 
-
-                               disp = dseg_addaddress(cd, &(fi->value));
-
-                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_clinit, fi->class, 0);
-
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
-                               }
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class,
+                                                                                 fi->class, disp);
                        }
 
                        M_ALD(REG_ITMP1, REG_PV, disp);
+
                        switch (fieldtype) {
                        case TYPE_INT:
                                M_IST_INTERN(REG_ZERO, REG_ITMP1, 0);
@@ -2042,143 +2123,138 @@ bool codegen(jitdata *jd)
                case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       gen_nullptr_check(s1);
+                       emit_nullpointer_check(cd, iptr, s1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = 0;
 
-                               codegen_addpatchref(cd, PATCHER_get_putfield,
-                                                                       iptr->sx.s23.s3.uf, 0);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                               a = 0;
-
-                       } else {
-                               a = iptr->sx.s23.s3.fmiref->p.field->offset;
+                               patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
+                               fieldtype = fi->type;
+                               disp      = fi->offset;
                        }
 
                        switch (fieldtype) {
                        case TYPE_INT:
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                               M_ILD(d, s1, a);
-                               emit_store_dst(jd, iptr, d);
+                               M_ILD(d, s1, disp);
                                break;
                        case TYPE_LNG:
+#if SIZEOF_VOID_P == 8
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                               M_LLD(d, s1, a);
-                               emit_store_dst(jd, iptr, d);
+                               M_LLD(d, s1, disp);
+#else
+                               d = codegen_reg_of_dst(jd, iptr, REG_ITMP23_PACKED);
+                               M_LLD_GETFIELD(d, s1, disp);
+#endif
                                break;
                        case TYPE_ADR:
                                d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
-                               M_ALD(d, s1, a);
-                               emit_store_dst(jd, iptr, d);
+                               M_ALD(d, s1, disp);
                                break;
                        case TYPE_FLT:
                                d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                               M_FLD(d, s1, a);
-                               emit_store_dst(jd, iptr, d);
+                               M_FLD(d, s1, disp);
                                break;
                        case TYPE_DBL:                          
                                d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                               M_DLD(d, s1, a);
-                               emit_store_dst(jd, iptr, d);
+                               M_DLD(d, s1, disp);
                                break;
                        }
+                       emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_PUTFIELD:   /* ..., objectref, value  ==> ...               */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       gen_nullptr_check(s1);
-
-                       if (!IS_FLT_DBL_TYPE(fieldtype)) {
-                               s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       } else {
-                               s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       }
+                       emit_nullpointer_check(cd, iptr, s1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = 0;
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
+                               fieldtype = fi->type;
+                               disp      = fi->offset;
+                       }
 
-                               codegen_addpatchref(cd, PATCHER_get_putfield,
-                                                                       iptr->sx.s23.s3.uf, 0);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                               a = 0;
-
-                       } else {
-                               a = iptr->sx.s23.s3.fmiref->p.field->offset;
+#if SIZEOF_VOID_P == 8
+                       if (IS_INT_LNG_TYPE(fieldtype))
+                               s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       else
+                               s2 = emit_load_s2(jd, iptr, REG_FTMP1);
+#else
+                       if (IS_INT_LNG_TYPE(fieldtype)) {
+                               if (IS_2_WORD_TYPE(fieldtype))
+                                       s2 = emit_load_s2(jd, iptr, REG_ITMP23_PACKED);
+                               else
+                                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        }
+                       else
+                               s2 = emit_load_s2(jd, iptr, REG_FTMP2);
+#endif
+
+                       if (INSTRUCTION_IS_UNRESOLVED(iptr))
+                               patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
 
                        switch (fieldtype) {
                        case TYPE_INT:
-                               M_IST(s2, s1, a);
+                               M_IST(s2, s1, disp);
                                break;
                        case TYPE_LNG:
-                               M_LST(s2, s1, a);
+                               M_LST(s2, s1, disp);
                                break;
                        case TYPE_ADR:
-                               M_AST(s2, s1, a);
+                               M_AST(s2, s1, disp);
                                break;
                        case TYPE_FLT:
-                               M_FST(s2, s1, a);
+                               M_FST(s2, s1, disp);
                                break;
                        case TYPE_DBL:
-                               M_DST(s2, s1, a);
+                               M_DST(s2, s1, disp);
                                break;
                        }
                        break;
 
                case ICMD_PUTFIELDCONST:  /* ..., objectref  ==> ...                  */
-                                         /* val = value (in current instruction)     */
-                                         /* following NOP)                           */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       gen_nullptr_check(s1);
+                       emit_nullpointer_check(cd, iptr, s1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               unresolved_field *uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = 0;
 
-                               codegen_addpatchref(cd, PATCHER_get_putfield,
-                                                                       uf, 0);
-
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                               a = 0;
-
-                       } else {
-                               a = INSTRUCTION_RESOLVED_FIELDINFO(iptr + 1)->offset;
+                               patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
+                               fieldtype = fi->type;
+                               disp      = fi->offset;
                        }
 
                        switch (fieldtype) {
                        case TYPE_INT:
-                               M_IST(REG_ZERO, s1, a);
+                               M_IST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_LNG:
-                               M_LST(REG_ZERO, s1, a);
+                               M_LST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_ADR:
-                               M_AST(REG_ZERO, s1, a);
+                               M_AST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_FLT:
-                               M_FST(REG_ZERO, s1, a);
+                               M_FST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_DBL:
-                               M_DST(REG_ZERO, s1, a);
+                               M_DST(REG_ZERO, s1, disp);
                                break;
                        }
                        break;
@@ -2193,16 +2269,13 @@ bool codegen(jitdata *jd)
                        
 #ifdef ENABLE_VERIFIER
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
-                                                                       iptr->sx.s23.s2.uc, 0);
+                               uc = iptr->sx.s23.s2.uc;
 
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
+                               patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
                        }
 #endif /* ENABLE_VERIFIER */
 
-                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       disp = dseg_add_functionptr(cd, asm_handle_exception);
                        M_ALD(REG_ITMP2, REG_PV, disp);
                        M_JSR(REG_ITMP2_XPC, REG_ITMP2);
                        M_NOP;
@@ -2212,370 +2285,541 @@ bool codegen(jitdata *jd)
                        break;
 
                case ICMD_GOTO:         /* ... ==> ...                                */
-                       M_BR(0);
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+               case ICMD_RET:          /* ... ==> ...                                */
+
+                       emit_br(cd, iptr->dst.block);
                        ALIGNCODENOP;
                        break;
 
                case ICMD_JSR:          /* ... ==> ...                                */
 
-                       dseg_addtarget(cd, iptr->sx.s23.s3.jsrtarget.block);
-                       M_ALD(REG_ITMP1, REG_PV, -(cd->dseglen));
-                       M_JSR(REG_ITMP1, REG_ITMP1);        /* REG_ITMP1 = return address */
-                       M_NOP;
-                       break;
-                       
-               case ICMD_RET:          /* ... ==> ...                                */
-                                       /* s1.localindex = local variable                       */
-                       var = &(rd->locals[iptr->s1.localindex][TYPE_ADR]);
-                       if (var->flags & INMEMORY) {
-                               M_ALD(REG_ITMP1, REG_SP, var->regoff * 8);
-                               M_RET(REG_ITMP1);
-                       } else
-                               M_RET(var->regoff);
-                       M_NOP;
+                       emit_br(cd, iptr->sx.s23.s3.jsrtarget.block);
                        ALIGNCODENOP;
                        break;
-
+                       
                case ICMD_IFNULL:       /* ..., value ==> ...                         */
+               case ICMD_IFNONNULL:
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       M_BEQZ(s1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
-                       break;
-
-               case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
-
-                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       M_BNEZ(s1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       emit_bccz(cd, iptr->dst.block, iptr->opc - ICMD_IFNULL, s1, BRANCH_OPT_NONE);
                        break;
 
                case ICMD_IFEQ:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BEQZ(s1, 0);
-                       else {
+                       if (iptr->sx.val.i == 0)
+                               emit_beqz(cd, iptr->dst.block, s1);
+                       else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
-                               M_BEQ(s1, REG_ITMP2, 0);
+                               emit_beq(cd, iptr->dst.block, s1, REG_ITMP2);
                        }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
                        break;
 
                case ICMD_IFLT:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BLTZ(s1, 0);
-                       else {
-                               if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767)) {
+                       if (iptr->sx.val.i == 0)
+                               emit_bltz(cd, iptr->dst.block, s1);
+                       else {
+                               if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767))
                                        M_CMPLT_IMM(s1, iptr->sx.val.i, REG_ITMP1);
-                               else {
+                               else {
                                        ICONST(REG_ITMP2, iptr->sx.val.i);
                                        M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
                                }
-                               M_BNEZ(REG_ITMP1, 0);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP1);
                        }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
                        break;
 
                case ICMD_IFLE:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BLEZ(s1, 0);
-                               }
+                       if (iptr->sx.val.i == 0)
+                               emit_blez(cd, iptr->dst.block, s1);
                        else {
                                if ((iptr->sx.val.i >= -32769) && (iptr->sx.val.i <= 32766)) {
                                        M_CMPLT_IMM(s1, iptr->sx.val.i + 1, REG_ITMP1);
-                                       M_BNEZ(REG_ITMP1, 0);
-                                       }
+                                       emit_bnez(cd, iptr->dst.block, REG_ITMP1);
+                               }
                                else {
                                        ICONST(REG_ITMP2, iptr->sx.val.i);
                                        M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
-                                       M_BEQZ(REG_ITMP1, 0);
-                                       }
+                                       emit_beqz(cd, iptr->dst.block, REG_ITMP1);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       }
                        break;
 
                case ICMD_IFNE:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BNEZ(s1, 0);
-                               }
+                       if (iptr->sx.val.i == 0)
+                               emit_bnez(cd, iptr->dst.block, s1);
                        else {
                                ICONST(REG_ITMP2, iptr->sx.val.i);
-                               M_BNE(s1, REG_ITMP2, 0);
-                               }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_bne(cd, iptr->dst.block, s1, REG_ITMP2);
+                       }
                        break;
 
                case ICMD_IFGT:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BGTZ(s1, 0);
-                               }
+                       if (iptr->sx.val.i == 0)
+                               emit_bgtz(cd, iptr->dst.block, s1);
                        else {
                                if ((iptr->sx.val.i >= -32769) && (iptr->sx.val.i <= 32766)) {
                                        M_CMPLT_IMM(s1, iptr->sx.val.i + 1, REG_ITMP1);
-                                       M_BEQZ(REG_ITMP1, 0);
-                                       }
+                                       emit_beqz(cd, iptr->dst.block, REG_ITMP1);
+                               }
                                else {
                                        ICONST(REG_ITMP2, iptr->sx.val.i);
                                        M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
-                                       M_BNEZ(REG_ITMP1, 0);
-                                       }
+                                       emit_bnez(cd, iptr->dst.block, REG_ITMP1);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       }
                        break;
 
                case ICMD_IFGE:         /* ..., value ==> ...                         */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.i == 0) {
-                               M_BGEZ(s1, 0);
-                               }
+                       if (iptr->sx.val.i == 0)
+                               emit_bgez(cd, iptr->dst.block, s1);
                        else {
-                               if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767)) {
+                               if ((iptr->sx.val.i >= -32768) && (iptr->sx.val.i <= 32767))
                                        M_CMPLT_IMM(s1, iptr->sx.val.i, REG_ITMP1);
-                                       }
                                else {
                                        ICONST(REG_ITMP2, iptr->sx.val.i);
                                        M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
-                                       }
-                               M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP1);
+                       }
                        break;
 
                case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.l == 0) {
-                               M_BEQZ(s1, 0);
-                               }
+                       if (iptr->sx.val.l == 0)
+                               emit_beqz(cd, iptr->dst.block, s1);
                        else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
-                               M_BEQ(s1, REG_ITMP2, 0);
-                               }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_beq(cd, iptr->dst.block, s1, REG_ITMP2);
+                       }
+#else
+                       if (iptr->sx.val.l == 0) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_OR(GET_LOW_REG(s1), GET_HIGH_REG(s1), REG_ITMP3);
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_XOR(s1, REG_ITMP2, REG_ITMP2);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
+                               M_XOR(s1, REG_ITMP3, REG_ITMP3);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP3);
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
                        break;
 
                case ICMD_IF_LLT:       /* ..., value ==> ...                         */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.l == 0) {
-                               M_BLTZ(s1, 0);
-                               }
+                       if (iptr->sx.val.l == 0)
+                               emit_bltz(cd, iptr->dst.block, s1);
                        else {
-                               if ((iptr->sx.val.l >= -32768) && (iptr->sx.val.l <= 32767)) {
-                                       M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP1);
-                                       }
+                               if ((iptr->sx.val.l >= -32768) && (iptr->sx.val.l <= 32767))
+                                       M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP3);
                                else {
                                        LCONST(REG_ITMP2, iptr->sx.val.l);
-                                       M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
-                                       }
-                               M_BNEZ(REG_ITMP1, 0);
+                                       M_CMPLT(s1, REG_ITMP2, REG_ITMP3);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#else
+                       if (iptr->sx.val.l == 0) {
+                               /* if high word is less than zero, the whole long is too */
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               emit_bltz(cd, iptr->dst.block, s1);
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_CMPLT(s1, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                               s2 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_BNE(s1, REG_ITMP2, 5); /* XXX */
+                               M_NOP;
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               M_CMPULT(s2, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
                        break;
 
                case ICMD_IF_LLE:       /* ..., value ==> ...                         */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.l == 0) {
-                               M_BLEZ(s1, 0);
-                               }
+                       if (iptr->sx.val.l == 0)
+                               emit_blez(cd, iptr->dst.block, s1);
                        else {
                                if ((iptr->sx.val.l >= -32769) && (iptr->sx.val.l <= 32766)) {
-                                       M_CMPLT_IMM(s1, iptr->sx.val.l + 1, REG_ITMP1);
-                                       M_BNEZ(REG_ITMP1, 0);
-                                       }
+                                       M_CMPLT_IMM(s1, iptr->sx.val.l + 1, REG_ITMP2);
+                                       emit_bnez(cd, iptr->dst.block, REG_ITMP2);
+                               }
                                else {
                                        LCONST(REG_ITMP2, iptr->sx.val.l);
-                                       M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
-                                       M_BEQZ(REG_ITMP1, 0);
-                                       }
+                                       M_CMPGT(s1, REG_ITMP2, REG_ITMP3);
+                                       emit_beqz(cd, iptr->dst.block, REG_ITMP3);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       }
+#else
+                       if (iptr->sx.val.l == 0) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_BGTZ(GET_HIGH_REG(s1), 5); /* XXX */
+                               M_NOP;
+                               emit_bltz(cd, iptr->dst.block, GET_HIGH_REG(s1));
+                               emit_beqz(cd, iptr->dst.block, GET_LOW_REG(s1));
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_CMPLT(s1, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                               s2 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_BNE(s1, REG_ITMP2, 5); /* XXX */
+                               M_NOP;
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               M_CMPUGT(s2, REG_ITMP2, REG_ITMP3);
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
                        break;
 
                case ICMD_IF_LNE:       /* ..., value ==> ...                         */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.l == 0) {
-                               M_BNEZ(s1, 0);
-                               }
+                       if (iptr->sx.val.l == 0)
+                               emit_bnez(cd, iptr->dst.block, s1);
                        else {
                                LCONST(REG_ITMP2, iptr->sx.val.l);
-                               M_BNE(s1, REG_ITMP2, 0);
-                               }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_bne(cd, iptr->dst.block, s1, REG_ITMP2);
+                       }
+#else
+                       if (iptr->sx.val.l == 0) {
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               M_OR(GET_LOW_REG(s1), GET_HIGH_REG(s1), REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_XOR(s1, REG_ITMP2, REG_ITMP2);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP3, iptr->sx.val.l & 0xffffffff);
+                               M_XOR(s1, REG_ITMP3, REG_ITMP3);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
                        break;
 
                case ICMD_IF_LGT:       /* ..., value ==> ...                         */
 
+#if SIZEOF_VOID_P == 8
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       if (iptr->sx.val.l == 0) {
-                               M_BGTZ(s1, 0);
-                               }
+                       if (iptr->sx.val.l == 0)
+                               emit_bgtz(cd, iptr->dst.block, s1);
                        else {
                                if ((iptr->sx.val.l >= -32769) && (iptr->sx.val.l <= 32766)) {
-                                       M_CMPLT_IMM(s1, iptr->sx.val.l + 1, REG_ITMP1);
-                                       M_BEQZ(REG_ITMP1, 0);
-                                       }
+                                       M_CMPLT_IMM(s1, iptr->sx.val.l + 1, REG_ITMP2);
+                                       emit_beqz(cd, iptr->dst.block, REG_ITMP2);
+                               }
                                else {
                                        LCONST(REG_ITMP2, iptr->sx.val.l);
-                                       M_CMPGT(s1, REG_ITMP2, REG_ITMP1);
-                                       M_BNEZ(REG_ITMP1, 0);
-                                       }
+                                       M_CMPGT(s1, REG_ITMP2, REG_ITMP3);
+                                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
-                       break;
-
-               case ICMD_IF_LGE:       /* ..., value ==> ...                         */
-
-                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       }
+#else
                        if (iptr->sx.val.l == 0) {
-                               M_BGEZ(s1, 0);
-                               }
+                               s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                               emit_bgtz(cd, iptr->dst.block, GET_HIGH_REG(s1));
+                               M_BLTZ(GET_HIGH_REG(s1), 3); /* XXX */
+                               M_NOP;
+                               emit_bnez(cd, iptr->dst.block, GET_LOW_REG(s1));
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_CMPGT(s1, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                               s2 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_BNE(s1, REG_ITMP2, 5); /* XXX */
+                               M_NOP;
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               M_CMPUGT(s2, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
+                       break;
+
+               case ICMD_IF_LGE:       /* ..., value ==> ...                         */
+
+#if SIZEOF_VOID_P == 8
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       if (iptr->sx.val.l == 0)
+                               emit_bgez(cd, iptr->dst.block, s1);
                        else {
                                if ((iptr->sx.val.l >= -32768) && (iptr->sx.val.l <= 32767)) {
-                                       M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP1);
-                                       }
+                                       M_CMPLT_IMM(s1, iptr->sx.val.l, REG_ITMP3);
+                               }
                                else {
                                        LCONST(REG_ITMP2, iptr->sx.val.l);
-                                       M_CMPLT(s1, REG_ITMP2, REG_ITMP1);
-                                       }
-                               M_BEQZ(REG_ITMP1, 0);
+                                       M_CMPLT(s1, REG_ITMP2, REG_ITMP3);
                                }
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#else
+                       if (iptr->sx.val.l == 0) {
+                               /* if high word is greater equal zero, the whole long is too */
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               emit_bgez(cd, iptr->dst.block, s1);
+                       }
+                       else {
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                               ICONST(REG_ITMP2, iptr->sx.val.l >> 32);
+                               M_CMPGT(s1, REG_ITMP2, REG_ITMP3);
+                               emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                               s2 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                               M_BNE(s1, REG_ITMP2, 5); /* XXX */
+                               M_NOP;
+                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               M_CMPULT(s2, REG_ITMP2, REG_ITMP3);
+                               emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       }
+#endif
                        break;
 
                case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
-               case ICMD_IF_LCMPEQ:    /* op1 = target JavaVM pc                     */
-               case ICMD_IF_ACMPEQ:
+               case ICMD_IF_ACMPEQ:    /* op1 = target JavaVM pc                     */
+#if SIZEOF_VOID_P == 8
+               case ICMD_IF_LCMPEQ:
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_BEQ(s1, s2, 0);
-                       codegen_addreference(cd, iptr->dst.block);
+                       emit_beq(cd, iptr->dst.block, s1, s2);
+                       break;
+
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPEQ:    /* ..., value, value ==> ...                  */
+                                       /* op1 = target JavaVM pc                     */
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_BNE(s1, s2, 3); /* XXX TWISTI: uff, that is a problem */
                        M_NOP;
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       emit_beq(cd, iptr->dst.block, s1, s2);
                        break;
+#endif
 
                case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
-               case ICMD_IF_LCMPNE:    /* op1 = target JavaVM pc                     */
-               case ICMD_IF_ACMPNE:
+               case ICMD_IF_ACMPNE:    /* op1 = target JavaVM pc                     */
+#if SIZEOF_VOID_P == 8
+               case ICMD_IF_LCMPNE:
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_BNE(s1, s2, 0);
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       emit_bne(cd, iptr->dst.block, s1, s2);
                        break;
 
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPNE:    /* ..., value, value ==> ...                  */
+
+                       /* TODO: could be optimized (XOR or SUB) */
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       emit_bne(cd, iptr->dst.block, s1, s2);
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       emit_bne(cd, iptr->dst.block, s1, s2);
+                       break;
+#endif
+
                case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
+#if SIZEOF_VOID_P == 8
                case ICMD_IF_LCMPLT:    /* op1 = target JavaVM pc                     */
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_CMPLT(s1, s2, REG_ITMP1);
-                       M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       break;
+
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPLT:    /* ..., value, value ==> ...                  */
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       /* load low-bits before the branch, so we know the distance */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_BNEZ(REG_ITMP3, 4); /* XXX */
                        M_NOP;
+                       M_CMPULT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
                        break;
+#endif
 
                case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
+#if SIZEOF_VOID_P == 8
                case ICMD_IF_LCMPGT:    /* op1 = target JavaVM pc                     */
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_CMPGT(s1, s2, REG_ITMP1);
-                       M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       break;
+
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPGT:    /* ..., value, value ==> ...                  */
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       /* load low-bits before the branch, so we know the distance */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_BNEZ(REG_ITMP3, 4); /* XXX */
                        M_NOP;
+                       M_CMPUGT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
                        break;
+#endif
 
                case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
+#if SIZEOF_VOID_P == 8
                case ICMD_IF_LCMPLE:    /* op1 = target JavaVM pc                     */
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_CMPGT(s1, s2, REG_ITMP1);
-                       M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       break;
+
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPLE:    /* ..., value, value ==> ...                  */
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       /* load low-bits before the branch, so we know the distance */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_BNEZ(REG_ITMP3, 4); /* XXX */
                        M_NOP;
+                       M_CMPUGT(s1, s2, REG_ITMP3);
+                       emit_beqz(cd, iptr->dst.block, REG_ITMP3);
                        break;
+#endif
 
                case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
+#if SIZEOF_VOID_P == 8
                case ICMD_IF_LCMPGE:    /* op1 = target JavaVM pc                     */
+#endif
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
-                       M_CMPLT(s1, s2, REG_ITMP1);
-                       M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, iptr->dst.block);
-                       M_NOP;
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       emit_beqz(cd, iptr->dst.block, REG_ITMP3);
                        break;
 
+#if SIZEOF_VOID_P == 4
+               case ICMD_IF_LCMPGE:    /* ..., value, value ==> ...                  */
+
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_CMPGT(s1, s2, REG_ITMP3);
+                       emit_bnez(cd, iptr->dst.block, REG_ITMP3);
+                       M_CMPLT(s1, s2, REG_ITMP3);
+                       /* load low-bits before the branch, so we know the distance */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
+                       M_BNEZ(REG_ITMP3, 4); /* XXX */
+                       M_NOP;
+                       M_CMPULT(s1, s2, REG_ITMP3);
+                       emit_beqz(cd, iptr->dst.block, REG_ITMP3);
+                       break;
+#endif
 
                case ICMD_IRETURN:      /* ..., retvalue ==> ...                      */
+#if SIZEOF_VOID_P == 8
                case ICMD_LRETURN:
+#endif
 
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_RESULT);
                        M_INTMOVE(s1, REG_RESULT);
                        goto nowperformreturn;
 
                case ICMD_ARETURN:      /* ..., retvalue ==> ...                      */
 
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_RESULT);
                        M_INTMOVE(s1, REG_RESULT);
 
 #ifdef ENABLE_VERIFIER
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
-                                                                       iptr->sx.s23.s2.uc, 0);
+                               uc = iptr->sx.s23.s2.uc;
 
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
+                               patcher_add_patch_ref(jd, PATCHER_resolve_class, uc, 0);
                        }
 #endif /* ENABLE_VERIFIER */
                        goto nowperformreturn;
 
-           case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
+#if SIZEOF_VOID_P == 4
+               case ICMD_LRETURN:      /* ..., retvalue ==> ...                      */
 
+                       s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
+                       M_LNGMOVE(s1, REG_RESULT_PACKED);
+                       goto nowperformreturn;
+#endif
+
+           case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_FRESULT);
                        M_FLTMOVE(s1, REG_FRESULT);
                        goto nowperformreturn;
 
            case ICMD_DRETURN:      /* ..., retvalue ==> ...                      */
 
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_FRESULT);
                        M_DBLMOVE(s1, REG_FRESULT);
                        goto nowperformreturn;
 
                case ICMD_RETURN:      /* ...  ==> ...                                */
 
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
+
 nowperformreturn:
                        {
                        s4 i, p;
@@ -2589,7 +2833,7 @@ nowperformreturn:
 
 #if defined(ENABLE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-                               disp = dseg_addaddress(cd, LOCK_monitor_exit);
+                               disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
                                M_ALD(REG_ITMP3, REG_PV, disp);
 
                                /* we need to save the proper return value */
@@ -2597,20 +2841,30 @@ nowperformreturn:
                                switch (iptr->opc) {
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
+#if SIZEOF_VOID_P == 8
+                               case ICMD_LRETURN:
+#endif
+                                       M_ALD(REG_A0, REG_SP, rd->memuse * 8);
+                                       M_JSR(REG_RA, REG_ITMP3);
+                                       M_AST(REG_RESULT, REG_SP, rd->memuse * 8);  /* delay slot */
+                                       break;
+#if SIZEOF_VOID_P == 4
                                case ICMD_LRETURN:
-                                       M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
+                                       M_ALD(REG_A0, REG_SP, rd->memuse * 8);
+                                       M_LST(REG_RESULT_PACKED, REG_SP, rd->memuse * 8);
                                        M_JSR(REG_RA, REG_ITMP3);
-                                       M_LST(REG_RESULT, REG_SP, rd->memuse * 8);  /* delay slot */
+                                       M_NOP;
                                        break;
+#endif
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
-                                       M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
+                                       M_ALD(REG_A0, REG_SP, rd->memuse * 8);
                                        M_JSR(REG_RA, REG_ITMP3);
                                        M_DST(REG_FRESULT, REG_SP, rd->memuse * 8); /* delay slot */
                                        break;
                                case ICMD_RETURN:
                                        M_JSR(REG_RA, REG_ITMP3);
-                                       M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8); /* delay*/
+                                       M_ALD(REG_A0, REG_SP, rd->memuse * 8); /* delay*/
                                        break;
                                }
 
@@ -2619,9 +2873,16 @@ nowperformreturn:
                                switch (iptr->opc) {
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
+#if SIZEOF_VOID_P == 8
                                case ICMD_LRETURN:
-                                       M_LLD(REG_RESULT, REG_SP, rd->memuse * 8);
+#endif
+                                       M_ALD(REG_RESULT, REG_SP, rd->memuse * 8);
+                                       break;
+#if SIZEOF_VOID_P == 4
+                               case ICMD_LRETURN:
+                                       M_LLD(REG_RESULT_PACKED, REG_SP, rd->memuse * 8);
                                        break;
+#endif
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
                                        M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
@@ -2639,7 +2900,7 @@ nowperformreturn:
                        /* restore saved registers                                        */
 
                        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
-                               p--; M_LLD(rd->savintregs[i], REG_SP, p * 8);
+                               p--; M_ALD(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);
@@ -2656,12 +2917,12 @@ nowperformreturn:
 
                                if (hi == 0) {
                                        M_RET(REG_RA);
-                                       M_LADD_IMM(REG_SP, lo, REG_SP);             /* delay slot */
+                                       M_AADD_IMM(REG_SP, lo, REG_SP);             /* delay slot */
                                } else {
                                        M_LUI(REG_ITMP3,hi);
-                                       M_LADD_IMM(REG_ITMP3,lo,REG_ITMP3);
+                                       M_AADD_IMM(REG_ITMP3,lo,REG_ITMP3);
                                        M_RET(REG_RA);
-                                       M_LADD(REG_ITMP3,REG_SP,REG_SP);            /* delay slot */
+                                       M_AADD(REG_ITMP3,REG_SP,REG_SP);            /* delay slot */
                                }
 
                        } else {
@@ -2676,15 +2937,14 @@ nowperformreturn:
 
                case ICMD_TABLESWITCH:  /* ..., index ==> ...                         */
                        {
-                       s4 i, l, *s4ptr;
-                       void **tptr;
+                       s4 i, l;
+                       branch_target_t *table;
 
-                       tptr = iptr->dst.table;
+                       table = iptr->dst.table;
+
+                       l = iptr->sx.s23.s2.tablelow;
+                       i = iptr->sx.s23.s3.tablehigh;
 
-                       s4ptr = iptr->val.a;
-                       l = s4ptr[1];                          /* low     */
-                       i = s4ptr[2];                          /* high    */
-                       
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        if (l == 0)
                                {M_INTMOVE(s1, REG_ITMP1);}
@@ -2695,29 +2955,28 @@ nowperformreturn:
                                ICONST(REG_ITMP2, l);
                                M_ISUB(s1, REG_ITMP2, REG_ITMP1);
                                }
+
+                       /* number of targets */
                        i = i - l + 1;
 
                        /* range check */
 
                        M_CMPULT_IMM(REG_ITMP1, i, REG_ITMP2);
-                       M_BEQZ(REG_ITMP2, 0);
-                       codegen_addreference(cd, (basicblock *) tptr[0]);
-                       M_ASLL_IMM(REG_ITMP1, POINTERSHIFT, REG_ITMP1);      /* delay slot*/
+                       emit_beqz(cd, table[0].block, REG_ITMP2);
 
                        /* build jump table top down and use address of lowest entry */
 
-                       /* s4ptr += 3 + i; */
-                       tptr += i;
+                       table += i;
 
                        while (--i >= 0) {
-                               /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
-                               dseg_addtarget(cd, (basicblock *) tptr[0]); 
-                               --tptr;
-                               }
+                               dseg_add_target(cd, table->block); 
+                               --table;
+                       }
                        }
 
-                       /* length of dataseg after last dseg_addtarget is used by load */
+                       /* length of dataseg after last dseg_add_target is used by load */
 
+                       M_ASLL_IMM(REG_ITMP1, POINTERSHIFT, REG_ITMP1);
                        M_AADD(REG_ITMP1, REG_PV, REG_ITMP2);
                        M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
                        M_JMP(REG_ITMP2);
@@ -2728,32 +2987,23 @@ nowperformreturn:
 
                case ICMD_LOOKUPSWITCH: /* ..., key ==> ...                           */
                        {
-                       s4 i, /*l, */val, *s4ptr;
-                       void **tptr;
+                       s4 i;
+                       lookup_target_t *lookup;
 
-                       tptr = iptr->dst.lookup;
+                       lookup = iptr->dst.lookup;
 
-                       s4ptr = iptr->val.a;
-                       /*l = s4ptr[0];*/                          /* default  */
-                       i = s4ptr[1];                          /* count    */
+                       i = iptr->sx.s23.s2.lookupcount;
                        
                        MCODECHECK((i<<2)+8);
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                       while (--i >= 0) {
-                               s4ptr += 2;
-                               ++tptr;
 
-                               val = s4ptr[0];
-                               ICONST(REG_ITMP2, val);
-                               M_BEQ(s1, REG_ITMP2, 0);
-                               codegen_addreference(cd, (basicblock *) tptr[0]); 
-                               M_NOP;
+                       while (--i >= 0) {
+                               ICONST(REG_ITMP2, lookup->value);
+                               emit_beq(cd, lookup->target.block, s1, REG_ITMP2);
+                               ++lookup;
                        }
 
-                       M_BR(0);
-                       tptr = iptr->dst.lookup;
-                       codegen_addreference(cd, (basicblock *) tptr[0]);
-                       M_NOP;
+                       emit_br(cd, iptr->sx.s23.s3.lookupdefault.block);
                        ALIGNCODENOP;
                        break;
                        }
@@ -2761,8 +3011,8 @@ nowperformreturn:
 
                case ICMD_BUILTIN:      /* ..., arg1 ==> ...                          */
 
-                       bte = iptr->val.a;
-                       md = bte->md;
+                       bte = iptr->sx.s23.s3.bte;
+                       md  = bte->md;
                        goto gen_method;
 
                case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...            */
@@ -2771,12 +3021,16 @@ nowperformreturn:
                case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer    */
                case ICMD_INVOKEINTERFACE:
 
+                       REPLACEMENT_POINT_INVOKE(cd, iptr);
+
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               md = iptr->sx.s23.s3.um->methodref->parseddesc.md;
                                lm = NULL;
+                               um = iptr->sx.s23.s3.um;
+                               md = um->methodref->parseddesc.md;
                        }
                        else {
                                lm = iptr->sx.s23.s3.fmiref->p.method;
+                               um = NULL;
                                md = lm->parseddesc;
                        }
 
@@ -2787,165 +3041,186 @@ gen_method:
 
                        /* copy arguments to registers or stack location                  */
 
-                       for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
-                               if (src->varkind == ARGVAR)
+                       for (s3 = s3 - 1; s3 >= 0; s3--) {
+                               var = VAR(iptr->sx.s23.s2.args[s3]);
+                               d   = md->params[s3].regoff;
+
+                               if (var->flags & PREALLOC)
                                        continue;
-                               if (IS_INT_LNG_TYPE(src->type)) {
+
+                               if (IS_INT_LNG_TYPE(var->type)) {
+#if SIZEOF_VOID_P == 8
                                        if (!md->params[s3].inmemory) {
-                                               s1 = rd->argintregs[md->params[s3].regoff];
-                                               d = emit_load(jd, iptr, src, s1);
-                                               M_INTMOVE(d, s1);
-                                       else  {
-                                               d = emit_load(jd, iptr, src, REG_ITMP1);
-                                               M_LST(d, REG_SP, md->params[s3].regoff * 8);
+                                               s1 = emit_load(jd, iptr, var, d);
+                                               M_INTMOVE(s1, d);
+                                       }
+                                       else  {
+                                               s1 = emit_load(jd, iptr, var, REG_ITMP1);
+                                               M_LST(s1, REG_SP, d);
                                        }
+#else
+                                       if (!md->params[s3].inmemory) {
+                                               s1 = emit_load(jd, iptr, var, d);
 
-                               } else {
+                                               if (IS_2_WORD_TYPE(var->type))
+                                                       M_LNGMOVE(s1, d);
+                                               else
+                                                       M_INTMOVE(s1, d);
+                                       }
+                                       else {
+                                               if (IS_2_WORD_TYPE(var->type)) {
+                                                       s1 = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
+                                                       M_LST(s1, REG_SP, d);
+                                               }
+                                               else {
+                                                       s1 = emit_load(jd, iptr, var, REG_ITMP1);
+                                                       M_IST(s1, REG_SP, d);
+                                               }
+                                       }
+#endif
+                               }
+                               else {
                                        if (!md->params[s3].inmemory) {
-                                               s1 = rd->argfltregs[md->params[s3].regoff];
-                                               d = emit_load(jd, iptr, src, s1);
-                                               if (IS_2_WORD_TYPE(src->type))
-                                                       M_DMOV(d, s1);
+                                               s1 = emit_load(jd, iptr, var, d);
+                                               if (IS_2_WORD_TYPE(var->type))
+                                                       M_DBLMOVE(s1, d);
                                                else
-                                                       M_FMOV(d, s1);
-
-                                       else {
-                                               d = emit_load(jd, iptr, src, REG_FTMP1);
-                                               if (IS_2_WORD_TYPE(src->type))
-                                                       M_DST(d, REG_SP, md->params[s3].regoff * 8);
+                                                       M_FLTMOVE(s1, d);
+                                       }
+                                       else {
+                                               s1 = emit_load(jd, iptr, var, REG_FTMP1);
+                                               if (IS_2_WORD_TYPE(var->type))
+                                                       M_DST(s1, REG_SP, d);
                                                else
-                                                       M_FST(d, REG_SP, md->params[s3].regoff * 8);
+                                                       M_FST(s1, REG_SP, d);
                                        }
                                }
                        }
 
                        switch (iptr->opc) {
                        case ICMD_BUILTIN:
-                               disp = dseg_addaddress(cd, bte->fp);
-                               d = md->returntype.type;
+                               disp = dseg_add_functionptr(cd, bte->fp);
 
                                M_ALD(REG_ITMP3, REG_PV, disp);  /* built-in-function pointer */
+
+                               /* generate the actual call */
+
+                               /* TWISTI: i actually don't know the reason for using
+                                  REG_ITMP3 here instead of REG_PV. */
+
                                M_JSR(REG_RA, REG_ITMP3);
                                M_NOP;
+                               REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, -disp);
 
-
-                               if (INSTRUCTION_MUST_CHECK(iptr)) {
-                                       M_BEQZ(REG_RESULT, 0);
-                                       codegen_add_fillinstacktrace_ref(cd);
-                                       M_NOP;
-                               }
+                               emit_exception_check(cd, iptr);
                                break;
 
                        case ICMD_INVOKESPECIAL:
-                               M_BEQZ(rd->argintregs[0], 0);
-                               codegen_add_nullpointerexception_ref(cd);
-                               M_NOP;
+                               emit_nullpointer_check(cd, iptr, REG_A0);
                                /* fall through */
 
                        case ICMD_INVOKESTATIC:
                                if (lm == NULL) {
-                                       unresolved_method *um = iptr->sx.s23.s3.um;
-
-                                       disp = dseg_addaddress(cd, NULL);
-
-                                       codegen_addpatchref(cd, PATCHER_invokestatic_special,
-                                                                               um, disp);
-
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       disp = dseg_add_unique_address(cd, um);
 
-                                       d = um->methodref->parseddesc.md->returntype.type;
-
-                               } else {
-                                       disp = dseg_addaddress(cd, lm->stubroutine);
-                                       d = lm->parseddesc->returntype.type;
+                                       patcher_add_patch_ref(jd, PATCHER_invokestatic_special, um,
+                                                                                 disp);
                                }
+                               else
+                                       disp = dseg_add_address(cd, lm->stubroutine);
 
                                M_ALD(REG_PV, REG_PV, disp);          /* method pointer in pv */
+
+                               /* generate the actual call */
+
                                M_JSR(REG_RA, REG_PV);
                                M_NOP;
+                               REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEVIRTUAL:
-                               gen_nullptr_check(rd->argintregs[0]);
+                               emit_nullpointer_check(cd, iptr, REG_A0);
 
                                if (lm == NULL) {
-                                       unresolved_method *um = iptr->sx.s23.s3.um;
-
-                                       codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
-
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
 
                                        s1 = 0;
-                                       d = um->methodref->parseddesc.md->returntype.type;
-
-                               } else {
+                               }
+                               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));
+                               /* implicit null-pointer check */
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, s1);
+
+                               /* generate the actual call */
+
                                M_JSR(REG_RA, REG_PV);
                                M_NOP;
+                               REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEINTERFACE:
-                               gen_nullptr_check(rd->argintregs[0]);
+                               emit_nullpointer_check(cd, iptr, REG_A0);
 
                                if (lm == NULL) {
-                                       unresolved_method *um = iptr->sx.s23.s3.um;
-
-                                       codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
-
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
 
                                        s1 = 0;
                                        s2 = 0;
-                                       d = um->methodref->parseddesc.md->returntype.type;
-
-                               } else {
+                               }
+                               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));
+                               /* implicit null-pointer check */
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
                                M_ALD(REG_PV, REG_METHODPTR, s2);
+
+                               /* generate the actual call */
+
                                M_JSR(REG_RA, REG_PV);
                                M_NOP;
+                               REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, -disp);
                                break;
                        }
 
-                       /* d contains return type */
+                       /* store return value */
+
+                       d = md->returntype.type;
 
                        if (d != TYPE_VOID) {
-                               if (IS_INT_LNG_TYPE(iptr->dst->type)) {
+                               if (IS_INT_LNG_TYPE(d)) {
+#if SIZEOF_VOID_P == 8
                                        s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
                                        M_INTMOVE(REG_RESULT, s1);
-                               } else {
+#else
+                                       if (IS_2_WORD_TYPE(d)) {
+                                               s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT_PACKED);
+                                               M_LNGMOVE(REG_RESULT_PACKED, s1);
+                                       }
+                                       else {
+                                               s1 = codegen_reg_of_dst(jd, iptr, REG_RESULT);
+                                               M_INTMOVE(REG_RESULT, s1);
+                                       }
+#endif
+                               }
+                               else {
                                        s1 = codegen_reg_of_dst(jd, iptr, REG_FRESULT);
-                                       if (IS_2_WORD_TYPE(iptr->dst->type))
+                                       if (IS_2_WORD_TYPE(d))
                                                M_DMOV(REG_FRESULT, s1);
                                        else
                                                M_FMOV(REG_FRESULT, s1);
@@ -2956,140 +3231,95 @@ gen_method:
 
 
                case ICMD_CHECKCAST:  /* ..., objectref ==> ..., objectref            */
-                                     /* 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));
-                        */
 
                        if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
                                classinfo *super;
-                               vftbl_t   *supervftbl;
                                s4         superindex;
 
-                               super = iptr->sx.s23.s3.c.cls;
-
-                               if (super == NULL) {
+                               if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
+                                       super      = NULL;
                                        superindex = 0;
-                                       supervftbl = NULL;
                                }
                                else {
+                                       super      = iptr->sx.s23.s3.c.cls;
                                        superindex = super->index;
-                                       supervftbl = super->vftbl;
                                }
                        
-#if defined(ENABLE_THREADS)
-                               codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+                               if ((super == NULL) || !(super->flags & ACC_INTERFACE))
+                                       CODEGEN_CRITICAL_SECTION_NEW;
 
                                s1 = emit_load_s1(jd, iptr, REG_ITMP1);
 
-                               /* calculate interface checkcast code size */
-
-                               s2 = 8;
-                               if (super == NULL)
-                                       s2 += (opt_showdisassemble ? 2 : 0);
-
-                               /* calculate class checkcast code size */
-
-                               s3 = 10 /* 10 + (s1 == REG_ITMP1) */;
-                               if (super == NULL)
-                                       s3 += (opt_showdisassemble ? 2 : 0);
-
                                /* if class is not resolved, check which code to call */
 
                                if (super == NULL) {
-                                       M_BEQZ(s1, 5 + (opt_showdisassemble ? 2 : 0) + s2 + 2 + s3);
-                                       M_NOP;
-
-                                       disp = dseg_adds4(cd, 0);                 /* super->flags */
+                                       emit_label_beqz(cd, BRANCH_LABEL_1, s1);
 
-                                       codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
-                                                                               iptr->sx.s23.s3.c.ref,
-                                                                               disp);
+                                       cr   = iptr->sx.s23.s3.c.ref;
+                                       disp = dseg_add_unique_s4(cd, 0);         /* super->flags */
 
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
+                                                                                 cr, disp);
 
-                                       /* XXX TWISTI M_ILD can be 2 instructions long (jump offset) */
                                        M_ILD(REG_ITMP2, REG_PV, disp);
                                        M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
-                                       M_BEQZ(REG_ITMP2, 1 + s2 + 2);
-                                       M_NOP;
+                                       emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP2);
                                }
 
                                /* interface checkcast code */
 
                                if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
-                                       if (super != NULL) {
-                                               M_BEQZ(s1, 1 + s2);
-                                               M_NOP;
+                                       if (super == NULL) {
+                                               cr = iptr->sx.s23.s3.c.ref;
+
+                                               patcher_add_patch_ref(jd, PATCHER_checkcast_interface,
+                                                                                         cr, 0);
                                        }
                                        else {
-                                               codegen_addpatchref(cd,
-                                                                                       PATCHER_checkcast_instanceof_interface,
-                                                                                       iptr->sx.s23.s3.c.ref,
-                                                                                       0);
-
-                                               if (opt_showdisassemble) {
-                                                       M_NOP; M_NOP;
-                                               }
+                                               emit_label_beqz(cd, BRANCH_LABEL_3, s1);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
-                                       M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
+                                       M_ILD(REG_ITMP3, REG_ITMP2,
+                                                 OFFSET(vftbl_t, interfacetablelength));
                                        M_IADD_IMM(REG_ITMP3, -superindex, REG_ITMP3);
-                                       M_BLEZ(REG_ITMP3, 0);
-                                       codegen_add_classcastexception_ref(cd, s1);
-                                       M_NOP;
+                                       emit_classcast_check(cd, iptr, ICMD_IFLE, REG_ITMP3, s1);
+
                                        M_ALD(REG_ITMP3, REG_ITMP2,
                                                  OFFSET(vftbl_t, interfacetable[0]) -
                                                  superindex * sizeof(methodptr*));
-                                       M_BEQZ(REG_ITMP3, 0);
-                                       codegen_add_classcastexception_ref(cd, s1);
-                                       M_NOP;
+                                       emit_classcast_check(cd, iptr, ICMD_IFEQ, REG_ITMP3, s1);
 
-                                       if (super == NULL) {
-                                               M_BR(1 + s3);
-                                               M_NOP;
-                                       }
+                                       if (super == NULL)
+                                               emit_label_br(cd, BRANCH_LABEL_4);
+                                       else
+                                               emit_label(cd, BRANCH_LABEL_3);
                                }
 
                                /* class checkcast code */
 
                                if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
-                                       disp = dseg_addaddress(cd, (void *) supervftbl);
+                                       if (super == NULL) {
+                                               emit_label(cd, BRANCH_LABEL_2);
+
+                                               cr   = iptr->sx.s23.s3.c.ref;
+                                               disp = dseg_add_unique_address(cd, NULL);
 
-                                       if (super != NULL) {
-                                               M_BEQZ(s1, 1 + s3);
-                                               M_NOP;
+                                               patcher_add_patch_ref(jd,
+                                                                                         PATCHER_resolve_classref_to_vftbl,
+                                                                                         cr, disp);
                                        }
                                        else {
-                                               codegen_addpatchref(cd,
-                                                                                       PATCHER_checkcast_instanceof_class,
-                                                                                       iptr->sx.s23.s3.c.ref,
-                                                                                       disp);
+                                               disp = dseg_add_address(cd, super->vftbl);
 
-                                               if (opt_showdisassemble) {
-                                                       M_NOP; M_NOP;
-                                               }
+                                               emit_label_beqz(cd, BRANCH_LABEL_5, s1);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ALD(REG_ITMP3, REG_PV, disp);
-#if defined(ENABLE_THREADS)
-                                       codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
+                                       CODEGEN_CRITICAL_SECTION_START;
+
                                        M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                        /*                              if (s1 != REG_ITMP1) { */
                                        /*                                      M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
@@ -3103,44 +3333,48 @@ gen_method:
                                        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(ENABLE_THREADS)
-                                       codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
+                                       CODEGEN_CRITICAL_SECTION_END;
+
                                        /*                              } */
                                        M_CMPULT(REG_ITMP3, REG_ITMP2, REG_ITMP3);
-                                       M_BNEZ(REG_ITMP3, 0);
-                                       codegen_add_classcastexception_ref(cd, s1);
-                                       M_NOP;
+                                       emit_classcast_check(cd, iptr, ICMD_IFNE, REG_ITMP3, s1);
+
+                                       if (super != NULL)
+                                               emit_label(cd, BRANCH_LABEL_5);
+                               }
+
+                               if (super == NULL) {
+                                       emit_label(cd, BRANCH_LABEL_1);
+                                       emit_label(cd, BRANCH_LABEL_4);
                                }
 
                                d = codegen_reg_of_dst(jd, iptr, s1);
                        }
                        else {
-                               s1 = emit_load_s1(jd, iptr, rd->argintregs[0]);
-                               M_INTMOVE(s1, rd->argintregs[0]);
-
-                               disp = dseg_addaddress(cd, iptr->sx.s23.s3.c.cls);
+                               s1 = emit_load_s1(jd, iptr, REG_A0);
+                               M_INTMOVE(s1, REG_A0);
 
                                if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                                       codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
-                                                                               iptr->sx.s23.s3.c.ref,
-                                                                               disp);
+                                       cr   = iptr->sx.s23.s3.c.ref;
+                                       disp = dseg_add_unique_address(cd, NULL);
 
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       patcher_add_patch_ref(jd,
+                                                                                 PATCHER_resolve_classref_to_classinfo,
+                                                                                 cr, disp);
+                               }
+                               else {
+                                       disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
                                }
 
-                               M_ALD(rd->argintregs[1], REG_PV, disp);
-                               disp = dseg_addaddress(cd, BUILTIN_arraycheckcast);
+                               M_ALD(REG_A1, REG_PV, disp);
+                               disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
                                M_ALD(REG_ITMP3, REG_PV, disp);
                                M_JSR(REG_RA, REG_ITMP3);
                                M_NOP;
 
                                s1 = emit_load_s1(jd, iptr, REG_ITMP1);
-                               M_BEQZ(REG_RESULT, 0);
-                               codegen_add_classcastexception_ref(cd, s1);
-                               M_NOP;
+                               emit_classcast_check(cd, iptr, ICMD_IFEQ, REG_RESULT, s1);
 
                                d = codegen_reg_of_dst(jd, iptr, s1);
                        }
@@ -3150,103 +3384,67 @@ gen_method:
                        break;
 
                case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
-                                     /* 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));
-                        */
 
                        {
                        classinfo *super;
-                       vftbl_t   *supervftbl;
                        s4         superindex;
 
-                       super = (classinfo *) iptr->val.a;
+                       super = iptr->sx.s23.s3.c.cls;
 
-                       if (super == NULL) {
+                       if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
+                               super      = NULL;
                                superindex = 0;
-                               supervftbl = NULL;
                        }
                        else {
+                               super      = iptr->sx.s23.s3.c.cls;
                                superindex = super->index;
-                               supervftbl = super->vftbl;
                        }
                        
-#if defined(ENABLE_THREADS)
-                       codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+                       if ((super == NULL) || !(super->flags & ACC_INTERFACE))
+                               CODEGEN_CRITICAL_SECTION_NEW;
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
                        }
 
-                       /* calculate interface instanceof code size */
-
-                       s2 = 7;
-                       if (super == NULL)
-                               s2 += (opt_showdisassemble ? 2 : 0);
-
-                       /* calculate class instanceof code size */
-
-                       s3 = 8;
-                       if (super == NULL)
-                               s3 += (opt_showdisassemble ? 2 : 0);
-
                        M_CLR(d);
 
                        /* if class is not resolved, check which code to call */
 
                        if (super == NULL) {
-                               M_BEQZ(s1, 5 + (opt_showdisassemble ? 2 : 0) + s2 + 2 + s3);
-                               M_NOP;
+                               emit_label_beqz(cd, BRANCH_LABEL_1, s1);
 
-                               disp = dseg_adds4(cd, 0);                     /* super->flags */
+                               cr   = iptr->sx.s23.s3.c.ref;
+                               disp = dseg_add_unique_s4(cd, 0);             /* super->flags */
 
-                               codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
-                                                                       iptr->sx.s23.s3.c.ref, disp);
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
+                                                                         cr, disp);
 
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                               /* XXX TWISTI M_ILD can be 2 instructions long (jump offset) */
                                M_ILD(REG_ITMP3, REG_PV, disp);
                                M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
-                               M_BEQZ(REG_ITMP3, 1 + s2 + 2);
-                               M_NOP;
+                               emit_label_beqz(cd, BRANCH_LABEL_2, REG_ITMP3);
                        }
 
                        /* interface instanceof code */
 
                        if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
-                               if (super != NULL) {
-                                       M_BEQZ(s1, 1 + s2);
-                                       M_NOP;
+                               if (super == NULL) {
+                                       cr = iptr->sx.s23.s3.c.ref;
+
+                                       patcher_add_patch_ref(jd, PATCHER_instanceof_interface,
+                                                                                 cr, 0);
                                }
                                else {
-                                       codegen_addpatchref(cd,
-                                                                               PATCHER_checkcast_instanceof_interface,
-                                                                               iptr->sx.s23.s3.c.ref, 0);
-
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       emit_label_beqz(cd, BRANCH_LABEL_3, s1);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                               M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
+                               M_ILD(REG_ITMP3, REG_ITMP1,
+                                         OFFSET(vftbl_t, interfacetablelength));
                                M_IADD_IMM(REG_ITMP3, -superindex, REG_ITMP3);
                                M_BLEZ(REG_ITMP3, 3);
                                M_NOP;
@@ -3255,46 +3453,54 @@ gen_method:
                                          superindex * sizeof(methodptr*));
                                M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
 
-                               if (super == NULL) {
-                                       M_BR(1 + s3);
-                                       M_NOP;
-                               }
+                               if (super == NULL)
+                                       emit_label_br(cd, BRANCH_LABEL_4);
+                               else
+                                       emit_label(cd, BRANCH_LABEL_3);
                        }
 
                        /* class instanceof code */
 
                        if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
-                               disp = dseg_addaddress(cd, supervftbl);
+                               if (super == NULL) {
+                                       emit_label(cd, BRANCH_LABEL_2);
 
-                               if (super != NULL) {
-                                       M_BEQZ(s1, 1 + s3);
-                                       M_NOP;
+                                       cr   = iptr->sx.s23.s3.c.ref;
+                                       disp = dseg_add_unique_address(cd, NULL);
+
+                                       patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
+                                                                                 cr, disp);
                                }
                                else {
-                                       codegen_addpatchref(cd, PATCHER_checkcast_instanceof_class,
-                                                                               iptr->sx.s23.s3.c.ref,
-                                                                               disp);
+                                       disp = dseg_add_address(cd, super->vftbl);
 
-                                       if (opt_showdisassemble) {
-                                               M_NOP; M_NOP;
-                                       }
+                                       emit_label_beqz(cd, BRANCH_LABEL_5, s1);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_ITMP2, REG_PV, disp);
-#if defined(ENABLE_THREADS)
-                               codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
+                               CODEGEN_CRITICAL_SECTION_START;
+
                                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(ENABLE_THREADS)
-                               codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
+                               CODEGEN_CRITICAL_SECTION_END;
+
                                M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1); 
                                M_CMPULT(REG_ITMP2, REG_ITMP1, d);
                                M_XOR_IMM(d, 1, d);
+
+                               if (super != NULL)
+                                       emit_label(cd, BRANCH_LABEL_5);
                        }
+
+                       if (super == NULL) {
+                               emit_label(cd, BRANCH_LABEL_1);
+                               emit_label(cd, BRANCH_LABEL_4);
+                       }
+
                        emit_store_dst(jd, iptr, d);
                        }
                        break;
@@ -3305,53 +3511,59 @@ gen_method:
 
                        MCODECHECK((iptr->s1.argcount << 1) + 64);
 
-                       for (s1 = iptr->s1.argcount; --s1 >= 0; src = src->prev) {
+                       for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
+
+                               var = VAR(iptr->sx.s23.s2.args[s1]);
+
                                /* copy SAVEDVAR sizes to stack */
 
-                               if (src->varkind != ARGVAR) {
-                                       s2 = emit_load(jd, iptr, src, REG_ITMP1);
+                               if (!(var->flags & PREALLOC)) {
+                                       s2 = emit_load(jd, iptr, var, REG_ITMP1);
+#if SIZEOF_VOID_P == 8
                                        M_LST(s2, REG_SP, s1 * 8);
+#else
+                                       M_IST(s2, REG_SP, (s1 + 2) * 8);
+#endif
                                }
                        }
 
                        /* a0 = dimension count */
 
-                       ICONST(rd->argintregs[0], iptr->s1.argcount);
+                       ICONST(REG_A0, iptr->s1.argcount);
 
                        /* is patcher function set? */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               disp = dseg_addaddress(cd, NULL);
-
-                               codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
-                                                                       iptr->sx.s23.s3.c.ref, disp);
+                               cr   = iptr->sx.s23.s3.c.ref;
+                               disp = dseg_add_unique_address(cd, NULL);
 
-                               if (opt_showdisassemble) {
-                                       M_NOP; M_NOP;
-                               }
-
-                       } else {
-                               disp = dseg_addaddress(cd, iptr->sx.s23.s3.c.cls);
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
+                                                                         cr, disp);
+                       }
+                       else {
+                               disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
                        }
 
                        /* a1 = arraydescriptor */
 
-                       M_ALD(rd->argintregs[1], REG_PV, disp);
+                       M_ALD(REG_A1, REG_PV, disp);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
-                       M_INTMOVE(REG_SP, rd->argintregs[2]);
+#if SIZEOF_VOID_P == 8
+                       M_MOV(REG_SP, REG_A2);
+#else
+                       M_AADD_IMM(REG_SP, 4*4, REG_A2);
+#endif
 
-                       disp = dseg_addaddress(cd, BUILTIN_multianewarray);
+                       disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_JSR(REG_RA, REG_ITMP3);
                        M_NOP;
 
                        /* check for exception before result assignment */
 
-                       M_BEQZ(REG_RESULT, 0);
-                       codegen_add_fillinstacktrace_ref(cd);
-                       M_NOP;
+                       emit_exception_check(cd, iptr);
 
                        d = codegen_reg_of_dst(jd, iptr, REG_RESULT);
                        M_INTMOVE(REG_RESULT, d);
@@ -3359,49 +3571,14 @@ gen_method:
                        break;
 
                default:
-                       *exceptionptr = new_internalerror("Unknown ICMD %d", iptr->opc);
+                       exceptions_throw_internalerror("Unknown ICMD %d during code generation",
+                                                                                  iptr->opc);
                        return false;
        } /* switch */
                
        } /* for instruction */
                
-       /* copy values to interface registers */
-
-       src = bptr->outstack;
-       len = bptr->outdepth;
-       MCODECHECK(64+len);
-#if defined(ENABLE_LSRA)
-       if (!opt_lsra) 
-#endif
-       while (src) {
-               len--;
-               if ((src->varkind != STACKVAR)) {
-                       s2 = src->type;
-                       if (IS_FLT_DBL_TYPE(s2)) {
-                               s1 = emit_load(jd, iptr, src, REG_FTMP1);
-                               if (rd->interfaces[len][s2].flags & INMEMORY) {
-                                       if (IS_2_WORD_TYPE(s2))
-                                               M_DST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
-                                       else
-                                               M_FST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
-
-                               } else {
-                                       if (IS_2_WORD_TYPE(s2))
-                                               M_DMOV(s1, rd->interfaces[len][s2].regoff);
-                                       else
-                                               M_FMOV(s1, rd->interfaces[len][s2].regoff);
-                               }
-
-                       } else {
-                               s1 = emit_load(jd, iptr, src, REG_ITMP1);
-                               if (rd->interfaces[len][s2].flags & INMEMORY)
-                                       M_LST(s1, REG_SP, rd->interfaces[len][s2].regoff * 8);
-                               else
-                                       M_INTMOVE(s1, rd->interfaces[len][s2].regoff);
-                       }
-               }
-               src = src->prev;
-       }
+       MCODECHECK(64); /* XXX require smaller number? */
 
        /* At the end of a basic block we may have to append some nops,
           because the patcher stub calling code might be longer than the
@@ -3418,13 +3595,9 @@ gen_method:
 
        dseg_createlinenumbertable(cd);
 
-       /* generate exception and patcher stubs */
-
-       emit_exception_stubs(jd);
-       emit_patcher_stubs(jd);
-       emit_replacement_stubs(jd);
+       /* generate traps */
 
-       codegen_finish(jd);
+       emit_patcher_traps(jd);
 
        /* everything's ok */
 
@@ -3432,94 +3605,54 @@ gen_method:
 }
 
 
-/* createcompilerstub **********************************************************
+/* codegen_emit_stub_compiler **************************************************
 
-   Creates a stub routine which calls the compiler.
+   Emits a stub routine which calls the compiler.
        
 *******************************************************************************/
 
-#define COMPILERSTUB_DATASIZE    3 * SIZEOF_VOID_P
-#define COMPILERSTUB_CODESIZE    4 * 4
-
-#define COMPILERSTUB_SIZE        COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
-
-
-u1 *createcompilerstub(methodinfo *m)
+void codegen_emit_stub_compiler(jitdata *jd)
 {
-       u1          *s;                     /* memory to hold the stub            */
-       ptrint      *d;
-       codeinfo    *code;
+       methodinfo  *m;
        codegendata *cd;
-       s4           dumpsize;
-
-       s = CNEW(u1, COMPILERSTUB_SIZE);
-
-       /* set data pointer and code pointer */
 
-       d = (ptrint *) s;
-       s = s + COMPILERSTUB_DATASIZE;
-
-       /* mark start of dump memory area */
-
-       dumpsize = dump_size();
-
-       cd = DNEW(codegendata);
-       cd->mcodeptr = s;
-
-       /* Store the codeinfo pointer in the same place as in the
-          methodheader for compiled methods. */
+       /* get required compiler data */
 
-       code = code_codeinfo_new(m);
+       m  = jd->m;
+       cd = jd->cd;
 
-       d[0] = (ptrint) asm_call_jit_compiler;
-       d[1] = (ptrint) m;
-       d[2] = (ptrint) code;
+       /* code for the stub */
 
        M_ALD_INTERN(REG_ITMP1, REG_PV, -2 * SIZEOF_VOID_P);  /* codeinfo pointer */
        M_ALD_INTERN(REG_PV, REG_PV, -3 * SIZEOF_VOID_P);  /* pointer to compiler */
        M_JMP(REG_PV);
        M_NOP;
-
-       md_cacheflush(s, (s4) (cd->mcodeptr - (u1 *) d));
-
-#if defined(ENABLE_STATISTICS)
-       if (opt_stat)
-               count_cstub_len += COMPILERSTUB_SIZE;
-#endif
-
-       /* release dump area */
-
-       dump_release(dumpsize);
-
-       return s;
 }
 
 
-/* createnativestub ************************************************************
+/* codegen_emit_stub_native ****************************************************
 
-   Creates a stub routine which calls a native method.
+   Emits a stub routine which calls a native method.
 
 *******************************************************************************/
 
-u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
+void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 {
-       methodinfo   *m;
-       codeinfo     *code;
-       codegendata  *cd;
-       registerdata *rd;
-       methoddesc   *md;
-       s4            nativeparams;
-       s4            i, j;                 /* count variables                    */
-       s4            t;
-       s4            s1, s2, disp;
-       s4            funcdisp;             /* displacement of the function       */
+       methodinfo  *m;
+       codeinfo    *code;
+       codegendata *cd;
+       methoddesc  *md;
+       s4           nativeparams;
+       s4           i, j;
+       s4           t;
+       s4           s1, s2, disp;
+       s4           funcdisp;              /* displacement of the function       */
 
        /* get required compiler data */
 
        m    = jd->m;
        code = jd->code;
        cd   = jd->cd;
-       rd   = jd->rd;
 
        /* initialize variables */
 
@@ -3533,27 +3666,32 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                sizeof(stackframeinfo) / SIZEOF_VOID_P +
                sizeof(localref_table) / SIZEOF_VOID_P +
                md->paramcount +                /* for saving arguments over calls    */
+#if SIZEOF_VOID_P == 4
+               5 +                             /* additional save space (MIPS32)     */
+#endif
                1 +                             /* for saving return address          */
                nmd->memuse;
 
+       /* adjust stackframe size for 16-byte alignment */
+
+       if (cd->stackframesize & 1)
+               cd->stackframesize++;
+
        /* create method header */
 
-#if SIZEOF_VOID_P == 4
-       (void) dseg_addaddress(cd, code);                      /* CodeinfoPointer */
-#endif
-       (void) dseg_addaddress(cd, code);                      /* MethodPointer   */
-       (void) dseg_adds4(cd, 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_add_unique_address(cd, code);              /* CodeinfoPointer */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
+       (void) dseg_add_unique_s4(cd, 0);                      /* IsSync          */
+       (void) dseg_add_unique_s4(cd, 0);                      /* IsLeaf          */
+       (void) dseg_add_unique_s4(cd, 0);                      /* IntSave         */
+       (void) dseg_add_unique_s4(cd, 0);                      /* FltSave         */
        (void) dseg_addlinenumbertablesize(cd);
-       (void) dseg_adds4(cd, 0);                              /* ExTableSize     */
+       (void) dseg_add_unique_s4(cd, 0);                      /* ExTableSize     */
 
        /* generate stub code */
 
        M_LDA(REG_SP, REG_SP, -cd->stackframesize * 8); /* build up stackframe    */
-       M_AST(REG_RA, REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P); /* store RA*/
+       M_AST(REG_RA, REG_SP, (cd->stackframesize - 1) * 8); /* store RA          */
 
 #if !defined(NDEBUG)
        if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
@@ -3562,57 +3700,100 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* get function address (this must happen before the stackframeinfo) */
 
-       funcdisp = dseg_addaddress(cd, f);
+       funcdisp = dseg_add_functionptr(cd, f);
 
 #if !defined(WITH_STATIC_CLASSPATH)
-       if (f == NULL) {
-               codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
-
-               if (opt_showdisassemble) {
-                       M_NOP; M_NOP;
-               }
-       }
+       if (f == NULL)
+               patcher_add_patch_ref(jd, PATCHER_resolve_native_function, m, funcdisp);
 #endif
 
        /* save integer and float argument registers */
 
+#if SIZEOF_VOID_P == 8
        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);
+               if (IS_INT_LNG_TYPE(md->params[i].type)) {
+                       s1 = md->params[i].regoff;
+                       M_AST(s1, REG_SP, j * 8);
                        j++;
                }
        }
+#else
+       for (i = 0, j = 5; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->params[i].type)) {
+                       if (!md->params[i].inmemory) {
+                               s1 = md->params[i].regoff;
+
+                               if (IS_2_WORD_TYPE(md->params[i].type))
+                                       M_LST(s1, REG_SP, j * 8);
+                               else
+                                       M_IST(s1, REG_SP, j * 8);
+
+                               j++;
+                       }
+               }
+       }
+#endif
 
        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);
+               if (IS_FLT_DBL_TYPE(md->params[i].type)) {
+                       s1 = md->params[i].regoff;
+
+                       if (IS_2_WORD_TYPE(md->params[i].type))
+                               M_DST(s1, REG_SP, j * 8);
+                       else
+                               M_FST(s1, REG_SP, j * 8);
+
                        j++;
                }
        }
 
        /* prepare data structures for native function call */
 
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P, rd->argintregs[0]);
-       M_MOV(REG_PV, rd->argintregs[1]);
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8, rd->argintregs[2]);
-       M_ALD(rd->argintregs[3], REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P);
-       disp = dseg_addaddress(cd, codegen_start_native_call);
+       M_AADD_IMM(REG_SP, (cd->stackframesize - 1) * 8, REG_A0);
+       M_MOV(REG_PV, REG_A1);
+       M_AADD_IMM(REG_SP, cd->stackframesize * 8, REG_A2);
+       M_ALD(REG_A3, REG_SP, (cd->stackframesize - 1) * 8);
+       disp = dseg_add_functionptr(cd, codegen_start_native_call);
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_JSR(REG_RA, REG_ITMP3);
        M_NOP; /* XXX fill me! */
 
        /* restore integer and float argument registers */
 
+#if SIZEOF_VOID_P == 8
        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);
+               if (IS_INT_LNG_TYPE(md->params[i].type)) {
+                       s1 = md->params[i].regoff;
+                       M_LLD(s1, REG_SP, j * 8);
                        j++;
                }
        }
+#else
+       for (i = 0, j = 5; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->params[i].type)) {
+                       if (!md->params[i].inmemory) {
+                               s1 = md->params[i].regoff;
+
+                               if (IS_2_WORD_TYPE(md->params[i].type))
+                                       M_LLD(s1, REG_SP, j * 8);
+                               else
+                                       M_ILD(s1, REG_SP, j * 8);
+
+                               j++;
+                       }
+               }
+       }
+#endif
 
        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);
+               if (IS_FLT_DBL_TYPE(md->params[i].type)) {
+                       s1 = md->params[i].regoff;
+
+                       if (IS_2_WORD_TYPE(md->params[i].type))
+                               M_DLD(s1, REG_SP, j * 8);
+                       else
+                               M_FLD(s1, REG_SP, j * 8);
+
                        j++;
                }
        }
@@ -3620,56 +3801,123 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
        /* copy or spill arguments to new locations */
 
        for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
-               t = md->paramtypes[i].type;
+               t = md->params[i].type;
 
                if (IS_INT_LNG_TYPE(t)) {
                        if (!md->params[i].inmemory) {
-                               s1 = rd->argintregs[md->params[i].regoff];
+                               s1 = md->params[i].regoff;
+                               s2 = nmd->params[j].regoff;
 
                                if (!nmd->params[j].inmemory) {
-                                       s2 = rd->argintregs[nmd->params[j].regoff];
+#if SIZEOF_VOID_P == 8
                                        M_INTMOVE(s1, s2);
-                               } else {
-                                       s2 = nmd->params[j].regoff;
-                                       M_AST(s1, REG_SP, s2 * 8);
+#else
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_LNGMOVE(s1, s2);
+                                       else
+                                               M_INTMOVE(s1, s2);
+#endif
+                               }
+                               else {
+#if SIZEOF_VOID_P == 8
+                                       M_LST(s1, REG_SP, s2);
+#else
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_LST(s1, REG_SP, s2);
+                                       else
+                                               M_IST(s1, REG_SP, s2);
+#endif
                                }
-
-                       } else {
-                               s1 = md->params[i].regoff + cd->stackframesize;
-                               s2 = nmd->params[j].regoff;
-                               M_ALD(REG_ITMP1, REG_SP, s1 * 8);
-                               M_AST(REG_ITMP1, REG_SP, s2 * 8);
                        }
+                       else {
+                               s1 = md->params[i].regoff + cd->stackframesize * 8;
+                               s2 = nmd->params[j].regoff;
 
-               } else {
+#if SIZEOF_VOID_P == 8
+                               M_LLD(REG_ITMP1, REG_SP, s1);
+                               M_LST(REG_ITMP1, REG_SP, s2);
+#else
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_LLD(REG_ITMP12_PACKED, REG_SP, s1);
+                                       M_LST(REG_ITMP12_PACKED, REG_SP, s2);
+                               }
+                               else {
+                                       M_ILD(REG_ITMP1, REG_SP, s1);
+                                       M_IST(REG_ITMP1, REG_SP, s2);
+                               }
+#endif
+                       }
+               }
+               else {
                        if (!md->params[i].inmemory) {
-                               s1 = rd->argfltregs[md->params[i].regoff];
+                               s1 = md->params[i].regoff;
+                               s2 = nmd->params[j].regoff;
 
                                if (!nmd->params[j].inmemory) {
-                                       s2 = rd->argfltregs[nmd->params[j].regoff];
+#if SIZEOF_VOID_P == 8
                                        if (IS_2_WORD_TYPE(t))
                                                M_DMOV(s1, s2);
                                        else
                                                M_FMOV(s1, s2);
+#else
+                                       /* On MIPS32 float arguments for native functions
+                                          can never be in float argument registers, since
+                                          the first argument is _always_ an integer
+                                          argument (JNIEnv) */
+
+                                       if (IS_2_WORD_TYPE(t)) {
+                                               /* double high/low order is endian
+                                                  independent: even numbered holds low
+                                                  32-bits, odd numbered high 32-bits */
+
+                                               M_MFC1(GET_LOW_REG(s2), s1);           /* low 32-bits */
+                                               M_MFC1(GET_HIGH_REG(s2), s1 + 1);     /* high 32-bits */
+                                       }
+                                       else
+                                               M_MFC1(s2, s1);
+#endif
+                               }
+                               else {
+#if SIZEOF_VOID_P == 8
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_DST(s1, REG_SP, s2);
+                                       else
+                                               M_FST(s1, REG_SP, s2);
+#else
+                                       /* s1 may have been originally in 2 int registers,
+                                          but was moved out by the native function
+                                          argument(s), just get low register */
 
-                               } else {
-                                       s2 = nmd->params[j].regoff;
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DST(s1, REG_SP, s2 * 8);
+                                               M_DST(GET_LOW_REG(s1), REG_SP, s2);
                                        else
-                                               M_FST(s1, REG_SP, s2 * 8);
+                                               M_FST(GET_LOW_REG(s1), REG_SP, s2);
+#endif
                                }
-
-                       else {
-                               s1 = md->params[i].regoff + cd->stackframesize;
+                       }
+                       else {
+                               s1 = md->params[i].regoff + cd->stackframesize * 8;
                                s2 = nmd->params[j].regoff;
+
+#if SIZEOF_VOID_P == 8
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DLD(REG_FTMP1, REG_SP, s1 * 8);
-                                       M_DST(REG_FTMP1, REG_SP, s2 * 8);
-                               } else {
-                                       M_FLD(REG_FTMP1, REG_SP, s1 * 8);
-                                       M_FST(REG_FTMP1, REG_SP, s2 * 8);
+                                       M_DLD(REG_FTMP1, REG_SP, s1);
+                                       M_DST(REG_FTMP1, REG_SP, s2);
+                               }
+                               else {
+                                       M_FLD(REG_FTMP1, REG_SP, s1);
+                                       M_FST(REG_FTMP1, REG_SP, s2);
+                               }
+#else
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_DLD(REG_FTMP1, REG_SP, s1);
+                                       M_DST(REG_FTMP1, REG_SP, s2);
+                               }
+                               else {
+                                       M_FLD(REG_FTMP1, REG_SP, s1);
+                                       M_FST(REG_FTMP1, REG_SP, s2);
                                }
+#endif
                        }
                }
        }
@@ -3677,14 +3925,14 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
        /* 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);
+               disp = dseg_add_address(cd, m->class);
+               M_ALD(REG_A1, REG_PV, disp);
        }
 
        /* put env into first argument register */
 
-       disp = dseg_addaddress(cd, _Jv_env);
-       M_ALD(rd->argintregs[0], REG_PV, disp);
+       disp = dseg_add_address(cd, _Jv_env);
+       M_ALD(REG_A0, REG_PV, disp);
 
        /* do the native function call */
 
@@ -3694,11 +3942,32 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* save return value */
 
-       if (md->returntype.type != TYPE_VOID) {
-               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);
+       switch (md->returntype.type) {
+#if SIZEOF_VOID_P == 8
+       case TYPE_INT:
+       case TYPE_LNG:
+       case TYPE_ADR:
+               M_LST(REG_RESULT, REG_SP, 0 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DST(REG_FRESULT, REG_SP, 0 * 8);
+               break;
+#else
+       case TYPE_INT:
+       case TYPE_ADR:
+               M_IST(REG_RESULT, REG_SP, 1*4 + 0 * 8);
+               break;
+       case TYPE_LNG:
+               M_LST(REG_RESULT_PACKED, REG_SP, 1*4 + 0 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DST(REG_FRESULT, REG_SP, 1*4 + 0 * 8);
+               break;
+#endif
+       case TYPE_VOID:
+               break;
        }
 
 #if !defined(NDEBUG)
@@ -3708,8 +3977,8 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* remove native stackframe info */
 
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P, rd->argintregs[0]);
-       disp = dseg_addaddress(cd, codegen_finish_native_call);
+       M_AADD_IMM(REG_SP, (cd->stackframesize - 1) * 8, REG_A0);
+       disp = dseg_add_functionptr(cd, codegen_finish_native_call);
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_JSR(REG_RA, REG_ITMP3);
        M_NOP; /* XXX fill me! */
@@ -3717,14 +3986,35 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* restore return value */
 
-       if (md->returntype.type != TYPE_VOID) {
-               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);
+       switch (md->returntype.type) {
+#if SIZEOF_VOID_P == 8
+       case TYPE_INT:
+       case TYPE_LNG:
+       case TYPE_ADR:
+               M_LLD(REG_RESULT, REG_SP, 0 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DLD(REG_FRESULT, REG_SP, 0 * 8);
+               break;
+#else
+       case TYPE_INT:
+       case TYPE_ADR:
+               M_ILD(REG_RESULT, REG_SP, 1*4 + 0 * 8);
+               break;
+       case TYPE_LNG:
+               M_LLD(REG_RESULT_PACKED, REG_SP, 1*4 + 0 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DLD(REG_FRESULT, REG_SP, 1*4 + 0 * 8);
+               break;
+#endif
+       case TYPE_VOID:
+               break;
        }
 
-       M_ALD(REG_RA, REG_SP, cd->stackframesize * 8 - SIZEOF_VOID_P); /* load RA */
+       M_ALD(REG_RA, REG_SP, (cd->stackframesize - 1) * 8); /* load RA           */
 
        /* check for exception */
 
@@ -3736,18 +4026,14 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* handle exception */
        
-       disp = dseg_addaddress(cd, asm_handle_nat_exception);
+       disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
        M_ALD(REG_ITMP3, REG_PV, disp);     /* load asm exception handler address */
        M_JMP(REG_ITMP3);                   /* jump to asm exception handler      */
        M_ASUB_IMM(REG_RA, 4, REG_ITMP2_XPC); /* get exception address (DELAY)    */
 
-       /* generate patcher stubs */
-
-       emit_patcher_stubs(jd);
-
-       codegen_finish(jd);
+       /* Generate patcher traps. */
 
-       return code->entrypoint;
+       emit_patcher_traps(jd);
 }