1 /*
2 
3 Copyright 2009, 2011 William Hart. All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are
6 permitted provided that the following conditions are met:
7 
8    1. Redistributions of source code must retain the above copyright notice, this list of
9       conditions and the following disclaimer.
10 
11    2. Redistributions in binary form must reproduce the above copyright notice, this list
12       of conditions and the following disclaimer in the documentation and/or other materials
13       provided with the distribution.
14 
15 THIS SOFTWARE IS PROVIDED BY William Hart ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL William Hart OR
18 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 The views and conclusions contained in the software and documentation are those of the
26 authors and should not be interpreted as representing official policies, either expressed
27 or implied, of William Hart.
28 
29 */
30 
31 #include "mpir.h"
32 #include "gmp-impl.h"
33 #include "longlong.h"
34 
mpir_fft_adjust(mp_ptr r,mp_ptr i1,mp_size_t i,mp_size_t limbs,mp_bitcnt_t w)35 void mpir_fft_adjust(mp_ptr r, mp_ptr i1, mp_size_t i, mp_size_t limbs, mp_bitcnt_t w)
36 {
37    mp_bitcnt_t b1;
38    mp_limb_t cy;
39    mp_size_t x;
40 
41    b1 = i*w;
42    x  = b1/GMP_LIMB_BITS;
43    b1 = b1%GMP_LIMB_BITS;
44 
45    if (x)
46    {
47       mpn_copyi(r + x, i1, limbs - x);
48       r[limbs] = 0;
49       cy = mpn_neg_n(r, i1 + limbs - x, x);
50       mpn_addmod_2expp1_1(r + x, limbs - x, -i1[limbs]);
51       mpn_sub_1(r + x, r + x, limbs - x + 1, cy);
52       mpn_mul_2expmod_2expp1(r, r, limbs, b1);
53    } else
54       mpn_mul_2expmod_2expp1(r, i1, limbs, b1);
55 }
56