/ include / libm_special.h
libm_special.h
  1  /*
  2   * Copyright (C) 2008-2020 Advanced Micro Devices, Inc. All rights reserved.
  3   *
  4   * Redistribution and use in source and binary forms, with or without modification,
  5   * are permitted provided that the following conditions are met:
  6   * 1. Redistributions of source code must retain the above copyright notice,
  7   *    this list of conditions and the following disclaimer.
  8   * 2. Redistributions in binary form must reproduce the above copyright notice,
  9   *    this list of conditions and the following disclaimer in the documentation
 10   *    and/or other materials provided with the distribution.
 11   * 3. Neither the name of the copyright holder nor the names of its contributors
 12   *    may be used to endorse or promote products derived from this software without
 13   *    specific prior written permission.
 14   *
 15   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 16   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 17   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 18   * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 19   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 20   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 21   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 22   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 23   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 24   * POSSIBILITY OF SUCH DAMAGE.
 25   *
 26   */
 27  
 28  #ifndef __LIBM_SPECIAL_H__
 29  #define __LIBM_SPECIAL_H__
 30  
 31  #include <stdint.h>
 32  
 33  #include <math.h>
 34  #include <libm_errno_amd.h>
 35  #if defined(WIN64)  |  defined(WINDOWS)
 36  
 37  #include <fpieee.h>
 38  #define EXCEPTION_S _exception
 39  #define __amd_handle_error _handle_error
 40  #define __amd_handle_errorf _handle_errorf
 41  
 42  double _handle_error(
 43          char *fname,
 44          int opcode,
 45          unsigned long long value,
 46          int type,
 47          int flags,
 48          int error,
 49          double arg1,
 50          double arg2,
 51          int nargs
 52          );
 53  
 54  float _handle_errorf(
 55          char *fname,
 56          int opcode,
 57          unsigned long long value,
 58          int type,
 59          int flags,
 60          int error,
 61          float arg1,
 62          float arg2,
 63          int nargs
 64          );
 65  
 66  #else //Windows
 67  #define EXCEPTION_S exception
 68  
 69  double __amd_handle_error(
 70          char *fname,
 71          int opcode,
 72          unsigned long long value,
 73          int type,
 74          int flags,
 75          int error,
 76          double arg1,
 77          double arg2,
 78          int nargs
 79          );
 80  
 81  float __amd_handle_errorf(
 82          char *fname,
 83          int opcode,
 84          unsigned long long value,
 85          int type,
 86          int flags,
 87          int error,
 88          float arg1,
 89          float arg2,
 90          int nargs
 91          );
 92  
 93  
 94  
 95  typedef enum {
 96      __amd_unspecified,
 97      __amd_add,
 98      __amd_subtract,
 99      __amd_multiply,
100      __amd_divide,
101      __amd_squareroot,
102      __amd_remainder,
103      __amd_compare,
104      __amd_convert,
105      __amd_round,
106      __amd_truncate,
107      __amd_floor,
108      __amd_ceil,
109      __amd_acos,
110      __amd_asin,
111      __amd_atan,
112      __amd_atan2,
113      __amd_cabs,
114      __amd_cos,
115      __amd_cosh,
116      __amd_exp,
117      __amd_fabs,
118      __amd_fmod,
119      __amd_frexp,
120      __amd_hypot,
121      __amd_ldexp,
122      __amd_log,
123      __amd_log10,
124      __amd_modf,
125      __amd_pow,
126      __amd_sin,
127      __amd_sinh,
128      __amd_tan,
129      __amd_tanh,
130      __amd_y0,
131      __amd_y1,
132      __amd_yn,
133      __amd_logb,
134      __amd_nextafter,
135      __amd_negate, 
136      __amd_fmin,         
137      __amd_fmax,         
138      __amd_converttrunc, 
139      __amd_addps,        
140      __amd_addss,
141      __amd_subps,
142      __amd_subss,
143      __amd_mulps,
144      __amd_mulss,
145      __amd_divps,
146      __amd_divss,
147      __amd_sqrtps,
148      __amd_sqrtss,
149      __amd_maxps,
150      __amd_maxss,
151      __amd_minps,
152      __amd_minss,
153      __amd_cmpps,
154      __amd_cmpss,
155      __amd_comiss,
156      __amd_ucomiss,
157      __amd_cvtpi2ps,
158      __amd_cvtsi2ss,
159      __amd_cvtps2pi,
160      __amd_Cvtss2si,
161      __amd_cvttps2pi,
162      __amd_cvttss2si,
163      __amd_addsubps,       /* XMMI for PNI */
164      __amd_haddps,         /* XMMI for PNI */
165      __amd_hsubps,         /* XMMI for PNI */
166      __amd_roundps,        /* 66 0F 3A 08  */ 
167      __amd_roundss,        /* 66 0F 3A 0A  */
168      __amd_dpps,           /* 66 0F 3A 40  */
169      __amd_addpd,         /* XMMI2 */ 
170      __amd_addsd,
171      __amd_subpd,
172      __amd_subsd,
173      __amd_mulpd,
174      __amd_mulsd,
175      __amd_divpd,
176      __amd_divsd,
177      __amd_sqrtpd,
178      __amd_sqrtsd,
179      __amd_maxpd,
180      __amd_maxsd,
181      __amd_minpd,
182      __amd_minsd,
183      __amd_cmppd,
184      __amd_cmpsd,
185      __amd_comisd,
186      __amd_ucomisd,
187      __amd_cvtpd2pi,   /* 66 2D */
188      __amd_cvtsd2si,   /* F2 */
189      __amd_cvttpd2pi,  /* 66 2C */
190      __amd_cvttsd2si,  /* F2 */
191      __amd_cvtps2pd,   /* 0F 5A */
192      __amd_cvtss2sd,   /* F3 */
193      __amd_cvtpd2ps,   /* 66 */
194      __amd_cvtsd2ss,   /* F2 */
195      __amd_cvtdq2ps,   /* 0F 5B */
196      __amd_cvttps2dq,  /* F3 */
197      __amd_cvtps2dq,   /* 66 */
198      __amd_cvttpd2dq,  /* 66 0F E6 */
199      __amd_cvtpd2dq,   /* F2 */
200      __amd_addsubpd,   /* 66 0F D0 */
201      __amd_haddpd,     /* 66 0F 7C */
202      __amd_hsubpd,     /* 66 0F 7D */
203      __amd_roundpd,    /* 66 0F 3A 09 */
204      __amd_roundsd,    /* 66 0F 3A 0B */
205      __amd_dppd,       /* 66 0F 3A 41 */
206      __amd_fmaSingle,
207      __amd_fmaDouble,
208      __amd_fms,
209      __amd_fmsSingle,
210      __amd_fmsDouble,
211      __amd_fnma,
212      __amd_fnmaSingle,
213      __amd_fnmaDouble,
214      __amd_famin,
215      __amd_famax,
216  } _AMDLIBM_CODE;
217  
218  #define _DOMAIN     1   /* argument domain error */
219  #define _SING       2   /* argument singularity */
220  #define _OVERFLOW   3   /* overflow range error */
221  #define _UNDERFLOW  4   /* underflow range error */
222  #define _TLOSS      5   /* total loss of precision */
223  #define _PLOSS      6   /* partial loss of precision */
224  #endif
225  
226  typedef enum 
227  {
228      __amd_asinh = (__amd_dppd + 20),
229      __amd_acosh,
230      __amd_atanh,
231      __amd_cbrt,
232      __amd_exp10,
233      __amd_exp2,
234      __amd_expm1,
235      __amd_lrint,
236      __amd_rint,
237      __amd_nexttoward,
238      __amd_nearbyint,
239      __amd_fdim,
240      __amd_finite,
241      __amd_scalbn,
242      __amd_scalbln,
243      __amd_log1p,
244      __amd_log2,
245      __amd_llrint,
246      __amd_llround,
247      __amd_lround,
248      __amd_remquo,
249          __amd_fma
250  }_AMDLIBM_EXTERNAL;
251  
252  
253  extern  double _cbrt_special            (double x);
254  extern  double _cos_special             (double x);
255  extern  double _exp10_special           (double x, double y, uint32_t code);
256  extern  double _exp2_special            (double x, double y, uint32_t code);
257  extern  double _expm1_special           (double x, double y, uint32_t code);
258  extern  double _exp_special             (double x, double y, uint32_t code);
259  extern  double _fabs_special            (double x);
260  extern  double _fdim_special            (double x, double y, double r);
261  extern  double _fmax_special            (double x, double y);
262  extern  double _fmin_special            (double x, double y);
263  extern  double _fmod_special            (double x, double y, uint32_t errorCode);
264  extern  double _log10_special           (double x, double y, uint32_t code);
265  extern  double _log1p_special           (double x, double y, uint32_t code);
266  extern  double _log2_special            (double x, double y, uint32_t code);
267  extern  double _log_special             (double x, double y, uint32_t code);
268  extern  double _nearbyint_special       (double x);
269  extern  double _pow_special             (double x, double y, double z, uint32_t code);
270  extern  double _remainder_special       (double x, double y, uint32_t errorCode);
271  extern  double _round_special           (double x, double r);
272  extern  double _sin_cos_special         (double x, char *name, _AMDLIBM_CODE code);
273  extern  double _sincos_special_underflow (double x, char *name, _AMDLIBM_CODE code);
274  extern  double _sin_special             (double x);
275  extern  double _sin_special_underflow   (double x);
276  extern  double _tan_special             (double x);
277  extern  double _trunc_special           (double x, double r);
278  extern  void _sincos_special            (double x, double *sy, double *cy);
279  
280  extern  float _cbrtf_special            (float x);
281  extern  float _cosf_special             (float x);
282  extern  float _exp10f_special           (float x, float y, uint32_t code);
283  extern  float _exp2f_special            (float x, float y, uint32_t code);
284  extern  float _expf_special             (float x, float y, uint32_t code);
285  extern  float _expm1f_special           (float x, float y, uint32_t code);
286  extern  float _fabsf_special            (float x);
287  extern  float _fdimf_special            (float x, float y, float r);
288  extern  float _fmaxf_special            (float x, float y);
289  extern  float _fminf_special            (float x, float y);
290  extern  float _fmodf_special            (float x, float y, uint32_t errorCode);
291  extern  float _log10f_special           (float x, float y, uint32_t code);
292  extern  float _log1pf_special           (float x, float y, uint32_t code);
293  extern  float _log2f_special            (float x, float y, uint32_t code);
294  extern  float _logf_special             (float x, float y, uint32_t code);
295  extern  float _powf_special             (float x, float y, float z, uint32_t code);
296  extern  float _remainderf_special       (float x, float y, uint32_t errorCode);
297  extern  float _sinf_cosf_special        (float x, char *name, _AMDLIBM_CODE code);
298  extern  float _sinf_special             (float x);
299  extern  float _tanf_special             (float x);
300  extern  float _truncf_special           (float x, float r);
301  extern  void _sincosf_special           (float x, float *sy, float *cy);
302  extern  float _sinf_cosf_special_underflow(float x, char *name, _AMDLIBM_CODE code);
303  
304  #endif // __LIBM_SPECIAL_H__;