FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / s390x / vec2_float.c
blob950db1a163d457c07a04cbefb07fb28c08689e87
1 #include <stdio.h>
3 typedef unsigned char __attribute__((vector_size(16))) charvec;
5 #define TO_CHARVEC(val) \
6 ({ \
7 union { \
8 typeof(val) x; \
9 charvec v; \
10 } vec_pun = {val}; \
11 vec_pun.v; \
14 #define FROM_CHARVEC(type, vec) \
15 ({ \
16 union { \
17 charvec v; \
18 type x; \
19 } vec_pun = {vec}; \
20 vec_pun.x; \
23 typedef struct {
24 unsigned int x[4];
25 } u2_v;
27 typedef struct {
28 unsigned long x[2];
29 } u3_v;
31 typedef struct {
32 unsigned long x[2]; /* avoid 128-bit integers */
33 } u4_v;
35 typedef struct {
36 float x[4];
37 } f2_v;
39 typedef struct {
40 double x[2];
41 } f3_v;
43 typedef struct {
44 long double x[1];
45 } f4_v;
47 #define INF (1./0.)
48 #define NAN (0./0.)
50 static const u2_v vec_u2_a = {{-1, 0x7ffffff0, 42, 0}};
51 static const u2_v vec_u2_b = {{0x7fffff80, 1, 1000, -0x7caffe}};
52 static const u2_v vec_u2_c = {{0x7fffff, 0x70000000, -10000, 0xffff}};
53 static const u2_v vec_u2_e = {{0x7fffffff, 0x8000000, 0, 42}};
55 static const f2_v vec_f2_a = {{16777215., -16777215., 42.5, 10000.}};
56 static const f2_v vec_f2_b = {{4., 3., 42.5, 1.}};
57 static const f2_v vec_f2_c = {{0., INF, -0., -INF}};
58 static const f2_v vec_f2_d = {{-16777214., 16777214., -23., -9999.}};
59 static const f2_v vec_f2_e = {{NAN, -NAN, NAN, -NAN}};
61 static const f3_v vec_f3_a = {{(double)((1UL << 52) - 1), -16777215.}};
62 static const f3_v vec_f3_b = {{0.1, 3.}};
63 static const f3_v vec_f3_c = {{-0., INF}};
64 static const f3_v vec_f3_e = {{NAN, -NAN}};
66 static const f4_v vec_f4_a = {{16777215.0L}};
67 static const f4_v vec_f4_b = {{4.0L}};
68 static const f4_v vec_f4_c = {{INF}};
69 static const f4_v vec_f4_d = {{-23.0}};
70 static const f4_v vec_f4_e = {{NAN}};
72 static const u3_v vec_ini = {{0x0112233445566778, 0x899aabbccddeeff0}};
74 /* -- Dump a vector depending on FP format and single-element control -- */
76 static void dump_cc(int cc)
78 if (cc) {
79 printf(" cc=%d", cc);
81 putchar('\n');
84 static void dump_vu2(charvec v)
86 u2_v u = FROM_CHARVEC(u2_v, v);
87 printf("\t%d | %d | %d | %d", u.x[0], u.x[1], u.x[2], u.x[3]);
90 static void dump_wu2(charvec v)
92 u2_v u = FROM_CHARVEC(u2_v, v);
93 printf("\t%d | - | - | -", u.x[0]);
96 static void dump_wu4(charvec v)
98 u4_v u = FROM_CHARVEC(u4_v, v);
99 if (u.x[0] == 0) {
100 printf("\t%ld", u.x[1]);
101 } else if (u.x[0] == -1UL) {
102 printf("\t-%ld", -u.x[1]);
103 } else {
104 printf("\t0x%016lx%016lx", u.x[0], u.x[1]);
108 static void dump_vf2(charvec v)
110 f2_v u = FROM_CHARVEC(f2_v, v);
111 printf("\t%a | %a | %a | %a", u.x[0], u.x[1], u.x[2], u.x[3]);
114 static void dump_ef2(charvec v)
116 f2_v u = FROM_CHARVEC(f2_v, v);
117 printf("\t%a | - | %a | -", u.x[0], u.x[2]);
120 static void dump_vf3(charvec v)
122 f3_v u = FROM_CHARVEC(f3_v, v);
123 printf("\t%a | %a", u.x[0], u.x[1]);
126 static void dump_wf3(charvec v)
128 f3_v u = FROM_CHARVEC(f3_v, v);
129 printf("\t%a | -", u.x[0]);
132 static void dump_wf2(charvec v)
134 f2_v u = FROM_CHARVEC(f2_v, v);
135 printf("\t%a | - | - | -", u.x[0]);
138 static void dump_wf4(charvec v)
140 f4_v u = FROM_CHARVEC(f4_v, v);
141 printf("\t%La", u.x[0]);
144 /* -- Vector unary operators -- */
146 #define TEST_EXEC(opc1,opc2,fmt,ty1,ty2,insn,m3,m4,m5) \
147 do { \
148 puts(#insn); \
149 test_##insn##_##m3##_##m4##_##m5(vec_##ty2##_a); \
150 test_##insn##_##m3##_##m4##_##m5(vec_##ty2##_b); \
151 test_##insn##_##m3##_##m4##_##m5(vec_##ty2##_c); \
152 test_##insn##_##m3##_##m4##_##m5(vec_##ty2##_e); \
153 } while (0)
155 #define TEST_GENERATE(opc1, opc2, fmt, ty1, ty2, insn, m3, m4, m5) \
156 static void test_##insn##_##m3##_##m4##_##m5(ty2##_v a) \
158 charvec out = TO_CHARVEC(vec_ini); \
159 int cc = -1; \
160 __asm__("cr 0,0\n\t" \
161 ".insn vrr,0x" #opc1 "00000000" #opc2 ",%[out],%[a],0," #m3 \
162 "," #m4 "," #m5 "\n\t" \
163 "ipm %[cc]\n\t" \
164 "srl %[cc],28" \
165 : [cc] "=d"(cc), [out] "+v"(out) \
166 : [a] "v"(TO_CHARVEC(a)) \
167 : "cc"); \
168 dump_##fmt##ty1(out); \
169 dump_cc(cc); \
172 #define INSNS \
173 XTEST(e7,c0, v,u2, f2, vclfeb, 2,4,0); \
174 XTEST(e7,c0, w,u2, f2, wclfeb, 2,12,0); \
175 XTEST(e7,c1, v,f2, u2, vcelfb, 2,4,0); \
176 XTEST(e7,c1, w,f2, u2, wcelfb, 2,12,0); \
177 XTEST(e7,c2, v,u2, f2, vcfeb, 2,4,0); \
178 XTEST(e7,c2, w,u2, f2, wcfeb, 2,12,0); \
179 XTEST(e7,c3, v,f2, u2, vcefb, 2,4,0); \
180 XTEST(e7,c3, w,f2, u2, wcefb, 2,12,0); \
181 XTEST(e7,c4, v,f3, f2, vldeb, 2,0,0); \
182 XTEST(e7,c4, w,f3, f2, wldeb, 2,8,0); \
183 XTEST(e7,c4, w,f4, f3, wflld, 3,8,0); \
184 XTEST(e7,c5, e,f2, f3, vledb, 3,4,0); \
185 XTEST(e7,c5, w,f2, f3, wledb, 3,12,0); \
186 XTEST(e7,c5, w,f3, f4, wflrx, 4,12,0); \
187 XTEST(e7,c7, v,f2, f2, vfisb, 2,0,0); \
188 XTEST(e7,c7, w,f2, f2, wfisb, 2,8,0); \
189 XTEST(e7,c7, w,f4, f4, wfixb, 4,8,0); \
190 XTEST(e7,cc, v,f2, f2, vflcsb, 2,0,0); \
191 XTEST(e7,cc, w,f2, f2, wflcsb, 2,8,0); \
192 XTEST(e7,cc, w,f4, f4, wflcxb, 4,8,0); \
193 XTEST(e7,cc, v,f2, f2, vflnsb, 2,0,1); \
194 XTEST(e7,cc, w,f2, f2, wflnsb, 2,8,1); \
195 XTEST(e7,cc, w,f4, f4, wflnxb, 4,8,1); \
196 XTEST(e7,cc, v,f2, f2, vflpsb, 2,0,2); \
197 XTEST(e7,cc, w,f2, f2, wflpsb, 2,8,2); \
198 XTEST(e7,cc, w,f4, f4, wflpxb, 4,8,2); \
199 XTEST(e7,ce, v,f2, f2, vfsqsb, 2,0,0); \
200 XTEST(e7,ce, w,f2, f2, wfsqsb, 2,8,0); \
201 XTEST(e7,ce, w,f4, f4, wfsqxb, 4,8,0);
203 #define XTEST TEST_GENERATE
204 INSNS
205 #undef XTEST
207 static void test_all_unops()
209 #define XTEST TEST_EXEC
210 INSNS
211 #undef XTEST
214 #undef INSNS
215 #undef TEST_GENERATE
216 #undef TEST_EXEC
218 /* -- Vector binary operators -- */
220 #define TEST_EXEC(opc1,opc2,fmt,ty1,insn,m4,m5,m6) \
221 do { \
222 puts(#insn); \
223 test_##insn##_##m4##_##m5##_##m6(vec_f##m4##_a, vec_f##m4##_b); \
224 test_##insn##_##m4##_##m5##_##m6(vec_f##m4##_b, vec_f##m4##_a); \
225 test_##insn##_##m4##_##m5##_##m6(vec_f##m4##_a, vec_f##m4##_c); \
226 test_##insn##_##m4##_##m5##_##m6(vec_f##m4##_d, vec_f##m4##_e); \
227 } while (0)
229 #define TEST_GENERATE(opc1, opc2, fmt, ty1, insn, m4, m5, m6) \
230 static void test_##insn##_##m4##_##m5##_##m6(f##m4##_v a, f##m4##_v b) \
232 charvec out = TO_CHARVEC(vec_ini); \
233 int cc = -1; \
234 __asm__("cr 0,0\n\t" \
235 ".insn vrr,0x" #opc1 "00000000" #opc2 ",%[out],%[a],%[b]," #m4 \
236 "," #m5 "," #m6 "\n\t" \
237 "ipm %[cc]\n\t" \
238 "srl %[cc],28" \
239 : [cc] "=d"(cc), [out] "+v"(out) \
240 : [a] "v"(TO_CHARVEC(a)), [b] "v"(TO_CHARVEC(b)) \
241 : "cc"); \
242 dump_##fmt##ty1(out); \
243 dump_cc(cc); \
246 #define INSNS \
247 XTEST(e7,e2, v,f2, vfssb, 2,0,0); \
248 XTEST(e7,e2, w,f2, wfssb, 2,8,0); \
249 XTEST(e7,e2, w,f4, wfsxb, 4,8,0); \
250 XTEST(e7,e3, v,f2, vfasb, 2,0,0); \
251 XTEST(e7,e3, w,f2, wfasb, 2,8,0); \
252 XTEST(e7,e3, w,f4, wfaxb, 4,8,0); \
253 XTEST(e7,e5, v,f2, vfdsb, 2,0,0); \
254 XTEST(e7,e5, w,f2, wfdsb, 2,8,0); \
255 XTEST(e7,e5, w,f4, wfdxb, 4,8,0); \
256 XTEST(e7,e7, v,f2, vfmsb, 2,0,0); \
257 XTEST(e7,e7, w,f2, wfmsb, 2,8,0); \
258 XTEST(e7,e7, w,f4, wfmxb, 4,8,0); \
259 XTEST(e7,e8, v,u2, vfcesb, 2,0,0); \
260 XTEST(e7,e8, w,u2, wfcesb, 2,8,0); \
261 XTEST(e7,e8, w,u4, wfcexb, 4,8,0); \
262 XTEST(e7,e8, v,u2, vfcesbs, 2,0,1); \
263 XTEST(e7,e8, w,u2, wfcesbs, 2,8,1); \
264 XTEST(e7,e8, w,u4, wfcexbs, 4,8,1); \
265 XTEST(e7,ea, v,u2, vfchesb, 2,0,0); \
266 XTEST(e7,ea, w,u2, wfchesb, 2,8,0); \
267 XTEST(e7,ea, w,u4, wfchexb, 4,8,0); \
268 XTEST(e7,ea, v,u2, vfchesbs, 2,0,1); \
269 XTEST(e7,ea, w,u2, wfchesbs, 2,8,1); \
270 XTEST(e7,ea, w,u4, wfchexbs, 4,8,1); \
271 XTEST(e7,ee, v,f2, vfminsb, 2,0,0); \
272 XTEST(e7,ee, w,f2, wfminsb, 2,8,0); \
273 XTEST(e7,ee, w,f4, wfminxb, 4,8,0); \
274 XTEST(e7,ef, v,f2, vfmaxsb, 2,0,0); \
275 XTEST(e7,ef, w,f2, wfmaxsb, 2,8,0); \
276 XTEST(e7,ef, w,f4, wfmaxxb, 4,8,0); \
277 XTEST(e7,eb, v,u2, vfchsb, 2,0,0); \
278 XTEST(e7,eb, w,u2, wfchsb, 2,8,0); \
279 XTEST(e7,eb, w,u4, wfchxb, 4,8,0); \
280 XTEST(e7,eb, v,u2, vfchsbs, 2,0,1); \
281 XTEST(e7,eb, w,u2, wfchsbs, 2,8,1); \
282 XTEST(e7,eb, w,u4, wfchxbs, 4,8,1);
284 #define XTEST TEST_GENERATE
285 INSNS
286 #undef XTEST
288 static void test_all_binops()
290 #define XTEST TEST_EXEC
291 INSNS
292 #undef XTEST
295 #undef INSNS
296 #undef TEST_GENERATE
297 #undef TEST_EXEC
299 /* -- Vector ternary operators -- */
301 #define TEST_EXEC(opc1,opc2,fmt,ty,insn,m5,m6) \
302 do { \
303 puts(#insn); \
304 test_##insn##_##m5##_##m6(vec_##ty##_a, vec_##ty##_b, vec_##ty##_c); \
305 test_##insn##_##m5##_##m6(vec_##ty##_b, vec_##ty##_a, vec_##ty##_d); \
306 } while (0)
308 #define TEST_GENERATE(opc1, opc2, fmt, ty, insn, m5, m6) \
309 static void test_##insn##_##m5##_##m6(ty##_v a, ty##_v b, ty##_v c) \
311 charvec out = TO_CHARVEC(vec_ini); \
312 int cc = -1; \
313 register charvec my_b __asm__("v6") = TO_CHARVEC(b); \
314 register charvec my_c __asm__("v7") = TO_CHARVEC(c); \
315 __asm__("cr 0,0\n\t" \
316 ".insn vri,0x" #opc1 "00000000" #opc2 ",%[out],%[a],0x6" #m6 \
317 "0,7," #m5 "\n\t" \
318 "ipm %[cc]\n\t" \
319 "srl %[cc],28" \
320 : [cc] "=d"(cc), [out] "+v"(out) \
321 : [a] "v"(TO_CHARVEC(a)), [b] "v"(my_b), [c] "v"(my_c) \
322 : "cc"); \
323 dump_##fmt##ty(out); \
324 dump_cc(cc); \
327 #define INSNS \
328 XTEST(e7,8e, v,f2, vfmssb, 0,2); \
329 XTEST(e7,8e, w,f2, wfmssb, 8,2); \
330 XTEST(e7,8e, w,f4, wfmsxb, 8,4); \
331 XTEST(e7,8f, v,f2, vfmasb, 0,2); \
332 XTEST(e7,8f, w,f2, wfmasb, 8,2); \
333 XTEST(e7,8f, w,f4, wfmaxb, 8,4); \
334 XTEST(e7,9e, v,f2, vfnmssb, 0,2); \
335 XTEST(e7,9e, w,f2, wfnmssb, 8,2); \
336 XTEST(e7,9e, w,f4, wfnmsxb, 8,4); \
337 XTEST(e7,9f, v,f2, vfnmasb, 0,2); \
338 XTEST(e7,9f, w,f2, wfnmasb, 8,2); \
339 XTEST(e7,9f, w,f4, wfnmaxb, 8,4);
341 #define XTEST TEST_GENERATE
342 INSNS
343 #undef XTEST
345 static void test_all_ternops()
347 #define XTEST TEST_EXEC
348 INSNS
349 #undef XTEST
352 #undef INSNS
353 #undef TEST_GENERATE
354 #undef TEST_EXEC
356 /* -- Vector scalar compare operators -- */
358 #define TEST_EXEC(opc1,opc2,ty,insn,m3,m4) \
359 do { \
360 puts(#insn); \
361 test_##insn##_##m3##_##m4(vec_##ty##_a, vec_##ty##_b); \
362 test_##insn##_##m3##_##m4(vec_##ty##_b, vec_##ty##_a); \
363 test_##insn##_##m3##_##m4(vec_##ty##_c, vec_##ty##_c); \
364 test_##insn##_##m3##_##m4(vec_##ty##_a, vec_##ty##_e); \
365 } while (0)
367 #define TEST_GENERATE(opc1, opc2, ty, insn, m3, m4) \
368 static void test_##insn##_##m3##_##m4(ty##_v a, ty##_v b) \
370 int cc = -1; \
371 __asm__("cr 0,0\n\t" \
372 ".insn vrr,0x" #opc1 "00000000" #opc2 ",%[a],%[b],0," #m3 \
373 "," #m4 ",0\n\t" \
374 "ipm %[cc]\n\t" \
375 "srl %[cc],28" \
376 : [cc] "=d"(cc) \
377 : [a] "v"(TO_CHARVEC(a)), [b] "v"(TO_CHARVEC(b)) \
378 : "cc"); \
379 printf("\tcc=%d\n", cc); \
382 #define INSNS \
383 XTEST(e7,cb, f2, wfcsb, 2,0); \
384 XTEST(e7,cb, f4, wfcxb, 4,0);
386 #define XTEST TEST_GENERATE
387 INSNS
388 #undef XTEST
390 static void test_all_scalar_compares()
392 #define XTEST TEST_EXEC
393 INSNS
394 #undef XTEST
397 #undef INSNS
398 #undef TEST_GENERATE
399 #undef TEST_EXEC
401 /* -- Vector FP test data class -- */
403 #define TEST_EXEC(opc1,opc2,fmt,ty1,ty2,insn,i3,m4,m5) \
404 do { \
405 puts(#insn); \
406 test_##insn##_##m3##_##m4(vec_##ty2##_a); \
407 test_##insn##_##m3##_##m4(vec_##ty2##_b); \
408 test_##insn##_##m3##_##m4(vec_##ty2##_c); \
409 test_##insn##_##m3##_##m4(vec_##ty2##_d); \
410 test_##insn##_##m3##_##m4(vec_##ty2##_e); \
411 } while (0)
413 #define TEST_GENERATE(opc1, opc2, fmt, ty1, ty2, insn, i3, m4, m5) \
414 static void test_##insn##_##m3##_##m4(ty2##_v a) \
416 charvec out = TO_CHARVEC(vec_ini); \
417 int cc = -1; \
418 __asm__("cr 0,0\n\t" \
419 ".insn vri,0x" #opc1 "00000000" #opc2 ",%[out],%[a]," #i3 \
420 "," #m4 "," #m5 "\n\t" \
421 "ipm %[cc]\n\t" \
422 "srl %[cc],28" \
423 : [cc] "=d"(cc), [out] "+v"(out) \
424 : [a] "v"(TO_CHARVEC(a)) \
425 : "cc"); \
426 dump_##fmt##ty1(out); \
427 dump_cc(cc); \
430 #define INSNS \
431 XTEST(e7,4a, v,u2,f2, vftcisb, 0x864,2,0); \
432 XTEST(e7,4a, w,u2,f2, wftcisb, 0x520,2,8); \
433 XTEST(e7,4a, w,u4,f4, wftcixb, 0x3c0,4,0);
435 #define XTEST TEST_GENERATE
436 INSNS
437 #undef XTEST
439 static void test_all_vftci()
441 #define XTEST TEST_EXEC
442 INSNS
443 #undef XTEST
446 #undef INSNS
447 #undef TEST_GENERATE
448 #undef TEST_EXEC
451 int main()
453 test_all_unops();
454 test_all_binops();
455 test_all_ternops();
456 test_all_scalar_compares();
457 test_all_vftci();
458 return 0;