Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64sf_hypot.c
blob4d4925a215cbd3b46699fc373affe35500cc4c2f
1 /*
2 * Copyright 2023 Siemens
4 * The authors hereby grant permission to use, copy, modify, distribute,
5 * and license this software and its documentation for any purpose, provided
6 * that existing copyright notices are retained in all copies and that this
7 * notice is included verbatim in any distributions. No written agreement,
8 * license, or royalty fee is required for any of the authorized uses.
9 * Modifications to this software may be copyrighted by their authors
10 * and need not follow the licensing terms described here, provided that
11 * the new terms are clearly indicated on the first page of each file where
12 * they apply.
16 * ====================================================
17 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
19 * Developed at SunPro, a Sun Microsystems, Inc. business.
20 * Permission to use, copy, modify, and distribute this
21 * software is freely granted, provided that this notice
22 * is preserved.
23 * ====================================================
26 /* Based on newlib/libm/mathfp/ef_hypot.c in Newlib. */
28 #include "amdgcnmach.h"
30 v64sf v64sf_sqrtf_aux (v64sf, v64si);
32 DEF_VS_MATH_FUNC (v64sf, hypotf, v64sf x, v64sf y)
34 FUNCTION_INIT (v64sf);
36 v64sf a = x;
37 v64sf b = y;
39 v64si ha;
40 GET_FLOAT_WORD (ha, x, NO_COND);
41 ha &= 0x7fffffffL;
42 v64si hb;
43 GET_FLOAT_WORD (hb, y, NO_COND);
44 hb &= 0x7fffffffL;
46 VECTOR_IF (hb > ha, cond)
47 v64si j = ha;
48 VECTOR_COND_MOVE (ha, hb, cond);
49 VECTOR_COND_MOVE (hb, j, cond);
50 VECTOR_ENDIF
51 SET_FLOAT_WORD (a, ha, NO_COND); /* a <- |a| */
52 SET_FLOAT_WORD (b, hb, NO_COND); /* b <- |b| */
53 VECTOR_IF((ha - hb) > 0xf000000L, cond) // x/y > 2**30 */
54 VECTOR_RETURN (a + b, cond);
55 VECTOR_ENDIF
57 v64si k = VECTOR_INIT (0);
59 VECTOR_IF (ha > 0x58800000L, cond) /* a>2**50 */
60 VECTOR_IF2 (ha >= 0x7f800000L, cond2, cond) /* Inf or NaN */
61 v64sf w = a + b; // for sNaN */
62 VECTOR_COND_MOVE (w, a, cond2 & (ha == 0x7f800000));
63 VECTOR_COND_MOVE (w, b, cond2 & (hb == 0x7f800000));
64 VECTOR_RETURN (w, cond);
65 VECTOR_ENDIF
66 /* scale a and b by 2**-60 */
67 VECTOR_COND_MOVE (ha, ha - 0x5d800000, cond);
68 VECTOR_COND_MOVE (hb, hb - 0x5d800000, cond);
69 VECTOR_COND_MOVE (k, k + 60, cond);
70 SET_FLOAT_WORD (a, ha, cond);
71 SET_FLOAT_WORD (b, hb, cond);
72 VECTOR_ENDIF
73 VECTOR_IF (hb < 0x26800000, cond) /* b < 2**-50 */
74 VECTOR_IF2 (hb <= 0x007fffff, cond2, cond) /* subnormal b or 0 */
75 VECTOR_RETURN (a, cond2 & (hb == 0));
76 /* t1=2^126 */
77 v64sf t1;
78 SET_FLOAT_WORD (t1, VECTOR_INIT (0x3f000000), cond2);
79 VECTOR_COND_MOVE (b, b * t1, cond2);
80 VECTOR_COND_MOVE (a, a * t1, cond2);
81 VECTOR_COND_MOVE (k, k - 126, cond2);
82 VECTOR_ELSE2 (cond2, cond) /* scale a and b by 2^60 */
83 VECTOR_COND_MOVE (ha, ha + 0x5d800000, cond2); /* a *= 2^60 */
84 VECTOR_COND_MOVE (hb, hb + 0x5d800000, cond2); /* b *= 2^60 */
85 VECTOR_COND_MOVE (k, k - 60, cond2);
86 SET_FLOAT_WORD (a, ha, cond2);
87 SET_FLOAT_WORD (b, hb, cond2);
88 VECTOR_ENDIF
89 VECTOR_ENDIF
90 /* medium size a and b */
91 v64sf w = a - b;
92 VECTOR_IF (w > b, cond)
93 v64sf t1;
94 SET_FLOAT_WORD (t1, ha & 0xfffff000, cond);
95 v64sf t2 = a - t1;
96 VECTOR_COND_MOVE (w, v64sf_sqrtf_aux (t1*t1 - (b*(-b) - t2 * (a + t1)), __mask), cond);
97 VECTOR_ELSE (cond)
98 VECTOR_COND_MOVE (a, a+a, cond);
99 v64sf y1;
100 SET_FLOAT_WORD (y1, hb & 0xfffff000, cond);
101 v64sf y2 = b - y1;
102 v64sf t1;
103 SET_FLOAT_WORD (t1, ha + 0x00800000, cond);
104 v64sf t2 = a - t1;
105 VECTOR_COND_MOVE (w, v64sf_sqrtf_aux (t1*y1 - (w*(-w) - (t1*y2 + t2*b)), __mask), cond);
106 VECTOR_ENDIF
107 VECTOR_IF (k != 0, cond)
108 v64sf t1;
109 SET_FLOAT_WORD (t1, 0x3f800000 + (k << 23), cond);
110 VECTOR_RETURN (t1 * w, cond);
111 VECTOR_ELSE (cond)
112 VECTOR_RETURN (w, cond);
113 VECTOR_ENDIF
115 FUNCTION_RETURN;
118 DEF_VARIANTS2 (hypotf, sf, sf)