OSDN Git Service

* config/i386/xmmintrin.h (_mm_prefetch): Added const to first arg.
[pf3gnuchains/gcc-fork.git] / gcc / ginclude / tgmath.h
1 /* Copyright (C) 2004, 2005 Free Software Foundation, Inc.
2    Contributed by Apple, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* As a special exception, if you include this header file into source
22    files compiled by GCC, this header file does not by itself cause
23    the resulting executable to be covered by the GNU General Public
24    License.  This exception does not however invalidate any other
25    reasons why the executable file might be covered by the GNU General
26    Public License.  */
27
28 /*
29  * ISO C Standard:  7.22  Type-generic math <tgmath.h>
30  */
31
32 #ifndef _TGMATH_H
33 #define _TGMATH_H
34
35 #include <math.h>
36
37 #ifndef __cplusplus
38 #include <complex.h>
39
40 /* Naming convention: generic macros are defining using
41    __TGMATH_CPLX*, __TGMATH_REAL*, and __TGMATH_CPLX_ONLY.  _CPLX
42    means the generic argument(s) may be real or complex, _REAL means
43    real only, _CPLX means complex only.  If there is no suffix, we are
44    defining a function of one generic argument.  If the suffix is _n
45    it is a function of n generic arguments.  If the suffix is _m_n it
46    is a function of n arguments, the first m of which are generic.  We
47    only define these macros for values of n and/or m that are needed. */
48
49 /* The general rules for generic macros are given in 7.22 paragraphs 1 and 2.
50    If any generic parameter is complex, we use a complex version.  Otherwise
51    we use a real version.  If the real part of any generic parameter is long
52    double, we use the long double version.  Otherwise if the real part of any
53    generic parameter is double or of integer type, we use the double version.
54    Otherwise we use the float version. */
55
56 #define __tg_cplx(expr) \
57   __builtin_classify_type(expr) == 9
58
59 #define __tg_ldbl(expr) \
60   __builtin_types_compatible_p(__typeof__(expr), long double)
61
62 #define __tg_dbl(expr)                                       \
63   (__builtin_types_compatible_p(__typeof__(expr), double)    \
64    || __builtin_classify_type(expr) == 1)
65
66 #define __tg_choose(x,f,d,l)                                  \
67   __builtin_choose_expr(__tg_ldbl(x), l,                      \
68                         __builtin_choose_expr(__tg_dbl(x), d, \
69                                               f))
70
71 #define __tg_choose_2(x,y,f,d,l)                                             \
72   __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y), l,                     \
73                         __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y), d, \
74                                               f))
75
76 #define __tg_choose_3(x,y,z,f,d,l)                                        \
77    __builtin_choose_expr(__tg_ldbl(x) || __tg_ldbl(y) || __tg_ldbl(z), l, \
78                         __builtin_choose_expr(__tg_dbl(x) || __tg_dbl(y)  \
79                                               || __tg_dbl(z), d,          \
80                                               f))
81
82 #define __TGMATH_CPLX(z,R,C)                                                  \
83   __builtin_choose_expr (__tg_cplx(z),                                        \
84                          __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z)), \
85                          __tg_choose (z, R##f(z), (R)(z), R##l(z)))
86
87 #define __TGMATH_CPLX_2(z1,z2,R,C)                                             \
88   __builtin_choose_expr (__tg_cplx(z1) || __tg_cplx(z2),                       \
89                          __tg_choose_2 (__real__(z1), __real__(z2),            \
90                                         C##f(z1,z2), (C)(z1,z2), C##l(z1,z2)), \
91                          __tg_choose_2 (z1, z2,                                \
92                                         R##f(z1,z2), (R)(z1,z2), R##l(z1,z2)))
93
94 #define __TGMATH_REAL(x,R) \
95   __tg_choose (x, R##f(x), (R)(x), R##l(x))
96 #define __TGMATH_REAL_2(x,y,R) \
97   __tg_choose_2 (x, y, R##f(x,y), (R)(x,y), R##l(x,y))
98 #define __TGMATH_REAL_3(x,y,z,R) \
99   __tg_choose_3 (x, y, z, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
100 #define __TGMATH_REAL_1_2(x,y,R) \
101   __tg_choose (x, R##f(x,y), (R)(x,y), R##l(x,y))
102 #define __TGMATH_REAL_2_3(x,y,z,R) \
103   __tg_choose_2 (x, y, R##f(x,y,z), (R)(x,y,z), R##l(x,y,z))
104 #define __TGMATH_CPLX_ONLY(z,C) \
105   __tg_choose (__real__(z), C##f(z), (C)(z), C##l(z))
106
107 /* Functions defined in both <math.h> and <complex.h> (7.22p4) */
108 #define acos(z)          __TGMATH_CPLX(z, acos, cacos)
109 #define asin(z)          __TGMATH_CPLX(z, asin, casin)
110 #define atan(z)          __TGMATH_CPLX(z, atan, catan)
111 #define acosh(z)         __TGMATH_CPLX(z, acosh, cacosh)
112 #define asinh(z)         __TGMATH_CPLX(z, asinh, casinh)
113 #define atanh(z)         __TGMATH_CPLX(z, atanh, catanh)
114 #define cos(z)           __TGMATH_CPLX(z, cos, ccos)
115 #define sin(z)           __TGMATH_CPLX(z, sin, csin)
116 #define tan(z)           __TGMATH_CPLX(z, tan, ctan)
117 #define cosh(z)          __TGMATH_CPLX(z, cosh, ccosh)
118 #define sinh(z)          __TGMATH_CPLX(z, sinh, csinh)
119 #define tanh(z)          __TGMATH_CPLX(z, tanh, ctanh)
120 #define exp(z)           __TGMATH_CPLX(z, exp, cexp)
121 #define log(z)           __TGMATH_CPLX(z, log, clog)
122 #define pow(z1,z2)       __TGMATH_CPLX_2(z1, z2, pow, cpow)
123 #define sqrt(z)          __TGMATH_CPLX(z, sqrt, csqrt)
124 #define fabs(z)          __TGMATH_CPLX(z, fabs, cabs)
125
126 /* Functions defined in <math.h> only (7.22p5) */
127 #define atan2(x,y)       __TGMATH_REAL_2(x, y, atan2)
128 #define cbrt(x)          __TGMATH_REAL(x, cbrt)
129 #define ceil(x)          __TGMATH_REAL(x, ceil)
130 #define copysign(x,y)    __TGMATH_REAL_2(x, y, copysign)
131 #define erf(x)           __TGMATH_REAL(x, erf)
132 #define erfc(x)          __TGMATH_REAL(x, erfc)
133 #define exp2(x)          __TGMATH_REAL(x, exp2)
134 #define expm1(x)         __TGMATH_REAL(x, expm1)
135 #define fdim(x,y)        __TGMATH_REAL_2(x, y, fdim)
136 #define floor(x)         __TGMATH_REAL(x, floor)
137 #define fma(x,y,z)       __TGMATH_REAL_3(x, y, z, fma)
138 #define fmax(x,y)        __TGMATH_REAL_2(x, y, fmax)
139 #define fmin(x,y)        __TGMATH_REAL_2(x, y, fmin)
140 #define fmod(x,y)        __TGMATH_REAL_2(x, y, fmod)
141 #define frexp(x,y)       __TGMATH_REAL_1_2(x, y, frexp)
142 #define hypot(x,y)       __TGMATH_REAL_2(x, y, hypot)
143 #define ilogb(x)         __TGMATH_REAL(x, ilogb)
144 #define ldexp(x,y)       __TGMATH_REAL_1_2(x, y, ldexp)
145 #define lgamma(x)        __TGMATH_REAL(x, lgamma)
146 #define llrint(x)        __TGMATH_REAL(x, llrint)
147 #define llround(x)       __TGMATH_REAL(x, llround)
148 #define log10(x)         __TGMATH_REAL(x, log10)
149 #define log1p(x)         __TGMATH_REAL(x, log1p)
150 #define log2(x)          __TGMATH_REAL(x, log2)
151 #define logb(x)          __TGMATH_REAL(x, logb)
152 #define lrint(x)         __TGMATH_REAL(x, lrint)
153 #define lround(x)        __TGMATH_REAL(x, lround)
154 #define nearbyint(x)     __TGMATH_REAL(x, nearbyint)
155 #define nextafter(x,y)   __TGMATH_REAL_2(x, y, nextafter)
156 #define nexttoward(x,y)  __TGMATH_REAL_1_2(x, y, nexttoward)
157 #define remainder(x,y)   __TGMATH_REAL_2(x, y, remainder)
158 #define remquo(x,y,z)    __TGMATH_REAL_2_3(x, y, z, remquo)
159 #define rint(x)          __TGMATH_REAL(x, rint)
160 #define round(x)         __TGMATH_REAL(x, round)
161 #define scalbn(x,y)      __TGMATH_REAL_1_2(x, y, scalbn)
162 #define scalbln(x,y)     __TGMATH_REAL_1_2(x, y, scalbln)
163 #define tgamma(x)        __TGMATH_REAL(x, tgamma)
164 #define trunc(x)         __TGMATH_REAL(x, trunc)
165
166 /* Functions defined in <complex.h> only (7.22p6) */
167 #define carg(z)          __TGMATH_CPLX_ONLY(z, carg)
168 #define cimag(z)         __TGMATH_CPLX_ONLY(z, cimag)
169 #define conj(z)          __TGMATH_CPLX_ONLY(z, conj)
170 #define cproj(z)         __TGMATH_CPLX_ONLY(z, cproj)
171 #define creal(z)         __TGMATH_CPLX_ONLY(z, creal)
172
173 #endif /* __cplusplus */
174 #endif /* _TGMATH_H */