OSDN Git Service

* gcc.dg/torture/builtin-modf-1.c: Remove -funsafe-math-optimizations.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / torture / builtin-symmetric-1.c
1 /* Copyright (C) 2006  Free Software Foundation.
2
3    Verify that built-in math function folding of symmetric even and
4    odd functions is correctly performed by the compiler.
5
6    Origin: Kaveh R. Ghazi,  November 09, 2006.  */
7
8 /* { dg-do link } */
9 /* { dg-options "-ffast-math" } */
10
11 /* All references to link_error should go away at compile-time.  */
12 extern void link_error(int);
13
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)
23
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)
33
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)
39
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)
49
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)
59
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)
63 {
64   TESTIT_EVEN(cos);
65   TESTIT_EVEN(cosh);
66   TESTIT_EVEN(fabs);
67
68   TESTIT_EVEN_C(ccos);
69   TESTIT_EVEN_C(ccosh);
70   TESTIT_EVEN_C(cabs);
71
72   TESTIT_EVEN_I(abs, i);
73   TESTIT_EVEN_I(imaxabs, im);
74   TESTIT_EVEN_I(labs, l);
75   TESTIT_EVEN_I(llabs, ll);
76
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);
95
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);
105 }
106
107 int main()
108 {
109   foo (1,1,1,1,1,1,1,1,1,1);
110   return 0;
111 }