Skip to content

Commit 509f3e2

Browse files
committed
JIT: Remove redundant branches to jump in the assembly optimizer
* Refactor JIT assembly optimizer making instructions instances not just strings * Remove redundant jumps and branches where legal to do so * Modifies _BINARY_OP_SUBSCR_STR_INT to avoid excessive inlining depth TEST_TEMPLATE: projects/python/templates/default PYTHON_OPTIONS: --configure-flags "--enable-experimental-jit" Jira: ENTLLT-8874 Change-Id: I605618c92814059bc63a1d16825a66d1824f3df2
1 parent 53ec7c8 commit 509f3e2

File tree

8 files changed

+220
-74
lines changed

8 files changed

+220
-74
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,10 @@ dummy_func(
982982
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
983983
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
984984
DEOPT_IF(PyUnicode_GET_LENGTH(str) <= index);
985-
// Specialize for reading an ASCII character from any string:
986-
Py_UCS4 c = PyUnicode_READ_CHAR(str, index);
987-
DEOPT_IF(Py_ARRAY_LENGTH(_Py_SINGLETON(strings).ascii) <= c);
985+
// Specialize for reading an ASCII character from an ASCII string:
986+
DEOPT_IF(!PyUnicode_IS_COMPACT_ASCII(str));
987+
uint8_t c = PyUnicode_1BYTE_DATA(str)[index];
988+
assert(c < 128);
988989
STAT_INC(BINARY_OP, hit);
989990
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
990991
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);

Python/executor_cases.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/jit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ set_bits(uint32_t *loc, uint8_t loc_start, uint64_t value, uint8_t value_start,
181181
#define IS_AARCH64_ADRP(I) (((I) & 0x9F000000) == 0x90000000)
182182
#define IS_AARCH64_BRANCH(I) (((I) & 0x7C000000) == 0x14000000)
183183
#define IS_AARCH64_BRANCH_COND(I) (((I) & 0x7C000000) == 0x54000000)
184+
#define IS_AARCH64_BRANCH_ZERO(I) (((I) & 0x7E000000) == 0x34000000)
184185
#define IS_AARCH64_TEST_AND_BRANCH(I) (((I) & 0x7E000000) == 0x36000000)
185186
#define IS_AARCH64_LDR_OR_STR(I) (((I) & 0x3B000000) == 0x39000000)
186187
#define IS_AARCH64_MOV(I) (((I) & 0x9F800000) == 0x92800000)
@@ -348,7 +349,7 @@ void
348349
patch_aarch64_19r(unsigned char *location, uint64_t value)
349350
{
350351
uint32_t *loc32 = (uint32_t *)location;
351-
assert(IS_AARCH64_BRANCH_COND(*loc32));
352+
assert(IS_AARCH64_BRANCH_COND(*loc32) || IS_AARCH64_BRANCH_ZERO(*loc32));
352353
value -= (uintptr_t)location;
353354
// Check that we're not out of range of 21 signed bits:
354355
assert((int64_t)value >= -(1 << 20));

Tools/cases_generator/analyzer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
614614
"PyUnicode_Concat",
615615
"PyUnicode_GET_LENGTH",
616616
"PyUnicode_READ_CHAR",
617+
"PyUnicode_IS_COMPACT_ASCII",
618+
"PyUnicode_1BYTE_DATA",
617619
"Py_ARRAY_LENGTH",
618620
"Py_FatalError",
619621
"Py_INCREF",

0 commit comments

Comments
 (0)