1 /* Test __builtin_tgmath: valid uses, standard floating-point types. */
3 /* { dg-options "" } */
5 extern void abort (void);
6 extern void exit (int);
8 #define CHECK_CALL(C, E, V) \
13 extern __typeof (C) V; \
19 extern long double var_ld
;
20 extern _Complex
float var_cf
;
21 extern _Complex
double var_cd
;
22 extern _Complex
long double var_cld
;
25 typedef float float_type
;
26 typedef double double_type
;
28 /* Test simple case, real arguments and return type. */
30 float_type
t1f (float x
) { return x
+ 1; }
31 double t1d (double_type x
) { return x
+ 2; }
32 long double t1l (volatile long double x
) { return x
+ 3; }
34 #define t1v(x) __builtin_tgmath (t1f, t1d, t1l, x)
35 #define t1vr(x) __builtin_tgmath (t1l, t1d, t1f, x)
41 volatile float vf
= 2;
46 CHECK_CALL (t1v (f
), 2, var_f
);
47 CHECK_CALL (t1v (vf
), 3, var_f
);
48 CHECK_CALL (t1v (d
), 5, var_d
);
49 CHECK_CALL (t1v (ld
), 7, var_ld
);
50 CHECK_CALL (t1v (i
), 7, var_d
);
51 CHECK_CALL (t1v (ll
), 8, var_d
);
52 CHECK_CALL (t1vr (f
), 2, var_f
);
53 CHECK_CALL (t1vr (vf
), 3, var_f
);
54 CHECK_CALL (t1vr (d
), 5, var_d
);
55 CHECK_CALL (t1vr (ld
), 7, var_ld
);
56 CHECK_CALL (t1vr (i
), 7, var_d
);
57 CHECK_CALL (t1vr (ll
), 8, var_d
);
60 /* Test first argument not type-generic. */
62 float t2f (int a
, float x
) { return a
* x
+ 1; }
63 double t2d (int a
, double x
) { return a
* x
+ 2; }
64 long double t2l (int a
, long double x
) { return a
* x
+ 3; }
66 #define t2v(a, x) __builtin_tgmath (t2f, t2d, t2l, a, x)
75 unsigned long long ll
= 5;
76 CHECK_CALL (t2v (1, f
), 2, var_f
);
77 CHECK_CALL (t2v (2, d
), 6, var_d
);
78 CHECK_CALL (t2v (3, ld
), 12, var_ld
);
79 CHECK_CALL (t2v (4, i
), 18, var_d
);
80 CHECK_CALL (t2v (5, ll
), 27, var_d
);
83 /* Test return type not type-generic. */
85 int t3f (float x
) { return x
+ 1; }
86 int t3d (double x
) { return x
+ 2; }
87 int t3l (long double x
) { return x
+ 3; }
89 #define t3v(x) __builtin_tgmath (t3f, t3d, t3l, x)
98 CHECK_CALL (t3v (f
), 2, var_i
);
99 CHECK_CALL (t3v (d
), 4, var_i
);
100 CHECK_CALL (t3v (ld
), 6, var_i
);
101 CHECK_CALL (t3v (s
), 6, var_i
);
104 /* Test multiple type-generic arguments. */
106 float t4f (float x
, float y
) { return 10 * x
+ y
; }
107 double t4d (double x
, double y
) { return 100 * x
+ y
; }
108 long double t4l (long double x
, long double y
) { return 1000 * x
+ y
; }
110 #define t4v(x, y) __builtin_tgmath (t4f, t4d, t4l, x, y)
121 CHECK_CALL (t4v (f1
, f2
), 12, var_f
);
122 CHECK_CALL (t4v (f2
, f1
), 21, var_f
);
123 CHECK_CALL (t4v (f1
, d1
), 103, var_d
);
124 CHECK_CALL (t4v (d2
, f2
), 402, var_d
);
125 CHECK_CALL (t4v (f1
, l
), 106, var_d
);
126 CHECK_CALL (t4v (ld
, f1
), 5001, var_ld
);
127 CHECK_CALL (t4v (l
, l
), 606, var_d
);
128 CHECK_CALL (t4v (l
, ld
), 6005, var_ld
);
131 /* Test complex argument, real return type. */
133 float t5f (_Complex
float x
) { return 1 + __real__ x
+ 3 * __imag__ x
; }
134 double t5d (_Complex
double x
) { return 2 + __real__ x
+ 4 * __imag__ x
; }
135 long double t5l (_Complex
long double x
) { return 3 + __real__ x
+ 5 * __imag__ x
; }
137 #define t5v(x) __builtin_tgmath (t5f, t5d, t5l, x)
143 _Complex
float cf
= 2 + 3i
;
145 _Complex
double cd
= 5 + 6i
;
147 _Complex
long double cld
= 8 + 9i
;
149 _Complex
int ci
= 11 + 12i
;
150 CHECK_CALL (t5v (f
), 2, var_f
);
151 CHECK_CALL (t5v (cf
), 12, var_f
);
152 CHECK_CALL (t5v (d
), 6, var_d
);
153 CHECK_CALL (t5v (cd
), 31, var_d
);
154 CHECK_CALL (t5v (ld
), 10, var_ld
);
155 CHECK_CALL (t5v (cld
), 56, var_ld
);
156 CHECK_CALL (t5v (i
), 12, var_d
);
157 CHECK_CALL (t5v (ci
), 61, var_d
);
160 /* Test complex argument, complex return type. */
162 _Complex
float t6f (_Complex
float x
) { return 1 + x
; }
163 _Complex
double t6d (_Complex
double x
) { return 2 + x
; }
164 _Complex
long double t6l (_Complex
long double x
) { return 3 + x
; }
166 #define t6v(x) __builtin_tgmath (t6f, t6d, t6l, x)
172 _Complex
float cf
= 2 + 3i
;
174 _Complex
double cd
= 5 + 6i
;
176 _Complex
long double cld
= 8 + 9i
;
178 _Complex
int ci
= 11 + 12i
;
179 CHECK_CALL (t6v (f
), 2, var_cf
);
180 CHECK_CALL (t6v (cf
), 3 + 3i
, var_cf
);
181 CHECK_CALL (t6v (d
), 6, var_cd
);
182 CHECK_CALL (t6v (cd
), 7 + 6i
, var_cd
);
183 CHECK_CALL (t6v (ld
), 10, var_cld
);
184 CHECK_CALL (t6v (cld
), 11 + 9i
, var_cld
);
185 CHECK_CALL (t6v (i
), 12, var_cd
);
186 CHECK_CALL (t6v (ci
), 13 + 12i
, var_cd
);
189 /* Test real and complex argument, real return type. */
191 float t7f (float x
) { return 1 + x
; }
192 float t7cf (_Complex
float x
) { return 2 + __real__ x
; }
193 double t7d (double x
) { return 3 + x
; }
194 double t7cd (_Complex
double x
) { return 4 + __real__ x
; }
195 long double t7l (long double x
) { return 5 + x
; }
196 long double t7cl (_Complex
long double x
) { return 6 + __real__ x
; }
198 #define t7v(x) __builtin_tgmath (t7f, t7d, t7l, t7cf, t7cd, t7cl, x)
204 _Complex
float cf
= 2 + 3i
;
206 _Complex
double cd
= 5 + 6i
;
208 _Complex
long double cld
= 8 + 9i
;
210 _Complex
int ci
= 11 + 12i
;
211 CHECK_CALL (t7v (f
), 2, var_f
);
212 CHECK_CALL (t7v (cf
), 4, var_f
);
213 CHECK_CALL (t7v (d
), 7, var_d
);
214 CHECK_CALL (t7v (cd
), 9, var_d
);
215 CHECK_CALL (t7v (ld
), 12, var_ld
);
216 CHECK_CALL (t7v (cld
), 14, var_ld
);
217 CHECK_CALL (t7v (i
), 13, var_d
);
218 CHECK_CALL (t7v (ci
), 15, var_d
);
221 /* Test real and complex argument, real and complex return type. */
223 float t8f (float x
) { return 1 + x
; }
224 _Complex
float t8cf (_Complex
float x
) { return 2 + x
; }
225 double t8d (double x
) { return 3 + x
; }
226 _Complex
double t8cd (_Complex
double x
) { return 4 + x
; }
227 long double t8l (long double x
) { return 5 + x
; }
228 _Complex
long double t8cl (_Complex
long double x
) { return 6 + x
; }
230 #define t8v(x) __builtin_tgmath (t8f, t8d, t8l, t8cf, t8cd, t8cl, x)
236 _Complex
float cf
= 2 + 3i
;
238 _Complex
double cd
= 5 + 6i
;
240 _Complex
long double cld
= 8 + 9i
;
242 _Complex
int ci
= 11 + 12i
;
243 CHECK_CALL (t8v (f
), 2, var_f
);
244 CHECK_CALL (t8v (cf
), 4 + 3i
, var_cf
);
245 CHECK_CALL (t8v (d
), 7, var_d
);
246 CHECK_CALL (t8v (cd
), 9 + 6i
, var_cd
);
247 CHECK_CALL (t8v (ld
), 12, var_ld
);
248 CHECK_CALL (t8v (cld
), 14 + 9i
, var_cld
);
249 CHECK_CALL (t8v (i
), 13, var_d
);
250 CHECK_CALL (t8v (ci
), 15 + 12i
, var_cd
);
253 /* Test multiple type-generic arguments, real and complex. */
255 float t9f (float x
, float y
) { return x
+ 10 * y
; }
256 _Complex
float t9cf (_Complex
float x
, _Complex
float y
) { return x
+ 100 * y
; }
257 double t9d (double x
, double y
) { return x
+ 1000 * y
; }
258 _Complex
double t9cd (_Complex
double x
, _Complex
double y
) { return x
+ 10000 * y
; }
259 long double t9l (long double x
, long double y
) { return x
+ 100000 * y
; }
260 _Complex
long double t9cl (_Complex
long double x
, _Complex
long double y
) { return x
+ 1000000 * y
; }
262 #define t9v(x, y) __builtin_tgmath (t9f, t9d, t9l, t9cf, t9cd, t9cl, x, y)
268 _Complex
float cf
= 2 + 3i
;
270 _Complex
double cd
= 5 + 6i
;
272 _Complex
long double cld
= 8 + 9i
;
274 _Complex
int ci
= 11 + 12i
;
275 CHECK_CALL (t9v (f
, f
), 11, var_f
);
276 CHECK_CALL (t9v (f
, cf
), 201 + 300i
, var_cf
);
277 CHECK_CALL (t9v (cf
, f
), 102 + 3i
, var_cf
);
278 CHECK_CALL (t9v (f
, i
), 10001, var_d
);
279 CHECK_CALL (t9v (i
, f
), 1010, var_d
);
280 CHECK_CALL (t9v (d
, d
), 4004, var_d
);
281 CHECK_CALL (t9v (d
, cd
), 50004 + 60000i
, var_cd
);
282 CHECK_CALL (t9v (ld
, i
), 1000007, var_ld
);
283 CHECK_CALL (t9v (cf
, cld
), 8000002 + 9000003i
, var_cld
);
284 CHECK_CALL (t9v (i
, i
), 10010, var_d
);
285 CHECK_CALL (t9v (ci
, i
), 100011 + 12i
, var_cd
);
288 /* Test functions rounding result to narrower type. */
290 float t10d (double x
) { return 1 + x
; }
291 float t10l (long double x
) { return 2 + x
; }
293 #define t10v(x) __builtin_tgmath (t10d, t10l, x)
302 CHECK_CALL (t10v (f
), 2, var_f
);
303 CHECK_CALL (t10v (d
), 3, var_f
);
304 CHECK_CALL (t10v (ld
), 5, var_f
);
305 CHECK_CALL (t10v (s
), 5, var_f
);