FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / s390x / misc3.c
blobeeeea1163c293ec5b59d95f201b1137fa1d4903d
1 #include <stdio.h>
3 /* -- Logical instructions -- */
5 #define TEST_GENERATE(opcode,insn) \
6 static void test_##insn(unsigned long a, unsigned long b) \
7 { \
8 unsigned long out = 0xdecaffee42424242; \
9 int cc; \
11 __asm__( \
12 "cr 0,0\n\t" /* Clear CC */ \
13 ".insn rrf,0x" #opcode "0000,%[out],%[a],%[b],0\n\t" \
14 "ipm %[cc]\n\t" \
15 "srl %[cc],28\n" \
16 : [out] "+d" (out), \
17 [cc] "=d" (cc) \
18 : [a] "d" (a), \
19 [b] "d" (b) \
20 : "cc"); \
22 printf("\t%016lx %016lx -> %016lx cc=%d\n", \
23 a, b, out, cc); \
26 #define TEST_EXEC(opcode,insn) \
27 do { \
28 puts(#insn); \
29 test_##insn(0, 0); \
30 test_##insn(0, -1); \
31 test_##insn(-1, 0); \
32 test_##insn(-1, -1); \
33 test_##insn(0x012345678abcdef, 0); \
34 test_##insn(0x012345678abcdef, -1); \
35 test_##insn(0x55555555aaaaaaaa, 0xaaaaaaaa55555555); \
36 } while (0)
38 #define INSNS \
39 XTEST(b9f5,ncrk); \
40 XTEST(b9e5,ncgrk); \
41 XTEST(b974,nnrk); \
42 XTEST(b964,nngrk); \
43 XTEST(b976,nork); \
44 XTEST(b966,nogrk); \
45 XTEST(b977,nxrk); \
46 XTEST(b967,nxgrk); \
47 XTEST(b975,ocrk); \
48 XTEST(b965,ocgrk);
50 #define XTEST TEST_GENERATE
51 INSNS
52 #undef XTEST
54 static void test_all_logical_insns()
56 #define XTEST TEST_EXEC
57 INSNS
58 #undef XTEST
60 #undef INSNS
61 #undef TEST_GENERATE
62 #undef TEST_EXEC
65 /* -- Full population count -- */
67 static void test_popcnt(unsigned long op2)
69 unsigned long result;
70 int cc;
72 __asm__(".insn rrf,0xb9e10000,%[result],%[op2],8,0\n\t"
73 "ipm %[cc]\n\t"
74 "srl %[cc],28\n"
75 : [result]"=d" (result),
76 [cc]"=d" (cc)
77 : [op2]"d" (op2)
78 : "cc");
79 printf("\t%016lx -> %2lu cc=%d\n", op2, result, cc);
82 static int test_all_popcnt()
84 puts("popcnt");
85 test_popcnt(0);
86 test_popcnt(1);
87 test_popcnt(0x8000000000000000);
88 test_popcnt(-1UL);
89 test_popcnt(0xff427e3800556bcd);
90 return 0;
93 /* -- Select -- */
95 #define TEST_GENERATE(opcode,insn) \
96 static void test_##insn(unsigned long a, unsigned long b) \
97 { \
98 unsigned long out0 = 0x0cafebad0badcafe; \
99 unsigned long out1 = 0x0badcafe0cafebad; \
101 __asm__( \
102 "cr 0,0\n\t" /* Clear CC */ \
103 ".insn rrf,0x" #opcode "0000,%[out0],%[a],%[b],8\n\t" \
104 ".insn rrf,0x" #opcode "0000,%[out1],%[a],%[b],7\n\t" \
105 : [out0] "+d" (out0), \
106 [out1] "+d" (out1) \
107 : [a] "d" (a), \
108 [b] "d" (b) \
109 : "cc"); \
111 printf("\t%016lx %016lx -> %016lx %016lx\n", \
112 a, b, out0, out1); \
115 #define TEST_EXEC(opcode,insn) \
116 do { \
117 puts(#insn); \
118 test_##insn(-1, 0); \
119 test_##insn(0, -1); \
120 test_##insn(0x1234567890abcdef, 0xfedcba9876543210); \
121 } while (0)
123 #define INSNS \
124 XTEST(b9f0,selr); \
125 XTEST(b9e3,selgr); \
126 XTEST(b9c0,selfhr);
128 #define XTEST TEST_GENERATE
129 INSNS
130 #undef XTEST
132 static void test_all_select()
134 #define XTEST TEST_EXEC
135 INSNS
136 #undef XTEST
138 #undef INSNS
139 #undef TEST_GENERATE
140 #undef TEST_EXEC
143 /* -- Move right to left -- */
145 static void test_mvcrl(char *to, char *from, size_t len)
147 len -= 1;
148 __asm__("lgr 0,%[len]\n\t"
149 ".insn sse,0xe50a00000000,%[to],%[from]\n\t"
150 : [to] "+Q" (*(char (*)[len]) to)
151 : [from] "Q" (*(char (*)[len]) from),
152 [len] "d" (len)
153 : );
156 static void test_all_mvcrl()
158 static const char pattern[] =
159 "abcdefghijklmnopqrstuvwxyz-0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZ";
160 char buf[4 * sizeof(pattern) - 2];
162 test_mvcrl(buf, (char *) pattern, sizeof(pattern));
163 test_mvcrl(buf + sizeof(pattern) - 1, buf, sizeof(pattern));
164 test_mvcrl(buf + 2 * sizeof(pattern) - 2, buf, 2 * sizeof(pattern) - 1);
165 test_mvcrl(buf + 32, buf + 10, 63);
166 test_mvcrl(buf + 2, buf + 1, 256);
167 test_mvcrl(buf + 254, buf + 256, 2);
168 puts("mvcrl");
169 for (int i = 0; i < 256; i += 64) {
170 printf("\t%.64s\n", buf + i);
175 int main()
177 test_all_logical_insns();
178 test_all_popcnt();
179 test_all_select();
180 test_all_mvcrl();
181 return 0;