Thanks for your reply and your interest.

Yes. Only Linux platform is tested on my side.

I spent about two months for this initial task.
To be honest, I haven't had a very clear overview of this CPU-specific JIT 
parts so far, but I simply added the arm64 supports where necessary to make 
JIT/arm64 runnable.
Yes. Agree with you that JIT docs would be very helpful.

Yes your are right. Currently this JIT/arm64 is much smaller than JIT/x86. 
As mentioned in my previous email, only very simple functionalities are 
(partially) supported.
I'm now working on more features.

Thanks again for your comments.
Hao

-----Original Message-----
From: Calvin Buckley <cal...@cmpct.info> 
Sent: Thursday, March 18, 2021 4:18 AM
To: Hao Sun <hao....@arm.com>; internals@lists.php.net
Cc: nd <n...@arm.com>
Subject: Re: [PHP-DEV] RFC: PHP JIT/arm64 port

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....@arm.com<mailto:hao....@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
> 



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to