Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-132554: SpecializeGET_ITER andFOR_ITER forrange#135063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
markshannon wants to merge23 commits intopython:main
base:main
Choose a base branch
Loading
fromfaster-cpython:specialize-for-iter-range
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
23 commits
Select commitHold shift + click to select a range
4e34e27
Specialize GET_ITER
markshannonApr 30, 2025
37757c6
Add news
markshannonApr 30, 2025
658a422
Specialize FOR_ITER for ranges using tagged ints
markshannonApr 30, 2025
8cf4e6e
Allow range starts other than zero
markshannonMay 27, 2025
11117b4
Specialize GET_ITER for range
markshannonMay 28, 2025
d6f033f
Fix assert
markshannonMay 28, 2025
4679ccc
Fix GET_ITER stats
markshannonMay 29, 2025
06c1680
Fix stats for FOR_ITER specialization
markshannonJun 3, 2025
15cb250
Remove unused function
markshannonJun 3, 2025
89d5d85
Correct comment
markshannonJun 3, 2025
9f688e7
Fix merge glitch
markshannonJun 3, 2025
7325b44
Fix tier 2 unspecialized iteration over ranges
markshannonJun 3, 2025
e5f666d
Make functions inline for the JIT
markshannonJun 3, 2025
8efce0a
Make PyStackRef_BoxInt inline for JIT
markshannonJun 3, 2025
94ad6f9
Merge branch 'main' into specialize-for-iter-range
markshannonJun 6, 2025
7ba5753
Fix PyStackRef_TaggedIntLessThan for Py_STACKREF_DEBUG
markshannonJun 6, 2025
7553e10
Merge branch 'main' into specialize-for-iter-range
markshannonJun 6, 2025
baf4722
Merge branch 'main' into specialize-for-iter-range
markshannonJun 9, 2025
122a816
Cleanup _ITER_JUMP_TUPLE
markshannonJun 10, 2025
9b65402
Merge branch 'main' into specialize-for-iter-range
markshannonJun 13, 2025
4e44e85
Extend iteration by index to strings and bytes
markshannonJun 16, 2025
c41d531
Streamline non-specialized FOR_ITER
markshannonJun 16, 2025
47520ee
Convert INSTRUMENTED_FOR_ITER into macro.
markshannonJun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionsInclude/cpython/object.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -239,6 +239,9 @@ struct _typeobject {
* Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).
*/
uint16_t tp_versions_used;
/* Returns the object at the index given, or NULL if out-of-bounds
* Never raises an exception. */
iterindexfunc tp_iterindex;
};

#define _Py_ATTR_CACHE_UNUSED (30000) // (see tp_versions_used)
Expand Down
1 change: 1 addition & 0 deletionsInclude/internal/pycore_code.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -313,6 +313,7 @@ extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
_Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
int oparg);
extern void _Py_Specialize_GetIter(_PyStackRef iter, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ForIter(_PyStackRef iter, _PyStackRef null_or_index, _Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
Expand Down
3 changes: 2 additions & 1 deletionInclude/internal/pycore_magic_number.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -281,6 +281,7 @@ Known values:
Python 3.15a1 3651 (Simplify LOAD_CONST)
Python 3.15a1 3652 (Virtual iterators)
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
Python 3.15a1 3654 (Specialize GET_ITER. Add FOR_ITER_INDEX)


Python 3.16 will start with 3700
Expand All@@ -294,7 +295,7 @@ PC/launcher.c must also be updated.

*/

#define PYC_MAGIC_NUMBER3653
#define PYC_MAGIC_NUMBER3654
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
45 changes: 35 additions & 10 deletionsInclude/internal/pycore_opcode_metadata.h
View file
Open in desktop

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

39 changes: 39 additions & 0 deletionsInclude/internal/pycore_range.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,52 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

typedef struct {
PyObject_HEAD
PyObject *start;
PyObject *stop;
PyObject *step;
PyObject *length;
} rangeobject;

typedef struct {
PyObject_HEAD
long start;
long step;
long len;
} _PyRangeIterObject;

// Does this range have step == 1 and both start and stop in compact int range?
static inline int
_PyRange_IsSimpleCompact(PyObject *range) {
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
if (_PyLong_IsCompact((PyLongObject *)r->start) &&
_PyLong_IsCompact((PyLongObject *)r->stop) &&
r->step == _PyLong_GetOne()
) {
return 1;
}
return 0;
}

static inline Py_ssize_t
_PyRange_GetStartIfCompact(PyObject *range)
{
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
assert(_PyLong_IsCompact((PyLongObject *)r->start));
return _PyLong_CompactValue((PyLongObject *)r->start);
}

static inline Py_ssize_t
_PyRange_GetStopIfCompact(PyObject *range) {
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
assert(_PyLong_IsCompact((PyLongObject *)r->stop));
return _PyLong_CompactValue((PyLongObject *)r->stop);
}

#ifdef __cplusplus
}
#endif
Expand Down
32 changes: 31 additions & 1 deletionInclude/internal/pycore_stackref.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,6 +115,14 @@ PyStackRef_IsTaggedInt(_PyStackRef ref)
return (ref.index & 1) == 1;
}

static inline bool
PyStackRef_TaggedIntLessThan(_PyStackRef a, _PyStackRef b)
{
assert(PyStackRef_IsTaggedInt(a));
assert(PyStackRef_IsTaggedInt(b));
return ((intptr_t)a.bits) < ((intptr_t)b.bits);
}

static inline PyObject *
_PyStackRef_AsPyObjectBorrow(_PyStackRef ref, const char *filename, int linenumber)
{
Expand DownExpand Up@@ -329,10 +337,18 @@ static inline _PyStackRef
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
{
assert((ref.bits & Py_TAG_BITS) == Py_INT_TAG); // Is tagged int
assert((ref.bits & (~Py_TAG_BITS)) != (INT_MAX & (~Py_TAG_BITS))); // Isn't about to overflow
assert((ref.bits & (~Py_TAG_BITS)) != (INTPTR_MAX & (~Py_TAG_BITS))); // Isn't about to overflow
return (_PyStackRef){ .bits = ref.bits + 4 };
}

static inline bool
PyStackRef_TaggedIntLessThan(_PyStackRef a, _PyStackRef b)
{
assert(PyStackRef_IsTaggedInt(a));
assert(PyStackRef_IsTaggedInt(b));
return ((intptr_t)a.bits) < ((intptr_t)b.bits);
}

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

#ifdef Py_GIL_DISABLED
Expand DownExpand Up@@ -849,6 +865,20 @@ _Py_TryXGetStackRef(PyObject **src, _PyStackRef *out)
} \
} while (0)


static inline _PyStackRef
PyStackRef_BoxInt(_PyStackRef i)
{
assert(PyStackRef_IsTaggedInt(i));
intptr_t val = PyStackRef_UntagInt(i);
PyObject *boxed = PyLong_FromSsize_t(val);
if (boxed == NULL) {
return PyStackRef_ERROR;
}
return PyStackRef_FromPyObjectSteal(boxed);
}


#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp