1 /* Test unsigned integer comparison ops
2 clr, clgr, clgfr, cl, clg, clgf, clfi, clgfi
3
4 missing: cly, clrl, clgrl, clgfrl
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <inttypes.h>
10 #include <limits.h>
11 #include "opcodes.h"
12
13 #undef RIL_RU
14 #define RIL_RU(op1,r1,op2,i2) \
15 ".short 0x" #op1 #r1 #op2 "\n\t" \
16 ".long " #i2 "\n\t"
17
18
19 /* Perform a single unsigned comparison
20 Both operands in register */
21 #define SCOMP_REG_REG(insn, v1, v2) \
22 ({ \
23 int cc; \
24 uint64_t op1 = v1; \
25 uint64_t op2 = v2; \
26 asm volatile( #insn " %1, %2\n\t" \
27 "ipm %0\n\t" \
28 "srl %0,28\n\t" \
29 : "=d" (cc) \
30 : "d" (op1), "d" (op2) \
31 : "cc"); \
32 printf("%.6s (%"PRIu64", %"PRIu64") --> cc = %d\n", \
33 #insn, op1, op2, cc); \
34 })
35
36 /* Perform a single unsigned comparison
37 Left operand in register, right operand in memory */
38 #define SCOMP_REG_MEM(insn, v1, v2, op2_t) \
39 ({ \
40 int cc; \
41 uint64_t op1 = v1; \
42 op2_t op2 = v2; \
43 asm volatile( #insn " %1, %2\n\t" \
44 "ipm %0\n\t" \
45 "srl %0,28\n\t" \
46 : "=d" (cc) \
47 : "d" (op1), "Q" (op2) \
48 : "cc"); \
49 printf("%.6s (%"PRIu64", %"PRIu64") --> cc = %d\n", \
50 #insn, op1, (uint64_t)op2, cc); \
51 })
52
53 /* Perform a single unsigned comparison
54 Left operand in register, right operand is an immediate constant */
55 #define SCOMP_REG_IMM(insn, v1, v2) \
56 ({ \
57 int cc; \
58 register uint64_t op1 asm("8") = v1; \
59 asm volatile( insn(8, v2) \
60 "ipm %0\n\t" \
61 "srl %0,28\n\t" \
62 : "=d" (cc) \
63 : "d" (op1) \
64 : "cc"); \
65 printf("%.6s (%"PRIu64", %"PRIu64") --> cc = %d\n", \
66 #insn, op1, (uint64_t)v2, cc); \
67 })
68
69 /* Run a sequence of unsigned comparisons for a given insn */
70 #define run_scomp_reg_reg(insn) \
71 ({ \
72 SCOMP_REG_REG(insn, 0, 0); \
73 SCOMP_REG_REG(insn, 0, 1); \
74 SCOMP_REG_REG(insn, 1, 0); \
75 SCOMP_REG_REG(insn, 2, 1); \
76 SCOMP_REG_REG(insn, 2, 2); \
77 SCOMP_REG_REG(insn, 2, 3); \
78 SCOMP_REG_REG(insn, 0, INT8_MAX); \
79 SCOMP_REG_REG(insn, INT8_MAX, 0); \
80 SCOMP_REG_REG(insn, INT8_MAX, INT8_MAX-1); \
81 SCOMP_REG_REG(insn, INT8_MAX, INT8_MAX); \
82 SCOMP_REG_REG(insn, 0, INT16_MAX); \
83 SCOMP_REG_REG(insn, INT16_MAX, 0); \
84 SCOMP_REG_REG(insn, INT16_MAX, INT16_MAX); \
85 SCOMP_REG_REG(insn, INT16_MAX, INT16_MAX-1); \
86 SCOMP_REG_REG(insn, 0, INT32_MAX); \
87 SCOMP_REG_REG(insn, INT32_MAX, 0); \
88 SCOMP_REG_REG(insn, INT32_MAX, INT32_MAX); \
89 SCOMP_REG_REG(insn, INT32_MAX, INT32_MAX-1); \
90 })
91
92 /* Run a sequence of signed comparisons for a given insn */
93 #define run_scomp_reg_mem(insn, op2_t) \
94 ({ \
95 SCOMP_REG_MEM(insn, 0, 0, op2_t); \
96 SCOMP_REG_MEM(insn, 0, 1, op2_t); \
97 SCOMP_REG_MEM(insn, 1, 0, op2_t); \
98 SCOMP_REG_MEM(insn, 2, 1, op2_t); \
99 SCOMP_REG_MEM(insn, 2, 2, op2_t); \
100 SCOMP_REG_MEM(insn, 2, 3, op2_t); \
101 SCOMP_REG_MEM(insn, 0, INT8_MAX, op2_t); \
102 SCOMP_REG_MEM(insn, INT8_MAX, 0, op2_t); \
103 SCOMP_REG_MEM(insn, INT8_MAX, INT8_MAX-1, op2_t); \
104 SCOMP_REG_MEM(insn, INT8_MAX, INT8_MAX, op2_t); \
105 SCOMP_REG_MEM(insn, 0, INT16_MAX, op2_t); \
106 SCOMP_REG_MEM(insn, INT16_MAX, 0, op2_t); \
107 SCOMP_REG_MEM(insn, INT16_MAX, INT16_MAX-1, op2_t); \
108 SCOMP_REG_MEM(insn, INT16_MAX, INT16_MAX, op2_t); \
109 SCOMP_REG_MEM(insn, 0, INT32_MAX, op2_t); \
110 SCOMP_REG_MEM(insn, INT32_MAX, 0, op2_t); \
111 SCOMP_REG_MEM(insn, INT32_MAX, INT32_MAX-1, op2_t); \
112 SCOMP_REG_MEM(insn, INT32_MAX, INT32_MAX, op2_t); \
113 })
114
115 /* Run a sequence of signed comparisons for a given insn */
116 #define run_scomp_reg_imm(insn) \
117 ({ \
118 SCOMP_REG_IMM(insn, 0, 0); \
119 SCOMP_REG_IMM(insn, 0, 1); \
120 SCOMP_REG_IMM(insn, 1, 0); \
121 SCOMP_REG_IMM(insn, 2, 1); \
122 SCOMP_REG_IMM(insn, 2, 2); \
123 SCOMP_REG_IMM(insn, 2, 3); \
124 SCOMP_REG_IMM(insn, INT8_MAX, 0); \
125 SCOMP_REG_IMM(insn, INT8_MAX, INT8_MAX-1); \
126 SCOMP_REG_IMM(insn, INT8_MAX, INT8_MAX); \
127 SCOMP_REG_IMM(insn, 0, INT16_MAX); \
128 SCOMP_REG_IMM(insn, INT16_MAX, 0); \
129 SCOMP_REG_IMM(insn, INT16_MAX, INT16_MAX); \
130 SCOMP_REG_IMM(insn, INT16_MAX, INT16_MAX-1); \
131 SCOMP_REG_IMM(insn, 0, INT32_MAX); \
132 SCOMP_REG_IMM(insn, INT32_MAX, 0); \
133 SCOMP_REG_IMM(insn, INT32_MAX, INT32_MAX); \
134 SCOMP_REG_IMM(insn, INT32_MAX, INT32_MAX-1); \
135 })
136
137 void
signed_comparison_reg_reg(void)138 signed_comparison_reg_reg(void)
139 {
140 run_scomp_reg_reg(clr);
141
142 run_scomp_reg_reg(clgr);
143 /* Special cases for clgr */
144 SCOMP_REG_REG(clgr, INT64_MIN, INT64_MIN);
145 SCOMP_REG_REG(clgr, INT64_MIN, INT64_MAX);
146 SCOMP_REG_REG(clgr, INT64_MAX, INT64_MIN);
147 SCOMP_REG_REG(clgr, INT64_MAX, INT64_MAX);
148
149 run_scomp_reg_reg(clgfr);
150 /* Special cases for clgfr */
151 SCOMP_REG_REG(clgfr, INT64_MIN, INT32_MIN);
152 SCOMP_REG_REG(clgfr, INT64_MIN, INT32_MAX);
153 SCOMP_REG_REG(clgfr, INT64_MAX, INT32_MIN);
154 SCOMP_REG_REG(clgfr, INT64_MAX, INT32_MAX);
155 }
156
157 void
signed_comparison_reg_mem(void)158 signed_comparison_reg_mem(void)
159 {
160 run_scomp_reg_mem(cl, int32_t);
161
162 run_scomp_reg_mem(clg, int64_t);
163 /* Special cases for clg */
164 SCOMP_REG_MEM(clg, INT64_MIN, INT64_MIN, int64_t);
165 SCOMP_REG_MEM(clg, INT64_MIN, INT64_MAX, int64_t);
166 SCOMP_REG_MEM(clg, INT64_MAX, INT64_MIN, int64_t);
167 SCOMP_REG_MEM(clg, INT64_MAX, INT64_MAX, int64_t);
168
169 run_scomp_reg_mem(clgf, int32_t);
170 /* Special cases for clgf */
171 SCOMP_REG_MEM(clgf, INT64_MIN, INT32_MIN, int32_t);
172 SCOMP_REG_MEM(clgf, INT64_MIN, INT32_MAX, int32_t);
173 SCOMP_REG_MEM(clgf, INT64_MAX, INT32_MIN, int32_t);
174 SCOMP_REG_MEM(clgf, INT64_MAX, INT32_MAX, int32_t);
175 }
176
177 void
signed_comparison_reg_imm(void)178 signed_comparison_reg_imm(void)
179 {
180 run_scomp_reg_imm(CLFI);
181
182 run_scomp_reg_imm(CLGFI);
183 /* Special cases for clgfi */
184 SCOMP_REG_IMM(CLGFI, INT64_MIN, INT32_MIN);
185 SCOMP_REG_IMM(CLGFI, INT64_MIN, INT32_MAX);
186 SCOMP_REG_IMM(CLGFI, INT64_MAX, INT32_MIN);
187 SCOMP_REG_IMM(CLGFI, INT64_MAX, INT32_MAX);
188 }
189
190
main(void)191 int main(void)
192 {
193 signed_comparison_reg_reg();
194 signed_comparison_reg_mem();
195 signed_comparison_reg_imm();
196
197 return 0;
198 }
199