1 /* Test __builtin_tgmath: valid uses, decimal floating-point types. */
2 /* { dg-do run } */
3 /* { dg-options "" } */
4
5 extern void abort (void);
6 extern void exit (int);
7
8 #define CHECK_CALL(C, E, V) \
9 do \
10 { \
11 if ((C) != (E)) \
12 abort (); \
13 extern __typeof (C) V; \
14 } \
15 while (0)
16
17 extern float var_f;
18 extern double var_d;
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;
23 extern _Decimal32 var_d32;
24 extern _Decimal64 var_d64;
25 extern _Decimal128 var_d128;
26 extern int var_i;
27
28 /* Test decimal-only function, single argument. */
29
t1d32(_Decimal32 x)30 _Decimal32 t1d32 (_Decimal32 x) { return x + 1; }
t1d64(_Decimal64 x)31 _Decimal64 t1d64 (_Decimal64 x) { return x + 2; }
t1d128(_Decimal128 x)32 _Decimal128 t1d128 (_Decimal128 x) { return x + 3; }
33
34 #define t1v(x) __builtin_tgmath (t1d32, t1d64, t1d128, x)
35
36 static void
test_1(void)37 test_1 (void)
38 {
39 _Decimal32 d32 = 32;
40 _Decimal64 d64 = 64;
41 _Decimal128 d128 = 128;
42 int i = 256;
43 CHECK_CALL (t1v (d32), 33, var_d32);
44 CHECK_CALL (t1v (d64), 66, var_d64);
45 CHECK_CALL (t1v (d128), 131, var_d128);
46 CHECK_CALL (t1v (i), 258, var_d64);
47 }
48
49 /* Test decimal-only function, two arguments. */
50
t2d32(_Decimal32 x,_Decimal32 y)51 _Decimal32 t2d32 (_Decimal32 x, _Decimal32 y) { return 10 * x + y; }
t2d64(_Decimal64 x,_Decimal64 y)52 _Decimal64 t2d64 (_Decimal64 x, _Decimal64 y) { return 100 * x + y;; }
t2d128(_Decimal128 x,_Decimal128 y)53 _Decimal128 t2d128 (_Decimal128 x, _Decimal128 y) { return 1000 * x + y; }
54
55 #define t2v(x, y) __builtin_tgmath (t2d32, t2d64, t2d128, x, y)
56
57 static void
test_2(void)58 test_2 (void)
59 {
60 _Decimal32 d32 = 1;
61 _Decimal64 d64 = 2;
62 _Decimal128 d128 = 3;
63 int i = 4;
64 CHECK_CALL (t2v (d32, d32), 11, var_d32);
65 CHECK_CALL (t2v (d64, d64), 202, var_d64);
66 CHECK_CALL (t2v (d32, d64), 102, var_d64);
67 CHECK_CALL (t2v (d128, d64), 3002, var_d128);
68 CHECK_CALL (t2v (d128, i), 3004, var_d128);
69 CHECK_CALL (t2v (i, i), 404, var_d64);
70 CHECK_CALL (t2v (i, d32), 401, var_d64);
71 }
72
73 /* Test real-only function, single argument. */
74
t3f(float x)75 float t3f (float x) { return x + 1; }
t3d(double x)76 double t3d (double x) { return x + 2; }
t3l(long double x)77 long double t3l (long double x) { return x + 3; }
t3d32(_Decimal32 x)78 _Decimal32 t3d32 (_Decimal32 x) { return x + 4; }
t3d64(_Decimal64 x)79 _Decimal64 t3d64 (_Decimal64 x) { return x + 5; }
t3d128(_Decimal128 x)80 _Decimal128 t3d128 (_Decimal128 x) { return x + 6; }
81
82 #define t3v(x) __builtin_tgmath (t3f, t3d, t3l, t3d32, t3d64, t3d128, x)
83
84 static void
test_3(void)85 test_3 (void)
86 {
87 float f = 1;
88 double d = 2;
89 long double ld = 3;
90 int i = 4;
91 _Decimal32 d32 = 5;
92 _Decimal64 d64 = 6;
93 _Decimal128 d128 = 7;
94 CHECK_CALL (t3v (f), 2, var_f);
95 CHECK_CALL (t3v (d), 4, var_d);
96 CHECK_CALL (t3v (ld), 6, var_ld);
97 CHECK_CALL (t3v (i), 6, var_d);
98 CHECK_CALL (t3v (d32), 9, var_d32);
99 CHECK_CALL (t3v (d64), 11, var_d64);
100 CHECK_CALL (t3v (d128), 13, var_d128);
101 }
102
103 /* Test real-and-complex function, single argument. */
104
t4f(float x)105 float t4f (float x) { return x + 1; }
t4d(double x)106 double t4d (double x) { return x + 2; }
t4l(long double x)107 long double t4l (long double x) { return x + 3; }
t4cf(_Complex float x)108 _Complex float t4cf (_Complex float x) { return x + 4; }
t4cd(_Complex double x)109 _Complex double t4cd (_Complex double x) { return x + 5; }
t4cl(_Complex long double x)110 _Complex long double t4cl (_Complex long double x) { return x + 6; }
t4d32(_Decimal32 x)111 _Decimal32 t4d32 (_Decimal32 x) { return x + 7; }
t4d64(_Decimal64 x)112 _Decimal64 t4d64 (_Decimal64 x) { return x + 8; }
t4d128(_Decimal128 x)113 _Decimal128 t4d128 (_Decimal128 x) { return x + 9; }
114
115 #define t4v(x) __builtin_tgmath (t4f, t4d, t4l, t4cf, t4cd, t4cl, t4d32, t4d64, t4d128, x)
116
117 static void
test_4(void)118 test_4 (void)
119 {
120 float f = 1;
121 double d = 2;
122 long double ld = 3;
123 int i = 4;
124 _Complex float cf = 5;
125 _Complex double cd = 6;
126 _Complex long double cld = 7;
127 _Complex int ci = 8;
128 _Decimal32 d32 = 9;
129 _Decimal64 d64 = 10;
130 _Decimal128 d128 = 11;
131 CHECK_CALL (t4v (f), 2, var_f);
132 CHECK_CALL (t4v (d), 4, var_d);
133 CHECK_CALL (t4v (ld), 6, var_ld);
134 CHECK_CALL (t4v (i), 6, var_d);
135 CHECK_CALL (t4v (cf), 9, var_cf);
136 CHECK_CALL (t4v (cd), 11, var_cd);
137 CHECK_CALL (t4v (cld), 13, var_cld);
138 CHECK_CALL (t4v (ci), 13, var_cd);
139 CHECK_CALL (t4v (d32), 16, var_d32);
140 CHECK_CALL (t4v (d64), 18, var_d64);
141 CHECK_CALL (t4v (d128), 20, var_d128);
142 }
143
144 /* Test real-and-complex function, real return type, single argument. */
145
t5f(float x)146 float t5f (float x) { return x + 1; }
t5d(double x)147 double t5d (double x) { return x + 2; }
t5l(long double x)148 long double t5l (long double x) { return x + 3; }
t5cf(_Complex float x)149 float t5cf (_Complex float x) { return __real__ x + 4; }
t5cd(_Complex double x)150 double t5cd (_Complex double x) { return __real__ x + 5; }
t5cl(_Complex long double x)151 long double t5cl (_Complex long double x) { return __real__ x + 6; }
t5d32(_Decimal32 x)152 _Decimal32 t5d32 (_Decimal32 x) { return x + 7; }
t5d64(_Decimal64 x)153 _Decimal64 t5d64 (_Decimal64 x) { return x + 8; }
t5d128(_Decimal128 x)154 _Decimal128 t5d128 (_Decimal128 x) { return x + 9; }
155
156 #define t5v(x) __builtin_tgmath (t5f, t5d, t5l, t5cf, t5cd, t5cl, t5d32, t5d64, t5d128, x)
157
158 static void
test_5(void)159 test_5 (void)
160 {
161 float f = 1;
162 double d = 2;
163 long double ld = 3;
164 int i = 4;
165 _Complex float cf = 5;
166 _Complex double cd = 6;
167 _Complex long double cld = 7;
168 _Complex int ci = 8;
169 _Decimal32 d32 = 9;
170 _Decimal64 d64 = 10;
171 _Decimal128 d128 = 11;
172 CHECK_CALL (t5v (f), 2, var_f);
173 CHECK_CALL (t5v (d), 4, var_d);
174 CHECK_CALL (t5v (ld), 6, var_ld);
175 CHECK_CALL (t5v (i), 6, var_d);
176 CHECK_CALL (t5v (cf), 9, var_f);
177 CHECK_CALL (t5v (cd), 11, var_d);
178 CHECK_CALL (t5v (cld), 13, var_ld);
179 CHECK_CALL (t5v (ci), 13, var_d);
180 CHECK_CALL (t5v (d32), 16, var_d32);
181 CHECK_CALL (t5v (d64), 18, var_d64);
182 CHECK_CALL (t5v (d128), 20, var_d128);
183 }
184
185 /* Test real-and-complex function, two arguments. */
186
t6f(float x,float y)187 float t6f (float x, float y) { return x * 10 + y; }
t6d(double x,double y)188 double t6d (double x, double y) { return x * 100 + y; }
t6l(long double x,long double y)189 long double t6l (long double x, long double y) { return x * 1000 + y; }
t6cf(_Complex float x,_Complex float y)190 _Complex float t6cf (_Complex float x, _Complex float y) { return x * 10000 + y; }
t6cd(_Complex double x,_Complex double y)191 _Complex double t6cd (_Complex double x, _Complex double y) { return x * 100000 + y; }
t6cl(_Complex long double x,_Complex long double y)192 _Complex long double t6cl (_Complex long double x, _Complex long double y) { return x * 1000000 + y; }
t6d32(_Decimal32 x,_Decimal32 y)193 _Decimal32 t6d32 (_Decimal32 x, _Decimal32 y) { return x * 50 + y; }
t6d64(_Decimal64 x,_Decimal64 y)194 _Decimal64 t6d64 (_Decimal64 x, _Decimal64 y) { return x * 500 + y; }
t6d128(_Decimal128 x,_Decimal128 y)195 _Decimal128 t6d128 (_Decimal128 x, _Decimal128 y) { return x * 5000 + y; }
196
197 #define t6v(x, y) __builtin_tgmath (t6f, t6d, t6l, t6cf, t6cd, t6cl, t6d32, t6d64, t6d128, x, y)
198
199 static void
test_6(void)200 test_6 (void)
201 {
202 float f = 1;
203 double d = 2;
204 long double ld = 3;
205 int i = 4;
206 _Complex float cf = 5;
207 _Complex double cd = 6;
208 _Complex long double cld = 7;
209 _Complex int ci = 8;
210 _Decimal32 d32 = 9;
211 _Decimal64 d64 = 10;
212 _Decimal128 d128 = 11;
213 CHECK_CALL (t6v (f, f), 11, var_f);
214 CHECK_CALL (t6v (d, f), 201, var_d);
215 CHECK_CALL (t6v (f, d), 102, var_d);
216 CHECK_CALL (t6v (f, i), 104, var_d);
217 CHECK_CALL (t6v (ld, f), 3001, var_ld);
218 CHECK_CALL (t6v (i, ld), 4003, var_ld);
219 CHECK_CALL (t6v (i, i), 404, var_d);
220 CHECK_CALL (t6v (cf, f), 50001, var_cf);
221 CHECK_CALL (t6v (cf, cf), 50005, var_cf);
222 CHECK_CALL (t6v (cd, cf), 600005, var_cd);
223 CHECK_CALL (t6v (d, cld), 2000007, var_cld);
224 CHECK_CALL (t6v (ci, ci), 800008, var_cd);
225 CHECK_CALL (t6v (ci, f), 800001, var_cd);
226 CHECK_CALL (t6v (d32, d32), 459, var_d32);
227 CHECK_CALL (t6v (d64, i), 5004, var_d64);
228 CHECK_CALL (t6v (i, d32), 2009, var_d64);
229 CHECK_CALL (t6v (d128, d32), 55009, var_d128);
230 }
231
232 /* Test decimal-only function rounding result to narrower type. */
233
t7d64(_Decimal64 x)234 _Decimal32 t7d64 (_Decimal64 x) { return 1 + x; }
t7d128(_Decimal128 x)235 _Decimal32 t7d128 (_Decimal128 x) { return 2 + x; }
236
237 #define t7v(x) __builtin_tgmath (t7d64, t7d128, x)
238
239 static void
test_7(void)240 test_7 (void)
241 {
242 _Decimal32 d32 = 1;
243 _Decimal64 d64 = 2;
244 _Decimal128 d128 = 3;
245 short s = 4;
246 CHECK_CALL (t7v (d32), 2, var_d32);
247 CHECK_CALL (t7v (d64), 3, var_d32);
248 CHECK_CALL (t7v (d128), 5, var_d32);
249 CHECK_CALL (t7v (s), 5, var_d32);
250 }
251
252 int
main(void)253 main (void)
254 {
255 test_1 ();
256 test_2 ();
257 test_3 ();
258 test_4 ();
259 test_5 ();
260 test_6 ();
261 test_7 ();
262 exit (0);
263 }
264