} while (0)
#endif
+#ifndef MONO_EMIT_NEW_COMPARE_BRANCH_LABEL_CHAINED
+#define MONO_EMIT_NEW_COMPARE_BRANCH_LABEL_CHAINED(cfg, cmp_op, sreg1, sreg2, label) \
+ do { \
+ MONO_EMIT_NEW_BRANCH_LABEL (s, (cmp_op), (label)); \
+} while (0)
+#endif
+
#ifndef MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL
#define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL(cfg, cmp_op, sreg1, imm, label) \
do { \
} while (0)
#endif
+#ifndef MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL_CHAINED
+#define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL_CHAINED(cfg, cmp_op, sreg1, imm, label) \
+ do { \
+ MONO_EMIT_NEW_BRANCH_LABEL (s, (cmp_op), (label)); \
+} while (0)
+#endif
+
#ifndef MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK
#define MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK(cfg, cmp_op, sreg1, sreg2, block) \
do { \
} while (0)
#endif
+#ifndef MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK_CHAINED
+#define MONO_EMIT_NEW_COMPARE_BRANCH_BLOCK_CHAINED(cfg, cmp_op, sreg1, sreg2, block) \
+ do { \
+ MONO_EMIT_NEW_BRANCH_BLOCK (s, (cmp_op), (block)); \
+} while (0)
+#endif
+
#ifndef MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK
#define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK(cfg, cmp_op, sreg1, imm, block) \
do { \
} while (0)
#endif
+#ifndef MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK_CHAINED
+#define MONO_EMIT_NEW_COMPARE_IMM_BRANCH_BLOCK_CHAINED(cfg, cmp_op, sreg1, imm, block) \
+ do { \
+ MONO_EMIT_NEW_BRANCH_BLOCK (s, (cmp_op), (block)); \
+} while (0)
+#endif
+
%%
%termprefix OP_ CEE_
}
stmt: OP_MEMCPY (base, base) {
- int size = tree->backend.size;
+ int size = tree->backend.memcpy_args->size;
+ int align = tree->backend.memcpy_args->align;
if (size > 0)
mini_emit_memcpy (s, state->left->tree->inst_basereg, state->left->tree->inst_offset,
- state->right->tree->inst_basereg, state->right->tree->inst_offset, size, 0);
+ state->right->tree->inst_basereg, state->right->tree->inst_offset, size, align);
}
stmt: OP_MEMSET (base) {
- int size = tree->backend.size;
+ int size = tree->backend.memcpy_args->size;
+ int align = tree->backend.memcpy_args->align;
if (size > 0)
- mini_emit_memset (s, state->left->tree->inst_basereg, state->left->tree->inst_offset, size, tree->inst_imm, 0);
+ mini_emit_memset (s, state->left->tree->inst_basereg, state->left->tree->inst_offset, size, tree->inst_imm, align);
}
reg: OP_LDELEMA2D (reg, OP_GROUP (reg, reg)) "20" {
reg: OP_CLT (cflags),
reg: OP_CLT_UN (cflags),
reg: OP_CGT (cflags),
-reg: OP_CGT_UN (cflags) {
+reg: OP_CGT_UN (cflags) "2" {
tree->dreg = state->reg1;
mono_bblock_add_inst (s->cbb, tree);
}
if (klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
MONO_EMIT_NEW_LOAD_MEMBASE (s, vtable_reg, obj_reg, G_STRUCT_OFFSET (MonoObject, vtable));
/* the object_is_null target simply copies the input register to the output */
- mini_emit_isninst_iface_cast (s, vtable_reg, klass, false_label, object_is_null);
+ mini_emit_isinst_iface (s, vtable_reg, klass, false_label, object_is_null);
} else {
int klass_reg = mono_regstate_next_int (s->rs);
}
MONO_EMIT_NEW_BRANCH_LABEL (s, OP_BR, false_label);
} else if (klass->cast_class->flags & TYPE_ATTRIBUTE_INTERFACE) {
- mini_emit_isninst_iface_class_cast (s, eclass_reg, klass->cast_class, false_label, object_is_null);
+ mini_emit_isinst_iface_class (s, eclass_reg, klass->cast_class, false_label, object_is_null);
} else {
if ((klass->rank == 1) && (klass->byval_arg.type == MONO_TYPE_SZARRAY)) {
/* Check that the object is a vector too */
}
/* 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);
+ mini_emit_isinst (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);
+ mini_emit_isinst (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 */
} else {
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, false_label, object_is_null);
+ mini_emit_isinst (s, klass_reg, klass, false_label, object_is_null);
}
}
}
if (klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
MONO_NEW_LABEL (s, interface_fail_label);
MONO_EMIT_NEW_LOAD_MEMBASE (s, tmp_reg, obj_reg, G_STRUCT_OFFSET (MonoObject, vtable));
- mini_emit_isninst_iface_cast (s, tmp_reg, klass, interface_fail_label, true_label);
+ mini_emit_isinst_iface (s, tmp_reg, klass, interface_fail_label, true_label);
mono_bblock_add_inst (s->cbb, interface_fail_label);
MONO_EMIT_NEW_LOAD_MEMBASE (s, klass_reg, tmp_reg, G_STRUCT_OFFSET (MonoVTable, klass));
MONO_EMIT_NEW_LOAD_MEMBASE (s, tmp_reg, obj_reg, G_STRUCT_OFFSET (MonoTransparentProxy, custom_type_info));
MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BEQ, tmp_reg, 0, no_proxy_label);
- mini_emit_isninst_cast (s, klass_reg, klass, false2_label, true_label);
+ mini_emit_isinst (s, klass_reg, klass, false2_label, true_label);
MONO_EMIT_NEW_BRANCH_LABEL (s, OP_BR, false2_label);
mono_bblock_add_inst (s->cbb, no_proxy_label);
- mini_emit_isninst_cast (s, klass_reg, klass, false_label, true_label);
+ mini_emit_isinst (s, klass_reg, klass, false_label, true_label);
}
mono_bblock_add_inst (s->cbb, false_label);
MONO_NEW_LABEL (s, fail_label);
MONO_EMIT_NEW_LOAD_MEMBASE (s, tmp_reg, obj_reg, G_STRUCT_OFFSET (MonoObject, vtable));
- mini_emit_isninst_iface_cast (s, tmp_reg, klass, fail_label, ok_result_label);
+ mini_emit_isinst_iface (s, tmp_reg, klass, fail_label, ok_result_label);
mono_bblock_add_inst (s->cbb, fail_label);
MONO_EMIT_NEW_LOAD_MEMBASE (s, klass_reg, tmp_reg, G_STRUCT_OFFSET (MonoVTable, klass));
MONO_EMIT_NEW_LOAD_MEMBASE (s, tmp_reg, obj_reg, G_STRUCT_OFFSET (MonoTransparentProxy, custom_type_info));
MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BEQ, tmp_reg, 0, no_proxy_label);
- mini_emit_isninst_cast (s, klass_reg, klass, fail_label, ok_result_label);
+ mini_emit_isinst (s, klass_reg, klass, fail_label, ok_result_label);
mono_bblock_add_inst (s->cbb, fail_label);
MONO_EMIT_NEW_ICONST (s, state->reg1, 1);
MONO_EMIT_NEW_BRANCH_LABEL (s, OP_BR, end_label);
MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREP_MEMBASE_REG, state->right->reg1, G_STRUCT_OFFSET (MonoTypedRef, value), state->left->left->reg1);
}
+reg: OP_MIN (reg, reg) "2" {
+ /* min (x,y) = y + (((x-y)>>31)&(x-y)); */
+ int diff = mono_regstate_next_int (s->rs);
+ int shifted = mono_regstate_next_int (s->rs);
+ int anded = mono_regstate_next_int (s->rs);
+ MONO_EMIT_NEW_BIALU (s, CEE_SUB, diff, state->left->reg1, state->right->reg1);
+ MONO_EMIT_NEW_BIALU_IMM (s, OP_SHR_IMM, shifted, diff, (sizeof(void*)*8-1));
+ MONO_EMIT_NEW_BIALU (s, CEE_AND, anded, shifted, diff);
+ MONO_EMIT_NEW_BIALU (s, CEE_ADD, state->reg1, anded, state->right->reg1);
+}
+
+reg: OP_MAX (reg, reg) "2" {
+ /* max (x,y) = x - (((x-y)>>31)&(x-y)); */
+ int diff = mono_regstate_next_int (s->rs);
+ int shifted = mono_regstate_next_int (s->rs);
+ int anded = mono_regstate_next_int (s->rs);
+ MONO_EMIT_NEW_BIALU (s, CEE_SUB, diff, state->left->reg1, state->right->reg1);
+ MONO_EMIT_NEW_BIALU_IMM (s, OP_SHR_IMM, shifted, diff, (sizeof(void*)*8-1));
+ MONO_EMIT_NEW_BIALU (s, CEE_AND, anded, shifted, diff);
+ MONO_EMIT_NEW_BIALU (s, CEE_SUB, state->reg1, state->left->reg1, anded);
+}
+
%%
#ifdef MONO_ARCH_NEED_GOT_VAR
/* Emit code which loads interface_offsets [klass->interface_id]
* The array is stored in memory before vtable.
*/
+#ifndef MONO_ARCH_HAVE_IMT
static void
mini_emit_load_intf_reg_vtable (MonoCompile *s, int intf_reg, int vtable_reg, MonoClass *klass)
{
MONO_EMIT_NEW_LOAD_MEMBASE (s, intf_reg, vtable_reg, -((klass->interface_id + 1) * SIZEOF_VOID_P));
}
}
+#endif
/*
* Emit code which loads into "intf_bit_reg" a nonzero value if the MonoClass
}
}
+#ifdef MONO_ARCH_HAVE_IMT
+static void
+emit_imt_argument (MonoCompile *cfg, MonoCallInst *call) {
+#ifdef MONO_ARCH_IMT_REG
+ int method_reg = mono_regstate_next_int (cfg->rs);
+
+ if (cfg->compile_aot) {
+ MONO_EMIT_NEW_AOTCONST (cfg, method_reg, call->method, MONO_PATCH_INFO_METHODCONST);
+ } else {
+ MonoInst *inst;
+ MONO_INST_NEW (cfg, inst, OP_PCONST);
+ inst->inst_p0 = call->method;
+ inst->dreg = method_reg;
+ mono_bblock_add_inst (cfg->cbb, inst);
+ }
+
+ mono_call_inst_add_outarg_reg (cfg, call, method_reg, MONO_ARCH_IMT_REG, FALSE);
+#else
+ mono_arch_emit_imt_argument (cfg, call);
+#endif
+}
+#endif
+
static void
mini_emit_virtual_call (MonoCompile *cfg, void *st, MonoInst *tree, int novirtop, int virtop)
{
return;
}
+#ifdef MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
+ if ((method->klass->parent == mono_defaults.multicastdelegate_class) && (!strcmp (method->name, "Invoke"))) {
+ /* Make a call to delegate->invoke_impl */
+ tree->dreg = state->reg1;
+ tree->opcode = virtop;
+ tree->inst_basereg = this_reg;
+ tree->inst_offset = G_STRUCT_OFFSET (MonoDelegate, invoke_impl);
+ mono_bblock_add_inst (cfg->cbb, tree);
+ return;
+ }
+#endif
+
+ if ((method->flags & METHOD_ATTRIBUTE_VIRTUAL) &&
+ ((method->flags & METHOD_ATTRIBUTE_FINAL) ||
+ (method->klass && method->klass->flags & TYPE_ATTRIBUTE_SEALED))) {
+ /*
+ * the method is virtual, but we can statically dispatch since either
+ * it's class or the method itself are sealed.
+ * But first we need to ensure it's not a null reference.
+ */
+ MONO_EMIT_NEW_UNALU (cfg, OP_CHECK_THIS, -1, this_reg);
+
+ tree->dreg = state->reg1;
+ tree->opcode = novirtop;
+ mono_bblock_add_inst (cfg->cbb, tree);
+ return;
+ }
+
/* Initialize method->slot */
mono_class_setup_vtable (method->klass);
vtable_reg = mono_regstate_next_int (cfg->rs);
MONO_EMIT_NEW_LOAD_MEMBASE (cfg, vtable_reg, this_reg, G_STRUCT_OFFSET (MonoObject, vtable));
if (method->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
+#ifdef MONO_ARCH_HAVE_IMT
+ guint32 imt_slot = mono_method_get_imt_slot (method);
+ emit_imt_argument (cfg, (MonoCallInst*)tree);
+ slot_reg = vtable_reg;
+ tree->inst_offset = ((gint32)imt_slot - MONO_IMT_SIZE) * SIZEOF_VOID_P;
+#else
slot_reg = mono_regstate_next_int (cfg->rs);
mini_emit_load_intf_reg_vtable (cfg, slot_reg, vtable_reg, method->klass);
tree->inst_offset = method->slot * SIZEOF_VOID_P;
+#endif
} else {
slot_reg = vtable_reg;
tree->inst_offset = G_STRUCT_OFFSET (MonoVTable, vtable) + (method->slot * SIZEOF_VOID_P);
mono_bblock_add_inst (cfg->cbb, tree);
}
+/*
+ * Emit code for ISINST/CASTCLASS
+ */
static void
-mini_emit_isninst_cast (MonoCompile *s, int klass_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
+mini_emit_isinst (MonoCompile *s, int klass_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
{
int idepth_reg = mono_regstate_next_int (s->rs);
int stypes_reg = mono_regstate_next_int (s->rs);
}
}
+/*
+ * Emit code for ISINST/CASTCLASS for interfaces
+ */
static void
-mini_emit_isninst_iface_cast (MonoCompile *s, int vtable_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
+mini_emit_isinst_iface (MonoCompile *s, int vtable_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
{
int intf_reg = mono_regstate_next_int (s->rs);
mini_emit_max_iid_check_vtable (s, vtable_reg, klass, false_target);
mini_emit_load_intf_bit_reg_vtable (s, intf_reg, vtable_reg, klass);
- /* the object_is_null target simply copies the input register to the output */
- MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BNE_UN, intf_reg, 0, true_target);
+ if (true_target)
+ MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BNE_UN, intf_reg, 0, true_target);
+ else
+ MONO_EMIT_NEW_COMPARE_IMM_EXC (s, EQ, intf_reg, 0, "InvalidCastException");
}
/*
* Variant of the above that takes a register to the class, not the vtable.
*/
static void
-mini_emit_isninst_iface_class_cast (MonoCompile *s, int klass_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
+mini_emit_isinst_iface_class (MonoCompile *s, int klass_reg, MonoClass *klass, MonoInst *false_target, MonoInst *true_target)
{
int intf_bit_reg = mono_regstate_next_int (s->rs);
mini_emit_max_iid_check_class (s, klass_reg, klass, false_target);
mini_emit_load_intf_bit_reg_class (s, intf_bit_reg, klass_reg, klass);
- /* the object_is_null target simply copies the input register to the output */
- MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BNE_UN, intf_bit_reg, 0, true_target);
+ if (true_target)
+ MONO_EMIT_NEW_COMPARE_IMM_BRANCH_LABEL (s, CEE_BNE_UN, intf_bit_reg, 0, true_target);
+ else
+ MONO_EMIT_NEW_COMPARE_IMM_EXC (s, EQ, intf_bit_reg, 0, "InvalidCastException");
}
static void
mini_emit_castclass_iface (MonoCompile *s, int vtable_reg, MonoClass *klass)
{
- int intf_reg = mono_regstate_next_int (s->rs);
-
- mini_emit_max_iid_check_vtable (s, vtable_reg, klass, NULL);
- mini_emit_load_intf_bit_reg_vtable (s, intf_reg, vtable_reg, klass);
- MONO_EMIT_NEW_COMPARE_IMM_EXC (s, EQ, intf_reg, 0, "InvalidCastException");
+ mini_emit_isinst_iface (s, vtable_reg, klass, NULL, NULL);
}
/*
static void
mini_emit_castclass_iface_class (MonoCompile *s, int klass_reg, MonoClass *klass)
{
- int intf_bit_reg = mono_regstate_next_int (s->rs);
-
- mini_emit_max_iid_check_class (s, klass_reg, klass, NULL);
- mini_emit_load_intf_bit_reg_class (s, intf_bit_reg, klass_reg, klass);
- MONO_EMIT_NEW_COMPARE_IMM_EXC (s, EQ, intf_bit_reg, 0, "InvalidCastException");
+ mini_emit_isinst_iface_class (s, klass_reg, klass, NULL, NULL);
}
static void
{
int cur_reg;
+ if (align < 4) {
+ /* This could be optimized further if neccesary */
+ while (size >= 1) {
+ cur_reg = mono_regstate_next_int (s->rs);
+ MONO_EMIT_NEW_LOAD_MEMBASE_OP (s, OP_LOADI1_MEMBASE, cur_reg, srcreg, soffset);
+ MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREI1_MEMBASE_REG, destreg, doffset, cur_reg);
+ doffset += 1;
+ soffset += 1;
+ size -= 1;
+ }
+ }
+
/* FIXME: consider alignment for archs that need it. */
#if !NO_UNALIGNED_ACCESS
if (sizeof (gpointer) == 8) {
else
MONO_EMIT_NEW_ICONST (s, val_reg, val);
+ if (align < 4) {
+ /* This could be optimized further if neccesary */
+ while (size >= 1) {
+ MONO_EMIT_NEW_STORE_MEMBASE (s, OP_STOREI1_MEMBASE_REG, destreg, offset, val_reg);
+ offset += 1;
+ size -= 1;
+ }
+ return;
+ }
+
/* FIXME: consider alignment for archs that need it. */
#if !NO_UNALIGNED_ACCESS
if (sizeof (gpointer) == 8) {