Skip to content

Commit 88dfc47

Browse files
committed
Fix #79595: zend_init_fpu() alters FPU precision
On startup, PHP deliberately changes the floating point control word to enforce binary64 format for the calculations for best consistency across platforms. However, this is unnessary when compiling under `__SSE__`, because in this case the x87 instructions are not used. Therefore, we can skip the modification, which has the benefit that system libraries are free to work in the mode of their liking.
1 parent da801ba commit 88dfc47

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88
. Fixed bug #79489 (.user.ini does not inherit). (cmb)
99
. Fixed bug #79600 (Regression in 7.4.6 when yielding an array based
1010
generator). (Nikita)
11+
. Fixed bug #79595 (zend_init_fpu() alters FPU precision). (cmb, Nikita)
1112

1213
- FFI:
1314
. Fixed bug #79571 (FFI: var_dumping unions may segfault). (cmb)

Zend/zend_float.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
ZEND_API void zend_init_fpu(void) /* {{{ */
2424
{
25-
#if XPFPA_HAVE_CW
25+
/* under __SSE__ the FPCW is irrelevant; no need to change it */
26+
#if XPFPA_HAVE_CW && !defined(__SSE__)
2627
XPFPA_DECLARE
2728

2829
if (!EG(saved_fpu_cw_ptr)) {
@@ -38,7 +39,7 @@ ZEND_API void zend_init_fpu(void) /* {{{ */
3839

3940
ZEND_API void zend_shutdown_fpu(void) /* {{{ */
4041
{
41-
#if XPFPA_HAVE_CW
42+
#if XPFPA_HAVE_CW && !defined(__SSE__)
4243
if (EG(saved_fpu_cw_ptr)) {
4344
XPFPA_RESTORE_CW(EG(saved_fpu_cw_ptr));
4445
}
@@ -49,8 +50,10 @@ ZEND_API void zend_shutdown_fpu(void) /* {{{ */
4950

5051
ZEND_API void zend_ensure_fpu_mode(void) /* {{{ */
5152
{
53+
#ifndef __SSE__
5254
XPFPA_DECLARE
5355

5456
XPFPA_SWITCH_DOUBLE();
57+
#endif
5558
}
5659
/* }}} */

0 commit comments

Comments
 (0)