Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_And(PyLongObject *left, PyLongObject *right);

int _PyLong_AssignValue(PyObject **target, Py_ssize_t value);

Expand Down
38 changes: 19 additions & 19 deletions Include/internal/pycore_opcode.h

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

109 changes: 55 additions & 54 deletions Include/opcode.h

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

1 change: 1 addition & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def pseudo_op(name, op, real_ops):
"BINARY_OP_MULTIPLY_INT",
"BINARY_OP_SUBTRACT_FLOAT",
"BINARY_OP_SUBTRACT_INT",
"BINARY_OP_AND_INT",
],
"BINARY_SUBSCR": [
"BINARY_SUBSCR_DICT",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``BINARY_OP_AND_INT`` for and operation between int objects. Patch by
Dong-hee Na.
Comment thread
corona10 marked this conversation as resolved.
Outdated
16 changes: 10 additions & 6 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5299,16 +5299,20 @@ long_bitwise(PyLongObject *a,
return (PyObject *)maybe_small_long(long_normalize(z));
}

PyObject *
_PyLong_And(PyLongObject *a, PyLongObject *b)
{
if (IS_MEDIUM_VALUE(a) && IS_MEDIUM_VALUE(b)) {
return _PyLong_FromSTwoDigits(medium_value(a) & medium_value(b));
}
return long_bitwise(a, '&', b);
}

static PyObject *
long_and(PyObject *a, PyObject *b)
{
CHECK_BINOP(a, b);
PyLongObject *x = (PyLongObject*)a;
PyLongObject *y = (PyLongObject*)b;
if (IS_MEDIUM_VALUE(x) && IS_MEDIUM_VALUE(y)) {
return _PyLong_FromSTwoDigits(medium_value(x) & medium_value(y));
}
return long_bitwise(x, '&', y);
return _PyLong_And((PyLongObject *)a, (PyLongObject *)b);
}

static PyObject *
Expand Down
12 changes: 12 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ dummy_func(
BINARY_OP_MULTIPLY_INT,
BINARY_OP_SUBTRACT_FLOAT,
BINARY_OP_SUBTRACT_INT,
BINARY_OP_AND_INT,
};


Expand Down Expand Up @@ -332,6 +333,17 @@ dummy_func(
ERROR_IF(sum == NULL, error);
}

inst(BINARY_OP_AND_INT, (unused/1, left, right -- and)) {
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP);
STAT_INC(BINARY_OP, hit);
and = _PyLong_And((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
ERROR_IF(and == NULL, error);
}

family(binary_subscr, INLINE_CACHE_ENTRIES_BINARY_SUBSCR) = {
BINARY_SUBSCR,
BINARY_SUBSCR_DICT,
Expand Down
18 changes: 18 additions & 0 deletions Python/generated_cases.c.h

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

Loading