add prefix to cutoff variables

This commit is contained in:
Daniel Mendler 2019-10-22 18:01:08 +02:00 committed by Steffen Jaeckel
parent 121973fc6b
commit 14642642f9
No known key found for this signature in database
GPG Key ID: AF0CB17621EDAD72
7 changed files with 40 additions and 45 deletions

View File

@ -37,8 +37,8 @@ static int mtest_opponent(void)
#ifndef MP_FIXED_CUTOFFS
/* force KARA and TOOM to enable despite cutoffs */
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
MP_KARATSUBA_SQR_CUTOFF = MP_KARATSUBA_MUL_CUTOFF = 8;
MP_TOOM_SQR_CUTOFF = MP_TOOM_MUL_CUTOFF = 16;
#endif
for (;;) {

View File

@ -2199,12 +2199,12 @@ static int test_s_mp_toom_mul(void)
goto LBL_ERR;
}
tc_cutoff = TOOM_MUL_CUTOFF;
TOOM_MUL_CUTOFF = INT_MAX;
tc_cutoff = MP_TOOM_MUL_CUTOFF;
MP_TOOM_MUL_CUTOFF = INT_MAX;
if ((err = mp_mul(&a, &b, &c)) != MP_OKAY) {
goto LBL_ERR;
}
TOOM_MUL_CUTOFF = tc_cutoff;
MP_TOOM_MUL_CUTOFF = tc_cutoff;
if ((err = mp_mul(&a, &b, &d)) != MP_OKAY) {
goto LBL_ERR;
}

View File

@ -234,18 +234,18 @@ int main(int argc, char **argv)
if (should_test("mulsqr", argc, argv) != 0) {
/* do mult/square twice, first without karatsuba and second with */
old_kara_m = KARATSUBA_MUL_CUTOFF;
old_kara_s = KARATSUBA_SQR_CUTOFF;
old_kara_m = MP_KARATSUBA_MUL_CUTOFF;
old_kara_s = MP_KARATSUBA_SQR_CUTOFF;
/* currently toom-cook cut-off is too high to kick in, so we just use the karatsuba values */
old_toom_m = old_kara_m;
old_toom_s = old_kara_s;
for (ix = 0; ix < 3; ix++) {
printf("With%s Karatsuba, With%s Toom\n", (ix == 1) ? "" : "out", (ix == 2) ? "" : "out");
KARATSUBA_MUL_CUTOFF = (ix == 1) ? old_kara_m : 9999;
KARATSUBA_SQR_CUTOFF = (ix == 1) ? old_kara_s : 9999;
TOOM_MUL_CUTOFF = (ix == 2) ? old_toom_m : 9999;
TOOM_SQR_CUTOFF = (ix == 2) ? old_toom_s : 9999;
MP_KARATSUBA_MUL_CUTOFF = (ix == 1) ? old_kara_m : 9999;
MP_KARATSUBA_SQR_CUTOFF = (ix == 1) ? old_kara_s : 9999;
MP_TOOM_MUL_CUTOFF = (ix == 2) ? old_toom_m : 9999;
MP_TOOM_SQR_CUTOFF = (ix == 2) ? old_toom_s : 9999;
log = FOPEN((ix == 0) ? "logs/mult.log" : (ix == 1) ? "logs/mult_kara.log" : "logs/mult_toom.log", "w");
for (cnt = 4; cnt <= (10240 / MP_DIGIT_BIT); cnt += 2) {

View File

@ -256,18 +256,18 @@ const struct cutoffs max_cutoffs =
static void set_cutoffs(const struct cutoffs *c)
{
KARATSUBA_MUL_CUTOFF = c->KARATSUBA_MUL;
KARATSUBA_SQR_CUTOFF = c->KARATSUBA_SQR;
TOOM_MUL_CUTOFF = c->TOOM_MUL;
TOOM_SQR_CUTOFF = c->TOOM_SQR;
MP_KARATSUBA_MUL_CUTOFF = c->KARATSUBA_MUL;
MP_KARATSUBA_SQR_CUTOFF = c->KARATSUBA_SQR;
MP_TOOM_MUL_CUTOFF = c->TOOM_MUL;
MP_TOOM_SQR_CUTOFF = c->TOOM_SQR;
}
static void get_cutoffs(struct cutoffs *c)
{
c->KARATSUBA_MUL = KARATSUBA_MUL_CUTOFF;
c->KARATSUBA_SQR = KARATSUBA_SQR_CUTOFF;
c->TOOM_MUL = TOOM_MUL_CUTOFF;
c->TOOM_SQR = TOOM_SQR_CUTOFF;
c->KARATSUBA_MUL = MP_KARATSUBA_MUL_CUTOFF;
c->KARATSUBA_SQR = MP_KARATSUBA_SQR_CUTOFF;
c->TOOM_MUL = MP_TOOM_MUL_CUTOFF;
c->TOOM_SQR = MP_TOOM_SQR_CUTOFF;
}
@ -414,13 +414,13 @@ int main(int argc, char **argv)
s_usage(argv[0]);
}
str = argv[opt];
KARATSUBA_MUL_CUTOFF = (int)s_strtol(str, &endptr, "[1/4] No value for KARATSUBA_MUL_CUTOFF given");
MP_KARATSUBA_MUL_CUTOFF = (int)s_strtol(str, &endptr, "[1/4] No value for MP_KARATSUBA_MUL_CUTOFF given");
str = endptr + 1;
KARATSUBA_SQR_CUTOFF = (int)s_strtol(str, &endptr, "[2/4] No value for KARATSUBA_SQR_CUTOFF given");
MP_KARATSUBA_SQR_CUTOFF = (int)s_strtol(str, &endptr, "[2/4] No value for MP_KARATSUBA_SQR_CUTOFF given");
str = endptr + 1;
TOOM_MUL_CUTOFF = (int)s_strtol(str, &endptr, "[3/4] No value for TOOM_MUL_CUTOFF given");
MP_TOOM_MUL_CUTOFF = (int)s_strtol(str, &endptr, "[3/4] No value for MP_TOOM_MUL_CUTOFF given");
str = endptr + 1;
TOOM_SQR_CUTOFF = (int)s_strtol(str, &endptr, "[4/4] No value for TOOM_SQR_CUTOFF given");
MP_TOOM_SQR_CUTOFF = (int)s_strtol(str, &endptr, "[4/4] No value for MP_TOOM_SQR_CUTOFF given");
break;
case 'h':
s_exit_code = EXIT_SUCCESS;
@ -448,7 +448,7 @@ int main(int argc, char **argv)
int *cutoff, *update;
uint64_t (*fn)(int size);
} test[] = {
#define T_MUL_SQR(n, o, f) { #n, &o##_CUTOFF, &(updated.o), MP_HAS(S_MP_##o) ? f : NULL }
#define T_MUL_SQR(n, o, f) { #n, &MP_##o##_CUTOFF, &(updated.o), MP_HAS(S_MP_##o) ? f : NULL }
/*
The influence of the Comba multiplication cannot be
eradicated programmatically. It depends on the size
@ -526,15 +526,15 @@ int main(int argc, char **argv)
set_cutoffs(&orig);
if (args.terse == 1) {
printf("%d %d %d %d\n",
KARATSUBA_MUL_CUTOFF,
KARATSUBA_SQR_CUTOFF,
TOOM_MUL_CUTOFF,
TOOM_SQR_CUTOFF);
MP_KARATSUBA_MUL_CUTOFF,
MP_KARATSUBA_SQR_CUTOFF,
MP_TOOM_MUL_CUTOFF,
MP_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);
printf("KARATSUBA_MUL_CUTOFF = %d\n", MP_KARATSUBA_MUL_CUTOFF);
printf("KARATSUBA_SQR_CUTOFF = %d\n", MP_KARATSUBA_SQR_CUTOFF);
printf("TOOM_MUL_CUTOFF = %d\n", MP_TOOM_MUL_CUTOFF);
printf("TOOM_SQR_CUTOFF = %d\n", MP_TOOM_SQR_CUTOFF);
}
}
}

View File

@ -5,10 +5,10 @@
#ifndef MP_FIXED_CUTOFFS
#include "tommath_cutoffs.h"
int KARATSUBA_MUL_CUTOFF = MP_DEFAULT_KARATSUBA_MUL_CUTOFF,
KARATSUBA_SQR_CUTOFF = MP_DEFAULT_KARATSUBA_SQR_CUTOFF,
TOOM_MUL_CUTOFF = MP_DEFAULT_TOOM_MUL_CUTOFF,
TOOM_SQR_CUTOFF = MP_DEFAULT_TOOM_SQR_CUTOFF;
int MP_KARATSUBA_MUL_CUTOFF = MP_DEFAULT_KARATSUBA_MUL_CUTOFF,
MP_KARATSUBA_SQR_CUTOFF = MP_DEFAULT_KARATSUBA_SQR_CUTOFF,
MP_TOOM_MUL_CUTOFF = MP_DEFAULT_TOOM_MUL_CUTOFF,
MP_TOOM_SQR_CUTOFF = MP_DEFAULT_TOOM_SQR_CUTOFF;
#endif
#endif

View File

@ -122,10 +122,10 @@ typedef enum {
#ifndef MP_FIXED_CUTOFFS
extern int
KARATSUBA_MUL_CUTOFF,
KARATSUBA_SQR_CUTOFF,
TOOM_MUL_CUTOFF,
TOOM_SQR_CUTOFF;
MP_KARATSUBA_MUL_CUTOFF,
MP_KARATSUBA_SQR_CUTOFF,
MP_TOOM_MUL_CUTOFF,
MP_TOOM_SQR_CUTOFF;
#endif
/* define this to use lower memory usage routines (exptmods mostly) */

View File

@ -116,11 +116,6 @@ do { \
# define MP_KARATSUBA_SQR_CUTOFF MP_DEFAULT_KARATSUBA_SQR_CUTOFF
# define MP_TOOM_MUL_CUTOFF MP_DEFAULT_TOOM_MUL_CUTOFF
# define MP_TOOM_SQR_CUTOFF MP_DEFAULT_TOOM_SQR_CUTOFF
#else
# define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF
# define MP_KARATSUBA_SQR_CUTOFF KARATSUBA_SQR_CUTOFF
# define MP_TOOM_MUL_CUTOFF TOOM_MUL_CUTOFF
# define MP_TOOM_SQR_CUTOFF TOOM_SQR_CUTOFF
#endif
/* define heap macros */