summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c21
-rw-r--r--Python/executor_cases.c.h6
-rw-r--r--Python/generated_cases.c.h98
-rw-r--r--Python/tier2_redundancy_eliminator_bytecodes.c8
-rw-r--r--Python/tier2_redundancy_eliminator_cases.c.h10
5 files changed, 88 insertions, 55 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 27c439b..10bb152 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2200,9 +2200,16 @@ dummy_func(
macro(COMPARE_OP) = _SPECIALIZE_COMPARE_OP + _COMPARE_OP;
- inst(COMPARE_OP_FLOAT, (unused/1, left, right -- res)) {
- DEOPT_IF(!PyFloat_CheckExact(left));
- DEOPT_IF(!PyFloat_CheckExact(right));
+ macro(COMPARE_OP_FLOAT) =
+ _GUARD_BOTH_FLOAT + unused/1 + _COMPARE_OP_FLOAT;
+
+ macro(COMPARE_OP_INT) =
+ _GUARD_BOTH_INT + unused/1 + _COMPARE_OP_INT;
+
+ macro(COMPARE_OP_STR) =
+ _GUARD_BOTH_UNICODE + unused/1 + _COMPARE_OP_STR;
+
+ op(_COMPARE_OP_FLOAT, (left, right -- res)) {
STAT_INC(COMPARE_OP, hit);
double dleft = PyFloat_AS_DOUBLE(left);
double dright = PyFloat_AS_DOUBLE(right);
@@ -2215,9 +2222,7 @@ dummy_func(
}
// Similar to COMPARE_OP_FLOAT
- inst(COMPARE_OP_INT, (unused/1, left, right -- res)) {
- DEOPT_IF(!PyLong_CheckExact(left));
- DEOPT_IF(!PyLong_CheckExact(right));
+ op(_COMPARE_OP_INT, (left, right -- res)) {
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left));
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right));
STAT_INC(COMPARE_OP, hit);
@@ -2234,9 +2239,7 @@ dummy_func(
}
// Similar to COMPARE_OP_FLOAT, but for ==, != only
- inst(COMPARE_OP_STR, (unused/1, left, right -- res)) {
- DEOPT_IF(!PyUnicode_CheckExact(left));
- DEOPT_IF(!PyUnicode_CheckExact(right));
+ op(_COMPARE_OP_STR, (left, right -- res)) {
STAT_INC(COMPARE_OP, hit);
int eq = _PyUnicode_Equal(left, right);
assert((oparg >> 5) == Py_EQ || (oparg >> 5) == Py_NE);
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index b46885e..445f98b 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -2100,8 +2100,6 @@
oparg = CURRENT_OPARG();
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (!PyFloat_CheckExact(left)) goto deoptimize;
- if (!PyFloat_CheckExact(right)) goto deoptimize;
STAT_INC(COMPARE_OP, hit);
double dleft = PyFloat_AS_DOUBLE(left);
double dright = PyFloat_AS_DOUBLE(right);
@@ -2123,8 +2121,6 @@
oparg = CURRENT_OPARG();
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (!PyLong_CheckExact(left)) goto deoptimize;
- if (!PyLong_CheckExact(right)) goto deoptimize;
if (!_PyLong_IsCompact((PyLongObject *)left)) goto deoptimize;
if (!_PyLong_IsCompact((PyLongObject *)right)) goto deoptimize;
STAT_INC(COMPARE_OP, hit);
@@ -2150,8 +2146,6 @@
oparg = CURRENT_OPARG();
right = stack_pointer[-1];
left = stack_pointer[-2];
- if (!PyUnicode_CheckExact(left)) goto deoptimize;
- if (!PyUnicode_CheckExact(right)) goto deoptimize;
STAT_INC(COMPARE_OP, hit);
int eq = _PyUnicode_Equal(left, right);
assert((oparg >> 5) == Py_EQ || (oparg >> 5) == Py_NE);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 324e53d..7899106 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -2026,20 +2026,26 @@
PyObject *right;
PyObject *left;
PyObject *res;
- /* Skip 1 cache entry */
+ // _GUARD_BOTH_FLOAT
right = stack_pointer[-1];
left = stack_pointer[-2];
- DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
- DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
- STAT_INC(COMPARE_OP, hit);
- double dleft = PyFloat_AS_DOUBLE(left);
- double dright = PyFloat_AS_DOUBLE(right);
- // 1 if NaN, 2 if <, 4 if >, 8 if ==; this matches low four bits of the oparg
- int sign_ish = COMPARISON_BIT(dleft, dright);
- _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
- _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
- res = (sign_ish & oparg) ? Py_True : Py_False;
- // It's always a bool, so we don't care about oparg & 16.
+ {
+ DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
+ DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
+ }
+ /* Skip 1 cache entry */
+ // _COMPARE_OP_FLOAT
+ {
+ STAT_INC(COMPARE_OP, hit);
+ double dleft = PyFloat_AS_DOUBLE(left);
+ double dright = PyFloat_AS_DOUBLE(right);
+ // 1 if NaN, 2 if <, 4 if >, 8 if ==; this matches low four bits of the oparg
+ int sign_ish = COMPARISON_BIT(dleft, dright);
+ _Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
+ _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
+ res = (sign_ish & oparg) ? Py_True : Py_False;
+ // It's always a bool, so we don't care about oparg & 16.
+ }
stack_pointer[-2] = res;
stack_pointer += -1;
DISPATCH();
@@ -2053,24 +2059,30 @@
PyObject *right;
PyObject *left;
PyObject *res;
- /* Skip 1 cache entry */
+ // _GUARD_BOTH_INT
right = stack_pointer[-1];
left = stack_pointer[-2];
- DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
- DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
- DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
- DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_OP);
- STAT_INC(COMPARE_OP, hit);
- assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
+ {
+ DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
+ DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
+ }
+ /* Skip 1 cache entry */
+ // _COMPARE_OP_INT
+ {
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_OP);
+ STAT_INC(COMPARE_OP, hit);
+ assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
_PyLong_DigitCount((PyLongObject *)right) <= 1);
- Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
- Py_ssize_t iright = _PyLong_CompactValue((PyLongObject *)right);
- // 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
- int sign_ish = COMPARISON_BIT(ileft, iright);
- _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
- _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
- res = (sign_ish & oparg) ? Py_True : Py_False;
- // It's always a bool, so we don't care about oparg & 16.
+ Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
+ Py_ssize_t iright = _PyLong_CompactValue((PyLongObject *)right);
+ // 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
+ int sign_ish = COMPARISON_BIT(ileft, iright);
+ _Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
+ _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
+ res = (sign_ish & oparg) ? Py_True : Py_False;
+ // It's always a bool, so we don't care about oparg & 16.
+ }
stack_pointer[-2] = res;
stack_pointer += -1;
DISPATCH();
@@ -2084,21 +2096,27 @@
PyObject *right;
PyObject *left;
PyObject *res;
- /* Skip 1 cache entry */
+ // _GUARD_BOTH_UNICODE
right = stack_pointer[-1];
left = stack_pointer[-2];
- DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
- DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
- STAT_INC(COMPARE_OP, hit);
- int eq = _PyUnicode_Equal(left, right);
- assert((oparg >> 5) == Py_EQ || (oparg >> 5) == Py_NE);
- _Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
- _Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
- assert(eq == 0 || eq == 1);
- assert((oparg & 0xf) == COMPARISON_NOT_EQUALS || (oparg & 0xf) == COMPARISON_EQUALS);
- assert(COMPARISON_NOT_EQUALS + 1 == COMPARISON_EQUALS);
- res = ((COMPARISON_NOT_EQUALS + eq) & oparg) ? Py_True : Py_False;
- // It's always a bool, so we don't care about oparg & 16.
+ {
+ DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
+ DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
+ }
+ /* Skip 1 cache entry */
+ // _COMPARE_OP_STR
+ {
+ STAT_INC(COMPARE_OP, hit);
+ int eq = _PyUnicode_Equal(left, right);
+ assert((oparg >> 5) == Py_EQ || (oparg >> 5) == Py_NE);
+ _Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
+ _Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
+ assert(eq == 0 || eq == 1);
+ assert((oparg & 0xf) == COMPARISON_NOT_EQUALS || (oparg & 0xf) == COMPARISON_EQUALS);
+ assert(COMPARISON_NOT_EQUALS + 1 == COMPARISON_EQUALS);
+ res = ((COMPARISON_NOT_EQUALS + eq) & oparg) ? Py_True : Py_False;
+ // It's always a bool, so we don't care about oparg & 16.
+ }
stack_pointer[-2] = res;
stack_pointer += -1;
DISPATCH();
diff --git a/Python/tier2_redundancy_eliminator_bytecodes.c b/Python/tier2_redundancy_eliminator_bytecodes.c
index 3f6e8ce..e9b556d 100644
--- a/Python/tier2_redundancy_eliminator_bytecodes.c
+++ b/Python/tier2_redundancy_eliminator_bytecodes.c
@@ -77,6 +77,14 @@ dummy_func(void) {
sym_set_type(right, &PyFloat_Type);
}
+ op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
+ if (sym_matches_type(left, &PyUnicode_Type) &&
+ sym_matches_type(right, &PyUnicode_Type)) {
+ REPLACE_OP(this_instr, _NOP, 0 ,0);
+ }
+ sym_set_type(left, &PyUnicode_Type);
+ sym_set_type(right, &PyUnicode_Type);
+ }
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
if (is_const(left) && is_const(right)) {
diff --git a/Python/tier2_redundancy_eliminator_cases.c.h b/Python/tier2_redundancy_eliminator_cases.c.h
index 904700a..f41fe32 100644
--- a/Python/tier2_redundancy_eliminator_cases.c.h
+++ b/Python/tier2_redundancy_eliminator_cases.c.h
@@ -351,6 +351,16 @@
}
case _GUARD_BOTH_UNICODE: {
+ _Py_UOpsSymType *right;
+ _Py_UOpsSymType *left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ if (sym_matches_type(left, &PyUnicode_Type) &&
+ sym_matches_type(right, &PyUnicode_Type)) {
+ REPLACE_OP(this_instr, _NOP, 0 ,0);
+ }
+ sym_set_type(left, &PyUnicode_Type);
+ sym_set_type(right, &PyUnicode_Type);
break;
}