THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES. IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
Copyright 2020-2022 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
or
* the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received copies of the GNU General Public License and the GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
rp += k * n;
op += k * n;
hp = op;
hl = hp[n]; /* initial op[k*n]. */
ASSERT (hl < GMP_NUMB_MAX - 1);
#if MOD_BKNP1_ONLY3 == 0 /* The first MPN_INCR_U (rp + n, 1, cy); in the loop should be
rp[n] = cy; */
*rp = 0; #endif
i = k >> 1; do
{
mp_limb_t cy, bw;
rp -= n;
op -= n;
cy = hl + mpn_add_n (rp, op, hp, n); #if MOD_BKNP1_ONLY3
rp[n] = cy; #else
MPN_INCR_U (rp + n, (k - i * 2) * n + 1, cy); #endif
rp -= n;
op -= n;
bw = hl + mpn_sub_n (rp, op, hp, n);
MPN_DECR_U (rp + n, (k - i * 2 + 1) * n + 1, bw);
} while (--i != 0);
for (; (hl = *(rp += k * n)) != 0; ) /* Should run only once... */
{
*rp = 0;
i = k >> 1; do
{
rp -= n;
MPN_INCR_U (rp, (k - i * 2 + 1) * n + 1, hl);
rp -= n;
MPN_DECR_U (rp, (k - i * 2 + 2) * n + 1, hl);
} while (--i != 0);
}
}
/* Fully normalise */
MPN_DECR_U (r, n + 1, h);
h -= r[n];
r[n] = 0;
MPN_INCR_U (r, n + 1, h);
}
staticvoid
_mpn_modbnp1_neg_ip (mp_ptr r, mp_size_t n, mp_limb_t h)
{
r[n] = 0;
MPN_INCR_U (r, n + 1, -h); if (UNLIKELY (r[n] != 0))
_mpn_modbnp1_pn_ip (r, n, 1);
}
staticvoid
_mpn_modbnp1_nc_ip (mp_ptr r, mp_size_t n, mp_limb_t h)
{ if (h & GMP_NUMB_HIGHBIT) /* This means h < 0 */
{
_mpn_modbnp1_neg_ip (r, n, h);
} else
{
r[n] = h; if (h)
_mpn_modbnp1_pn_ip(r, n, h);
}
}
/* {rp, rn + 1} = {op, on} mod (B^{rn}+1) */ /* Used when rn < on < 2*rn. */ staticvoid
_mpn_modbnp1 (mp_ptr rp, mp_size_t rn, mp_srcptr op, mp_size_t on)
{
mp_limb_t bw;
#if 0 if (UNLIKELY (on <= rn))
{
MPN_COPY (rp, op, on);
MPN_ZERO (rp + on, rn - on); return;
} #endif
cy = - mpn_sub_n (rp, op, op + rn, rn); for (;;) {
op += 2 * rn;
cy += mpn_add_n (rp, rp, op, rn); if (--k == 0) break;
cy -= mpn_sub_n (rp, rp, op + rn, rn);
};
cy += op[rn];
_mpn_modbnp1_nc_ip (rp, rn, cy);
}
/* For the various mpn_divexact_byN here, fall back to using either mpn_pi1_bdiv_q_1 or mpn_divexact_1. The former has less overhead and is faster if it is native. For now, since mpn_divexact_1 is native on platforms where mpn_pi1_bdiv_q_1 does not yet exist, do not use
mpn_pi1_bdiv_q_1 unconditionally. FIXME. */
/* Thanks to Chinese remainder theorem, store in {rp, k*n+1} the value mod (B^(k*n)+1), given {ap, k*n+1} mod ((B^(k*n)+1)/(B^n+1)) and {bp, n+1} mod (B^n+1) . {tp, n+1} is a scratch area. tp == rp or rp == ap are possible.
*/ staticvoid
_mpn_crt (mp_ptr rp, mp_srcptr ap, mp_srcptr bp,
mp_size_t n, unsigned k, mp_ptr tp)
{
mp_limb_t mod; unsigned i;
#if MOD_BKNP1_ONLY3
ASSERT (k == 3);
k = 3; #endif
_mpn_modbnp1_kn (tp, ap, n, k); if (mpn_sub_n (tp, bp, tp, n + 1))
_mpn_modbnp1_neg_ip (tp, n, tp[n]);
#if MOD_BKNP1_USE11 if (UNLIKELY (k == 11))
{
ASSERT (GMP_NUMB_BITS % 2 == 0); /* mod <- -Mod(B^n+1,11)^-1 */
mod = n * (GMP_NUMB_BITS % 5) % 5; if ((mod > 2) || UNLIKELY (mod == 0))
mod += 5;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.