Skip to content

Commit 8efce0a

Browse files
committed
Make PyStackRef_BoxInt inline for JIT
1 parent e5f666d commit 8efce0a

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Include/internal/pycore_stackref.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ PyStackRef_TaggedIntLessThan(_PyStackRef a, _PyStackRef b)
292292

293293
#define PyStackRef_IsDeferredOrTaggedInt(ref) (((ref).bits & Py_TAG_REFCNT) != 0)
294294

295-
extern _PyStackRef PyStackRef_BoxInt(_PyStackRef i);
296-
297295
#ifdef Py_GIL_DISABLED
298296

299297
#define Py_TAG_DEFERRED Py_TAG_REFCNT
@@ -807,6 +805,20 @@ _Py_TryXGetStackRef(PyObject **src, _PyStackRef *out)
807805
} \
808806
} while (0)
809807

808+
809+
static inline _PyStackRef
810+
PyStackRef_BoxInt(_PyStackRef i)
811+
{
812+
assert(PyStackRef_IsTaggedInt(i));
813+
intptr_t val = PyStackRef_UntagInt(i);
814+
PyObject *boxed = PyLong_FromSsize_t(val);
815+
if (boxed == NULL) {
816+
return PyStackRef_NULL;
817+
}
818+
return PyStackRef_FromPyObjectSteal(boxed);
819+
}
820+
821+
810822
#ifdef __cplusplus
811823
}
812824
#endif

Objects/longobject.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6873,19 +6873,3 @@ PyLongWriter_Finish(PyLongWriter *writer)
68736873

68746874
return (PyObject*)obj;
68756875
}
6876-
6877-
// Tagged int support
6878-
6879-
_PyStackRef
6880-
PyStackRef_BoxInt(_PyStackRef i)
6881-
{
6882-
assert((i.bits & Py_INT_TAG) == Py_INT_TAG);
6883-
intptr_t val = (intptr_t)i.bits;
6884-
val = Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 2);
6885-
PyObject *boxed = PyLong_FromSsize_t(val);
6886-
if (boxed == NULL) {
6887-
return PyStackRef_NULL;
6888-
}
6889-
return PyStackRef_FromPyObjectSteal(boxed);
6890-
}
6891-

0 commit comments

Comments
 (0)