Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-100239: specialize long tail of binary operations #128722

Merged
merged 20 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
29 changes: 27 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct {

typedef struct {
_Py_BackoffCounter counter;
uint16_t external_cache[4];
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
} _PyBinaryOpCache;

#define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
Expand Down Expand Up @@ -345,8 +346,8 @@ extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals);
extern int _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
int oparg, _PyStackRef *locals);
extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
_Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
Expand Down Expand Up @@ -443,6 +444,12 @@ write_obj(uint16_t *p, PyObject *val)
memcpy(p, &val, sizeof(val));
}

static inline void
write_void(uint16_t *p, void *val)
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
{
memcpy(p, &val, sizeof(val));
}

static inline uint16_t
read_u16(uint16_t *p)
{
Expand Down Expand Up @@ -473,6 +480,14 @@ read_obj(uint16_t *p)
return val;
}

static inline void *
read_void(uint16_t *p)
{
void *val;
memcpy(&val, p, sizeof(val));
return val;
}

/* See Objects/exception_handling_notes.txt for details.
*/
static inline unsigned char *
Expand Down Expand Up @@ -576,6 +591,16 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
return restart_backoff_counter(counter);
}

/* Specialization Extensions */

/* callbacks for an external specialization */
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);

typedef struct _PyBinaryOpSpecializationDescr {
binaryopguardfunc guard;
binaryopactionfunc action;
} PyBinaryOpSpecializationDescr;

/* Comparison bit masks. */

Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Known values:
Python 3.14a4 3610 (Add VALUE_WITH_FAKE_GLOBALS format to annotationlib)
Python 3.14a4 3611 (Add NOT_TAKEN instruction)
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
Python 3.14a4 3613 (Add BINARY_OP_EXTEND)

Python 3.15 will start with 3650

Expand All @@ -277,7 +278,7 @@ PC/launcher.c must also be updated.

*/

#define PYC_MAGIC_NUMBER 3612
#define PYC_MAGIC_NUMBER 3613
/* 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: 29 additions & 16 deletions Include/internal/pycore_opcode_metadata.h

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

Loading