Skip to content

Commit 42eed7b

Browse files
committed
Fix GH-10271: Incorrect arithmetic calculations when using JIT
1 parent 0d011e4 commit 42eed7b

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ext/opcache/jit/zend_jit_x86.dasc

+6
Original file line numberDiff line numberDiff line change
@@ -16209,11 +16209,17 @@ static zend_regset zend_jit_get_scratch_regset(const zend_op *opline, const zend
1620916209
}
1621016210
}
1621116211
if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_DOUBLE)) {
16212+
if (opline->op1_type == IS_CONST) {
16213+
ZEND_REGSET_INCL(regset, ZREG_R0);
16214+
}
1621216215
if (ssa_op->result_def != current_var) {
1621316216
ZEND_REGSET_INCL(regset, ZREG_XMM0);
1621416217
}
1621516218
}
1621616219
if ((op1_info & MAY_BE_DOUBLE) && (op2_info & MAY_BE_LONG)) {
16220+
if (opline->op2_type == IS_CONST) {
16221+
ZEND_REGSET_INCL(regset, ZREG_R0);
16222+
}
1621716223
if (zend_is_commutative(opline->opcode)) {
1621816224
if (ssa_op->result_def != current_var) {
1621916225
ZEND_REGSET_INCL(regset, ZREG_XMM0);

ext/opcache/tests/jit/gh10271.phpt

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