5 #define DEFINE_SHIFT_SINGLE_COMMON(_name, _insn_str) \
6 static uint64_t _name(uint64_t op1, uint64_t op2, uint64_t *cc) \
8 asm(" sll %[cc],28\n" \
13 : [op1] "+&r" (op1), \
19 #define DEFINE_SHIFT_SINGLE_2(_insn, _offset) \
20 DEFINE_SHIFT_SINGLE_COMMON(_insn ## _ ## _offset, \
21 #_insn " %[op1]," #_offset "(%[op2])")
22 #define DEFINE_SHIFT_SINGLE_3(_insn, _offset) \
23 DEFINE_SHIFT_SINGLE_COMMON(_insn ## _ ## _offset, \
24 #_insn " %[op1],%[op1]," #_offset "(%[op2])")
25 #define DEFINE_SHIFT_DOUBLE(_insn, _offset) \
26 static uint64_t _insn ## _ ## _offset(uint64_t op1, uint64_t op2, \
29 uint32_t op1h = op1 >> 32; \
30 uint32_t op1l = op1 & 0xffffffff; \
31 register uint32_t r2 asm("2") = op1h; \
32 register uint32_t r3 asm("3") = op1l; \
34 asm(" sll %[cc],28\n" \
36 " " #_insn " %[r2]," #_offset "(%[op2])\n" \
46 return (((uint64_t)op1h) << 32) | op1l; \
49 DEFINE_SHIFT_SINGLE_3(rll
, 0x4cf3b);
50 DEFINE_SHIFT_SINGLE_3(rllg
, 0x697c9);
51 DEFINE_SHIFT_SINGLE_2(sla
, 0x4b0);
52 DEFINE_SHIFT_SINGLE_2(sla
, 0xd54);
53 DEFINE_SHIFT_SINGLE_3(slak
, 0x2832c);
54 DEFINE_SHIFT_SINGLE_3(slag
, 0x66cc4);
55 DEFINE_SHIFT_SINGLE_3(slag
, 0xd54);
56 DEFINE_SHIFT_SINGLE_2(sll
, 0xd04);
57 DEFINE_SHIFT_SINGLE_3(sllk
, 0x2699f);
58 DEFINE_SHIFT_SINGLE_3(sllg
, 0x59df9);
59 DEFINE_SHIFT_SINGLE_2(sra
, 0x67e);
60 DEFINE_SHIFT_SINGLE_3(srak
, 0x60943);
61 DEFINE_SHIFT_SINGLE_3(srag
, 0x6b048);
62 DEFINE_SHIFT_SINGLE_2(srl
, 0x035);
63 DEFINE_SHIFT_SINGLE_3(srlk
, 0x43dfc);
64 DEFINE_SHIFT_SINGLE_3(srlg
, 0x27227);
65 DEFINE_SHIFT_DOUBLE(slda
, 0x38b);
66 DEFINE_SHIFT_DOUBLE(sldl
, 0x031);
67 DEFINE_SHIFT_DOUBLE(srda
, 0x36f);
68 DEFINE_SHIFT_DOUBLE(srdl
, 0x99a);
72 uint64_t (*insn
)(uint64_t, uint64_t, uint64_t *);
79 static const struct shift_test tests
[] = {
83 .op1
= 0xecbd589a45c248f5ull
,
84 .op2
= 0x62e5508ccb4c99fdull
,
85 .exp_result
= 0xecbd589af545c248ull
,
91 .op1
= 0xaa2d54c1b729f7f4ull
,
92 .op2
= 0x5ffcf7465f5cd71full
,
93 .exp_result
= 0x29f7f4aa2d54c1b7ull
,
99 .op1
= 0x8bf21fb67cca0e96ull
,
100 .op2
= 0x3ddf2f53347d3030ull
,
101 .exp_result
= 0x8bf21fb600000000ull
,
107 .op1
= 0xe4faaed5def0e926ull
,
108 .op2
= 0x18d586fab239cbeeull
,
109 .exp_result
= 0xe4faaed5fbc3a498ull
,
114 .insn
= slak_0x2832c
,
115 .op1
= 0x7300bf78707f09f9ull
,
116 .op2
= 0x4d193b85bb5cb39bull
,
117 .exp_result
= 0x7300bf783f84fc80ull
,
122 .insn
= slag_0x66cc4
,
123 .op1
= 0xe805966de1a77762ull
,
124 .op2
= 0x0e92953f6aa91c6bull
,
125 .exp_result
= 0xbbb1000000000000ull
,
131 .op1
= 0xdef0e92600000000ull
,
132 .op2
= 0x18d586fab239cbeeull
,
133 .exp_result
= 0xfbc3a49800000000ull
,
139 .op1
= 0xb90281a3105939dfull
,
140 .op2
= 0xb5e4df7e082e4c5eull
,
141 .exp_result
= 0xb90281a300000000ull
,
146 .insn
= sllk_0x2699f
,
147 .op1
= 0x777c6cf116f99557ull
,
148 .op2
= 0xe0556cf112e5a458ull
,
149 .exp_result
= 0x777c6cf100000000ull
,
154 .insn
= sllg_0x59df9
,
155 .op1
= 0xcdf86cbfbc0f3557ull
,
156 .op2
= 0x325a45acf99c6d3dull
,
157 .exp_result
= 0x55c0000000000000ull
,
163 .op1
= 0xb878f048d5354183ull
,
164 .op2
= 0x9e27d13195931f79ull
,
165 .exp_result
= 0xb878f048ffffffffull
,
170 .insn
= srak_0x60943
,
171 .op1
= 0xb6ceb5a429cedb35ull
,
172 .op2
= 0x352354900ae34d7aull
,
173 .exp_result
= 0xb6ceb5a400000000ull
,
178 .insn
= srag_0x6b048
,
179 .op1
= 0xd54dd4468676c63bull
,
180 .op2
= 0x84d026db7b4dca28ull
,
181 .exp_result
= 0xffffffffffffd54dull
,
187 .op1
= 0x09be503ef826815full
,
188 .op2
= 0xbba8d1a0e542d5c1ull
,
189 .exp_result
= 0x9be503e00000000ull
,
194 .insn
= srlk_0x43dfc
,
195 .op1
= 0x540d6c8de71aee2aull
,
196 .op2
= 0x0000000000000000ull
,
197 .exp_result
= 0x540d6c8d00000000ull
,
202 .insn
= srlg_0x27227
,
203 .op1
= 0x26f7123c1c447a34ull
,
204 .op2
= 0x0000000000000000ull
,
205 .exp_result
= 0x00000000004dee24ull
,
211 .op1
= 0x7988f722dd5bbe7cull
,
212 .op2
= 0x9aed3f95b4d78cc2ull
,
213 .exp_result
= 0x1ee45bab77cf8000ull
,
219 .op1
= 0xaae2918dce2b049aull
,
220 .op2
= 0x0000000000000000ull
,
221 .exp_result
= 0x0934000000000000ull
,
227 .op1
= 0x0cd4ed9228a50978ull
,
228 .op2
= 0x72b046f0848b8cc9ull
,
229 .exp_result
= 0x000000000000000cull
,
235 .op1
= 0x1018611c41689a1dull
,
236 .op2
= 0x2907e150c50ba319ull
,
237 .exp_result
= 0x0000000000000203ull
,
247 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++) {
251 result
= tests
[i
].insn(tests
[i
].op1
, tests
[i
].op2
, &cc
);
252 if (result
!= tests
[i
].exp_result
) {
255 "actual = 0x%" PRIx64
"\n"
256 "expected = 0x%" PRIx64
"\n",
257 tests
[i
].name
, result
, tests
[i
].exp_result
);
260 if (cc
!= tests
[i
].exp_cc
) {
263 "actual = %" PRIu64
"\n"
264 "expected = %" PRIu64
"\n",
265 tests
[i
].name
, cc
, tests
[i
].exp_cc
);