YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h" #include"longlong.h"
/* Input is {ap,rn}; output is {rp,rn}, computation is modB^rn-1,andvaluesaresemi-normalised;zeroisrepresented aseither0orB^n-1.Needsascratchof2rnlimbsattp.
tp==rp is allowed. */ staticvoid
mpn_bc_sqrmod_bnm1 (mp_ptr rp, mp_srcptr ap, mp_size_t rn, mp_ptr tp)
{
mp_limb_t cy;
ASSERT (0 < rn);
mpn_sqr (tp, ap, rn);
cy = mpn_add_n (rp, tp, tp + rn, rn); /* If cy == 1, then the value of rp is at most B^rn - 2, so there can
* be no overflow when adding in the carry. */
MPN_INCR_U (rp, rn, cy);
}
/* Input is {ap,rn+1}; output is {rp,rn+1}, in normalisedrepresentation,computationismodB^rn+1.Needs ascratchareaof2rnlimbsattp;tp==rpisallowed.
Output is normalised. */ staticvoid
mpn_bc_sqrmod_bnp1 (mp_ptr rp, mp_srcptr ap, mp_size_t rn, mp_ptr tp)
{
mp_limb_t cy; unsigned k;
#if HAVE_NATIVE_mpn_rsh1add_n || HAVE_NATIVE_mpn_rsh1add_nc #if HAVE_NATIVE_mpn_rsh1add_nc
cy = mpn_rsh1add_nc(rp, rp, xp, n, xp[n]); /* B^n = 1 */
hi = cy << (GMP_NUMB_BITS - 1);
cy = 0; /* next update of rp[n-1] will set cy = 1 only if rp[n-1]+=hi
overflows, i.e. a further increment will not overflow again. */ #else/* ! _nc */
cy = xp[n] + mpn_rsh1add_n(rp, rp, xp, n); /* B^n = 1 */
hi = (cy<<(GMP_NUMB_BITS-1))&GMP_NUMB_MASK; /* (cy&1) << ... */
cy >>= 1; /* cy = 1 only if xp[n] = 1 i.e. {xp,n} = ZERO, this implies that
the rsh1add was a simple rshift: the top bit is 0. cy=1 => hi=0. */ #endif #if GMP_NAIL_BITS == 0
add_ssaaaa(cy, rp[n-1], cy, rp[n-1], CNST_LIMB(0), hi); #else
cy += (hi & rp[n-1]) >> (GMP_NUMB_BITS-1);
rp[n-1] ^= hi; #endif #else/* ! HAVE_NATIVE_mpn_rsh1add_n */ #if HAVE_NATIVE_mpn_add_nc
cy = mpn_add_nc(rp, rp, xp, n, xp[n]); #else/* ! _nc */
cy = xp[n] + mpn_add_n(rp, rp, xp, n); /* xp[n] == 1 implies {xp,n} == ZERO */ #endif
cy += (rp[0]&1);
mpn_rshift(rp, rp, n, 1);
ASSERT (cy <= 2);
hi = (cy<<(GMP_NUMB_BITS-1))&GMP_NUMB_MASK; /* (cy&1) << ... */
cy >>= 1; /* We can have cy != 0 only if hi = 0... */
ASSERT ((rp[n-1] & GMP_NUMB_HIGHBIT) == 0);
rp[n-1] |= hi; /* ... rp[n-1] + cy can not overflow, the following INCR is correct. */ #endif
ASSERT (cy <= 1); /* Next increment can not overflow, read the previous comments about cy. */
ASSERT ((cy == 0) || ((rp[n-1] & GMP_NUMB_HIGHBIT) == 0));
MPN_INCR_U(rp, n, cy);
/* Compute the highest half: ([(xp+xm)/2mod(B^n-1)]-xp)*B^n
*/ if (UNLIKELY (2*an < rn))
{ /* Note that in this case, the only way the result can equal zeromodB^{rn}-1isiftheinputiszero,and thentheoutputofboththerecursivecallsandthisCRT
reconstruction is zero, not B^{rn} - 1. */
cy = mpn_sub_n (rp + n, rp, xp, 2*an - n);
/* FIXME: This subtraction of the high parts is not really necessary,wedoittogetthecarryout,andforsanity
checking. */
cy = xp[n] + mpn_sub_nc (xp + 2*an - n, rp + 2*an - n,
xp + 2*an - n, rn - 2*an, cy);
ASSERT (mpn_zero_p (xp + 2*an - n+1, rn - 1 - 2*an));
cy = mpn_sub_1 (rp, rp, 2*an, cy);
ASSERT (cy == (xp + 2*an - n)[0]);
} else
{
cy = xp[n] + mpn_sub_n (rp + n, rp, xp, n); /* cy = 1 only if {xp,n+1} is not ZERO, i.e. {rp,n} is not ZERO.
DECR will affect _at most_ the lowest n limbs. */
MPN_DECR_U (rp, 2*n, cy);
} #undef a0 #undef a1 #undef xp #undef sp1
}
}
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.