1 /* mpn_mul_n -- multiply natural numbers.
3 Copyright 1991, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2005, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 mpn_mul_n (mp_ptr p, mp_srcptr a, mp_srcptr b, mp_size_t n)
29 ASSERT (! MPN_OVERLAP_P (p, 2 * n, a, n));
30 ASSERT (! MPN_OVERLAP_P (p, 2 * n, b, n));
32 if (BELOW_THRESHOLD (n, MUL_TOOM22_THRESHOLD))
34 mpn_mul_basecase (p, a, n, b, n);
36 else if (BELOW_THRESHOLD (n, MUL_TOOM33_THRESHOLD))
38 /* Allocate workspace of fixed size on stack: fast! */
39 mp_limb_t ws[mpn_toom22_mul_itch (MUL_TOOM33_THRESHOLD_LIMIT-1,
40 MUL_TOOM33_THRESHOLD_LIMIT-1)];
41 ASSERT (MUL_TOOM33_THRESHOLD <= MUL_TOOM33_THRESHOLD_LIMIT);
42 mpn_toom22_mul (p, a, n, b, n, ws);
44 else if (BELOW_THRESHOLD (n, MUL_TOOM44_THRESHOLD))
49 ws = TMP_SALLOC_LIMBS (mpn_toom33_mul_itch (n, n));
50 mpn_toom33_mul (p, a, n, b, n, ws);
53 else if (BELOW_THRESHOLD (n, MUL_TOOM6H_THRESHOLD))
58 ws = TMP_SALLOC_LIMBS (mpn_toom44_mul_itch (n, n));
59 mpn_toom44_mul (p, a, n, b, n, ws);
62 else if (BELOW_THRESHOLD (n, MUL_TOOM8H_THRESHOLD))
67 ws = TMP_SALLOC_LIMBS (mpn_toom6_mul_n_itch (n));
68 mpn_toom6h_mul (p, a, n, b, n, ws);
71 else if (BELOW_THRESHOLD (n, MUL_FFT_THRESHOLD))
76 ws = TMP_ALLOC_LIMBS (mpn_toom8_mul_n_itch (n));
77 mpn_toom8h_mul (p, a, n, b, n, ws);
82 /* The current FFT code allocates its own space. That should probably
84 mpn_fft_mul (p, a, n, b, n);