In some rare cases, the register allocator can spill registers but end up not utilizi...
[llvm/msp430.git] / test / CodeGen / CellSPU / useful-harnesses / i64operations.c
blobb613bd872e2875f38c6462cb38b8380d989b168f
1 #include <stdio.h>
2 #include "i64operations.h"
4 int64_t tval_a = 1234567890003LL;
5 int64_t tval_b = 2345678901235LL;
6 int64_t tval_c = 1234567890001LL;
7 int64_t tval_d = 10001LL;
8 int64_t tval_e = 10000LL;
9 uint64_t tval_f = 0xffffff0750135eb9;
10 int64_t tval_g = -1;
12 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
14 int
15 i64_eq(int64_t a, int64_t b)
17 return (a == b);
20 int
21 i64_neq(int64_t a, int64_t b)
23 return (a != b);
26 int
27 i64_gt(int64_t a, int64_t b)
29 return (a > b);
32 int
33 i64_le(int64_t a, int64_t b)
35 return (a <= b);
38 int
39 i64_ge(int64_t a, int64_t b) {
40 return (a >= b);
43 int
44 i64_lt(int64_t a, int64_t b) {
45 return (a < b);
48 int
49 i64_uge(uint64_t a, uint64_t b)
51 return (a >= b);
54 int
55 i64_ult(uint64_t a, uint64_t b)
57 return (a < b);
60 int
61 i64_ugt(uint64_t a, uint64_t b)
63 return (a > b);
66 int
67 i64_ule(uint64_t a, uint64_t b)
69 return (a <= b);
72 int64_t
73 i64_eq_select(int64_t a, int64_t b, int64_t c, int64_t d)
75 return ((a == b) ? c : d);
78 int64_t
79 i64_neq_select(int64_t a, int64_t b, int64_t c, int64_t d)
81 return ((a != b) ? c : d);
84 int64_t
85 i64_gt_select(int64_t a, int64_t b, int64_t c, int64_t d) {
86 return ((a > b) ? c : d);
89 int64_t
90 i64_le_select(int64_t a, int64_t b, int64_t c, int64_t d) {
91 return ((a <= b) ? c : d);
94 int64_t
95 i64_ge_select(int64_t a, int64_t b, int64_t c, int64_t d) {
96 return ((a >= b) ? c : d);
99 int64_t
100 i64_lt_select(int64_t a, int64_t b, int64_t c, int64_t d) {
101 return ((a < b) ? c : d);
104 uint64_t
105 i64_ugt_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d)
107 return ((a > b) ? c : d);
110 uint64_t
111 i64_ule_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d)
113 return ((a <= b) ? c : d);
116 uint64_t
117 i64_uge_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
118 return ((a >= b) ? c : d);
121 uint64_t
122 i64_ult_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
123 return ((a < b) ? c : d);
126 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
128 struct harness_int64_pred int64_tests_eq[] = {
129 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, TRUE_VAL, &tval_c},
130 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, FALSE_VAL, &tval_d},
131 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, FALSE_VAL, &tval_d},
132 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d},
133 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c}
136 struct harness_int64_pred int64_tests_neq[] = {
137 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, FALSE_VAL, &tval_d},
138 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, TRUE_VAL, &tval_c},
139 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, TRUE_VAL, &tval_c},
140 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c},
141 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d}
144 struct harness_int64_pred int64_tests_sgt[] = {
145 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, FALSE_VAL, &tval_d},
146 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, FALSE_VAL, &tval_d},
147 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, TRUE_VAL, &tval_c},
148 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c},
149 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d}
152 struct harness_int64_pred int64_tests_sle[] = {
153 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, TRUE_VAL, &tval_c},
154 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, TRUE_VAL, &tval_c},
155 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, FALSE_VAL, &tval_d},
156 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d},
157 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c}
160 struct harness_int64_pred int64_tests_sge[] = {
161 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, TRUE_VAL, &tval_c},
162 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, FALSE_VAL, &tval_d},
163 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, TRUE_VAL, &tval_c},
164 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c},
165 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, TRUE_VAL, &tval_c}
168 struct harness_int64_pred int64_tests_slt[] = {
169 {"a %s a", &tval_a, &tval_a, &tval_c, &tval_d, FALSE_VAL, &tval_d},
170 {"a %s b", &tval_a, &tval_b, &tval_c, &tval_d, TRUE_VAL, &tval_c},
171 {"a %s c", &tval_a, &tval_c, &tval_c, &tval_d, FALSE_VAL, &tval_d},
172 {"d %s e", &tval_d, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d},
173 {"e %s e", &tval_e, &tval_e, &tval_c, &tval_d, FALSE_VAL, &tval_d}
176 struct int64_pred_s int64_preds[] = {
177 {"eq", i64_eq, i64_eq_select,
178 int64_tests_eq, ARR_SIZE(int64_tests_eq)},
179 {"neq", i64_neq, i64_neq_select,
180 int64_tests_neq, ARR_SIZE(int64_tests_neq)},
181 {"gt", i64_gt, i64_gt_select,
182 int64_tests_sgt, ARR_SIZE(int64_tests_sgt)},
183 {"le", i64_le, i64_le_select,
184 int64_tests_sle, ARR_SIZE(int64_tests_sle)},
185 {"ge", i64_ge, i64_ge_select,
186 int64_tests_sge, ARR_SIZE(int64_tests_sge)},
187 {"lt", i64_lt, i64_lt_select,
188 int64_tests_slt, ARR_SIZE(int64_tests_slt)}
191 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
193 struct harness_uint64_pred uint64_tests_ugt[] = {
194 {"a %s a", (uint64_t *) &tval_a, (uint64_t *) &tval_a, (uint64_t *) &tval_c,
195 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
196 {"a %s b", (uint64_t *) &tval_a, (uint64_t *) &tval_b, (uint64_t *) &tval_c,
197 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d },
198 {"a %s c", (uint64_t *) &tval_a, (uint64_t *) &tval_c, (uint64_t *) &tval_c,
199 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c },
200 {"d %s e", (uint64_t *) &tval_d, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
201 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c },
202 {"e %s e", (uint64_t *) &tval_e, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
203 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d }
206 struct harness_uint64_pred uint64_tests_ule[] = {
207 {"a %s a", (uint64_t *) &tval_a, (uint64_t *) &tval_a, (uint64_t *) &tval_c,
208 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
209 {"a %s b", (uint64_t *) &tval_a, (uint64_t *) &tval_b, (uint64_t *) &tval_c,
210 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
211 {"a %s c", (uint64_t *) &tval_a, (uint64_t *) &tval_c, (uint64_t *) &tval_c,
212 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
213 {"d %s e", (uint64_t *) &tval_d, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
214 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
215 {"e %s e", (uint64_t *) &tval_e, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
216 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c}
219 struct harness_uint64_pred uint64_tests_uge[] = {
220 {"a %s a", (uint64_t *) &tval_a, (uint64_t *) &tval_a, (uint64_t *) &tval_c,
221 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
222 {"a %s b", (uint64_t *) &tval_a, (uint64_t *) &tval_b, (uint64_t *) &tval_c,
223 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
224 {"a %s c", (uint64_t *) &tval_a, (uint64_t *) &tval_c, (uint64_t *) &tval_c,
225 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
226 {"d %s e", (uint64_t *) &tval_d, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
227 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
228 {"e %s e", (uint64_t *) &tval_e, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
229 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c}
232 struct harness_uint64_pred uint64_tests_ult[] = {
233 {"a %s a", (uint64_t *) &tval_a, (uint64_t *) &tval_a, (uint64_t *) &tval_c,
234 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
235 {"a %s b", (uint64_t *) &tval_a, (uint64_t *) &tval_b, (uint64_t *) &tval_c,
236 (uint64_t *) &tval_d, TRUE_VAL, (uint64_t *) &tval_c},
237 {"a %s c", (uint64_t *) &tval_a, (uint64_t *) &tval_c, (uint64_t *) &tval_c,
238 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
239 {"d %s e", (uint64_t *) &tval_d, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
240 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d},
241 {"e %s e", (uint64_t *) &tval_e, (uint64_t *) &tval_e, (uint64_t *) &tval_c,
242 (uint64_t *) &tval_d, FALSE_VAL, (uint64_t *) &tval_d}
245 struct uint64_pred_s uint64_preds[] = {
246 {"ugt", i64_ugt, i64_ugt_select,
247 uint64_tests_ugt, ARR_SIZE(uint64_tests_ugt)},
248 {"ule", i64_ule, i64_ule_select,
249 uint64_tests_ule, ARR_SIZE(uint64_tests_ule)},
250 {"uge", i64_uge, i64_uge_select,
251 uint64_tests_uge, ARR_SIZE(uint64_tests_uge)},
252 {"ult", i64_ult, i64_ult_select,
253 uint64_tests_ult, ARR_SIZE(uint64_tests_ult)}
257 compare_expect_int64(const struct int64_pred_s * pred)
259 int j, failed = 0;
261 for (j = 0; j < pred->n_tests; ++j) {
262 int pred_result;
264 pred_result = (*pred->predfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs);
266 if (pred_result != pred->tests[j].expected) {
267 char str[64];
269 sprintf(str, pred->tests[j].fmt_string, pred->name);
270 printf("%s: returned value is %d, expecting %d\n", str,
271 pred_result, pred->tests[j].expected);
272 printf(" lhs = %19lld (0x%016llx)\n", *pred->tests[j].lhs,
273 *pred->tests[j].lhs);
274 printf(" rhs = %19lld (0x%016llx)\n", *pred->tests[j].rhs,
275 *pred->tests[j].rhs);
276 ++failed;
277 } else {
278 int64_t selresult;
280 selresult = (pred->selfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs,
281 *pred->tests[j].select_a,
282 *pred->tests[j].select_b);
284 if (selresult != *pred->tests[j].select_expected) {
285 char str[64];
287 sprintf(str, pred->tests[j].fmt_string, pred->name);
288 printf("%s select: returned value is %d, expecting %d\n", str,
289 pred_result, pred->tests[j].expected);
290 printf(" lhs = %19lld (0x%016llx)\n", *pred->tests[j].lhs,
291 *pred->tests[j].lhs);
292 printf(" rhs = %19lld (0x%016llx)\n", *pred->tests[j].rhs,
293 *pred->tests[j].rhs);
294 printf(" true = %19lld (0x%016llx)\n", *pred->tests[j].select_a,
295 *pred->tests[j].select_a);
296 printf(" false = %19lld (0x%016llx)\n", *pred->tests[j].select_b,
297 *pred->tests[j].select_b);
298 ++failed;
303 printf(" %d tests performed, should be %d.\n", j, pred->n_tests);
305 return failed;
309 compare_expect_uint64(const struct uint64_pred_s * pred)
311 int j, failed = 0;
313 for (j = 0; j < pred->n_tests; ++j) {
314 int pred_result;
316 pred_result = (*pred->predfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs);
317 if (pred_result != pred->tests[j].expected) {
318 char str[64];
320 sprintf(str, pred->tests[j].fmt_string, pred->name);
321 printf("%s: returned value is %d, expecting %d\n", str,
322 pred_result, pred->tests[j].expected);
323 printf(" lhs = %19llu (0x%016llx)\n", *pred->tests[j].lhs,
324 *pred->tests[j].lhs);
325 printf(" rhs = %19llu (0x%016llx)\n", *pred->tests[j].rhs,
326 *pred->tests[j].rhs);
327 ++failed;
328 } else {
329 uint64_t selresult;
331 selresult = (pred->selfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs,
332 *pred->tests[j].select_a,
333 *pred->tests[j].select_b);
334 if (selresult != *pred->tests[j].select_expected) {
335 char str[64];
337 sprintf(str, pred->tests[j].fmt_string, pred->name);
338 printf("%s select: returned value is %d, expecting %d\n", str,
339 pred_result, pred->tests[j].expected);
340 printf(" lhs = %19llu (0x%016llx)\n", *pred->tests[j].lhs,
341 *pred->tests[j].lhs);
342 printf(" rhs = %19llu (0x%016llx)\n", *pred->tests[j].rhs,
343 *pred->tests[j].rhs);
344 printf(" true = %19llu (0x%016llx)\n", *pred->tests[j].select_a,
345 *pred->tests[j].select_a);
346 printf(" false = %19llu (0x%016llx)\n", *pred->tests[j].select_b,
347 *pred->tests[j].select_b);
348 ++failed;
353 printf(" %d tests performed, should be %d.\n", j, pred->n_tests);
355 return failed;
358 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
361 test_i64_sext_i32(int in, int64_t expected) {
362 int64_t result = (int64_t) in;
364 if (result != expected) {
365 char str[64];
366 sprintf(str, "i64_sext_i32(%d) returns %lld\n", in, result);
367 return 1;
370 return 0;
374 test_i64_sext_i16(short in, int64_t expected) {
375 int64_t result = (int64_t) in;
377 if (result != expected) {
378 char str[64];
379 sprintf(str, "i64_sext_i16(%hd) returns %lld\n", in, result);
380 return 1;
383 return 0;
387 test_i64_sext_i8(signed char in, int64_t expected) {
388 int64_t result = (int64_t) in;
390 if (result != expected) {
391 char str[64];
392 sprintf(str, "i64_sext_i8(%d) returns %lld\n", in, result);
393 return 1;
396 return 0;
400 test_i64_zext_i32(unsigned int in, uint64_t expected) {
401 uint64_t result = (uint64_t) in;
403 if (result != expected) {
404 char str[64];
405 sprintf(str, "i64_zext_i32(%u) returns %llu\n", in, result);
406 return 1;
409 return 0;
413 test_i64_zext_i16(unsigned short in, uint64_t expected) {
414 uint64_t result = (uint64_t) in;
416 if (result != expected) {
417 char str[64];
418 sprintf(str, "i64_zext_i16(%hu) returns %llu\n", in, result);
419 return 1;
422 return 0;
426 test_i64_zext_i8(unsigned char in, uint64_t expected) {
427 uint64_t result = (uint64_t) in;
429 if (result != expected) {
430 char str[64];
431 sprintf(str, "i64_zext_i8(%u) returns %llu\n", in, result);
432 return 1;
435 return 0;
438 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
440 int64_t
441 i64_shl_const(int64_t a) {
442 return a << 10;
445 int64_t
446 i64_shl(int64_t a, int amt) {
447 return a << amt;
450 uint64_t
451 u64_shl_const(uint64_t a) {
452 return a << 10;
455 uint64_t
456 u64_shl(uint64_t a, int amt) {
457 return a << amt;
460 int64_t
461 i64_srl_const(int64_t a) {
462 return a >> 10;
465 int64_t
466 i64_srl(int64_t a, int amt) {
467 return a >> amt;
470 uint64_t
471 u64_srl_const(uint64_t a) {
472 return a >> 10;
475 uint64_t
476 u64_srl(uint64_t a, int amt) {
477 return a >> amt;
480 int64_t
481 i64_sra_const(int64_t a) {
482 return a >> 10;
485 int64_t
486 i64_sra(int64_t a, int amt) {
487 return a >> amt;
490 uint64_t
491 u64_sra_const(uint64_t a) {
492 return a >> 10;
495 uint64_t
496 u64_sra(uint64_t a, int amt) {
497 return a >> amt;
501 test_u64_constant_shift(const char *func_name, uint64_t (*func)(uint64_t), uint64_t a, uint64_t expected) {
502 uint64_t result = (*func)(a);
504 if (result != expected) {
505 printf("%s(0x%016llx) returns 0x%016llx, expected 0x%016llx\n", func_name, a, result, expected);
506 return 1;
509 return 0;
513 test_i64_constant_shift(const char *func_name, int64_t (*func)(int64_t), int64_t a, int64_t expected) {
514 int64_t result = (*func)(a);
516 if (result != expected) {
517 printf("%s(0x%016llx) returns 0x%016llx, expected 0x%016llx\n", func_name, a, result, expected);
518 return 1;
521 return 0;
525 test_u64_variable_shift(const char *func_name, uint64_t (*func)(uint64_t, int), uint64_t a, unsigned int b, uint64_t expected) {
526 uint64_t result = (*func)(a, b);
528 if (result != expected) {
529 printf("%s(0x%016llx, %d) returns 0x%016llx, expected 0x%016llx\n", func_name, a, b, result, expected);
530 return 1;
533 return 0;
537 test_i64_variable_shift(const char *func_name, int64_t (*func)(int64_t, int), int64_t a, unsigned int b, int64_t expected) {
538 int64_t result = (*func)(a, b);
540 if (result != expected) {
541 printf("%s(0x%016llx, %d) returns 0x%016llx, expected 0x%016llx\n", func_name, a, b, result, expected);
542 return 1;
545 return 0;
548 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
550 int64_t i64_mul(int64_t a, int64_t b) {
551 return a * b;
554 /* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */
557 main(void)
559 int i, j, failed = 0;
560 const char *something_failed = " %d tests failed.\n";
561 const char *all_tests_passed = " All tests passed.\n";
563 printf("tval_a = %20lld (0x%016llx)\n", tval_a, tval_a);
564 printf("tval_b = %20lld (0x%016llx)\n", tval_b, tval_b);
565 printf("tval_c = %20lld (0x%016llx)\n", tval_c, tval_c);
566 printf("tval_d = %20lld (0x%016llx)\n", tval_d, tval_d);
567 printf("tval_e = %20lld (0x%016llx)\n", tval_e, tval_e);
568 printf("tval_f = %20llu (0x%016llx)\n", tval_f, tval_f);
569 printf("tval_g = %20llu (0x%016llx)\n", tval_g, tval_g);
570 printf("----------------------------------------\n");
572 for (i = 0; i < ARR_SIZE(int64_preds); ++i) {
573 printf("%s series:\n", int64_preds[i].name);
574 if ((failed = compare_expect_int64(int64_preds + i)) > 0) {
575 printf(something_failed, failed);
576 } else {
577 printf(all_tests_passed);
580 printf("----------------------------------------\n");
583 for (i = 0; i < ARR_SIZE(uint64_preds); ++i) {
584 printf("%s series:\n", uint64_preds[i].name);
585 if ((failed = compare_expect_uint64(uint64_preds + i)) > 0) {
586 printf(something_failed, failed);
587 } else {
588 printf(all_tests_passed);
591 printf("----------------------------------------\n");
594 /*----------------------------------------------------------------------*/
596 puts("signed/zero-extend tests:");
598 failed = 0;
599 failed += test_i64_sext_i32(-1, -1LL);
600 failed += test_i64_sext_i32(10, 10LL);
601 failed += test_i64_sext_i32(0x7fffffff, 0x7fffffffLL);
602 failed += test_i64_sext_i16(-1, -1LL);
603 failed += test_i64_sext_i16(10, 10LL);
604 failed += test_i64_sext_i16(0x7fff, 0x7fffLL);
605 failed += test_i64_sext_i8(-1, -1LL);
606 failed += test_i64_sext_i8(10, 10LL);
607 failed += test_i64_sext_i8(0x7f, 0x7fLL);
609 failed += test_i64_zext_i32(0xffffffff, 0x00000000ffffffffLLU);
610 failed += test_i64_zext_i32(0x01234567, 0x0000000001234567LLU);
611 failed += test_i64_zext_i16(0xffff, 0x000000000000ffffLLU);
612 failed += test_i64_zext_i16(0x569a, 0x000000000000569aLLU);
613 failed += test_i64_zext_i8(0xff, 0x00000000000000ffLLU);
614 failed += test_i64_zext_i8(0xa0, 0x00000000000000a0LLU);
616 if (failed > 0) {
617 printf(" %d tests failed.\n", failed);
618 } else {
619 printf(" All tests passed.\n");
622 printf("----------------------------------------\n");
624 failed = 0;
625 puts("signed left/right shift tests:");
626 failed += test_i64_constant_shift("i64_shl_const", i64_shl_const, tval_a, 0x00047dc7ec114c00LL);
627 failed += test_i64_variable_shift("i64_shl", i64_shl, tval_a, 10, 0x00047dc7ec114c00LL);
628 failed += test_i64_constant_shift("i64_srl_const", i64_srl_const, tval_a, 0x0000000047dc7ec1LL);
629 failed += test_i64_variable_shift("i64_srl", i64_srl, tval_a, 10, 0x0000000047dc7ec1LL);
630 failed += test_i64_constant_shift("i64_sra_const", i64_sra_const, tval_a, 0x0000000047dc7ec1LL);
631 failed += test_i64_variable_shift("i64_sra", i64_sra, tval_a, 10, 0x0000000047dc7ec1LL);
633 if (failed > 0) {
634 printf(" %d tests ailed.\n", failed);
635 } else {
636 printf(" All tests passed.\n");
639 printf("----------------------------------------\n");
641 failed = 0;
642 puts("unsigned left/right shift tests:");
643 failed += test_u64_constant_shift("u64_shl_const", u64_shl_const, tval_f, 0xfffc1d404d7ae400LL);
644 failed += test_u64_variable_shift("u64_shl", u64_shl, tval_f, 10, 0xfffc1d404d7ae400LL);
645 failed += test_u64_constant_shift("u64_srl_const", u64_srl_const, tval_f, 0x003fffffc1d404d7LL);
646 failed += test_u64_variable_shift("u64_srl", u64_srl, tval_f, 10, 0x003fffffc1d404d7LL);
647 failed += test_i64_constant_shift("i64_sra_const", i64_sra_const, tval_f, 0xffffffffc1d404d7LL);
648 failed += test_i64_variable_shift("i64_sra", i64_sra, tval_f, 10, 0xffffffffc1d404d7LL);
649 failed += test_u64_constant_shift("u64_sra_const", u64_sra_const, tval_f, 0x003fffffc1d404d7LL);
650 failed += test_u64_variable_shift("u64_sra", u64_sra, tval_f, 10, 0x003fffffc1d404d7LL);
652 if (failed > 0) {
653 printf(" %d tests ailed.\n", failed);
654 } else {
655 printf(" All tests passed.\n");
658 printf("----------------------------------------\n");
660 int64_t result;
662 result = i64_mul(tval_g, tval_g);
663 printf("%20lld * %20lld = %20lld (0x%016llx)\n", tval_g, tval_g, result, result);
664 result = i64_mul(tval_d, tval_e);
665 printf("%20lld * %20lld = %20lld (0x%016llx)\n", tval_d, tval_e, result, result);
666 /* 0xba7a664f13077c9 */
667 result = i64_mul(tval_a, tval_b);
668 printf("%20lld * %20lld = %20lld (0x%016llx)\n", tval_a, tval_b, result, result);
670 printf("----------------------------------------\n");
672 return 0;