1
0
mirror of https://github.com/php/php-src.git synced 2026-04-17 21:11:02 +02:00
Files
archived-php-src/ext/opcache/tests/jit/cmp_005.phpt
Hao Sun 3e164dee99 JIT/AArch64: Support shifted immediate (#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, #4096` would be encoded by DynASM
into `add x0, x1, #1, lsl #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 #12 on all the
values from the first range.

Note that this helper works for add/adds/sub/subs/cmp/cmn instructions.

[1] https://github.com/LuaJIT/LuaJIT/pull/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
2021-06-23 17:18:03 +08:00

76 lines
1.5 KiB
PHP

--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)