Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use size_t #430

Closed
wants to merge 23 commits into from
Closed
157 changes: 157 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
DONE mp_abs.c
DONE mp_add.c
DONE mp_sub.c
DONE mp_count_bits.c
DONE mp_cutoffs.c
DONE mp_cmp.c
DONE mp_cmp_d.c
DONE mp_cmp_mag.c
DONE mp_and.c
DONE mp_xor.c
DONE mp_or.c
DONE mp_fwrite.c
DONE mp_copy.c
DONE mp_clamp.c
DONE mp_clear.c
DONE mp_clear_multi.c
DONE mp_exch.c
DONE mp_get_double.c
DONE mp_get_i32.c
DONE mp_get_i64.c
DONE mp_get_l.c
DONE mp_get_ll.c
DONE mp_get_mag_u32.c
DONE mp_get_mag_u64.c
DONE mp_get_mag_ul.c
DONE mp_get_mag_ull.c
DONE mp_grow.c
DONE mp_init.c
DONE mp_init_copy.c
DONE mp_init_i32.c
DONE mp_init_i64.c
DONE mp_init_l.c
DONE mp_init_ll.c
DONE mp_init_multi.c
DONE mp_init_set.c
DONE mp_init_size.c
DONE mp_init_u32.c
DONE mp_init_u64.c
DONE mp_init_ul.c
DONE mp_init_ull.c
DONE mp_cnt_lsb.c
DONE mp_complement.c
DONE mp_error_to_string.c
DONE mp_from_sbin.c
DONE mp_from_ubin.c
DONE mp_neg.c
DONE mp_pack.c
DONE mp_pack_count.c
DONE mp_unpack.c
DONE mp_zero.c
DONE mp_ubin_size.c
DONE mp_to_radix.c
DONE mp_radix_size.c
DONE mp_radix_smap.c
DONE mp_rand.c
DONE mp_shrink.c
DONE mp_sbin_size.c
DONE mp_set.c
DONE mp_set_double.c
DONE mp_set_i32.c
DONE mp_set_i64.c
DONE mp_set_l.c
DONE mp_set_ll.c
DONE mp_set_u32.c
DONE mp_set_u64.c
DONE mp_set_ul.c
DONE mp_set_ull.c
DONE s_mp_rand_jenkins.c
DONE s_mp_rand_platform.c
DONE mp_rshd.c
DONE mp_lshd.c
DONE mp_to_sbin.c
DONE mp_to_ubin.c
DONE mp_2expt.c
DONE mp_gcd.c
DONE mp_kronecker.c
DONE mp_mul.c
DONE mp_sqr.c
DONE mp_addmod.c
DONE mp_mod.c
DONE mp_mod_d.c
DONE mp_lcm.c
DONE mp_exteuclid.c
DONE mp_sqrmod.c
DONE mp_div.c
DONE mp_sqrt.c
DONE s_mp_get_bit.c
DONE mp_mod_2d.c
DONE mp_submod.c
DONE s_mp_karatsuba_sqr.c
DONE mp_mulmod.c
DONE mp_prime_tab.c
DONE mp_invmod.c
DONE s_mp_invmod_fast.c
DONE s_mp_invmod_slow.c
DONE s_mp_balance_mul.c
DONE s_mp_div_recursive.c
DONE s_mp_div_small.c
DONE s_mp_toom_mul.c
DONE s_mp_prime_is_divisible.c
DONE mp_signed_rsh.c
DONE mp_prime_rabin_miller_trials.c
DONE mp_prime_fermat.c
DONE s_mp_log_pow2.c
DONE mp_sqrtmod_prime.c
DONE mp_reduce_2k.c
DONE mp_reduce_2k_l.c
DONE mp_add_d.c
DONE mp_sub_d.c
DONE s_mp_add.c
DONE s_mp_sub.c
DONE mp_reduce_2k_setup.c
DONE mp_reduce_2k_setup_l.c
DONE mp_dr_setup.c
DONE mp_mul_2d.c
DONE s_mp_karatsuba_mul.c
DONE mp_reduce_setup.c
DONE mp_reduce_is_2k.c
DONE mp_reduce_is_2k_l.c
DONE mp_div_2d.c
DONE mp_div_2.c
DONE mp_div_3.c
DONE mp_mul_2.c
DONE mp_div_d.c
DONE mp_mul_d.c
DONE mp_reduce.c
DONE s_mp_toom_sqr.c
DONE mp_prime_rand.c
DONE mp_is_square.c
DONE mp_montgomery_setup.c
DONE mp_prime_next_prime.c
DONE mp_exptmod.c

s_mp_div_school.c
mp_dr_is_modulus.c
mp_dr_reduce.c
mp_expt_u32.c
mp_log_u32.c
mp_montgomery_calc_normalization.c
mp_montgomery_reduce.c
mp_prime_frobenius_underwood.c
mp_prime_is_prime.c
mp_prime_miller_rabin.c
mp_prime_strong_lucas_selfridge.c
mp_root_u32.c
s_mp_exptmod.c
s_mp_exptmod_fast.c

DONE! s_mp_log.c
DONE! s_mp_log_d.c
DONE!? s_mp_montgomery_reduce_fast.c
DONE! s_mp_mul_high_digs.c
DONE! s_mp_mul_high_digs_fast.c
DONE! s_mp_sqr.c
DONE!? s_mp_sqr_fast.c
DONE!? s_mp_mul_digs.c
DONE!? s_mp_mul_digs_fast.c
6 changes: 3 additions & 3 deletions demo/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ static int test_mp_prime_rand(void)
goto LBL_ERR;
}
if (mp_count_bits(&a) != ix) {
printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix);
printf("Prime is %zu not %d bits!!!\n", mp_count_bits(&a), ix);
goto LBL_ERR;
}
}
Expand Down Expand Up @@ -991,7 +991,7 @@ static int test_mp_prime_is_prime(void)
goto LBL_ERR;
}
if (mp_count_bits(&a) != ix) {
printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix);
printf("Prime is %zu not %d bits!!!\n", mp_count_bits(&a), ix);
goto LBL_ERR;
}
/* let's see if it's really a safe prime */
Expand Down Expand Up @@ -1308,7 +1308,7 @@ static int test_mp_cnt_lsb(void)
mp_set(&a, 1uL);
for (ix = 0; ix < 1024; ix++) {
if (mp_cnt_lsb(&a) != ix) {
printf("Failed at %d, %d\n", ix, mp_cnt_lsb(&a));
printf("Failed at %d, %zu\n", ix, mp_cnt_lsb(&a));
goto LBL_ERR;
}
mp_mul_2(&a, &a);
Expand Down
39 changes: 19 additions & 20 deletions etc/tune.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
static uint64_t s_timer_function(void);
static void s_timer_start(void);
static uint64_t s_timer_stop(void);
static uint64_t s_time_mul(int size);
static uint64_t s_time_sqr(int size);
static uint64_t s_time_mul(size_t size);
static uint64_t s_time_sqr(size_t size);
static void s_usage(char *s);

static uint64_t s_timer_function(void)
Expand Down Expand Up @@ -59,7 +59,7 @@ static int s_stabilization_extra;
static int s_offset = 1;

#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
static uint64_t s_time_mul(int size)
static uint64_t s_time_mul(size_t size)
{
int x;
mp_err e;
Expand Down Expand Up @@ -105,7 +105,7 @@ static uint64_t s_time_mul(int size)
return t1;
}

static uint64_t s_time_sqr(int size)
static uint64_t s_time_sqr(size_t size)
{
int x;
mp_err e;
Expand Down Expand Up @@ -156,7 +156,7 @@ struct tune_args {
int increment_print;
} args;

static void s_run(const char *name, uint64_t (*op)(int size), int *cutoff)
static void s_run(const char *name, uint64_t (*op)(size_t size), size_t *cutoff)
{
int x, count = 0;
uint64_t t1, t2;
Expand Down Expand Up @@ -247,12 +247,11 @@ static void s_usage(char *s)
}

struct cutoffs {
int KARATSUBA_MUL, KARATSUBA_SQR;
int TOOM_MUL, TOOM_SQR;
size_t KARATSUBA_MUL, KARATSUBA_SQR, TOOM_MUL, TOOM_SQR;
};

const struct cutoffs max_cutoffs =
{ INT_MAX, INT_MAX, INT_MAX, INT_MAX };
{ SIZE_MAX, SIZE_MAX, SIZE_MAX, SIZE_MAX };

static void set_cutoffs(const struct cutoffs *c)
{
Expand Down Expand Up @@ -445,8 +444,8 @@ int main(int argc, char **argv)
if ((args.bncore == 0) && (printpreset == 0)) {
struct {
const char *name;
int *cutoff, *update;
uint64_t (*fn)(int size);
size_t *cutoff, *update;
uint64_t (*fn)(size_t size);
} test[] = {
#define T_MUL_SQR(n, o, f) { #n, &MP_##o##_CUTOFF, &(updated.o), MP_HAS(S_MP_##o) ? f : NULL }
/*
Expand All @@ -472,16 +471,16 @@ int main(int argc, char **argv)
}
}
if (args.terse == 1) {
printf("%d %d %d %d\n",
printf("%zu %zu %zu %zu\n",
updated.KARATSUBA_MUL,
updated.KARATSUBA_SQR,
updated.TOOM_MUL,
updated.TOOM_SQR);
} else {
printf("KARATSUBA_MUL_CUTOFF = %d\n", updated.KARATSUBA_MUL);
printf("KARATSUBA_SQR_CUTOFF = %d\n", updated.KARATSUBA_SQR);
printf("TOOM_MUL_CUTOFF = %d\n", updated.TOOM_MUL);
printf("TOOM_SQR_CUTOFF = %d\n", updated.TOOM_SQR);
printf("KARATSUBA_MUL_CUTOFF = %zu\n", updated.KARATSUBA_MUL);
printf("KARATSUBA_SQR_CUTOFF = %zu\n", updated.KARATSUBA_SQR);
printf("TOOM_MUL_CUTOFF = %zu\n", updated.TOOM_MUL);
printf("TOOM_SQR_CUTOFF = %zu\n", updated.TOOM_SQR);
}

if (args.print == 1) {
Expand Down Expand Up @@ -525,16 +524,16 @@ int main(int argc, char **argv)
if (args.verbose == 1) {
set_cutoffs(&orig);
if (args.terse == 1) {
printf("%d %d %d %d\n",
printf("%zu %zu %zu %zu\n",
MP_KARATSUBA_MUL_CUTOFF,
MP_KARATSUBA_SQR_CUTOFF,
MP_TOOM_MUL_CUTOFF,
MP_TOOM_SQR_CUTOFF);
} else {
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);
printf("KARATSUBA_MUL_CUTOFF = %zu\n", MP_KARATSUBA_MUL_CUTOFF);
printf("KARATSUBA_SQR_CUTOFF = %zu\n", MP_KARATSUBA_SQR_CUTOFF);
printf("TOOM_MUL_CUTOFF = %zu\n", MP_TOOM_MUL_CUTOFF);
printf("TOOM_SQR_CUTOFF = %zu\n", MP_TOOM_SQR_CUTOFF);
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions libtommath_VS2008.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,6 @@
RelativePath="mp_mod_2d.c"
>
</File>
<File
RelativePath="mp_mod_d.c"
>
</File>
<File
RelativePath="mp_montgomery_calc_normalization.c"
>
Expand Down
32 changes: 16 additions & 16 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp
mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_get_mag_ull.o mp_grow.o mp_init.o mp_init_copy.o \
mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_ll.o mp_init_multi.o mp_init_set.o mp_init_size.o \
mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_init_ull.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o \
mp_log_u32.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_mod_d.o mp_montgomery_calc_normalization.o \
mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o \
mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o \
mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o \
mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_prime_tab.o mp_radix_size.o mp_radix_smap.o \
mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \
mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_u32.o mp_rshd.o \
mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_ll.o mp_set_u32.o \
mp_set_u64.o mp_set_ul.o mp_set_ull.o mp_shrink.o mp_signed_rsh.o mp_sqr.o mp_sqrmod.o mp_sqrt.o \
mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o \
mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o s_mp_balance_mul.o s_mp_div_recursive.o s_mp_div_school.o \
s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod_fast.o s_mp_invmod_slow.o \
s_mp_karatsuba_mul.o s_mp_karatsuba_sqr.o s_mp_log.o s_mp_log_d.o s_mp_log_pow2.o \
s_mp_montgomery_reduce_fast.o s_mp_mul_digs.o s_mp_mul_digs_fast.o s_mp_mul_high_digs.o \
s_mp_mul_high_digs_fast.o s_mp_prime_is_divisible.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o \
s_mp_sqr_fast.o s_mp_sub.o s_mp_toom_mul.o s_mp_toom_sqr.o
mp_log_u32.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \
mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \
mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \
mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \
mp_prime_strong_lucas_selfridge.o mp_prime_tab.o mp_radix_size.o mp_radix_smap.o mp_rand.o \
mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o mp_reduce_2k_setup_l.o \
mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_u32.o mp_rshd.o mp_sbin_size.o mp_set.o \
mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_ll.o mp_set_u32.o mp_set_u64.o mp_set_ul.o \
mp_set_ull.o mp_shrink.o mp_signed_rsh.o mp_sqr.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o \
mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o \
s_mp_add.o s_mp_balance_mul.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \
s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod_fast.o s_mp_invmod_slow.o s_mp_karatsuba_mul.o \
s_mp_karatsuba_sqr.o s_mp_log.o s_mp_log_d.o s_mp_log_pow2.o s_mp_montgomery_reduce_fast.o \
s_mp_mul_digs.o s_mp_mul_digs_fast.o s_mp_mul_high_digs.o s_mp_mul_high_digs_fast.o \
s_mp_prime_is_divisible.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_fast.o s_mp_sub.o \
s_mp_toom_mul.o s_mp_toom_sqr.o

#END_INS

Expand Down
32 changes: 16 additions & 16 deletions makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp
mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_get_mag_ull.o mp_grow.o mp_init.o mp_init_copy.o \
mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_ll.o mp_init_multi.o mp_init_set.o mp_init_size.o \
mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_init_ull.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o \
mp_log_u32.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_mod_d.o mp_montgomery_calc_normalization.o \
mp_montgomery_reduce.o mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o \
mp_neg.o mp_or.o mp_pack.o mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o \
mp_prime_is_prime.o mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o \
mp_prime_rand.o mp_prime_strong_lucas_selfridge.o mp_prime_tab.o mp_radix_size.o mp_radix_smap.o \
mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o \
mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_u32.o mp_rshd.o \
mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_ll.o mp_set_u32.o \
mp_set_u64.o mp_set_ul.o mp_set_ull.o mp_shrink.o mp_signed_rsh.o mp_sqr.o mp_sqrmod.o mp_sqrt.o \
mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o \
mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o s_mp_balance_mul.o s_mp_div_recursive.o s_mp_div_school.o \
s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod_fast.o s_mp_invmod_slow.o \
s_mp_karatsuba_mul.o s_mp_karatsuba_sqr.o s_mp_log.o s_mp_log_d.o s_mp_log_pow2.o \
s_mp_montgomery_reduce_fast.o s_mp_mul_digs.o s_mp_mul_digs_fast.o s_mp_mul_high_digs.o \
s_mp_mul_high_digs_fast.o s_mp_prime_is_divisible.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o \
s_mp_sqr_fast.o s_mp_sub.o s_mp_toom_mul.o s_mp_toom_sqr.o
mp_log_u32.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \
mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \
mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \
mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \
mp_prime_strong_lucas_selfridge.o mp_prime_tab.o mp_radix_size.o mp_radix_smap.o mp_rand.o \
mp_read_radix.o mp_reduce.o mp_reduce_2k.o mp_reduce_2k_l.o mp_reduce_2k_setup.o mp_reduce_2k_setup_l.o \
mp_reduce_is_2k.o mp_reduce_is_2k_l.o mp_reduce_setup.o mp_root_u32.o mp_rshd.o mp_sbin_size.o mp_set.o \
mp_set_double.o mp_set_i32.o mp_set_i64.o mp_set_l.o mp_set_ll.o mp_set_u32.o mp_set_u64.o mp_set_ul.o \
mp_set_ull.o mp_shrink.o mp_signed_rsh.o mp_sqr.o mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o \
mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o \
s_mp_add.o s_mp_balance_mul.o s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o \
s_mp_exptmod_fast.o s_mp_get_bit.o s_mp_invmod_fast.o s_mp_invmod_slow.o s_mp_karatsuba_mul.o \
s_mp_karatsuba_sqr.o s_mp_log.o s_mp_log_d.o s_mp_log_pow2.o s_mp_montgomery_reduce_fast.o \
s_mp_mul_digs.o s_mp_mul_digs_fast.o s_mp_mul_high_digs.o s_mp_mul_high_digs_fast.o \
s_mp_prime_is_divisible.o s_mp_rand_jenkins.o s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_fast.o s_mp_sub.o \
s_mp_toom_mul.o s_mp_toom_sqr.o

HEADERS_PUB=tommath.h
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB)
Expand Down
Loading