Piotr Caban : msvcrt: Import rint implementation from musl.
Alexandre Julliard
julliard at winehq.org
Mon May 10 15:44:05 CDT 2021
Module: wine
Branch: master
Commit: cba9981c473211ee53777dae70d82d3f80f92308
URL: https://source.winehq.org/git/wine.git/?a=commit;h=cba9981c473211ee53777dae70d82d3f80f92308
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon May 10 20:11:34 2021 +0200
msvcrt: Import rint implementation from musl.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at 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 2a4a756c812..59248c28c99 100755
--- a/configure
+++ b/configure
@@ -19652,7 +19652,6 @@ for ac_func in \
remainderf \
remquo \
remquof \
- rint \
rintf \
tgamma \
tgammaf \
diff --git a/configure.ac b/configure.ac
index 5578ee98edf..0c1ea608d7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2692,7 +2692,6 @@ AC_CHECK_FUNCS(\
remainderf \
remquo \
remquof \
- rint \
rintf \
tgamma \
tgammaf \
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c
index 95c83fcbcc9..c1702c5b810 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;
@@ -4273,10 +4281,33 @@ float CDECL log2f(float x)
/*********************************************************************
* rint (MSVCR120.@)
+ *
+ * Copied from musl: src/math/rint.c
*/
double CDECL rint(double x)
{
- return unix_funcs->rint(x);
+ static const double toint = 1 / DBL_EPSILON;
+
+ ULONGLONG llx = *(ULONGLONG*)&x;
+ int e = llx >> 52 & 0x7ff;
+ int s = llx >> 63;
+ unsigned cw;
+ double y;
+
+ if (e >= 0x3ff+52)
+ return x;
+ cw = _controlfp(0, 0);
+ if ((cw & _MCW_PC) != _PC_53)
+ _controlfp(_PC_53, _MCW_PC);
+ if (s)
+ y = fp_barrier(x - toint) + toint;
+ else
+ y = fp_barrier(x + toint) - toint;
+ if ((cw & _MCW_PC) != _PC_53)
+ _controlfp(cw, _MCW_PC);
+ if (y == 0)
+ return s ? -0.0 : 0;
+ return y;
}
/*********************************************************************
diff --git a/dlls/msvcrt/unixlib.c b/dlls/msvcrt/unixlib.c
index 33c25ef8d40..f72fd0cc161 100644
--- a/dlls/msvcrt/unixlib.c
+++ b/dlls/msvcrt/unixlib.c
@@ -729,18 +729,6 @@ static float CDECL unix_remquof(float x, float y, int *quo)
#endif
}
-/*********************************************************************
- * rint
- */
-static double CDECL unix_rint(double x)
-{
-#ifdef HAVE_RINT
- return rint(x);
-#else
- return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
-#endif
-}
-
/*********************************************************************
* rintf
*/
@@ -934,7 +922,6 @@ static const struct unix_funcs funcs =
unix_remainderf,
unix_remquo,
unix_remquof,
- unix_rint,
unix_rintf,
unix_sin,
unix_sinf,
diff --git a/dlls/msvcrt/unixlib.h b/dlls/msvcrt/unixlib.h
index c96eda3c3a0..f5245cfb645 100644
--- a/dlls/msvcrt/unixlib.h
+++ b/dlls/msvcrt/unixlib.h
@@ -88,7 +88,6 @@ struct unix_funcs
float (CDECL *remainderf)(float x, float y);
double (CDECL *remquo)(double x, double y, int *quo);
float (CDECL *remquof)(float x, float y, int *quo);
- double (CDECL *rint)(double x);
float (CDECL *rintf)(float x);
double (CDECL *sin)(double x);
float (CDECL *sinf)(float x);
diff --git a/include/config.h.in b/include/config.h.in
index a0bc1b4b247..181cbc3d5aa 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -684,9 +684,6 @@
/* Define to 1 if you have the `res_getservers' function. */
#undef HAVE_RES_GETSERVERS
-/* Define to 1 if you have the `rint' function. */
-#undef HAVE_RINT
-
/* Define to 1 if you have the `rintf' function. */
#undef HAVE_RINTF
More information about the wine-cvs
mailing list