Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113595 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99391 invoked from network); 17 Mar 2021 20:23:42 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2021 20:23:42 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D477C1804D8 for ; Wed, 17 Mar 2021 13:17:46 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail.cmpct.info (supercat.cmpct.info [71.19.146.230]) by php-smtp4.php.net (Postfix) with ESMTP for ; Wed, 17 Mar 2021 13:17:45 -0700 (PDT) Received: from [192.168.2.29] (fctnnbsc38w-142-167-240-56.dhcp-dynamic.fibreop.nb.bellaliant.net [142.167.240.56]) by mail.cmpct.info (Postfix) with ESMTPSA id 3DAE03FC5B; Wed, 17 Mar 2021 20:17:42 +0000 (-00) Message-ID: <3a2edb5e17b9754d7013a9ff3c43cd094fd223ff.camel@cmpct.info> To: Hao Sun , "internals@lists.php.net" Cc: nd Date: Wed, 17 Mar 2021 17:17:39 -0300 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.1 (3.38.1-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC: PHP JIT/arm64 port From: calvin@cmpct.info (Calvin Buckley) This is great work! I assume you've only tested much on Linux, but I do have an M1 Mac here to test. I'm curious how much effort this took you, in terms of figuring out the CPU-specific parts of the JIT, and what needed untangling from machine- specific code and what didn't. I've been curious what it'd take to write another JIT backend (for a supported CPU in DynASM). I noticed the changes you've made to generic parts of the JIT were minimal; only improvements that'd be optional to dasm, minor detanglement in generic code/the build system, and adding Capstone. The current state of the JIT being x86 only made it hard to determine what was specific to x86 and what wasn't. The ARM backend here also seems pretty small compared to the x86 one, though that might just be lack of feature parity. (Regardless, better JIT docs would be great!) On Wed, 2021-03-17 at 03:27 +0000, Hao Sun wrote: > Hi Internals, > > Currently PHP JIT only supports x86 and x86_64 CPUs on POSIX > platforms and Windows.[1] With the prevalence of PHP language and the > notable > growth of ARM-based servers market, we believe JIT/arm64 would be in > urgent need in the near future. > > As an initial effort to enable PHP JIT/arm64, we (ARM) have supported > the basic functionality, and (partially) implemented the compilation > for > several opcodes. Currently a number of simple JIT test cases from PHP > test framework can be passed on ARM-based machine. There are still a > lot > of missing parts, such as hot loops, class/object/array operations, > exception handling, etc, and we will continue working on them. > > We would like to share our work with you (See the draft patch > https://github.com/shqking/php-src/commit/6aaf935). > Any feedback would be greatly appreciated, and please let we know if > anyone wants to contribute to this port. > > Thanks, > Hao SUN > Email: hao.sun@arm.com > > ------------------------------------------------------- > Main updates: > 1. JIT backend for AArch64 > A new alternative, i.e. AArch64, was added while building PHP JIT. > See the updates in the following files. Note that we adopt > capstone[2] for > disassembly on AArch64. > >   build/Makefile.global >   ext/opcache/config.m4 >   ext/opcache/config.w32 >   ext/opcache/jit/Makefile.frag >   ext/opcache/jit/zend_jit.c >   ext/opcache/jit/zend_jit_vm_helpers.c >   ext/opcache/jit/zend_jit_disasm_arm64.c >   ext/opcache/jit/zend_jit_gdb.c >   ext/opcache/jit/zend_jit_perf_dump.c > > 2. DynASM library > PHP JIT uses DynASM[3] (developed for LuaJIT project) to generate > native code on the fly. We added two useful but missing features, > global label > reference and dynamic register names, into DynASM/arm64. See the > updates in files: > >   ext/opcache/jit/dynasm/dasm_arm64.h >   ext/opcache/jit/dynasm/dasm_arm64.lua > > Note that these two features are available on DynASM/x86. > > 3. compilation for opcodes on AArch64 > Our main work falls in the following files. > >   ext/opcache/jit/zend_jit_arm64.h >   ext/opcache/jit/zend_jit_arm64.dasc >   ext/opcache/jit/zend_jit_internal.h >   Zend/zend_vm_opcodes.h > > * AArch64 registers and calling conventions are defined. > > * Instruction cache must be flushed for the JIT-ed code on AArch64. > See macro JIT_CACHE_FLUSH in file 'zend_jit_internal.h'. > > * We have (partially) implemented the compilation for several > opcodes, mainly for the function-based JIT (with opcache.jit=1203). > Currently, > test cases involving internal function call (e.g. var_dump), > additions with integers/floating-point numbers, integer overflows and > simple > exception, can be supported now. See our newly added test cases under > directory 'ext/opcache/tests/jit/arm64/'. > > * Trace counter stubs are implemented for tracing JIT (with > opcache.jit=1255). See zend_jit_hybrid_trace_counter_stub() and > zend_jit_hybrid_hot_trace_stub() in file 'zend_jit_arm64.dasc'. Hot > functions can be recognized and compiled successfully. See the test > case 'hot_func_002.phpt'. > > How to build and test: > Our local test environment is an ARM-based server with Ubuntu 20.04 > and GCC-10. We follow the building commands as shown in the readme > file [4]. > Note that library capstone should be installed in advance. > > We suggest running the JIT test cases using the following command. In > our local test, 59 out of all 128 cases can be passed currently. >   $ make test TESTS='-d opcache.jit=1203 ext/opcache/tests/jit/' > > [1] https://wiki.php.net/rfc/jit > [2] https://www.capstone-engine.org/ > [3] https://luajit.org/dynasm.html > [4] https://github.com/php/php-src >