Skip to content

Commit ba2a612

Browse files
committed
use tagged ints for indexes. Work in progress
1 parent 9ca5b0e commit ba2a612

15 files changed

+422
-385
lines changed

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ PyAPI_FUNC(_PyStackRef) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyS
362362
#endif
363363
#endif
364364

365+
_PyStackRef _PyForIter_NextWithIndex(PyObject *seq, _PyStackRef index);
366+
365367
#ifdef __cplusplus
366368
}
367369
#endif

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
311311
_Py_CODEUNIT *instr, int oparg);
312312
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
313313
int oparg);
314-
extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int oparg);
314+
extern void _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT *instr, int oparg);
315315
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
316316
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
317317
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_stackref.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ extern intptr_t PyStackRef_UntagInt(_PyStackRef ref);
231231

232232
extern _PyStackRef PyStackRef_TagInt(intptr_t i);
233233

234+
extern _PyStackRef PyStackRef_IncrementTaggedInt(_PyStackRef ref);
235+
234236
extern bool
235237
PyStackRef_IsNullOrInt(_PyStackRef ref);
236238

@@ -255,7 +257,16 @@ static inline intptr_t
255257
PyStackRef_UntagInt(_PyStackRef i)
256258
{
257259
assert((i.bits & Py_INT_TAG) == Py_INT_TAG);
258-
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, i.bits, 2);
260+
intptr_t val = (intptr_t)i.bits;
261+
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 2);
262+
}
263+
264+
265+
static inline _PyStackRef
266+
PyStackRef_IncrementTaggedInt(_PyStackRef ref)
267+
{
268+
assert(ref.bits != (uintptr_t)-1); // Overflow
269+
return (_PyStackRef){ .bits = ref.bits + 4 };
259270
}
260271

261272

@@ -683,7 +694,13 @@ PyStackRef_XCLOSE(_PyStackRef ref)
683694

684695
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
685696

686-
#define PyStackRef_TYPE(stackref) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref))
697+
static inline PyTypeObject *
698+
PyStackRef_TYPE(_PyStackRef stackref) {
699+
if (PyStackRef_IsTaggedInt(stackref)) {
700+
return &PyLong_Type;
701+
}
702+
return Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref));
703+
}
687704

688705
// Converts a PyStackRef back to a PyObject *, converting the
689706
// stackref to a new reference.

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)