blob: f269918402c612d669daf528c6de555400a4c55a [file] [log] [blame]
florianabbc9af2012-05-12 00:05:14 +00001#include <stdio.h>
2#include <stdint.h>
3#include "opcodes.h"
4
5#define BRASLCLOBBER "0","1","2","3","4","5","14", \
6 "f0","f1","f2","f3","f4","f5","f6","f7"
7
8void if_eq(void) { printf("equal\n"); }
9void if_ne(void) { printf("not equal\n"); }
10void if_gt(void) { printf("greater than\n"); }
11void if_le(void) { printf("less or equal\n"); }
12void if_lt(void) { printf("less than\n"); }
13void if_ge(void) { printf("greater or equal\n"); }
14void if_taken(void) { printf("taken\n"); }
15void if_not_taken(void) { printf("not taken\n"); }
16
17#undef LT
18#define NEVER 0
19#define GT 2
20#define LT 4
21#define NE 6
22#define EQ 8
23#define LE C
24#define GE A
25#define ALWAYS E
26
27
28void compare_never(int64_t value1, int64_t value2)
29{
30 register int64_t val1 asm("r7") = value1;
31 register int64_t val2 asm("r8") = value2;
32
33 asm volatile(
floriance004eb2012-06-09 16:19:31 +000034 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +000035 CGRJ(7,8,8,NEVER) "\n\t"
36 "brasl 14,if_not_taken\n\t"
37 "j 0f\n\t"
38 "brasl 14,if_taken\n\t"
floriance004eb2012-06-09 16:19:31 +000039 "0: aghi 15,160\n\t"
40 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +000041 return;
42}
43
44void compare_always(int64_t value1, int64_t value2)
45{
46 register int64_t val1 asm("r7") = value1;
47 register int64_t val2 asm("r8") = value2;
48
49 asm volatile(
floriance004eb2012-06-09 16:19:31 +000050 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +000051 CGRJ(7,8,8,ALWAYS) "\n\t"
52 "brasl 14,if_not_taken\n\t"
53 "j 0f\n\t"
54 "brasl 14,if_taken\n\t"
floriance004eb2012-06-09 16:19:31 +000055 "0: aghi 15,160\n\t"
56 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +000057 return;
58}
59
60void compare_le(int64_t value1, int64_t value2)
61{
62 register int64_t val1 asm("r7") = value1;
63 register int64_t val2 asm("r8") = value2;
64
65 asm volatile(
floriance004eb2012-06-09 16:19:31 +000066 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +000067 CGRJ(7,8,8,LE) "\n\t"
68 "brasl 14,if_gt\n\t"
69 "j 0f\n\t"
70 "brasl 14,if_le\n\t"
floriance004eb2012-06-09 16:19:31 +000071 "0: aghi 15,160\n\t"
72 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +000073 return;
74}
75
76void compare_ge(int64_t value1, int64_t value2)
77{
78 register int64_t val1 asm("r7") = value1;
79 register int64_t val2 asm("r8") = value2;
80
81 asm volatile(
floriance004eb2012-06-09 16:19:31 +000082 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +000083 CGRJ(7,8,8,GE) "\n\t"
84 "brasl 14,if_lt\n\t"
85 "j 0f\n\t"
86 "brasl 14,if_ge\n\t"
floriance004eb2012-06-09 16:19:31 +000087 "0: aghi 15,160\n\t"
88 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +000089 return;
90}
91
92void compare_gt(int64_t value1, int64_t value2)
93{
94 register int64_t val1 asm("r7") = value1;
95 register int64_t val2 asm("r8") = value2;
96
97 asm volatile(
floriance004eb2012-06-09 16:19:31 +000098 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +000099 CGRJ(7,8,8,GT) "\n\t"
100 "brasl 14,if_le\n\t"
101 "j 0f\n\t"
102 "brasl 14,if_gt\n\t"
floriance004eb2012-06-09 16:19:31 +0000103 "0: aghi 15,160\n\t"
104 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +0000105 return;
106}
107
108void compare_lt(int64_t value1, int64_t value2)
109{
110 register int64_t val1 asm("r7") = value1;
111 register int64_t val2 asm("r8") = value2;
112
113 asm volatile(
floriance004eb2012-06-09 16:19:31 +0000114 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +0000115 CGRJ(7,8,8,LT) "\n\t"
116 "brasl 14,if_ge\n\t"
117 "j 0f\n\t"
118 "brasl 14,if_lt\n\t"
floriance004eb2012-06-09 16:19:31 +0000119 "0: aghi 15,160\n\t"
120 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +0000121 return;
122}
123
124void compare_eq(int64_t value1, int64_t value2)
125{
126 register int64_t val1 asm("r7") = value1;
127 register int64_t val2 asm("r8") = value2;
128
129 asm volatile(
floriance004eb2012-06-09 16:19:31 +0000130 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +0000131 CGRJ(7,8,8,EQ) "\n\t"
132 "brasl 14,if_ne\n\t"
133 "j 0f\n\t"
134 "brasl 14,if_eq\n\t"
floriance004eb2012-06-09 16:19:31 +0000135 "0: aghi 15,160\n\t"
136 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +0000137 return;
138}
139
140void compare_ne(int64_t value1, int64_t value2)
141{
142 register int64_t val1 asm("r7") = value1;
143 register int64_t val2 asm("r8") = value2;
144
145 asm volatile(
floriance004eb2012-06-09 16:19:31 +0000146 "aghi 15,-160\n\t"
florianabbc9af2012-05-12 00:05:14 +0000147 CGRJ(7,8,8,NE) "\n\t"
148 "brasl 14,if_eq\n\t"
149 "j 0f\n\t"
150 "brasl 14,if_ne\n\t"
floriance004eb2012-06-09 16:19:31 +0000151 "0: aghi 15,160\n\t"
152 : : "d"(val1), "d"(val2) : "15", BRASLCLOBBER);
florianabbc9af2012-05-12 00:05:14 +0000153 return;
154}
155
156int main()
157{
158 compare_eq(-12, 42);
159 compare_eq(42, 42);
160 compare_eq(100, 42);
161
162 compare_ne(-12, 42);
163 compare_ne(42, 42);
164 compare_ne(100, 42);
165
166 compare_gt(-12, 42);
167 compare_gt(42, 42);
168 compare_gt(100, 42);
169
170 compare_lt(-12, 42);
171 compare_lt(42, 42);
172 compare_lt(100, 42);
173
174 compare_le(-12, 42);
175 compare_le(42, 42);
176 compare_le(100, 42);
177
178 compare_ge(-12, 42);
179 compare_ge(42, 42);
180 compare_ge(100, 42);
181
182 compare_never(-12, 42);
183 compare_never(42, 42);
184 compare_never(100, 42);
185
186 compare_always(-12, 42);
187 compare_always(42, 42);
188 compare_always(100, 42);
189
190 return 0;
191}