* gcc.dg/ucnid-[23456].c: XFAIL on AIX.
[official-gcc.git] / gcc / testsuite / gcc.dg / arm-eabi1.c
blob0df295aa72688be6f672693113b0641ded72e34a
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", "unaligned
27 memory access", "memory copying, clearing, and setting"
28 functions. */
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <math.h>
34 #define decl_float(code, type) \
35 extern type __aeabi_ ## code ## add (type, type); \
36 extern type __aeabi_ ## code ## div (type, type); \
37 extern type __aeabi_ ## code ## mul (type, type); \
38 extern type __aeabi_ ## code ## neg (type); \
39 extern type __aeabi_ ## code ## rsub (type, type); \
40 extern type __aeabi_ ## code ## sub (type, type); \
41 extern int __aeabi_ ## code ## cmpeq (type, type); \
42 extern int __aeabi_ ## code ## cmplt (type, type); \
43 extern int __aeabi_ ## code ## cmple (type, type); \
44 extern int __aeabi_ ## code ## cmpge (type, type); \
45 extern int __aeabi_ ## code ## cmpgt (type, type); \
46 extern int __aeabi_ ## code ## cmpun (type, type); \
47 extern int __aeabi_ ## code ## 2iz (type); \
48 extern unsigned int __aeabi_ ## code ## 2uiz (type); \
49 extern long long __aeabi_ ## code ## 2lz (type); \
50 extern unsigned long long __aeabi_ ## code ## 2ulz (type); \
51 extern type __aeabi_i2 ## code (int); \
52 extern type __aeabi_ui2 ## code (int); \
53 extern type __aeabi_l2 ## code (long long); \
54 extern type __aeabi_ul2 ## code (unsigned long long); \
56 type code ## zero = 0.0; \
57 type code ## one = 1.0; \
58 type code ## two = 2.0; \
59 type code ## four = 4.0; \
60 type code ## minus_one = -1.0; \
61 type code ## minus_two = -2.0; \
62 type code ## minus_four = -4.0; \
63 type code ## epsilon = 1E-32; \
64 type code ## NaN = 0.0 / 0.0;
66 decl_float (d, double)
67 decl_float (f, float)
69 extern float __aeabi_d2f (double);
70 extern double __aeabi_f2d (float);
71 extern long long __aeabi_lmul (long long, long long);
72 extern long long __aeabi_llsl (long long, int);
73 extern long long __aeabi_llsr (long long, int);
74 extern long long __aeabi_lasr (long long, int);
75 extern int __aeabi_lcmp (long long, long long);
76 extern int __aeabi_ulcmp (unsigned long long, unsigned long long);
78 #define eq(a, b, type, abs, epsilon, format) \
79 { \
80 type a1; \
81 type b1; \
83 fprintf (stderr, "%d: Test %s == %s\n", __LINE__, #a, #b); \
84 a1 = a; \
85 b1 = b; \
86 if (abs (a1 - b1) > epsilon) \
87 { \
88 fprintf (stderr, "%d: " format " != " format "\n", \
89 __LINE__, a1, b1); \
90 abort (); \
91 } \
94 #define ieq(a, b) eq (a, b, int, abs, 0, "%d")
95 #define ueq(a, b) eq (a, b, unsigned int, abs, 0, "%u")
96 #define leq(a, b) eq (a, b, long long, abs, 0, "%lld")
97 #define uleq(a, b) eq (a, b, unsigned long long, abs, 0, "%llu")
98 #define feq(a, b) eq (a, b, float, fabs, fepsilon, "%f")
99 #define deq(a, b) eq (a, b, double, fabs, depsilon, "%g")
101 int main () {
102 /* Table 2. Double-precision floating-point arithmetic. */
103 deq (__aeabi_dadd (dzero, done), done);
104 deq (__aeabi_dadd (done, done), dtwo);
105 deq (__aeabi_ddiv (dminus_four, dminus_two), dtwo);
106 deq (__aeabi_ddiv (dminus_two, dtwo), dminus_one);
107 deq (__aeabi_dmul (dtwo, dtwo), dfour);
108 deq (__aeabi_dmul (dminus_one, dminus_two), dtwo);
109 deq (__aeabi_dneg (dminus_one), done);
110 deq (__aeabi_dneg (dfour), dminus_four);
111 deq (__aeabi_drsub (done, dzero), dminus_one);
112 deq (__aeabi_drsub (dtwo, dminus_two), dminus_four);
113 deq (__aeabi_dsub (dzero, done), dminus_one);
114 deq (__aeabi_dsub (dminus_two, dtwo), dminus_four);
116 /* Table 3. Double-precision floating-point comparisons. */
117 ieq (__aeabi_dcmpeq (done, done), 1);
118 ieq (__aeabi_dcmpeq (done, dzero), 0);
119 ieq (__aeabi_dcmpeq (dNaN, dzero), 0);
120 ieq (__aeabi_dcmpeq (dNaN, dNaN), 0);
122 ieq (__aeabi_dcmplt (dzero, done), 1);
123 ieq (__aeabi_dcmplt (done, dzero), 0);
124 ieq (__aeabi_dcmplt (dzero, dzero), 0);
125 ieq (__aeabi_dcmplt (dzero, dNaN), 0);
126 ieq (__aeabi_dcmplt (dNaN, dNaN), 0);
128 ieq (__aeabi_dcmple (dzero, done), 1);
129 ieq (__aeabi_dcmple (done, dzero), 0);
130 ieq (__aeabi_dcmple (dzero, dzero), 1);
131 ieq (__aeabi_dcmple (dzero, dNaN), 0);
132 ieq (__aeabi_dcmple (dNaN, dNaN), 0);
134 ieq (__aeabi_dcmpge (dzero, done), 0);
135 ieq (__aeabi_dcmpge (done, dzero), 1);
136 ieq (__aeabi_dcmpge (dzero, dzero), 1);
137 ieq (__aeabi_dcmpge (dzero, dNaN), 0);
138 ieq (__aeabi_dcmpge (dNaN, dNaN), 0);
140 ieq (__aeabi_dcmpgt (dzero, done), 0);
141 ieq (__aeabi_dcmpgt (done, dzero), 1);
142 ieq (__aeabi_dcmplt (dzero, dzero), 0);
143 ieq (__aeabi_dcmpgt (dzero, dNaN), 0);
144 ieq (__aeabi_dcmpgt (dNaN, dNaN), 0);
146 ieq (__aeabi_dcmpun (done, done), 0);
147 ieq (__aeabi_dcmpun (done, dzero), 0);
148 ieq (__aeabi_dcmpun (dNaN, dzero), 1);
149 ieq (__aeabi_dcmpun (dNaN, dNaN), 1);
151 /* Table 4. Single-precision floating-point arithmetic. */
152 feq (__aeabi_fadd (fzero, fone), fone);
153 feq (__aeabi_fadd (fone, fone), ftwo);
154 feq (__aeabi_fdiv (fminus_four, fminus_two), ftwo);
155 feq (__aeabi_fdiv (fminus_two, ftwo), fminus_one);
156 feq (__aeabi_fmul (ftwo, ftwo), ffour);
157 feq (__aeabi_fmul (fminus_one, fminus_two), ftwo);
158 feq (__aeabi_fneg (fminus_one), fone);
159 feq (__aeabi_fneg (ffour), fminus_four);
160 feq (__aeabi_frsub (fone, fzero), fminus_one);
161 feq (__aeabi_frsub (ftwo, fminus_two), fminus_four);
162 feq (__aeabi_fsub (fzero, fone), fminus_one);
163 feq (__aeabi_fsub (fminus_two, ftwo), fminus_four);
165 /* Table 5. Single-precision floating-point comparisons. */
166 ieq (__aeabi_fcmpeq (fone, fone), 1);
167 ieq (__aeabi_fcmpeq (fone, fzero), 0);
168 ieq (__aeabi_fcmpeq (fNaN, fzero), 0);
169 ieq (__aeabi_fcmpeq (fNaN, fNaN), 0);
171 ieq (__aeabi_fcmplt (fzero, fone), 1);
172 ieq (__aeabi_fcmplt (fone, fzero), 0);
173 ieq (__aeabi_fcmplt (fzero, fzero), 0);
174 ieq (__aeabi_fcmplt (fzero, fNaN), 0);
175 ieq (__aeabi_fcmplt (fNaN, fNaN), 0);
177 ieq (__aeabi_fcmple (fzero, fone), 1);
178 ieq (__aeabi_fcmple (fone, fzero), 0);
179 ieq (__aeabi_fcmple (fzero, fzero), 1);
180 ieq (__aeabi_fcmple (fzero, fNaN), 0);
181 ieq (__aeabi_fcmple (fNaN, fNaN), 0);
183 ieq (__aeabi_fcmpge (fzero, fone), 0);
184 ieq (__aeabi_fcmpge (fone, fzero), 1);
185 ieq (__aeabi_fcmpge (fzero, fzero), 1);
186 ieq (__aeabi_fcmpge (fzero, fNaN), 0);
187 ieq (__aeabi_fcmpge (fNaN, fNaN), 0);
189 ieq (__aeabi_fcmpgt (fzero, fone), 0);
190 ieq (__aeabi_fcmpgt (fone, fzero), 1);
191 ieq (__aeabi_fcmplt (fzero, fzero), 0);
192 ieq (__aeabi_fcmpgt (fzero, fNaN), 0);
193 ieq (__aeabi_fcmpgt (fNaN, fNaN), 0);
195 ieq (__aeabi_fcmpun (fone, fone), 0);
196 ieq (__aeabi_fcmpun (fone, fzero), 0);
197 ieq (__aeabi_fcmpun (fNaN, fzero), 1);
198 ieq (__aeabi_fcmpun (fNaN, fNaN), 1);
200 /* Table 6. Floating-point to integer conversions. */
201 ieq (__aeabi_d2iz (dminus_one), -1);
202 ueq (__aeabi_d2uiz (done), 1);
203 leq (__aeabi_d2lz (dminus_two), -2LL);
204 uleq (__aeabi_d2ulz (dfour), 4LL);
205 ieq (__aeabi_f2iz (fminus_one), -1);
206 ueq (__aeabi_f2uiz (fone), 1);
207 leq (__aeabi_f2lz (fminus_two), -2LL);
208 uleq (__aeabi_f2ulz (ffour), 4LL);
210 /* Table 7. Conversions between floating types. */
211 feq (__aeabi_d2f (dtwo), ftwo);
212 deq (__aeabi_f2d (fminus_four), dminus_four);
214 /* Table 8. Integer to floating-point conversions. */
215 deq (__aeabi_i2d (-1), dminus_one);
216 deq (__aeabi_ui2d (2), dtwo);
217 deq (__aeabi_l2d (-1), dminus_one);
218 deq (__aeabi_ul2d (2ULL), dtwo);
219 feq (__aeabi_i2f (-1), fminus_one);
220 feq (__aeabi_ui2f (2), ftwo);
221 feq (__aeabi_l2f (-1), fminus_one);
222 feq (__aeabi_ul2f (2ULL), ftwo);
224 /* Table 9. Long long functions. */
225 leq (__aeabi_lmul (4LL, -1LL), -4LL);
226 leq (__aeabi_llsl (2LL, 1), 4LL);
227 leq (__aeabi_llsr (-1LL, 63), 1);
228 leq (__aeabi_lasr (-1LL, 63), -1);
229 ieq (__aeabi_lcmp (0LL, 1LL), -1);
230 ieq (__aeabi_lcmp (0LL, 0LL), 0);
231 ieq (__aeabi_lcmp (1LL, 0LL), 1);
232 ieq (__aeabi_ulcmp (0LL, 1LL), -1);
233 ieq (__aeabi_ulcmp (0LL, 0LL), 0);
234 ieq (__aeabi_ulcmp (1LL, 0LL), 1);