From 52f4ed16e0c330e7fe89d70ddb000dc9130609da Mon Sep 17 00:00:00 2001 From: wxue1 Date: Mon, 19 Sep 2022 18:51:34 -0700 Subject: [PATCH] Indirect call reduction for Jit code Changing indirect call to direct call for Jit code benefits the branch prediction, which gets 1% performance gain in our workload. Similarly, we change indirect jump to direct jump. Signed-off-by: Su, Tao Signed-off-by: Wang, Xue --- NEWS | 3 +++ ext/opcache/jit/zend_jit_x86.dasc | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 6de45231be4..bda2072d1b0 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,9 @@ PHP NEWS . Fixed bug GH-8805 (finfo returns wrong mime type for woff/woff2 files). (Anatol) +- Opcache: + . Added indirect call reduction for jit on x86 architectures. (wxue1) + 29 Sep 2022, PHP 8.1.11 - Core: diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index ba6e52abbcc..6c59cd54642 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -152,6 +152,11 @@ static size_t tsrm_tls_offset; #define IS_SIGNED_32BIT(val) ((((intptr_t)(val)) <= 0x7fffffff) && (((intptr_t)(val)) >= (-2147483647 - 1))) +/* Call range is before or after 2GB */ +#define MAY_USE_32BIT_ADDR(addr) \ + (IS_SIGNED_32BIT((char*)(addr) - (char*)dasm_buf) && \ + IS_SIGNED_32BIT((char*)(addr) - (char*)dasm_end)) + #define CAN_USE_AVX() (JIT_G(opt_flags) & allowed_opt_flags & ZEND_JIT_CPU_AVX) /* Not Implemented Yet */ @@ -353,7 +358,7 @@ static size_t tsrm_tls_offset; |.macro EXT_CALL, func, tmp_reg | .if X64 -|| if (IS_32BIT(dasm_end) && IS_32BIT(func)) { +|| if (MAY_USE_32BIT_ADDR(func)) { | call qword &func || } else { | LOAD_ADDR tmp_reg, func @@ -366,7 +371,7 @@ static size_t tsrm_tls_offset; |.macro EXT_JMP, func, tmp_reg | .if X64 -|| if (IS_32BIT(dasm_end) && IS_32BIT(func)) { +|| if (MAY_USE_32BIT_ADDR(func)) { | jmp qword &func || } else { | LOAD_ADDR tmp_reg, func