| 1 |
/* Copyright (C) 2009 Free Software Foundation. |
| 2 |
|
| 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. |
| 6 |
|
| 7 |
Origin: Kaveh R. Ghazi, August 13, 2009. */ |
| 8 |
|
| 9 |
/* { dg-do run } */ |
| 10 |
/* { dg-options "-O2" } */ |
| 11 |
/* { dg-add-options ieee } */ |
| 12 |
|
| 13 |
extern void link_error(int); |
| 14 |
|
| 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) |
| 20 |
|
| 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 |
| 28 |
|
| 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) |
| 35 |
|
| 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) |
| 44 |
|
| 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) |
| 51 |
|
| 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) |
| 60 |
|
| 61 |
int main() |
| 62 |
{ |
| 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); |
| 68 |
|
| 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); |
| 74 |
|
| 75 |
/* Test for accuracy. */ |
| 76 |
COMPILETIME_TESTIT (double, |
| 77 |
(1 + __DBL_EPSILON__ + 1i), |
| 78 |
*, |
| 79 |
(1 - __DBL_EPSILON__ + 1i), |
| 80 |
-4.93038065763132378382330353301741393545754021943139377981e-32+2i); |
| 81 |
|
| 82 |
/* This becomes (NaN + iInf). */ |
| 83 |
#define VAL1 ((_Complex double)__builtin_inf() * 1i) |
| 84 |
|
| 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); |
| 89 |
|
| 90 |
RUNTIME_TESTIT (double, 1, /, VAL1, 0); |
| 91 |
STATICINIT_TESTIT (double, 1, /, VAL1, 0); |
| 92 |
|
| 93 |
return 0; |
| 94 |
} |