Skip to content

Commit

Permalink
swap order of tags and refcounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Mar 29, 2024
1 parent 8be49a5 commit 5e2018c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 85 deletions.
8 changes: 8 additions & 0 deletions Include/internal/pycore_tagged.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ _Py_untag_stack(PyObject **dst, const _PyTaggedPtr *src, size_t length) {
} \
} while (0)

static inline _PyTaggedPtr _Py_NewRef_Tagged(_PyTaggedPtr obj)
{
Py_INCREF_TAGGED(obj);
return obj;
}

#define Py_NewRef_Tagged(op) _Py_NewRef_Tagged(op);

#ifdef __cplusplus
}
#endif
Expand Down
25 changes: 12 additions & 13 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ dummy_func(
Py_INCREF_TAGGED(value);
}

replicate(8) inst(STORE_FAST, (value --)) {
SETLOCAL(oparg, value_tagged);
replicate(8) inst(STORE_FAST, (value: _PyTaggedPtr --)) {
SETLOCAL(oparg, value);
}

pseudo(STORE_FAST_MAYBE_NULL) = {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ dummy_func(
STAT_INC(UNPACK_SEQUENCE, hit);
PyObject **items = _PyTuple_ITEMS(seq);
for (int i = oparg; --i >= 0; ) {
*values++ = Py_OBJ_TAG(Py_NewRef(items[i]));
*values++ = Py_NewRef_Tagged(Py_OBJ_TAG(items[i]));
}
DECREF_INPUTS();
}
Expand All @@ -1262,7 +1262,7 @@ dummy_func(
STAT_INC(UNPACK_SEQUENCE, hit);
PyObject **items = _PyList_ITEMS(seq);
for (int i = oparg; --i >= 0; ) {
*values++ = Py_OBJ_TAG(Py_NewRef(items[i]));
*values++ = Py_NewRef_Tagged(Py_OBJ_TAG(items[i]));
}
DECREF_INPUTS();
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ dummy_func(
int offset = co->co_nlocalsplus - oparg;
for (int i = 0; i < oparg; ++i) {
PyObject *o = PyTuple_GET_ITEM(closure, i);
frame->localsplus[offset + i] = Py_OBJ_TAG(Py_NewRef(o));
frame->localsplus[offset + i] = Py_NewRef_Tagged(Py_OBJ_TAG(o));
}
}

Expand Down Expand Up @@ -2068,7 +2068,7 @@ dummy_func(
// Manipulate stack directly because we exit with DISPATCH_INLINED().
STACK_SHRINK(1);
new_frame->localsplus[0] = owner_tagged;
new_frame->localsplus[1] = Py_OBJ_TAG(Py_NewRef(name));
new_frame->localsplus[1] = Py_NewRef_Tagged(Py_OBJ_TAG(name));
frame->return_offset = (uint16_t)(next_instr - this_instr);
DISPATCH_INLINED(new_frame);
}
Expand Down Expand Up @@ -3060,9 +3060,9 @@ dummy_func(
args--;
total_args++;
PyObject *self = ((PyMethodObject *)callable)->im_self;
args[0] = Py_OBJ_TAG(Py_NewRef(self));
args[0] = Py_NewRef_Tagged(Py_OBJ_TAG(self));
PyObject *method = ((PyMethodObject *)callable)->im_func;
args[-1] = Py_OBJ_TAG(Py_NewRef(method));
args[-1] = Py_NewRef_Tagged(Py_OBJ_TAG(method));
Py_DECREF(callable);
callable = method;
}
Expand Down Expand Up @@ -3162,7 +3162,7 @@ dummy_func(
PyFunctionObject *func = (PyFunctionObject *)callable;
new_frame = _PyFrame_PushUnchecked(tstate, func, oparg + has_self);
_PyTaggedPtr *first_non_self_local = new_frame->localsplus + has_self;
new_frame->localsplus[0] = Py_OBJ_TAG(self_or_null);
new_frame->localsplus[0] = self_or_null_tagged;
for (int i = 0; i < oparg; i++) {
first_non_self_local[i] = args[i];
}
Expand Down Expand Up @@ -3237,7 +3237,7 @@ dummy_func(
}
for (int i = argcount; i < code->co_argcount; i++) {
PyObject *def = PyTuple_GET_ITEM(func->func_defaults, i - min_args);
new_frame->localsplus[i] = Py_OBJ_TAG(Py_NewRef(def));
new_frame->localsplus[i] = Py_NewRef_Tagged(Py_OBJ_TAG(def));
}
// Manipulate stack and cache directly since we leave using DISPATCH_INLINED().
STACK_SHRINK(oparg + 2);
Expand Down Expand Up @@ -3423,7 +3423,6 @@ dummy_func(

/* Free the arguments. */
for (int i = 0; i < total_args; i++) {
// Note: unpacked above.
Py_DECREF_TAGGED(args[i]);
}
Py_DECREF(callable);
Expand Down Expand Up @@ -3707,9 +3706,9 @@ dummy_func(
args--;
total_args++;
PyObject *self = ((PyMethodObject *)callable)->im_self;
args[0] = Py_OBJ_TAG(Py_NewRef(self));
args[0] = Py_NewRef_Tagged(Py_OBJ_TAG(self));
PyObject *method = ((PyMethodObject *)callable)->im_func;
args[-1] = Py_OBJ_TAG(Py_NewRef(method));
args[-1] = Py_NewRef_Tagged(Py_OBJ_TAG(method));
Py_DECREF_TAGGED(callable_tagged);
callable = method;
}
Expand Down
91 changes: 36 additions & 55 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5e2018c

Please sign in to comment.