* src/vm/jit/i386/codegen.c (codegen): Implemented inlining of synchronized
[cacao.git] / src / vm / jit / i386 / emitfuncs.c
index fbc3bd0917b835f89b696abbab294645d4f18174..9903ceef72bee778c09fd977c0649f57f5090dc2 100644 (file)
@@ -1,9 +1,9 @@
 /* vm/jit/i386/emitfuncs.c - i386 code emitter functions
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Christian Thalinger
 
-   $Id: emitfuncs.c 2316 2005-04-21 16:40:28Z twisti $
+   $Id: emitfuncs.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
+
+#include "config.h"
+#include "vm/types.h"
+
 #include "vm/statistics.h"
 #include "vm/jit/jit.h"
+#include "vm/jit/i386/md-abi.h"
 #include "vm/jit/i386/emitfuncs.h"
 #include "vm/jit/i386/codegen.h"
-#include "vm/jit/i386/types.h"
-
-#ifdef STATISTICS
-#define COUNT(a) (a)++
-#else
-#define COUNT(a)
-#endif
 
 
 void i386_emit_ialu(codegendata *cd, s4 alu_op, stackptr src, instruction *iptr)
@@ -48,60 +46,60 @@ void i386_emit_ialu(codegendata *cd, s4 alu_op, stackptr src, instruction *iptr)
        if (iptr->dst->flags & INMEMORY) {
                if ((src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->regoff == iptr->dst->regoff) {
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
 
                        } else if (src->prev->regoff == iptr->dst->regoff) {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
-                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 8, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
+                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 4, REG_ITMP1);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else if ((src->flags & INMEMORY) && !(src->prev->flags & INMEMORY)) {
                        if (src->regoff == iptr->dst->regoff) {
-                               i386_alu_reg_membase(cd, alu_op, src->prev->regoff, REG_SP, iptr->dst->regoff * 8);
+                               i386_alu_reg_membase(cd, alu_op, src->prev->regoff, REG_SP, iptr->dst->regoff * 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
                                i386_alu_reg_reg(cd, alu_op, src->prev->regoff, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else if (!(src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->prev->regoff == iptr->dst->regoff) {
-                               i386_alu_reg_membase(cd, alu_op, src->regoff, REG_SP, iptr->dst->regoff * 8);
+                               i386_alu_reg_membase(cd, alu_op, src->regoff, REG_SP, iptr->dst->regoff * 4);
                                                
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
                                i386_alu_reg_reg(cd, alu_op, src->regoff, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else {
-                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 8);
-                       i386_alu_reg_membase(cd, alu_op, src->regoff, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 4);
+                       i386_alu_reg_membase(cd, alu_op, src->regoff, REG_SP, iptr->dst->regoff * 4);
                }
 
        } else {
                if ((src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
-                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, iptr->dst->regoff);
-                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 8, iptr->dst->regoff);
+                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, iptr->dst->regoff);
+                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 4, iptr->dst->regoff);
 
                } else if ((src->flags & INMEMORY) && !(src->prev->flags & INMEMORY)) {
                        if (src->prev->regoff != iptr->dst->regoff)
                                i386_mov_reg_reg(cd, src->prev->regoff, iptr->dst->regoff);
 
-                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 8, iptr->dst->regoff);
+                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 4, iptr->dst->regoff);
 
                } else if (!(src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->regoff != iptr->dst->regoff)
                                i386_mov_reg_reg(cd, src->regoff, iptr->dst->regoff);
 
-                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->prev->regoff * 8, iptr->dst->regoff);
+                       i386_alu_membase_reg(cd, alu_op, REG_SP, src->prev->regoff * 4, iptr->dst->regoff);
 
                } else {
                        if (src->regoff == iptr->dst->regoff) {
@@ -123,22 +121,22 @@ void i386_emit_ialuconst(codegendata *cd, s4 alu_op, stackptr src, instruction *
        if (iptr->dst->flags & INMEMORY) {
                if (src->flags & INMEMORY) {
                        if (src->regoff == iptr->dst->regoff) {
-                               i386_alu_imm_membase(cd, alu_op, iptr->val.i, REG_SP, iptr->dst->regoff * 8);
+                               i386_alu_imm_membase(cd, alu_op, iptr->val.i, REG_SP, iptr->dst->regoff * 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
                                i386_alu_imm_reg(cd, alu_op, iptr->val.i, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else {
-                       i386_mov_reg_membase(cd, src->regoff, REG_SP, iptr->dst->regoff * 8);
-                       i386_alu_imm_membase(cd, alu_op, iptr->val.i, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_reg_membase(cd, src->regoff, REG_SP, iptr->dst->regoff * 4);
+                       i386_alu_imm_membase(cd, alu_op, iptr->val.i, REG_SP, iptr->dst->regoff * 4);
                }
 
        } else {
                if (src->flags & INMEMORY) {
-                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, iptr->dst->regoff);
+                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, iptr->dst->regoff);
                        i386_alu_imm_reg(cd, alu_op, iptr->val.i, iptr->dst->regoff);
 
                } else {
@@ -158,24 +156,24 @@ void i386_emit_lalu(codegendata *cd, s4 alu_op, stackptr src, instruction *iptr)
        if (iptr->dst->flags & INMEMORY) {
                if ((src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->regoff == iptr->dst->regoff) {
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8 + 4, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8 + 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4 + 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4 + 4);
 
                        } else if (src->prev->regoff == iptr->dst->regoff) {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8 + 4, REG_ITMP1);
-                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 8 + 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4 + 4, REG_ITMP1);
+                               i386_alu_reg_membase(cd, alu_op, REG_ITMP1, REG_SP, iptr->dst->regoff * 4 + 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
-                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 8, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8 + 4, REG_ITMP1);
-                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 8 + 4, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8 + 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
+                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 4, REG_ITMP1);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4 + 4, REG_ITMP1);
+                               i386_alu_membase_reg(cd, alu_op, REG_SP, src->regoff * 4 + 4, REG_ITMP1);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4 + 4);
                        }
                }
        }
@@ -187,16 +185,16 @@ void i386_emit_laluconst(codegendata *cd, s4 alu_op, stackptr src, instruction *
        if (iptr->dst->flags & INMEMORY) {
                if (src->flags & INMEMORY) {
                        if (src->regoff == iptr->dst->regoff) {
-                               i386_alu_imm_membase(cd, alu_op, iptr->val.l, REG_SP, iptr->dst->regoff * 8);
-                               i386_alu_imm_membase(cd, alu_op, iptr->val.l >> 32, REG_SP, iptr->dst->regoff * 8 + 4);
+                               i386_alu_imm_membase(cd, alu_op, iptr->val.l, REG_SP, iptr->dst->regoff * 4);
+                               i386_alu_imm_membase(cd, alu_op, iptr->val.l >> 32, REG_SP, iptr->dst->regoff * 4 + 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
                                i386_alu_imm_reg(cd, alu_op, iptr->val.l, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8 + 4, REG_ITMP1);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4 + 4, REG_ITMP1);
                                i386_alu_imm_reg(cd, alu_op, iptr->val.l >> 32, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8 + 4);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4 + 4);
                        }
                }
        }
@@ -208,53 +206,53 @@ void i386_emit_ishift(codegendata *cd, s4 shift_op, stackptr src, instruction *i
        if (iptr->dst->flags & INMEMORY) {
                if ((src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->prev->regoff == iptr->dst->regoff) {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, ECX);
-                               i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, ECX);
+                               i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 4);
 
                        } else {
-                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, ECX);
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, ECX);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
                                i386_shift_reg(cd, shift_op, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else if ((src->flags & INMEMORY) && !(src->prev->flags & INMEMORY)) {
-                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, ECX);
-                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 8);
-                       i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, ECX);
+                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 4);
+                       i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 4);
 
                } else if (!(src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
                        if (src->prev->regoff == iptr->dst->regoff) {
                                if (src->regoff != ECX)
                                        i386_mov_reg_reg(cd, src->regoff, ECX);
 
-                               i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 8);
+                               i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 4);
 
                        } else {        
                                if (src->regoff != ECX)
                                        i386_mov_reg_reg(cd, src->regoff, ECX);
 
-                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, REG_ITMP1);
+                               i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, REG_ITMP1);
                                i386_shift_reg(cd, shift_op, REG_ITMP1);
-                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                               i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                        }
 
                } else {
                        if (src->regoff != ECX)
                                i386_mov_reg_reg(cd, src->regoff, ECX);
 
-                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 8);
-                       i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_reg_membase(cd, src->prev->regoff, REG_SP, iptr->dst->regoff * 4);
+                       i386_shift_membase(cd, shift_op, REG_SP, iptr->dst->regoff * 4);
                }
 
        } else {
                if ((src->flags & INMEMORY) && (src->prev->flags & INMEMORY)) {
-                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, ECX);
-                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, iptr->dst->regoff);
+                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, ECX);
+                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, iptr->dst->regoff);
                        i386_shift_reg(cd, shift_op, iptr->dst->regoff);
 
                } else if ((src->flags & INMEMORY) && !(src->prev->flags & INMEMORY)) {
-                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, ECX);
+                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, ECX);
 
                        if (src->prev->regoff != iptr->dst->regoff)
                                i386_mov_reg_reg(cd, src->prev->regoff, iptr->dst->regoff);
@@ -265,7 +263,7 @@ void i386_emit_ishift(codegendata *cd, s4 shift_op, stackptr src, instruction *i
                        if (src->regoff != ECX)
                                i386_mov_reg_reg(cd, src->regoff, ECX);
 
-                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 8, iptr->dst->regoff);
+                       i386_mov_membase_reg(cd, REG_SP, src->prev->regoff * 4, iptr->dst->regoff);
                        i386_shift_reg(cd, shift_op, iptr->dst->regoff);
 
                } else {
@@ -285,21 +283,21 @@ void i386_emit_ishiftconst(codegendata *cd, s4 shift_op, stackptr src, instructi
 {
        if ((src->flags & INMEMORY) && (iptr->dst->flags & INMEMORY)) {
                if (src->regoff == iptr->dst->regoff) {
-                       i386_shift_imm_membase(cd, shift_op, iptr->val.i, REG_SP, iptr->dst->regoff * 8);
+                       i386_shift_imm_membase(cd, shift_op, iptr->val.i, REG_SP, iptr->dst->regoff * 4);
 
                } else {
-                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, REG_ITMP1);
+                       i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, REG_ITMP1);
                        i386_shift_imm_reg(cd, shift_op, iptr->val.i, REG_ITMP1);
-                       i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_reg_membase(cd, REG_ITMP1, REG_SP, iptr->dst->regoff * 4);
                }
 
        } else if ((src->flags & INMEMORY) && !(iptr->dst->flags & INMEMORY)) {
-               i386_mov_membase_reg(cd, REG_SP, src->regoff * 8, iptr->dst->regoff);
+               i386_mov_membase_reg(cd, REG_SP, src->regoff * 4, iptr->dst->regoff);
                i386_shift_imm_reg(cd, shift_op, iptr->val.i, iptr->dst->regoff);
                                
        } else if (!(src->flags & INMEMORY) && (iptr->dst->flags & INMEMORY)) {
-               i386_mov_reg_membase(cd, src->regoff, REG_SP, iptr->dst->regoff * 8);
-               i386_shift_imm_membase(cd, shift_op, iptr->val.i, REG_SP, iptr->dst->regoff * 8);
+               i386_mov_reg_membase(cd, src->regoff, REG_SP, iptr->dst->regoff * 4);
+               i386_shift_imm_membase(cd, shift_op, iptr->val.i, REG_SP, iptr->dst->regoff * 4);
 
        } else {
                if (src->regoff != iptr->dst->regoff)
@@ -316,26 +314,26 @@ void i386_emit_ifcc_iconst(codegendata *cd, s4 if_op, stackptr src, instruction
                s4 offset = 0;
 
                if (src->flags & INMEMORY) {
-                       i386_alu_imm_membase(cd, I386_CMP, 0, REG_SP, src->regoff * 8);
+                       i386_alu_imm_membase(cd, ALU_CMP, 0, REG_SP, src->regoff * 4);
 
                } else {
                        i386_test_reg_reg(cd, src->regoff, src->regoff);
                }
 
                offset += 7;
-               CALCOFFSETBYTES(offset, REG_SP, iptr->dst->regoff * 8);
+               CALCOFFSETBYTES(offset, REG_SP, iptr->dst->regoff * 4);
        
                i386_jcc(cd, if_op, offset + (iptr[1].opc == ICMD_ELSE_ICONST) ? 5 + offset : 0);
-               i386_mov_imm_membase(cd, iptr->val.i, REG_SP, iptr->dst->regoff * 8);
+               i386_mov_imm_membase(cd, iptr->val.i, REG_SP, iptr->dst->regoff * 4);
 
                if (iptr[1].opc == ICMD_ELSE_ICONST) {
                        i386_jmp_imm(cd, offset);
-                       i386_mov_imm_membase(cd, iptr[1].val.i, REG_SP, iptr->dst->regoff * 8);
+                       i386_mov_imm_membase(cd, iptr[1].val.i, REG_SP, iptr->dst->regoff * 4);
                }
 
        } else {
                if (src->flags & INMEMORY) {
-                       i386_alu_imm_membase(cd, I386_CMP, 0, REG_SP, src->regoff * 8);
+                       i386_alu_imm_membase(cd, ALU_CMP, 0, REG_SP, src->regoff * 4);
 
                } else {
                        i386_test_reg_reg(cd, src->regoff, src->regoff);
@@ -395,8 +393,6 @@ void i386_mov_membase32_reg(codegendata *cd, s4 basereg, s4 disp, s4 reg)
 {
        COUNT(count_mov_mem_reg);
        *(cd->mcodeptr++) = 0x8b;
-/*     i386_address_byte(2,(reg),(basereg)); */
-/*     i386_emit_imm32((disp)); */
        i386_emit_membase32((basereg),(disp),(reg));
 }
 
@@ -588,6 +584,14 @@ void i386_alu_imm_reg(codegendata *cd, s4 opc, s4 imm, s4 dreg)
 }
 
 
+void i386_alu_imm32_reg(codegendata *cd, s4 opc, s4 imm, s4 dreg)
+{
+       *(cd->mcodeptr++) = 0x81;
+       i386_emit_reg((opc),(dreg));
+       i386_emit_imm32((imm));
+}
+
+
 void i386_alu_imm_membase(codegendata *cd, s4 opc, s4 imm, s4 basereg, s4 disp)
 {
        if (i386_is_imm8(imm)) {