Skip to content

Commit

Permalink
[mono][interp] Add stobj version for no reference case (#79165)
Browse files Browse the repository at this point in the history
* [mono][interp] Remove some duplicated code

* [mono][interp] Add stobj version for no reference case

The noref opcode is twice as fast and it doesn't mark any cards for the GC to scan.
  • Loading branch information
BrzVlad authored Dec 3, 2022
1 parent 02c144a commit b77aa8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6088,6 +6088,11 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
ip += 4;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_STOBJ_VT_NOREF) {
memcpy (LOCAL_VAR (ip [1], gpointer), locals + ip [2], ip [3]);
ip += 4;
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_CONV_OVF_U8_I4) {
gint32 val = LOCAL_VAR (ip [2], gint32);
if (val < 0)
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/mini/interp/mintops.def
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ OPDEF(MINT_CPOBJ, "cpobj", 4, 0, 2, MintOpClassToken)
OPDEF(MINT_CPOBJ_VT, "cpobj.vt", 4, 0, 2, MintOpClassToken)
OPDEF(MINT_LDOBJ_VT, "ldobj.vt", 4, 1, 1, MintOpShortInt)
OPDEF(MINT_STOBJ_VT, "stobj.vt", 4, 0, 2, MintOpClassToken)
OPDEF(MINT_STOBJ_VT_NOREF, "stobj.vt.noref", 4, 0, 2, MintOpShortInt)
OPDEF(MINT_CPBLK, "cpblk", 4, 0, 3, MintOpNoArgs)
OPDEF(MINT_INITBLK, "initblk", 4, 0, 3, MintOpNoArgs)
OPDEF(MINT_LOCALLOC, "localloc", 3, 1, 1, MintOpNoArgs)
Expand Down
31 changes: 17 additions & 14 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,19 +1856,27 @@ interp_emit_ldobj (TransformData *td, MonoClass *klass)
}

static void
interp_emit_stobj (TransformData *td, MonoClass *klass)
interp_emit_stobj (TransformData *td, MonoClass *klass, gboolean reverse_order)
{
int mt = mint_type (m_class_get_byval_arg (klass));

if (mt == MINT_TYPE_VT) {
interp_add_ins (td, MINT_STOBJ_VT);
td->last_ins->data [0] = get_data_item_index (td, klass);
if (m_class_has_references (klass)) {
interp_add_ins (td, MINT_STOBJ_VT);
td->last_ins->data [0] = get_data_item_index (td, klass);
} else {
interp_add_ins (td, MINT_STOBJ_VT_NOREF);
td->last_ins->data [0] = GINT32_TO_UINT16 (mono_class_value_size (klass, NULL));
}
} else {
int opcode = interp_get_stind_for_mt (mt);
interp_add_ins (td, opcode);
}
td->sp -= 2;
interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
if (reverse_order)
interp_ins_set_sregs2 (td->last_ins, td->sp [1].local, td->sp [0].local);
else
interp_ins_set_sregs2 (td->last_ins, td->sp [0].local, td->sp [1].local);
}

static void
Expand Down Expand Up @@ -1993,7 +2001,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
store_local (td, local);
interp_emit_ldelema (td, target_method->klass, value_class);
load_local (td, local);
interp_emit_stobj (td, element_class);
interp_emit_stobj (td, element_class, FALSE);
td->ip += 5;
return TRUE;
} else if (!strcmp (tm, "UnsafeStore")) {
Expand Down Expand Up @@ -2210,7 +2218,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
MonoClass *klass = mono_class_from_mono_type_internal (type);

interp_emit_ldobj (td, klass);
interp_emit_stobj (td, klass);
interp_emit_stobj (td, klass, FALSE);

td->ip += 5;
return TRUE;
Expand Down Expand Up @@ -4175,12 +4183,7 @@ interp_emit_sfld_access (TransformData *td, MonoClassField *field, MonoClass *fi
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
}
} else {
int opcode = (mt == MINT_TYPE_VT) ? MINT_STOBJ_VT : interp_get_stind_for_mt (mt);
interp_add_ins (td, opcode);
td->sp -= 2;
interp_ins_set_sregs2 (td->last_ins, td->sp [1].local, td->sp [0].local);
if (mt == MINT_TYPE_VT)
td->last_ins->data [0] = get_data_item_index (td, field_class);
interp_emit_stobj (td, field_class, TRUE);
}
} else {
gpointer field_addr = mono_static_field_get_addr (vtable, field);
Expand Down Expand Up @@ -6201,7 +6204,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
interp_emit_metadata_update_ldflda (td, field, error);
goto_if_nok (error, exit);
load_local (td, local);
interp_emit_stobj (td, field_class);
interp_emit_stobj (td, field_class, FALSE);
td->ip += 5;
break;
}
Expand Down Expand Up @@ -6297,7 +6300,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,

BARRIER_IF_VOLATILE (td, MONO_MEMORY_BARRIER_REL);

interp_emit_stobj (td, klass);
interp_emit_stobj (td, klass, FALSE);

td->ip += 5;
break;
Expand Down

0 comments on commit b77aa8a

Please sign in to comment.