1 /* Copyright (C) 2006 Free Software Foundation.
3 Verify that built-in math function folding of fmin/fmax is
4 correctly performed by the compiler.
6 Origin: Kaveh R. Ghazi, November 13, 2006. */
9 /* { dg-options "-fno-math-errno" } */
11 /* All references to link_error should go away at compile-time. */
12 extern void link_error(int);
14 #define DECLARE(FUNC) \
15 extern float FUNC##f (float); \
16 extern double FUNC (double); \
17 extern long double FUNC##l (long double)
18 #define DECLARE_L(FUNC) \
19 extern long FUNC##f (float); \
20 extern long FUNC (double); \
21 extern long FUNC##l (long double)
22 #define DECLARE2(FUNC) \
23 extern float FUNC##f (float, float); \
24 extern double FUNC (double, double); \
25 extern long double FUNC##l (long double, long double)
33 extern int pure(int) __attribute__ ((__pure__));
35 /* Test that FUNC(x,x) == x. We cast to (long) so "!=" folds. */
36 #define TEST_EQ(FUNC) do { \
37 if ((long)FUNC##f(xf,xf) != (long)xf) \
38 link_error(__LINE__); \
39 if ((long)FUNC(x,x) != (long)x) \
40 link_error(__LINE__); \
41 if ((long)FUNC##l(xl,xl) != (long)xl) \
42 link_error(__LINE__); \
45 /* Test that FUNC(purefn,purefn) == purefn. We cast to (long) so "!=" folds. */
46 #define TEST_EQ_PURE(FUNC) do { \
47 if ((long)FUNC##f(pure(i),pure(i)) != (long)FUNC##f(pure(i),pure(i))) \
48 link_error(__LINE__); \
49 if ((long)FUNC(pure(i),pure(i)) != (long)FUNC(pure(i),pure(i))) \
50 link_error(__LINE__); \
51 if ((long)FUNC##l(pure(i),pure(i)) != (long)FUNC##l(pure(i),pure(i))) \
52 link_error(__LINE__); \
55 /* Test that lround(FUNC(int,int)) == lrint(FUNC(int,int)), i.e. both
56 lround() and lrint() should be folded away. */
57 #define TEST_NONNEG(FUNC) do { \
58 if (lroundf(FUNC##f(i,j)) != lrintf(FUNC##f(i,j))) \
59 link_error(__LINE__); \
60 if (lround(FUNC(i,j)) != lrint(FUNC(i,j))) \
61 link_error(__LINE__); \
62 if (lroundl(FUNC##l(i,j)) != lrintl(FUNC##l(i,j))) \
63 link_error(__LINE__); \
66 /* Test that (long)fabs(FUNC(fabs(x),fabs(y))) ==
67 (long)FUNC(fabs(x),fabs(y)). We cast to (long) so "!=" folds. */
68 #define TEST_INT(FUNC) do { \
69 if ((long)fabsf(FUNC##f(fabsf(xf),fabsf(yf))) != (long)FUNC##f(fabsf(xf),fabsf(yf))) \
70 link_error(__LINE__); \
71 if ((long)fabs(FUNC(fabs(x),fabs(y))) != (long)FUNC(fabs(x),fabs(y))) \
72 link_error(__LINE__); \
73 if ((long)fabsl(FUNC##l(fabsl(xl),fabsl(yl))) != (long)FUNC##l(fabsl(xl),fabsl(yl))) \
74 link_error(__LINE__); \
77 /* Test that FUNC(NaN,x) == x. We cast to (long) so "!=" folds. Set
78 parameter SIGNAL to `s' for testing signaling NaN. */
79 #define TEST_NAN(FUNC,SIGNAL) do { \
80 if ((long)FUNC##f(__builtin_nan##SIGNAL##f(""),xf) != (long)xf) \
81 link_error(__LINE__); \
82 if ((long)FUNC##f(xf,__builtin_nan##SIGNAL##f("")) != (long)xf) \
83 link_error(__LINE__); \
84 if ((long)FUNC(__builtin_nan##SIGNAL(""),x) != (long)x) \
85 link_error(__LINE__); \
86 if ((long)FUNC(x,__builtin_nan##SIGNAL("")) != (long)x) \
87 link_error(__LINE__); \
88 if ((long)FUNC##l(__builtin_nan##SIGNAL##l(""),xl) != (long)xl) \
89 link_error(__LINE__); \
90 if ((long)FUNC##l(xl,__builtin_nan##SIGNAL##l("")) != (long)xl) \
91 link_error(__LINE__); \
94 void __attribute__ ((__noinline__))
95 foo (float xf, double x, long double xl,
96 float yf, double y, long double yl,
121 foo (1,1,1,1,1,1,1,1);