Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
e53c4bd5
Commit
e53c4bd5
authored
Feb 01, 2021
by
Piotr Caban
Committed by
Alexandre Julliard
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Imporve sqrt accuracy and performance on x86_64.
Signed-off-by:
Piotr Caban
<
piotr@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
b3fcb0f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
26 deletions
+62
-26
math.c
dlls/msvcrt/math.c
+62
-26
No files found.
dlls/msvcrt/math.c
View file @
e53c4bd5
...
...
@@ -1165,6 +1165,43 @@ double CDECL sinh( double x )
return
ret
;
}
static
inline
double
CDECL
ret_nan
(
void
)
{
double
x
=
1
.
0
;
return
(
x
-
x
)
/
(
x
-
x
);
}
BOOL
sqrt_validate
(
double
*
x
)
{
short
c
=
_dclass
(
*
x
);
if
(
c
==
FP_ZERO
)
return
FALSE
;
if
(
c
==
FP_NAN
)
{
#ifdef __i386__
*
x
=
math_error
(
_DOMAIN
,
"sqrt"
,
*
x
,
0
,
*
x
);
#else
/* set signaling bit */
*
(
ULONGLONG
*
)
x
|=
0x8000000000000ULL
;
#endif
return
FALSE
;
}
if
(
signbit
(
*
x
))
{
*
x
=
math_error
(
_DOMAIN
,
"sqrt"
,
*
x
,
0
,
ret_nan
());
return
FALSE
;
}
if
(
c
==
FP_INFINITE
)
return
FALSE
;
return
TRUE
;
}
#if defined(__x86_64__)
double
CDECL
sse2_sqrt
(
double
);
__ASM_GLOBAL_FUNC
(
sse2_sqrt
,
"sqrtsd %xmm0, %xmm0
\n\t
"
"ret"
)
#endif
/*********************************************************************
* sqrt (MSVCRT.@)
*
...
...
@@ -1172,6 +1209,12 @@ double CDECL sinh( double x )
*/
double
CDECL
sqrt
(
double
x
)
{
#ifdef __x86_64__
if
(
!
sqrt_validate
(
&
x
))
return
x
;
return
sse2_sqrt
(
x
);
#else
static
const
double
tiny
=
1.0e-300
;
double
z
;
...
...
@@ -1180,21 +1223,13 @@ double CDECL sqrt( double x )
unsigned
int
r
,
t1
,
s1
,
ix1
,
q1
;
ULONGLONG
ix
;
if
(
!
sqrt_validate
(
&
x
))
return
x
;
ix
=
*
(
ULONGLONG
*
)
&
x
;
ix0
=
ix
>>
32
;
ix1
=
ix
;
/* take care of Inf and NaN */
if
(
isnan
(
x
)
||
(
isinf
(
x
)
&&
x
>
0
))
return
x
;
/* take care of zero */
if
(
ix0
<=
0
)
{
if
(((
ix0
&
~
sign
)
|
ix1
)
==
0
)
return
x
;
/* sqrt(+-0) = +-0 */
if
(
ix0
<
0
)
return
math_error
(
_DOMAIN
,
"sqrt"
,
x
,
0
,
(
x
-
x
)
/
(
x
-
x
));
}
/* normalize x */
m
=
ix0
>>
20
;
if
(
m
==
0
)
{
/* subnormal x */
...
...
@@ -1278,6 +1313,7 @@ double CDECL sqrt( double x )
ix
<<=
32
;
ix
|=
ix1
;
return
*
(
double
*
)
&
ix
;
#endif
}
/*********************************************************************
...
...
@@ -3424,6 +3460,21 @@ __int64 CDECL llrintf(float x)
return
unix_funcs
->
llrintf
(
x
);
}
/*********************************************************************
* _dclass (MSVCR120.@)
*
* Copied from musl: src/math/__fpclassify.c
*/
short
CDECL
_dclass
(
double
x
)
{
union
{
double
f
;
UINT64
i
;
}
u
=
{
x
};
int
e
=
u
.
i
>>
52
&
0x7ff
;
if
(
!
e
)
return
u
.
i
<<
1
?
FP_SUBNORMAL
:
FP_ZERO
;
if
(
e
==
0x7ff
)
return
(
u
.
i
<<
12
)
?
FP_NAN
:
FP_INFINITE
;
return
FP_NORMAL
;
}
#if _MSVCR_VER>=120
/*********************************************************************
...
...
@@ -3491,21 +3542,6 @@ float CDECL truncf(float x)
}
/*********************************************************************
* _dclass (MSVCR120.@)
*
* Copied from musl: src/math/__fpclassify.c
*/
short
CDECL
_dclass
(
double
x
)
{
union
{
double
f
;
UINT64
i
;
}
u
=
{
x
};
int
e
=
u
.
i
>>
52
&
0x7ff
;
if
(
!
e
)
return
u
.
i
<<
1
?
FP_SUBNORMAL
:
FP_ZERO
;
if
(
e
==
0x7ff
)
return
(
u
.
i
<<
12
)
?
FP_NAN
:
FP_INFINITE
;
return
FP_NORMAL
;
}
/*********************************************************************
* _fdclass (MSVCR120.@)
*
* Copied from musl: src/math/__fpclassifyf.c
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment