diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 29 | ||||
-rw-r--r-- | Python/specialize.c | 14 |
2 files changed, 16 insertions, 27 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index b15c101..83309e2 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2267,13 +2267,16 @@ handle_eval_breaker: Py_DECREF(v); Py_DECREF(container); Py_DECREF(sub); - if (err != 0) + if (err != 0) { goto error; + } + JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR); DISPATCH(); } TARGET(STORE_SUBSCR_ADAPTIVE) { - if (oparg == 0) { + _PyStoreSubscrCache *cache = (_PyStoreSubscrCache *)next_instr; + if (cache->counter == 0) { PyObject *sub = TOP(); PyObject *container = SECOND(); next_instr--; @@ -2284,8 +2287,7 @@ handle_eval_breaker: } else { STAT_INC(STORE_SUBSCR, deferred); - // oparg is the adaptive cache counter - UPDATE_PREV_INSTR_OPARG(next_instr, oparg - 1); + cache->counter--; JUMP_TO_INSTRUCTION(STORE_SUBSCR); } } @@ -2312,6 +2314,7 @@ handle_eval_breaker: Py_DECREF(old_value); Py_DECREF(sub); Py_DECREF(list); + JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR); NOTRACE_DISPATCH(); } @@ -2328,6 +2331,7 @@ handle_eval_breaker: if (err != 0) { goto error; } + JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR); DISPATCH(); } @@ -5520,21 +5524,6 @@ opname ## _miss: \ JUMP_TO_INSTRUCTION(opname); \ } -#define MISS_WITH_OPARG_COUNTER(opname) \ -opname ## _miss: \ - { \ - STAT_INC(opname, miss); \ - uint8_t oparg = _Py_OPARG(next_instr[-1])-1; \ - UPDATE_PREV_INSTR_OPARG(next_instr, oparg); \ - assert(_Py_OPARG(next_instr[-1]) == oparg); \ - if (oparg == 0) /* too many cache misses */ { \ - oparg = ADAPTIVE_CACHE_BACKOFF; \ - next_instr[-1] = _Py_MAKECODEUNIT(opname ## _ADAPTIVE, oparg); \ - STAT_INC(opname, deopt); \ - } \ - JUMP_TO_INSTRUCTION(opname); \ - } - MISS_WITH_INLINE_CACHE(LOAD_ATTR) MISS_WITH_INLINE_CACHE(STORE_ATTR) MISS_WITH_INLINE_CACHE(LOAD_GLOBAL) @@ -5545,7 +5534,7 @@ MISS_WITH_INLINE_CACHE(BINARY_OP) MISS_WITH_INLINE_CACHE(COMPARE_OP) MISS_WITH_INLINE_CACHE(BINARY_SUBSCR) MISS_WITH_INLINE_CACHE(UNPACK_SEQUENCE) -MISS_WITH_OPARG_COUNTER(STORE_SUBSCR) +MISS_WITH_INLINE_CACHE(STORE_SUBSCR) binary_subscr_dict_error: { diff --git a/Python/specialize.c b/Python/specialize.c index dae4e3f..a11a76c 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -301,12 +301,11 @@ optimize(_Py_CODEUNIT *instructions, int len) uint8_t adaptive_opcode = adaptive_opcodes[opcode]; if (adaptive_opcode) { instructions[i] = _Py_MAKECODEUNIT(adaptive_opcode, oparg); - int caches = _PyOpcode_InlineCacheEntries[opcode]; // Make sure the adaptive counter is zero: - assert((caches ? instructions[i + 1] : oparg) == 0); + assert(instructions[i + 1] == 0); previous_opcode = -1; previous_oparg = -1; - i += caches; + i += _PyOpcode_InlineCacheEntries[opcode]; } else { assert(!_PyOpcode_InlineCacheEntries[opcode]); @@ -1313,6 +1312,7 @@ success: int _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *instr) { + _PyStoreSubscrCache *cache = (_PyStoreSubscrCache *)(instr + 1); PyTypeObject *container_type = Py_TYPE(container); if (container_type == &PyList_Type) { if (PyLong_CheckExact(sub)) { @@ -1320,7 +1320,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins && ((PyLongObject *)sub)->ob_digit[0] < (size_t)PyList_GET_SIZE(container)) { *instr = _Py_MAKECODEUNIT(STORE_SUBSCR_LIST_INT, - initial_counter_value()); + _Py_OPARG(*instr)); goto success; } else { @@ -1338,8 +1338,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins } } if (container_type == &PyDict_Type) { - *instr = _Py_MAKECODEUNIT(STORE_SUBSCR_DICT, - initial_counter_value()); + *instr = _Py_MAKECODEUNIT(STORE_SUBSCR_DICT, _Py_OPARG(*instr)); goto success; } #ifdef Py_STATS @@ -1406,11 +1405,12 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins fail: STAT_INC(STORE_SUBSCR, failure); assert(!PyErr_Occurred()); - *instr = _Py_MAKECODEUNIT(_Py_OPCODE(*instr), ADAPTIVE_CACHE_BACKOFF); + cache->counter = ADAPTIVE_CACHE_BACKOFF; return 0; success: STAT_INC(STORE_SUBSCR, success); assert(!PyErr_Occurred()); + cache->counter = initial_counter_value(); return 0; } |