Fix #79595: zend_init_fpu() alters FPU precision
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 20 May 2020 11:23:17 +0000 (13:23 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 22 May 2020 13:46:13 +0000 (15:46 +0200)
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.

NEWS
Zend/zend_float.c

diff --git a/NEWS b/NEWS
index eb88651544e523293f5f65bd730b484943b73ff1..007406315f1db7c965594bcdb7dc819c37a0e0f6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
   . Fixed bug #79489 (.user.ini does not inherit). (cmb)
   . Fixed bug #79600 (Regression in 7.4.6 when yielding an array based
     generator). (Nikita)
+  . Fixed bug #79595 (zend_init_fpu() alters FPU precision). (cmb, Nikita)
 
 - FFI:
   . Fixed bug #79571 (FFI: var_dumping unions may segfault). (cmb)
index 90af0c4a5f9002d08dd81a1c138f86f87f0610c1..2d7e6529a53d886e6eb8eb84aecc0f09799b45db 100644 (file)
@@ -22,7 +22,8 @@
 
 ZEND_API void zend_init_fpu(void) /* {{{ */
 {
-#if XPFPA_HAVE_CW
+/* under __SSE__ the FPCW is irrelevant; no need to change it */
+#if XPFPA_HAVE_CW && !defined(__SSE__)
        XPFPA_DECLARE
 
        if (!EG(saved_fpu_cw_ptr)) {
@@ -38,7 +39,7 @@ ZEND_API void zend_init_fpu(void) /* {{{ */
 
 ZEND_API void zend_shutdown_fpu(void) /* {{{ */
 {
-#if XPFPA_HAVE_CW
+#if XPFPA_HAVE_CW && !defined(__SSE__)
        if (EG(saved_fpu_cw_ptr)) {
                XPFPA_RESTORE_CW(EG(saved_fpu_cw_ptr));
        }
@@ -49,8 +50,10 @@ ZEND_API void zend_shutdown_fpu(void) /* {{{ */
 
 ZEND_API void zend_ensure_fpu_mode(void) /* {{{ */
 {
+#ifndef __SSE__
        XPFPA_DECLARE
 
        XPFPA_SWITCH_DOUBLE();
+#endif
 }
 /* }}} */