Module: wine Branch: master Commit: f4de92a4ed5c8d8d8c1b57222ad3d10e7bd63229 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f4de92a4ed5c8d8d8c1b57222...
Author: Piotr Caban piotr@codeweavers.com Date: Thu Apr 29 17:06:41 2021 +0200
msvcrt: Import round implementation from musl.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
configure | 1 - configure.ac | 1 - dlls/msvcrt/math.c | 33 ++++++++++++++++++++++++++++++++- dlls/msvcrt/unixlib.c | 13 ------------- dlls/msvcrt/unixlib.h | 1 - include/config.h.in | 3 --- 6 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/configure b/configure index 2251a30af72..ca517b1d31a 100755 --- a/configure +++ b/configure @@ -19651,7 +19651,6 @@ for ac_func in \ remquof \ rint \ rintf \ - round \ tgamma \ tgammaf \ trunc \ diff --git a/configure.ac b/configure.ac index 20ec971b5bb..46bbb8a70f8 100644 --- a/configure.ac +++ b/configure.ac @@ -2694,7 +2694,6 @@ AC_CHECK_FUNCS(\ remquof \ rint \ rintf \ - round \ tgamma \ tgammaf \ trunc \ diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 018a8ae47e4..a29ed5786e2 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -87,6 +87,14 @@ static inline float fp_barrierf(float x) return y; }
+#if _MSVCR_VER>=120 +static inline double fp_barrier(double x) +{ + volatile double y = x; + return y; +} +#endif + static inline double CDECL ret_nan( BOOL update_sw ) { double x = 1.0; @@ -4321,10 +4329,33 @@ short CDECL _dclass(double x)
/********************************************************************* * round (MSVCR120.@) + * + * Copied from musl: src/math/round.c */ double CDECL round(double x) { - return unix_funcs->round(x); + static const double toint = 1 / DBL_EPSILON; + + ULONGLONG llx = *(ULONGLONG*)&x; + int e = llx >> 52 & 0x7ff; + double y; + + if (e >= 0x3ff + 52) + return x; + if (llx >> 63) + x = -x; + if (e < 0x3ff - 1) + return 0 * *(double*)&llx; + y = fp_barrier(x + toint) - toint - x; + if (y > 0.5) + y = y + x - 1; + else if (y <= -0.5) + y = y + x + 1; + else + y = y + x; + if (llx >> 63) + y = -y; + return y; }
/********************************************************************* diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c index a7c7202c516..33c25ef8d40 100644 --- a/dlls/msvcrt/unixlib.c +++ b/dlls/msvcrt/unixlib.c @@ -753,18 +753,6 @@ static float CDECL unix_rintf(float x) #endif }
-/********************************************************************* - * round - */ -static double CDECL unix_round(double x) -{ -#ifdef HAVE_ROUND - return round(x); -#else - return unix_rint(x); -#endif -} - /********************************************************************* * sin */ @@ -948,7 +936,6 @@ static const struct unix_funcs funcs = unix_remquof, unix_rint, unix_rintf, - unix_round, unix_sin, unix_sinf, unix_sinh, diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h index 89972ed669f..c96eda3c3a0 100644 --- a/dlls/msvcrt/unixlib.h +++ b/dlls/msvcrt/unixlib.h @@ -90,7 +90,6 @@ struct unix_funcs float (CDECL *remquof)(float x, float y, int *quo); double (CDECL *rint)(double x); float (CDECL *rintf)(float x); - double (CDECL *round)(double x); double (CDECL *sin)(double x); float (CDECL *sinf)(float x); double (CDECL *sinh)(double x); diff --git a/include/config.h.in b/include/config.h.in index 387c8b718ff..a0bc1b4b247 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -690,9 +690,6 @@ /* Define to 1 if you have the `rintf' function. */ #undef HAVE_RINTF
-/* Define to 1 if you have the `round' function. */ -#undef HAVE_ROUND - /* Define to 1 if you have the <sasl/sasl.h> header file. */ #undef HAVE_SASL_SASL_H