diff --git a/mp_fread.c b/mp_fread.c index cf09ec1d..baf539f6 100644 --- a/mp_fread.c +++ b/mp_fread.c @@ -5,22 +5,12 @@ #ifndef MP_NO_FILE -/* TODO: It would be some effort involved to connect mp_fwrite (mp_fread) to s_faster_read_radix. - - It is rather simple, on the other side, to just read the whole string into - memory and send it to s_faster_read_radix but it would need heap that may or - may not be available. So: check if there is something in the middle (e.g.: read - in chunks (LSD to MSD) and send those strings to s_faster_read_radix). - - NOTE: reading from a stream is quite fast already, especially bases of the form 2^n. */ - /* read a bigint from a file stream in ASCII */ mp_err mp_fread(mp_int *a, int radix, FILE *stream) { mp_err err = MP_OKAY; mp_sign sign = MP_ZPOS; int ch; - mp_digit binary_radix = 0u; /* make sure the radix is ok */ if ((radix < 2) || (radix > 64)) { @@ -42,10 +32,6 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream) /* clear a */ mp_zero(a); - if (MP_IS_2EXPT((unsigned int)radix)) { - binary_radix = (mp_digit)s_mp_log2_radix[radix]; - } - do { uint8_t y; unsigned pos; @@ -62,12 +48,8 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream) } /* shift up and add */ - if (binary_radix != 0u) { - if ((err = mp_mul_2d(a, (int)binary_radix, a)) != MP_OKAY) goto LBL_ERR; - } else { - if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) goto LBL_ERR; - } - if ((err = mp_add_d(a, y, a)) != MP_OKAY) goto LBL_ERR; + if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) goto LBL_ERR; + if ((err = mp_add_d(a, y, a)) != MP_OKAY) goto LBL_ERR; } while ((ch = fgetc(stream)) != EOF); diff --git a/s_mp_faster_to_radix.c b/s_mp_faster_to_radix.c index cb87820c..8a6bb69f 100644 --- a/s_mp_faster_to_radix.c +++ b/s_mp_faster_to_radix.c @@ -23,8 +23,6 @@ static int s_mp_compute_s(int t, int k) return (r > (MP_MAX_DIGIT_COUNT * MP_DIGIT_BIT)) ? 0 : (int)r; } - -/* TODO: Make variable names a bit more "talkative" */ static mp_err s_mp_to_radix_recursive(const mp_int *a, char **str, size_t *part_maxlen, size_t *part_written, int radix, int32_t k, int32_t t, bool pad, bool first, mp_int *P, mp_int *R) { @@ -52,8 +50,6 @@ static mp_err s_mp_to_radix_recursive(const mp_int *a, char **str, size_t *part_ See also: Modern Computer Arithmetic, version 0.5.9, page 59 */ - - /* TODO: Most of it is already in mp_reduce. Change mp_reduce to return the quotient, too? */ Beta = (int)s_mp_compute_s(t+1, k); if (Beta == 0) { err = MP_OVF; @@ -173,11 +169,6 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w /* Compute initial reciprocal R[0] and expand it (R[0]^(2^k) */ if ((err = mp_init_i32(&P[0], n)) != MP_OKAY) goto LTM_ERR; - /* TODO: chunksize does not seem to matter much above the initial b^y, d.n.f.t. remove this line if - MP_RADIX_BARRETT_START_MULTIPLICATOR is removed but don't forget the possibility that - the OS does not like too many recursions. This routine does use a lot of stack - and it calls other D&C algorithms (fast multiplication, fast division) that need a little - slice of the stack, too (vid.: ulimit -s) */ if ((err = mp_expt_n(&P[0], MP_RADIX_BARRETT_START_MULTIPLICATOR, &P[0])) != MP_OKAY) goto LTM_ERR; if ((err = mp_init(&R[0])) != MP_OKAY) goto LTM_ERR; if ((err = mp_2expt(&R[0], 2*k)) != MP_OKAY) goto LTM_ERR; @@ -231,7 +222,6 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w if (MP_IS_POWER_OF_TWO(&P[t])) { if ((err = mp_div_2d(&R[t], mp_count_bits(&P[t]) - 1, &R[t], NULL)) != MP_OKAY) goto LTM_ERR; } else { - /* TODO: does not work for all bases, check which one and also if it is worth the hassle */ if ((radix == 10) && ((2 * mp_count_bits(&P[t])) > ilog2a)) { break; }