Add recent bug fixes to the FFT code

This commit is contained in:
gladman 2012-07-14 14:39:23 +00:00
parent f98ebdcf26
commit 0e06c37a20
2 changed files with 14 additions and 12 deletions

View File

@ -37,7 +37,7 @@ fft_combine_limbs(mp_ptr res, mp_srcptr * poly, long length, mp_size_t coeff_lim
{
mp_size_t skip, i;
for (skip = 0, i = 0; i < length && skip + output_limbs <= total_limbs; i++, skip += coeff_limbs)
for (skip = 0, i = 0; i < length && skip + output_limbs + 1 <= total_limbs; i++, skip += coeff_limbs)
mpn_add(res + skip, res + skip, output_limbs + 1, poly[i], output_limbs);
while ((skip < total_limbs) && (i < length))
@ -71,7 +71,7 @@ fft_combine_bits(mp_ptr res, mp_srcptr * poly, long length, mp_bitcnt_t bits, mp
limb_ptr = res;
end = res + total_limbs;
for (i = 0; i < length && limb_ptr + output_limbs < end; i++)
for (i = 0; i < length && limb_ptr + output_limbs + 1 < end; i++)
{
if (shift_bits)
{

View File

@ -46,6 +46,18 @@ int mpn_mulmod_2expp1(mp_ptr r, mp_srcptr i1, mp_srcptr i2, mp_size_t n, mp_size
mp_limb_t c = 2 * i1[limbs] + i2[limbs];
if (c & 1)
{
mpn_neg_n(r, i1, limbs + 1);
mpn_normmod_2expp1(r, limbs);
return 0;
} else if (c & 2)
{
mpn_neg_n(r, i2, limbs + 1);
mpn_normmod_2expp1(r, limbs);
return 0;
}
if (limbs <= FFT_MULMOD_2EXPP1_CUTOFF)
{
if(bits)
@ -64,16 +76,6 @@ int mpn_mulmod_2expp1(mp_ptr r, mp_srcptr i1, mp_srcptr i2, mp_size_t n, mp_size
fft_mulmod_2expp1(r, i1, i2, limbs, depth1, w1);
if (c & 1)
{
mpn_neg_n(r, i1, limbs + 1);
mpn_normmod_2expp1(r, limbs);
} else if (c & 2)
{
mpn_neg_n(r, i2, limbs + 1);
mpn_normmod_2expp1(r, limbs);
}
return r[limbs];
}