Piotr Caban : msvcrt: Don't use fegetenv in nearbyint.

Alexandre Julliard julliard at winehq.org
Tue Feb 1 15:21:33 CST 2022


Module: wine
Branch: master
Commit: 5d9d195f49693c7f6c99dab5e9337834b1ab04c4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5d9d195f49693c7f6c99dab5e9337834b1ab04c4

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Mon Jan 31 21:36:33 2022 +0100

msvcrt: Don't use fegetenv in nearbyint.

The fegetenv/feupdateenv functions are broken in msvcr120 and are
causing unintentional SSE control word changes.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcrt/math.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index b12ba3e9585..3907dc9dc94 100644
--- a/dlls/msvcrt/math.c
+++ b/dlls/msvcrt/math.c
@@ -6844,13 +6844,25 @@ double CDECL _yn(int n, double x)
  */
 double CDECL nearbyint(double x)
 {
-    fenv_t env;
+    BOOL update_cw, update_sw;
+    unsigned int cw, sw;
 
-    fegetenv(&env);
-    _control87(_MCW_EM, _MCW_EM);
+    _setfp(&cw, 0, &sw, 0);
+    update_cw = !(cw & _EM_INEXACT);
+    update_sw = !(sw & _SW_INEXACT);
+    if (update_cw)
+    {
+        cw |= _EM_INEXACT;
+        _setfp(&cw, _EM_INEXACT, NULL, 0);
+    }
     x = rint(x);
-    feclearexcept(FE_INEXACT);
-    feupdateenv(&env);
+    if (update_cw || update_sw)
+    {
+        sw = 0;
+        cw &= ~_EM_INEXACT;
+        _setfp(update_cw ? &cw : NULL, _EM_INEXACT,
+                update_sw ? &sw : NULL, _SW_INEXACT);
+    }
     return x;
 }
 




More information about the wine-cvs mailing list