1 #include <stdio.h>
2
3 #define branch(mask,_v1,_v2) \
4 ({ \
5 unsigned char taken; \
6 unsigned long b1 = _v1; \
7 unsigned long b2 = _v2; \
8 asm volatile(" slgr %[b1],%[b2]\n\t" \
9 " brc " #mask " ,1f\n\t" \
10 " mvi %[taken],0\n\t" \
11 " j 0f\n\t" \
12 "1: mvi %[taken],1\n\t" \
13 "0: bcr 0,0 /* nop */\n\t" \
14 : [taken] "=Q" (taken), [b1] "+d"(b1) \
15 : [b2] "d"(b2) \
16 : "cc"); \
17 taken; \
18 })
19
20
21 /* cc = (op1 == op2) ? 2
22 : (op1 > op2) ? 3 : 1; */
23
24
25 void
slgr_equal(void)26 slgr_equal(void)
27 {
28 unsigned long v1, v2;
29 int wrong, ok;
30
31 printf("Test #1 op1 == op2\n");
32
33 v1 = v2 = 42;
34 wrong = ok = 0;
35
36 if (branch(0, v1, v2)) ++wrong; else ++ok;
37 if (branch(1, v1, v2)) ++wrong; else ++ok;
38 if (branch(2, v1, v2)) ++ok; else ++wrong;
39 if (branch(3, v1, v2)) ++ok; else ++wrong;
40 if (branch(4, v1, v2)) ++wrong; else ++ok;
41 if (branch(5, v1, v2)) ++wrong; else ++ok;
42 if (branch(6, v1, v2)) ++ok; else ++wrong;
43 if (branch(7, v1, v2)) ++ok; else ++wrong;
44 if (branch(8, v1, v2)) ++wrong; else ++ok;
45 if (branch(9, v1, v2)) ++wrong; else ++ok;
46 if (branch(10, v1, v2)) ++ok; else ++wrong;
47 if (branch(11, v1, v2)) ++ok; else ++wrong;
48 if (branch(12, v1, v2)) ++wrong; else ++ok;
49 if (branch(13, v1, v2)) ++wrong; else ++ok;
50 if (branch(14, v1, v2)) ++ok; else ++wrong;
51 if (branch(15, v1, v2)) ++ok; else ++wrong;
52
53 if (wrong != 0 || ok != 16)
54 printf("FAILED\n");
55 else
56 printf("OK\n");
57 }
58
59 void
slgr_less(void)60 slgr_less(void)
61 {
62 unsigned long v1, v2;
63 int wrong, ok;
64
65 printf("Test #2 op1 < op2\n");
66
67 v1 = 100;
68 v2 = 1000;
69
70 wrong = ok = 0;
71
72 if (branch(0, v1, v2)) ++wrong; else ++ok;
73 if (branch(1, v1, v2)) ++wrong; else ++ok;
74 if (branch(2, v1, v2)) ++wrong; else ++ok;
75 if (branch(3, v1, v2)) ++wrong; else ++ok;
76 if (branch(4, v1, v2)) ++ok; else ++wrong;
77 if (branch(5, v1, v2)) ++ok; else ++wrong;
78 if (branch(6, v1, v2)) ++ok; else ++wrong;
79 if (branch(7, v1, v2)) ++ok; else ++wrong;
80 if (branch(8, v1, v2)) ++wrong; else ++ok;
81 if (branch(9, v1, v2)) ++wrong; else ++ok;
82 if (branch(10, v1, v2)) ++wrong; else ++ok;
83 if (branch(11, v1, v2)) ++wrong; else ++ok;
84 if (branch(12, v1, v2)) ++ok; else ++wrong;
85 if (branch(13, v1, v2)) ++ok; else ++wrong;
86 if (branch(14, v1, v2)) ++ok; else ++wrong;
87 if (branch(15, v1, v2)) ++ok; else ++wrong;
88
89 if (wrong != 0 /* || ok != 16 */)
90 printf("FAILED\n");
91 else
92 printf("OK\n");
93 }
94
95 void
slgr_greater(void)96 slgr_greater(void)
97 {
98 unsigned long v1, v2;
99 int wrong, ok;
100
101 printf("Test #3 op1 > op2\n");
102
103 v1 = 10000;
104 v2 = 1000;
105
106 wrong = ok = 0;
107
108 if (branch(0, v1, v2)) ++wrong; else ++ok;
109 if (branch(1, v1, v2)) ++ok; else ++wrong;
110 if (branch(2, v1, v2)) ++wrong; else ++ok;
111 if (branch(3, v1, v2)) ++ok; else ++wrong;
112 if (branch(4, v1, v2)) ++wrong; else ++ok;
113 if (branch(5, v1, v2)) ++ok; else ++wrong;
114 if (branch(6, v1, v2)) ++wrong; else ++ok;
115 if (branch(7, v1, v2)) ++ok; else ++wrong;
116 if (branch(8, v1, v2)) ++wrong; else ++ok;
117 if (branch(9, v1, v2)) ++ok; else ++wrong;
118 if (branch(10, v1, v2)) ++wrong; else ++ok;
119 if (branch(11, v1, v2)) ++ok; else ++wrong;
120 if (branch(12, v1, v2)) ++wrong; else ++ok;
121 if (branch(13, v1, v2)) ++ok; else ++wrong;
122 if (branch(14, v1, v2)) ++wrong; else ++ok;
123 if (branch(15, v1, v2)) ++ok; else ++wrong;
124
125 if (wrong != 0 || ok != 16)
126 printf("FAILED\n");
127 else
128 printf("OK\n");
129 }
130
main()131 int main()
132 {
133 slgr_equal();
134 slgr_less();
135 slgr_greater();
136
137 return 0;
138 }
139