1#include <stdio.h> 2#include "i64operations.h" 3 4int64_t tval_a = 1234567890003LL; 5int64_t tval_b = 2345678901235LL; 6int64_t tval_c = 1234567890001LL; 7int64_t tval_d = 10001LL; 8int64_t tval_e = 10000LL; 9uint64_t tval_f = 0xffffff0750135eb9; 10int64_t tval_g = -1; 11 12/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 13 14int 15i64_eq(int64_t a, int64_t b) 16{ 17 return (a == b); 18} 19 20int 21i64_neq(int64_t a, int64_t b) 22{ 23 return (a != b); 24} 25 26int 27i64_gt(int64_t a, int64_t b) 28{ 29 return (a > b); 30} 31 32int 33i64_le(int64_t a, int64_t b) 34{ 35 return (a <= b); 36} 37 38int 39i64_ge(int64_t a, int64_t b) { 40 return (a >= b); 41} 42 43int 44i64_lt(int64_t a, int64_t b) { 45 return (a < b); 46} 47 48int 49i64_uge(uint64_t a, uint64_t b) 50{ 51 return (a >= b); 52} 53 54int 55i64_ult(uint64_t a, uint64_t b) 56{ 57 return (a < b); 58} 59 60int 61i64_ugt(uint64_t a, uint64_t b) 62{ 63 return (a > b); 64} 65 66int 67i64_ule(uint64_t a, uint64_t b) 68{ 69 return (a <= b); 70} 71 72int64_t 73i64_eq_select(int64_t a, int64_t b, int64_t c, int64_t d) 74{ 75 return ((a == b) ? c : d); 76} 77 78int64_t 79i64_neq_select(int64_t a, int64_t b, int64_t c, int64_t d) 80{ 81 return ((a != b) ? c : d); 82} 83 84int64_t 85i64_gt_select(int64_t a, int64_t b, int64_t c, int64_t d) { 86 return ((a > b) ? c : d); 87} 88 89int64_t 90i64_le_select(int64_t a, int64_t b, int64_t c, int64_t d) { 91 return ((a <= b) ? c : d); 92} 93 94int64_t 95i64_ge_select(int64_t a, int64_t b, int64_t c, int64_t d) { 96 return ((a >= b) ? c : d); 97} 98 99int64_t 100i64_lt_select(int64_t a, int64_t b, int64_t c, int64_t d) { 101 return ((a < b) ? c : d); 102} 103 104uint64_t 105i64_ugt_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) 106{ 107 return ((a > b) ? c : d); 108} 109 110uint64_t 111i64_ule_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) 112{ 113 return ((a <= b) ? c : d); 114} 115 116uint64_t 117i64_uge_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) { 118 return ((a >= b) ? c : d); 119} 120 121uint64_t 122i64_ult_select(uint64_t a, uint64_t b, uint64_t c, uint64_t d) { 123 return ((a < b) ? c : d); 124} 125 126/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 127 128struct 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} 134}; 135 136struct 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} 142}; 143 144struct 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} 150}; 151 152struct 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} 158}; 159 160struct 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} 166}; 167 168struct 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} 174}; 175 176struct 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)} 189}; 190 191/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 192 193struct 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 } 204}; 205 206struct 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} 217}; 218 219struct 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} 230}; 231 232struct 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} 243}; 244 245struct 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)} 254}; 255 256int 257compare_expect_int64(const struct int64_pred_s * pred) 258{ 259 int j, failed = 0; 260 261 for (j = 0; j < pred->n_tests; ++j) { 262 int pred_result; 263 264 pred_result = (*pred->predfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs); 265 266 if (pred_result != pred->tests[j].expected) { 267 char str[64]; 268 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; 279 280 selresult = (pred->selfunc) (*pred->tests[j].lhs, *pred->tests[j].rhs, 281 *pred->tests[j].select_a, 282 *pred->tests[j].select_b); 283 284 if (selresult != *pred->tests[j].select_expected) { 285 char str[64]; 286 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; 299 } 300 } 301 } 302 303 printf(" %d tests performed, should be %d.\n", j, pred->n_tests); 304 305 return failed; 306} 307 308int 309compare_expect_uint64(const struct uint64_pred_s * pred) 310{ 311 int j, failed = 0; 312 313 for (j = 0; j < pred->n_tests; ++j) { 314 int pred_result; 315 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]; 319 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; 330 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]; 336 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; 349 } 350 } 351 } 352 353 printf(" %d tests performed, should be %d.\n", j, pred->n_tests); 354 355 return failed; 356} 357 358/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 359 360int 361test_i64_sext_i32(int in, int64_t expected) { 362 int64_t result = (int64_t) in; 363 364 if (result != expected) { 365 char str[64]; 366 sprintf(str, "i64_sext_i32(%d) returns %lld\n", in, result); 367 return 1; 368 } 369 370 return 0; 371} 372 373int 374test_i64_sext_i16(short in, int64_t expected) { 375 int64_t result = (int64_t) in; 376 377 if (result != expected) { 378 char str[64]; 379 sprintf(str, "i64_sext_i16(%hd) returns %lld\n", in, result); 380 return 1; 381 } 382 383 return 0; 384} 385 386int 387test_i64_sext_i8(signed char in, int64_t expected) { 388 int64_t result = (int64_t) in; 389 390 if (result != expected) { 391 char str[64]; 392 sprintf(str, "i64_sext_i8(%d) returns %lld\n", in, result); 393 return 1; 394 } 395 396 return 0; 397} 398 399int 400test_i64_zext_i32(unsigned int in, uint64_t expected) { 401 uint64_t result = (uint64_t) in; 402 403 if (result != expected) { 404 char str[64]; 405 sprintf(str, "i64_zext_i32(%u) returns %llu\n", in, result); 406 return 1; 407 } 408 409 return 0; 410} 411 412int 413test_i64_zext_i16(unsigned short in, uint64_t expected) { 414 uint64_t result = (uint64_t) in; 415 416 if (result != expected) { 417 char str[64]; 418 sprintf(str, "i64_zext_i16(%hu) returns %llu\n", in, result); 419 return 1; 420 } 421 422 return 0; 423} 424 425int 426test_i64_zext_i8(unsigned char in, uint64_t expected) { 427 uint64_t result = (uint64_t) in; 428 429 if (result != expected) { 430 char str[64]; 431 sprintf(str, "i64_zext_i8(%u) returns %llu\n", in, result); 432 return 1; 433 } 434 435 return 0; 436} 437 438/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 439 440int64_t 441i64_shl_const(int64_t a) { 442 return a << 10; 443} 444 445int64_t 446i64_shl(int64_t a, int amt) { 447 return a << amt; 448} 449 450uint64_t 451u64_shl_const(uint64_t a) { 452 return a << 10; 453} 454 455uint64_t 456u64_shl(uint64_t a, int amt) { 457 return a << amt; 458} 459 460int64_t 461i64_srl_const(int64_t a) { 462 return a >> 10; 463} 464 465int64_t 466i64_srl(int64_t a, int amt) { 467 return a >> amt; 468} 469 470uint64_t 471u64_srl_const(uint64_t a) { 472 return a >> 10; 473} 474 475uint64_t 476u64_srl(uint64_t a, int amt) { 477 return a >> amt; 478} 479 480int64_t 481i64_sra_const(int64_t a) { 482 return a >> 10; 483} 484 485int64_t 486i64_sra(int64_t a, int amt) { 487 return a >> amt; 488} 489 490uint64_t 491u64_sra_const(uint64_t a) { 492 return a >> 10; 493} 494 495uint64_t 496u64_sra(uint64_t a, int amt) { 497 return a >> amt; 498} 499 500int 501test_u64_constant_shift(const char *func_name, uint64_t (*func)(uint64_t), uint64_t a, uint64_t expected) { 502 uint64_t result = (*func)(a); 503 504 if (result != expected) { 505 printf("%s(0x%016llx) returns 0x%016llx, expected 0x%016llx\n", func_name, a, result, expected); 506 return 1; 507 } 508 509 return 0; 510} 511 512int 513test_i64_constant_shift(const char *func_name, int64_t (*func)(int64_t), int64_t a, int64_t expected) { 514 int64_t result = (*func)(a); 515 516 if (result != expected) { 517 printf("%s(0x%016llx) returns 0x%016llx, expected 0x%016llx\n", func_name, a, result, expected); 518 return 1; 519 } 520 521 return 0; 522} 523 524int 525test_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); 527 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; 531 } 532 533 return 0; 534} 535 536int 537test_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); 539 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; 543 } 544 545 return 0; 546} 547 548/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 549 550int64_t i64_mul(int64_t a, int64_t b) { 551 return a * b; 552} 553 554/* ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- */ 555 556int 557main(void) 558{ 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"; 562 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"); 571 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); 578 } 579 580 printf("----------------------------------------\n"); 581 } 582 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); 589 } 590 591 printf("----------------------------------------\n"); 592 } 593 594 /*----------------------------------------------------------------------*/ 595 596 puts("signed/zero-extend tests:"); 597 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); 608 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); 615 616 if (failed > 0) { 617 printf(" %d tests failed.\n", failed); 618 } else { 619 printf(" All tests passed.\n"); 620 } 621 622 printf("----------------------------------------\n"); 623 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); 632 633 if (failed > 0) { 634 printf(" %d tests ailed.\n", failed); 635 } else { 636 printf(" All tests passed.\n"); 637 } 638 639 printf("----------------------------------------\n"); 640 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); 651 652 if (failed > 0) { 653 printf(" %d tests ailed.\n", failed); 654 } else { 655 printf(" All tests passed.\n"); 656 } 657 658 printf("----------------------------------------\n"); 659 660 int64_t result; 661 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); 669 670 printf("----------------------------------------\n"); 671 672 return 0; 673} 674