Skip to content

Commit 3893a92

Browse files
authored
gh-100239: specialize long tail of binary operations (#128722)
1 parent e81fe94 commit 3893a92

21 files changed

+796
-492
lines changed

Include/internal/pycore_code.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef struct {
100100

101101
typedef struct {
102102
_Py_BackoffCounter counter;
103+
uint16_t external_cache[4];
103104
} _PyBinaryOpCache;
104105

105106
#define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
@@ -438,7 +439,7 @@ write_u64(uint16_t *p, uint64_t val)
438439
}
439440

440441
static inline void
441-
write_obj(uint16_t *p, PyObject *val)
442+
write_ptr(uint16_t *p, void *val)
442443
{
443444
memcpy(p, &val, sizeof(val));
444445
}
@@ -576,6 +577,16 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
576577
return restart_backoff_counter(counter);
577578
}
578579

580+
/* Specialization Extensions */
581+
582+
/* callbacks for an external specialization */
583+
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
584+
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
585+
586+
typedef struct {
587+
binaryopguardfunc guard;
588+
binaryopactionfunc action;
589+
} _PyBinaryOpSpecializationDescr;
579590

580591
/* Comparison bit masks. */
581592

Include/internal/pycore_magic_number.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ Known values:
266266
Python 3.14a4 3611 (Add NOT_TAKEN instruction)
267267
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
268268
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
269+
Python 3.14a5 3614 (Add BINARY_OP_EXTEND)
269270
270271
Python 3.15 will start with 3650
271272
@@ -278,7 +279,7 @@ PC/launcher.c must also be updated.
278279
279280
*/
280281

281-
#define PYC_MAGIC_NUMBER 3613
282+
#define PYC_MAGIC_NUMBER 3614
282283
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
283284
(little-endian) and then appending b'\r\n'. */
284285
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

+29-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)