2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-symmetric-1.c
blob4834d8e2b3266b56424b485251d24f41e5a74b04
1 /* Copyright (C) 2006 Free Software Foundation.
3 Verify that built-in math function folding of symmetric even and
4 odd functions is correctly performed by the compiler.
6 Origin: Kaveh R. Ghazi, November 09, 2006. */
8 /* { dg-do link } */
9 /* { dg-options "-ffast-math" } */
11 /* All references to link_error should go away at compile-time. */
12 extern void link_error(int);
14 /* Test that FUNC(-ARG) == FUNC(ARG). */
15 #define TESTIT_EVEN(FUNC) do { \
16 if (__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
17 link_error(__LINE__); \
18 if (__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
19 link_error(__LINE__); \
20 if (__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
21 link_error(__LINE__); \
22 } while (0)
24 /* Test that FUNC(-ARG) == FUNC(ARG), where ARG has a complex type. */
25 #define TESTIT_EVEN_C(FUNC) do { \
26 if (__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
27 link_error(__LINE__); \
28 if (__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
29 link_error(__LINE__); \
30 if (__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
31 link_error(__LINE__); \
32 } while (0)
34 /* Test that FUNC(-VAR) == FUNC(VAR), where VAR has an int type. */
35 #define TESTIT_EVEN_I(FUNC,VAR) do { \
36 if (__builtin_##FUNC(-VAR) != __builtin_##FUNC(VAR)) \
37 link_error(__LINE__); \
38 } while (0)
40 /* Test that -FUNC(ARG) == FUNC(-ARG). */
41 #define TESTIT_ODD(FUNC) do { \
42 if (-__builtin_##FUNC##f(-xf) != __builtin_##FUNC##f(xf)) \
43 link_error(__LINE__); \
44 if (-__builtin_##FUNC(-x) != __builtin_##FUNC(x)) \
45 link_error(__LINE__); \
46 if (-__builtin_##FUNC##l(-xl) != __builtin_##FUNC##l(xl)) \
47 link_error(__LINE__); \
48 } while (0)
50 /* Test that -FUNC(ARG) == FUNC(-ARG), where ARG has a complex type. */
51 #define TESTIT_ODD_C(FUNC) do { \
52 if (-__builtin_##FUNC##f(-cxf) != __builtin_##FUNC##f(cxf)) \
53 link_error(__LINE__); \
54 if (-__builtin_##FUNC(-cx) != __builtin_##FUNC(cx)) \
55 link_error(__LINE__); \
56 if (-__builtin_##FUNC##l(-cxl) != __builtin_##FUNC##l(cxl)) \
57 link_error(__LINE__); \
58 } while (0)
60 void foo (float xf, double x, long double xl,
61 __complex__ float cxf, __complex__ double cx, __complex__ long double cxl,
62 int i, long l, long long ll, __INTMAX_TYPE__ im)
64 TESTIT_EVEN(cos);
65 TESTIT_EVEN(cosh);
66 TESTIT_EVEN(fabs);
68 TESTIT_EVEN_C(ccos);
69 TESTIT_EVEN_C(ccosh);
70 TESTIT_EVEN_C(cabs);
72 TESTIT_EVEN_I(abs, i);
73 TESTIT_EVEN_I(imaxabs, im);
74 TESTIT_EVEN_I(labs, l);
75 TESTIT_EVEN_I(llabs, ll);
77 TESTIT_ODD(asin);
78 TESTIT_ODD(asinh);
79 TESTIT_ODD(atan);
80 TESTIT_ODD(atanh);
81 TESTIT_ODD(cbrt);
82 TESTIT_ODD(erf);
83 TESTIT_ODD(llrint);
84 TESTIT_ODD(llround);
85 TESTIT_ODD(lrint);
86 TESTIT_ODD(lround);
87 TESTIT_ODD(nearbyint);
88 TESTIT_ODD(rint);
89 TESTIT_ODD(round);
90 TESTIT_ODD(sin);
91 TESTIT_ODD(sinh);
92 TESTIT_ODD(tan);
93 TESTIT_ODD(tanh);
94 TESTIT_ODD(trunc);
96 TESTIT_ODD_C(casin);
97 TESTIT_ODD_C(casinh);
98 TESTIT_ODD_C(catan);
99 TESTIT_ODD_C(catanh);
100 TESTIT_ODD_C(cproj);
101 TESTIT_ODD_C(csin);
102 TESTIT_ODD_C(csinh);
103 TESTIT_ODD_C(ctan);
104 TESTIT_ODD_C(ctanh);
107 int main()
109 foo (1,1,1,1,1,1,1,1,1,1);
110 return 0;