merged volatile memory barriers
[cacao.git] / src / vm / jit / mips / codegen.c
index cf207a347b1c06c9ed197af441edacd916ae05fb..5d323820121d98bcf922afe2e90416c52f141d0c 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/mips/codegen.c - machine code generator for MIPS
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 #include "vm/jit/emit-common.hpp"
 #include "vm/jit/jit.hpp"
 #include "vm/jit/linenumbertable.hpp"
+#include "vm/jit/parse.hpp"
 #include "vm/jit/patcher-common.hpp"
 #include "vm/jit/reg.h"
+#include "vm/jit/stacktrace.hpp"
 #include "vm/jit/trap.hpp"
 
-#if defined(ENABLE_LSRA)
-# include "vm/jit/allocator/lsra.h"
-#endif
-
-
-/* codegen_emit ****************************************************************
-
-   Generates machine code.
-
-*******************************************************************************/
-
-bool codegen_emit(jitdata *jd)
-{
-
-
-       savedregs_num = code_is_leafmethod(code) ? 0 : 1; /* space to save the RA */
-
-
-#if defined(ENABLE_THREADS)
-       /* space to save argument of monitor_enter */
-
-       if (checksync && code_is_synchronized(code)) {
-# if SIZEOF_VOID_P == 8
-               cd->stackframesize++;
-# else
-               rd->memuse++;
-               cd->stackframesize += 2;
-# endif
-       }
-#endif
-
-       /* keep stack 16-byte aligned */
-
-       if (cd->stackframesize & 1)
-               cd->stackframesize++;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
 /**
  * Generates machine code for the method prolog.
@@ -266,7 +217,7 @@ void codegen_emit_epilog(jitdata* jd)
        /* deallocate stack and return */
 
        if (cd->stackframesize) {
-               int32_t lo, hi;
+               int32_t lo, hi, disp;
 
                disp = cd->stackframesize * 8;
                lo = (short) (disp);
@@ -526,19 +477,19 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                                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);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
                                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);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                                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);
+                               ICONST(REG_ITMP1, iptr->sx.val.l & 0xffffffff);
                                s1 = emit_load_s1_low(jd, iptr, REG_ITMP3);
-                               M_IADD(s1, REG_ITMP2, GET_LOW_REG(d));
+                               M_IADD(s1, REG_ITMP1, GET_LOW_REG(d));
                                M_CMPULT(GET_LOW_REG(d), s1, REG_ITMP3);
-                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP2);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                                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));
@@ -583,7 +534,7 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                        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);
+                       s2 = emit_load_s2_low(jd, iptr, REG_ITMP2);
                        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
@@ -611,10 +562,10 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
 #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);
+                               s1 = emit_load_s1_low(jd, iptr, REG_ITMP1);
                                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);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                                M_ISUB_IMM(s1, 1, GET_HIGH_REG(d));
                                M_IADD(GET_HIGH_REG(d), REG_ITMP3, GET_HIGH_REG(d));
                        }
@@ -625,11 +576,11 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                                M_IADD(GET_HIGH_REG(s1), REG_ITMP3, GET_HIGH_REG(d));
                        }
                        else {
-                               ICONST(REG_ITMP2, iptr->sx.val.l & 0xffffffff);
+                               ICONST(REG_ITMP1, 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_ITMP1, GET_LOW_REG(d));
+                               M_CMPULT(s1, REG_ITMP1, REG_ITMP3);
+                               s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                                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));
@@ -829,12 +780,12 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                                M_AND_IMM(d, iptr->sx.val.i, d);
                        }
                        else {
-                               ICONST(REG_ITMP2, iptr->sx.val.i);
-                               M_AND(s1, REG_ITMP2, d);
+                               ICONST(REG_ITMP3, iptr->sx.val.i);
+                               M_AND(s1, REG_ITMP3, d);
                                M_BGEZ(s1, 4);
                                M_NOP;
                                M_ISUB(REG_ZERO, s1, d);
-                               M_AND(d, REG_ITMP2, d);
+                               M_AND(d, REG_ITMP3, d);
                        }
                        M_ISUB(REG_ZERO, d, d);
                        emit_store_dst(jd, iptr, d);
@@ -1059,7 +1010,7 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                        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);
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
                        M_AND(s1, s2, GET_HIGH_REG(d));
 #endif
@@ -1131,7 +1082,7 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                        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);
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
                        M_OR(s1, s2, GET_HIGH_REG(d));
 #endif
@@ -1203,7 +1154,7 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
                        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);
+                       s1 = emit_load_s1_high(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, REG_ITMP3);
                        M_XOR(s1, s2, GET_HIGH_REG(d));
 #endif
@@ -2698,19 +2649,6 @@ void codegen_emit_instruction(jitdata* jd, instruction* iptr)
 
 
 
-XXX
-                               else {
-                                       s1 = codegen_reg_of_dst(jd, iptr, REG_FRESULT);
-                                       if (IS_2_WORD_TYPE(d))
-                                               M_DMOV(REG_FRESULT, s1);
-                                       else
-                                               M_FMOV(REG_FRESULT, s1);
-                               }
-                               emit_store_dst(jd, iptr, s1);
-                       }
-                       break;
-
-
                case ICMD_CHECKCAST:  /* ..., objectref ==> ..., objectref            */
 
                        if (!(iptr->flags.bits & INS_FLAG_ARRAY)) {
@@ -2953,10 +2891,8 @@ XXX
 
                        if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
                                if (super == NULL) {
-                                       constant_classref * iptr->sx.s23.s3.c.ref;
-
                                        patcher_add_patch_ref(jd, PATCHER_instanceof_interface,
-                                                                                 cr, 0);
+                                                                                 iptr->sx.s23.s3.c.ref, 0);
                                }
                                else {
                                        emit_label_beqz(cd, BRANCH_LABEL_3, s1);