Commit Graph

124113 Commits

Author SHA1 Message Date
Dmitry Stogov
57f2fe44c6 Use "red zone" for HYBRID VM.
Support for CALL VM and VM without global register variables.
2021-05-18 15:32:31 +03:00
Dmitry Stogov
39e80971c7 Make bit helpers to be inline 2021-05-18 15:32:31 +03:00
Dmitry Stogov
add2544e1c Missed instruction 2021-05-18 15:32:31 +03:00
Dmitry Stogov
434eb1a3d9 Duplicate return 2021-05-18 15:32:31 +03:00
Dmitry Stogov
91aaea362f typo 2021-05-18 15:32:31 +03:00
Dmitry Stogov
018fca92ad Added missed UNDEF_OPLINE_RESULT 2021-05-18 15:32:31 +03:00
Hao Sun
4039c5865a Add the helper to check whether an immediate is valid for logical instructions
We implement a simplified version. Every value with one single bit can
be encoded for logical instructions and we suppose this quick check can
cover a lot of common masks.

Besides, add macro TST_64_WITH_ONE since it's used often to test 64-bit
register with constant 1.

Change-Id: I850a6ac6acbe2d12f85180e407344580ee6fea61
2021-05-18 15:32:31 +03:00
Hao Sun
86326b5ddb Fix the encoding of immediate for logical instructions
Previous implementation[1] of the immediate encoding for logical
instructions('and/orr/eor/tst') is incorrect. It's more complicated than
that of 'add/sub/ldr/str/movz'.[2]

Ideally a helper is needed to "determine whether an immediate value can
be encoded as the immediate operand of a logical instruction for the
given register size"[3].

Macros "BW_OP_x_WITH_CONST" and "TST_x_WITH_CONST" are defined to wrap
the logical instrunctions with constants. Currently this helper is not
implemented yet.

All the uses of bitwise operations and 'tst' are revisited and updated.

Note that test case bug80745.phpt will pass with this patch.

[1] https://github.com/php/php-src/commit/47d8252
[2]
https://dinfuehr.github.io/blog/encoding-of-immediate-values-on-aarch64/
[3]
5c95b810cb/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h (L213)

Change-Id: I0bfa088cafcffe30e0f18fa1f0638338ef00eb20
2021-05-18 15:32:31 +03:00
Hao Sun
06b9eb500f Support failed test case: switch_jumptable.phpt
Opcodes ZEND_SWITCH_LONG, ZEND_SWITCH_STRING and ZEND_MATCH are
supported in this patch.

Change-Id: I71ae3d40e65ec1b29d3d9115ac41caef17cf6ae5
2021-05-18 15:32:30 +03:00
Hao Sun
ff72c1575a Remove the TODO comments for DOUBLE CMP
As explained by Dmitry, 'ucomsd' in x86 sets 'p' flag, and it also
always sets 'z' and 'c' flags. [1]

Besides, remove one duplicate 'break'.

[1]. https://mudongliang.github.io/x86/html/file_module_x86_id_316.html

Change-Id: I767214c7ab8db31115801a3ae96b20320757899f
2021-05-18 15:32:30 +03:00
Hao Sun
42bec86a3c Optimizing LONG MUL to SHIFT: refine the trigger condition and add overflow detection
LONG MUL can be optimzied into left shift if either operand is a power
of two. Conditions "IS_SIGNED_32BIT()" and "is_power_of_two()" are used
to filter out invalid candidates. However, there exists one exception,
i.e. -2147483648(that is 0xffff,ffff,8000,0000). See the stand-alone
case[1].

Assume "a = 3; b = -2147483648;". The expected result of "a * b" is one
negative value. However, it would be optimized to "a << 31", which is
positive.

This trigger condition is refined.
1) For x86 implementation, another check for positive numbers is added.
Note that LONG type, i.e. zend_long, is defined as int32_t for x86 arch
and int64_t for x64 arch. This optimization only accepts values which
can be represented by int32_t type as default. See IS_SIGNED_32BIlT(),
2) For AArch64, we employ helper function zend_long_is_power_of_two()
since values of int64_t type are used.

Overflow detection for left shifting is added in this patch as well.

Note 1: bit helper functions are arch-independent and we move them into
zend_jit_internals.h.

Note 2: two test cases are added. Test case mul_003.phpt is used to
check the trigger condition and mul_004.phpt is designed to check
overflow detection.

Note 3: overflow detection for x86 is not implemented yet as I think
anotehr temporay register besides R0 is needed. Hence mul_004.phpt would
fail on x86 machine.
If we can use R1 as tmp_reg, the code can be updated as below.

```
  |	GET_ZVAL_LVAL result_reg, op1_addr
  if (may_overflow) {
    use_ovf_flag = 0;
    /* Compare 'op' and '((op << n) >> n)' for overflow.
     * Flag: jne -> overflow. je -> no overflow.
     */
    tmp_reg = ZREG_R1
    |	mov Ra(tmp_reg), Ra(result_reg)
    |	shl Ra(tmp_reg), floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
    |	sar Ra(tmp_reg), floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
    |	cmp Ra(tmp_reg), Ra(result_reg)
  }
  |	shl Ra(result_reg), floor_log2(Z_LVAL_P(Z_ZV(op2_addr)))
```

[1]. https://godbolt.org/z/1vKbfv8oG

Change-Id: Ie90e1d4e7c8b94a0c8f61386dfe650fa2c6879a1
2021-05-18 15:32:30 +03:00
Dmitry Stogov
c84cc92633 Fixed type checks and return value handling 2021-05-18 15:32:30 +03:00
Dmitry Stogov
350115196c Create C call frames for helper functions that perform nested calls 2021-05-18 15:32:30 +03:00
Dmitry Stogov
1c6bea8153 Fixed incorrect efree() 2021-05-18 15:32:30 +03:00
Dmitry Stogov
cf3c313150 Disable unsuitable optimization 2021-05-18 15:32:30 +03:00
Dmitry Stogov
a1bf150b9e Fixed condition and avoid usage of non-temporary registers 2021-05-18 15:32:30 +03:00
Dmitry Stogov
b9281168ab Wrong register 2021-05-18 15:32:30 +03:00
Dmitry Stogov
8f98474b5a Fixed type check 2021-05-18 15:32:30 +03:00
Dmitry Stogov
c1020c4ecf Support for interupts 2021-05-18 15:32:30 +03:00
Dmitry Stogov
2854043742 Fixed compilation warnings 2021-05-18 15:32:29 +03:00
Dmitry Stogov
23b07035a9 Fixed map_ptr resolution 2021-05-18 15:32:29 +03:00
Dmitry Stogov
b4f013a2df Fixed load of incorrect size 2021-05-18 15:32:29 +03:00
Dmitry Stogov
7c6b451ecc Fixed INC/DEC_PROP (tests/classes/incdec_property_*.phpt) 2021-05-18 15:32:29 +03:00
Dmitry Stogov
03537c4602 Temporary diable JIT for SWITCH and MATCH instructions (SWITCH should
work, MATCH is going to fail)
2021-05-18 15:32:29 +03:00
Dmitry Stogov
9776279415 Get rid of NYI in call/return sequences 2021-05-18 15:32:29 +03:00
Dmitry Stogov
1289ebcaab Implement exceptional stubs 2021-05-18 15:32:29 +03:00
Dmitry Stogov
b550dbd68b Support for VERIFY_RETURN_TYPE, ISSET_ISEMPTY_CV, IN_ARRAY and ADD with
array operands.
2021-05-18 15:32:29 +03:00
Dmitry Stogov
36358c5a16 Get rid of NIY in spill code 2021-05-18 15:32:29 +03:00
Dmitry Stogov
326c9bf937 Support for PRE/POST_INC/DEC_OBJ 2021-05-18 15:32:29 +03:00
Dmitry Stogov
f52ec02ea9 Get rid of testing NIY_STUBs 2021-05-18 15:32:29 +03:00
Dmitry Stogov
761b56ab0f Support for FETCH_THIS, FETCH_OBJ, ASSIGN_OBJ and ASSIGN_OBJ_OP 2021-05-18 15:32:29 +03:00
Dmitry Stogov
09070fa8bc Support for BIND_GLOBAL 2021-05-18 15:32:28 +03:00
Dmitry Stogov
0bfe4da47d Support for TYPE_CHECK 2021-05-18 15:32:28 +03:00
Dmitry Stogov
8c0cb57d9f Support for FETCH_CONST 2021-05-18 15:32:28 +03:00
Dmitry Stogov
c86a4af06d Fixed reference-countoing. Use 32-bit registers. 2021-05-18 15:32:28 +03:00
Dmitry Stogov
c1f390b983 Support for FE_RESET and FE_FETCH 2021-05-18 15:32:28 +03:00
Dmitry Stogov
edf87fda3c Support for moving between allocated registers 2021-05-18 15:32:28 +03:00
Dmitry Stogov
695047369f Support for STRLEN and COUNT 2021-05-18 15:32:28 +03:00
Dmitry Stogov
2aac47b3fb Support for DEFINED 2021-05-18 15:32:28 +03:00
Dmitry Stogov
c68ec03f2b Support for FREE and FE_FREE 2021-05-18 15:32:28 +03:00
Dmitry Stogov
7d8ee8a989 Support for missed IS_NOT_IDENTICAL cases 2021-05-18 15:32:28 +03:00
Dmitry Stogov
7d3e0a4af2 Support for ECHO with non-constant operand 2021-05-18 15:32:28 +03:00
Dmitry Stogov
d9b2b26e99 Get rid of some NIY traps in DynADM macros 2021-05-18 15:32:28 +03:00
Dmitry Stogov
a409eed4bf Support for more cases in INIT_METHOD_CALL, DO_FCALL* and RETURN 2021-05-18 15:32:28 +03:00
Dmitry Stogov
29ff75165d Support for SEND_VAL/SEND_VAR/SEND_REF/CHECK_FUNC_ARG/CHECK_UNDEF_ARGS 2021-05-18 15:32:28 +03:00
Hao Sun
cb52d2731c Support LONG MUL with overflow detection
Overflow detection for LONG MUL is added in this patch. Quite different
from 'subs' and 'adds' where overflow can be easily checked via the V
flags, LONG MUL wouldn't set the flags.

We use 'smulh' instruction to get the upper 64 bits of the 128-bit
result and check the top 65 bits to tell whether integer overflow
occurs. [1]

Note that LONG MUL can be substituted by 'adds' or 'lsl' in some cases.
Hence, flag 'use_mul' is introduced in order to select the proper
overflow check check instruction afterwards.

[1]
https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/detecting-overflow-from-mul

Change-Id: I67e8287e9044c2a96b188d4bf6674736713abfe9
2021-05-18 15:32:28 +03:00
Dmitry Stogov
0482102b04 Support for ASSIGN_DIM_OP 2021-05-18 15:32:28 +03:00
Dmitry Stogov
09647a0a90 Support for ASSIGN_OP 2021-05-18 15:32:27 +03:00
Dmitry Stogov
e6d0a220f3 Support for ISSET_DIM 2021-05-18 15:32:27 +03:00
Dmitry Stogov
be81cad827 Accurate RETVAL register usage 2021-05-18 15:32:27 +03:00