beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / mullo_basecase.c
blob37d9018a49319f38cc5d62f77a95eb3c593f6ab8
1 /* mpn_mullo_basecase -- Internal routine to multiply two natural
2 numbers of length n and return the low part.
4 THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY
5 SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES.
8 Copyright (C) 2000, 2002, 2004, 2015 Free Software Foundation, Inc.
10 This file is part of the GNU MP Library.
12 The GNU MP Library is free software; you can redistribute it and/or modify
13 it under the terms of either:
15 * the GNU Lesser General Public License as published by the Free
16 Software Foundation; either version 3 of the License, or (at your
17 option) any later version.
21 * the GNU General Public License as published by the Free Software
22 Foundation; either version 2 of the License, or (at your option) any
23 later version.
25 or both in parallel, as here.
27 The GNU MP Library is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
29 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30 for more details.
32 You should have received copies of the GNU General Public License and the
33 GNU Lesser General Public License along with the GNU MP Library. If not,
34 see https://www.gnu.org/licenses/. */
36 #include "gmp.h"
37 #include "gmp-impl.h"
39 /* FIXME: Should optionally use mpn_mul_2/mpn_addmul_2. */
41 #ifndef MULLO_VARIANT
42 #define MULLO_VARIANT 2
43 #endif
46 #if MULLO_VARIANT == 1
47 void
48 mpn_mullo_basecase (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
50 mp_size_t i;
52 mpn_mul_1 (rp, up, n, vp[0]);
54 for (i = n - 1; i > 0; i--)
56 vp++;
57 rp++;
58 mpn_addmul_1 (rp, up, i, vp[0]);
61 #endif
64 #if MULLO_VARIANT == 2
65 void
66 mpn_mullo_basecase (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n)
68 mp_limb_t h;
70 h = up[0] * vp[n - 1];
72 if (n != 1)
74 mp_size_t i;
75 mp_limb_t v0;
77 v0 = *vp++;
78 h += up[n - 1] * v0 + mpn_mul_1 (rp, up, n - 1, v0);
79 rp++;
81 for (i = n - 2; i > 0; i--)
83 v0 = *vp++;
84 h += up[i] * v0 + mpn_addmul_1 (rp, up, i, v0);
85 rp++;
89 rp[0] = h;
91 #endif