2012-01-04 18:48:12 -05:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2009, 2011 William Hart. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
conditions and the following disclaimer.
|
|
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY William Hart ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL William Hart OR
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those of the
|
|
|
|
authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
or implied, of William Hart.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mpir.h"
|
|
|
|
#include "gmp-impl.h"
|
|
|
|
|
2012-01-17 10:13:24 -05:00
|
|
|
void
|
2012-09-27 16:00:46 -04:00
|
|
|
mpn_mul_mfa_trunc_sqrt2(mp_ptr r1, mp_srcptr i1, mp_size_t n1,
|
2012-01-17 10:13:24 -05:00
|
|
|
mp_srcptr i2, mp_size_t n2, mp_bitcnt_t depth, mp_bitcnt_t w)
|
2012-01-04 18:48:12 -05:00
|
|
|
{
|
2012-06-03 09:01:34 -04:00
|
|
|
mp_size_t n = (((mp_size_t)1)<<depth);
|
2012-01-04 18:48:12 -05:00
|
|
|
mp_bitcnt_t bits1 = (n*w - (depth+1))/2;
|
2012-06-03 09:01:34 -04:00
|
|
|
mp_size_t sqrt = (((mp_size_t)1)<<(depth/2));
|
2012-01-04 18:48:12 -05:00
|
|
|
|
|
|
|
mp_size_t r_limbs = n1 + n2;
|
|
|
|
mp_size_t limbs = (n*w)/GMP_LIMB_BITS;
|
|
|
|
mp_size_t size = limbs + 1;
|
|
|
|
|
|
|
|
mp_size_t j1 = (n1*GMP_LIMB_BITS - 1)/bits1 + 1;
|
|
|
|
mp_size_t j2 = (n2*GMP_LIMB_BITS - 1)/bits1 + 1;
|
|
|
|
|
|
|
|
mp_size_t i, j, trunc;
|
|
|
|
|
2012-01-17 10:13:24 -05:00
|
|
|
mp_ptr * ii, * jj, t1, t2, s1, ptr;
|
2012-01-04 18:48:12 -05:00
|
|
|
mp_limb_t * tt;
|
|
|
|
TMP_DECL;
|
|
|
|
|
|
|
|
TMP_MARK;
|
2012-01-05 08:52:16 -05:00
|
|
|
ii = TMP_BALLOC_MP_PTRS(4*(n + n*size) + 5*size);
|
2012-01-17 10:13:24 -05:00
|
|
|
for (i = 0, ptr = (mp_ptr) ii + 4*n; i < 4*n; i++, ptr += size)
|
2012-01-04 18:48:12 -05:00
|
|
|
{
|
|
|
|
ii[i] = ptr;
|
|
|
|
}
|
|
|
|
t1 = ptr;
|
|
|
|
t2 = t1 + size;
|
|
|
|
s1 = t2 + size;
|
|
|
|
tt = s1 + size;
|
|
|
|
|
2012-01-07 08:29:44 -05:00
|
|
|
if (i1 != i2)
|
2012-01-04 18:48:12 -05:00
|
|
|
{
|
2012-01-07 08:29:44 -05:00
|
|
|
jj = TMP_BALLOC_MP_PTRS(4*(n + n*size));
|
2012-01-17 10:13:24 -05:00
|
|
|
for (i = 0, ptr = (mp_ptr) jj + 4*n; i < 4*n; i++, ptr += size)
|
2012-01-07 08:29:44 -05:00
|
|
|
{
|
|
|
|
jj[i] = ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
jj = ii;
|
|
|
|
|
2012-01-16 03:42:34 -05:00
|
|
|
trunc = j1 + j2 - 1;
|
|
|
|
if (trunc <= 2*n) trunc = 2*n + 1; /* trunc must be greater than 2n */
|
|
|
|
trunc = 2*sqrt*((trunc + 2*sqrt - 1)/(2*sqrt)); /* trunc must be divisible by 2*sqrt */
|
2012-01-04 18:48:12 -05:00
|
|
|
|
2012-10-18 12:29:08 -04:00
|
|
|
j1 = mpir_fft_split_bits(ii, i1, n1, bits1, limbs);
|
2012-01-04 18:48:12 -05:00
|
|
|
for (j = j1 ; j < 4*n; j++)
|
|
|
|
mpn_zero(ii[j], limbs + 1);
|
|
|
|
|
2012-10-18 12:29:08 -04:00
|
|
|
mpir_fft_mfa_trunc_sqrt2_outer(ii, n, w, &t1, &t2, &s1, sqrt, trunc);
|
2012-01-04 18:48:12 -05:00
|
|
|
|
2012-01-07 08:29:44 -05:00
|
|
|
if (i1 != i2)
|
|
|
|
{
|
2012-10-18 12:29:08 -04:00
|
|
|
j2 = mpir_fft_split_bits(jj, i2, n2, bits1, limbs);
|
2012-01-07 08:29:44 -05:00
|
|
|
for (j = j2 ; j < 4*n; j++)
|
|
|
|
mpn_zero(jj[j], limbs + 1);
|
2012-10-18 12:29:08 -04:00
|
|
|
mpir_fft_mfa_trunc_sqrt2_outer(jj, n, w, &t1, &t2, &s1, sqrt, trunc);
|
2012-01-07 08:29:44 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
j2 = j1;
|
2012-01-04 18:48:12 -05:00
|
|
|
|
2012-10-18 12:29:08 -04:00
|
|
|
mpir_fft_mfa_trunc_sqrt2_inner(ii, jj, n, w, &t1, &t2, &s1, sqrt, trunc, tt);
|
|
|
|
mpir_ifft_mfa_trunc_sqrt2_outer(ii, n, w, &t1, &t2, &s1, sqrt, trunc);
|
2012-01-04 18:48:12 -05:00
|
|
|
|
|
|
|
mpn_zero(r1, r_limbs);
|
2012-10-18 12:29:08 -04:00
|
|
|
mpir_fft_combine_bits(r1, ii, j1 + j2 - 1, bits1, limbs, r_limbs);
|
2012-01-04 18:48:12 -05:00
|
|
|
|
|
|
|
TMP_FREE;
|
2014-03-24 14:54:51 -04:00
|
|
|
}
|