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
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
35 ******************************************************************/
37 /* Based on newlib/libm/mathfp/sf_asine.c in Newlib. */
39 #include "amdgcnmach.h"
41 v64si
v64sf_numtestf (v64sf
);
42 v64sf
v64sf_sqrtf (v64sf
);
44 static const float p
[] = { 0.933935835, -0.504400557 };
45 static const float q
[] = { 0.560363004e+1, -0.554846723e+1 };
46 static const float a
[] = { 0.0, 0.785398163 };
47 static const float b
[] = { 1.570796326, 0.785398163 };
49 #if defined (__has_builtin) && __has_builtin (__builtin_gcn_fabsvf)
51 DEF_VS_MATH_FUNC (v64sf
, asinef
, v64sf x
, int acosine
)
53 FUNCTION_INIT (v64sf
);
55 v64si branch
= VECTOR_INIT (0);
57 /* Check for special values. */
58 v64si i
= v64sf_numtestf (x
);
59 VECTOR_IF ((i
== NAN
) | (i
== INF
), cond
)
61 VECTOR_RETURN (VECTOR_MERGE (x
, VECTOR_INIT (z_infinity_f
.f
),
66 v64sf y
= __builtin_gcn_fabsvf (x
);
69 VECTOR_IF (y
> 0.5f
, cond
)
70 VECTOR_COND_MOVE (i
, VECTOR_INIT (1 - acosine
), cond
);
72 /* Check for range error. */
73 VECTOR_IF2 (y
> 1.0f
, cond2
, cond
)
75 VECTOR_RETURN (VECTOR_INIT (z_notanum_f
.f
), cond2
);
78 VECTOR_COND_MOVE (g
, (1.0f
- y
) / 2.0f
, cond
);
79 VECTOR_COND_MOVE (y
, -2.0f
* v64sf_sqrtf (g
), cond
);
80 VECTOR_COND_MOVE (branch
, VECTOR_INIT (-1), cond
);
82 VECTOR_COND_MOVE (i
, VECTOR_INIT (acosine
), cond
);
83 VECTOR_IF2 (y
< z_rooteps_f
, cond2
, cond
)
84 VECTOR_COND_MOVE (res
, y
, cond2
);
85 VECTOR_ELSE2 (cond2
, cond
)
86 VECTOR_COND_MOVE (g
, y
* y
, cond2
);
90 VECTOR_IF ((y
>= z_rooteps_f
) | branch
, cond
)
92 /* Calculate the Taylor series. */
93 v64sf P
= (p
[1] * g
+ p
[0]) * g
;
94 v64sf Q
= (g
+ q
[1]) * g
+ q
[0];
97 VECTOR_COND_MOVE (res
, y
+ y
* R
, cond
);
101 v64sf a_i
= VECTOR_MERGE (VECTOR_INIT (a
[1]), VECTOR_INIT (a
[0]), i
!= 0);
103 /* Calculate asine or acose. */
106 VECTOR_COND_MOVE (res
, (a_i
+ res
) + a_i
, NO_COND
);
107 VECTOR_IF (x
< 0.0f
, cond
)
108 VECTOR_COND_MOVE (res
, -res
, cond
);
113 v64sf b_i
= VECTOR_MERGE (VECTOR_INIT(b
[1]), VECTOR_INIT(b
[0]), i
!= 0);
115 VECTOR_IF (x
< 0.0f
, cond
)
116 VECTOR_COND_MOVE (res
, (b_i
+ res
) + b_i
, cond
);
118 VECTOR_COND_MOVE (res
, (a_i
- res
) + a_i
, cond
);
122 VECTOR_RETURN (res
, NO_COND
);