Implement C _FloatN, _FloatNx types.
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / vec-cvt-1.c
blob78a9009560524cddae70c270957b01b5c5f8aa49
1 /* { dg-do run } */
2 /* This test is too big for small targets. */
3 /* { dg-require-effective-target size32plus } */
5 #include <stdlib.h>
7 #define N 1024
8 signed char sc[N];
9 short ss[N];
10 int si[N];
11 long long sl[N];
12 unsigned char uc[N];
13 unsigned short us[N];
14 unsigned int ui[N];
15 unsigned long long ul[N];
16 float f[N];
17 double d[N];
19 #define FN1(from, to) \
20 __attribute__((noinline, noclone)) void \
21 from##2##to (void) \
22 { \
23 int i; \
24 for (i = 0; i < N; i++) \
25 to[i] = from[i]; \
27 #define FN(intt, fltt) FN1 (intt, fltt) FN1 (fltt, intt)
29 FN (sc, f)
30 FN (ss, f)
31 FN (si, f)
32 FN (sl, f)
33 FN (uc, f)
34 FN (us, f)
35 FN (ui, f)
36 FN (ul, f)
37 FN (sc, d)
38 FN (ss, d)
39 FN (si, d)
40 FN (sl, d)
41 FN (uc, d)
42 FN (us, d)
43 FN (ui, d)
44 FN (ul, d)
46 #define FLTTEST(min, max, intt) \
47 __attribute__((noinline, noclone)) void \
48 flttointtest##intt (void) \
49 { \
50 int i; \
51 volatile float fltmin, fltmax, vf, vf2; \
52 volatile double dblmin, dblmax, vd, vd2; \
53 if (min == 0) \
54 fltmin = 0.0f; \
55 else \
56 { \
57 vf2 = fltmin = min - 1.0f; \
58 for (vf = 1.0f; (fltmin = vf2 + vf) == vf2; vf = vf * 2.0f) \
59 ; \
60 } \
61 vf2 = fltmax = max + 1.0f; \
62 for (vf = 1.0f; (fltmax = vf2 - vf) == vf2; vf = vf * 2.0f) \
63 ; \
64 if (min == 0) \
65 dblmin = 0.0; \
66 else \
67 { \
68 vd2 = dblmin = min - 1.0; \
69 for (vd = 1.0; (dblmin = vd2 + vd) == vd2; vd = vd * 2.0) \
70 ; \
71 } \
72 vd2 = dblmax = max + 1.0; \
73 for (vd = 1.0; (dblmax = vd2 - vd) == vd2; vd = vd * 2.0) \
74 ; \
75 for (i = 0; i < N; i++) \
76 { \
77 asm (""); \
78 if (i == 0) \
79 f[i] = fltmin; \
80 else if (i < N / 4) \
81 f[i] = fltmin + i + 0.25f; \
82 else if (i < 3 * N / 4) \
83 f[i] = (fltmax + fltmin) / 2.0 - N * 8 + 16.0f * i; \
84 else \
85 f[i] = fltmax - N + 1 + i; \
86 if (f[i] < fltmin) f[i] = fltmin; \
87 if (f[i] > fltmax) f[i] = fltmax; \
88 if (i == 0) \
89 d[i] = dblmin; \
90 else if (i < N / 4) \
91 d[i] = dblmin + i + 0.25f; \
92 else if (i < 3 * N / 4) \
93 d[i] = (dblmax + dblmin) / 2.0 - N * 8 + 16.0f * i; \
94 else \
95 d[i] = dblmax - N + 1 + i; \
96 if (d[i] < dblmin) d[i] = dblmin; \
97 if (d[i] > dblmax) d[i] = dblmax; \
98 } \
99 f2##intt (); \
100 for (i = 0; i < N; i++) \
101 if (intt[i] != (__typeof (intt[0])) f[i]) \
102 abort (); \
103 d2##intt (); \
104 for (i = 0; i < N; i++) \
105 if (intt[i] != (__typeof (intt[0])) d[i]) \
106 abort (); \
107 for (i = 0; i < N; i++) \
109 unsigned long long r = rand (); \
110 r = (r << 21) ^ (unsigned) rand (); \
111 r = (r << 21) ^ (unsigned) rand (); \
112 asm (""); \
113 f[i] = (r >> 59) / 32.0f + (__typeof (intt[0])) r; \
114 if (f[i] < fltmin) f[i] = fltmin; \
115 if (f[i] > fltmax) f[i] = fltmax; \
116 d[i] = (r >> 59) / 32.0 + (__typeof (intt[0])) r; \
117 if (d[i] < dblmin) f[i] = dblmin; \
118 if (d[i] > dblmax) f[i] = dblmax; \
120 f2##intt (); \
121 for (i = 0; i < N; i++) \
122 if (intt[i] != (__typeof (intt[0])) f[i]) \
123 abort (); \
124 d2##intt (); \
125 for (i = 0; i < N; i++) \
126 if (intt[i] != (__typeof (intt[0])) d[i]) \
127 abort (); \
130 __attribute__((noinline, noclone)) void \
131 inttoflttest##intt (void) \
133 int i; \
134 volatile float vf; \
135 volatile double vd; \
136 for (i = 0; i < N; i++) \
138 asm (""); \
139 if (i < N / 4) \
140 intt[i] = min + i; \
141 else if (i < 3 * N / 4) \
142 intt[i] = (max + min) / 2 - N * 8 + 16 * i; \
143 else \
144 intt[i] = max - N + 1 + i; \
146 intt##2f (); \
147 for (i = 0; i < N; i++) \
149 vf = intt[i]; \
150 if (f[i] != vf) \
151 abort (); \
153 intt##2d (); \
154 for (i = 0; i < N; i++) \
156 vd = intt[i]; \
157 if (d[i] != vd) \
158 abort (); \
160 for (i = 0; i < N; i++) \
162 unsigned long long r = rand (); \
163 r = (r << 21) ^ (unsigned) rand (); \
164 r = (r << 21) ^ (unsigned) rand (); \
165 asm (""); \
166 intt[i] = r; \
168 intt##2f (); \
169 for (i = 0; i < N; i++) \
171 vf = intt[i]; \
172 if (f[i] != vf) \
173 abort (); \
175 intt##2d (); \
176 for (i = 0; i < N; i++) \
178 vd = intt[i]; \
179 if (d[i] != vd) \
180 abort (); \
184 FLTTEST (- __SCHAR_MAX__ - 1, __SCHAR_MAX__, sc)
185 FLTTEST (- __SHRT_MAX__ - 1, __SHRT_MAX__, ss)
186 FLTTEST (- __INT_MAX__ - 1, __INT_MAX__, si)
187 FLTTEST (- __LONG_LONG_MAX__ - 1LL, __LONG_LONG_MAX__, sl)
188 FLTTEST (0, 2U * __SCHAR_MAX__ + 1, uc)
189 FLTTEST (0, 2U * __SHRT_MAX__ + 1, us)
190 FLTTEST (0, 2U * __INT_MAX__ + 1, ui)
191 FLTTEST (0, 2ULL * __LONG_LONG_MAX__ + 1, ul)
194 main ()
196 flttointtestsc ();
197 flttointtestss ();
198 flttointtestsi ();
199 flttointtestsl ();
200 flttointtestuc ();
201 flttointtestus ();
202 flttointtestui ();
203 flttointtestul ();
204 inttoflttestsc ();
205 inttoflttestss ();
206 inttoflttestsi ();
207 inttoflttestsl ();
208 inttoflttestuc ();
209 inttoflttestus ();
210 inttoflttestui ();
211 inttoflttestul ();
212 return 0;