1 |
149 |
jeremybenn |
/* Copyright (C) 2004 Free Software Foundation.
|
2 |
|
|
|
3 |
|
|
Verify that GCC can determine which built-in functions produce a
|
4 |
|
|
nonnegative result.
|
5 |
|
|
|
6 |
|
|
Written by Kaveh Ghazi, 2004-03-10. */
|
7 |
|
|
|
8 |
|
|
/* { dg-do link } */
|
9 |
|
|
/* { dg-options "-ffast-math" } */
|
10 |
|
|
|
11 |
|
|
#define PROTOTYPE_RTYPE(FN,RTYPE) extern RTYPE FN(double); \
|
12 |
|
|
extern RTYPE FN##f(float); \
|
13 |
|
|
extern RTYPE FN##l(long double);
|
14 |
|
|
#define PROTOTYPE(FN) extern double FN(double); extern float FN##f(float); \
|
15 |
|
|
extern long double FN##l(long double);
|
16 |
|
|
#define PROTOTYPE2(FN) extern double FN(double, double); \
|
17 |
|
|
extern float FN##f(float, float); \
|
18 |
|
|
extern long double FN##l(long double, long double);
|
19 |
|
|
#define CPROTOTYPE1(FN) extern double FN(_Complex double); \
|
20 |
|
|
extern float FN##f(_Complex float); \
|
21 |
|
|
extern long double FN##l(_Complex long double);
|
22 |
|
|
#define CPROTOTYPE1(FN) extern double FN(_Complex double); \
|
23 |
|
|
extern float FN##f(_Complex float); \
|
24 |
|
|
extern long double FN##l(_Complex long double);
|
25 |
|
|
#define IPROTOTYPE(FN) extern int FN(int); extern int FN##l(long); \
|
26 |
|
|
extern int FN##ll(long long);
|
27 |
|
|
#define PROTOTYPE2TYPE2(FN,A2TYPE) extern double FN(double, A2TYPE); \
|
28 |
|
|
extern float FN##f(float, A2TYPE); \
|
29 |
|
|
extern long double FN##l(long double, A2TYPE);
|
30 |
|
|
#define PROTOTYPE2_A2FPTR(FN) extern double FN(double, double *); \
|
31 |
|
|
extern float FN##f(float, float *); \
|
32 |
|
|
extern long double FN##l(long double, long double *);
|
33 |
|
|
|
34 |
|
|
extern int signbit (double);
|
35 |
|
|
extern int signbitf (float);
|
36 |
|
|
extern int signbitl (long double);
|
37 |
|
|
|
38 |
|
|
void test(double d1, double d2, float f1, float f2,
|
39 |
|
|
long double ld1, long double ld2)
|
40 |
|
|
{
|
41 |
|
|
/* These are always nonnegative. */
|
42 |
|
|
|
43 |
|
|
#define TEST1(FN) \
|
44 |
|
|
extern void link_failure_##FN (void); PROTOTYPE(FN) \
|
45 |
|
|
if (signbit(FN(d1)) || signbitf(FN##f(f1)) || signbitl(FN##l(ld1))) \
|
46 |
|
|
link_failure_##FN()
|
47 |
|
|
|
48 |
|
|
#define TEST2(FN) \
|
49 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2(FN) \
|
50 |
|
|
if (signbit(FN(d1,d2)) || signbitf(FN##f(f1,f2)) || signbitl(FN##l(ld1,ld2))) \
|
51 |
|
|
link_failure_##FN()
|
52 |
|
|
|
53 |
|
|
#define CTEST1(FN) \
|
54 |
|
|
extern void link_failure_##FN (void); CPROTOTYPE1(FN) \
|
55 |
|
|
if (signbit(FN(d1)) || signbitf(FN##f(f1)) || signbitl(FN##l(ld1))) \
|
56 |
|
|
link_failure_##FN()
|
57 |
|
|
|
58 |
|
|
#define ITEST1(FN) \
|
59 |
|
|
extern void link_failure_##FN (void); IPROTOTYPE(FN) \
|
60 |
|
|
if (signbit(FN(d1)) || signbitf(FN##l(f1)) || signbitl(FN##ll(ld1))) \
|
61 |
|
|
link_failure_##FN()
|
62 |
|
|
|
63 |
|
|
TEST1 (acos);
|
64 |
|
|
TEST1 (acosh);
|
65 |
|
|
CTEST1 (cabs);
|
66 |
|
|
TEST1 (cosh);
|
67 |
|
|
TEST1 (erfc);
|
68 |
|
|
TEST1 (exp);
|
69 |
|
|
TEST1 (exp10);
|
70 |
|
|
TEST1 (exp2);
|
71 |
|
|
TEST1 (fabs);
|
72 |
|
|
TEST2 (fdim);
|
73 |
|
|
TEST2 (hypot);
|
74 |
|
|
TEST1 (pow10);
|
75 |
|
|
TEST1 (sqrt);
|
76 |
|
|
ITEST1 (ffs);
|
77 |
|
|
ITEST1 (__builtin_parity);
|
78 |
|
|
ITEST1 (__builtin_popcount);
|
79 |
|
|
|
80 |
|
|
/* These are nonnegative if the first argument is. */
|
81 |
|
|
#define ARG1TEST1(FN) \
|
82 |
|
|
extern void link_failure_##FN (void); PROTOTYPE(FN) \
|
83 |
|
|
if (signbit(FN(fabs(d1))) || signbitf(FN##f(fabsf(f1))) \
|
84 |
|
|
|| signbitl(FN##l(fabsl(ld1)))) \
|
85 |
|
|
link_failure_##FN()
|
86 |
|
|
|
87 |
|
|
/* Same, but allow specifying the return type. */
|
88 |
|
|
#define ARG1TEST1_RTYPE(FN,RTYPE) \
|
89 |
|
|
extern void link_failure_##FN (void); PROTOTYPE_RTYPE(FN,RTYPE) \
|
90 |
|
|
if (signbit(FN(fabs(d1))) || signbitf(FN##f(fabsf(f1))) \
|
91 |
|
|
|| signbitl(FN##l(fabsl(ld1)))) \
|
92 |
|
|
link_failure_##FN()
|
93 |
|
|
|
94 |
|
|
/* These are nonnegative if the first argument is. */
|
95 |
|
|
#define ARG1TEST2(FN) \
|
96 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2(FN) \
|
97 |
|
|
if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
|
98 |
|
|
|| signbitl(FN##l(fabsl(ld1),ld2))) \
|
99 |
|
|
link_failure_##FN()
|
100 |
|
|
|
101 |
|
|
/* These are nonnegative if the second argument is. */
|
102 |
|
|
#define ARG2TEST2(FN) \
|
103 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2(FN) \
|
104 |
|
|
if (signbit(FN(d1,fabs(d2))) || signbitf(FN##f(f1,fabsf(f2))) \
|
105 |
|
|
|| signbitl(FN##l(ld1,fabsl(ld2)))) \
|
106 |
|
|
link_failure_##FN()
|
107 |
|
|
|
108 |
|
|
/* These are nonnegative if the first OR second argument is. */
|
109 |
|
|
#define ARG2TESTor(FN) \
|
110 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2(FN) \
|
111 |
|
|
if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
|
112 |
|
|
|| signbitl(FN##l(fabsl(ld1),ld2)) || signbit(FN(d1,fabs(d2))) \
|
113 |
|
|
|| signbitf(FN##f(f1,fabsf(f2))) || signbitl(FN##l(ld1,fabsl(ld2)))) \
|
114 |
|
|
link_failure_##FN()
|
115 |
|
|
|
116 |
|
|
/* These are nonnegative if the first AND second argument is. */
|
117 |
|
|
#define ARG2TESTand(FN) \
|
118 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2(FN) \
|
119 |
|
|
if (signbit(FN(fabs(d1),fabs(d2))) || signbitf(FN##f(fabsf(f1),fabsf(f2))) \
|
120 |
|
|
|| signbitl(FN##l(fabsl(ld1),fabsl(ld2)))) \
|
121 |
|
|
link_failure_##FN()
|
122 |
|
|
|
123 |
|
|
/* These are nonnegative if the first argument is, 2nd arg is int. */
|
124 |
|
|
#define ARG2TEST1_A2INT(FN) \
|
125 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2TYPE2(FN, int) \
|
126 |
|
|
if (signbit(FN(fabs(d1),d2)) || signbitf(FN##f(fabsf(f1),f2)) \
|
127 |
|
|
|| signbitl(FN##l(fabsl(ld1),ld2))) \
|
128 |
|
|
link_failure_##FN()
|
129 |
|
|
|
130 |
|
|
/* These are nonnegative if the first argument is, specify 2nd arg. */
|
131 |
|
|
#define ARG2TEST1_A2FPTR(FN) \
|
132 |
|
|
extern void link_failure_##FN (void); PROTOTYPE2_A2FPTR(FN) \
|
133 |
|
|
if (signbit(FN(fabs(d1),&d2)) || signbitf(FN##f(fabsf(f1),&f2)) \
|
134 |
|
|
|| signbitl(FN##l(fabsl(ld1),&ld2))) \
|
135 |
|
|
link_failure_##FN()
|
136 |
|
|
|
137 |
|
|
ARG1TEST1 (asinh);
|
138 |
|
|
ARG1TEST1 (atan);
|
139 |
|
|
ARG1TEST1 (atanh);
|
140 |
|
|
ARG1TEST1 (cbrt);
|
141 |
|
|
ARG1TEST1 (ceil);
|
142 |
|
|
ARG1TEST1 (erf);
|
143 |
|
|
ARG1TEST1 (expm1);
|
144 |
|
|
ARG1TEST1 (floor);
|
145 |
|
|
ARG1TEST2 (fmod);
|
146 |
|
|
ARG2TEST1_A2INT (ldexp);
|
147 |
|
|
ARG1TEST1_RTYPE (__builtin_llceil, long long);
|
148 |
|
|
ARG1TEST1_RTYPE (__builtin_llfloor, long long);
|
149 |
|
|
ARG1TEST1_RTYPE (llrint, long long);
|
150 |
|
|
ARG1TEST1_RTYPE (llround, long long);
|
151 |
|
|
ARG1TEST1_RTYPE (__builtin_lceil, long);
|
152 |
|
|
ARG1TEST1_RTYPE (__builtin_lfloor, long);
|
153 |
|
|
ARG1TEST1_RTYPE (lrint, long);
|
154 |
|
|
ARG1TEST1_RTYPE (lround, long);
|
155 |
|
|
/* The modf* functions aren't ever "const" or "pure" even with
|
156 |
|
|
-ffast-math so they won't be eliminated and yield a link failure. */
|
157 |
|
|
/* ARG2TEST1_A2FPTR (modf);*/
|
158 |
|
|
ARG1TEST1 (nearbyint);
|
159 |
|
|
ARG1TEST2 (pow);
|
160 |
|
|
ARG1TEST1 (rint);
|
161 |
|
|
ARG1TEST1 (round);
|
162 |
|
|
ARG1TEST1_RTYPE (signbit, int);
|
163 |
|
|
ARG1TEST1 (sinh);
|
164 |
|
|
ARG1TEST1 (tanh);
|
165 |
|
|
ARG1TEST1 (trunc);
|
166 |
|
|
|
167 |
|
|
ARG2TESTor (fmax);
|
168 |
|
|
ARG2TESTand (fmin);
|
169 |
|
|
ARG2TEST2 (copysign);
|
170 |
|
|
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
int main (void)
|
174 |
|
|
{
|
175 |
|
|
return 0;
|
176 |
|
|
}
|