From b8f3811ba95036d52e6699e465d8ed35ccba1171 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 20 May 2020 13:23:17 +0200 Subject: [PATCH 1/2] 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. --- Zend/zend_float.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Zend/zend_float.c b/Zend/zend_float.c index 90af0c4a5f900..a840ffbc60014 100644 --- a/Zend/zend_float.c +++ b/Zend/zend_float.c @@ -22,7 +22,7 @@ ZEND_API void zend_init_fpu(void) /* {{{ */ { -#if XPFPA_HAVE_CW +#if XPFPA_HAVE_CW && !defined(__SSE__) XPFPA_DECLARE if (!EG(saved_fpu_cw_ptr)) { @@ -38,7 +38,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 +49,10 @@ ZEND_API void zend_shutdown_fpu(void) /* {{{ */ ZEND_API void zend_ensure_fpu_mode(void) /* {{{ */ { +#ifndef __SSE__ XPFPA_DECLARE XPFPA_SWITCH_DOUBLE(); +#endif } /* }}} */ From 66cb2ead4bcb02e8d88d51f13142485dc1d75474 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 22 May 2020 10:08:30 +0200 Subject: [PATCH 2/2] Add comment --- Zend/zend_float.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Zend/zend_float.c b/Zend/zend_float.c index a840ffbc60014..2d7e6529a53d8 100644 --- a/Zend/zend_float.c +++ b/Zend/zend_float.c @@ -22,6 +22,7 @@ ZEND_API void zend_init_fpu(void) /* {{{ */ { +/* under __SSE__ the FPCW is irrelevant; no need to change it */ #if XPFPA_HAVE_CW && !defined(__SSE__) XPFPA_DECLARE