* Removed all Id tags.
[cacao.git] / src / vm / jit / m68k / codegen.c
index 89cb88588527d664b284c7f2007842ca22f167ba..ad266464d27fa167e4584f396879386b06ea4365 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen.c 7564 2007-03-23 23:36:17Z twisti $
-
 */
 
 
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 
 #include "md-abi.h"
 #include "md-os.h"
@@ -40,6 +39,7 @@
 
 #include "mm/memory.h"
 #include "native/jni.h"
+#include "native/localref.h"
 #include "native/native.h"
 
 #include "threads/lock-common.h"
@@ -109,41 +109,45 @@ bool codegen_emit(jitdata *jd)
 
                savedregs_num += (INT_SAV_CNT - rd->savintreguse);
                savedregs_num += (ADR_SAV_CNT - rd->savadrreguse);
-               savedregs_num += (FLT_SAV_CNT - rd->savfltreguse) * 2;
+               savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
 
                cd->stackframesize = rd->memuse + savedregs_num;
+       
+               /* we always add 2 stack slots.
+                * 1 word the lock word, which may be unused and resides @ rd->memuse * 8
+                * + 2 words to either save the return value for LOCK_monitor_exit @ rd->memuse * 8 + 8
+                * on the other hand we could use 2 words when a builtin returns a doulbe which are
+                * returned in %d0, %d1 and need to be stored onto the stack and read in used a fmovemd
+                * so we always _need_ at least 2 slots, and this keeps the code simple */
+               cd->stackframesize += 2;        
 
-               /* FIXME: we could need 2 words to move a double result, which gets
-                * passed in %d0, %d1 into a floating point register, this is of 
-                * course onyl true when not using ENABLE_SOFTFLOAT, so this could be
-                * optimized away, for now always use 2 more words. When optimizing watch
-                * the threading code, which stores the lock word, the offset would change */
-               cd->stackframesize += 2;
+               cd->stackframesize *= 8;        /* we use 8 byte stack slots */
 
+#if 0
 #if defined(ENABLE_THREADS)
                /* we need additional space to save argument of monitor_enter */
                if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                        if (IS_2_WORD_TYPE(m->parseddesc->returntype.type))     {
                                cd->stackframesize += 2;
                        } else  {
-                               cd->stackframesize ++;
+                               cd->stackframesize += 1;
                        }
                }
 #endif
-               
+#endif 
        
                /* create method header */
                (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
-               (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize       */
+               (void) dseg_add_unique_s4(cd, cd->stackframesize);         /* FrameSize       */
 #if defined(ENABLE_THREADS)
                if (checksync && (m->flags & ACC_SYNCHRONIZED))
-                       (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 4);/* IsSync         */
+                       (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8);/* IsSync         */
                else
 #endif
                (void) dseg_add_unique_s4(cd, 0);                      /* IsSync          */
                (void) dseg_add_unique_s4(cd, jd->isleafmethod);       /* IsLeaf          */
 
-               /* XXX we use the IntSAce a split field for the adr now */
+               /* XXX we use the IntSave a split field for the adr now */
                (void) dseg_add_unique_s4(cd, (ADR_SAV_CNT - rd->savadrreguse) << 16 | (INT_SAV_CNT - rd->savintreguse)); /* IntSave */
                (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
 
@@ -167,19 +171,19 @@ bool codegen_emit(jitdata *jd)
                emit_verbosecall_enter(jd);
 #endif
                /* create stack frame */
-               M_AADD_IMM(-(cd->stackframesize*4), REG_SP);
+               M_AADD_IMM(-(cd->stackframesize), REG_SP);
 
                /* save used callee saved registers */
                p = cd->stackframesize;
                for (i=INT_SAV_CNT-1; i>=rd->savintreguse; --i) {
-                       p--; M_IST(rd->savintregs[i], REG_SP, p*4);
+                       p-=8; M_IST(rd->savintregs[i], REG_SP, p);
                }
                for (i=ADR_SAV_CNT-1; i>=rd->savadrreguse; --i) {
-                       p--; M_AST(rd->savadrregs[i], REG_SP, p*4);
+                       p-=8; M_AST(rd->savadrregs[i], REG_SP, p);
                }
 #if !defined(ENABLE_SOFTFLOAT)
                for (i=FLT_SAV_CNT-1; i>=rd->savfltreguse; --i) {
-                       p-=2; M_DST(rd->savfltregs[i], REG_SP, p*4);    /* FIXME */
+                       p-=8; M_FSTORE(rd->savfltregs[i], REG_SP, p);
                }       
 #else
                assert(FLT_SAV_CNT == 0);
@@ -212,22 +216,17 @@ bool codegen_emit(jitdata *jd)
                        case TYPE_INT:
                                if (!IS_INMEMORY(var->flags)) {      /* stack arg -> register */
                                        if (IS_2_WORD_TYPE(t))  {
-                                               M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1 + 1) * 4);
+                                               M_LLD(var->vv.regoff, REG_SP, cd->stackframesize + s1 + 4);
                                        } else {
-                                               M_ILD(var->vv.regoff, REG_SP, (cd->stackframesize + s1 + 1) * 4);
+                                               M_ILD(var->vv.regoff, REG_SP, cd->stackframesize + s1 + 4);
                                        }
                                } else {                             /* stack arg -> spilled  */
-#if 1
-                                       M_ILD(REG_ITMP1, REG_SP, (cd->stackframesize + s1 + 1) * 4);
-                                       M_IST(REG_ITMP1, REG_SP, var->vv.regoff * 4);
+                                       M_ILD(REG_ITMP1, REG_SP, cd->stackframesize + s1 + 4);
+                                       M_IST(REG_ITMP1, REG_SP, var->vv.regoff);
                                        if (IS_2_WORD_TYPE(t)) {
-                                               M_ILD(REG_ITMP1, REG_SP, (cd->stackframesize + s1 + 1) * 4 + 4);
-                                               M_IST(REG_ITMP1, REG_SP, var->vv.regoff * 4 + 4);
+                                               M_ILD(REG_ITMP1, REG_SP, cd->stackframesize  + s1 + 4 + 4);
+                                               M_IST(REG_ITMP1, REG_SP, var->vv.regoff + 4);
                                        }
-#else
-                                       /* Reuse Memory Position on Caller Stack */
-                                       var->vv.regoff = cd->stackframesize + s1;
-#endif
                                } 
                                break;
 #if !defined(ENABLE_SOFTFLOAT)
@@ -235,37 +234,27 @@ bool codegen_emit(jitdata *jd)
                        case TYPE_DBL:
                                if (!IS_INMEMORY(var->flags)) {      /* stack-arg -> register */
                                        if (IS_2_WORD_TYPE(t))  {
-                                               M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1 + 1) * 4);
+                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize + s1 + 4);
                                        } else {
-                                               M_FLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1 + 1) * 4);
+                                               M_FLD(var->vv.regoff, REG_SP, cd->stackframesize + s1 + 4);
                                        }
                                } else {                             /* stack-arg -> spilled  */
-#if 1
                                        if (IS_2_WORD_TYPE(t)) {
-                                               M_DLD(REG_FTMP1, REG_SP, (cd->stackframesize + s1 + 1) * 4);
-                                               M_DST(REG_FTMP1, REG_SP, var->vv.regoff * 4);
+                                               M_DLD(REG_FTMP1, REG_SP, cd->stackframesize + s1 + 4);
+                                               M_DST(REG_FTMP1, REG_SP, var->vv.regoff);
                                        } else {
-                                               M_FLD(REG_FTMP1, REG_SP, (cd->stackframesize + s1 + 1) * 4);
-                                               M_FST(REG_FTMP1, REG_SP, var->vv.regoff * 4);
+                                               M_FLD(REG_FTMP1, REG_SP, cd->stackframesize + s1 + 4);
+                                               M_FST(REG_FTMP1, REG_SP, var->vv.regoff);
                                        }
-#else
-                                       /* Reuse Memory Position on Caller Stack */
-                                       var->vv.regoff = cd->stackframesize + s1;
-#endif
                                }
                                break;
 #endif /* SOFTFLOAT */
                        case TYPE_ADR:
                                if (!IS_INMEMORY(var->flags)) {      /* stack-arg -> register */
-                                       M_ALD(var->vv.regoff, REG_SP, (cd->stackframesize + s1 + 1) * 4);
+                                       M_ALD(var->vv.regoff, REG_SP, cd->stackframesize + s1 + 4);
                                } else {                             /* stack-arg -> spilled  */
-#if 1
-                                       M_ALD(REG_ATMP1, REG_SP, (cd->stackframesize + s1 + 1) * 4);
-                                       M_AST(REG_ATMP1, REG_SP, var->vv.regoff * 4);
-#else
-                               /* Reuse Memory Position on Caller Stack */
-                               var->vv.regoff = cd->stackframesize + s1;
-#endif
+                                       M_ALD(REG_ATMP1, REG_SP, cd->stackframesize + s1 + 4);
+                                       M_AST(REG_ATMP1, REG_SP, var->vv.regoff);
                                }
                                break;
                        default: assert(0);
@@ -273,19 +262,19 @@ bool codegen_emit(jitdata *jd)
                } /* end for argument out of stack*/
 
 #if defined(ENABLE_THREADS)
-       /* call monitor_enter function */
+       /* call lock_monitor_enter function */
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                if (m->flags & ACC_STATIC)      {
                        M_AMOV_IMM((&m->class->object.header), REG_ATMP1);
                } else  {
                        /* for non-static case the first arg is the object */
-                       M_ALD(REG_ATMP1, REG_SP, cd->stackframesize*4 + 4);
+                       M_ALD(REG_ATMP1, REG_SP, cd->stackframesize + 4);
                        M_ATST(REG_ATMP1);
                        M_BNE(2);
                        M_TRAP(M68K_EXCEPTION_HARDWARE_NULLPOINTER);
                }
 
-               M_AST(REG_ATMP1, REG_SP, rd->memuse * 4 + 2*4);
+               M_AST(REG_ATMP1, REG_SP, rd->memuse * 8);
                M_AST(REG_ATMP1, REG_SP, 0 * 4);
                M_JSR_IMM(LOCK_monitor_enter);
        }
@@ -306,8 +295,35 @@ bool codegen_emit(jitdata *jd)
        /* branch resolving */
        codegen_resolve_branchrefs(cd, bptr);
 
+       /* handle replacement points */
+       REPLACEMENT_POINT_BLOCK_START(cd, bptr);
+
+#if defined(ENABLE_PROFILING)
+       assert(0);
+#endif
        /* FIXME there are still some constrcuts to copy in here */
 
+#if defined(ENABLE_LSRA)
+       assert(0);
+#endif
+
+       /* copy interface registers to their destination */
+       len = bptr->indepth;
+       MCODECHECK(64+len);
+
+       while (len > 0) {
+               len--;
+               var = VAR(bptr->invars[len]);
+               if ((len == bptr->indepth-1) && (bptr->type == BBTYPE_EXH)) {
+                       d = codegen_reg_of_var(0, var, REG_ATMP1_XPTR);
+                       M_ADRMOVE(REG_ATMP1_XPTR, d);
+                       emit_store(jd, NULL, var, d);
+               }
+               else {
+                       assert((var->flags & INOUT));
+               }
+       }
+
        /* walk through all instructions */
        len = bptr->icount;
        currentline = 0;
@@ -396,6 +412,76 @@ bool codegen_emit(jitdata *jd)
                        break;
 
 
+               /* some long operations *********************************************/
+               case ICMD_LADD:       /* ..., val1, val2  ==> ..., val1 + val2        */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_INTMOVE(s2, REG_ITMP1);
+                       M_IADD(s1, REG_ITMP1);                  /* low word */
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP3);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP2);
+                       M_INTMOVE(s2, REG_ITMP2);
+                       M_IADDX(s1, REG_ITMP2);                 /* high word */
+                       emit_store_dst(jd, iptr, d);
+                       break;
+                       
+               case ICMD_LADDCONST:  /* ..., value  ==> ..., value + constant        */
+                                     /* sx.val.l = constant                          */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       
+                       M_IMOV_IMM(iptr->sx.val.l >> 32, REG_ITMP3);
+
+                       s3 = iptr->sx.val.l & 0xffffffff;
+                       M_INTMOVE(s1, REG_ITMP1);
+                       M_IADD_IMM(s3, REG_ITMP1);              /* lower word in REG_ITMP1 now */
+
+                       M_IADDX(REG_ITMP3, REG_ITMP2);  /* high word in REG_ITMP2 now */
+                       M_LNGMOVE(REG_ITMP12_PACKED, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_LSUB:       /* ..., val1, val2  ==> ..., val1 - val2        */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_INTMOVE(s1, REG_ITMP1);
+                       M_ISUB(s2, REG_ITMP1);                  /* low word */
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
+                       M_INTMOVE(s1, REG_ITMP2);
+                       M_ISUBX(s2, REG_ITMP2);                 /* high word */
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_LSUBCONST:  /* ..., value  ==> ..., value - constant        */
+                                     /* sx.val.l = constant                          */
+                       s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       
+                       M_IMOV_IMM( (-iptr->sx.val.l) >> 32, REG_ITMP3);
+
+                       s3 = (-iptr->sx.val.l) & 0xffffffff;
+                       M_INTMOVE(s1, REG_ITMP1);
+                       M_IADD_IMM(s3, REG_ITMP1);              /* lower word in REG_ITMP1 now */
+
+                       M_IADDX(REG_ITMP3, REG_ITMP2);  /* high word in REG_ITMP2 now */
+                       M_LNGMOVE(REG_ITMP12_PACKED, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
+                       M_LNGMOVE(s1, REG_ITMP12_PACKED);
+                       M_INEG(GET_LOW_REG(REG_ITMP12_PACKED));
+                       M_INEGX(GET_HIGH_REG(REG_ITMP12_PACKED));
+                       M_LNGMOVE(REG_ITMP12_PACKED, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
 
                /* integer operations ************************************************/
                case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
@@ -408,16 +494,6 @@ bool codegen_emit(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
-#if 0
-               case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
-
-                       s1 = emit_load_s1(jd, iptr, REG_ITMP12_PACKED);
-                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP12_PACKED);
-                       M_SUBFIC(GET_LOW_REG(s1), 0, GET_LOW_REG(d));
-                       M_SUBFZE(GET_HIGH_REG(s1), GET_HIGH_REG(d));
-                       emit_store_dst(jd, iptr, d);
-                       break;
-#endif
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP3);
@@ -779,7 +855,147 @@ bool codegen_emit(jitdata *jd)
                        emit_store_dst(jd, iptr, d);
                        break;
 
+               /* floating point operations ******************************************/
+               #if !defined(ENABLE_SOFTFLOAT)
+               case ICMD_FCMPL:                /* ..., val1, val2  ==> ..., val1 fcmpl val2  */
+               case ICMD_DCMPL:
+                       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_IMOV_IMM(-1, d);
+                       M_FCMP(s1, s2);
+                       M_BFUN(14);     /* result is -1, branch to end */
+                       M_BFLT(10);     /* result is -1, branch to end */
+                       M_IMOV_IMM(0, d);
+                       M_BFEQ(4)       /* result is 0, branch to end */
+                       M_IMOV_IMM(1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FCMPG:                /* ..., val1, val2  ==> ..., val1 fcmpg val2  */
+               case ICMD_DCMPG:
+                       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_IMOV_IMM(1, d);
+                       M_FCMP(s1, s2);
+                       M_BFUN(16);     /* result is +1, branch to end */
+                       M_BFGT(14);     /* result is +1, branch to end */
+                       M_IMOV_IMM(0, d);
+                       M_BFEQ(8)       /* result is 0, branch to end */
+                       M_IMOV_IMM(-1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
 
+               case ICMD_FMUL:       /* ..., val1, val2  ==> ..., val1 * 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_FTMP2);
+                       M_FLTMOVE(s2, REG_FTMP2);
+                       M_FMUL(s1, REG_FTMP2);
+                       M_FLTMOVE(REG_FTMP2, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 * 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_FTMP2);
+                       M_DBLMOVE(s2, REG_FTMP2);
+                       M_DMUL(s1, REG_FTMP2);
+                       M_DBLMOVE(REG_FTMP2, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FDIV:       /* ..., val1, val2  ==> ..., val1 / 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_FTMP1);
+                       M_FLTMOVE(s1, REG_FTMP1);
+                       M_FDIV(s2, REG_FTMP1);
+                       M_FLTMOVE(REG_FTMP1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_DDIV:       /* ..., val1, val2  ==> ..., val1 / 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_FTMP1);
+                       M_DBLMOVE(s1, REG_FTMP1);
+                       M_DDIV(s2, REG_FTMP1);
+                       M_DBLMOVE(REG_FTMP1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FADD:       /* ..., val1, val2  ==> ..., val1 + 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_FTMP2);
+                       M_FLTMOVE(s2, REG_FTMP2);
+                       M_FADD(s1, REG_FTMP2);
+                       M_FLTMOVE(REG_FTMP2, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_DADD:       /* ..., val1, val2  ==> ..., val1 + 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_FTMP2);
+                       M_DBLMOVE(s2, REG_FTMP2);
+                       M_DADD(s1, REG_FTMP2);
+                       M_DBLMOVE(REG_FTMP2, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FSUB:       /* ..., val1, val2  ==> ..., val1 - 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_FTMP2);
+                       M_FLTMOVE(s1, REG_FTMP1);
+                       M_FSUB(s2, REG_FTMP1);
+                       M_FLTMOVE(REG_FTMP1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_DSUB:       /* ..., val1, val2  ==> ..., val1 - 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_FTMP2);
+                       M_DBLMOVE(s1, REG_FTMP1);
+                       M_DSUB(s2, REG_FTMP1);
+                       M_DBLMOVE(REG_FTMP1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_F2D:       /* ..., value  ==> ..., (double) value           */
+                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
+                       M_F2D(s1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_D2F:       /* ..., value  ==> ..., (float) value           */
+                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
+                       M_D2F(s1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
+                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
+                       M_FNEG(s1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
+                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
+                       d = codegen_reg_of_dst(jd, iptr, REG_FTMP2);
+                       M_DNEG(s1, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+               #endif
 
                /* load/store/copy/move operations ************************************/
 
@@ -899,21 +1115,27 @@ bool codegen_emit(jitdata *jd)
 
 
                /* MEMORY *************************************************************/
-               case ICMD_GETSTATIC:
-                       if (INSTRUCTION_IS_UNRESOLVED(iptr))    {
+
+               case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
+
+                       if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
                                uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
-                               codegen_addpatchref(cd, PATCHER_get_putstatic, uf, 0);
-                       } else  {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
+                               disp      = 0;
 
+                               codegen_addpatchref(cd, PATCHER_get_putstatic, uf, 0);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
+                               disp      = (intptr_t) fi->value;
+
                                if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_initialize_class, fi->class, 0);
+                                       codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+                                                                               0);
                                }
-
-                               disp = (ptrint) &(fi->value);
                        }
+
                        M_AMOV_IMM(disp, REG_ATMP1);
                        switch (fieldtype) {
 #if defined(ENABLE_SOFTFLOAT)
@@ -953,15 +1175,18 @@ bool codegen_emit(jitdata *jd)
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
                                uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
+                               disp      = 0;
 
                                codegen_addpatchref(cd, PATCHER_get_putstatic, uf, 0);
-                       } else {
+                       }
+                       else {
                                fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
-                               disp      = &(fi->value);
+                               disp      = (intptr_t) fi->value;
 
                                if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class))
-                                       codegen_addpatchref(cd, PATCHER_initialize_class, fi->class, 0);
+                                       codegen_addpatchref(cd, PATCHER_initialize_class, fi->class,
+                                                                               0);
                        }
                
                        M_AMOV_IMM(disp, REG_ATMP1);
@@ -1111,7 +1336,7 @@ bool codegen_emit(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ATMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        /* implicit null-pointer check */
-                       M_ILD(d, s1, OFFSET(java_arrayheader, size));
+                       M_ILD(d, s1, OFFSET(java_array_t, size));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1122,7 +1347,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_bytearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_bytearray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1139,7 +1364,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(1, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_chararray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_chararray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1156,7 +1381,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(1, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_shortarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_shortarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                
@@ -1174,7 +1399,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_intarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_intarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1190,7 +1415,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP1);
                        M_ISSL_IMM(3, REG_ITMP1);
-                       M_IADD_IMM(OFFSET(java_longarray, data[0]), REG_ITMP1);
+                       M_IADD_IMM(OFFSET(java_longarray_t, data[0]), REG_ITMP1);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP1, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1204,7 +1429,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_floatarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_floatarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1224,7 +1449,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(3, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_doublearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_doublearray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1245,7 +1470,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_objectarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_objectarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
        
@@ -1261,7 +1486,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_INTMOVE(s2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_bytearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_bytearray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1275,7 +1500,7 @@ bool codegen_emit(jitdata *jd)
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(1, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_chararray, data[0]), REG_ITMP2); 
+                       M_IADD_IMM(OFFSET(java_chararray_t, data[0]), REG_ITMP2); 
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1289,7 +1514,7 @@ bool codegen_emit(jitdata *jd)
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(1, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_shortarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_shortarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1303,7 +1528,7 @@ bool codegen_emit(jitdata *jd)
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_intarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_intarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1317,7 +1542,7 @@ bool codegen_emit(jitdata *jd)
 
                        M_INTMOVE(s2, REG_ITMP1);
                        M_ISSL_IMM(3, REG_ITMP1);
-                       M_IADD_IMM(OFFSET(java_longarray, data[0]), REG_ITMP1);
+                       M_IADD_IMM(OFFSET(java_longarray_t, data[0]), REG_ITMP1);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP1, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1331,7 +1556,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(2, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_floatarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_floatarray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1350,7 +1575,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_INTMOVE(s2, REG_ITMP2);
                        M_ISSL_IMM(3, REG_ITMP2);
-                       M_IADD_IMM(OFFSET(java_doublearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(OFFSET(java_doublearray_t, data[0]), REG_ITMP2);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP2, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1384,7 +1609,7 @@ bool codegen_emit(jitdata *jd)
                        s3 = emit_load_s3(jd, iptr, REG_ATMP2);
                        M_INTMOVE(s2, REG_ITMP1);
                        M_ISSL_IMM(2, REG_ITMP1);
-                       M_IADD_IMM(OFFSET(java_objectarray, data[0]), REG_ITMP1);
+                       M_IADD_IMM(OFFSET(java_objectarray_t, data[0]), REG_ITMP1);
                        M_ADRMOVE(s1, REG_ATMP1);
                        M_AADDINT(REG_ITMP1, REG_ATMP1);
                        /* implicit null-pointer check */
@@ -1434,27 +1659,27 @@ bool codegen_emit(jitdata *jd)
 #endif
                                        case TYPE_LNG:
                                                d = emit_load(jd, iptr, var, REG_ITMP12_PACKED);
-                                               M_LST(d, REG_SP, md->params[s3].regoff*4);
+                                               M_LST(d, REG_SP, md->params[s3].regoff);
                                                break;
 #if defined(ENABLE_SOFTFLOAT)
                                        case TYPE_FLT:
 #endif
                                        case TYPE_INT:
                                                d = emit_load(jd, iptr, var, REG_ITMP1);
-                                               M_IST(d, REG_SP, md->params[s3].regoff*4);
+                                               M_IST(d, REG_SP, md->params[s3].regoff);
                                                break;
                                        case TYPE_ADR:
                                                d = emit_load(jd, iptr, var, REG_ATMP1);
-                                               M_AST(d, REG_SP, md->params[s3].regoff*4);
+                                               M_AST(d, REG_SP, md->params[s3].regoff);
                                                break;
 #if !defined(ENABLE_SOFTFLOAT)
                                        case TYPE_FLT:
                                                d = emit_load(jd, iptr, var, REG_FTMP1);
-                                               M_FST(d, REG_SP, md->params[s3].regoff*4);
+                                               M_FST(d, REG_SP, md->params[s3].regoff);
                                                break;
                                        case TYPE_DBL:
                                                d = emit_load(jd, iptr, var, REG_FTMP1);
-                                               M_DST(d, REG_SP, md->params[s3].regoff*4);
+                                               M_DST(d, REG_SP, md->params[s3].regoff);
                                                break;
 #endif
                                        default:
@@ -1504,7 +1729,7 @@ bool codegen_emit(jitdata *jd)
                                        /* load object pointer (==argument 0) */
                                        M_ALD(REG_ATMP1, REG_SP, 0);
                                        /* implicit null-pointer check */
-                                       M_ALD(REG_METHODPTR, REG_ATMP1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_METHODPTR, REG_ATMP1, OFFSET(java_object_t, vftbl));
                                        M_ALD(REG_ATMP3, REG_METHODPTR, s1);
                                        /* generate the actual call */
                                        M_JSR(REG_ATMP3);
@@ -1523,7 +1748,7 @@ bool codegen_emit(jitdata *jd)
                                        M_ALD(REG_ATMP1, REG_SP, 0);
 
                                        /* implicit null-pointer check */
-                                       M_ALD(REG_METHODPTR, REG_ATMP1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_METHODPTR, REG_ATMP1, OFFSET(java_object_t, vftbl));
                                        M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
                                        M_ALD(REG_ATMP3, REG_METHODPTR, s2);
 
@@ -1562,14 +1787,26 @@ bool codegen_emit(jitdata *jd)
                                                M_INT2ADRMOVE(REG_RESULT, s1);
                                                break;
 #if !defined(ENABLE_SOFTFLOAT)
+                                       /*
+                                        *      for BUILTINS float values are returned in %d0,%d1
+                                        *      within cacao we use %fp0 for that.
+                                        */
                                        case TYPE_FLT:
                                                s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                                               M_INT2FLTMOVE(REG_FRESULT, s1);
+                                               if (iptr->opc == ICMD_BUILTIN)  {
+                                                       M_INT2FLTMOVE(REG_FRESULT, s1);
+                                               } else  {
+                                                       M_FLTMOVE(REG_FRESULT, s1);
+                                               }
                                                break;
                                        case TYPE_DBL:
                                                s1 = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
-                                               M_LST(REG_RESULT_PACKED, REG_SP, rd->memuse * 4);
-                                               M_DLD(s1, REG_SP, rd->memuse * 4);
+                                               if (iptr->opc == ICMD_BUILTIN)  {
+                                                       M_LST(REG_RESULT_PACKED, REG_SP, rd->memuse * 4 + 4);
+                                                       M_DLD(s1, REG_SP, rd->memuse * 4 + 4);
+                                               } else  {
+                                                       M_DBLMOVE(REG_FRESULT, s1);
+                                               }
                                                break;
 #endif
                                        default:
@@ -1608,7 +1845,6 @@ bool codegen_emit(jitdata *jd)
                case ICMD_DRETURN:
 #endif
                case ICMD_LRETURN:      /* ..., retvalue ==> ...                      */
-
                        REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_RESULT_PACKED);
                        M_LNGMOVE(s1, REG_RESULT_PACKED);
@@ -1616,12 +1852,17 @@ bool codegen_emit(jitdata *jd)
 
 #if !defined(ENABLE_SOFTFLOAT)
                case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
-               case ICMD_DRETURN:
-
                        REPLACEMENT_POINT_RETURN(cd, iptr);
                        s1 = emit_load_s1(jd, iptr, REG_FRESULT);
                        M_FLTMOVE(s1, REG_FRESULT);
                        goto nowperformreturn;
+
+               case ICMD_DRETURN:
+                       REPLACEMENT_POINT_RETURN(cd, iptr);
+                       s1 = emit_load_s1(jd, iptr, REG_FRESULT);
+                       M_DBLMOVE(s1, REG_FRESULT);
+                       goto nowperformreturn;
+
 #endif
 
                case ICMD_RETURN:      /* ...  ==> ...                                */
@@ -1642,7 +1883,7 @@ nowperformreturn:
 #if defined(ENABLE_THREADS)
                        /* call lock_monitor_exit */
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-                               M_ILD(REG_ITMP3, REG_SP, rd->memuse * 4 + 2*4);
+                               M_ILD(REG_ITMP3, REG_SP, rd->memuse * 8);
 
                                /* we need to save the proper return value */
                                /* we do not care for the long -> doubel convert space here */
@@ -1651,21 +1892,21 @@ nowperformreturn:
                                case ICMD_DRETURN:
 #endif
                                case ICMD_LRETURN:
-                                       M_LST(REG_RESULT_PACKED, REG_SP, rd->memuse * 4);
+                                       M_LST(REG_RESULT_PACKED, REG_SP, rd->memuse * 8 + 8);
                                        break;
 #if defined(ENABLE_SOFTFLOAT)
                                case ICMD_FRETURN:
 #endif
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
-                                       M_IST(REG_RESULT , REG_SP, rd->memuse * 4);
+                                       M_IST(REG_RESULT , REG_SP, rd->memuse * 8 + 8);
                                        break;
 #if !defined(ENABLE_SOFTFLOAT)
                                case ICMD_FRETURN:
-                                       M_FST(REG_FRESULT, REG_SP, rd->memuse * 4);
+                                       M_FST(REG_FRESULT, REG_SP, rd->memuse * 8 + 8);
                                        break;
                                case ICMD_DRETURN:
-                                       M_DST(REG_FRESULT, REG_SP, rd->memuse * 4);
+                                       M_DST(REG_FRESULT, REG_SP, rd->memuse * 8 + 8);
                                        break;
 #endif
                                }
@@ -1680,21 +1921,21 @@ nowperformreturn:
                                case ICMD_DRETURN:
 #endif
                                case ICMD_LRETURN:
-                                       M_LLD(REG_RESULT_PACKED, REG_SP, rd->memuse * 4);
+                                       M_LLD(REG_RESULT_PACKED, REG_SP, rd->memuse * 8 + 8);
                                        break;
 #if defined(ENABLE_SOFTFLOAT)
                                case ICMD_FRETURN:
 #endif
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
-                                       M_ILD(REG_RESULT , REG_SP, rd->memuse * 4);
+                                       M_ILD(REG_RESULT , REG_SP, rd->memuse * 8 + 8);
                                        break;
 #if !defined(ENABLE_SOFTFLOAT)
                                case ICMD_FRETURN:
-                                       M_FLD(REG_FRESULT, REG_SP, rd->memuse * 4);
+                                       M_FLD(REG_FRESULT, REG_SP, rd->memuse * 8 + 8);
                                        break;
                                case ICMD_DRETURN:
-                                       M_DLD(REG_FRESULT, REG_SP, rd->memuse * 4);
+                                       M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8 + 8);
                                        break;
 #endif
                                }
@@ -1715,18 +1956,18 @@ nowperformreturn:
                        /* restore saved registers                                        */
 
                        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
-                               p--; M_ILD(rd->savintregs[i], REG_SP, p * 4);
+                               p-=8; M_ILD(rd->savintregs[i], REG_SP, p);
                        }
                        for (i=ADR_SAV_CNT-1; i>=rd->savadrreguse; --i) {
-                               p--; M_ALD(rd->savadrregs[i], REG_SP, p*4);
+                               p-=8; M_ALD(rd->savadrregs[i], REG_SP, p);
                        }
 #if !defined(ENABLE_SOFTFLOAT)
                        for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
-                               p -= 2; M_DLD(rd->savfltregs[i], REG_SP, p * 4);
+                               p-=8; M_FLOAD(rd->savfltregs[i], REG_SP, p);
                        }
 #endif
                        /* deallocate stack                                               */
-                       M_AADD_IMM(cd->stackframesize*4, REG_SP);
+                       M_AADD_IMM(cd->stackframesize, REG_SP);
                        M_RET;
                        }
                        break;
@@ -1795,7 +2036,7 @@ nowperformreturn:
                                        emit_label_beq(cd, BRANCH_LABEL_3);
                                }
 
-                               M_ALD(REG_ATMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ATMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ILD(REG_ITMP3, REG_ATMP1, OFFSET(vftbl_t, interfacetablelength));
                                M_IADD_IMM(-superindex, REG_ITMP3);     /* -superindex may be patched patched */
                                M_ITST(REG_ITMP3);
@@ -1825,7 +2066,7 @@ nowperformreturn:
                                        emit_label_beq(cd, BRANCH_LABEL_5);
                                }
 
-                               M_ALD(REG_ATMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ATMP1, s1, OFFSET(java_object_t, vftbl));
 
                                CODEGEN_CRITICAL_SECTION_START;
 
@@ -1915,7 +2156,7 @@ nowperformreturn:
                                                emit_label_beq(cd, BRANCH_LABEL_3);
                                        }
 
-                                       M_ALD(REG_ATMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ATMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ILD(REG_ITMP3, REG_ATMP2, OFFSET(vftbl_t, interfacetablelength));
        
                                        M_IADD_IMM(-superindex, REG_ITMP3);     /* superindex patched */
@@ -1946,7 +2187,7 @@ nowperformreturn:
                                                emit_label_beq(cd, BRANCH_LABEL_5);
                                        }
 
-                                       M_ALD(REG_ATMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ATMP2, s1, OFFSET(java_object_t, vftbl));
 
                                        CODEGEN_CRITICAL_SECTION_START;
 
@@ -2114,8 +2355,21 @@ nowperformreturn:
                        exceptions_throw_internalerror("Unknown ICMD %d during code generation", iptr->opc);
                        return false;
        } /* switch */
-       M_TPF;
+       /* M_TPF; */ /* nop after each ICMD */
        } /* for each instruction */
+
+       /* 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
+          actual instruction. So codepatching does not change the
+          following block unintentionally. */
+
+       if (cd->mcodeptr < cd->lastmcodeptr) {
+               while (cd->mcodeptr < cd->lastmcodeptr) {
+                       M_NOP;
+               }
+       }
+
+
        } /* if (btpre->flags >= BBREACHED) */
        } /* for each basic block */
 
@@ -2123,7 +2377,6 @@ nowperformreturn:
 
        /* generate stubs */
        emit_patcher_stubs(jd);
-       REPLACEMENT_EMIT_STUBS(jd);
 
        return true;
 }
@@ -2182,10 +2435,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        cd->stackframesize =    sizeof(stackframeinfo) / SIZEOF_VOID_P +
                                sizeof(localref_table) / SIZEOF_VOID_P +
                                nmd->memuse +
-                       #if 0
-                               4 +                                             /* %d0,%d1,%a0,%a1*/
-                               2 * 2 +                                         /* %f0,%f1 */
-                       #endif
                                1 +                                             /* functionptr */
                                4;                                              /* args for codegen_start_native_call */
 
@@ -2219,17 +2468,6 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        M_AST(REG_ATMP2, REG_SP, 4 * 4);
 
-       /* save integer and float temp registers */
-       /*
-       M_IST(REG_D0, REG_SP, 4*4 + 2*8 + 3*4);
-       M_IST(REG_D1, REG_SP, 4*4 + 2*8 + 2*4);
-       M_AST(REG_A0, REG_SP, 4*4 + 2*8 + 1*4);
-       M_AST(REG_A1, REG_SP, 4*4 + 2*8 + 0*4);
-       */
-
-       /* TODO */
-       /* store %f0, %f1 */
-
        /* put arguments for codegen_start_native_call onto stack */
        /* void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra) */
        
@@ -2260,8 +2498,8 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
                /* all arguments via stack */
                assert(md->params[i].inmemory);                                         
 
-               s1 = (md->params[i].regoff + cd->stackframesize + 1) * 4;
-               s2 = nmd->params[j].regoff * 4;
+               s1 = md->params[i].regoff + cd->stackframesize * 4 + 4;
+               s2 = nmd->params[j].regoff;
 
                /* simply copy argument stack */
                M_ILD(REG_ITMP1, REG_SP, s1);
@@ -2288,25 +2526,18 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        switch (md->returntype.type)    {
                case TYPE_VOID: break;
 
-#if defined(ENABLE_SOFTFLOAT)
+               /* natives return float arguments in %d0, %d1, cacao expects them in %fp0 */
                case TYPE_DBL:
-#endif
                case TYPE_LNG:
                        M_IST(REG_D1, REG_SP, 2 * 4);
                        /* fall through */
 
-#if defined(ENABLE_SOFTFLOAT)
                case TYPE_FLT:
-#endif
                case TYPE_INT:
                case TYPE_ADR:
                        M_IST(REG_D0, REG_SP, 1 * 4);
                        break;
 
-#if !defined(ENABLE_SOFTFLOAT)
-               case TYPE_FLT:
-               case TYPE_DBL:  /* FIXME */
-#endif
                default: assert(0);
        }
        
@@ -2329,26 +2560,30 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        switch (md->returntype.type)    {
                case TYPE_VOID: break;
 
-#if defined(ENABLE_SOFTFLOAT)
                case TYPE_DBL:
-#endif
                case TYPE_LNG:
                        M_ILD(REG_D1, REG_SP, 2 * 4);
                        /* fall through */
-#if defined(ENABLE_SOFTFLOAT)
                case TYPE_FLT:
-#endif
                case TYPE_INT:
                case TYPE_ADR:
                        M_ILD(REG_D0, REG_SP, 1 * 4);
                        break;
 
+               default: assert(0);
+       }
 #if !defined(ENABLE_SOFTFLOAT)
+               /* additionally load values into floating points registers
+                * as cacao jit code expects them there */
+       switch (md->returntype.type)    {
                case TYPE_FLT:
-               case TYPE_DBL:  /* FIXME */
-#endif
-               default: assert(0);
+                       M_FLD(REG_D0, REG_SP, 1 * 4);
+                       break;
+               case TYPE_DBL:  
+                       M_DLD(REG_D0, REG_SP, 1 * 4);
+                       break;
        }
+#endif
        /* restore saved registers */
 
        M_AADD_IMM(cd->stackframesize*4, REG_SP);