devctl.h: update for POSIX-1.2024
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64df_asine.c
blobd1af526ef202a65e767a9eda13d38f418a863e5a
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 * Copyright (c) 1994-2009 Red Hat, Inc. All rights reserved.
18 * This copyrighted material is made available to anyone wishing to use,
19 * modify, copy, or redistribute it subject to the terms and conditions
20 * of the BSD License. This program is distributed in the hope that
21 * it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
22 * including the implied warranties of MERCHANTABILITY or FITNESS FOR
23 * A PARTICULAR PURPOSE. A copy of this license is available at
24 * http://www.opensource.org/licenses. Any Red Hat trademarks that are
25 * incorporated in the source code or documentation are not subject to
26 * the BSD License and may only be used or replicated with the express
27 * permission of Red Hat, Inc.
30 /******************************************************************
31 * The following routines are coded directly from the algorithms
32 * and coefficients given in "Software Manual for the Elementary
33 * Functions" by William J. Cody, Jr. and William Waite, Prentice
34 * Hall, 1980.
35 ******************************************************************/
37 /* Based on newlib/libm/mathfp/s_asine.c in Newlib. */
39 #include "amdgcnmach.h"
41 v64si v64df_numtest (v64df);
42 v64df v64df_sqrt_aux (v64df, v64di);
44 static const double p[] = { -0.27368494524164255994e+2,
45 0.57208227877891731407e+2,
46 -0.39688862997404877339e+2,
47 0.10152522233806463645e+2,
48 -0.69674573447350646411 };
49 static const double q[] = { -0.16421096714498560795e+3,
50 0.41714430248260412556e+3,
51 -0.38186303361750149284e+3,
52 0.15095270841030604719e+3,
53 -0.23823859153670238830e+2 };
54 static const double a[] = { 0.0, 0.78539816339744830962 };
55 static const double b[] = { 1.57079632679489661923, 0.78539816339744830962 };
57 #if defined (__has_builtin) && __has_builtin (__builtin_gcn_fabsv)
59 DEF_VD_MATH_FUNC (v64df, asine, v64df x, int acosine)
61 FUNCTION_INIT (v64df);
63 v64si branch = VECTOR_INIT (0);
65 /* Check for special values. */
66 v64si i = v64df_numtest (x);
67 VECTOR_IF ((i == NAN) | (i == INF), cond)
68 errno = EDOM;
69 VECTOR_RETURN (VECTOR_MERGE (x, VECTOR_INIT (z_infinity.d),
70 i == NAN),
71 cond);
72 VECTOR_ENDIF
74 v64df y = __builtin_gcn_fabsv (x);
75 v64df g, res;
77 VECTOR_IF (y > 0.5, cond)
78 VECTOR_COND_MOVE (i, VECTOR_INIT (1 - acosine), cond);
80 /* Check for range error. */
81 VECTOR_IF2 (y > 1.0, cond2, cond)
82 errno = ERANGE;
83 VECTOR_RETURN (VECTOR_INIT (z_notanum.d), cond2);
84 VECTOR_ENDIF
86 VECTOR_COND_MOVE (g, (1.0 - y) / 2.0, cond);
87 VECTOR_COND_MOVE (y, -2.0 * v64df_sqrt_aux (g, __mask), cond);
88 VECTOR_COND_MOVE (branch, VECTOR_INIT (-1), cond);
89 VECTOR_ELSE (cond)
90 VECTOR_COND_MOVE (i, VECTOR_INIT (acosine), cond);
91 VECTOR_IF2 (y < z_rooteps, cond2, cond)
92 VECTOR_COND_MOVE (res, y, cond2);
93 VECTOR_ELSE2 (cond2, cond)
94 VECTOR_COND_MOVE (g, y * y, cond2);
95 VECTOR_ENDIF
96 VECTOR_ENDIF
98 VECTOR_IF ((y >= z_rooteps) | __builtin_convertvector(branch, v64di), cond)
100 /* Calculate the Taylor series. */
101 v64df P = ((((p[4] * g + p[3]) * g + p[2]) * g + p[1]) * g + p[0]) * g;
102 v64df Q = ((((g + q[4]) * g + q[3]) * g + q[2]) * g + q[1]) * g + q[0];
103 v64df R = P / Q;
105 VECTOR_COND_MOVE (res, y + y * R, cond);
107 VECTOR_ENDIF
109 v64df a_i = VECTOR_MERGE (VECTOR_INIT (a[1]), VECTOR_INIT (a[0]), i != 0);
111 /* Calculate asine or acose. */
112 if (acosine == 0)
114 VECTOR_COND_MOVE (res, (a_i + res) + a_i, NO_COND);
115 VECTOR_IF (x < 0.0, cond)
116 VECTOR_COND_MOVE (res, -res, cond);
117 VECTOR_ENDIF
119 else
121 v64df b_i = VECTOR_MERGE (VECTOR_INIT(b[1]), VECTOR_INIT(b[0]), i != 0);
123 VECTOR_IF (x < 0.0, cond)
124 VECTOR_COND_MOVE (res, (b_i + res) + b_i, cond);
125 VECTOR_ELSE (cond)
126 VECTOR_COND_MOVE (res, (a_i - res) + a_i, cond);
127 VECTOR_ENDIF
130 VECTOR_RETURN (res, NO_COND);
132 FUNCTION_RETURN;
135 #endif