Hash :
2a2e2716
Author :
Date :
2019-05-12T11:33:17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
/* Tune the Karatsuba parameters
*
* Tom St Denis, tstdenis82@gmail.com
*/
#include "../tommath.h"
#include "../tommath_private.h"
#include <stdint.h>
#include <time.h>
#include <inttypes.h>
#include <limits.h>
#include <errno.h>
/*
Please take in mind that both multiplicands are of the same size. The balancing
mechanism in mp_balance works well but has some overhead itself. You can test
the behaviour of it with the option "-o" followed by a (small) positive number 'x'
to generate ratios of the form 1:x.
*/
static uint64_t s_timer_function(void);
static void s_timer_start(void);
static uint64_t s_timer_stop(void);
static uint64_t s_time_mul(int size);
static uint64_t s_time_sqr(int size);
static void s_usage(char *s);
static uint64_t s_timer_function(void)
{
#if _POSIX_C_SOURCE >= 199309L
#define LTM_BILLION 1000000000
struct timespec ts;
/* TODO: Sets errno in case of error. Use? */
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((uint64_t)ts.tv_sec) * LTM_BILLION + (uint64_t)ts.tv_nsec);
#else
clock_t t;
t = clock();
if (t < (clock_t)(0)) {
return (uint64_t)(0);
}
return (uint64_t)(t);
#endif
}
/* generic ISO C timer */
static uint64_t s_timer_tmp;
static void s_timer_start(void)
{
s_timer_tmp = s_timer_function();
}
static uint64_t s_timer_stop(void)
{
return s_timer_function() - s_timer_tmp;
}
static int s_check_result;
static int s_number_of_test_loops;
static int s_stabilization_extra;
static int s_offset = 1;
#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
static uint64_t s_time_mul(int size)
{
int x, e;
mp_int a, b, c, d;
uint64_t t1;
if ((e = mp_init_multi(&a, &b, &c, &d, NULL)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if ((e = mp_rand(&a, size * s_offset)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if ((e = mp_rand(&b, size)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
s_timer_start();
for (x = 0; x < s_number_of_test_loops; x++) {
if ((e = mp_mul(&a,&b,&c)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if (s_check_result == 1) {
if ((e = s_mp_mul(&a,&b,&d)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if (mp_cmp(&c, &d) != MP_EQ) {
/* Time of 0 cannot happen (famous last words?) */
t1 = 0uLL;
goto LTM_ERR;
}
}
}
t1 = s_timer_stop();
LTM_ERR:
mp_clear_multi(&a, &b, &c, &d, NULL);
return t1;
}
static uint64_t s_time_sqr(int size)
{
int x, e;
mp_int a, b, c;
uint64_t t1;
if ((e = mp_init_multi(&a, &b, &c, NULL)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if ((e = mp_rand(&a, size)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
s_timer_start();
for (x = 0; x < s_number_of_test_loops; x++) {
if ((e = mp_sqr(&a,&b)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if (s_check_result == 1) {
if ((e = s_mp_sqr(&a,&c)) != MP_OKAY) {
t1 = UINT64_MAX;
goto LTM_ERR;
}
if (mp_cmp(&c, &b) != MP_EQ) {
t1 = 0uLL;
goto LTM_ERR;
}
}
}
t1 = s_timer_stop();
LTM_ERR:
mp_clear_multi(&a, &b, &c, NULL);
return t1;
}
static void s_usage(char *s)
{
fprintf(stderr,"Usage: %s [TvcpGbtrSLFfMmosh]\n",s);
fprintf(stderr," -T testmode, for use with testme.sh\n");
fprintf(stderr," -v verbose, print all timings\n");
fprintf(stderr," -c check results\n");
fprintf(stderr," -p print benchmark of final cutoffs in files \"multiplying\"\n");
fprintf(stderr," and \"squaring\"\n");
fprintf(stderr," -G [string] suffix for the filenames listed above\n");
fprintf(stderr," Implies '-p'\n");
fprintf(stderr," -b print benchmark of bncore.c\n");
fprintf(stderr," -t prints space (0x20) separated results\n");
fprintf(stderr," -r [64] number of rounds\n");
fprintf(stderr," -S [0xdeadbeef] seed for PRNG\n");
fprintf(stderr," -L [3] number of negative values accumulated until the result is accepted\n");
fprintf(stderr," -M [3000] upper limit of T-C tests/prints\n");
fprintf(stderr," -m [1] increment of T-C tests/prints\n");
fprintf(stderr," -o [1] multiplier for the second multiplicand\n");
fprintf(stderr," (Not for computing the cut-offs!)\n");
fprintf(stderr," -s 'preset' use values in 'preset' for printing.\n");
fprintf(stderr," 'preset' is a comma separated string with cut-offs for\n");
fprintf(stderr," ksm, kss, tc3m, tc3s in that order\n");
fprintf(stderr," ksm = karatsuba multiplication\n");
fprintf(stderr," kss = karatsuba squaring\n");
fprintf(stderr," tc3m = Toom-Cook 3-way multiplication\n");
fprintf(stderr," tc3s = Toom-Cook 3-way squaring\n");
fprintf(stderr," Implies '-p'\n");
fprintf(stderr," -h this message\n");
}
int main(int argc, char **argv)
{
uint64_t t1, t2;
int x, i, j;
int count = 0;
int testmode = 0;
int verbose = 0;
int print = 0;
int bncore = 0;
int terse = 0;
int upper_limit_print = 3000;
int increment_print = 1;
int printpreset = 0;
/*int preset[8];*/
int base = 10;
char *endptr, *str;
long val;
uint64_t seed = 0xdeadbeef;
int opt;
int ksm, kss, tc3m, tc3s;
FILE *squaring, *multiplying;
char mullog[256] = "multiplying";
char sqrlog[256] = "squaring";
s_number_of_test_loops = 64;
s_stabilization_extra = 3;
/* Very simple option parser, please treat it nicely. */
if (argc != 1) {
for (opt = 1; (opt < argc) && (argv[opt][0] == '-'); opt++) {
switch (argv[opt][1]) {
case 'T':
testmode = 1;
s_check_result = 1;
upper_limit_print = 1000;
increment_print = 11;
s_number_of_test_loops = 1;
s_stabilization_extra = 1;
s_offset = 1;
break;
case 'v':
verbose = 1;
break;
case 'c':
s_check_result = 1;
break;
case 'p':
print = 1;
break;
case 'G':
print = 1;
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
/* manual strcat() */
for (i = 0; i < 255; i++) {
if (mullog[i] == '\0') {
break;
}
}
for (j = 0; i < 255; j++, i++) {
mullog[i] = argv[opt][j];
if (argv[opt][j] == '\0') {
break;
}
}
for (i = 0; i < 255; i++) {
if (sqrlog[i] == '\0') {
break;
}
}
for (j = 0; i < 255; j++, i++) {
sqrlog[i] = argv[opt][j];
if (argv[opt][j] == '\0') {
break;
}
}
break;
case 'b':
bncore = 1;
break;
case 't':
terse = 1;
break;
case 'S':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
|| (errno != 0 && val == 0)) {
fprintf(stderr,"Seed %s not usable\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No seed given?\n");
exit(EXIT_FAILURE);
}
seed = (uint64_t)val;
break;
case 'L':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"Value %s not usable\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No value for option \"-L\"given\n");
exit(EXIT_FAILURE);
}
s_stabilization_extra = (int)val;
break;
case 'o':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"Value %s not usable as an offset\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No value for the offset given\n");
exit(EXIT_FAILURE);
}
s_offset = (int)val;
break;
case 'r':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"Value %s not usable as the number of rounds for \"-r\"\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No value for the number of rounds given\n");
exit(EXIT_FAILURE);
}
s_number_of_test_loops = (int)val;
break;
case 'M':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"Value %s not usable as the upper limit of T-C tests (\"-M\")\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No value for the upper limit of T-C tests given\n");
exit(EXIT_FAILURE);
}
upper_limit_print = (int)val;
break;
case 'm':
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"Value %s not usable as the increment for the T-C tests (\"-m\")\n", argv[opt]);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No value for the increment for the T-C tests given\n");
exit(EXIT_FAILURE);
}
increment_print = (int)val;
break;
case 's':
printpreset = 1;
print = 1;
opt++;
if (opt >= argc) {
s_usage(argv[0]);
}
str = argv[opt];
i = 0;
/* Only the most basic checks */
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"input #%d wrong\n", i+1);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No input for #%d?\n", i+1);
exit(EXIT_FAILURE);
}
i++;
str = endptr + 1;
KARATSUBA_MUL_CUTOFF = (int)val;
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"input #%d wrong\n", i+1);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No input for #%d?\n", i+1);
exit(EXIT_FAILURE);
}
i++;
str = endptr + 1;
KARATSUBA_SQR_CUTOFF = (int)val;
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"input #%d wrong\n", i+1);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No input for #%d?\n", i+1);
exit(EXIT_FAILURE);
}
i++;
str = endptr + 1;
TOOM_MUL_CUTOFF = (int)val;
errno = 0;
val = strtol(str, &endptr, base);
if ((val > INT_MAX || val < 0) || (errno != 0)) {
fprintf(stderr,"input #%d wrong\n", i+1);
exit(EXIT_FAILURE);
}
if (endptr == str) {
fprintf(stderr, "No input for #%d?\n", i+1);
exit(EXIT_FAILURE);
}
i++;
str = endptr + 1;
TOOM_SQR_CUTOFF = (int)val;
break;
case 'h':
default:
s_usage(argv[0]);
exit(EXIT_FAILURE);
}
}
}
/*
mp_rand uses the cryptographically secure
source of the OS by default. That is too expensive, too slow and
most important for a benchmark: it is not repeatable.
*/
s_mp_rand_jenkins_init(seed);
mp_rand_source(s_mp_rand_jenkins);
ksm = KARATSUBA_MUL_CUTOFF;
kss = KARATSUBA_SQR_CUTOFF;
tc3m = TOOM_MUL_CUTOFF;
tc3s = TOOM_SQR_CUTOFF;
if ((bncore == 0) && (printpreset == 0)) {
/* Turn all limits from bncore.c to the max */
KARATSUBA_MUL_CUTOFF = INT_MAX;
KARATSUBA_SQR_CUTOFF = INT_MAX;
TOOM_MUL_CUTOFF = INT_MAX;
TOOM_SQR_CUTOFF = INT_MAX;
#ifdef BN_S_MP_KARATSUBA_MUL_C
/*
The influence of the Comba multiplication cannot be
eradicated programmatically. It depends on the size
of the macro MP_WPARRAY in tommath.h which needs to
be changed manually (to 0 (zero)).
*/
if ((verbose == 1) || (testmode == 1)) {
puts("# Karatsuba multiplication.");
}
for (x = 8; x < upper_limit_print; x += increment_print) {
KARATSUBA_MUL_CUTOFF = INT_MAX;
t1 = s_time_mul(x);
if ((t1 == 0uLL) || (t1 == UINT64_MAX)) {
fprintf(stderr,"Karatsuba multiplication failed at x = INT_MAX (%s)\n",
(t1 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
KARATSUBA_MUL_CUTOFF = x;
t2 = s_time_mul(x);
if ((t2 == 0uLL) || (t2 == UINT64_MAX)) {
fprintf(stderr,"Karatsuba multiplication failed (%s)\n",
(t2 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
if (verbose == 1) {
printf("%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
}
if (t2 < t1) {
if (count == s_stabilization_extra) {
count = 0;
break;
} else if (count < s_stabilization_extra) {
count++;
}
} else if (count > 0) {
count--;
}
}
KARATSUBA_MUL_CUTOFF = x - s_stabilization_extra * increment_print;
#endif
#ifdef BN_S_MP_KARATSUBA_SQR_C
if ((verbose == 1) || (testmode == 1)) {
puts("# Karatsuba squaring.");
}
for (x = 8; x < upper_limit_print; x += increment_print) {
KARATSUBA_SQR_CUTOFF = INT_MAX;
t1 = s_time_sqr(x);
if ((t1 == 0uLL) || (t1 == UINT64_MAX)) {
fprintf(stderr,"Karatsuba squaring failed at x = INT_MAX (%s)\n",
(t1 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
KARATSUBA_SQR_CUTOFF = x;
t2 = s_time_sqr(x);
if ((t2 == 0uLL) || (t2 == UINT64_MAX)) {
fprintf(stderr,"Karatsuba squaring failed (%s)\n",
(t2 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
if (verbose == 1) {
printf("%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
}
if (t2 < t1) {
if (count == s_stabilization_extra) {
count = 0;
break;
} else if (count < s_stabilization_extra) {
count++;
}
} else if (count > 0) {
count--;
}
}
KARATSUBA_SQR_CUTOFF = x - s_stabilization_extra * increment_print;
#endif
#ifdef BN_S_MP_TOOM_MUL_C
if ((verbose == 1) || (testmode == 1)) {
puts("# Toom-Cook 3-way multiplying.");
}
for (x = 8; x < upper_limit_print; x += increment_print) {
TOOM_MUL_CUTOFF = INT_MAX;
t1 = s_time_mul(x);
if ((t1 == 0uLL) || (t1 == UINT64_MAX)) {
fprintf(stderr,"Toom-Cook 3-way multiplying failed at x = INT_MAX (%s)\n",
(t1 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
TOOM_MUL_CUTOFF = x;
t2 = s_time_mul(x);
if ((t2 == 0uLL) || (t2 == UINT64_MAX)) {
fprintf(stderr,"Toom-Cook 3-way multiplication failed (%s)\n",
(t2 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
if (verbose == 1) {
printf("%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
}
if (t2 < t1) {
if (count == s_stabilization_extra) {
count = 0;
break;
} else if (count < s_stabilization_extra) {
count++;
}
} else if (count > 0) {
count--;
}
}
TOOM_MUL_CUTOFF = x - s_stabilization_extra * increment_print;
#endif
#ifdef BN_S_MP_TOOM_SQR_C
if ((verbose == 1) || (testmode == 1)) {
puts("# Toom-Cook 3-way squaring.");
}
for (x = 8; x < upper_limit_print; x += increment_print) {
TOOM_SQR_CUTOFF = INT_MAX;
t1 = s_time_sqr(x);
if ((t1 == 0uLL) || (t1 == UINT64_MAX)) {
fprintf(stderr,"Toom-Cook 3-way squaring failed at x = INT_MAX (%s)\n",
(t1 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
TOOM_SQR_CUTOFF = x;
t2 = s_time_sqr(x);
if ((t2 == 0uLL) || (t2 == UINT64_MAX)) {
fprintf(stderr,"Toom-Cook 3-way squaring failed (%s)\n",
(t2 == 0uLL)?"wrong result":"internal error");
exit(EXIT_FAILURE);
}
if (verbose == 1) {
printf("%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
}
if (t2 < t1) {
if (count == s_stabilization_extra) {
count = 0;
break;
} else if (count < s_stabilization_extra) {
count++;
}
} else if (count > 0) {
count--;
}
}
TOOM_SQR_CUTOFF = x - s_stabilization_extra * increment_print;
#endif
}
if (terse == 1) {
printf("%d %d %d %d\n",
KARATSUBA_MUL_CUTOFF,
KARATSUBA_SQR_CUTOFF,
TOOM_MUL_CUTOFF,
TOOM_SQR_CUTOFF);
} else {
printf("KARATSUBA_MUL_CUTOFF = %d\n", KARATSUBA_MUL_CUTOFF);
printf("KARATSUBA_SQR_CUTOFF = %d\n", KARATSUBA_SQR_CUTOFF);
printf("TOOM_MUL_CUTOFF = %d\n", TOOM_MUL_CUTOFF);
printf("TOOM_SQR_CUTOFF = %d\n", TOOM_SQR_CUTOFF);
}
if (print == 1) {
printf("Printing data for graphing to \"%s\" and \"%s\"\n",mullog, sqrlog);
multiplying = fopen(mullog, "w+");
if (multiplying == NULL) {
fprintf(stderr, "Opening file \"%s\" failed\n", mullog);
exit(EXIT_FAILURE);
}
squaring = fopen(sqrlog, "w+");
if (squaring == NULL) {
fprintf(stderr, "Opening file \"%s\" failed\n",sqrlog);
exit(EXIT_FAILURE);
}
for (x = 8; x < upper_limit_print; x += increment_print) {
KARATSUBA_MUL_CUTOFF = INT_MAX;
KARATSUBA_SQR_CUTOFF = INT_MAX;
TOOM_MUL_CUTOFF = INT_MAX;
TOOM_SQR_CUTOFF = INT_MAX;
t1 = s_time_mul(x);
KARATSUBA_MUL_CUTOFF = kss;
KARATSUBA_SQR_CUTOFF = ksm;
TOOM_MUL_CUTOFF = tc3m;
TOOM_SQR_CUTOFF = tc3s;
t2 = s_time_mul(x);
fprintf(multiplying, "%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
fflush(multiplying);
if (verbose == 1) {
printf("MUL %d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
fflush(stdout);
}
KARATSUBA_MUL_CUTOFF = INT_MAX;
KARATSUBA_SQR_CUTOFF = INT_MAX;
TOOM_MUL_CUTOFF = INT_MAX;
TOOM_SQR_CUTOFF = INT_MAX;
t1 = s_time_sqr(x);
KARATSUBA_MUL_CUTOFF = kss;
KARATSUBA_SQR_CUTOFF = ksm;
TOOM_MUL_CUTOFF = tc3m;
TOOM_SQR_CUTOFF = tc3s;
t2 = s_time_sqr(x);
fprintf(squaring,"%d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
fflush(squaring);
if (verbose == 1) {
printf("SQR %d: %9"PRIu64" %9"PRIu64", %9"PRIi64"\n", x, t1, t2, (int64_t)t2 - (int64_t)t1);
fflush(stdout);
}
}
printf("Finished. Data for graphing in \"%s\" and \"%s\"\n",mullog, sqrlog);
if (verbose == 1) {
KARATSUBA_MUL_CUTOFF = kss;
KARATSUBA_SQR_CUTOFF = ksm;
TOOM_MUL_CUTOFF = tc3m;
TOOM_SQR_CUTOFF = tc3s;
if (terse == 1) {
printf("%d %d %d %d\n",
KARATSUBA_MUL_CUTOFF,
KARATSUBA_SQR_CUTOFF,
TOOM_MUL_CUTOFF,
TOOM_SQR_CUTOFF);
} else {
printf("KARATSUBA_MUL_CUTOFF = %d\n", KARATSUBA_MUL_CUTOFF);
printf("KARATSUBA_SQR_CUTOFF = %d\n", KARATSUBA_SQR_CUTOFF);
printf("TOOM_MUL_CUTOFF = %d\n", TOOM_MUL_CUTOFF);
printf("TOOM_SQR_CUTOFF = %d\n", TOOM_SQR_CUTOFF);
}
}
}
exit(EXIT_SUCCESS);
}