* g++.dg/pph/c1attr-warn-unused-result.cc: New.
[official-gcc.git] / gcc / testsuite / g++.dg / pph / c1eabi1.h
blob3ac35ce536e52ed4461570696039b83a0904eab7
1 #ifndef __PPH_GUARD_H
2 #define __PPH_GUARD_H
3 /* { dg-options "-w -fpermissive" } */
4 /* { dg-xfail-if "ICEs the compiler during PPH read" { "*-*-*" } } */
5 /* { dg-prune-output "In file included.*" } */
6 /* This file tests most of the non-C++ run-time helper functions
7 described in Section 4 of the "Run-Time ABI for the ARM
8 Architecture". These are basic tests; they do not try to validate
9 all of the corner cases in these routines.
11 The functions not tested here are:
13 __aeabi_cdcmpeq
14 __aeabi_cdcmple
15 __aeabi_cdrcmple
16 __aeabi_cfcmpeq
17 __aeabi_cfcmple
18 __aeabi_cfrcmple
19 __aeabi_ldivmod
20 __aeabi_uldivmod
21 __aeabi_idivmod
22 __aeabi_uidivmod
24 These functions have non-standard calling conventions that would
25 require the use of inline assembly to test. It would be good to
26 add such tests, but they have not yet been implemented.
28 There are also no tests for the "division by zero", "memory copying,
29 clearing, and setting" functions. */
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <math.h>
35 /* All these functions are defined to use the base ABI, so use the
36 attribute to ensure the tests use the base ABI to call them even
37 when the VFP ABI is otherwise in effect. */
38 #define PCS __attribute__((pcs("aapcs")))
40 #define decl_float(code, type) \
41 extern type __aeabi_ ## code ## add (type, type) PCS; \
42 extern type __aeabi_ ## code ## div (type, type) PCS; \
43 extern type __aeabi_ ## code ## mul (type, type) PCS; \
44 extern type __aeabi_ ## code ## neg (type) PCS; \
45 extern type __aeabi_ ## code ## rsub (type, type) PCS; \
46 extern type __aeabi_ ## code ## sub (type, type) PCS; \
47 extern int __aeabi_ ## code ## cmpeq (type, type) PCS; \
48 extern int __aeabi_ ## code ## cmplt (type, type) PCS; \
49 extern int __aeabi_ ## code ## cmple (type, type) PCS; \
50 extern int __aeabi_ ## code ## cmpge (type, type) PCS; \
51 extern int __aeabi_ ## code ## cmpgt (type, type) PCS; \
52 extern int __aeabi_ ## code ## cmpun (type, type) PCS; \
53 extern int __aeabi_ ## code ## 2iz (type) PCS; \
54 extern unsigned int __aeabi_ ## code ## 2uiz (type) PCS; \
55 extern long long __aeabi_ ## code ## 2lz (type) PCS; \
56 extern unsigned long long __aeabi_ ## code ## 2ulz (type) PCS; \
57 extern type __aeabi_i2 ## code (int) PCS; \
58 extern type __aeabi_ui2 ## code (int) PCS; \
59 extern type __aeabi_l2 ## code (long long) PCS; \
60 extern type __aeabi_ul2 ## code (unsigned long long) PCS; \
62 type code ## zero = 0.0; \
63 type code ## one = 1.0; \
64 type code ## two = 2.0; \
65 type code ## four = 4.0; \
66 type code ## minus_one = -1.0; \
67 type code ## minus_two = -2.0; \
68 type code ## minus_four = -4.0; \
69 type code ## epsilon = 1E-32; \
70 type code ## NaN = 0.0 / 0.0;
72 decl_float (d, double)
73 decl_float (f, float)
75 extern float __aeabi_d2f (double) PCS;
76 extern double __aeabi_f2d (float) PCS;
77 extern long long __aeabi_lmul (long long, long long);
78 extern long long __aeabi_llsl (long long, int);
79 extern long long __aeabi_llsr (long long, int);
80 extern long long __aeabi_lasr (long long, int);
81 extern int __aeabi_lcmp (long long, long long);
82 extern int __aeabi_ulcmp (unsigned long long, unsigned long long);
83 extern int __aeabi_idiv (int, int);
84 extern unsigned int __aeabi_uidiv (unsigned int, unsigned int);
85 extern int __aeabi_uread4 (void *);
86 extern int __aeabi_uwrite4 (int, void *);
87 extern long long __aeabi_uread8 (void *);
88 extern long long __aeabi_uwrite8 (long long, void *);
90 #define eq(a, b, type, abs, epsilon, format) \
91 { \
92 type a1; \
93 type b1; \
95 a1 = a; \
96 b1 = b; \
97 if (abs (a1 - b1) > epsilon) \
98 { \
99 fprintf (stderr, "%d: Test %s == %s\n", __LINE__, #a, #b); \
100 fprintf (stderr, "%d: " format " != " format "\n", \
101 __LINE__, a1, b1); \
102 abort (); \
106 #define ieq(a, b) eq (a, b, int, abs, 0, "%d")
107 #define ueq(a, b) eq (a, b, unsigned int, abs, 0, "%u")
108 #define leq(a, b) eq (a, b, long long, abs, 0, "%lld")
109 #define uleq(a, b) eq (a, b, unsigned long long, abs, 0, "%llu")
110 #define feq(a, b) eq (a, b, float, fabs, fepsilon, "%f")
111 #define deq(a, b) eq (a, b, double, fabs, depsilon, "%g")
113 #define NUM_CMP_VALUES 6
115 /* Values picked to cover a range of small, large, positive and negative. */
116 static unsigned int cmp_val[NUM_CMP_VALUES] =
120 0x40000000,
121 0x80000000,
122 0xc0000000,
123 0xffffffff
126 /* All combinations for each of the above values. */
127 #define ulcmp(l, s, m) \
128 s, l, l, l, l, l, m, s, l, l, l, l, \
129 m, m, s, l, l, l, m, m, m, s, l, l, \
130 m, m, m, m, s, l, m, m, m, m, m, s
132 #define lcmp(l, s, m) \
133 s, l, l, m, m, m, m, s, l, m, m, m, \
134 m, m, s, m, m, m, l, l, l, s, l, l, \
135 l, l, l, m, s, l, l, l, l, m, m, s
137 /* All combinations of the above for high/low words. */
138 static int lcmp_results[] =
140 lcmp(ulcmp(-1, -1, -1), ulcmp(-1, 0, 1), ulcmp(1, 1, 1))
143 static int ulcmp_results[] =
145 ulcmp(ulcmp(-1, -1, -1), ulcmp(-1, 0, 1), ulcmp(1, 1, 1))
148 static int signof(int i)
150 if (i < 0)
151 return -1;
153 if (i == 0)
154 return 0;
156 return 1;
159 int main () {
160 unsigned char bytes[256];
161 int i, j, k, n;
162 int *result;
164 /* Table 2. Double-precision floating-point arithmetic. */
165 deq (__aeabi_dadd (dzero, done), done);
166 deq (__aeabi_dadd (done, done), dtwo);
167 deq (__aeabi_ddiv (dminus_four, dminus_two), dtwo);
168 deq (__aeabi_ddiv (dminus_two, dtwo), dminus_one);
169 deq (__aeabi_dmul (dtwo, dtwo), dfour);
170 deq (__aeabi_dmul (dminus_one, dminus_two), dtwo);
171 deq (__aeabi_dneg (dminus_one), done);
172 deq (__aeabi_dneg (dfour), dminus_four);
173 deq (__aeabi_drsub (done, dzero), dminus_one);
174 deq (__aeabi_drsub (dtwo, dminus_two), dminus_four);
175 deq (__aeabi_dsub (dzero, done), dminus_one);
176 deq (__aeabi_dsub (dminus_two, dtwo), dminus_four);
178 /* Table 3. Double-precision floating-point comparisons. */
179 ieq (__aeabi_dcmpeq (done, done), 1);
180 ieq (__aeabi_dcmpeq (done, dzero), 0);
181 ieq (__aeabi_dcmpeq (dNaN, dzero), 0);
182 ieq (__aeabi_dcmpeq (dNaN, dNaN), 0);
184 ieq (__aeabi_dcmplt (dzero, done), 1);
185 ieq (__aeabi_dcmplt (done, dzero), 0);
186 ieq (__aeabi_dcmplt (dzero, dzero), 0);
187 ieq (__aeabi_dcmplt (dzero, dNaN), 0);
188 ieq (__aeabi_dcmplt (dNaN, dNaN), 0);
190 ieq (__aeabi_dcmple (dzero, done), 1);
191 ieq (__aeabi_dcmple (done, dzero), 0);
192 ieq (__aeabi_dcmple (dzero, dzero), 1);
193 ieq (__aeabi_dcmple (dzero, dNaN), 0);
194 ieq (__aeabi_dcmple (dNaN, dNaN), 0);
196 ieq (__aeabi_dcmpge (dzero, done), 0);
197 ieq (__aeabi_dcmpge (done, dzero), 1);
198 ieq (__aeabi_dcmpge (dzero, dzero), 1);
199 ieq (__aeabi_dcmpge (dzero, dNaN), 0);
200 ieq (__aeabi_dcmpge (dNaN, dNaN), 0);
202 ieq (__aeabi_dcmpgt (dzero, done), 0);
203 ieq (__aeabi_dcmpgt (done, dzero), 1);
204 ieq (__aeabi_dcmplt (dzero, dzero), 0);
205 ieq (__aeabi_dcmpgt (dzero, dNaN), 0);
206 ieq (__aeabi_dcmpgt (dNaN, dNaN), 0);
208 ieq (__aeabi_dcmpun (done, done), 0);
209 ieq (__aeabi_dcmpun (done, dzero), 0);
210 ieq (__aeabi_dcmpun (dNaN, dzero), 1);
211 ieq (__aeabi_dcmpun (dNaN, dNaN), 1);
213 /* Table 4. Single-precision floating-point arithmetic. */
214 feq (__aeabi_fadd (fzero, fone), fone);
215 feq (__aeabi_fadd (fone, fone), ftwo);
216 feq (__aeabi_fdiv (fminus_four, fminus_two), ftwo);
217 feq (__aeabi_fdiv (fminus_two, ftwo), fminus_one);
218 feq (__aeabi_fmul (ftwo, ftwo), ffour);
219 feq (__aeabi_fmul (fminus_one, fminus_two), ftwo);
220 feq (__aeabi_fneg (fminus_one), fone);
221 feq (__aeabi_fneg (ffour), fminus_four);
222 feq (__aeabi_frsub (fone, fzero), fminus_one);
223 feq (__aeabi_frsub (ftwo, fminus_two), fminus_four);
224 feq (__aeabi_fsub (fzero, fone), fminus_one);
225 feq (__aeabi_fsub (fminus_two, ftwo), fminus_four);
227 /* Table 5. Single-precision floating-point comparisons. */
228 ieq (__aeabi_fcmpeq (fone, fone), 1);
229 ieq (__aeabi_fcmpeq (fone, fzero), 0);
230 ieq (__aeabi_fcmpeq (fNaN, fzero), 0);
231 ieq (__aeabi_fcmpeq (fNaN, fNaN), 0);
233 ieq (__aeabi_fcmplt (fzero, fone), 1);
234 ieq (__aeabi_fcmplt (fone, fzero), 0);
235 ieq (__aeabi_fcmplt (fzero, fzero), 0);
236 ieq (__aeabi_fcmplt (fzero, fNaN), 0);
237 ieq (__aeabi_fcmplt (fNaN, fNaN), 0);
239 ieq (__aeabi_fcmple (fzero, fone), 1);
240 ieq (__aeabi_fcmple (fone, fzero), 0);
241 ieq (__aeabi_fcmple (fzero, fzero), 1);
242 ieq (__aeabi_fcmple (fzero, fNaN), 0);
243 ieq (__aeabi_fcmple (fNaN, fNaN), 0);
245 ieq (__aeabi_fcmpge (fzero, fone), 0);
246 ieq (__aeabi_fcmpge (fone, fzero), 1);
247 ieq (__aeabi_fcmpge (fzero, fzero), 1);
248 ieq (__aeabi_fcmpge (fzero, fNaN), 0);
249 ieq (__aeabi_fcmpge (fNaN, fNaN), 0);
251 ieq (__aeabi_fcmpgt (fzero, fone), 0);
252 ieq (__aeabi_fcmpgt (fone, fzero), 1);
253 ieq (__aeabi_fcmplt (fzero, fzero), 0);
254 ieq (__aeabi_fcmpgt (fzero, fNaN), 0);
255 ieq (__aeabi_fcmpgt (fNaN, fNaN), 0);
257 ieq (__aeabi_fcmpun (fone, fone), 0);
258 ieq (__aeabi_fcmpun (fone, fzero), 0);
259 ieq (__aeabi_fcmpun (fNaN, fzero), 1);
260 ieq (__aeabi_fcmpun (fNaN, fNaN), 1);
262 /* Table 6. Floating-point to integer conversions. */
263 ieq (__aeabi_d2iz (dminus_one), -1);
264 ueq (__aeabi_d2uiz (done), 1);
265 leq (__aeabi_d2lz (dminus_two), -2LL);
266 uleq (__aeabi_d2ulz (dfour), 4LL);
267 ieq (__aeabi_f2iz (fminus_one), -1);
268 ueq (__aeabi_f2uiz (fone), 1);
269 leq (__aeabi_f2lz (fminus_two), -2LL);
270 uleq (__aeabi_f2ulz (ffour), 4LL);
272 /* Table 7. Conversions between floating types. */
273 feq (__aeabi_d2f (dtwo), ftwo);
274 deq (__aeabi_f2d (fminus_four), dminus_four);
276 /* Table 8. Integer to floating-point conversions. */
277 deq (__aeabi_i2d (-1), dminus_one);
278 deq (__aeabi_ui2d (2), dtwo);
279 deq (__aeabi_l2d (-1), dminus_one);
280 deq (__aeabi_ul2d (2ULL), dtwo);
281 feq (__aeabi_i2f (-1), fminus_one);
282 feq (__aeabi_ui2f (2), ftwo);
283 feq (__aeabi_l2f (-1), fminus_one);
284 feq (__aeabi_ul2f (2ULL), ftwo);
286 /* Table 9. Long long functions. */
287 leq (__aeabi_lmul (4LL, -1LL), -4LL);
288 leq (__aeabi_llsl (2LL, 1), 4LL);
289 leq (__aeabi_llsr (-1LL, 63), 1);
290 leq (__aeabi_lasr (-1LL, 63), -1);
292 result = lcmp_results;
293 for (i = 0; i < NUM_CMP_VALUES; i++)
294 for (j = 0; j < NUM_CMP_VALUES; j++)
295 for (k = 0; k < NUM_CMP_VALUES; k++)
296 for (n = 0; n < NUM_CMP_VALUES; n++)
298 ieq (signof (__aeabi_lcmp
299 (((long long)cmp_val[i] << 32) | cmp_val[k],
300 ((long long)cmp_val[j] << 32) | cmp_val[n])),
301 *result);
302 result++;
304 result = ulcmp_results;
305 for (i = 0; i < NUM_CMP_VALUES; i++)
306 for (j = 0; j < NUM_CMP_VALUES; j++)
307 for (k = 0; k < NUM_CMP_VALUES; k++)
308 for (n = 0; n < NUM_CMP_VALUES; n++)
310 ieq (signof (__aeabi_ulcmp
311 (((long long)cmp_val[i] << 32) | cmp_val[k],
312 ((long long)cmp_val[j] << 32) | cmp_val[n])),
313 *result);
314 result++;
317 ieq (__aeabi_idiv (-550, 11), -50);
318 ueq (__aeabi_uidiv (4000000000U, 1000000U), 4000U);
320 for (i = 0; i < 256; i++)
321 bytes[i] = i;
323 #ifdef __ARMEB__
324 ieq (__aeabi_uread4 (bytes + 1), 0x01020304U);
325 leq (__aeabi_uread8 (bytes + 3), 0x030405060708090aLL);
326 ieq (__aeabi_uwrite4 (0x66778899U, bytes + 5), 0x66778899U);
327 leq (__aeabi_uwrite8 (0x2030405060708090LL, bytes + 15),
328 0x2030405060708090LL);
329 #else
330 ieq (__aeabi_uread4 (bytes + 1), 0x04030201U);
331 leq (__aeabi_uread8 (bytes + 3), 0x0a09080706050403LL);
332 ieq (__aeabi_uwrite4 (0x99887766U, bytes + 5), 0x99887766U);
333 leq (__aeabi_uwrite8 (0x9080706050403020LL, bytes + 15),
334 0x9080706050403020LL);
335 #endif
337 for (i = 0; i < 4; i++)
338 ieq (bytes[5 + i], (6 + i) * 0x11);
340 for (i = 0; i < 8; i++)
341 ieq (bytes[15 + i], (2 + i) * 0x10);
343 exit (0);
345 #endif