forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT/AArch64: Support shifted immediate (php#7165)
* JIT/AArch64: Support shifted immediate As pointed out by MikePall in [1], shifted immediate value is supported. See [2]. For example, `add x0, x1, php#4096` would be encoded by DynASM into `add x0, x1, #1, lsl php#12` directly. In this patch, a helper is added to check whether an immediate value is in the two allowed ranges: (1) 0 to 4095, and (2) LSL php#12 on all the values from the first range. Note that this helper works for add/adds/sub/subs/cmp/cmn instructions. [1] LuaJIT/LuaJIT#718 [2] https://github.com/LuaJIT/LuaJIT/blob/v2.1/dynasm/dasm_arm64.lua#L342 Change-Id: I4870048b9b8e6c429b73a4803af2a3b2d5ec0fbb * Deprecatd CMP_IMM/ADD_SUB_IMM and add test cases Macros CMP_IMM and ADD_SUB_IMM are deprecated and instead we use this helper to guard the immediate encoding. Add two 64-bit only test cases, since 64-bit integers are used and tested inside. Change-Id: I0b42d4617b40372e2f4ce5b6ad31a4ddb7d89e49
- Loading branch information
Showing
3 changed files
with
166 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--TEST-- | ||
JIT ADD: 007 Addition with immediate values | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.file_update_protection=0 | ||
opcache.jit_buffer_size=1M | ||
opcache.protect_memory=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?> | ||
--FILE-- | ||
<?php | ||
function foo($a) { | ||
$b = 0; | ||
$c = 31; | ||
$d = 0xfff; | ||
$e = 0x1000; | ||
$f = 0xfff000; | ||
$g = 0xff001; // Cannot be encoded into imm12 field | ||
$h = 0x1000000; // Cannot be encoded into imm12 field | ||
$i = 0xf12345678; // Cannot be encoded into imm12 field | ||
$j = -31; // Cannot be encoded into imm12 field | ||
|
||
$a = $a + $b; | ||
$a = $a + $c; | ||
$a = $a + $d; | ||
$a = $a + $e; | ||
$a = $a + $f; | ||
$a = $a + $g; | ||
$a = $a + $h; | ||
$a = $a + $i; | ||
$a = $a + $j; | ||
var_dump($a); | ||
} | ||
|
||
function bar($a) { | ||
$b = 0; | ||
$c = 31; | ||
$d = 0xfff; | ||
$e = 0x1000; | ||
$f = 0xfff000; | ||
$g = 0xff001; // Cannot be encoded into imm12 field | ||
$h = 0x1000000; // Cannot be encoded into imm12 field | ||
$i = 0xf12345678; // Cannot be encoded into imm12 field | ||
$j = -31; // Cannot be encoded into imm12 field | ||
|
||
$a = $a - $b; | ||
$a = $a - $c; | ||
$a = $a - $d; | ||
$a = $a - $e; | ||
$a = $a - $f; | ||
$a = $a - $g; | ||
$a = $a - $h; | ||
$a = $a - $i; | ||
$a = $a - $j; | ||
var_dump($a); | ||
} | ||
|
||
foo(42); | ||
bar(0x1f12345678); | ||
?> | ||
--EXPECT-- | ||
int(64764532386) | ||
int(68684873728) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--TEST-- | ||
JIT CMP: 005 Comparisons with immediate values | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.file_update_protection=0 | ||
opcache.jit_buffer_size=1M | ||
opcache.protect_memory=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_INT_SIZE != 8) die("skip: 64-bit only"); ?> | ||
--FILE-- | ||
<?php | ||
function foo($a) { | ||
$b = 0; | ||
$c = 31; | ||
$d = 0xfff; | ||
$e = 0x1000; | ||
$f = 0xfff000; | ||
$g = 0xff001; // Cannot be encoded into imm12 field | ||
$h = 0x1000000; // Cannot be encoded into imm12 field | ||
$i = 0xf12345678; // Cannot be encoded into imm12 field | ||
|
||
var_dump($a > $b ? 1 : 0); | ||
var_dump($a > $c ? 1 : 0); | ||
var_dump($a > $d ? 1 : 0); | ||
var_dump($a > $e ? 1 : 0); | ||
var_dump($a > $f ? 1 : 0); | ||
var_dump($a > $g ? 1 : 0); | ||
var_dump($a > $h ? 1 : 0); | ||
var_dump($a > $i ? 1 : 0); | ||
} | ||
|
||
function bar($a) { | ||
$b = 0; | ||
$c = -31; | ||
$d = -4095; // negation of 0xfff | ||
$e = -4096; // negation of 0x1000 | ||
$f = -16773120; // negation of 0xfff000 | ||
$g = -1044481; // negation of 0xff001 | ||
$h = -16777216; // negation of 0x1000000 | ||
$i = -64729929336; // negation of 0xf12345678 | ||
|
||
var_dump($a > $b ? 1 : 0); | ||
var_dump($a > $c ? 1 : 0); | ||
var_dump($a > $d ? 1 : 0); | ||
var_dump($a > $e ? 1 : 0); | ||
var_dump($a > $f ? 1 : 0); | ||
var_dump($a > $g ? 1 : 0); | ||
var_dump($a > $h ? 1 : 0); | ||
var_dump($a > $i ? 1 : 0); | ||
} | ||
|
||
foo(42); | ||
bar(42); | ||
?> | ||
--EXPECT-- | ||
int(1) | ||
int(1) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) | ||
int(1) |