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 in newlib/libm/mathfp/sf_sineh.c in Newlib. */
39 #include "amdgcnmach.h"
41 v64sf
v64sf_expf_aux (v64sf
, v64si
);
42 v64si
v64sf_numtestf (v64sf
);
43 v64si
v64sf_isposf (v64sf
);
45 static const float q
[] = { -0.428277109e+2 };
46 static const float p
[] = { -0.713793159e+1,
48 static const float LNV
= 0.6931610107;
49 static const float INV_V2
= 0.2499930850;
50 static const float V_OVER2_MINUS1
= 0.1383027787e-4;
52 #if defined (__has_builtin) && __has_builtin (__builtin_gcn_fabsvf)
54 DEF_VS_MATH_FUNC (v64sf
, sinehf
, v64sf x
, int cosineh
)
56 const float WBAR
= 18.55;
58 FUNCTION_INIT (v64sf
);
60 v64si sgn
= VECTOR_INIT (0);
61 v64si v_cosineh
= VECTOR_INIT (cosineh
? -1 : 0);
63 /* Check for special values. */
64 v64si num_type
= v64sf_numtestf (x
);
65 VECTOR_IF (num_type
== NAN
, cond
)
67 VECTOR_RETURN (x
, cond
);
68 VECTOR_ELSEIF (num_type
== INF
, cond
)
70 VECTOR_RETURN (VECTOR_MERGE (VECTOR_INIT (z_infinity_f
.f
),
71 VECTOR_INIT (-z_infinity_f
.f
),
76 v64sf y
= __builtin_gcn_fabsvf (x
);
79 VECTOR_COND_MOVE (sgn
, VECTOR_INIT (-1), x
< 0.0f
);
83 VECTOR_IF (((y
> 1.0f
) & ~v_cosineh
) | v_cosineh
, cond
)
84 VECTOR_IF2 (y
> (float) BIGX
, cond2
, cond
)
87 /* Check for w > maximum here. */
88 VECTOR_IF2 (w
> (float) BIGX
, cond3
, cond2
)
90 VECTOR_RETURN (x
, cond3
);
93 v64sf z
= v64sf_expf_aux (w
, __mask
);
95 VECTOR_COND_MOVE (res
, z
* (V_OVER2_MINUS1
+ 1.0f
),
97 VECTOR_ELSE2 (cond2
, cond
)
98 v64sf z
= v64sf_expf_aux (y
, __mask
);
100 VECTOR_COND_MOVE (res
, (z
+ 1 / z
) * 0.5f
, cond2
);
102 VECTOR_COND_MOVE (res
, (z
- 1 / z
) * 0.5f
, cond2
);
106 VECTOR_COND_MOVE (res
, -res
, sgn
);
108 /* Check for y being too small. */
109 VECTOR_IF2 (y
< z_rooteps_f
, cond2
, cond
);
110 VECTOR_COND_MOVE (res
, x
, cond2
);
111 VECTOR_ELSE2 (cond2
, cond
)
112 /* Calculate the Taylor series. */
115 v64sf P
= p
[1] * f
+ p
[0];
116 v64sf R
= f
* (P
/ Q
);
118 VECTOR_COND_MOVE (res
, x
+ x
* R
, cond2
);
122 VECTOR_RETURN (res
, NO_COND
);