Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
void _Py_Specialize_BinaryOp. PyBinaryOpSpecializationDescr --> _PyBi…
…naryOpSpecializationDescr
  • Loading branch information
iritkatriel committed Jan 14, 2025
commit 0432b9a2e720391c99276d59cfc06ab064621900
8 changes: 4 additions & 4 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,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 int _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals);
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
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 @@ -597,10 +597,10 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);

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

/* Comparison bit masks. */

Expand Down
11 changes: 5 additions & 6 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ dummy_func(
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)(next_instr - INLINE_CACHE_ENTRIES_BINARY_OP);
PyBinaryOpSpecializationDescr *descr =
(PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);
_PyBinaryOpSpecializationDescr *descr =
(_PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);
assert(descr && descr->guard);
int res = descr->guard(left_o, right_o);
EXIT_IF(!res);
Expand All @@ -759,8 +759,8 @@ dummy_func(
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)(next_instr - INLINE_CACHE_ENTRIES_BINARY_OP);
PyBinaryOpSpecializationDescr *descr =
(PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);
_PyBinaryOpSpecializationDescr *descr =
(_PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);

STAT_INC(BINARY_OP, hit);

Expand Down Expand Up @@ -4768,8 +4768,7 @@ dummy_func(
#if ENABLE_SPECIALIZATION_FT
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
next_instr = this_instr;
int res = _Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, LOCALS_ARRAY);
ERROR_IF(res == -1, error);
_Py_Specialize_BinaryOp(lhs, rhs, next_instr, oparg, LOCALS_ARRAY);
DISPATCH_SAME_OPARG();
}
OPCODE_DEFERRED_INC(BINARY_OP);
Expand Down
8 changes: 4 additions & 4 deletions Python/executor_cases.c.h

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

11 changes: 5 additions & 6 deletions Python/generated_cases.c.h

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

30 changes: 15 additions & 15 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,14 +2417,14 @@ LONG_FLOAT_ACTION(compactlong_float_multiply, *)
LONG_FLOAT_ACTION(compactlong_float_true_div, /)
#undef LONG_FLOAT_ACTION

static PyBinaryOpSpecializationDescr float_compactlong_specs[NB_OPARG_LAST+1] = {
static _PyBinaryOpSpecializationDescr float_compactlong_specs[NB_OPARG_LAST+1] = {
[NB_ADD] = {float_compactlong_guard, float_compactlong_add},
[NB_SUBTRACT] = {float_compactlong_guard, float_compactlong_subtract},
[NB_TRUE_DIVIDE] = {float_compactlong_guard, float_compactlong_true_div},
[NB_MULTIPLY] = {float_compactlong_guard, float_compactlong_multiply},
};

static PyBinaryOpSpecializationDescr compactlong_float_specs[NB_OPARG_LAST+1] = {
static _PyBinaryOpSpecializationDescr compactlong_float_specs[NB_OPARG_LAST+1] = {
[NB_ADD] = {compactlong_float_guard, compactlong_float_add},
[NB_SUBTRACT] = {compactlong_float_guard, compactlong_float_subtract},
[NB_TRUE_DIVIDE] = {compactlong_float_guard, compactlong_float_true_div},
Expand All @@ -2433,7 +2433,7 @@ static PyBinaryOpSpecializationDescr compactlong_float_specs[NB_OPARG_LAST+1] =

static int
binary_op_extended_specialization(PyObject *lhs, PyObject *rhs, int oparg,
PyBinaryOpSpecializationDescr **descr)
_PyBinaryOpSpecializationDescr **descr)
{
#define LOOKUP_SPEC(TABLE, OPARG) \
if ((TABLE)[(OPARG)].action) { \
Expand All @@ -2449,7 +2449,7 @@ binary_op_extended_specialization(PyObject *lhs, PyObject *rhs, int oparg,
return 0;
}

int
void
_Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *instr,
int oparg, _PyStackRef *locals)
{
Expand All @@ -2474,18 +2474,18 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
bool to_store = (next.op.code == STORE_FAST);
if (to_store && PyStackRef_AsPyObjectBorrow(locals[next.op.arg]) == lhs) {
specialize(instr, BINARY_OP_INPLACE_ADD_UNICODE);
return 0;
return;
}
specialize(instr, BINARY_OP_ADD_UNICODE);
return 0;
return;
}
if (PyLong_CheckExact(lhs)) {
specialize(instr, BINARY_OP_ADD_INT);
return 0;
return;
}
if (PyFloat_CheckExact(lhs)) {
specialize(instr, BINARY_OP_ADD_FLOAT);
return 0;
return;
}
break;
case NB_MULTIPLY:
Expand All @@ -2495,11 +2495,11 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
}
if (PyLong_CheckExact(lhs)) {
specialize(instr, BINARY_OP_MULTIPLY_INT);
return 0;
return;
}
if (PyFloat_CheckExact(lhs)) {
specialize(instr, BINARY_OP_MULTIPLY_FLOAT);
return 0;
return;
}
break;
case NB_SUBTRACT:
Expand All @@ -2509,25 +2509,25 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
}
if (PyLong_CheckExact(lhs)) {
specialize(instr, BINARY_OP_SUBTRACT_INT);
return 0;
return;
}
if (PyFloat_CheckExact(lhs)) {
specialize(instr, BINARY_OP_SUBTRACT_FLOAT);
return 0;
return;
}
break;
}

PyBinaryOpSpecializationDescr *descr;
_PyBinaryOpSpecializationDescr *descr;
if (binary_op_extended_specialization(lhs, rhs, oparg, &descr)) {
specialize(instr, BINARY_OP_EXTEND);
write_void(cache->external_cache, (void*)descr);
return 0;
return;
}

SPECIALIZATION_FAIL(BINARY_OP, binary_op_fail_kind(oparg, lhs, rhs));
unspecialize(instr);
return 0;
return;
}


Expand Down