Module: wine Branch: master Commit: 554e7aee729df9dca7a84deb559c49749f25f069 URL: https://gitlab.winehq.org/wine/wine/-/commit/554e7aee729df9dca7a84deb559c497...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Mar 30 17:55:50 2023 +0200
msvcrt: Use the rint()/rintf() implementation from the bundled musl library.
---
dlls/msvcr120/msvcr120.spec | 4 +-- dlls/msvcrt/math.c | 79 ++++++++++++--------------------------------- dlls/ucrtbase/ucrtbase.spec | 8 ++--- libs/musl/src/math/rint.c | 4 +-- libs/musl/src/math/rintf.c | 4 +-- 5 files changed, 30 insertions(+), 69 deletions(-)
diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 102d6319f47..ec1fd48dce5 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -2334,9 +2334,9 @@ @ cdecl remquol(double double ptr) remquo @ cdecl rename(str str) @ cdecl rewind(ptr) -@ cdecl rint(double) +@ cdecl rint(double) MSVCRT_rint @ cdecl rintf(float) -@ cdecl rintl(double) rint +@ cdecl rintl(double) MSVCRT_rint @ cdecl round(double) @ cdecl roundf(float) @ cdecl roundl(double) round diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 1e67ced4360..b1cdb6efb64 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -953,37 +953,6 @@ double CDECL atan( double x ) return sign ? -z : z; }
-/********************************************************************* - * rint (MSVCR120.@) - * - * Copied from musl: src/math/rint.c - */ -double CDECL rint(double 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; -} - /* Copied from musl: src/math/exp_data.c */ static const UINT64 exp_T[] = { 0x0ULL, 0x3ff0000000000000ULL, @@ -2567,6 +2536,23 @@ int CDECL _isnan(double num)
#if _MSVCR_VER>=120
+/********************************************************************* + * rint (MSVCR120.@) + */ +double CDECL MSVCRT_rint(double x) +{ + unsigned cw; + double y; + + cw = _controlfp(0, 0); + if ((cw & _MCW_PC) != _PC_53) + _controlfp(_PC_53, _MCW_PC); + y = rint(x); + if ((cw & _MCW_PC) != _PC_53) + _controlfp(cw, _MCW_PC); + return y; +} + /********************************************************************* * _nearbyint (MSVCR120.@) * @@ -2585,7 +2571,7 @@ double CDECL nearbyint(double x) cw |= _EM_INEXACT; _setfp(&cw, _EM_INEXACT, NULL, 0); } - x = rint(x); + x = MSVCRT_rint(x); if (update_cw || update_sw) { sw = 0; @@ -3511,31 +3497,6 @@ void __cdecl __libm_sse2_sqrt_precise(void)
#if _MSVCR_VER>=120
-/********************************************************************* - * rintf (MSVCR120.@) - * - * Copied from musl: src/math/rintf.c - */ -float CDECL rintf(float x) -{ - static const float toint = 1 / FLT_EPSILON; - - unsigned int ix = *(unsigned int*)&x; - int e = ix >> 23 & 0xff; - int s = ix >> 31; - float y; - - if (e >= 0x7f + 23) - return x; - if (s) - y = fp_barrierf(x - toint) + toint; - else - y = fp_barrierf(x + toint) - toint; - if (y == 0) - return s ? -0.0f : 0.0f; - return y; -} - /********************************************************************* * lrint (MSVCR120.@) */ @@ -3543,7 +3504,7 @@ __msvcrt_long CDECL lrint(double x) { double d;
- d = rint(x); + d = MSVCRT_rint(x); if ((d < 0 && d != (double)(__msvcrt_long)d) || (d >= 0 && d != (double)(__msvcrt_ulong)d)) { *_errno() = EDOM; @@ -3575,7 +3536,7 @@ __int64 CDECL llrint(double x) { double d;
- d = rint(x); + d = MSVCRT_rint(x); if ((d < 0 && d != (double)(__int64)d) || (d >= 0 && d != (double)(unsigned __int64)d)) { *_errno() = EDOM; diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index a476681fc43..a05023b9f3e 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -1758,9 +1758,9 @@ @ cdecl _o_remquol(double double ptr) remquo @ cdecl _o_rename(str str) rename @ cdecl _o_rewind(ptr) rewind -@ cdecl _o_rint(double) rint +@ cdecl _o_rint(double) MSVCRT_rint @ cdecl _o_rintf(float) rintf -@ cdecl _o_rintl(double) rint +@ cdecl _o_rintl(double) MSVCRT_rint @ cdecl _o_round(double) round @ cdecl _o_roundf(float) roundf @ cdecl _o_roundl(double) round @@ -2471,9 +2471,9 @@ @ cdecl remquol(double double ptr) remquo @ cdecl rename(str str) @ cdecl rewind(ptr) -@ cdecl rint(double) +@ cdecl rint(double) MSVCRT_rint @ cdecl rintf(float) -@ cdecl rintl(double) rint +@ cdecl rintl(double) MSVCRT_rint @ cdecl round(double) @ cdecl roundf(float) @ cdecl roundl(double) round diff --git a/libs/musl/src/math/rint.c b/libs/musl/src/math/rint.c index 2de4ff0a99e..ad35201b266 100644 --- a/libs/musl/src/math/rint.c +++ b/libs/musl/src/math/rint.c @@ -20,9 +20,9 @@ double __cdecl rint(double x) if (e >= 0x3ff+52) return x; if (s) - y = x - toint + toint; + y = fp_barrier(x - toint) + toint; else - y = x + toint - toint; + y = fp_barrier(x + toint) - toint; if (y == 0) return s ? -0.0 : 0; return y; diff --git a/libs/musl/src/math/rintf.c b/libs/musl/src/math/rintf.c index 9e03461404d..455f9e3980f 100644 --- a/libs/musl/src/math/rintf.c +++ b/libs/musl/src/math/rintf.c @@ -22,9 +22,9 @@ float __cdecl rintf(float x) if (e >= 0x7f+23) return x; if (s) - y = x - toint + toint; + y = fp_barrierf(x - toint) + toint; else - y = x + toint - toint; + y = fp_barrierf(x + toint) - toint; if (y == 0) return s ? -0.0f : 0.0f; return y;