ReactOS 0.4.16-dev-250-g3ecd236
sqrtf.c
Go to the documentation of this file.
1
2/*******************************************************************************
3MIT License
4-----------
5
6Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this Software and associated documentaon files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25*******************************************************************************/
26
27#include "libm.h"
28#include "libm_util.h"
29
30#if USE_SOFTWARE_SQRT
31#define USE_SQRTF_AMD_INLINE
32#endif
33#define USE_NANF_WITH_FLAGS
34#define USE_HANDLE_ERRORF
35#include "libm_inlines.h"
36#if USE_SOFTWARE_SQRT
37#undef USE_SQRTF_AMD_INLINE
38#endif
39#undef USE_NANF_WITH_FLAGS
40#undef USE_HANDLE_ERRORF
41
42#include "libm_errno.h"
43
44// Disable "C4163: not available as intrinsic function" warning that older
45// compilers may issue here.
46#pragma warning(disable:4163)
47#pragma function(sqrtf)
48
49
50float sqrtf(float x)
51{
52#if USE_SOFTWARE_SQRT
53 return sqrtf_amd_inline(x);
54#else
55 float r;
56 unsigned int ux;
57 GET_BITS_SP32(x, ux);
58 /* Check for special cases for Microsoft error handling */
60 {
61 /* x is infinity, or NaN */
62 if (ux & MANTBITS_SP32)
63 {
64 /* NaN of some sort */
65 /* If it's a signaling NaN, convert to QNaN */
66 return _handle_errorf("sqrtf", OP_SQRT, ux|0x00400000, _DOMAIN, 0,
67 EDOM, x, 0.0F, 1);
68 }
69 else
70 {
71 /* +/-infinity */
72 if (ux & SIGNBIT_SP32)
73 {
74 /* - infinity */
75 return _handle_errorf("sqrtf", OP_SQRT, INDEFBITPATT_SP32,
76 _DOMAIN, AMD_F_INVALID, EDOM, x, 0.0F, 1);
77 }
78 /* positive infinite is not a problem */
79 }
80 }
81 if ((ux & SIGNBIT_SP32)&&(ux & ~SIGNBIT_SP32)) /* if x < zero */
82 {
83 return _handle_errorf("sqrtf", OP_SQRT, INDEFBITPATT_SP32,
84 _DOMAIN, AMD_F_INVALID, EDOM, x, 0.0F, 1);
85 }
86
87 /* VC++ intrinsic call */
89 return r;
90#endif
91}
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
#define EDOM
Definition: errno.h:39
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define _DOMAIN
Definition: math.h:39
#define AMD_F_INVALID
Definition: libm_new.h:86
#define INDEFBITPATT_SP32
Definition: libm_util.h:76
#define GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#define SIGNBIT_SP32
Definition: libm_util.h:68
#define PINFBITPATT_SP32
Definition: libm_util.h:77
#define MANTBITS_SP32
Definition: libm_util.h:70
#define sqrtf(x)
Definition: mymath.h:59
void _mm_store_ss(float *p, __m128 a)
Definition: xmmintrin.h:1052
__m128 _mm_load_ss(float const *p)
Definition: xmmintrin.h:956
__m128 _mm_sqrt_ss(__m128 a)
Definition: xmmintrin.h:592