-
Notifications
You must be signed in to change notification settings - Fork 7.9k
JIT/AArch64: Support shifted immediate #7165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this?
In any case, it would be great to add test(s) for edge cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have run ~4k .phpt test cases under "Zend/tests/, tests/ ext/opcache/tests/jit/", and didn't find any failure.
Good suggestion! I will add several new test cases soon. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two test cases are added, and in my local testing, immediate values in legitimate ranges can be encoded as the
imm
field as expected.cmp
andcmn
instructions, I only testedCMP_64_WITH_CONST
. Note: I tested that negative values can be encoded into theimm
field focmn
instruction.adds
andsubs
with macroADD_SUB_64_WITH_CONST
.I currently failed to construct test cases to use
CMP_32_WITH_CONST, CMP_64_WITH_CONST_32, ADD_SUB_32_WITH_CONST, ADD_SUB_64_WITH_CONST_32
, but I thinkarm64_may_encode_imm12
would work for them as well since these 4 macros share the same encoding logic ofimm12
withCMP_64_WITH_CONST
andADD_SUB_64_WITH_CONST
.