diff options
author | Niels M?ller <nisse@lysator.liu.se> | 2014-02-09 22:25:03 +0100 |
---|---|---|
committer | Niels M?ller <nisse@lysator.liu.se> | 2014-02-09 22:25:03 +0100 |
commit | c8d93ee947af2abfec03710244e099ec294d1ca6 (patch) | |
tree | 2f9708784a334ec3a788b65fe57fe738cc992671 /tune/tuneup.c | |
parent | 0fc7eacb163ae1847566fac4e0aa0bbb38792de1 (diff) | |
download | gmp-c8d93ee947af2abfec03710244e099ec294d1ca6.tar.gz |
Fixed off-by-one problem in tuning of mpn_sec_powm.
Diffstat (limited to 'tune/tuneup.c')
-rw-r--r-- | tune/tuneup.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tune/tuneup.c b/tune/tuneup.c index 9f731e4dd..0b2c5d22e 100644 --- a/tune/tuneup.c +++ b/tune/tuneup.c @@ -1911,7 +1911,10 @@ tune_powm_sec (void) printf ("#define POWM_SEC_TABLE "); - for (nbits = 1; nbits <= n_max * GMP_NUMB_BITS; ) + /* For nbits == 1, we should always use k == 1, so no need to tune + that. Starting with nbits == 2 also ensure that nbits always is + larger than the windowsize k+1. */ + for (nbits = 2; nbits <= n_max * GMP_NUMB_BITS; ) { n = (nbits - 1) / GMP_NUMB_BITS + 1; @@ -1952,6 +1955,10 @@ tune_powm_sec (void) if (possible_nbits_cutoff) { /* Two consecutive sizes indicate k increase, obey. */ + + /* Must always have x[k] >= k */ + ASSERT_ALWAYS (possible_nbits_cutoff >= k); + if (k > 1) printf (","); printf ("%ld", (long) possible_nbits_cutoff); @@ -1962,7 +1969,10 @@ tune_powm_sec (void) { /* One measurement indicate k increase, save nbits for further consideration. */ - possible_nbits_cutoff = nbits; + /* The new larger k gets used for sizes > the cutoff + value, hence the cutoff should be one less than the + smallest size where it gives a speedup. */ + possible_nbits_cutoff = nbits - 1; } } else |