1 #include <stdio.h>
2
3 #define branch(mask,_v1) \
4 ({ \
5 unsigned char taken; \
6 unsigned b1 = _v1; \
7 asm volatile( " ltr %[b1],%[b1]\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), [b1] "+d"(b1) \
14 : \
15 : "cc"); \
16 taken; \
17 })
18
19 void
ltr_1(void)20 ltr_1(void)
21 {
22 int wrong, ok, v1;
23
24 printf("Test #1 value = 0\n");
25
26 v1 = 0;
27 wrong = ok = 0;
28 if (branch(0, v1)) ++wrong; else ++ok;
29 if (branch(1, v1)) ++wrong; else ++ok;
30 if (branch(2, v1)) ++wrong; else ++ok;
31 if (branch(3, v1)) ++wrong; else ++ok;
32 if (branch(4, v1)) ++wrong; else ++ok;
33 if (branch(5, v1)) ++wrong; else ++ok;
34 if (branch(6, v1)) ++wrong; else ++ok;
35 if (branch(7, v1)) ++wrong; else ++ok;
36 if (branch(8, v1)) ++ok; else ++wrong;
37 if (branch(9, v1)) ++ok; else ++wrong;
38 if (branch(10, v1)) ++ok; else ++wrong;
39 if (branch(11, v1)) ++ok; else ++wrong;
40 if (branch(12, v1)) ++ok; else ++wrong;
41 if (branch(13, v1)) ++ok; else ++wrong;
42 if (branch(14, v1)) ++ok; else ++wrong;
43 if (branch(15, v1)) ++ok; else ++wrong;
44
45 if (wrong != 0 || ok != 16)
46 printf("FAILED\n");
47 else
48 printf("OK\n");
49 }
50
51 void
ltr_2(void)52 ltr_2(void)
53 {
54 int wrong, ok, v1;
55
56 printf("Test #2 value > 0\n");
57 v1 = 42;
58 wrong = ok = 0;
59 if (branch(0, v1)) ++wrong; else ++ok;
60 if (branch(1, v1)) ++wrong; else ++ok;
61 if (branch(2, v1)) ++ok; else ++wrong;
62 if (branch(3, v1)) ++ok; else ++wrong;
63 if (branch(4, v1)) ++wrong; else ++ok;
64 if (branch(5, v1)) ++wrong; else ++ok;
65 if (branch(6, v1)) ++ok; else ++wrong;
66 if (branch(7, v1)) ++ok; else ++wrong;
67 if (branch(8, v1)) ++wrong; else ++ok;
68 if (branch(9, v1)) ++wrong; else ++ok;
69 if (branch(10, v1)) ++ok; else ++wrong;
70 if (branch(11, v1)) ++ok; else ++wrong;
71 if (branch(12, v1)) ++wrong; else ++ok;
72 if (branch(13, v1)) ++wrong; else ++ok;
73 if (branch(14, v1)) ++ok; else ++wrong;
74 if (branch(15, v1)) ++ok; else ++wrong;
75
76 if (wrong != 0 || ok != 16)
77 printf("FAILED\n");
78 else
79 printf("OK\n");
80 }
81
82 void
ltr_3(void)83 ltr_3(void)
84 {
85 int wrong, ok, v1;
86
87 printf("Test #3 value < 0\n");
88
89 v1 = -100;
90 wrong = ok = 0;
91 if (branch(0, v1)) ++wrong; else ++ok;
92 if (branch(1, v1)) ++wrong; else ++ok;
93 if (branch(2, v1)) ++wrong; else ++ok;
94 if (branch(3, v1)) ++wrong; else ++ok;
95 if (branch(4, v1)) ++ok; else ++wrong;
96 if (branch(5, v1)) ++ok; else ++wrong;
97 if (branch(6, v1)) ++ok; else ++wrong;
98 if (branch(7, v1)) ++ok; else ++wrong;
99 if (branch(8, v1)) ++wrong; else ++ok;
100 if (branch(9, v1)) ++wrong; else ++ok;
101 if (branch(10, v1)) ++wrong; else ++ok;
102 if (branch(11, v1)) ++wrong; else ++ok;
103 if (branch(12, v1)) ++ok; else ++wrong;
104 if (branch(13, v1)) ++ok; else ++wrong;
105 if (branch(14, v1)) ++ok; else ++wrong;
106 if (branch(15, v1)) ++ok; else ++wrong;
107
108 if (wrong != 0 || ok != 16)
109 printf("FAILED\n");
110 else
111 printf("OK\n");
112 }
113
main()114 int main()
115 {
116 ltr_1();
117 ltr_2();
118 ltr_3();
119 return 0;
120 }
121