1 #include <stdio.h>
2 
3 #define branch(mask,i2,_v1)                            \
4   ({                                                   \
5         unsigned char taken;                           \
6         unsigned char v1 = _v1;                        \
7         asm volatile(   "       tm %[v]," #i2 "\n\t" \
8                  	"	brc " #mask " ,1f\n\t" \
9                         "       mvi %[taken],0\n\t"    \
10 			"	j   0f\n\t"            \
11 			"1:	mvi %[taken],1\n\t"    \
12 			"0:	bcr 0,0 /* nop */\n\t" \
13              : [taken] "=Q" (taken)                    \
14              : [v] "Q"(v1)                             \
15              : "cc");                                  \
16         taken;                                         \
17    })
18 
19 void
tm_mask_0(void)20 tm_mask_0(void)
21 {
22   int wrong, ok;
23   unsigned char v;
24 
25   printf("Test #1  mask == 0, value == ~0  --> cc == 0\n");
26 
27   v = ~0;
28   wrong = ok = 0;
29 
30   if (branch(0,  0, v)) ++wrong; else ++ok;
31   if (branch(1,  0, v)) ++wrong; else ++ok;
32   if (branch(2,  0, v)) ++wrong; else ++ok;
33   if (branch(3,  0, v)) ++wrong; else ++ok;
34   if (branch(4,  0, v)) ++wrong; else ++ok;
35   if (branch(5,  0, v)) ++wrong; else ++ok;
36   if (branch(6,  0, v)) ++wrong; else ++ok;
37   if (branch(7,  0, v)) ++wrong; else ++ok;
38   if (branch(8,  0, v)) ++ok; else ++wrong;
39   if (branch(9,  0, v)) ++ok; else ++wrong;
40   if (branch(10, 0, v)) ++ok; else ++wrong;
41   if (branch(11, 0, v)) ++ok; else ++wrong;
42   if (branch(12, 0, v)) ++ok; else ++wrong;
43   if (branch(13, 0, v)) ++ok; else ++wrong;
44   if (branch(14, 0, v)) ++ok; else ++wrong;
45   if (branch(15, 0, v)) ++ok; else ++wrong;
46 
47   if (wrong != 0 || ok != 16)
48     printf("FAILED\n");
49   else
50     printf("OK\n");
51 }
52 
53 void
tm_value_0(void)54 tm_value_0(void)
55 {
56   int wrong, ok;
57   unsigned char v;
58 
59   printf("Test #2  mask == 0xFF, value == 0  --> cc == 0\n");
60 
61   v = 0;
62   wrong = ok = 0;
63 
64   if (branch(0,  0xFF, v)) ++wrong; else ++ok;
65   if (branch(1,  0xFF, v)) ++wrong; else ++ok;
66   if (branch(2,  0xFF, v)) ++wrong; else ++ok;
67   if (branch(3,  0xFF, v)) ++wrong; else ++ok;
68   if (branch(4,  0xFF, v)) ++wrong; else ++ok;
69   if (branch(5,  0xFF, v)) ++wrong; else ++ok;
70   if (branch(6,  0xFF, v)) ++wrong; else ++ok;
71   if (branch(7,  0xFF, v)) ++wrong; else ++ok;
72   if (branch(8,  0xFF, v)) ++ok; else ++wrong;
73   if (branch(9,  0xFF, v)) ++ok; else ++wrong;
74   if (branch(10, 0xFF, v)) ++ok; else ++wrong;
75   if (branch(11, 0xFF, v)) ++ok; else ++wrong;
76   if (branch(12, 0xFF, v)) ++ok; else ++wrong;
77   if (branch(13, 0xFF, v)) ++ok; else ++wrong;
78   if (branch(14, 0xFF, v)) ++ok; else ++wrong;
79   if (branch(15, 0xFF, v)) ++ok; else ++wrong;
80 
81   if (wrong != 0 || ok != 16)
82     printf("FAILED\n");
83   else
84     printf("OK\n");
85 }
86 
87 void
tm_all_selected_bits_set_1(void)88 tm_all_selected_bits_set_1(void)
89 {
90   int wrong, ok;
91   unsigned char v;
92 
93   printf("Test #3  mask == 0xFF, value == 0xFF  --> cc == 3\n");
94 
95   v = 0xFF;
96   wrong = ok = 0;
97 
98   if (branch(0,  0xFF, v)) ++wrong; else ++ok;
99   if (branch(1,  0xFF, v)) ++ok; else ++wrong;
100   if (branch(2,  0xFF, v)) ++wrong; else ++ok;
101   if (branch(3,  0xFF, v)) ++ok; else ++wrong;
102   if (branch(4,  0xFF, v)) ++wrong; else ++ok;
103   if (branch(5,  0xFF, v)) ++ok; else ++wrong;
104   if (branch(6,  0xFF, v)) ++wrong; else ++ok;
105   if (branch(7,  0xFF, v)) ++ok; else ++wrong;
106   if (branch(8,  0xFF, v)) ++wrong; else ++ok;
107   if (branch(9,  0xFF, v)) ++ok; else ++wrong;
108   if (branch(10, 0xFF, v)) ++wrong; else ++ok;
109   if (branch(11, 0xFF, v)) ++ok; else ++wrong;
110   if (branch(12, 0xFF, v)) ++wrong; else ++ok;
111   if (branch(13, 0xFF, v)) ++ok; else ++wrong;
112   if (branch(14, 0xFF, v)) ++wrong; else ++ok;
113   if (branch(15, 0xFF, v)) ++ok; else ++wrong;
114 
115   if (wrong != 0 || ok != 16)
116     printf("FAILED\n");
117   else
118     printf("OK\n");
119 }
120 
121 void
tm_all_selected_bits_set_2(void)122 tm_all_selected_bits_set_2(void)
123 {
124   int wrong, ok;
125   unsigned char v;
126 
127   printf("Test #4  mask == 0x80, value == 0x80  --> cc == 3\n");
128 
129   v = 0x80;
130   wrong = ok = 0;
131 
132   if (branch(0,  0x80, v)) ++wrong; else ++ok;
133   if (branch(1,  0x80, v)) ++ok; else ++wrong;
134   if (branch(2,  0x80, v)) ++wrong; else ++ok;
135   if (branch(3,  0x80, v)) ++ok; else ++wrong;
136   if (branch(4,  0x80, v)) ++wrong; else ++ok;
137   if (branch(5,  0x80, v)) ++ok; else ++wrong;
138   if (branch(6,  0x80, v)) ++wrong; else ++ok;
139   if (branch(7,  0x80, v)) ++ok; else ++wrong;
140   if (branch(8,  0x80, v)) ++wrong; else ++ok;
141   if (branch(9,  0x80, v)) ++ok; else ++wrong;
142   if (branch(10, 0x80, v)) ++wrong; else ++ok;
143   if (branch(11, 0x80, v)) ++ok; else ++wrong;
144   if (branch(12, 0x80, v)) ++wrong; else ++ok;
145   if (branch(13, 0x80, v)) ++ok; else ++wrong;
146   if (branch(14, 0x80, v)) ++wrong; else ++ok;
147   if (branch(15, 0x80, v)) ++ok; else ++wrong;
148 
149   if (wrong != 0 || ok != 16)
150     printf("FAILED\n");
151   else
152     printf("OK\n");
153 }
154 
155 void
tm_some_selected_bits_set_msb_set(void)156 tm_some_selected_bits_set_msb_set(void)
157 {
158   int wrong, ok;
159   unsigned char v;
160 
161   printf("Test #5  mask == 0xF0, value == 0x90  --> cc == 1\n");
162 
163   v = 0x90;
164   wrong = ok = 0;
165 
166   if (branch(0,  0xF0, v)) ++wrong; else ++ok;
167   if (branch(1,  0xF0, v)) ++wrong; else ++ok;
168   if (branch(2,  0xF0, v)) ++wrong; else ++ok;
169   if (branch(3,  0xF0, v)) ++wrong; else ++ok;
170   if (branch(4,  0xF0, v)) ++ok; else ++wrong;
171   if (branch(5,  0xF0, v)) ++ok; else ++wrong;
172   if (branch(6,  0xF0, v)) ++ok; else ++wrong;
173   if (branch(7,  0xF0, v)) ++ok; else ++wrong;
174   if (branch(8,  0xF0, v)) ++wrong; else ++ok;
175   if (branch(9,  0xF0, v)) ++wrong; else ++ok;
176   if (branch(10, 0xF0, v)) ++wrong; else ++ok;
177   if (branch(11, 0xF0, v)) ++wrong; else ++ok;
178   if (branch(12, 0xF0, v)) ++ok; else ++wrong;
179   if (branch(13, 0xF0, v)) ++ok; else ++wrong;
180   if (branch(14, 0xF0, v)) ++ok; else ++wrong;
181   if (branch(15, 0xF0, v)) ++ok; else ++wrong;
182 
183   if (wrong != 0 || ok != 16)
184     printf("FAILED\n");
185   else
186     printf("OK\n");
187 }
188 
189 void
tm_some_selected_bits_set_msb_not_set(void)190 tm_some_selected_bits_set_msb_not_set(void)
191 {
192   int wrong, ok;
193   unsigned char v;
194 
195   printf("Test #6  mask == 0xF0, value == 0x30  --> cc == 1\n");
196 
197   v = 0x30;
198   wrong = ok = 0;
199 
200   if (branch(0,  0xF0, v)) ++wrong; else ++ok;
201   if (branch(1,  0xF0, v)) ++wrong; else ++ok;
202   if (branch(2,  0xF0, v)) ++wrong; else ++ok;
203   if (branch(3,  0xF0, v)) ++wrong; else ++ok;
204   if (branch(4,  0xF0, v)) ++ok; else ++wrong;
205   if (branch(5,  0xF0, v)) ++ok; else ++wrong;
206   if (branch(6,  0xF0, v)) ++ok; else ++wrong;
207   if (branch(7,  0xF0, v)) ++ok; else ++wrong;
208   if (branch(8,  0xF0, v)) ++wrong; else ++ok;
209   if (branch(9,  0xF0, v)) ++wrong; else ++ok;
210   if (branch(10, 0xF0, v)) ++wrong; else ++ok;
211   if (branch(11, 0xF0, v)) ++wrong; else ++ok;
212   if (branch(12, 0xF0, v)) ++ok; else ++wrong;
213   if (branch(13, 0xF0, v)) ++ok; else ++wrong;
214   if (branch(14, 0xF0, v)) ++ok; else ++wrong;
215   if (branch(15, 0xF0, v)) ++ok; else ++wrong;
216 
217   if (wrong != 0 || ok != 16)
218     printf("FAILED\n");
219   else
220     printf("OK\n");
221 }
222 
main()223 int main()
224 {
225   tm_mask_0();
226   tm_value_0();
227   tm_all_selected_bits_set_1();
228   tm_all_selected_bits_set_2();
229   tm_some_selected_bits_set_msb_set();
230   tm_some_selected_bits_set_msb_not_set();
231 
232   return 0;
233 }
234