From ea648eda285a9dbc0275c250f8767750cae063bf Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Wed, 9 Oct 2019 01:08:44 +0300 Subject: [PATCH] [interp] Small cleanups (mono/mono#17229) * [intepr] Add define for constant * [interp] Pass separately pop_vt_sp argument Cleans up the code a bit. There is no need to do fancy bit operations for such a slow opcode. Commit migrated from https://github.com/mono/mono/commit/579e385b96c5fd4d9e0b597d4820e3bd2e6cd24a --- src/mono/mono/mini/interp/interp-internals.h | 2 +- src/mono/mono/mini/interp/interp.c | 12 +++++------- src/mono/mono/mini/interp/mintops.def | 4 ++-- src/mono/mono/mini/interp/transform.c | 14 ++++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/mono/mono/mini/interp/interp-internals.h b/src/mono/mono/mini/interp/interp-internals.h index d509e62..a3f7366 100644 --- a/src/mono/mono/mini/interp/interp-internals.h +++ b/src/mono/mono/mini/interp/interp-internals.h @@ -22,7 +22,7 @@ #define MINT_TYPE_P 9 #define MINT_TYPE_VT 10 -#define BOX_NOT_CLEAR_VT_SP 0x4000 +#define INLINED_METHOD_FLAG 0xffff #define MINT_VT_ALIGNMENT 8 diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 53b777c..ff9e3f5 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -3104,8 +3104,7 @@ mono_interp_box_nullable (InterpFrame* frame, const guint16* ip, stackval* sp, M int const size = mono_class_value_size (c, NULL); guint16 offset = ip [2]; - gboolean const pop_vt_sp = !(offset & BOX_NOT_CLEAR_VT_SP); - offset &= ~BOX_NOT_CLEAR_VT_SP; + guint16 pop_vt_sp = !ip [3]; sp [-1 - offset].data.o = mono_nullable_box (sp [-1 - offset].data.p, c, error); mono_interp_error_cleanup (error); /* FIXME: don't swallow the error */ @@ -3125,8 +3124,7 @@ mono_interp_box_vt (InterpFrame* frame, const guint16* ip, stackval* sp) int const size = mono_class_value_size (c, NULL); guint16 offset = ip [2]; - gboolean const pop_vt_sp = !(offset & BOX_NOT_CLEAR_VT_SP); - offset &= ~BOX_NOT_CLEAR_VT_SP; + guint16 pop_vt_sp = !ip [3]; OBJREF (o) = mono_gc_alloc_obj (vtable, m_class_get_instance_size (vtable->klass)); mono_value_copy_internal (mono_object_get_data (o), sp [-1 - offset].data.p, c); @@ -4605,7 +4603,7 @@ common_vcall: guint16 param_count; guint16 imethod_index = ip [1]; - const gboolean is_inlined = imethod_index == 0xffff; + const gboolean is_inlined = imethod_index == INLINED_METHOD_FLAG; param_count = ip [2]; @@ -5255,12 +5253,12 @@ common_vcall: } MINT_IN_CASE(MINT_BOX_VT) { vt_sp -= mono_interp_box_vt (frame, ip, sp); - ip += 3; + ip += 4; MINT_IN_BREAK; } MINT_IN_CASE(MINT_BOX_NULLABLE) { vt_sp -= mono_interp_box_nullable (frame, ip, sp, error); - ip += 3; + ip += 4; MINT_IN_BREAK; } MINT_IN_CASE(MINT_NEWARR) { diff --git a/src/mono/mono/mini/interp/mintops.def b/src/mono/mono/mini/interp/mintops.def index 9a95e56..1c280e0 100644 --- a/src/mono/mono/mini/interp/mintops.def +++ b/src/mono/mono/mini/interp/mintops.def @@ -371,8 +371,8 @@ OPDEF(MINT_CASTCLASS_COMMON, "castclass.common", 2, Pop0, Push0, MintOpClassToke OPDEF(MINT_ISINST_COMMON, "isinst.common", 2, Pop1, Push1, MintOpClassToken) OPDEF(MINT_NEWARR, "newarr", 2, Pop1, Push1, MintOpClassToken) OPDEF(MINT_BOX, "box", 3, Pop0, Push0, MintOpTwoShorts) -OPDEF(MINT_BOX_VT, "box.vt", 3, Pop0, Push0, MintOpTwoShorts) -OPDEF(MINT_BOX_NULLABLE, "box.nullable", 3, Pop0, Push0, MintOpTwoShorts) +OPDEF(MINT_BOX_VT, "box.vt", 4, Pop0, Push0, MintOpTwoShorts) +OPDEF(MINT_BOX_NULLABLE, "box.nullable", 4, Pop0, Push0, MintOpTwoShorts) OPDEF(MINT_UNBOX, "unbox", 2, Pop1, Push1, MintOpClassToken) OPDEF(MINT_LDTOKEN, "ldtoken", 2, Pop0, Push1, MintOpClassToken) /* not really */ OPDEF(MINT_LDFTN, "ldftn", 2, Pop0, Push1, MintOpMethodToken) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index d6af967..50ebf87 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -2021,7 +2021,8 @@ interp_constrained_box (TransformData *td, MonoDomain *domain, MonoClass *constr g_assert (mt == MINT_TYPE_VT); interp_add_ins (td, MINT_BOX_NULLABLE); td->last_ins->data [0] = get_data_item_index (td, constrained_class); - td->last_ins->data [1] = csignature->param_count | ((td->sp - 1 - csignature->param_count)->type != STACK_TYPE_MP ? 0 : BOX_NOT_CLEAR_VT_SP); + td->last_ins->data [1] = csignature->param_count; + td->last_ins->data [2] = (td->sp - 1 - csignature->param_count)->type != STACK_TYPE_MP ? 0 : 1; } else { MonoVTable *vtable = mono_class_vtable_checked (domain, constrained_class, error); return_if_nok (error); @@ -2029,7 +2030,8 @@ interp_constrained_box (TransformData *td, MonoDomain *domain, MonoClass *constr if (mt == MINT_TYPE_VT) { interp_add_ins (td, MINT_BOX_VT); td->last_ins->data [0] = get_data_item_index (td, vtable); - td->last_ins->data [1] = csignature->param_count | ((td->sp - 1 - csignature->param_count)->type != STACK_TYPE_MP ? 0 : BOX_NOT_CLEAR_VT_SP); + td->last_ins->data [1] = csignature->param_count; + td->last_ins->data [2] = (td->sp - 1 - csignature->param_count)->type != STACK_TYPE_MP ? 0 : 1; } else { interp_add_ins (td, MINT_BOX); td->last_ins->data [0] = get_data_item_index (td, vtable); @@ -4337,7 +4339,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, goto_if_nok (error, exit); if (interp_inline_method (td, m, mheader, error)) { - newobj_fast->data [0] = 0xffff; + newobj_fast->data [0] = INLINED_METHOD_FLAG; break; } } @@ -6109,7 +6111,7 @@ get_inst_stack_usage (TransformData *td, InterpInst *ins, int *pop, int *push) } case MINT_NEWOBJ_FAST: { int param_count = ins->data [1]; - gboolean is_inlined = ins->data [0] == 0xffff; + gboolean is_inlined = ins->data [0] == INLINED_METHOD_FLAG; if (is_inlined) { // This needs to be handled explictly during cprop, in order to properly // keep track of stack contents @@ -6578,7 +6580,7 @@ retry: sp [-1].ins = NULL; sp++; } else if (ins->opcode >= MINT_BOX && ins->opcode <= MINT_BOX_NULLABLE) { - int offset = (ins->data [1] & ~BOX_NOT_CLEAR_VT_SP); + int offset = ins->data [1]; // Clear the stack slot that is boxed memset (&sp [-1 - offset], 0, sizeof (StackContentInfo)); // Make sure that the instructions that pushed this stack slot can't be @@ -6596,7 +6598,7 @@ retry: sp [-i].ins = NULL; memset (sp, 0, sizeof (StackContentInfo)); sp++; - } else if (ins->opcode == MINT_NEWOBJ_FAST && ins->data [0] == 0xffff) { + } else if (ins->opcode == MINT_NEWOBJ_FAST && ins->data [0] == INLINED_METHOD_FLAG) { int param_count = ins->data [1]; // memmove the stack values while clearing ins, to prevent instruction removal for (int i = 1; i <= param_count; i++) { -- 2.7.4