ReactOS 0.4.15-dev-7953-g1f49173
hypotf.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#ifdef USE_SOFTWARE_SQRT
31#define USE_SQRTF_AMD_INLINE
32#endif
33#define USE_INFINITYF_WITH_FLAGS
34#define USE_HANDLE_ERRORF
35#include "libm_inlines.h"
36#ifdef USE_SOFTWARE_SQRT
37#undef USE_SQRTF_AMD_INLINE
38#endif
39#undef USE_INFINITYF_WITH_FLAGS
40#undef USE_HANDLE_ERRORF
41
42#include "libm_errno.h"
43
44
45float FN_PROTOTYPE(_hypotf)(float x, float y)
46{
47 /* Returns sqrt(x*x + y*y) with no overflow or underflow unless
48 the result warrants it */
49
50 /* Do intermediate computations in double precision
51 and use sqrt instruction from chip if available. */
52 double dx = x, dy = y, dr, retval;
53
54 /* The largest finite float, stored as a double */
55 const double large = 3.40282346638528859812e+38; /* 0x47efffffe0000000 */
56
57
58 unsigned long long ux, uy, avx, avy;
59
61 avx &= ~SIGNBIT_DP64;
62 GET_BITS_DP64(y, avy);
63 avy &= ~SIGNBIT_DP64;
64 ux = (avx >> EXPSHIFTBITS_DP64);
65 uy = (avy >> EXPSHIFTBITS_DP64);
66
67 if (ux == BIASEDEMAX_DP64 + 1 || uy == BIASEDEMAX_DP64 + 1)
68 {
69 retval = x*x + y*y;
70 /* One or both of the arguments are NaN or infinity. The
71 result will also be NaN or infinity. */
72 if (((ux == BIASEDEMAX_DP64 + 1) && !(avx & MANTBITS_DP64)) ||
73 ((uy == BIASEDEMAX_DP64 + 1) && !(avy & MANTBITS_DP64)))
74 /* x or y is infinity. ISO C99 defines that we must
75 return +infinity, even if the other argument is NaN.
76 Note that the computation of x*x + y*y above will already
77 have raised invalid if either x or y is a signalling NaN. */
78 return infinityf_with_flags(0);
79 else
80 /* One or both of x or y is NaN, and neither is infinity.
81 Raise invalid if it's a signalling NaN */
82 return (float)retval;
83 }
84
85 dr = (dx*dx + dy*dy);
86
87#if USE_SOFTWARE_SQRT
88 retval = sqrtf_amd_inline(r);
89#else
90 /* VC++ intrinsic call */
92#endif
93
94 if (retval > large)
95 return _handle_errorf("_hypotf", OP_HYPOT, PINFBITPATT_SP32, _OVERFLOW,
97 else
98 return (float)retval;
99}
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 ERANGE
Definition: acclib.h:92
__m128d _mm_setzero_pd(void)
Definition: emmintrin.h:1048
__m128d _mm_sqrt_sd(__m128d a, __m128d b)
Definition: emmintrin.h:611
__m128d _mm_load_sd(double const *dp)
Definition: emmintrin.h:991
void _mm_store_sd(double *dp, __m128d a)
Definition: emmintrin.h:1059
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
float FN_PROTOTYPE() _hypotf(float x, float y)
Definition: hypotf.c:45
#define _OVERFLOW
Definition: math.h:41
#define FN_PROTOTYPE(fname)
Definition: libm.h:29
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_OVERFLOW
Definition: libm_new.h:83
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define BIASEDEMAX_DP64
Definition: libm_util.h:59
#define PINFBITPATT_SP32
Definition: libm_util.h:77
#define MANTBITS_DP64
Definition: libm_util.h:46
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
@ avx
Definition: optimize.h:112