2006-01-03 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / inssel.brg
index 5a80eb367c8917b029fa04ad6e5c0270b9623e2f..ddeb206fb2deee101d2e13675f6618a7c0419b10 100644 (file)
                mono_bblock_add_inst (cfg->cbb, inst); \
        } while (0)
 
+#define MONO_EMIT_BIALU_MEMBASE(cfg,tree,op,dr,sr,basereg,offset) do { \
+                               tree->opcode = op; \
+                               tree->dreg = dr; \
+                               tree->sreg1 = sr; \
+                               tree->sreg2 = basereg; \
+                               tree->inst_offset = offset; \
+                               mono_bblock_add_inst (s->cbb, tree); \
+       } while (0)
+
 #define MONO_EMIT_LOAD_MEMBASE(cfg,inst,dr,base,offset) do { \
                 (inst)->opcode = OP_LOAD_MEMBASE; \
                 (inst)->dreg = dr; \
@@ -399,6 +408,10 @@ stmt: OP_DUMMY_STORE {
 stmt: OP_NOT_REACHED {
 }
 
+stmt: OP_MEMORY_BARRIER {
+       mono_bblock_add_inst (s->cbb, tree);
+}
+
 #
 # load/store operations
 #
@@ -737,7 +750,7 @@ reg: OP_TLS_GET {
        mono_bblock_add_inst (s->cbb, tree);
 }
 
-stmt: CEE_SWITCH (reg) {
+stmt: CEE_SWITCH (reg) "2" {
        MonoInst *label;
        int offset_reg = mono_regstate_next_int (s->rs);
        int target_reg = mono_regstate_next_int (s->rs);
@@ -922,8 +935,13 @@ stmt: OP_THROW_OR_NULL (reg, reg) {
 
        MONO_NEW_LABEL (s, dont_throw);
 
-       MONO_EMIT_NEW_BIALU (s, OP_COMPARE, 0, state->left->reg1, state->right->reg1);
-       MONO_EMIT_NEW_BRANCH_LABEL (s, CEE_BNE_UN, dont_throw);
+       /*
+        * Currently, we allways rethrow the abort exception, despite the fact
+        * that this is not correct. See thread6.cs for an example. But propagating
+        * the abort exception is more important than getting the sematics right.
+     */
+       MONO_EMIT_NEW_BIALU_IMM (s, OP_COMPARE_IMM, -1, state->left->reg1, 0);
+       MONO_EMIT_NEW_BRANCH_LABEL (s, CEE_BEQ, dont_throw);
        MONO_EMIT_UNALU (s, tree, CEE_THROW, -1, state->left->reg1);
        mono_bblock_add_inst (s->cbb, dont_throw);
 }
@@ -989,7 +1007,7 @@ reg: CEE_ISINST (reg) {
                        MONO_EMIT_NEW_LOAD_MEMBASE (s, eclass_reg, klass_reg, G_STRUCT_OFFSET (MonoClass, cast_class));
                        if (klass->cast_class == mono_defaults.object_class) {
                                int parent_reg = mono_regstate_next_int (s->rs);
-                               int const_reg;
+                               int const_reg = -1;
                                MONO_EMIT_NEW_LOAD_MEMBASE (s, parent_reg, eclass_reg, G_STRUCT_OFFSET (MonoClass, parent));
                                if (s->compile_aot) {
                                        const_reg = mono_regstate_next_int (s->rs);
@@ -1008,7 +1026,7 @@ reg: CEE_ISINST (reg) {
                                MONO_EMIT_NEW_BRANCH_LABEL (s, CEE_BEQ, object_is_null);
                                MONO_EMIT_NEW_BRANCH_LABEL (s, CEE_BR, false_label);
                        } else if (klass->cast_class == mono_defaults.enum_class->parent) {
-                               int const_reg;
+                               int const_reg = -1;
                                
                                if (s->compile_aot) {
                                        const_reg = mono_regstate_next_int (s->rs);
@@ -1050,6 +1068,10 @@ reg: CEE_ISINST (reg) {
                                /* the object_is_null target simply copies the input register to the output */
                                mini_emit_isninst_cast (s, eclass_reg, klass->cast_class, false_label, object_is_null);
                        }
+               } else if (mono_class_is_nullable (klass)) {
+                       MONO_EMIT_NEW_LOAD_MEMBASE (s, klass_reg, vtable_reg, G_STRUCT_OFFSET (MonoVTable, klass));
+                       /* the object_is_null target simply copies the input register to the output */
+                       mini_emit_isninst_cast (s, klass_reg, klass->cast_class, false_label, object_is_null);
                } else {
                        if (!s->compile_aot && !(s->opt & MONO_OPT_SHARED) && (klass->flags & TYPE_ATTRIBUTE_SEALED)) {
                                /* the remoting code is broken, access the class for now */
@@ -1222,7 +1244,7 @@ reg: CEE_CASTCLASS (reg) {
                        MONO_EMIT_NEW_LOAD_MEMBASE (s, eclass_reg, klass_reg, G_STRUCT_OFFSET (MonoClass, cast_class));
                        if (klass->cast_class == mono_defaults.object_class) {
                                int parent_reg = mono_regstate_next_int (s->rs);
-                               int const_reg;
+                               int const_reg = -1;
                                MONO_EMIT_NEW_LOAD_MEMBASE (s, parent_reg, eclass_reg, G_STRUCT_OFFSET (MonoClass, parent));
                                if (s->compile_aot) {
                                        const_reg = mono_regstate_next_int (s->rs);
@@ -1601,7 +1623,6 @@ mini_emit_load_intf_reg (MonoCompile *s, int intf_reg, int ioffset_reg, MonoClas
        if (s->compile_aot) {
                int iid_reg = mono_regstate_next_int (s->rs);
                MONO_EMIT_NEW_AOTCONST (s, iid_reg, klass, MONO_PATCH_INFO_IID);
-               /* FIXME: Do a shift instead */
 #if SIZEOF_VOID_P == 8
                MONO_EMIT_NEW_BIALU_IMM (s, OP_SHL_IMM, iid_reg, iid_reg, 3);
 #else
@@ -1631,7 +1652,16 @@ mini_emit_load_intf_reg_class (MonoCompile *s, int intf_reg, int klass_reg, Mono
        int ioffset_reg = mono_regstate_next_int (s->rs);
 
        MONO_EMIT_NEW_LOAD_MEMBASE (s, ioffset_reg, klass_reg, G_STRUCT_OFFSET (MonoClass, interface_offsets));
-       mini_emit_load_intf_reg (s, intf_reg, ioffset_reg, klass);
+
+       if (s->compile_aot) {
+               int iid_reg = mono_regstate_next_int (s->rs);
+               MONO_EMIT_NEW_AOTCONST (s, iid_reg, klass, MONO_PATCH_INFO_IID);
+               MONO_EMIT_NEW_BIALU_IMM (s, OP_SHL_IMM, iid_reg, iid_reg, 2);
+               MONO_EMIT_NEW_BIALU (s, CEE_ADD, ioffset_reg, ioffset_reg, iid_reg);
+               MONO_EMIT_NEW_LOAD_MEMBASE_OP (s, OP_LOADI4_MEMBASE, intf_reg, ioffset_reg, 0);
+       }
+       else
+               MONO_EMIT_NEW_LOAD_MEMBASE_OP (s, OP_LOADI4_MEMBASE, intf_reg, ioffset_reg, klass->interface_id * sizeof (int));
 }
 
 void 
@@ -1842,7 +1872,7 @@ mini_emit_memcpy (MonoCompile *s, int destreg, int doffset, int srcreg, int soff
 }
 
 void 
-mini_emit_memset (MonoCompile *s, int destreg, int offset, int size, int val, int alignl)
+mini_emit_memset (MonoCompile *s, int destreg, int offset, int size, int val, int align)
 {
        int val_reg = mono_regstate_next_int (s->rs);
 
@@ -1851,13 +1881,21 @@ mini_emit_memset (MonoCompile *s, int destreg, int offset, int size, int val, in
        else
                MONO_EMIT_NEW_ICONST (s, val_reg, val);
 
+       /* FIXME: consider alignment for archs that need it. */
+#if !NO_UNALIGNED_ACCESS
        if (sizeof (gpointer) == 8) {
+               if (offset % 8) {
+                       MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg);
+                       offset += 4;
+                       size -= 4;
+               }
                while (size >= 8) {
                        MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREI8_MEMBASE_REG, destreg, offset, val_reg);
                        offset += 8;
                        size -= 8;
                }
        }       
+#endif
 
        while (size >= 4) {
                MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREI4_MEMBASE_REG, destreg, offset, val_reg);