Skip to content

Commit c010e8f

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-10271: Incorrect arithmetic calculations when using JIT
2 parents 2d3427c + 757e269 commit c010e8f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16174,11 +16174,17 @@ static zend_regset zend_jit_get_scratch_regset(const zend_op *opline, const zend
1617416174
}
1617516175
}
1617616176
if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_DOUBLE)) {
16177+
if (opline->op1_type == IS_CONST) {
16178+
ZEND_REGSET_INCL(regset, ZREG_R0);
16179+
}
1617716180
if (ssa_op->result_def != current_var) {
1617816181
ZEND_REGSET_INCL(regset, ZREG_XMM0);
1617916182
}
1618016183
}
1618116184
if ((op1_info & MAY_BE_DOUBLE) && (op2_info & MAY_BE_LONG)) {
16185+
if (opline->op2_type == IS_CONST) {
16186+
ZEND_REGSET_INCL(regset, ZREG_R0);
16187+
}
1618216188
if (zend_is_commutative(opline->opcode)) {
1618316189
if (ssa_op->result_def != current_var) {
1618416190
ZEND_REGSET_INCL(regset, ZREG_XMM0);

ext/opcache/tests/jit/gh10271.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
GH-10271: Incorrect arithmetic calculations when using JIT
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.jit_hot_loop=1
9+
--FILE--
10+
<?php
11+
$tang['KSI']=-9.1751656444142E-5;
12+
$tang['ETA']=8.5076090069491E-5;
13+
14+
$sol['X']['k']=-222.45470924306;
15+
$sol['X']['e']=-8.1787760034414;
16+
$sol['X'][1]=-0.020231298698539;
17+
18+
$sol['Y']['k']=-14.400586941152;
19+
$sol['Y']['e']=392.95090925357;
20+
$sol['Y'][1]=-0.035664413413272;
21+
22+
$sol['xc']=968;
23+
$sol['yc']=548;
24+
25+
for( $p=0; $p<3; $p++ )
26+
{
27+
print($p.': ');
28+
Tangential2XY($tang,$sol);
29+
}
30+
31+
function Tangential2XY(array $tang, array $sol) : array
32+
{
33+
$x = $sol['X']['k']*$tang['KSI'] + $sol['X']['e']*$tang['ETA'] + $sol['X'][1];
34+
$y = $sol['Y']['k']*$tang['KSI'] + $sol['Y']['e']*$tang['ETA'] + $sol['Y'][1];
35+
printf("In;%.12f;%.12f;%.12f;%.12f;",$x,$y,$sol['xc'],$sol['yc']);
36+
$x = $sol['xc']*($x+1);
37+
$y = $sol['yc']*($y+1);
38+
printf("Out;%.12f;%.12f\n",$x,$y);
39+
if( $x<100 )
40+
exit("Mamy to!\n");
41+
return ['x'=>$x,'y'=>$y];
42+
}
43+
?>
44+
--EXPECT--
45+
0: In;-0.000516528926;-0.000912408759;968.000000000000;548.000000000000;Out;967.500000000004;547.500000000009
46+
1: In;-0.000516528926;-0.000912408759;968.000000000000;548.000000000000;Out;967.500000000004;547.500000000009
47+
2: In;-0.000516528926;-0.000912408759;968.000000000000;548.000000000000;Out;967.500000000004;547.500000000009

0 commit comments

Comments
 (0)