Skip to content

opcache/jit support: Mac M1 build fic #6885

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 165 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
6b64898
Initial support of JIT/arm64
shqking Apr 1, 2021
1b19921
Hybrid use of registers
shqking Apr 9, 2021
a27474a
Support failed JIT test case: assign_002.phpt
shqking Apr 8, 2021
fd864f4
Support failed JIT test case: assign_010.phpt
shqking Apr 8, 2021
525ea70
Support failed JIT test case: assign_012.phpt
shqking Apr 8, 2021
132e675
Support failed JIT test case: assign_027.phpt
shqking Apr 9, 2021
9e37ddb
Support failed JIT test case: assign_024.phpt
shqking Apr 9, 2021
d594509
Support failed JIT test case: assign_022.phpt
shqking Apr 9, 2021
6bb7b98
Support failed JIT test case: assign_025.phpt
shqking Apr 12, 2021
e72da3e
Support failed JIT test case: assign_026.phpt
shqking Apr 12, 2021
01f6363
Support failed JIT test case: assign_dim_op_001.phpt
shqking Apr 12, 2021
11d4925
Support failed JIT test case: assign_dim_002.phpt
shqking Apr 12, 2021
ed6aca7
Support failed JIT test case: assign_static_prop_001.phpt
shqking Apr 12, 2021
a2ee26b
Support failed JIT test case: assign_036.phpt
shqking Apr 13, 2021
7df7cd7
Support failed JIT test case: assign_035.phpt
shqking Apr 13, 2021
dc1b5ee
Support failed JIT test case: fetch_dim_func_args_001.phpt
shqking Apr 13, 2021
0f6e663
Support failed JIT test case: fetch_dim_r_002.phpt
shqking Apr 14, 2021
34608cf
Support failed JIT test case: fetch_dim_rw_001.phpt
shqking Apr 14, 2021
1a6d135
Support failed JIT test case: fetch_obj_004.phpt
shqking Apr 14, 2021
ebc3357
Support failed JIT test case: fetch_obj_002.phpt
shqking Apr 14, 2021
065650c
Support failed JIT test case: fetch_obj_003.phpt
shqking Apr 14, 2021
1950c28
Replace --SKIPIF-- by --EXTENSIONS--
dstogov Apr 19, 2021
57ef76d
JIT/AArch64: INIT_FCALL and DO_FCALL support for optimized function c…
dstogov Apr 19, 2021
83c2228
Add necessary assertions on range for INIT_FCALL and DO_FCALL
shqking Apr 20, 2021
55b4bc8
Fix one bug in macro IF_GC_MAY_NOT_LEAK
shqking Apr 19, 2021
fcf437d
Support failed JIT test case: fetch_obj_001.phpt
shqking Apr 15, 2021
a379e68
Support failed JIT test case: cmp_001.phpt
shqking Apr 15, 2021
2f108d1
Support failed JIT test case: cmp_002.phpt
shqking Apr 15, 2021
e8dee08
Support failed JIT test case: cmp_004.phpt
shqking Apr 15, 2021
1b1b04b
Support failed JIT test case: cmp_003.phpt
shqking Apr 16, 2021
d205cc7
Support failed JIT test case: shift_left_001.phpt
shqking Apr 16, 2021
c8cb9e6
Support failed JIT test case: shift_left_002.phpt
shqking Apr 16, 2021
8976197
Support failed JIT test case: shift_right_001.phpt
shqking Apr 16, 2021
8119d47
Support failed JIT test case: shift_right_003.phpt
shqking Apr 16, 2021
49667f2
Support failed JIT test case: mod_001.phpt
shqking Apr 16, 2021
9afe5d7
Support failed JIT test case: send_ref_001.phpt
shqking Apr 17, 2021
131373f
Support failed JIT test case: send_val_001.phpt
shqking Apr 17, 2021
a4a918f
Support failed JIT test case: send_var_ex_001.phpt
shqking Apr 17, 2021
e5abd1f
Support failed JIT test case: jmpz_001.phpt
shqking Apr 17, 2021
9b20abe
Support failed JIT test case: jmpz_ex_001.phpt
shqking Apr 18, 2021
a2dbb1d
Support failed JIT test case: reg_alloc_003.phpt
shqking Apr 18, 2021
1c3f173
Support failed JIT test case: reg_alloc_002.phpt
shqking Apr 18, 2021
1740550
Replace "brk #0" with "NIY" (Not Implemented Yet) macro
dstogov Apr 20, 2021
64d57f3
Use NIY_STUB instead of NIY in stubs
dstogov Apr 20, 2021
d5f4308
Avoid useless "flags" byte extraction (it was inspired by unsuitable x86
dstogov Apr 20, 2021
691e212
Trmporary disable PROFITABILITY_CHECKS for better test coverage
dstogov Apr 20, 2021
65dde96
Added tests for ASSIGN
dstogov Apr 20, 2021
5c8b134
Support for most "uncommon" ASSIGN cases
dstogov Apr 20, 2021
e7d3d29
Support for missed case in zend_jit_tail_handler().
dstogov Apr 20, 2021
aa831b8
Support for IS_LONG SUB and XOR.
dstogov Apr 20, 2021
37700ec
Support for bitwise operations with the same operands ($a ^ $a)
dstogov Apr 20, 2021
b273047
Support for bitwise operations with non-integer arguments
dstogov Apr 20, 2021
4396977
Support for RECV/RECV_INIT
dstogov Apr 20, 2021
e4d1ab1
Support for passing extra arguments.
dstogov Apr 20, 2021
1fc8278
Support for most cases of BOOL/BOOL_NOT/JMPZNZ/JMP[N]Z_EX
dstogov Apr 20, 2021
bcf4bec
Support for DOUBLE math
dstogov Apr 20, 2021
ef22a04
Updates for commits between 121a0f7 and 12dcf34
shqking Apr 21, 2021
e5903d8
Remove the duplicate macro DOUBLE_GET_ZVAL_DVAL
shqking Apr 21, 2021
9ad29c3
Revisit the encoding of immediate
shqking Apr 21, 2021
2b45d29
Support for LONG math (except of MUL overflow detection)
dstogov Apr 21, 2021
41d07bd
Remove dead conditions
dstogov Apr 21, 2021
e369d10
Fixed possible incorrect assumption if constant is a power of 2.
dstogov Apr 21, 2021
7b2fafd
Support for INC/DEC
dstogov Apr 21, 2021
4e54daa
Support for CONCAT
dstogov Apr 21, 2021
24a4296
Support for comparison opcodes
dstogov Apr 21, 2021
a540962
Support for BOOL/BOOL_NOT with DOUBLE operand
dstogov Apr 21, 2021
7268364
Fixed copy/paste error
dstogov Apr 21, 2021
d44bde6
Support for IS_IDENTICAL/IS_NOT_IDENTICAL
dstogov Apr 21, 2021
fe793c1
Support for FETCH_DIM* and ASSIGN_DIM (exception handling is incomplete)
dstogov Apr 21, 2021
e3554de
Don't use FPR1 for consistency with x86
dstogov Apr 22, 2021
7b523f5
Fixed incorrect register usage
dstogov Apr 22, 2021
bb8ca9c
Fixed copy/paste error
dstogov Apr 22, 2021
ea6d866
Accurate RETVAL register usage
dstogov Apr 22, 2021
3e316da
Support for ISSET_DIM
dstogov Apr 22, 2021
459004b
Support for ASSIGN_OP
dstogov Apr 22, 2021
2413f0f
Support for ASSIGN_DIM_OP
dstogov Apr 22, 2021
578eb2e
Support LONG MUL with overflow detection
shqking Apr 21, 2021
5fac6aa
Support for SEND_VAL/SEND_VAR/SEND_REF/CHECK_FUNC_ARG/CHECK_UNDEF_ARGS
dstogov Apr 22, 2021
fa10c32
Support for more cases in INIT_METHOD_CALL, DO_FCALL* and RETURN
dstogov Apr 22, 2021
a87e871
Get rid of some NIY traps in DynADM macros
dstogov Apr 22, 2021
fd5a12b
Support for ECHO with non-constant operand
dstogov Apr 22, 2021
deb40ce
Support for missed IS_NOT_IDENTICAL cases
dstogov Apr 22, 2021
791572e
Support for FREE and FE_FREE
dstogov Apr 22, 2021
f22f2af
Support for DEFINED
dstogov Apr 22, 2021
9124bc5
Support for STRLEN and COUNT
dstogov Apr 22, 2021
f6a1279
Support for moving between allocated registers
dstogov Apr 22, 2021
23de7f4
Support for FE_RESET and FE_FETCH
dstogov Apr 22, 2021
eaf40bc
Fixed reference-countoing. Use 32-bit registers.
dstogov Apr 22, 2021
c51ce79
Support for FETCH_CONST
dstogov Apr 22, 2021
dee8e87
Support for TYPE_CHECK
dstogov Apr 22, 2021
50ae6b8
Support for BIND_GLOBAL
dstogov Apr 22, 2021
d19d269
Support for FETCH_THIS, FETCH_OBJ, ASSIGN_OBJ and ASSIGN_OBJ_OP
dstogov Apr 22, 2021
02bd77f
Get rid of testing NIY_STUBs
dstogov Apr 22, 2021
dd8f84e
Support for PRE/POST_INC/DEC_OBJ
dstogov Apr 22, 2021
ddb41c2
Get rid of NIY in spill code
dstogov Apr 22, 2021
fc30232
Support for VERIFY_RETURN_TYPE, ISSET_ISEMPTY_CV, IN_ARRAY and ADD with
dstogov Apr 22, 2021
331792d
Implement exceptional stubs
dstogov Apr 22, 2021
7771c7a
Get rid of NYI in call/return sequences
dstogov Apr 22, 2021
a8bb872
Temporary diable JIT for SWITCH and MATCH instructions (SWITCH should
dstogov Apr 22, 2021
aa7d359
Fixed INC/DEC_PROP (tests/classes/incdec_property_*.phpt)
dstogov Apr 23, 2021
a5852b2
Fixed load of incorrect size
dstogov Apr 23, 2021
996667d
Fixed map_ptr resolution
dstogov Apr 23, 2021
eed512e
Fixed compilation warnings
dstogov Apr 23, 2021
6806c4c
Support for interupts
dstogov Apr 23, 2021
bd75fd4
Fixed type check
dstogov Apr 23, 2021
7102b4b
Wrong register
dstogov Apr 23, 2021
6d8795f
Fixed condition and avoid usage of non-temporary registers
dstogov Apr 23, 2021
5fde196
Disable unsuitable optimization
dstogov Apr 23, 2021
dfa6018
Fixed incorrect efree()
dstogov Apr 23, 2021
d8ea7ab
Create C call frames for helper functions that perform nested calls
dstogov Apr 23, 2021
db2891e
Fixed type checks and return value handling
dstogov Apr 23, 2021
f1e3838
Optimizing LONG MUL to SHIFT: refine the trigger condition and add ov…
shqking Apr 22, 2021
7069462
Remove the TODO comments for DOUBLE CMP
shqking Apr 25, 2021
61b92be
DynASM/arm64: support 64-bit jump table
shqking Apr 25, 2021
2b78e52
Support failed test case: switch_jumptable.phpt
shqking Apr 25, 2021
c9552a6
Fix the encoding of immediate for logical instructions
shqking Apr 25, 2021
3a966b0
Add the helper to check whether an immediate is valid for logical ins…
shqking Apr 26, 2021
15a01f5
Added missed UNDEF_OPLINE_RESULT
dstogov Apr 26, 2021
c1479b9
typo
dstogov Apr 26, 2021
367fa86
Duplicate return
dstogov Apr 26, 2021
3e28bb3
Missed instruction
dstogov Apr 26, 2021
75d82cf
Make bit helpers to be inline
dstogov Apr 26, 2021
9a2d737
Use "red zone" for HYBRID VM.
dstogov Apr 26, 2021
6e59c0e
Disable "red zone" usage (it leads to crashes).
dstogov Apr 26, 2021
c53eeb0
Support for ZTS
dstogov Apr 26, 2021
2df3472
Enable register allocator (it was disabled because ZREG_NUM wasn't
dstogov Apr 26, 2021
fdba57d
Fixed compilation warning
dstogov Apr 27, 2021
e773a59
Fixed some compilation warnings
dstogov Apr 27, 2021
c083e4c
Remove the unnecessary 'bvs' check for IS_NOT_IDENTICAL case
shqking Apr 27, 2021
46599f9
Optimizing LONG MUL to SHIFT: add overflow detection for x86
shqking Apr 27, 2021
bcf37aa
Support ZEND_JIT_ON_PROF_REQUEST mode
shqking Apr 27, 2021
8c446af
Support ZEND_JIT_ON_HOT_COUNTERS mode
shqking Apr 27, 2021
cbefcc2
DynASM/arm64: Support for "b &addr"
dstogov Apr 27, 2021
c3dd2b9
Implement obvious trace side exits
dstogov Apr 27, 2021
c374210
Fixed incorrect register usage
dstogov Apr 27, 2021
121ea6a
Implement trace patching
dstogov Apr 27, 2021
a66f9cf
Fix incorrect macro LDR_STR_PIMM
shqking Apr 27, 2021
2e8eb40
Add the missing parts for macros ZVAL_COPY_CONST and ZVAL_COPY_CONST_2
shqking Apr 27, 2021
4bc5185
Fixed assertion
dstogov Apr 28, 2021
d1cba2a
Support for tracin JIT (incomplete, but abble to run Zend/bench.php)
dstogov Apr 28, 2021
5ddc4d1
Support for tracing JIT
dstogov Apr 28, 2021
72cf67e
Fixed register allocation.
dstogov Apr 28, 2021
e3de3f5
Attempt to fix Windows build
dstogov Apr 28, 2021
6be2a1d
ZREG_REG0 is not available in x86 build
dstogov Apr 28, 2021
d9f612f
Use TST_32_WITH_CONST macro
dstogov Apr 29, 2021
f0f5c1e
Remove useless SAFE_MEM_ACC_WITH_UOFFSET*
dstogov Apr 29, 2021
c52f46d
Fixed signed/unsigned comparison mess
dstogov Apr 29, 2021
b7256a4
Revisit 32-bit logical operations with constants
shqking Apr 29, 2021
3a4cec1
Moved tests from ext/opcache/tests/jit/arm64 to ext/opcache/tests/jit
dstogov Apr 29, 2021
1da69b8
Fixed signed/unsigned comparison mess and add one missing case
dstogov Apr 29, 2021
132fa52
Temporary disable PROFITABILITY_CHECKS for better test coverage and to
dstogov Apr 29, 2021
cd0dadf
Skip 64-bit related tests on 32-bit platforms
dstogov Apr 29, 2021
4765331
Don't optimize MUL into SHIFT if we have to check for overflow
dstogov Apr 29, 2021
1e59a8d
Improve code for MUL overflow detection (less instructions and less
dstogov Apr 29, 2021
77ae045
Optimize AArch64 code generator
dstogov Apr 30, 2021
66ba9af
Introduce CMP_64_WITH_CONST/CMP_64_WITH_CONST_32/CMP_32_WITH_CONST ma…
dstogov Apr 30, 2021
0609b97
Introduce ADD_SUB_64_WITH_CONST/ADD_SUB_64_WITH_CONST_32/ADD_SUB_32_W…
dstogov Apr 30, 2021
29c9d93
Use less temporary registers
dstogov Apr 30, 2021
b4e1e1c
Use single instruction
dstogov Apr 30, 2021
d58d2e7
Imroved code for CV initialization
dstogov Apr 30, 2021
f81f8f5
Imroved code for constants loading
dstogov Apr 30, 2021
7215283
Use B/BL intead of BR/BLR if possible
dstogov Apr 30, 2021
226d54d
Fix compilation warning
dstogov Apr 30, 2021
e20473a
Initial support of JIT/arm64
shqking Apr 1, 2021
0f7ab73
opcache/jit support: Mac M1 build fix
devnexen Apr 19, 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
3 changes: 2 additions & 1 deletion Zend/zend_vm_opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#endif

#if (ZEND_VM_KIND == ZEND_VM_KIND_HYBRID) && !defined(__SANITIZE_ADDRESS__)
# if ((defined(i386) && !defined(__PIC__)) || defined(__x86_64__) || defined(_M_X64))
# if ((defined(i386) && !defined(__PIC__)) || defined(__x86_64__) || \
defined(_M_X64) || defined(__aarch64__))
# define ZEND_VM_HYBRID_JIT_RED_ZONE_SIZE 16
# endif
#endif
Expand Down
3 changes: 3 additions & 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 All @@ -125,6 +126,8 @@ distclean: clean
rm -f scripts/man1/phpize.1 scripts/php-config scripts/man1/php-config.1 sapi/cli/php.1 sapi/cgi/php-cgi.1 sapi/phpdbg/phpdbg.1 ext/phar/phar.1 ext/phar/phar.phar.1
rm -f sapi/fpm/php-fpm.conf sapi/fpm/init.d.php-fpm sapi/fpm/php-fpm.service sapi/fpm/php-fpm.8 sapi/fpm/status.html
rm -f ext/phar/phar.phar ext/phar/phar.php
rm -f ext/opcache/jit/zend_jit_x86.c
rm -f ext/opcache/jit/zend_jit_arm64.c
if test "$(srcdir)" != "$(builddir)"; then \
rm -f ext/phar/phar/phar.inc; \
fi
Expand Down
7 changes: 6 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 @@ -58,6 +58,10 @@ if test "$PHP_OPCACHE" != "no"; then
x86*)
DASM_ARCH="x86"
;;
arm*-*-darwin*)
DASM_FLAGS="-D ARM64APPLE=1 -D ARM64=1"
DASM_ARCH="arm64"
;;
aarch64*)
DASM_FLAGS="-D ARM64=1"
DASM_ARCH="arm64"
Expand All @@ -77,6 +81,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
42 changes: 35 additions & 7 deletions ext/opcache/jit/dynasm/dasm_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
enum {
DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,
/* The following actions need a buffer position. */
DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG, DASM_ADDR_LG,
/* The following actions also have an argument. */
DASM_REL_PC, DASM_LABEL_PC,
DASM_IMM, DASM_IMM6, DASM_IMM12, DASM_IMM13W, DASM_IMM13X, DASM_IMML,
DASM_REL_PC, DASM_LABEL_PC, DASM_ADDR_PC, DASM_REL_A,
DASM_IMM, DASM_IMM6, DASM_IMM12, DASM_IMM13W, DASM_IMM13X, DASM_IMML, DASM_IMM_PC,
DASM_VREG,
DASM__MAX
};
Expand Down Expand Up @@ -251,14 +251,14 @@ void dasm_put(Dst_DECL, int start, ...)
case DASM_ESC: p++; ofs += 4; break;
case DASM_REL_EXT: break;
case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;
case DASM_REL_LG:
case DASM_REL_LG: case DASM_ADDR_LG:
n = (ins & 2047) - 10; pl = D->lglabels + n;
/* Bkwd rel or global. */
if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
pl += 10; n = *pl;
if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
goto linkrel;
case DASM_REL_PC:
case DASM_REL_PC: case DASM_ADDR_PC:
pl = D->pclabels + n; CKPL(pc, PC);
putrel:
n = *pl;
Expand Down Expand Up @@ -312,6 +312,13 @@ void dasm_put(Dst_DECL, int start, ...)
b[pos++] = m;
break;
}
case DASM_REL_A:
case DASM_IMM_PC: {
int m = va_arg(ap, int);
b[pos++] = n;
b[pos++] = m;
break;
}
case DASM_IMML: {
#ifdef DASM_CHECKS
int scale = (ins & 3);
Expand Down Expand Up @@ -378,11 +385,11 @@ int dasm_link(Dst_DECL, size_t *szp)
case DASM_ESC: p++; break;
case DASM_REL_EXT: break;
case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
case DASM_REL_LG: case DASM_REL_PC: pos++; break;
case DASM_REL_LG: case DASM_ADDR_LG: case DASM_REL_PC: case DASM_ADDR_PC: pos++; break;
case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
case DASM_IMM: case DASM_IMM6: case DASM_IMM12: case DASM_IMM13W:
case DASM_IMML: case DASM_VREG: pos++; break;
case DASM_IMM13X: pos += 2; break;
case DASM_IMM13X: case DASM_REL_A: case DASM_IMM_PC: pos += 2; break;
}
}
stop: (void)0;
Expand Down Expand Up @@ -421,6 +428,7 @@ int dasm_encode(Dst_DECL, void *buffer)
while (1) {
unsigned int ins = *p++;
unsigned int action = (ins >> 16);
unsigned long long addr = 0;
int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
switch (action) {
case DASM_STOP: case DASM_SECTION: goto stop;
Expand All @@ -431,6 +439,11 @@ int dasm_encode(Dst_DECL, void *buffer)
case DASM_ALIGN:
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
break;
case DASM_REL_A:
addr = (((unsigned long long)(*b++)) << 32) | (unsigned int)n;
CK((((addr - (ptrdiff_t)(cp+4)) + 0x08000000) >> 28) == 0, RANGE_REL);
n = (unsigned int)(addr - (ptrdiff_t)cp + 4);
goto patchrel;
case DASM_REL_LG:
if (n < 0) {
n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4);
Expand Down Expand Up @@ -461,6 +474,17 @@ int dasm_encode(Dst_DECL, void *buffer)
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
break;
case DASM_LABEL_PC: break;
case DASM_ADDR_LG:
if (n < 0) {
addr = (unsigned long long)D->globals[-n];
goto patchaddr;
}
case DASM_ADDR_PC:
addr = (unsigned long long)(*DASM_POS2PTR(D, n) + base);
patchaddr:
cp[-2] = (unsigned int)(addr);
cp[-1] = (unsigned int)(addr >> 32);
break;
case DASM_IMM:
cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);
break;
Expand All @@ -473,6 +497,10 @@ int dasm_encode(Dst_DECL, void *buffer)
case DASM_IMM13W:
cp[-1] |= (dasm_imm13(n, n) << 10);
break;
case DASM_IMM_PC:
cp[-2] = (unsigned int)(n);
cp[-1] = (unsigned int)(*b++);
break;
case DASM_IMM13X:
cp[-1] |= (dasm_imm13(n, *b++) << 10);
break;
Expand Down
39 changes: 33 additions & 6 deletions ext/opcache/jit/dynasm/dasm_arm64.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ local wline, werror, wfatal, wwarn
-- CHECK: Keep this in sync with the C code!
local action_names = {
"STOP", "SECTION", "ESC", "REL_EXT",
"ALIGN", "REL_LG", "LABEL_LG",
"REL_PC", "LABEL_PC", "IMM", "IMM6", "IMM12", "IMM13W", "IMM13X", "IMML",
"ALIGN", "REL_LG", "LABEL_LG", "ADDR_LG",
"REL_PC", "LABEL_PC", "ADDR_PC", "REL_A", "IMM", "IMM6", "IMM12", "IMM13W", "IMM13X", "IMML", "IMM_PC",
"VREG",
}

Expand Down Expand Up @@ -943,10 +943,17 @@ local function parse_template(params, template, nparams, pos)
op = parse_load_pair(params, nparams, n, op)

elseif p == "B" then
local mode, v, s = parse_label(q, false); n = n + 1
local m = branch_type(op)
waction("REL_"..mode, v+m, s, 1)

-- &expr (pointer)
if sub(q, 1, 1) == "&" then
local a = sub(q,2); n = n + 1
local m = branch_type(op)
waction("REL_A", m, format("(unsigned int)(unsigned long long)(%s)", a))
actargs[#actargs+1] = format("(unsigned int)((unsigned long long)(%s)>>32)", a)
else
local mode, v, s = parse_label(q, false); n = n + 1
local m = branch_type(op)
waction("REL_"..mode, v+m, s, 1)
end
elseif p == "I" then
op = op + parse_imm12(q); n = n + 1
elseif p == "i" then
Expand Down Expand Up @@ -1068,6 +1075,26 @@ map_op[".long_*"] = function(params)
end
end

-- Pseudo-opcodes for jump table entry.
map_op[".addr_1"] = function(params)
if not params then return "&addr | >label | <label | ->label | =>label" end
if secpos+1 > maxsecpos then wflush() end
local prefix = sub(params[1], 1, 1)
if prefix == "&" then
wputw(0)
wputw(0)
local imm = match(params[1], "^&(.*)$")
waction("IMM_PC", 0, format("(unsigned int)(unsigned long long)(%s)", imm))
actargs[#actargs+1] = format("(unsigned int)((unsigned long long)(%s)>>32)", imm)
else
local mode, n, s = parse_label(params[1], false)
if mode == "EXT" then werror("not support extern label reference") end
wputw(0)
wputw(0)
waction("ADDR_"..mode, n, s, 1)
end
end

-- Alignment pseudo-opcode.
map_op[".align_1"] = function(params)
if not params then return "numpow2" end
Expand Down
47 changes: 40 additions & 7 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__)
#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"
#if defined(__x86_64__) || defined(i386)
# include "jit/zend_jit_gdb.c"
#endif
#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 @@ -391,6 +421,9 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
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
Loading