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