source: trunk/libs/newlib/src/newlib/libm/common/math_config.h @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.4 KB
Line 
1/* Configuration for math routines.
2   Copyright (c) 2017 ARM Ltd.  All rights reserved.
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions
6   are met:
7   1. Redistributions of source code must retain the above copyright
8      notice, this list of conditions and the following disclaimer.
9   2. Redistributions in binary form must reproduce the above copyright
10      notice, this list of conditions and the following disclaimer in the
11      documentation and/or other materials provided with the distribution.
12   3. The name of the company may not be used to endorse or promote
13      products derived from this software without specific prior written
14      permission.
15
16   THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS AND ANY EXPRESS OR IMPLIED
17   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19   IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26
27#ifndef _MATH_CONFIG_H
28#define _MATH_CONFIG_H
29
30#include <math.h>
31#include <stdint.h>
32
33#ifndef WANT_ROUNDING
34/* Correct special case results in non-nearest rounding modes.  */
35# define WANT_ROUNDING 1
36#endif
37#ifndef WANT_ERRNO
38/* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0.  */
39# define WANT_ERRNO 1
40#endif
41#ifndef WANT_ERRNO_UFLOW
42/* Set errno to ERANGE if result underflows to 0 (in all rounding modes).  */
43# define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
44#endif
45
46#ifndef TOINT_INTRINSICS
47# define TOINT_INTRINSICS 0
48#endif
49#ifndef TOINT_RINT
50# define TOINT_RINT 0
51#endif
52#ifndef TOINT_SHIFT
53# define TOINT_SHIFT 1
54#endif
55
56static inline uint32_t
57asuint (float f)
58{
59  union
60  {
61    float f;
62    uint32_t i;
63  } u = {f};
64  return u.i;
65}
66
67static inline float
68asfloat (uint32_t i)
69{
70  union
71  {
72    uint32_t i;
73    float f;
74  } u = {i};
75  return u.f;
76}
77
78static inline uint64_t
79asuint64 (double f)
80{
81  union
82  {
83    double f;
84    uint64_t i;
85  } u = {f};
86  return u.i;
87}
88
89static inline double
90asdouble (uint64_t i)
91{
92  union
93  {
94    uint64_t i;
95    double f;
96  } u = {i};
97  return u.f;
98}
99
100#ifndef IEEE_754_2008_SNAN
101# define IEEE_754_2008_SNAN 1
102#endif
103static inline int
104issignalingf_inline (float x)
105{
106  uint32_t ix = asuint (x);
107  if (!IEEE_754_2008_SNAN)
108    return (ix & 0x7fc00000) == 0x7fc00000;
109  return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000;
110}
111
112#ifdef __GNUC__
113# define HIDDEN __attribute__ ((__visibility__ ("hidden")))
114# define NOINLINE __attribute__ ((noinline))
115#else
116# define HIDDEN
117# define NOINLINE
118#endif
119
120HIDDEN float __math_oflowf (unsigned long);
121HIDDEN float __math_uflowf (unsigned long);
122HIDDEN float __math_may_uflowf (unsigned long);
123HIDDEN float __math_divzerof (unsigned long);
124HIDDEN float __math_invalidf (float);
125
126/* Shared between expf, exp2f and powf.  */
127#define EXP2F_TABLE_BITS 5
128#define EXP2F_POLY_ORDER 3
129extern const struct exp2f_data
130{
131  uint64_t tab[1 << EXP2F_TABLE_BITS];
132  double shift_scaled;
133  double poly[EXP2F_POLY_ORDER];
134  double shift;
135  double invln2_scaled;
136  double poly_scaled[EXP2F_POLY_ORDER];
137} __exp2f_data HIDDEN;
138
139#define LOGF_TABLE_BITS 4
140#define LOGF_POLY_ORDER 4
141extern const struct logf_data
142{
143  struct
144  {
145    double invc, logc;
146  } tab[1 << LOGF_TABLE_BITS];
147  double ln2;
148  double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1.  */
149} __logf_data HIDDEN;
150
151#define LOG2F_TABLE_BITS 4
152#define LOG2F_POLY_ORDER 4
153extern const struct log2f_data
154{
155  struct
156  {
157    double invc, logc;
158  } tab[1 << LOG2F_TABLE_BITS];
159  double poly[LOG2F_POLY_ORDER];
160} __log2f_data HIDDEN;
161
162#define POWF_LOG2_TABLE_BITS 4
163#define POWF_LOG2_POLY_ORDER 5
164#if TOINT_INTRINSICS
165# define POWF_SCALE_BITS EXP2F_TABLE_BITS
166#else
167# define POWF_SCALE_BITS 0
168#endif
169#define POWF_SCALE ((double) (1 << POWF_SCALE_BITS))
170extern const struct powf_log2_data
171{
172  struct
173  {
174    double invc, logc;
175  } tab[1 << POWF_LOG2_TABLE_BITS];
176  double poly[POWF_LOG2_POLY_ORDER];
177} __powf_log2_data HIDDEN;
178
179#endif
Note: See TracBrowser for help on using the repository browser.