Merged with mainline at revision 128810.
[official-gcc.git] / gcc / testsuite / gcc.target / arm / eabi1.c
blob06af67102998a429f14fb4d1dcbe4707ee9f39db
1 /* { dg-do run { target arm*-*-symbianelf* arm*-*-eabi* } } */
2 /* { dg-options "" } */
4 /* This file tests most of the non-C++ run-time helper functions
5 described in Section 4 of the "Run-Time ABI for the ARM
6 Architecture". These are basic tests; they do not try to validate
7 all of the corner cases in these routines.
9 The functions not tested here are:
11 __aeabi_cdcmpeq
12 __aeabi_cdcmple
13 __aeabi_cdrcmple
14 __aeabi_cfcmpeq
15 __aeabi_cfcmple
16 __aeabi_cfrcmple
17 __aeabi_ldivmod
18 __aeabi_uldivmod
19 __aeabi_idivmod
20 __aeabi_uidivmod
22 These functions have non-standard calling conventions that would
23 require the use of inline assembly to test. It would be good to
24 add such tests, but they have not yet been implemented.
26 There are also no tests for the "division by zero", "memory copying,
27 clearing, and setting" functions. */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <math.h>
33 #define decl_float(code, type) \
34 extern type __aeabi_ ## code ## add (type, type); \
35 extern type __aeabi_ ## code ## div (type, type); \
36 extern type __aeabi_ ## code ## mul (type, type); \
37 extern type __aeabi_ ## code ## neg (type); \
38 extern type __aeabi_ ## code ## rsub (type, type); \
39 extern type __aeabi_ ## code ## sub (type, type); \
40 extern int __aeabi_ ## code ## cmpeq (type, type); \
41 extern int __aeabi_ ## code ## cmplt (type, type); \
42 extern int __aeabi_ ## code ## cmple (type, type); \
43 extern int __aeabi_ ## code ## cmpge (type, type); \
44 extern int __aeabi_ ## code ## cmpgt (type, type); \
45 extern int __aeabi_ ## code ## cmpun (type, type); \
46 extern int __aeabi_ ## code ## 2iz (type); \
47 extern unsigned int __aeabi_ ## code ## 2uiz (type); \
48 extern long long __aeabi_ ## code ## 2lz (type); \
49 extern unsigned long long __aeabi_ ## code ## 2ulz (type); \
50 extern type __aeabi_i2 ## code (int); \
51 extern type __aeabi_ui2 ## code (int); \
52 extern type __aeabi_l2 ## code (long long); \
53 extern type __aeabi_ul2 ## code (unsigned long long); \
55 type code ## zero = 0.0; \
56 type code ## one = 1.0; \
57 type code ## two = 2.0; \
58 type code ## four = 4.0; \
59 type code ## minus_one = -1.0; \
60 type code ## minus_two = -2.0; \
61 type code ## minus_four = -4.0; \
62 type code ## epsilon = 1E-32; \
63 type code ## NaN = 0.0 / 0.0;
65 decl_float (d, double)
66 decl_float (f, float)
68 extern float __aeabi_d2f (double);
69 extern double __aeabi_f2d (float);
70 extern long long __aeabi_lmul (long long, long long);
71 extern long long __aeabi_llsl (long long, int);
72 extern long long __aeabi_llsr (long long, int);
73 extern long long __aeabi_lasr (long long, int);
74 extern int __aeabi_lcmp (long long, long long);
75 extern int __aeabi_ulcmp (unsigned long long, unsigned long long);
76 extern int __aeabi_idiv (int, int);
77 extern unsigned int __aeabi_uidiv (unsigned int, unsigned int);
78 extern int __eabi_uread4 (void *);
79 extern int __eabi_uwrite4 (int, void *);
80 extern long long __eabi_uread8 (void *);
81 extern long long __eabi_uwrite8 (long long, void *);
83 #define eq(a, b, type, abs, epsilon, format) \
84 { \
85 type a1; \
86 type b1; \
88 a1 = a; \
89 b1 = b; \
90 if (abs (a1 - b1) > epsilon) \
91 { \
92 fprintf (stderr, "%d: Test %s == %s\n", __LINE__, #a, #b); \
93 fprintf (stderr, "%d: " format " != " format "\n", \
94 __LINE__, a1, b1); \
95 abort (); \
96 } \
99 #define ieq(a, b) eq (a, b, int, abs, 0, "%d")
100 #define ueq(a, b) eq (a, b, unsigned int, abs, 0, "%u")
101 #define leq(a, b) eq (a, b, long long, abs, 0, "%lld")
102 #define uleq(a, b) eq (a, b, unsigned long long, abs, 0, "%llu")
103 #define feq(a, b) eq (a, b, float, fabs, fepsilon, "%f")
104 #define deq(a, b) eq (a, b, double, fabs, depsilon, "%g")
106 #define NUM_CMP_VALUES 6
108 /* Values picked to cover a range of small, large, positive and negative. */
109 static unsigned int cmp_val[NUM_CMP_VALUES] =
113 0x40000000,
114 0x80000000,
115 0xc0000000,
116 0xffffffff
119 /* All combinations for each of the above values. */
120 #define ulcmp(l, s, m) \
121 s, l, l, l, l, l, m, s, l, l, l, l, \
122 m, m, s, l, l, l, m, m, m, s, l, l, \
123 m, m, m, m, s, l, m, m, m, m, m, s
125 #define lcmp(l, s, m) \
126 s, l, l, m, m, m, m, s, l, m, m, m, \
127 m, m, s, m, m, m, l, l, l, s, l, l, \
128 l, l, l, m, s, l, l, l, l, m, m, s
130 /* All combinations of the above for high/low words. */
131 static int lcmp_results[] =
133 lcmp(ulcmp(-1, -1, -1), ulcmp(-1, 0, 1), ulcmp(1, 1, 1))
136 static int ulcmp_results[] =
138 ulcmp(ulcmp(-1, -1, -1), ulcmp(-1, 0, 1), ulcmp(1, 1, 1))
141 static int signof(int i)
143 if (i < 0)
144 return -1;
146 if (i == 0)
147 return 0;
149 return 1;
152 int main () {
153 unsigned char bytes[256];
154 int i, j, k, n;
155 int *result;
157 /* Table 2. Double-precision floating-point arithmetic. */
158 deq (__aeabi_dadd (dzero, done), done);
159 deq (__aeabi_dadd (done, done), dtwo);
160 deq (__aeabi_ddiv (dminus_four, dminus_two), dtwo);
161 deq (__aeabi_ddiv (dminus_two, dtwo), dminus_one);
162 deq (__aeabi_dmul (dtwo, dtwo), dfour);
163 deq (__aeabi_dmul (dminus_one, dminus_two), dtwo);
164 deq (__aeabi_dneg (dminus_one), done);
165 deq (__aeabi_dneg (dfour), dminus_four);
166 deq (__aeabi_drsub (done, dzero), dminus_one);
167 deq (__aeabi_drsub (dtwo, dminus_two), dminus_four);
168 deq (__aeabi_dsub (dzero, done), dminus_one);
169 deq (__aeabi_dsub (dminus_two, dtwo), dminus_four);
171 /* Table 3. Double-precision floating-point comparisons. */
172 ieq (__aeabi_dcmpeq (done, done), 1);
173 ieq (__aeabi_dcmpeq (done, dzero), 0);
174 ieq (__aeabi_dcmpeq (dNaN, dzero), 0);
175 ieq (__aeabi_dcmpeq (dNaN, dNaN), 0);
177 ieq (__aeabi_dcmplt (dzero, done), 1);
178 ieq (__aeabi_dcmplt (done, dzero), 0);
179 ieq (__aeabi_dcmplt (dzero, dzero), 0);
180 ieq (__aeabi_dcmplt (dzero, dNaN), 0);
181 ieq (__aeabi_dcmplt (dNaN, dNaN), 0);
183 ieq (__aeabi_dcmple (dzero, done), 1);
184 ieq (__aeabi_dcmple (done, dzero), 0);
185 ieq (__aeabi_dcmple (dzero, dzero), 1);
186 ieq (__aeabi_dcmple (dzero, dNaN), 0);
187 ieq (__aeabi_dcmple (dNaN, dNaN), 0);
189 ieq (__aeabi_dcmpge (dzero, done), 0);
190 ieq (__aeabi_dcmpge (done, dzero), 1);
191 ieq (__aeabi_dcmpge (dzero, dzero), 1);
192 ieq (__aeabi_dcmpge (dzero, dNaN), 0);
193 ieq (__aeabi_dcmpge (dNaN, dNaN), 0);
195 ieq (__aeabi_dcmpgt (dzero, done), 0);
196 ieq (__aeabi_dcmpgt (done, dzero), 1);
197 ieq (__aeabi_dcmplt (dzero, dzero), 0);
198 ieq (__aeabi_dcmpgt (dzero, dNaN), 0);
199 ieq (__aeabi_dcmpgt (dNaN, dNaN), 0);
201 ieq (__aeabi_dcmpun (done, done), 0);
202 ieq (__aeabi_dcmpun (done, dzero), 0);
203 ieq (__aeabi_dcmpun (dNaN, dzero), 1);
204 ieq (__aeabi_dcmpun (dNaN, dNaN), 1);
206 /* Table 4. Single-precision floating-point arithmetic. */
207 feq (__aeabi_fadd (fzero, fone), fone);
208 feq (__aeabi_fadd (fone, fone), ftwo);
209 feq (__aeabi_fdiv (fminus_four, fminus_two), ftwo);
210 feq (__aeabi_fdiv (fminus_two, ftwo), fminus_one);
211 feq (__aeabi_fmul (ftwo, ftwo), ffour);
212 feq (__aeabi_fmul (fminus_one, fminus_two), ftwo);
213 feq (__aeabi_fneg (fminus_one), fone);
214 feq (__aeabi_fneg (ffour), fminus_four);
215 feq (__aeabi_frsub (fone, fzero), fminus_one);
216 feq (__aeabi_frsub (ftwo, fminus_two), fminus_four);
217 feq (__aeabi_fsub (fzero, fone), fminus_one);
218 feq (__aeabi_fsub (fminus_two, ftwo), fminus_four);
220 /* Table 5. Single-precision floating-point comparisons. */
221 ieq (__aeabi_fcmpeq (fone, fone), 1);
222 ieq (__aeabi_fcmpeq (fone, fzero), 0);
223 ieq (__aeabi_fcmpeq (fNaN, fzero), 0);
224 ieq (__aeabi_fcmpeq (fNaN, fNaN), 0);
226 ieq (__aeabi_fcmplt (fzero, fone), 1);
227 ieq (__aeabi_fcmplt (fone, fzero), 0);
228 ieq (__aeabi_fcmplt (fzero, fzero), 0);
229 ieq (__aeabi_fcmplt (fzero, fNaN), 0);
230 ieq (__aeabi_fcmplt (fNaN, fNaN), 0);
232 ieq (__aeabi_fcmple (fzero, fone), 1);
233 ieq (__aeabi_fcmple (fone, fzero), 0);
234 ieq (__aeabi_fcmple (fzero, fzero), 1);
235 ieq (__aeabi_fcmple (fzero, fNaN), 0);
236 ieq (__aeabi_fcmple (fNaN, fNaN), 0);
238 ieq (__aeabi_fcmpge (fzero, fone), 0);
239 ieq (__aeabi_fcmpge (fone, fzero), 1);
240 ieq (__aeabi_fcmpge (fzero, fzero), 1);
241 ieq (__aeabi_fcmpge (fzero, fNaN), 0);
242 ieq (__aeabi_fcmpge (fNaN, fNaN), 0);
244 ieq (__aeabi_fcmpgt (fzero, fone), 0);
245 ieq (__aeabi_fcmpgt (fone, fzero), 1);
246 ieq (__aeabi_fcmplt (fzero, fzero), 0);
247 ieq (__aeabi_fcmpgt (fzero, fNaN), 0);
248 ieq (__aeabi_fcmpgt (fNaN, fNaN), 0);
250 ieq (__aeabi_fcmpun (fone, fone), 0);
251 ieq (__aeabi_fcmpun (fone, fzero), 0);
252 ieq (__aeabi_fcmpun (fNaN, fzero), 1);
253 ieq (__aeabi_fcmpun (fNaN, fNaN), 1);
255 /* Table 6. Floating-point to integer conversions. */
256 ieq (__aeabi_d2iz (dminus_one), -1);
257 ueq (__aeabi_d2uiz (done), 1);
258 leq (__aeabi_d2lz (dminus_two), -2LL);
259 uleq (__aeabi_d2ulz (dfour), 4LL);
260 ieq (__aeabi_f2iz (fminus_one), -1);
261 ueq (__aeabi_f2uiz (fone), 1);
262 leq (__aeabi_f2lz (fminus_two), -2LL);
263 uleq (__aeabi_f2ulz (ffour), 4LL);
265 /* Table 7. Conversions between floating types. */
266 feq (__aeabi_d2f (dtwo), ftwo);
267 deq (__aeabi_f2d (fminus_four), dminus_four);
269 /* Table 8. Integer to floating-point conversions. */
270 deq (__aeabi_i2d (-1), dminus_one);
271 deq (__aeabi_ui2d (2), dtwo);
272 deq (__aeabi_l2d (-1), dminus_one);
273 deq (__aeabi_ul2d (2ULL), dtwo);
274 feq (__aeabi_i2f (-1), fminus_one);
275 feq (__aeabi_ui2f (2), ftwo);
276 feq (__aeabi_l2f (-1), fminus_one);
277 feq (__aeabi_ul2f (2ULL), ftwo);
279 /* Table 9. Long long functions. */
280 leq (__aeabi_lmul (4LL, -1LL), -4LL);
281 leq (__aeabi_llsl (2LL, 1), 4LL);
282 leq (__aeabi_llsr (-1LL, 63), 1);
283 leq (__aeabi_lasr (-1LL, 63), -1);
285 result = lcmp_results;
286 for (i = 0; i < NUM_CMP_VALUES; i++)
287 for (j = 0; j < NUM_CMP_VALUES; j++)
288 for (k = 0; k < NUM_CMP_VALUES; k++)
289 for (n = 0; n < NUM_CMP_VALUES; n++)
291 ieq (signof (__aeabi_lcmp
292 (((long long)cmp_val[i] << 32) | cmp_val[k],
293 ((long long)cmp_val[j] << 32) | cmp_val[n])),
294 *result);
295 result++;
297 result = ulcmp_results;
298 for (i = 0; i < NUM_CMP_VALUES; i++)
299 for (j = 0; j < NUM_CMP_VALUES; j++)
300 for (k = 0; k < NUM_CMP_VALUES; k++)
301 for (n = 0; n < NUM_CMP_VALUES; n++)
303 ieq (signof (__aeabi_ulcmp
304 (((long long)cmp_val[i] << 32) | cmp_val[k],
305 ((long long)cmp_val[j] << 32) | cmp_val[n])),
306 *result);
307 result++;
310 ieq (__aeabi_idiv (-550, 11), -50);
311 ueq (__aeabi_uidiv (4000000000U, 1000000U), 4000U);
313 for (i = 0; i < 256; i++)
314 bytes[i] = i;
316 #ifdef __ARMEB__
317 ieq (__aeabi_uread4 (bytes + 1), 0x01020304U);
318 leq (__aeabi_uread8 (bytes + 3), 0x030405060708090aLL);
319 ieq (__aeabi_uwrite4 (0x66778899U, bytes + 5), 0x66778899U);
320 leq (__aeabi_uwrite8 (0x2030405060708090LL, bytes + 15),
321 0x2030405060708090LL);
322 #else
323 ieq (__aeabi_uread4 (bytes + 1), 0x04030201U);
324 leq (__aeabi_uread8 (bytes + 3), 0x0a09080706050403LL);
325 ieq (__aeabi_uwrite4 (0x99887766U, bytes + 5), 0x99887766U);
326 leq (__aeabi_uwrite8 (0x9080706050403020LL, bytes + 15),
327 0x9080706050403020LL);
328 #endif
330 for (i = 0; i < 4; i++)
331 ieq (bytes[5 + i], (6 + i) * 0x11);
333 for (i = 0; i < 8; i++)
334 ieq (bytes[15 + i], (2 + i) * 0x10);
336 exit (0);