FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / s390x / flogr.c
blob079dc41052a8bd1e6fad3d2bd1cb9b8b56286f04
1 #include <stdio.h>
2 #include "opcodes.h"
4 /* The FLOGR insn reads from register R2 and writes to register R1 and
5 R1 + 1. So we need to distinguish three cases:
7 (1) All three registers R1, R1 + 1, and R2 are distinct
8 (2) R2 == R1
9 (3) R2 == R1 + 1
11 These are tested by flogr1, flogr2, and flogr3, respectively. */
13 /* Call FLOGR on INPUT. The results are returned through the parms. */
15 /* R2 != R1 && R2 != R1 + 1 */
16 void
17 flogr1(unsigned long input, unsigned long *bitpos, unsigned long *modval,
18 unsigned int *cc)
20 unsigned int psw;
21 register unsigned long value asm("4") = input;
23 asm volatile ( FLOGR(2,4)
24 "ipm %[psw]\n\t"
25 "stg 2, %[bitpos]\n\t"
26 "stg 3, %[modval]\n\t"
27 : [bitpos]"=T"(*bitpos), [modval]"=T"(*modval),
28 [psw]"=&d"(psw)
29 : [val] "d"(value)
30 : "2", "3", "cc");
32 *cc = psw >> 28;
33 #if 0
34 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
35 value, *bitpos, *modval, *cc);
36 #endif
39 /* R2 == R1 */
40 void
41 flogr2(unsigned long input, unsigned long *bitpos, unsigned long *modval,
42 unsigned int *cc)
44 unsigned int psw;
45 register unsigned long value asm("2") = input;
47 asm volatile ( FLOGR(2,2)
48 "ipm %[psw]\n\t"
49 "stg 2, %[bitpos]\n\t"
50 "stg 3, %[modval]\n\t"
51 : [bitpos]"=T"(*bitpos), [modval]"=T"(*modval),
52 [psw]"=&d"(psw), [val] "+d"(value)
54 : "3", "cc");
56 *cc = psw >> 28;
57 #if 0
58 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
59 value, *bitpos, *modval, *cc);
60 #endif
63 /* R2 == R1 + 1 */
64 void
65 flogr3(unsigned long input, unsigned long *bitpos, unsigned long *modval,
66 unsigned int *cc)
68 unsigned int psw;
69 register unsigned long value asm("3") = input;
71 asm volatile ( FLOGR(2,3)
72 "ipm %[psw]\n\t"
73 "stg 2, %[bitpos]\n\t"
74 "stg 3, %[modval]\n\t"
75 : [bitpos]"=T"(*bitpos), [modval]"=T"(*modval),
76 [psw]"=&d"(psw), [val] "+d"(value)
78 : "2", "cc");
80 *cc = psw >> 28;
81 #if 0
82 printf("value = %lx, bitpos = %lu, modval = %lx, cc = %d\n",
83 value, *bitpos, *modval, *cc);
84 #endif
87 void
88 runtest(void (*func)(unsigned long, unsigned long *, unsigned long *,
89 unsigned int *))
91 unsigned long bitpos, modval, value;
92 unsigned int cc;
93 int i;
95 /* Value 0 is special */
96 value = 0;
97 func(value, &bitpos, &modval, &cc);
98 if (modval != 0) fprintf(stderr, "modval is wrong for %lx\n", value);
99 if (bitpos != 64) fprintf(stderr, "bitpos is wrong for %lx\n", value);
100 if (cc != 0) fprintf(stderr, "cc is wrong for %lx\n", value);
102 /* Test with exactly 1 bit set */
103 for (i = 0; i < 64; ++i) {
104 value = 1ull << i;
105 func(value, &bitpos, &modval, &cc);
106 if (modval != 0) fprintf(stderr, "modval is wrong for %lx\n", value);
107 if (bitpos != 63 - i) fprintf(stderr, "bitpos is wrong for %lx\n", value);
108 if (cc != 2) fprintf(stderr, "cc is wrong for %lx\n", value);
111 /* Test with all bits 1 right from first 1 bit */
112 for (i = 1; i < 64; ++i) {
113 value = 1ull << i;
114 value = value | (value - 1);
115 func(value, &bitpos, &modval, &cc);
116 if (modval != (value >> 1)) fprintf(stderr, "modval is wrong for %lx\n", value);
117 if (bitpos != 63 - i) fprintf(stderr, "bitpos is wrong for %lx\n", value);
118 if (cc != 2) fprintf(stderr, "cc is wrong for %lx\n", value);
123 int main()
125 runtest(flogr1);
126 runtest(flogr2);
127 runtest(flogr3);
129 return 0;