Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active September 28, 2021 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/7925f076aafb80c2bf6e098c9e7e089e to your computer and use it in GitHub Desktop.
Save MasterDuke17/7925f076aafb80c2bf6e098c9e7e089e to your computer and use it in GitHub Desktop.
diff --git src/jit/graph.c src/jit/graph.c
index 69f7179e4..5b56020df 100644
--- src/jit/graph.c
+++ src/jit/graph.c
@@ -1915,6 +1915,7 @@ start:
case MVM_OP_objprimunsigned:
case MVM_OP_takehandlerresult:
case MVM_OP_exception:
+ case MVM_OP_scsetobj:
case MVM_OP_scgethandle:
case MVM_OP_scobjcount:
case MVM_OP_setobjsc:
diff --git src/jit/x64/emit.dasc src/jit/x64/emit.dasc
index 9efbd13a3..c04a17ad8 100644
--- src/jit/x64/emit.dasc
+++ src/jit/x64/emit.dasc
@@ -1902,6 +1902,41 @@ void MVM_jit_emit_primitive(MVMThreadContext *tc, MVMJitCompiler *compiler, MVMJ
| mov WORK[dst], TMP2;
break;
}
+ case MVM_OP_scsetobj: {
+ MVMint16 sc = ins->operands[0].reg.orig;
+ MVMint16 idx = ins->operands[1].reg.orig;
+ MVMint16 obj = ins->operands[2].reg.orig;
+ | mov TMP5, aword WORK[sc];
+ | cmp_repr_id TMP5, TMP6, MVM_REPR_ID_SCRef;
+ | je >1;
+ | throw_adhoc "Must provide an SCRef operand to scsetobj"
+ |1:
+ | mov ARG1, TC;
+ | mov ARG2, SCREF:TMP5;
+ | mov ARG3, WORK[idx];
+ | mov ARG4, aword WORK[obj];
+ | call &MVM_sc_set_object;
+ | mov ARG1, TC;
+ | mov TMP5, aword WORK[obj];
+ | get_stable ARG2, TMP5;
+ | call &MVM_sc_get_stable_sc;
+ | test RV, RV;
+ | jnz >2;
+ | mov ARG1, TC;
+ | mov TMP5, aword WORK[obj];
+ | get_stable ARG2, TMP5;
+ | mov TMP6, aword WORK[sc];
+ | mov ARG3, SCREF:TMP6;
+ | call &MVM_sc_set_stable_sc
+ | mov ARG1, TC;
+ | mov TMP5, aword WORK[sc];
+ | mov ARG2, SCREF:TMP5;
+ | mov TMP6, aword WORK[obj];
+ | get_stable ARG3, TMP6;
+ | call &MVM_sc_push_stable
+ |2:
+ break;
+ }
case MVM_OP_scgethandle: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 sc = ins->operands[1].reg.orig;
diff --git src/6model/sc.c src/6model/sc.c
index b120c42dd..4b9e3c693 100644
--- src/6model/sc.c
+++ src/6model/sc.c
@@ -519,3 +519,17 @@ void MVM_sc_wb_hit_st(MVMThreadContext *tc, MVMSTable *st) {
#endif
}
}
+
+void MVM_scsetobj_impl(MVMThreadContext *tc, MVMObject *sc, MVMObject *obj, MVMint64 idx) {
+ if (REPR(sc)->ID != MVM_REPR_ID_SCRef)
+ MVM_exception_throw_adhoc(tc,
+ "Must provide an SCRef operand to scsetobj");
+ MVM_sc_set_object(tc, (MVMSerializationContext *)sc,
+ idx, obj);
+ if (MVM_sc_get_stable_sc(tc, STABLE(obj)) == NULL) {
+ /* Need to claim the SC also; typical case for new type objects. */
+ MVMSTable *st = STABLE(obj);
+ MVM_sc_set_stable_sc(tc, st, (MVMSerializationContext *)sc);
+ MVM_sc_push_stable(tc, (MVMSerializationContext *)sc, st);
+ }
+}
diff --git src/6model/sc.h src/6model/sc.h
index e7a8b276e..897c90285 100644
--- src/6model/sc.h
+++ src/6model/sc.h
@@ -178,3 +178,4 @@ MVM_STATIC_INLINE void MVM_SC_WB_ST(MVMThreadContext *tc, MVMSTable *st) {
if (MVM_sc_get_idx_of_sc(&st->header) > 0)
MVM_sc_wb_hit_st(tc, st);
}
+void MVM_scsetobj_impl(MVMThreadContext *tc, MVMObject *sc, MVMObject *obj, MVMint64 idx);
diff --git src/core/interp.c src/core/interp.c
index f52aac320..1cfeb0810 100644
--- src/core/interp.c
+++ src/core/interp.c
@@ -3130,19 +3130,7 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
cur_op += 4;
goto NEXT;
OP(scsetobj): {
- MVMObject *sc = GET_REG(cur_op, 0).o;
- MVMObject *obj = GET_REG(cur_op, 4).o;
- if (REPR(sc)->ID != MVM_REPR_ID_SCRef)
- MVM_exception_throw_adhoc(tc,
- "Must provide an SCRef operand to scsetobj");
- MVM_sc_set_object(tc, (MVMSerializationContext *)sc,
- GET_REG(cur_op, 2).i64, obj);
- if (MVM_sc_get_stable_sc(tc, STABLE(obj)) == NULL) {
- /* Need to claim the SC also; typical case for new type objects. */
- MVMSTable *st = STABLE(obj);
- MVM_sc_set_stable_sc(tc, st, (MVMSerializationContext *)sc);
- MVM_sc_push_stable(tc, (MVMSerializationContext *)sc, st);
- }
+ MVM_scsetobj_impl(tc, GET_REG(cur_op, 0).o, GET_REG(cur_op, 4).o, GET_REG(cur_op, 2).i64);
cur_op += 6;
goto NEXT;
}
diff --git src/jit/graph.c src/jit/graph.c
index 69f7179e4..8050bab3e 100644
--- src/jit/graph.c
+++ src/jit/graph.c
@@ -166,6 +166,7 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
case MVM_OP_islist: case MVM_OP_ishash: return MVM_repr_compare_repr_id;
case MVM_OP_wval: case MVM_OP_wval_wide: return MVM_sc_get_sc_object;
case MVM_OP_scgetobjidx: return MVM_sc_find_object_idx_jit;
+ case MVM_OP_scsetobj: return MVM_scsetobj_impl;
case MVM_OP_getdynlex: return MVM_frame_getdynlex;
case MVM_OP_binddynlex: return MVM_frame_binddynlex;
case MVM_OP_getlexouter: return MVM_frame_find_lexical_by_name_outer;
@@ -3982,6 +3984,17 @@ start:
jg_append_call_c(tc, jg, op_to_func(tc, op), 2, args, MVM_JIT_RV_PTR, dst);
break;
}
+ case MVM_OP_scsetobj: {
+ MVMint32 sc = ins->operands[0].reg.orig;
+ MVMint64 idx = ins->operands[1].reg.orig;
+ MVMint32 obj = ins->operands[2].reg.orig;
+ MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
+ { MVM_JIT_REG_VAL, sc },
+ { MVM_JIT_REG_VAL, obj },
+ { MVM_JIT_REG_VAL, idx } };
+ jg_append_call_c(tc, jg, op_to_func(tc, op), 4, args, MVM_JIT_RV_VOID, -1);
+ break;
+ }
default: {
/* Check if it's an extop. */
MVMint32 emitted_extop = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment