@@ -547,6 +547,14 @@ initial_counter_value(void) {
547
547
#define SPEC_FAIL_STRING_COMPARE 13
548
548
#define SPEC_FAIL_NOT_FOLLOWED_BY_COND_JUMP 14
549
549
#define SPEC_FAIL_BIG_INT 15
550
+ #define SPEC_FAIL_COMPARE_BYTES 16
551
+ #define SPEC_FAIL_COMPARE_TUPLE 17
552
+ #define SPEC_FAIL_COMPARE_LIST 18
553
+ #define SPEC_FAIL_COMPARE_SET 19
554
+ #define SPEC_FAIL_COMPARE_BOOL 20
555
+ #define SPEC_FAIL_COMPARE_BASEOBJECT 21
556
+ #define SPEC_FAIL_COMPARE_FLOAT_LONG 22
557
+ #define SPEC_FAIL_COMPARE_LONG_FLOAT 23
550
558
551
559
/* FOR_ITER */
552
560
#define SPEC_FAIL_ITER_GENERATOR 10
@@ -1764,6 +1772,43 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
1764
1772
adaptive -> counter = initial_counter_value ();
1765
1773
}
1766
1774
1775
+
1776
+ #ifdef Py_STATS
1777
+ static int
1778
+ compare_op_fail_kind (PyObject * lhs , PyObject * rhs )
1779
+ {
1780
+ if (Py_TYPE (lhs ) != Py_TYPE (rhs )) {
1781
+ if (PyFloat_CheckExact (lhs ) && PyLong_CheckExact (rhs )) {
1782
+ return SPEC_FAIL_COMPARE_FLOAT_LONG ;
1783
+ }
1784
+ if (PyLong_CheckExact (lhs ) && PyFloat_CheckExact (rhs )) {
1785
+ return SPEC_FAIL_COMPARE_LONG_FLOAT ;
1786
+ }
1787
+ return SPEC_FAIL_DIFFERENT_TYPES ;
1788
+ }
1789
+ if (PyBytes_CheckExact (lhs )) {
1790
+ return SPEC_FAIL_COMPARE_BYTES ;
1791
+ }
1792
+ if (PyTuple_CheckExact (lhs )) {
1793
+ return SPEC_FAIL_COMPARE_TUPLE ;
1794
+ }
1795
+ if (PyList_CheckExact (lhs )) {
1796
+ return SPEC_FAIL_COMPARE_LIST ;
1797
+ }
1798
+ if (PySet_CheckExact (lhs ) || PyFrozenSet_CheckExact (lhs )) {
1799
+ return SPEC_FAIL_COMPARE_SET ;
1800
+ }
1801
+ if (PyBool_Check (lhs )) {
1802
+ return SPEC_FAIL_COMPARE_BOOL ;
1803
+ }
1804
+ if (Py_TYPE (lhs )-> tp_richcompare == PyBaseObject_Type .tp_richcompare ) {
1805
+ return SPEC_FAIL_COMPARE_BASEOBJECT ;
1806
+ }
1807
+ return SPEC_FAIL_OTHER ;
1808
+ }
1809
+ #endif
1810
+
1811
+
1767
1812
static int compare_masks [] = {
1768
1813
// 1-bit: jump if less than
1769
1814
// 2-bit: jump if equal
@@ -1795,7 +1840,7 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
1795
1840
when_to_jump_mask = (1 | 2 | 4 ) & ~when_to_jump_mask ;
1796
1841
}
1797
1842
if (Py_TYPE (lhs ) != Py_TYPE (rhs )) {
1798
- SPECIALIZATION_FAIL (COMPARE_OP , SPEC_FAIL_DIFFERENT_TYPES );
1843
+ SPECIALIZATION_FAIL (COMPARE_OP , compare_op_fail_kind ( lhs , rhs ) );
1799
1844
goto failure ;
1800
1845
}
1801
1846
if (PyFloat_CheckExact (lhs )) {
@@ -1825,7 +1870,7 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
1825
1870
goto success ;
1826
1871
}
1827
1872
}
1828
- SPECIALIZATION_FAIL (COMPARE_OP , SPEC_FAIL_OTHER );
1873
+ SPECIALIZATION_FAIL (COMPARE_OP , compare_op_fail_kind ( lhs , rhs ) );
1829
1874
failure :
1830
1875
STAT_INC (COMPARE_OP , failure );
1831
1876
cache_backoff (adaptive );
0 commit comments