Update libiberty demangler.
[valgrind.git] / auxprogs / ppc64shifts.c
blobcf8d571c3d734eacb90dbd4130005c365fffd3f9
2 #include <stdio.h>
4 typedef unsigned long long int ULong;
6 /* ------------------------ SRADI ------------------------ */
8 #define INSN_SRADI(nnn) \
9 void do_sradi_##nnn ( ULong arg, /*OUT*/ULong* res, /*OUT*/ULong* xer ) \
10 { \
11 ULong argW = arg; \
12 ULong resW = 0; \
13 ULong xerW = 0; \
14 __asm__ __volatile__( \
15 "sradi %0,%2, " #nnn "\n\t" \
16 "mfxer %1" \
17 : /*out*/ "=b"(resW), "=b"(xerW) \
18 : /*in*/ "b"(argW) \
19 : /*trash*/ "cc" \
20 ); \
21 *res = resW; \
22 *xer = xerW; \
25 INSN_SRADI(0)
26 INSN_SRADI(1)
27 INSN_SRADI(2)
28 INSN_SRADI(3)
29 INSN_SRADI(4)
30 INSN_SRADI(5)
31 INSN_SRADI(6)
32 INSN_SRADI(7)
33 INSN_SRADI(8)
34 INSN_SRADI(9)
35 INSN_SRADI(10)
36 INSN_SRADI(11)
37 INSN_SRADI(12)
38 INSN_SRADI(13)
39 INSN_SRADI(14)
40 INSN_SRADI(15)
41 INSN_SRADI(16)
42 INSN_SRADI(17)
43 INSN_SRADI(18)
44 INSN_SRADI(19)
45 INSN_SRADI(20)
46 INSN_SRADI(21)
47 INSN_SRADI(22)
48 INSN_SRADI(23)
49 INSN_SRADI(24)
50 INSN_SRADI(25)
51 INSN_SRADI(26)
52 INSN_SRADI(27)
53 INSN_SRADI(28)
54 INSN_SRADI(29)
55 INSN_SRADI(30)
56 INSN_SRADI(31)
57 INSN_SRADI(32)
58 INSN_SRADI(33)
59 INSN_SRADI(34)
60 INSN_SRADI(35)
61 INSN_SRADI(36)
62 INSN_SRADI(37)
63 INSN_SRADI(38)
64 INSN_SRADI(39)
65 INSN_SRADI(40)
66 INSN_SRADI(41)
67 INSN_SRADI(42)
68 INSN_SRADI(43)
69 INSN_SRADI(44)
70 INSN_SRADI(45)
71 INSN_SRADI(46)
72 INSN_SRADI(47)
73 INSN_SRADI(48)
74 INSN_SRADI(49)
75 INSN_SRADI(50)
76 INSN_SRADI(51)
77 INSN_SRADI(52)
78 INSN_SRADI(53)
79 INSN_SRADI(54)
80 INSN_SRADI(55)
81 INSN_SRADI(56)
82 INSN_SRADI(57)
83 INSN_SRADI(58)
84 INSN_SRADI(59)
85 INSN_SRADI(60)
86 INSN_SRADI(61)
87 INSN_SRADI(62)
88 INSN_SRADI(63)
90 static void* all_sradi[64]
91 = {
92 (void*)&do_sradi_0,
93 (void*)&do_sradi_1,
94 (void*)&do_sradi_2,
95 (void*)&do_sradi_3,
96 (void*)&do_sradi_4,
97 (void*)&do_sradi_5,
98 (void*)&do_sradi_6,
99 (void*)&do_sradi_7,
100 (void*)&do_sradi_8,
101 (void*)&do_sradi_9,
102 (void*)&do_sradi_10,
103 (void*)&do_sradi_11,
104 (void*)&do_sradi_12,
105 (void*)&do_sradi_13,
106 (void*)&do_sradi_14,
107 (void*)&do_sradi_15,
108 (void*)&do_sradi_16,
109 (void*)&do_sradi_17,
110 (void*)&do_sradi_18,
111 (void*)&do_sradi_19,
112 (void*)&do_sradi_20,
113 (void*)&do_sradi_21,
114 (void*)&do_sradi_22,
115 (void*)&do_sradi_23,
116 (void*)&do_sradi_24,
117 (void*)&do_sradi_25,
118 (void*)&do_sradi_26,
119 (void*)&do_sradi_27,
120 (void*)&do_sradi_28,
121 (void*)&do_sradi_29,
122 (void*)&do_sradi_30,
123 (void*)&do_sradi_31,
124 (void*)&do_sradi_32,
125 (void*)&do_sradi_33,
126 (void*)&do_sradi_34,
127 (void*)&do_sradi_35,
128 (void*)&do_sradi_36,
129 (void*)&do_sradi_37,
130 (void*)&do_sradi_38,
131 (void*)&do_sradi_39,
132 (void*)&do_sradi_40,
133 (void*)&do_sradi_41,
134 (void*)&do_sradi_42,
135 (void*)&do_sradi_43,
136 (void*)&do_sradi_44,
137 (void*)&do_sradi_45,
138 (void*)&do_sradi_46,
139 (void*)&do_sradi_47,
140 (void*)&do_sradi_48,
141 (void*)&do_sradi_49,
142 (void*)&do_sradi_50,
143 (void*)&do_sradi_51,
144 (void*)&do_sradi_52,
145 (void*)&do_sradi_53,
146 (void*)&do_sradi_54,
147 (void*)&do_sradi_55,
148 (void*)&do_sradi_56,
149 (void*)&do_sradi_57,
150 (void*)&do_sradi_58,
151 (void*)&do_sradi_59,
152 (void*)&do_sradi_60,
153 (void*)&do_sradi_61,
154 (void*)&do_sradi_62,
155 (void*)&do_sradi_63
158 /* ------------------------ SRAWI ------------------------ */
160 #define INSN_SRAWI(nnn) \
161 void do_srawi_##nnn ( ULong arg, /*OUT*/ULong* res, /*OUT*/ULong* xer ) \
163 ULong argW = arg; \
164 ULong resW = 0; \
165 ULong xerW = 0; \
166 __asm__ __volatile__( \
167 "srawi %0,%2, " #nnn "\n\t" \
168 "mfxer %1" \
169 : /*out*/ "=b"(resW), "=b"(xerW) \
170 : /*in*/ "b"(argW) \
171 : /*trash*/ "cc" \
172 ); \
173 *res = resW; \
174 *xer = xerW; \
177 INSN_SRAWI(0)
178 INSN_SRAWI(1)
179 INSN_SRAWI(2)
180 INSN_SRAWI(3)
181 INSN_SRAWI(4)
182 INSN_SRAWI(5)
183 INSN_SRAWI(6)
184 INSN_SRAWI(7)
185 INSN_SRAWI(8)
186 INSN_SRAWI(9)
187 INSN_SRAWI(10)
188 INSN_SRAWI(11)
189 INSN_SRAWI(12)
190 INSN_SRAWI(13)
191 INSN_SRAWI(14)
192 INSN_SRAWI(15)
193 INSN_SRAWI(16)
194 INSN_SRAWI(17)
195 INSN_SRAWI(18)
196 INSN_SRAWI(19)
197 INSN_SRAWI(20)
198 INSN_SRAWI(21)
199 INSN_SRAWI(22)
200 INSN_SRAWI(23)
201 INSN_SRAWI(24)
202 INSN_SRAWI(25)
203 INSN_SRAWI(26)
204 INSN_SRAWI(27)
205 INSN_SRAWI(28)
206 INSN_SRAWI(29)
207 INSN_SRAWI(30)
208 INSN_SRAWI(31)
210 static void* all_srawi[32]
212 (void*)&do_srawi_0,
213 (void*)&do_srawi_1,
214 (void*)&do_srawi_2,
215 (void*)&do_srawi_3,
216 (void*)&do_srawi_4,
217 (void*)&do_srawi_5,
218 (void*)&do_srawi_6,
219 (void*)&do_srawi_7,
220 (void*)&do_srawi_8,
221 (void*)&do_srawi_9,
222 (void*)&do_srawi_10,
223 (void*)&do_srawi_11,
224 (void*)&do_srawi_12,
225 (void*)&do_srawi_13,
226 (void*)&do_srawi_14,
227 (void*)&do_srawi_15,
228 (void*)&do_srawi_16,
229 (void*)&do_srawi_17,
230 (void*)&do_srawi_18,
231 (void*)&do_srawi_19,
232 (void*)&do_srawi_20,
233 (void*)&do_srawi_21,
234 (void*)&do_srawi_22,
235 (void*)&do_srawi_23,
236 (void*)&do_srawi_24,
237 (void*)&do_srawi_25,
238 (void*)&do_srawi_26,
239 (void*)&do_srawi_27,
240 (void*)&do_srawi_28,
241 (void*)&do_srawi_29,
242 (void*)&do_srawi_30,
243 (void*)&do_srawi_31
246 /* ------------------------ SRAD ------------------------ */
248 void do_srad ( ULong arg1, ULong arg2,
249 /*OUT*/ULong* res, /*OUT*/ULong* xer )
251 ULong arg1W = arg1;
252 ULong arg2W = arg2;
253 ULong resW = 0;
254 ULong xerW = 0;
255 __asm__ __volatile__(
256 "srad %0,%2,%3\n\t"
257 "mfxer %1"
258 : /*out*/ "=b"(resW), "=b"(xerW)
259 : /*in*/ "b"(arg1W), "b"(arg2W)
260 : /*trash*/ "cc"
262 *res = resW;
263 *xer = xerW;
267 /* ------------------------ SRAW ------------------------ */
269 void do_sraw ( ULong arg1, ULong arg2,
270 /*OUT*/ULong* res, /*OUT*/ULong* xer )
272 ULong arg1W = arg1;
273 ULong arg2W = arg2;
274 ULong resW = 0;
275 ULong xerW = 0;
276 __asm__ __volatile__(
277 "sraw %0,%2,%3\n\t"
278 "mfxer %1"
279 : /*out*/ "=b"(resW), "=b"(xerW)
280 : /*in*/ "b"(arg1W), "b"(arg2W)
281 : /*trash*/ "cc"
283 *res = resW;
284 *xer = xerW;
287 /* ------------------------ SRD ------------------------ */
289 void do_srd ( ULong arg1, ULong arg2,
290 /*OUT*/ULong* res, /*OUT*/ULong* xer )
292 ULong arg1W = arg1;
293 ULong arg2W = arg2;
294 ULong resW = 0;
295 ULong xerW = 0;
296 __asm__ __volatile__(
297 "srd %0,%2,%3\n\t"
298 "mfxer %1"
299 : /*out*/ "=b"(resW), "=b"(xerW)
300 : /*in*/ "b"(arg1W), "b"(arg2W)
301 : /*trash*/ "cc"
303 *res = resW;
304 *xer = xerW;
308 /* ------------------------ SRW ------------------------ */
310 void do_srw ( ULong arg1, ULong arg2,
311 /*OUT*/ULong* res, /*OUT*/ULong* xer )
313 ULong arg1W = arg1;
314 ULong arg2W = arg2;
315 ULong resW = 0;
316 ULong xerW = 0;
317 __asm__ __volatile__(
318 "srw %0,%2,%3\n\t"
319 "mfxer %1"
320 : /*out*/ "=b"(resW), "=b"(xerW)
321 : /*in*/ "b"(arg1W), "b"(arg2W)
322 : /*trash*/ "cc"
324 *res = resW;
325 *xer = xerW;
329 /* ------------------------ SLD ------------------------ */
331 void do_sld ( ULong arg1, ULong arg2,
332 /*OUT*/ULong* res, /*OUT*/ULong* xer )
334 ULong arg1W = arg1;
335 ULong arg2W = arg2;
336 ULong resW = 0;
337 ULong xerW = 0;
338 __asm__ __volatile__(
339 "sld %0,%2,%3\n\t"
340 "mfxer %1"
341 : /*out*/ "=b"(resW), "=b"(xerW)
342 : /*in*/ "b"(arg1W), "b"(arg2W)
343 : /*trash*/ "cc"
345 *res = resW;
346 *xer = xerW;
350 /* ------------------------ SLW ------------------------ */
352 void do_slw ( ULong arg1, ULong arg2,
353 /*OUT*/ULong* res, /*OUT*/ULong* xer )
355 ULong arg1W = arg1;
356 ULong arg2W = arg2;
357 ULong resW = 0;
358 ULong xerW = 0;
359 __asm__ __volatile__(
360 "slw %0,%2,%3\n\t"
361 "mfxer %1"
362 : /*out*/ "=b"(resW), "=b"(xerW)
363 : /*in*/ "b"(arg1W), "b"(arg2W)
364 : /*trash*/ "cc"
366 *res = resW;
367 *xer = xerW;
371 /* ------------------------ ------------------------ */
372 /* ------------------------ ------------------------ */
373 /* ------------------------ ------------------------ */
375 #define N_ARGS64 41
377 ULong args64[N_ARGS64] = {
378 0x0000000000000000ULL,
380 0x0000000000000001ULL,
381 0x0000000031415927ULL,
382 0x000000007FFFFFFFULL,
383 0x0000000080000000ULL,
384 0x00000000FFFFFFFFULL,
386 0x0000000100000000ULL,
387 0x3141592700000000ULL,
388 0x7FFFFFFF00000000ULL,
389 0x8000000000000000ULL,
390 0xFFFFFFFF00000000ULL,
392 0x7FFFFFFF00000001ULL,
393 0x7FFFFFFF31415927ULL,
394 0x7FFFFFFF7FFFFFFFULL,
395 0x7FFFFFFF80000000ULL,
396 0x7FFFFFFFFFFFFFFFULL,
398 0x000000017FFFFFFFULL,
399 0x314159277FFFFFFFULL,
400 0x7FFFFFFF7FFFFFFFULL,
401 0x800000007FFFFFFFULL,
402 0xFFFFFFFF7FFFFFFFULL,
404 0x8000000000000001ULL,
405 0x8000000031415927ULL,
406 0x800000007FFFFFFFULL,
407 0x8000000080000000ULL,
408 0x80000000FFFFFFFFULL,
410 0x0000000180000000ULL,
411 0x3141592780000000ULL,
412 0x7FFFFFFF80000000ULL,
413 0x8000000080000000ULL,
414 0xFFFFFFFF80000000ULL,
416 0xFFFFFFFF00000001ULL,
417 0xFFFFFFFF31415927ULL,
418 0xFFFFFFFF7FFFFFFFULL,
419 0xFFFFFFFF80000000ULL,
420 0xFFFFFFFFFFFFFFFFULL,
422 0x00000001FFFFFFFFULL,
423 0x31415927FFFFFFFFULL,
424 0x7FFFFFFFFFFFFFFFULL,
425 0x80000000FFFFFFFFULL,
426 0xFFFFFFFFFFFFFFFFULL
429 void do_unary ( char* name, void** fns, int n_fns )
431 int i, j;
432 ULong arg, res, xer;
433 void(*fn)(ULong,ULong*,ULong*);
434 for (i = 0; i < n_fns; i++) { /* shift */
435 for (j = 0; j < N_ARGS64; j++) { /* arg */
436 arg = args64[j];
437 res = xer = 0;
438 fn = fns[i];
439 fn( arg, &res, &xer );
440 printf("%5s(0x%016llx, %2d) = 0x%016llx, %d\n",
441 name, arg, (int)i, res, (int)((xer >> 29 & 1)));
446 void do_binary ( char* name, void* fnV )
448 int i, j;
449 ULong arg1, arg2, res, xer;
450 void(*fn)(ULong,ULong,ULong*,ULong*);
451 for (i = 0; i < 64+10; i++) { /* shift */
452 for (j = 0; j < N_ARGS64; j++) { /* arg */
453 arg1 = args64[j];
454 arg2 = i;
455 res = xer = 0;
456 fn = fnV;
457 fn( arg1, arg2, &res, &xer );
458 printf("%5s(0x%016llx, %2d) = 0x%016llx, %d\n",
459 name, arg1, (int)arg2, res, (int)((xer >> 29 & 1)));
464 int main ( void )
466 do_unary("sradi", all_sradi, 64);
467 do_unary("srawi", all_srawi, 32);
468 do_binary("srad", do_srad);
469 do_binary("sraw", do_sraw);
470 do_binary("srd", do_srd);
471 do_binary("srw", do_srw);
472 do_binary("sld", do_sld);
473 do_binary("slw", do_slw);
474 return 0;