* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Type>: Don't
[official-gcc.git] / gcc / testsuite / gcc.target / tic6x / builtin-math-7.c
bloba7deea3e22b76d762198f878838737a2f278d35a
1 /* Copyright (C) 2009 Free Software Foundation.
3 Verify that folding of complex mul and div work correctly.
4 TI C6X specific version, reduced by two tests that fails due to the
5 use of implicit -freciprocal-math.
7 Origin: Kaveh R. Ghazi, August 13, 2009. */
9 /* { dg-do run } */
10 /* { dg-options "-O2" } */
11 /* { dg-add-options ieee } */
13 extern void link_error(int);
15 /* Evaluate this expression at compile-time. */
16 #define COMPILETIME_TESTIT(TYPE,X,OP,Y,RES) do { \
17 if ((_Complex TYPE)(X) OP (_Complex TYPE)(Y) != (_Complex TYPE)(RES)) \
18 link_error(__LINE__); \
19 } while (0)
21 /* Use this error function for cases which only evaluate at
22 compile-time when optimizing. */
23 #ifdef __OPTIMIZE__
24 # define ERROR_FUNC(X) link_error(X)
25 #else
26 # define ERROR_FUNC(X) __builtin_abort()
27 #endif
29 /* Evaluate this expression at compile-time using static initializers. */
30 #define STATICINIT_TESTIT(TYPE,X,OP,Y,RES) do { \
31 static const _Complex TYPE foo = (_Complex TYPE)(X) OP (_Complex TYPE)(Y); \
32 if (foo != (_Complex TYPE)(RES)) \
33 ERROR_FUNC (__LINE__); \
34 } while (0)
36 /* Evaluate this expression at runtime. */
37 #define RUNTIME_TESTIT(TYPE,X,OP,Y,RES) do { \
38 volatile _Complex TYPE foo; \
39 foo = (_Complex TYPE)(X); \
40 foo OP##= (_Complex TYPE)(Y); \
41 if (foo != (_Complex TYPE)(RES)) \
42 __builtin_abort(); \
43 } while (0)
45 /* Evaluate this expression at compile-time and runtime. */
46 #define TESTIT(TYPE,X,OP,Y,RES) do { \
47 STATICINIT_TESTIT(TYPE,X,OP,Y,RES); \
48 COMPILETIME_TESTIT(TYPE,X,OP,Y,RES); \
49 RUNTIME_TESTIT(TYPE,X,OP,Y,RES); \
50 } while (0)
52 /* Either the real or imaginary parts should be infinity. */
53 #define TEST_ONE_PART_INF(VAL) do { \
54 static const _Complex double foo = (VAL); \
55 if (! __builtin_isinf(__real foo) && ! __builtin_isinf(__imag foo)) \
56 ERROR_FUNC (__LINE__); \
57 if (! __builtin_isinf(__real (VAL)) && ! __builtin_isinf(__imag (VAL))) \
58 __builtin_abort(); \
59 } while (0)
61 int main()
63 /* Test some regular finite values. */
64 TESTIT (double, 3.+4.i, *, 2, 6+8i);
65 TESTIT (double, 3.+4.i, /, 2, 1.5+2i);
66 TESTIT (int, 3+4i, *, 2, 6+8i);
67 TESTIT (int, 3+4i, /, 2, 1+2i);
69 TESTIT (double, 3.+4.i, *, 2+5i, -14+23i);
70 TESTIT (int, 3+4i, *, 2+5i, -14+23i);
71 TESTIT (int, 30+40i, /, 5i, 8-6i);
72 TESTIT (int, 14+6i, /, 7+3i, 2);
73 TESTIT (int, 8+24i, /, 4+12i, 2);
75 /* Test for accuracy. */
76 COMPILETIME_TESTIT (double,
77 (1 + __DBL_EPSILON__ + 1i),
79 (1 - __DBL_EPSILON__ + 1i),
80 -4.93038065763132378382330353301741393545754021943139377981e-32+2i);
82 /* This becomes (NaN + iInf). */
83 #define VAL1 ((_Complex double)__builtin_inf() * 1i)
85 /* Test some C99 Annex G special cases. */
86 TEST_ONE_PART_INF ((VAL1) * (VAL1));
87 TEST_ONE_PART_INF ((_Complex double)1 / (_Complex double)0);
88 TEST_ONE_PART_INF ((VAL1) / (_Complex double)1);
90 RUNTIME_TESTIT (double, 1, /, VAL1, 0);
91 STATICINIT_TESTIT (double, 1, /, VAL1, 0);
93 return 0;