diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-28 20:59:03 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-28 20:59:03 (GMT) |
commit | abf9722f425fcd4a8327dddaf5c5ccf08b1d30d6 (patch) | |
tree | f7fcce47ca0f81f1eb0ec24efb9e34025ae158eb /libtommath | |
parent | d74f47cb2ad9e4fa4b038c1a2205f3e8becc2af0 (diff) | |
download | tcl-abf9722f425fcd4a8327dddaf5c5ccf08b1d30d6.zip tcl-abf9722f425fcd4a8327dddaf5c5ccf08b1d30d6.tar.gz tcl-abf9722f425fcd4a8327dddaf5c5ccf08b1d30d6.tar.bz2 |
Turn KARATSUBA_MUL_CUTOFF (insize libtommath) et al into a #define in stead of exported int symbols.
Diffstat (limited to 'libtommath')
-rw-r--r-- | libtommath/bn_mp_get_bit.c | 12 | ||||
-rw-r--r-- | libtommath/tommath.h | 25 | ||||
-rw-r--r-- | libtommath/tommath_private.h | 11 |
3 files changed, 11 insertions, 37 deletions
diff --git a/libtommath/bn_mp_get_bit.c b/libtommath/bn_mp_get_bit.c index ab732c4..f5d2450 100644 --- a/libtommath/bn_mp_get_bit.c +++ b/libtommath/bn_mp_get_bit.c @@ -27,18 +27,8 @@ int mp_get_bit(const mp_int *a, int b) limb = b / DIGIT_BIT; - /* - * Zero is a special value with the member "used" set to zero. - * Needs to be tested before the check for the upper boundary - * otherwise (limb >= a->used) would be true for a = 0 - */ - - if (mp_iszero(a) != MP_NO) { - return MP_NO; - } - if (limb >= a->used) { - return MP_VAL; + return MP_NO; } bit = (mp_digit)(1) << (b % DIGIT_BIT); diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 00c8b35..85814e7 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -23,7 +23,7 @@ extern "C" { #endif /* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */ -#if defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) +#if defined(_WIN32) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) # define MP_32BIT #endif @@ -89,17 +89,7 @@ typedef unsigned long long mp_word; # endif #endif -/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ -#ifndef DIGIT_BIT -# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ -typedef unsigned long mp_min_u32; -#else -typedef mp_digit mp_min_u32; -#endif - -#define MP_DIGIT_BIT DIGIT_BIT #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) -#define MP_DIGIT_MAX MP_MASK /* equalities */ #define MP_LT -1 /* less than */ @@ -125,12 +115,6 @@ typedef mp_digit mp_min_u32; typedef int mp_err; -/* you'll have to tune these... */ -extern int KARATSUBA_MUL_CUTOFF, - KARATSUBA_SQR_CUTOFF, - TOOM_MUL_CUTOFF, - TOOM_SQR_CUTOFF; - /* define this to use lower memory usage routines (exptmods mostly) */ /* #define MP_LOW_MEM */ @@ -143,9 +127,6 @@ extern int KARATSUBA_MUL_CUTOFF, # endif #endif -/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ -#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1)) - /* the infamous mp_int structure */ typedef struct { int used, alloc, sign; @@ -156,10 +137,6 @@ typedef struct { typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); -#define USED(m) ((m)->used) -#define DIGIT(m, k) ((m)->dp[(k)]) -#define SIGN(m) ((m)->sign) - /* error code to char* string */ const char *mp_error_to_string(int code); diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 8fc3442..2096f77 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -42,15 +42,22 @@ extern "C" { # define XMALLOC malloc # define XFREE free # define XREALLOC realloc -# define XCALLOC calloc #elif 0 /* prototypes for our heap functions */ extern void *XMALLOC(size_t n); extern void *XREALLOC(void *p, size_t n); -extern void *XCALLOC(size_t n, size_t s); extern void XFREE(void *p); #endif +/* you'll have to tune these... */ +#define KARATSUBA_MUL_CUTOFF 80 /* Min. number of digits before Karatsuba multiplication is used. */ +#define KARATSUBA_SQR_CUTOFF 120 /* Min. number of digits before Karatsuba squaring is used. */ +#define TOOM_MUL_CUTOFF 350 /* no optimal values of these are known yet so set em high */ +#define TOOM_SQR_CUTOFF 400 + +/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ +#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1)) + /* lowlevel functions, do not call! */ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); |