Commit 14642642f9443463f6c7a4a8a08e5df894460e92

Daniel Mendler 2019-10-22T18:01:08

add prefix to cutoff variables

diff --git a/demo/mtest_opponent.c b/demo/mtest_opponent.c
index e77fec9..827c3f5 100644
--- a/demo/mtest_opponent.c
+++ b/demo/mtest_opponent.c
@@ -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 (;;) {
diff --git a/demo/test.c b/demo/test.c
index 0f0152a..41c4182 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -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;
    }
diff --git a/demo/timing.c b/demo/timing.c
index 47775da..a421f8d 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -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) {
diff --git a/etc/tune.c b/etc/tune.c
index e6850c6..be78ce3 100644
--- a/etc/tune.c
+++ b/etc/tune.c
@@ -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);
          }
       }
    }
diff --git a/mp_cutoffs.c b/mp_cutoffs.c
index 5593b55..46b04ef 100644
--- a/mp_cutoffs.c
+++ b/mp_cutoffs.c
@@ -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
diff --git a/tommath.h b/tommath.h
index f415a7f..b741674 100644
--- a/tommath.h
+++ b/tommath.h
@@ -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) */
diff --git a/tommath_private.h b/tommath_private.h
index b18663b..f1211a1 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -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 */