Skip to content

Commit 72d1748

Browse files
committed
gh-145742: Pre-tag operands for _LOAD_CONST_INLINE_BORROW variants
1 parent 113038f commit 72d1748

File tree

10 files changed

+580
-851
lines changed

10 files changed

+580
-851
lines changed

Include/internal/pycore_stackref.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,24 @@ PyStackRef_FromPyObjectBorrow(PyObject *obj)
615615
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_REFCNT};
616616
}
617617

618+
/* Create a stackref from a pre-tagged operand (tag bits already set).
619+
Used by _LOAD_CONST_INLINE_BORROW variants where the operand is
620+
tagged at trace creation time to avoid tagging on every execution. */
621+
static inline _PyStackRef
622+
PyStackRef_FromPreTagged(uintptr_t tagged)
623+
{
624+
assert(tagged & Py_TAG_REFCNT);
625+
return (_PyStackRef){ .bits = tagged };
626+
}
627+
628+
/* Tag a PyObject pointer as a borrowed operand for BORROW variants. */
629+
#define PyStackRef_TagBorrow(ptr) \
630+
((uintptr_t)(ptr) | Py_TAG_REFCNT)
631+
632+
/* Strip tag bits from a pre-tagged operand to recover the PyObject pointer. */
633+
#define PyStackRef_UntagBorrow(tagged) \
634+
((PyObject *)((uintptr_t)(tagged) & ~Py_TAG_BITS))
635+
618636
/* WARNING: This macro evaluates its argument more than once */
619637
#ifdef _WIN32
620638
#define PyStackRef_DUP(REF) \

0 commit comments

Comments
 (0)