Skip to content

Jit arm64 #6982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 195 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
ba43682
Initial support of JIT/arm64
shqking Apr 1, 2021
f3ba648
Hybrid use of registers
shqking Apr 9, 2021
f4f56f6
Support failed JIT test case: assign_002.phpt
shqking Apr 8, 2021
a70fd3f
Support failed JIT test case: assign_010.phpt
shqking Apr 8, 2021
653de5d
Support failed JIT test case: assign_012.phpt
shqking Apr 8, 2021
d7cfa32
Support failed JIT test case: assign_027.phpt
shqking Apr 9, 2021
ba9bc3a
Support failed JIT test case: assign_024.phpt
shqking Apr 9, 2021
4816d0d
Support failed JIT test case: assign_022.phpt
shqking Apr 9, 2021
006d443
Support failed JIT test case: assign_025.phpt
shqking Apr 12, 2021
d8d7932
Support failed JIT test case: assign_026.phpt
shqking Apr 12, 2021
de21c29
Support failed JIT test case: assign_dim_op_001.phpt
shqking Apr 12, 2021
35f253a
Support failed JIT test case: assign_dim_002.phpt
shqking Apr 12, 2021
79f35b4
Support failed JIT test case: assign_static_prop_001.phpt
shqking Apr 12, 2021
5ac51a5
Support failed JIT test case: assign_036.phpt
shqking Apr 13, 2021
d0829f8
Support failed JIT test case: assign_035.phpt
shqking Apr 13, 2021
f3bba0b
Support failed JIT test case: fetch_dim_func_args_001.phpt
shqking Apr 13, 2021
81ad6a0
Support failed JIT test case: fetch_dim_r_002.phpt
shqking Apr 14, 2021
b02c0d1
Support failed JIT test case: fetch_dim_rw_001.phpt
shqking Apr 14, 2021
77c394e
Support failed JIT test case: fetch_obj_004.phpt
shqking Apr 14, 2021
64d647a
Support failed JIT test case: fetch_obj_002.phpt
shqking Apr 14, 2021
501a114
Support failed JIT test case: fetch_obj_003.phpt
shqking Apr 14, 2021
ecd7b53
Replace --SKIPIF-- by --EXTENSIONS--
dstogov Apr 19, 2021
9ac405d
JIT/AArch64: INIT_FCALL and DO_FCALL support for optimized function c…
dstogov Apr 19, 2021
a7fba63
Add necessary assertions on range for INIT_FCALL and DO_FCALL
shqking Apr 20, 2021
de06cba
Fix one bug in macro IF_GC_MAY_NOT_LEAK
shqking Apr 19, 2021
4244562
Support failed JIT test case: fetch_obj_001.phpt
shqking Apr 15, 2021
b32926f
Support failed JIT test case: cmp_001.phpt
shqking Apr 15, 2021
10ee8b0
Support failed JIT test case: cmp_002.phpt
shqking Apr 15, 2021
a00ab83
Support failed JIT test case: cmp_004.phpt
shqking Apr 15, 2021
4b79f5b
Support failed JIT test case: cmp_003.phpt
shqking Apr 16, 2021
bbb7bbf
Support failed JIT test case: shift_left_001.phpt
shqking Apr 16, 2021
e02b273
Support failed JIT test case: shift_left_002.phpt
shqking Apr 16, 2021
72a43d6
Support failed JIT test case: shift_right_001.phpt
shqking Apr 16, 2021
ad59423
Support failed JIT test case: shift_right_003.phpt
shqking Apr 16, 2021
d5de3b0
Support failed JIT test case: mod_001.phpt
shqking Apr 16, 2021
7a4a461
Support failed JIT test case: send_ref_001.phpt
shqking Apr 17, 2021
43a72ec
Support failed JIT test case: send_val_001.phpt
shqking Apr 17, 2021
613af25
Support failed JIT test case: send_var_ex_001.phpt
shqking Apr 17, 2021
f177ef8
Support failed JIT test case: jmpz_001.phpt
shqking Apr 17, 2021
3fa5551
Support failed JIT test case: jmpz_ex_001.phpt
shqking Apr 18, 2021
04a28a2
Support failed JIT test case: reg_alloc_003.phpt
shqking Apr 18, 2021
4d9fab6
Support failed JIT test case: reg_alloc_002.phpt
shqking Apr 18, 2021
d25ee30
Replace "brk #0" with "NIY" (Not Implemented Yet) macro
dstogov Apr 20, 2021
6f9ca89
Use NIY_STUB instead of NIY in stubs
dstogov Apr 20, 2021
af999b4
Avoid useless "flags" byte extraction (it was inspired by unsuitable x86
dstogov Apr 20, 2021
2f4208e
Trmporary disable PROFITABILITY_CHECKS for better test coverage
dstogov Apr 20, 2021
d74c652
Added tests for ASSIGN
dstogov Apr 20, 2021
46d7f02
Support for most "uncommon" ASSIGN cases
dstogov Apr 20, 2021
eaf8135
Support for missed case in zend_jit_tail_handler().
dstogov Apr 20, 2021
b462265
Support for IS_LONG SUB and XOR.
dstogov Apr 20, 2021
93c42f2
Support for bitwise operations with the same operands ($a ^ $a)
dstogov Apr 20, 2021
b4bf1d0
Support for bitwise operations with non-integer arguments
dstogov Apr 20, 2021
ee72128
Support for RECV/RECV_INIT
dstogov Apr 20, 2021
73e1f6e
Support for passing extra arguments.
dstogov Apr 20, 2021
9158774
Support for most cases of BOOL/BOOL_NOT/JMPZNZ/JMP[N]Z_EX
dstogov Apr 20, 2021
2b254a8
Support for DOUBLE math
dstogov Apr 20, 2021
ecce8ca
Updates for commits between 121a0f7 and 12dcf34
shqking Apr 21, 2021
d36e589
Remove the duplicate macro DOUBLE_GET_ZVAL_DVAL
shqking Apr 21, 2021
5d9e641
Revisit the encoding of immediate
shqking Apr 21, 2021
483de70
Support for LONG math (except of MUL overflow detection)
dstogov Apr 21, 2021
f512742
Remove dead conditions
dstogov Apr 21, 2021
95f1e4d
Fixed possible incorrect assumption if constant is a power of 2.
dstogov Apr 21, 2021
3218d0e
Support for INC/DEC
dstogov Apr 21, 2021
e091f7c
Support for CONCAT
dstogov Apr 21, 2021
8c68b36
Support for comparison opcodes
dstogov Apr 21, 2021
948b3d8
Support for BOOL/BOOL_NOT with DOUBLE operand
dstogov Apr 21, 2021
04fc674
Fixed copy/paste error
dstogov Apr 21, 2021
4f36e23
Support for IS_IDENTICAL/IS_NOT_IDENTICAL
dstogov Apr 21, 2021
84470b7
Support for FETCH_DIM* and ASSIGN_DIM (exception handling is incomplete)
dstogov Apr 21, 2021
8b3a28c
Don't use FPR1 for consistency with x86
dstogov Apr 22, 2021
575b1b7
Fixed incorrect register usage
dstogov Apr 22, 2021
44ff89e
Fixed copy/paste error
dstogov Apr 22, 2021
117945c
Accurate RETVAL register usage
dstogov Apr 22, 2021
ef01820
Support for ISSET_DIM
dstogov Apr 22, 2021
fd76e4c
Support for ASSIGN_OP
dstogov Apr 22, 2021
4156337
Support for ASSIGN_DIM_OP
dstogov Apr 22, 2021
38a7896
Support LONG MUL with overflow detection
shqking Apr 21, 2021
290e8a1
Support for SEND_VAL/SEND_VAR/SEND_REF/CHECK_FUNC_ARG/CHECK_UNDEF_ARGS
dstogov Apr 22, 2021
6e33f5b
Support for more cases in INIT_METHOD_CALL, DO_FCALL* and RETURN
dstogov Apr 22, 2021
de06ea3
Get rid of some NIY traps in DynADM macros
dstogov Apr 22, 2021
c6c8a13
Support for ECHO with non-constant operand
dstogov Apr 22, 2021
062c8c5
Support for missed IS_NOT_IDENTICAL cases
dstogov Apr 22, 2021
a02355f
Support for FREE and FE_FREE
dstogov Apr 22, 2021
9102c86
Support for DEFINED
dstogov Apr 22, 2021
15e4451
Support for STRLEN and COUNT
dstogov Apr 22, 2021
ca4c3e6
Support for moving between allocated registers
dstogov Apr 22, 2021
769aedc
Support for FE_RESET and FE_FETCH
dstogov Apr 22, 2021
69a3446
Fixed reference-countoing. Use 32-bit registers.
dstogov Apr 22, 2021
f353dd4
Support for FETCH_CONST
dstogov Apr 22, 2021
2166c67
Support for TYPE_CHECK
dstogov Apr 22, 2021
d45c8d0
Support for BIND_GLOBAL
dstogov Apr 22, 2021
95f0d3d
Support for FETCH_THIS, FETCH_OBJ, ASSIGN_OBJ and ASSIGN_OBJ_OP
dstogov Apr 22, 2021
026af85
Get rid of testing NIY_STUBs
dstogov Apr 22, 2021
1770d9d
Support for PRE/POST_INC/DEC_OBJ
dstogov Apr 22, 2021
0b4decb
Get rid of NIY in spill code
dstogov Apr 22, 2021
54ff3d6
Support for VERIFY_RETURN_TYPE, ISSET_ISEMPTY_CV, IN_ARRAY and ADD with
dstogov Apr 22, 2021
98595ba
Implement exceptional stubs
dstogov Apr 22, 2021
70dc50c
Get rid of NYI in call/return sequences
dstogov Apr 22, 2021
27c70fa
Temporary diable JIT for SWITCH and MATCH instructions (SWITCH should
dstogov Apr 22, 2021
bb5a4c4
Fixed INC/DEC_PROP (tests/classes/incdec_property_*.phpt)
dstogov Apr 23, 2021
ef4fb1a
Fixed load of incorrect size
dstogov Apr 23, 2021
684e9e8
Fixed map_ptr resolution
dstogov Apr 23, 2021
fffc3e0
Fixed compilation warnings
dstogov Apr 23, 2021
23579b1
Support for interupts
dstogov Apr 23, 2021
f8d1a69
Fixed type check
dstogov Apr 23, 2021
abfdf7c
Wrong register
dstogov Apr 23, 2021
685ea2a
Fixed condition and avoid usage of non-temporary registers
dstogov Apr 23, 2021
eb3f6f5
Disable unsuitable optimization
dstogov Apr 23, 2021
f916800
Fixed incorrect efree()
dstogov Apr 23, 2021
e27eec0
Create C call frames for helper functions that perform nested calls
dstogov Apr 23, 2021
ed1a375
Fixed type checks and return value handling
dstogov Apr 23, 2021
80c7567
Optimizing LONG MUL to SHIFT: refine the trigger condition and add ov…
shqking Apr 22, 2021
d0a35a8
Remove the TODO comments for DOUBLE CMP
shqking Apr 25, 2021
2febcc4
Support failed test case: switch_jumptable.phpt
shqking Apr 25, 2021
3ba9f5a
Fix the encoding of immediate for logical instructions
shqking Apr 25, 2021
6b8b8c4
Add the helper to check whether an immediate is valid for logical ins…
shqking Apr 26, 2021
23e0f36
Added missed UNDEF_OPLINE_RESULT
dstogov Apr 26, 2021
e93acac
typo
dstogov Apr 26, 2021
7707391
Duplicate return
dstogov Apr 26, 2021
bd4d780
Missed instruction
dstogov Apr 26, 2021
51497de
Make bit helpers to be inline
dstogov Apr 26, 2021
576f4ee
Use "red zone" for HYBRID VM.
dstogov Apr 26, 2021
7fac916
Disable "red zone" usage (it leads to crashes).
dstogov Apr 26, 2021
af748cd
Support for ZTS
dstogov Apr 26, 2021
c2e9ffa
Enable register allocator (it was disabled because ZREG_NUM wasn't
dstogov Apr 26, 2021
39ca5f4
Fixed some compilation warnings
dstogov Apr 27, 2021
d185883
Remove the unnecessary 'bvs' check for IS_NOT_IDENTICAL case
shqking Apr 27, 2021
59c3019
Optimizing LONG MUL to SHIFT: add overflow detection for x86
shqking Apr 27, 2021
b08a2d2
Support ZEND_JIT_ON_PROF_REQUEST mode
shqking Apr 27, 2021
3b325ca
Support ZEND_JIT_ON_HOT_COUNTERS mode
shqking Apr 27, 2021
ae6cce3
Implement obvious trace side exits
dstogov Apr 27, 2021
3e30872
Fixed incorrect register usage
dstogov Apr 27, 2021
9ab8d53
Implement trace patching
dstogov Apr 27, 2021
ea75099
Fix incorrect macro LDR_STR_PIMM
shqking Apr 27, 2021
203bd0f
Add the missing parts for macros ZVAL_COPY_CONST and ZVAL_COPY_CONST_2
shqking Apr 27, 2021
bf5312b
Fixed assertion
dstogov Apr 28, 2021
dff047f
Support for tracin JIT (incomplete, but abble to run Zend/bench.php)
dstogov Apr 28, 2021
cb9925f
Support for tracing JIT
dstogov Apr 28, 2021
dfae2fb
Fixed register allocation.
dstogov Apr 28, 2021
e599da5
Attempt to fix Windows build
dstogov Apr 28, 2021
df8f1a1
ZREG_REG0 is not available in x86 build
dstogov Apr 28, 2021
d0eb8ec
Use TST_32_WITH_CONST macro
dstogov Apr 29, 2021
99c738e
Remove useless SAFE_MEM_ACC_WITH_UOFFSET*
dstogov Apr 29, 2021
a72dbda
Fixed signed/unsigned comparison mess
dstogov Apr 29, 2021
4418fdb
Revisit 32-bit logical operations with constants
shqking Apr 29, 2021
770cc44
Moved tests from ext/opcache/tests/jit/arm64 to ext/opcache/tests/jit
dstogov Apr 29, 2021
7df7b63
Fixed signed/unsigned comparison mess and add one missing case
dstogov Apr 29, 2021
7539a1e
Temporary disable PROFITABILITY_CHECKS for better test coverage and to
dstogov Apr 29, 2021
2b17ea2
Skip 64-bit related tests on 32-bit platforms
dstogov Apr 29, 2021
5f2695d
Don't optimize MUL into SHIFT if we have to check for overflow
dstogov Apr 29, 2021
1ff2a6c
Improve code for MUL overflow detection (less instructions and less
dstogov Apr 29, 2021
90a2cfc
Optimize AArch64 code generator
dstogov Apr 30, 2021
749361f
Introduce CMP_64_WITH_CONST/CMP_64_WITH_CONST_32/CMP_32_WITH_CONST ma…
dstogov Apr 30, 2021
4128c7b
Introduce ADD_SUB_64_WITH_CONST/ADD_SUB_64_WITH_CONST_32/ADD_SUB_32_W…
dstogov Apr 30, 2021
f294dd6
Use less temporary registers
dstogov Apr 30, 2021
dc6cd83
Use single instruction
dstogov Apr 30, 2021
a700819
Imroved code for CV initialization
dstogov Apr 30, 2021
13131f6
Imroved code for constants loading
dstogov Apr 30, 2021
d0be78f
Use B/BL intead of BR/BLR if possible
dstogov Apr 30, 2021
943361e
Fix compilation warning
dstogov Apr 30, 2021
6102bf7
Use proper macro
dstogov May 7, 2021
167ca3e
'lea' -> 'add'
dstogov May 7, 2021
15c134b
Don't use TMP3 except ZTS
shqking May 6, 2021
b8db3a6
Use ADD_SUB_IMM for macros ADD_SUB_*_WITH_CONST*
shqking May 6, 2021
34e9c6b
Use macros CMP_*_WITH_CONST if possible
shqking May 6, 2021
5d7cb19
Remove the deprecated macros
shqking May 6, 2021
449ddf1
Improve macro LONG_ADD_SUB_WITH_IMM
shqking May 6, 2021
7f7c3c8
Use fewer temporary registers if possible
shqking May 6, 2021
d6b9430
Fix commit 6e344ed: temporary register should be kept for GET_ZVAL_LVAL
shqking May 10, 2021
0616615
Fixed profile based JIT (opcache.jit=1225)
dstogov May 11, 2021
24cfa42
Revert the macro uses for Z_TYPE_P(val) in commit 1fff62b
shqking May 11, 2021
e8b6dae
Fixed JIT failure on Zend/tests/bug43175.phpt ZTS build, CALL VM.
dstogov May 11, 2021
3e2517b
Fix compilation warnings
dstogov May 11, 2021
e0e292d
Use better code for prologue and fix code generaion for "return -1".
dstogov May 11, 2021
ca9ec95
Peephole Code Optimization:
dstogov May 11, 2021
f2f2904
Fixed incorrect stack size calculation (sizeof(zval) == 16)
dstogov May 11, 2021
d88f21f
Fix commit 8143a49: macro ADD_SUB_64_WITH_CONST_32 should be used
shqking May 12, 2021
287d996
Fixed incorrect range check (missed sign bit)
dstogov May 12, 2021
272edad
Reenable PROFITABILITY_CHECKS
dstogov May 12, 2021
dbd0bfc
Implemented AArch64 support for GDB/JIT interface.
dstogov May 12, 2021
8ab1f6b
Fixed JIT memory usage debug info (opcache.jit_debug=0x200)
dstogov May 12, 2021
f6df3b0
Allow to print JIT assemble without binary addresses (opcache.jit_deb…
dstogov May 12, 2021
b61697e
Remove unused TMP4. Use intra-precedure call scratch registers for TM…
dstogov May 12, 2021
416b3bb
Use better code for trace exits. Don't store CPU registers that can't…
dstogov May 12, 2021
60436b3
Use symbolic labels for BL and ADR instructions
dstogov May 12, 2021
dc89a2d
Fixed ZTS build.
dstogov May 13, 2021
9aa463c
DynASM/ARM64: Add abiulity to plug-in generation of veneers to perfor…
dstogov May 13, 2021
303ec3c
Generate veneers to perform long jumps.
dstogov May 13, 2021
dcbf25f
JIT/AArch64: disable register allocation for expected ++/-- overflow …
dstogov May 14, 2021
cd443ec
Fixed format specifier
dstogov May 14, 2021
835280b
Fix "store to misaligned address" ASAN warnings
dstogov May 17, 2021
0ebf7cc
Fixed JIT failure after overflow detection (bench.php failure in 32-bit
dstogov May 17, 2021
8f6bea4
Fixed possible failure when repair after overflow detection
dstogov May 17, 2021
e1e5aed
Remove unnecessary #ifdef
dstogov May 18, 2021
7210c31
Fixed zend_long_is_power_of_two/zend_long_floor_log2 mess
dstogov May 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions TSRM/TSRM.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ TSRM_API size_t tsrm_get_ls_cache_tcb_offset(void)
asm ("leal _tsrm_ls_cache@ntpoff,%0"
: "=r" (ret));
return ret;
#elif defined(__aarch64__)
size_t ret;

asm("mov %0, xzr\n\t"
"add %0, %0, #:tprel_hi12:_tsrm_ls_cache, lsl #12\n\t"
"add %0, %0, #:tprel_lo12_nc:_tsrm_ls_cache"
: "=r" (ret));
return ret;
#else
return 0;
#endif
Expand Down
1 change: 1 addition & 0 deletions build/Makefile.global
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ clean:
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la $(SAPI_CLI_PATH) $(SAPI_CGI_PATH) $(SAPI_LITESPEED_PATH) $(SAPI_FPM_PATH) $(OVERALL_TARGET) modules/* libs/*
rm -f ext/opcache/jit/zend_jit_x86.c
rm -f ext/opcache/jit/zend_jit_arm64.c

distclean: clean
rm -f Makefile config.cache config.log config.status Makefile.objects Makefile.fragments libtool main/php_config.h main/internal_functions_cli.c main/internal_functions.c Zend/zend_dtrace_gen.h Zend/zend_dtrace_gen.h.bak Zend/zend_config.h
Expand Down
3 changes: 2 additions & 1 deletion ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if test "$PHP_OPCACHE" != "no"; then

if test "$PHP_OPCACHE_JIT" = "yes"; then
case $host_cpu in
i[[34567]]86*|x86*)
i[[34567]]86*|x86*|aarch64)
;;
*)
AC_MSG_WARN([JIT not supported by host architecture])
Expand Down Expand Up @@ -77,6 +77,7 @@ if test "$PHP_OPCACHE" != "no"; then
fi

PHP_SUBST(DASM_FLAGS)
PHP_SUBST(DASM_ARCH)

AC_MSG_CHECKING(for opagent in default path)
for i in /usr/local /usr; do
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (PHP_OPCACHE != "no") {
dasm_flags += " -D ZTS=1";
}
DEFINE("DASM_FLAGS", dasm_flags);
DEFINE("DASM_ARCH", "x86");

AC_DEFINE('HAVE_JIT', 1, 'Define to enable JIT');
/* XXX read this dynamically */
Expand Down
6 changes: 3 additions & 3 deletions ext/opcache/jit/Makefile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
$(builddir)/minilua: $(srcdir)/jit/dynasm/minilua.c
$(BUILD_CC) $(srcdir)/jit/dynasm/minilua.c -lm -o $@

$(builddir)/jit/zend_jit_x86.c: $(srcdir)/jit/zend_jit_x86.dasc $(srcdir)/jit/dynasm/*.lua $(builddir)/minilua
$(builddir)/minilua $(srcdir)/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(srcdir)/jit/zend_jit_x86.dasc
$(builddir)/jit/zend_jit_$(DASM_ARCH).c: $(srcdir)/jit/zend_jit_$(DASM_ARCH).dasc $(srcdir)/jit/dynasm/*.lua $(builddir)/minilua
$(builddir)/minilua $(srcdir)/jit/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(srcdir)/jit/zend_jit_$(DASM_ARCH).dasc

$(builddir)/jit/zend_jit.lo: \
$(builddir)/jit/zend_jit_x86.c \
$(builddir)/jit/zend_jit_$(DASM_ARCH).c \
$(srcdir)/jit/zend_jit_helpers.c \
$(srcdir)/jit/zend_jit_disasm.c \
$(srcdir)/jit/zend_jit_gdb.c \
Expand Down
21 changes: 15 additions & 6 deletions ext/opcache/jit/dynasm/dasm_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,15 @@ int dasm_link(Dst_DECL, size_t *szp)
return DASM_S_OK;
}

#ifdef DASM_ADD_VENEER
#define CK_REL(x, o) \
do { if (!(x) && !(n = DASM_ADD_VENEER(D, buffer, ins, b, cp, o))) \
return DASM_S_RANGE_REL|(p-D->actionlist-1); \
} while (0)
#else
#define CK_REL(x, o) CK(x, RANGE_REL)
#endif

#ifdef DASM_CHECKS
#define CK(x, st) \
do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
Expand Down Expand Up @@ -444,7 +453,7 @@ int dasm_encode(Dst_DECL, void *buffer)
if (n < 0) {
ptrdiff_t na = (ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4;
n = (int)na;
CK((ptrdiff_t)n == na, RANGE_REL);
CK_REL((ptrdiff_t)n == na, na);
goto patchrel;
}
/* fallthrough */
Expand All @@ -453,18 +462,18 @@ int dasm_encode(Dst_DECL, void *buffer)
n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) + 4;
patchrel:
if (!(ins & 0xf800)) { /* B, BL */
CK((n & 3) == 0 && ((n+0x08000000) >> 28) == 0, RANGE_REL);
CK_REL((n & 3) == 0 && ((n+0x08000000) >> 28) == 0, n);
cp[-1] |= ((n >> 2) & 0x03ffffff);
} else if ((ins & 0x800)) { /* B.cond, CBZ, CBNZ, LDR* literal */
CK((n & 3) == 0 && ((n+0x00100000) >> 21) == 0, RANGE_REL);
CK_REL((n & 3) == 0 && ((n+0x00100000) >> 21) == 0, n);
cp[-1] |= ((n << 3) & 0x00ffffe0);
} else if ((ins & 0x3000) == 0x2000) { /* ADR */
CK(((n+0x00100000) >> 21) == 0, RANGE_REL);
CK_REL(((n+0x00100000) >> 21) == 0, n);
cp[-1] |= ((n << 3) & 0x00ffffe0) | ((n & 3) << 29);
} else if ((ins & 0x3000) == 0x3000) { /* ADRP */
cp[-1] |= ((n >> 9) & 0x00ffffe0) | (((n >> 12) & 3) << 29);
} else if ((ins & 0x1000)) { /* TBZ, TBNZ */
CK((n & 3) == 0 && ((n+0x00008000) >> 16) == 0, RANGE_REL);
CK_REL((n & 3) == 0 && ((n+0x00008000) >> 16) == 0, n);
cp[-1] |= ((n << 3) & 0x0007ffe0);
} else if ((ins & 0x8000)) { /* absolute */
cp[0] = (unsigned int)((ptrdiff_t)cp - 4 + n);
Expand All @@ -475,7 +484,7 @@ int dasm_encode(Dst_DECL, void *buffer)
case DASM_REL_A: {
ptrdiff_t na = (((ptrdiff_t)(*b++) << 32) | (unsigned int)n) - (ptrdiff_t)cp + 4;
n = (int)na;
CK((ptrdiff_t)n == na, RANGE_REL);
CK_REL((ptrdiff_t)n == na, na);
goto patchrel;
}
case DASM_LABEL_LG:
Expand Down
67 changes: 57 additions & 10 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
#include "Optimizer/zend_call_graph.h"
#include "Optimizer/zend_dump.h"

#if defined(__x86_64__) || defined(i386) || defined(ZEND_WIN32)
#include "jit/zend_jit_x86.h"
#elif defined (__aarch64__)
#include "jit/zend_jit_arm64.h"
#else
#error "JIT not supported on this platform"
#endif

#include "jit/zend_jit_internal.h"

#ifdef ZTS
Expand Down Expand Up @@ -188,11 +195,6 @@ static bool zend_is_commutative(zend_uchar opcode)
opcode == ZEND_BW_XOR;
}

static bool zend_long_is_power_of_two(zend_long x)
{
return (x > 0) && !(x & (x - 1));
}

#define OP_RANGE(ssa_op, opN) \
(((opline->opN##_type & (IS_TMP_VAR|IS_VAR|IS_CV)) && \
ssa->var_info && \
Expand All @@ -204,19 +206,30 @@ static bool zend_long_is_power_of_two(zend_long x)
#define OP2_RANGE() OP_RANGE(ssa_op, op2)
#define OP1_DATA_RANGE() OP_RANGE(ssa_op + 1, op1)

#if defined(__x86_64__) || defined(i386) || defined(ZEND_WIN32)
#include "dynasm/dasm_x86.h"
#elif defined(__aarch64__)
static int zend_jit_add_veneer(dasm_State *Dst, void *buffer, uint32_t ins, int *b, uint32_t *cp, ptrdiff_t offset);
#define DASM_ADD_VENEER zend_jit_add_veneer
#include "dynasm/dasm_arm64.h"
#endif

#include "jit/zend_jit_helpers.c"
#include "jit/zend_jit_disasm.c"
#ifndef _WIN32
#include "jit/zend_jit_gdb.c"
#include "jit/zend_jit_perf_dump.c"
# include "jit/zend_jit_gdb.c"
# include "jit/zend_jit_perf_dump.c"
#endif
#ifdef HAVE_OPROFILE
# include "jit/zend_jit_oprofile.c"
#endif
#include "jit/zend_jit_vtune.c"

#if defined(__x86_64__) || defined(i386) || defined(ZEND_WIN32)
#include "jit/zend_jit_vtune.c"
#include "jit/zend_jit_x86.c"
#elif defined(__aarch64__)
#include "jit/zend_jit_arm64.c"
#endif

#if _WIN32
# include <Windows.h>
Expand Down Expand Up @@ -298,15 +311,32 @@ static void handle_dasm_error(int ret) {
case DASM_S_RANGE_PC:
fprintf(stderr, "DASM_S_RANGE_PC %d\n", ret & 0xffffffu);
break;
#ifdef DASM_S_RANGE_VREG
case DASM_S_RANGE_VREG:
fprintf(stderr, "DASM_S_RANGE_VREG\n");
break;
#endif
#ifdef DASM_S_UNDEF_L
case DASM_S_UNDEF_L:
fprintf(stderr, "DASM_S_UNDEF_L\n");
break;
#endif
#ifdef DASM_S_UNDEF_LG
case DASM_S_UNDEF_LG:
fprintf(stderr, "DASM_S_UNDEF_LG\n");
break;
#endif
#ifdef DASM_S_RANGE_REL
case DASM_S_RANGE_REL:
fprintf(stderr, "DASM_S_RANGE_REL\n");
break;
#endif
case DASM_S_UNDEF_PC:
fprintf(stderr, "DASM_S_UNDEF_PC\n");
break;
default:
fprintf(stderr, "DASM_S_%0x\n", ret & 0xff000000u);
break;
}
ZEND_UNREACHABLE();
}
Expand Down Expand Up @@ -380,6 +410,10 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
return NULL;
}

#ifdef __aarch64__
dasm_venners_size = 0;
#endif

ret = dasm_encode(dasm_state, *dasm_ptr);
if (ret != DASM_S_OK) {
#if ZEND_DEBUG
Expand All @@ -388,9 +422,16 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
return NULL;
}

#ifdef __aarch64__
size += dasm_venners_size;
#endif

entry = *dasm_ptr;
*dasm_ptr = (void*)((char*)*dasm_ptr + ZEND_MM_ALIGNED_SIZE_EX(size, DASM_ALIGNMENT));

/* flush the hardware I-cache */
JIT_CACHE_FLUSH(entry, entry + size);

if (trace_num) {
zend_jit_trace_add_code(entry, size);
}
Expand Down Expand Up @@ -4365,8 +4406,14 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached)
return FAILURE;
}

/* save JIT buffer pos */
zend_jit_unprotect();
#ifdef __aarch64__
/* reserve space for global labels veneers */
dasm_labels_veneers = *dasm_ptr;
*dasm_ptr = (void**)*dasm_ptr + zend_lb_MAX;
memset(dasm_labels_veneers, 0, sizeof(void*) * zend_lb_MAX);
#endif
/* save JIT buffer pos */
dasm_ptr[1] = dasm_ptr[0];
zend_jit_protect();

Expand All @@ -4376,7 +4423,7 @@ ZEND_EXT_API int zend_jit_startup(void *buf, size_t size, bool reattached)
ZEND_EXT_API void zend_jit_shutdown(void)
{
if (JIT_G(debug) & ZEND_JIT_DEBUG_SIZE) {
fprintf(stderr, "\nJIT memory usage: %td\n", (char*)*dasm_ptr - (char*)dasm_buf);
fprintf(stderr, "\nJIT memory usage: %td\n", (ptrdiff_t)((char*)*dasm_ptr - (char*)dasm_buf));
}

#ifdef HAVE_OPROFILE
Expand Down
1 change: 1 addition & 0 deletions ext/opcache/jit/zend_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#define ZEND_JIT_DEBUG_GDB (1<<8)
#define ZEND_JIT_DEBUG_SIZE (1<<9)
#define ZEND_JIT_DEBUG_ASM_ADDR (1<<10)

#define ZEND_JIT_DEBUG_TRACE_START (1<<12)
#define ZEND_JIT_DEBUG_TRACE_STOP (1<<13)
Expand Down
Loading