Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/source/nmod_poly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,25 @@ Multiplication
corresponding coefficients of the product of ``poly1`` and
``poly2``, the remaining coefficients being arbitrary.

.. function:: int _nmod_poly_mullow_want_fft_small(slong len1, slong len2, slong n, int squaring, nmod_t mod)

Estimate whether *fft_small* multiplication should be used instead of
other multiplication algorithms, given inputs of length *len1* and *len2*
and output truncation to length *n*.

.. function:: int _nmod_poly_mullow_fft_small_repack(nn_ptr z, nn_srcptr a, slong an, nn_srcptr b, slong bn, slong zn, nmod_t mod)

Internal helper function for :func:`_nmod_poly_mullow_fft_small`: if the
inputs are small enough to perform a repacked convolution of half the
length, multiply and return 1, otherwise do nothing and return 0.
The conditions on the arguments are the same as for :func:`_nmod_poly_mullow`.

.. function:: void _nmod_poly_mullow_fft_small(nn_ptr z, nn_srcptr a, slong an, nn_srcptr b, slong bn, slong zn, nmod_t mod)

Low multiplication via the *fft_small* module. Throws an error
if *fft_small* is not available. The conditions on the arguments
are the same as for :func:`_nmod_poly_mullow`.

.. function:: void _nmod_poly_mulmod(nn_ptr res, nn_srcptr poly1, slong len1, nn_srcptr poly2, slong len2, nn_srcptr f, slong lenf, nmod_t mod)

Sets ``res`` to the remainder of the product of ``poly1`` and
Expand Down
4 changes: 4 additions & 0 deletions src/nmod_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ void nmod_poly_mullow_KS(nmod_poly_t res, const nmod_poly_t poly1, const nmod_po
void _nmod_poly_mul(nn_ptr res, nn_srcptr poly1, slong len1, nn_srcptr poly2, slong len2, nmod_t mod);
void nmod_poly_mul(nmod_poly_t res, const nmod_poly_t poly1, const nmod_poly_t poly2);

int _nmod_poly_mullow_fft_small_repack(nn_ptr z, nn_srcptr a, slong an, nn_srcptr b, slong bn, slong zn, nmod_t mod);
int _nmod_poly_mullow_want_fft_small(slong len1, slong len2, slong n, int squaring, nmod_t mod);
void _nmod_poly_mullow_fft_small(nn_ptr z, nn_srcptr a, slong an, nn_srcptr b, slong bn, slong zn, nmod_t mod);

void _nmod_poly_mullow(nn_ptr res, nn_srcptr poly1, slong len1, nn_srcptr poly2, slong len2, slong trunc, nmod_t mod);
void nmod_poly_mullow(nmod_poly_t res, const nmod_poly_t poly1, const nmod_poly_t poly2, slong trunc);

Expand Down
45 changes: 5 additions & 40 deletions src/nmod_poly/mul.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,6 @@
#include "nmod.h"
#include "nmod_poly.h"

#if FLINT_HAVE_FFT_SMALL

#include "fft_small.h"

/* todo: check unbalanced cutoffs */

static const short fft_mul_tab[] = {1326, 1326, 1095, 802, 674, 537, 330, 306, 290,
274, 200, 192, 182, 173, 163, 99, 97, 93, 90, 82, 80, 438, 414, 324, 393,
298, 298, 268, 187, 185, 176, 176, 168, 167, 158, 158, 97, 96, 93, 92, 89,
89, 85, 85, 80, 81, 177, 172, 163, 162, 164, 176, 171, 167, 167, 164, 163,
163, 160, 165, 95, 96, 90, 94, };

static const short fft_sqr_tab[] = {1420, 1420, 1353, 964, 689, 569, 407, 353, 321,
321, 292, 279, 200, 182, 182, 159, 159, 152, 145, 139, 723, 626, 626, 569,
597, 448, 542, 292, 292, 200, 191, 191, 182, 182, 166, 166, 166, 159, 159,
159, 152, 152, 145, 145, 93, 200, 191, 182, 182, 182, 182, 191, 191, 191,
182, 182, 174, 182, 182, 182, 152, 152, 152, 145, };

#endif

void _nmod_poly_mul(nn_ptr res, nn_srcptr poly1, slong len1,
nn_srcptr poly2, slong len2, nmod_t mod)
{
Expand All @@ -44,29 +24,14 @@ void _nmod_poly_mul(nn_ptr res, nn_srcptr poly1, slong len1,
return;
}

bits = NMOD_BITS(mod);
cutoff_len = FLINT_MIN(len1, 2 * len2);

#if FLINT_HAVE_FFT_SMALL

if (poly1 == poly2 && len1 == len2)
{
if (cutoff_len >= fft_sqr_tab[bits - 1])
{
_nmod_poly_mul_mid_default_mpn_ctx(res, 0, len1 + len2 - 1, poly1, len1, poly2, len2, mod);
return;
}
}
else
if (_nmod_poly_mullow_want_fft_small(len1, len2, len1 + len2 - 1, (poly1 == poly2 && len1 == len2), mod))
{
if (cutoff_len >= fft_mul_tab[bits - 1])
{
_nmod_poly_mul_mid_default_mpn_ctx(res, 0, len1 + len2 - 1, poly1, len1, poly2, len2, mod);
return;
}
_nmod_poly_mullow_fft_small(res, poly1, len1, poly2, len2, len1 + len2 - 1, mod);
return;
}

#endif
bits = NMOD_BITS(mod);
cutoff_len = FLINT_MIN(len1, 2 * len2);

if (3 * cutoff_len < 2 * FLINT_MAX(bits, 10))
_nmod_poly_mul_classical(res, poly1, len1, poly2, len2, mod);
Expand Down
26 changes: 3 additions & 23 deletions src/nmod_poly/mullow.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@
#include "nmod.h"
#include "nmod_poly.h"

#if FLINT_HAVE_FFT_SMALL

#include "fft_small.h"

/* todo: separate squaring table */
/* todo: check unbalanced cutoffs */

static const short fft_mullow_tab[] = {1115, 1115, 597, 569, 407, 321, 306, 279, 191,
182, 166, 159, 152, 145, 139, 89, 85, 78, 75, 75, 69, 174, 174, 166, 159,
152, 152, 152, 97, 101, 106, 111, 101, 101, 101, 139, 145, 145, 139, 145,
145, 139, 145, 145, 145, 182, 182, 182, 182, 182, 182, 191, 200, 220, 210,
200, 210, 210, 210, 210, 191, 182, 182, 174, };

#endif


void _nmod_poly_mullow(nn_ptr res, nn_srcptr poly1, slong len1,
nn_srcptr poly2, slong len2, slong n, nmod_t mod)
{
Expand All @@ -49,17 +33,13 @@ void _nmod_poly_mullow(nn_ptr res, nn_srcptr poly1, slong len1,
return;
}

bits = NMOD_BITS(mod);

#if FLINT_HAVE_FFT_SMALL

if (len2 >= fft_mullow_tab[bits - 1])
if (_nmod_poly_mullow_want_fft_small(len1, len2, n, (poly1 == poly2 && len1 == len2), mod))
{
_nmod_poly_mul_mid_default_mpn_ctx(res, 0, n, poly1, len1, poly2, len2, mod);
_nmod_poly_mullow_fft_small(res, poly1, len1, poly2, len2, n, mod);
return;
}

#endif
bits = NMOD_BITS(mod);

if (n < 10 + bits * bits / 10)
_nmod_poly_mullow_classical(res, poly1, len1, poly2, len2, n, mod);
Expand Down
Loading
Loading