From d31b63df9cce749a88f06ee81883cbe92be28c77 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 25 Oct 2019 16:09:50 +0000 Subject: Put #define's in alphabetical order. Use MP_DIGIT_BIT in stead of (deprecated) DIGIT_BIT everywhere. (just code cleanup, nothing funcional) --- generic/tclInt.h | 2 +- generic/tclStrToD.c | 26 +++++++++++++------------- generic/tclStubInit.c | 2 +- generic/tclTomMathDecls.h | 24 +++++++++--------------- libtommath/bn_mp_sqrt.c | 10 +++++----- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/generic/tclInt.h b/generic/tclInt.h index cb18889..9038a56 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4039,7 +4039,7 @@ MODULE_SCOPE int TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr, int before, int after, int *indexPtr); MODULE_SCOPE int TclIndexDecode(int encoded, int endValue); -MODULE_SCOPE void TclBN_int_reverse(unsigned char *s, size_t len); +MODULE_SCOPE void TclBN_s_mp_reverse(unsigned char *s, size_t len); /* Constants used in index value encoding routines. */ #define TCL_INDEX_END (-2) diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 94e7600..9eeb89d 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -152,7 +152,7 @@ typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__))); #define QUICK_MAX 14 /* floor((FP_PRECISION-1)*log(2)/log(10))-1 */ #define BLETCH 0x10 /* Highest power of two that is greater than * DBL_MAX_10_EXP, divided by 16. */ -#define DIGIT_GROUP 8 /* floor(DIGIT_BIT*log(2)/log(10)) */ +#define DIGIT_GROUP 8 /* floor(MP_DIGIT_BIT*log(2)/log(10)) */ /* * Union used to dismantle floating point numbers. @@ -1491,9 +1491,9 @@ AccumulateDecimalDigit( * More than single digit multiplication. Multiply by the appropriate * small powers of 5, and then shift. Large strings of zeroes are * eaten 256 at a time; this is less efficient than it could be, but - * seems implausible. We presume that DIGIT_BIT is at least 27. The + * seems implausible. We presume that MP_DIGIT_BIT is at least 27. The * first multiplication, by up to 10**7, is done with a one-DIGIT - * multiply (this presumes that DIGIT_BIT >= 24). + * multiply (this presumes that MP_DIGIT_BIT >= 24). */ n = numZeros + 1; @@ -3146,7 +3146,7 @@ StrictInt64Conversion( * * Test whether bankers' rounding should round a digit up. Assumption is * made that the denominator of the fraction being tested is a power of - * 2**DIGIT_BIT. + * 2**MP_DIGIT_BIT. * * Results: * Returns 1 iff the fraction is more than 1/2, or if the fraction is @@ -3158,7 +3158,7 @@ StrictInt64Conversion( static inline int ShouldBankerRoundUpPowD( mp_int *b, /* Numerator of the fraction. */ - int sd, /* Denominator is 2**(sd*DIGIT_BIT). */ + int sd, /* Denominator is 2**(sd*MP_DIGIT_BIT). */ int isodd) /* 1 if the digit is odd, 0 if even. */ { int i; @@ -3197,7 +3197,7 @@ static inline int ShouldBankerRoundUpToNextPowD( mp_int *b, /* Numerator of the fraction. */ mp_int *m, /* Numerator of the rounding tolerance. */ - int sd, /* Common denominator is 2**(sd*DIGIT_BIT). */ + int sd, /* Common denominator is 2**(sd*MP_DIGIT_BIT). */ int convType, /* Conversion type: STEELE defeats * round-to-even (not sure why one wants to do * this; I copied it from Gay). FIXME */ @@ -3209,7 +3209,7 @@ ShouldBankerRoundUpToNextPowD( /* * Compare B and S-m - which is the same as comparing B+m and S - which we * do by computing b+m and doing a bitwhack compare against - * 2**(DIGIT_BIT*sd) + * 2**(MP_DIGIT_BIT*sd) */ mp_add(b, m, temp); @@ -3241,7 +3241,7 @@ ShouldBankerRoundUpToNextPowD( * Converts a double-precision number to the shortest string of digits * that reconverts exactly to the given number, or to 'ilim' digits if * that will yield a shorter result. The denominator in David Gay's - * conversion algorithm is known to be a power of 2**DIGIT_BIT, and hence + * conversion algorithm is known to be a power of 2**MP_DIGIT_BIT, and hence * the division in the main loop may be replaced by a digit shift and * mask. * @@ -3323,7 +3323,7 @@ ShorteningBignumConversionPowD( mp_init(&temp); /* - * Loop through the digits. Do division and mod by s == 2**(sd*DIGIT_BIT) + * Loop through the digits. Do division and mod by s == 2**(sd*MP_DIGIT_BIT) * by mp_digit extraction. */ @@ -3435,7 +3435,7 @@ ShorteningBignumConversionPowD( * Converts a double-precision number to a fixed-lengt string of 'ilim' * digits (or 'ilim1' if log10(d) has been overestimated). The * denominator in David Gay's conversion algorithm is known to be a power - * of 2**DIGIT_BIT, and hence the division in the main loop may be + * of 2**MP_DIGIT_BIT, and hence the division in the main loop may be * replaced by a digit shift and mask. * * Results: @@ -3496,7 +3496,7 @@ StrictBignumConversionPowD( mp_init(&temp); /* - * Loop through the digits. Do division and mod by s == 2**(sd*DIGIT_BIT) + * Loop through the digits. Do division and mod by s == 2**(sd*MP_DIGIT_BIT) * by mp_digit extraction. */ @@ -4262,7 +4262,7 @@ TclDoubleDigits( } else if (s5 == 0) { /* * The denominator is a power of 2, so we can replace division by - * digit shifts. First we round up s2 to a multiple of DIGIT_BIT, + * digit shifts. First we round up s2 to a multiple of MP_DIGIT_BIT, * and adjust m2 and b2 accordingly. Then we launch into a version * of the comparison that's specialized for the 'power of mp_digit * in the denominator' case. @@ -4318,7 +4318,7 @@ TclDoubleDigits( } else if (s5 == 0) { /* * The denominator is a power of 2, so we can replace division by - * digit shifts. First we round up s2 to a multiple of DIGIT_BIT, + * digit shifts. First we round up s2 to a multiple of MP_DIGIT_BIT, * and adjust m2 and b2 accordingly. Then we launch into a version * of the comparison that's specialized for the 'power of mp_digit * in the denominator' case. diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index ea53e42..50c14bf 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -430,7 +430,7 @@ mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b) mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen) { - size_t n = TclBN_mp_unsigned_bin_size(a); + size_t n = mp_ubin_size(a); if (*outlen < (unsigned long)n) { return MP_VAL; } diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index 8d8ca67..92bb512 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -51,11 +51,6 @@ /* Rename the global symbols in libtommath to avoid linkage conflicts */ #define bn_reverse TclBN_reverse -#define s_mp_reverse TclBN_int_reverse -#define fast_s_mp_mul_digs TclBN_fast_s_mp_mul_digs -#define s_mp_mul_digs_fast TclBN_fast_s_mp_mul_digs -#define fast_s_mp_sqr TclBN_fast_s_mp_sqr -#define s_mp_sqr_fast TclBN_fast_s_mp_sqr #define mp_add TclBN_mp_add #define mp_add_d TclBN_mp_add_d #define mp_and TclBN_mp_and @@ -78,7 +73,6 @@ #define mp_expt_d_ex TclBN_mp_expt_d_ex #define mp_expt_u32 TclBN_mp_expt_d #define mp_get_bit TclBN_mp_get_bit -#define s_mp_get_bit TclBN_mp_get_bit #define mp_grow TclBN_mp_grow #define mp_init TclBN_mp_init #define mp_init_copy TclBN_mp_init_copy @@ -86,10 +80,6 @@ #define mp_init_set TclBN_mp_init_set #define mp_init_set_int TclBN_mp_init_set_int #define mp_init_size TclBN_mp_init_size -#define mp_karatsuba_mul TclBN_mp_karatsuba_mul -#define s_mp_karatsuba_mul TclBN_mp_karatsuba_mul -#define mp_karatsuba_sqr TclBN_mp_karatsuba_sqr -#define s_mp_karatsuba_sqr TclBN_mp_karatsuba_sqr #define mp_isodd TclBN_mp_isodd #define mp_lshd TclBN_mp_lshd #define mp_mod TclBN_mp_mod @@ -119,11 +109,6 @@ #define mp_tc_xor TclBN_mp_xor #define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin #define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n -#define mp_toom_mul TclBN_mp_toom_mul -#define s_mp_toom_mul TclBN_mp_toom_mul -#define s_mp_balance_mul TclBN_mp_balance_mul -#define mp_toom_sqr TclBN_mp_toom_sqr -#define s_mp_toom_sqr TclBN_mp_toom_sqr #define mp_toradix_n TclBN_mp_toradix_n #define mp_to_radix TclBN_mp_to_radix #define mp_to_ubin TclBN_mp_to_ubin @@ -132,9 +117,18 @@ #define mp_xor TclBN_mp_xor #define mp_zero TclBN_mp_zero #define s_mp_add TclBN_s_mp_add +#define s_mp_balance_mul TclBN_mp_balance_mul +#define s_mp_get_bit TclBN_mp_get_bit +#define s_mp_karatsuba_mul TclBN_mp_karatsuba_mul +#define s_mp_karatsuba_sqr TclBN_mp_karatsuba_sqr #define s_mp_mul_digs TclBN_s_mp_mul_digs +#define s_mp_mul_digs_fast TclBN_fast_s_mp_mul_digs +#define s_mp_reverse TclBN_s_mp_reverse #define s_mp_sqr TclBN_s_mp_sqr +#define s_mp_sqr_fast TclBN_fast_s_mp_sqr #define s_mp_sub TclBN_s_mp_sub +#define s_mp_toom_mul TclBN_mp_toom_mul +#define s_mp_toom_sqr TclBN_mp_toom_sqr #undef TCL_STORAGE_CLASS #ifdef BUILD_tcl diff --git a/libtommath/bn_mp_sqrt.c b/libtommath/bn_mp_sqrt.c index aaeac1d..4481d3a 100644 --- a/libtommath/bn_mp_sqrt.c +++ b/libtommath/bn_mp_sqrt.c @@ -5,7 +5,7 @@ #ifndef NO_FLOATING_POINT #include -#if (DIGIT_BIT != 28) || (FLT_RADIX != 2) || (DBL_MANT_DIG != 53) || (DBL_MAX_EXP != 1024) +#if (MP_DIGIT_BIT != 28) || (FLT_RADIX != 2) || (DBL_MANT_DIG != 53) || (DBL_MAX_EXP != 1024) #define NO_FLOATING_POINT #endif #endif @@ -52,7 +52,7 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) d = 0.0; for (k = arg->used-1; k >= j; --k) { - d = ldexp(d, DIGIT_BIT) + (double)(arg->dp[k]); + d = ldexp(d, MP_DIGIT_BIT) + (double)(arg->dp[k]); } /* @@ -64,18 +64,18 @@ mp_err mp_sqrt(const mp_int *arg, mp_int *ret) /* dig is the most significant mp_digit of the square root */ - dig = (mp_digit) ldexp(d, -DIGIT_BIT); + dig = (mp_digit) ldexp(d, -MP_DIGIT_BIT); /* * If the most significant digit is nonzero, find the next digit down - * by subtracting DIGIT_BIT times thie most significant digit. + * by subtracting MP_DIGIT_BIT times thie most significant digit. * Subtract one from the result so that our initial estimate is always * low. */ if (dig) { t1.used = i+2; - d -= ldexp((double) dig, DIGIT_BIT); + d -= ldexp((double) dig, MP_DIGIT_BIT); if (d >= 1.0) { t1.dp[i+1] = dig; t1.dp[i] = ((mp_digit) d) - 1; -- cgit v0.12