1 /* Test compilation of tgmath macros.
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2007.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
21 #undef __NO_MATH_INLINES
22 #define __NO_MATH_INLINES 1
31 typedef complex float cfloat
;
32 typedef complex double cdouble
;
33 #ifndef NO_LONG_DOUBLE
34 typedef long double ldouble
;
35 typedef complex long double cldouble
;
37 typedef double ldouble
;
38 typedef complex double cldouble
;
41 float vfloat1
, vfloat2
, vfloat3
;
42 double vdouble1
, vdouble2
, vdouble3
;
43 ldouble vldouble1
, vldouble2
, vldouble3
;
44 cfloat vcfloat1
, vcfloat2
, vcfloat3
;
45 cdouble vcdouble1
, vcdouble2
, vcdouble3
;
46 cldouble vcldouble1
, vcldouble2
, vcldouble4
;
47 int vint1
, vint2
, vint3
;
48 long int vlong1
, vlong2
, vlong3
;
49 long long int vllong1
, vllong2
, vllong3
;
50 const float Vfloat1
= 1, Vfloat2
= 2, Vfloat3
= 3;
51 const double Vdouble1
= 1, Vdouble2
= 2, Vdouble3
= 3;
52 const ldouble Vldouble1
= 1, Vldouble2
= 2, Vldouble3
= 3;
53 const cfloat Vcfloat1
= 1, Vcfloat2
= 2, Vcfloat3
= 3;
54 const cdouble Vcdouble1
= 1, Vcdouble2
= 2, Vcdouble3
= 3;
55 const cldouble Vcldouble1
= 1, Vcldouble2
= 2, Vcldouble4
= 3;
56 const int Vint1
= 1, Vint2
= 2, Vint3
= 3;
57 const long int Vlong1
= 1, Vlong2
= 2, Vlong3
= 3;
58 const long long int Vllong1
= 1, Vllong2
= 2, Vllong3
= 3;
65 #ifndef NO_LONG_DOUBLE
90 int counts
[Tlast
][C_last
];
93 test (const int Vint4
, const long long int Vllong4
)
101 printf ("%s failure on line %d\n", (str), __LINE__); \
105 #define TEST_TYPE_ONLY(expr, rettype) \
108 __typeof__ (expr) texpr = 0; \
109 __typeof__ (rettype) ttype = 0, *ptype; \
110 if (sizeof (expr) != sizeof (rettype)) \
112 if (__alignof__ (expr) != __alignof__ (rettype)) \
114 __asm ("" : "=r" (ptype) : "0" (&ttype), "r" (&texpr)); \
115 if (&texpr == ptype) \
119 #define TEST2(expr, type, rettype, fn) \
122 __typeof__ (expr) texpr = 0; \
123 TEST_TYPE_ONLY (expr, rettype); \
125 FAIL ("internal error"); \
126 if (counts[T##type][C_##fn] != 0) \
127 FAIL ("internal error"); \
129 __asm __volatile ("" : : "r" (&texpr)); \
130 if (count != 1 || counts[T##type][C_##fn] != 1) \
132 FAIL ("wrong function called"); \
133 memset (counts, 0, sizeof (counts)); \
136 counts[T##type][C_##fn] = 0; \
139 #define TEST(expr, type, fn) TEST2(expr, type, type, fn)
141 TEST (cos (vfloat1
), float, cos
);
142 TEST (cos (vdouble1
), double, cos
);
143 TEST (cos (vldouble1
), ldouble
, cos
);
144 TEST (cos (vint1
), double, cos
);
145 TEST (cos (vllong1
), double, cos
);
146 TEST (cos (vcfloat1
), cfloat
, cos
);
147 TEST (cos (vcdouble1
), cdouble
, cos
);
148 TEST (cos (vcldouble1
), cldouble
, cos
);
149 TEST (cos (Vfloat1
), float, cos
);
150 TEST (cos (Vdouble1
), double, cos
);
151 TEST (cos (Vldouble1
), ldouble
, cos
);
152 TEST (cos (Vint1
), double, cos
);
153 TEST (cos (Vllong1
), double, cos
);
154 TEST (cos (Vcfloat1
), cfloat
, cos
);
155 TEST (cos (Vcdouble1
), cdouble
, cos
);
156 TEST (cos (Vcldouble1
), cldouble
, cos
);
158 TEST (fabs (vfloat1
), float, fabs
);
159 TEST (fabs (vdouble1
), double, fabs
);
160 TEST (fabs (vldouble1
), ldouble
, fabs
);
161 TEST (fabs (vint1
), double, fabs
);
162 TEST (fabs (vllong1
), double, fabs
);
163 TEST (fabs (vcfloat1
), float, cabs
);
164 TEST (fabs (vcdouble1
), double, cabs
);
165 TEST (fabs (vcldouble1
), ldouble
, cabs
);
166 TEST (fabs (Vfloat1
), float, fabs
);
167 TEST (fabs (Vdouble1
), double, fabs
);
168 TEST (fabs (Vldouble1
), ldouble
, fabs
);
170 /* GCC is too smart to optimize these out. */
171 TEST (fabs (Vint1
), double, fabs
);
172 TEST (fabs (Vllong1
), double, fabs
);
174 TEST_TYPE_ONLY (fabs (vllong1
), double);
175 TEST_TYPE_ONLY (fabs (vllong1
), double);
177 TEST (fabs (Vint4
), double, fabs
);
178 TEST (fabs (Vllong4
), double, fabs
);
179 TEST (fabs (Vcfloat1
), float, cabs
);
180 TEST (fabs (Vcdouble1
), double, cabs
);
181 TEST (fabs (Vcldouble1
), ldouble
, cabs
);
183 TEST (conj (vfloat1
), cfloat
, conj
);
184 TEST (conj (vdouble1
), cdouble
, conj
);
185 TEST (conj (vldouble1
), cldouble
, conj
);
186 TEST (conj (vint1
), cdouble
, conj
);
187 TEST (conj (vllong1
), cdouble
, conj
);
188 TEST (conj (vcfloat1
), cfloat
, conj
);
189 TEST (conj (vcdouble1
), cdouble
, conj
);
190 TEST (conj (vcldouble1
), cldouble
, conj
);
191 TEST (conj (Vfloat1
), cfloat
, conj
);
192 TEST (conj (Vdouble1
), cdouble
, conj
);
193 TEST (conj (Vldouble1
), cldouble
, conj
);
194 TEST (conj (Vint1
), cdouble
, conj
);
195 TEST (conj (Vllong1
), cdouble
, conj
);
196 TEST (conj (Vcfloat1
), cfloat
, conj
);
197 TEST (conj (Vcdouble1
), cdouble
, conj
);
198 TEST (conj (Vcldouble1
), cldouble
, conj
);
200 TEST (expm1 (vfloat1
), float, expm1
);
201 TEST (expm1 (vdouble1
), double, expm1
);
202 TEST (expm1 (vldouble1
), ldouble
, expm1
);
203 TEST (expm1 (vint1
), double, expm1
);
204 TEST (expm1 (vllong1
), double, expm1
);
205 TEST (expm1 (Vfloat1
), float, expm1
);
206 TEST (expm1 (Vdouble1
), double, expm1
);
207 TEST (expm1 (Vldouble1
), ldouble
, expm1
);
208 TEST (expm1 (Vint1
), double, expm1
);
209 TEST (expm1 (Vllong1
), double, expm1
);
211 TEST2 (lrint (vfloat1
), float, long int, lrint
);
212 TEST2 (lrint (vdouble1
), double, long int, lrint
);
213 TEST2 (lrint (vldouble1
), ldouble
, long int, lrint
);
214 TEST2 (lrint (vint1
), double, long int, lrint
);
215 TEST2 (lrint (vllong1
), double, long int, lrint
);
216 TEST2 (lrint (Vfloat1
), float, long int, lrint
);
217 TEST2 (lrint (Vdouble1
), double, long int, lrint
);
218 TEST2 (lrint (Vldouble1
), ldouble
, long int, lrint
);
219 TEST2 (lrint (Vint1
), double, long int, lrint
);
220 TEST2 (lrint (Vllong1
), double, long int, lrint
);
222 TEST (ldexp (vfloat1
, 6), float, ldexp
);
223 TEST (ldexp (vdouble1
, 6), double, ldexp
);
224 TEST (ldexp (vldouble1
, 6), ldouble
, ldexp
);
225 TEST (ldexp (vint1
, 6), double, ldexp
);
226 TEST (ldexp (vllong1
, 6), double, ldexp
);
227 TEST (ldexp (Vfloat1
, 6), float, ldexp
);
228 TEST (ldexp (Vdouble1
, 6), double, ldexp
);
229 TEST (ldexp (Vldouble1
, 6), ldouble
, ldexp
);
230 TEST (ldexp (Vint1
, 6), double, ldexp
);
231 TEST (ldexp (Vllong1
, 6), double, ldexp
);
233 #define FIRST(x, y) (y, x)
234 #define SECOND(x, y) (x, y)
235 #define NON_LDBL_TEST(fn, argm, arg, type, fnt) \
236 TEST (fn argm (arg, vfloat1), type, fnt); \
237 TEST (fn argm (arg, vdouble1), type, fnt); \
238 TEST (fn argm (arg, vint1), type, fnt); \
239 TEST (fn argm (arg, vllong1), type, fnt); \
240 TEST (fn argm (arg, Vfloat1), type, fnt); \
241 TEST (fn argm (arg, Vdouble1), type, fnt); \
242 TEST (fn argm (arg, Vint1), type, fnt); \
243 TEST (fn argm (arg, Vllong1), type, fnt);
244 #define NON_LDBL_CTEST(fn, argm, arg, type, fnt) \
245 NON_LDBL_TEST(fn, argm, arg, type, fnt); \
246 TEST (fn argm (arg, vcfloat1), type, fnt); \
247 TEST (fn argm (arg, vcdouble1), type, fnt); \
248 TEST (fn argm (arg, Vcfloat1), type, fnt); \
249 TEST (fn argm (arg, Vcdouble1), type, fnt);
250 #define BINARY_TEST(fn, fnt) \
251 TEST (fn (vfloat1, vfloat2), float, fnt); \
252 TEST (fn (Vfloat1, vfloat2), float, fnt); \
253 TEST (fn (vfloat1, Vfloat2), float, fnt); \
254 TEST (fn (Vfloat1, Vfloat2), float, fnt); \
255 TEST (fn (vldouble1, vldouble2), ldouble, fnt); \
256 TEST (fn (Vldouble1, vldouble2), ldouble, fnt); \
257 TEST (fn (vldouble1, Vldouble2), ldouble, fnt); \
258 TEST (fn (Vldouble1, Vldouble2), ldouble, fnt); \
259 NON_LDBL_TEST (fn, FIRST, vldouble2, ldouble, fnt); \
260 NON_LDBL_TEST (fn, SECOND, vldouble2, ldouble, fnt); \
261 NON_LDBL_TEST (fn, FIRST, Vldouble2, ldouble, fnt); \
262 NON_LDBL_TEST (fn, SECOND, Vldouble2, ldouble, fnt); \
263 NON_LDBL_TEST (fn, FIRST, vdouble2, double, fnt); \
264 NON_LDBL_TEST (fn, SECOND, vdouble2, double, fnt); \
265 NON_LDBL_TEST (fn, FIRST, Vdouble2, double, fnt); \
266 NON_LDBL_TEST (fn, SECOND, Vdouble2, double, fnt); \
267 NON_LDBL_TEST (fn, FIRST, vint2, double, fnt); \
268 NON_LDBL_TEST (fn, SECOND, vint2, double, fnt); \
269 NON_LDBL_TEST (fn, FIRST, Vint2, double, fnt); \
270 NON_LDBL_TEST (fn, SECOND, Vint2, double, fnt); \
271 NON_LDBL_TEST (fn, FIRST, vllong2, double, fnt); \
272 NON_LDBL_TEST (fn, SECOND, vllong2, double, fnt); \
273 NON_LDBL_TEST (fn, FIRST, Vllong2, double, fnt); \
274 NON_LDBL_TEST (fn, SECOND, Vllong2, double, fnt);
275 #define BINARY_CTEST(fn, fnt) \
276 BINARY_TEST (fn, fnt); \
277 TEST (fn (vcfloat1, vfloat2), cfloat, fnt); \
278 TEST (fn (Vcfloat1, vfloat2), cfloat, fnt); \
279 TEST (fn (vcfloat1, Vfloat2), cfloat, fnt); \
280 TEST (fn (Vcfloat1, Vfloat2), cfloat, fnt); \
281 TEST (fn (vcldouble1, vldouble2), cldouble, fnt); \
282 TEST (fn (Vcldouble1, vldouble2), cldouble, fnt); \
283 TEST (fn (vcldouble1, Vldouble2), cldouble, fnt); \
284 TEST (fn (Vcldouble1, Vldouble2), cldouble, fnt); \
285 TEST (fn (vcfloat1, vfloat2), cfloat, fnt); \
286 TEST (fn (Vcfloat1, vfloat2), cfloat, fnt); \
287 TEST (fn (vcfloat1, Vfloat2), cfloat, fnt); \
288 TEST (fn (Vcfloat1, Vfloat2), cfloat, fnt); \
289 TEST (fn (vcldouble1, vldouble2), cldouble, fnt); \
290 TEST (fn (Vcldouble1, vldouble2), cldouble, fnt); \
291 TEST (fn (vcldouble1, Vldouble2), cldouble, fnt); \
292 TEST (fn (Vcldouble1, Vldouble2), cldouble, fnt); \
293 TEST (fn (vcfloat1, vcfloat2), cfloat, fnt); \
294 TEST (fn (Vcfloat1, vcfloat2), cfloat, fnt); \
295 TEST (fn (vcfloat1, Vcfloat2), cfloat, fnt); \
296 TEST (fn (Vcfloat1, Vcfloat2), cfloat, fnt); \
297 TEST (fn (vcldouble1, vcldouble2), cldouble, fnt); \
298 TEST (fn (Vcldouble1, vcldouble2), cldouble, fnt); \
299 TEST (fn (vcldouble1, Vcldouble2), cldouble, fnt); \
300 TEST (fn (Vcldouble1, Vcldouble2), cldouble, fnt); \
301 NON_LDBL_CTEST (fn, FIRST, vcldouble2, cldouble, fnt); \
302 NON_LDBL_CTEST (fn, SECOND, vcldouble2, cldouble, fnt); \
303 NON_LDBL_CTEST (fn, FIRST, Vcldouble2, cldouble, fnt); \
304 NON_LDBL_CTEST (fn, SECOND, Vcldouble2, cldouble, fnt); \
305 NON_LDBL_CTEST (fn, FIRST, vcdouble2, cdouble, fnt); \
306 NON_LDBL_CTEST (fn, SECOND, vcdouble2, cdouble, fnt); \
307 NON_LDBL_CTEST (fn, FIRST, Vcdouble2, cdouble, fnt); \
308 NON_LDBL_CTEST (fn, SECOND, Vcdouble2, cdouble, fnt);
310 BINARY_TEST (atan2
, atan2
);
312 #define my_remquo(x, y) remquo (x, y, &quo)
313 BINARY_TEST (my_remquo
, remquo
);
316 BINARY_CTEST (pow
, pow
);
318 /* Testing all arguments of fma would be just too expensive,
319 so test just some. */
320 #define my_fma(x, y) fma (x, y, vfloat3)
321 BINARY_TEST (my_fma
, fma
);
323 #define my_fma(x, y) fma (x, vfloat3, y)
324 BINARY_TEST (my_fma
, fma
);
326 #define my_fma(x, y) fma (Vfloat3, x, y)
327 BINARY_TEST (my_fma
, fma
);
329 TEST (fma (vdouble1
, Vdouble2
, vllong3
), double, fma
);
330 TEST (fma (vint1
, Vint2
, vint3
), double, fma
);
331 TEST (fma (Vldouble1
, vldouble2
, Vldouble3
), ldouble
, fma
);
332 TEST (fma (vldouble1
, vint2
, Vdouble3
), ldouble
, fma
);
340 return test (vint1
, vllong1
);
343 /* Now generate the three functions. */
348 #define CTYPE cdouble
351 #include "test-tgmath2.c"
353 #define F(name) name##f
358 #include "test-tgmath2.c"
360 #ifndef NO_LONG_DOUBLE
361 #define F(name) name##l
363 #define CTYPE cldouble
366 #include "test-tgmath2.c"
369 #define TEST_FUNCTION do_test ()
370 #include "../test-skeleton.c"
375 #define P() puts (__FUNCTION__); count++
423 counts
[T
][C_expm1
]++;
431 counts
[T
][C_lrint
]++;
437 (F(ldexp
)) (TYPE x
, int y
)
439 counts
[T
][C_ldexp
]++;
445 (F(atan2
)) (TYPE x
, TYPE y
)
447 counts
[T
][C_atan2
]++;
453 (F(remquo
)) (TYPE x
, TYPE y
, int *z
)
455 counts
[T
][C_remquo
]++;
461 (F(pow
)) (TYPE x
, TYPE y
)
469 (F(cpow
)) (CTYPE x
, CTYPE y
)
477 (F(fma
)) (TYPE x
, TYPE y
, TYPE z
)