xref: /PHP-8.3/ext/opcache/tests/jit/mul_004.phpt (revision 186a5277)
1--TEST--
2JIT MUL: 004 Overflow check for optmizing MUL to SHIFT
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6opcache.file_update_protection=0
7opcache.jit_buffer_size=32M
8;opcache.jit_debug=257
9--EXTENSIONS--
10opcache
11--SKIPIF--
12<?php
13if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
14?>
15--FILE--
16<?php
17
18function mul2_8(int $a) {
19  $res = $a * 8;  // shift cnt: 3
20  var_dump($res);
21}
22
23function mul1_16(int $a) {
24  $res = 16 * $a; // shift cnt: 4
25  var_dump($res);
26}
27
28function mul2_big_int32(int $a) {
29  $res = $a * 0x10000000; // shift cnt: 29
30  var_dump($res);
31}
32
33function mul2_big_int64(int $a) {
34  $res = $a * 0x100000000; // shift cnt: 32
35  var_dump($res);
36}
37
38function mul2(int $a) {
39  $res = $a * 2; // $a + $a
40  var_dump($res);
41}
42
43mul2_8(3);
44mul2_8(-11);
45mul2_8(0x7fffffffffffffff);
46mul1_16(3);
47mul1_16(-13);
48mul1_16(0x7fffffffffffffff);
49mul2_big_int32(3);
50mul2_big_int32(-3);
51mul2_big_int32(0x10000000000);
52mul2_big_int64(3);
53mul2_big_int64(-3);
54mul2_big_int64(0x100000000);
55mul2(10);
56mul2(0x7fffffffffffffff);
57?>
58--EXPECT--
59int(24)
60int(-88)
61float(7.378697629483821E+19)
62int(48)
63int(-208)
64float(1.4757395258967641E+20)
65int(805306368)
66int(-805306368)
67float(2.9514790517935283E+20)
68int(12884901888)
69int(-12884901888)
70float(1.8446744073709552E+19)
71int(20)
72float(1.8446744073709552E+19)
73