1 /* mpn_pow_1 -- Compute powers R = U^exp.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2002 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Lesser General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21 You should have received a copy of the GNU Lesser General Public License along
22 with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
30 mpn_pow_1 (mp_ptr rp, mp_srcptr bp, mp_size_t bn, mp_limb_t exp, mp_ptr tp)
38 /* FIXME: Add operand overlap criteria */
49 MPN_COPY (rp, bp, bn);
54 /* Count number of bits in exp, and compute where to put initial square in
55 order to magically get results in the entry rp. Use simple code,
56 optimized for small exp. For large exp, the bignum operations will take
57 so much time that the slowness of this code will be negligible. */
60 for (x = exp; x != 0; x >>= 1)
75 rn = 2 * bn; rn -= rp[rn - 1] == 0;
77 for (i = GMP_LIMB_BITS - cnt - 1;;)
80 if ((exp & GMP_LIMB_HIGHBIT) != 0)
82 rp[rn] = mpn_mul_1 (rp, rp, rn, bl);
90 rn = 2 * rn; rn -= tp[rn - 1] == 0;
96 if (((par ^ cnt) & 1) == 0)
100 rn = 2 * bn; rn -= rp[rn - 1] == 0;
102 for (i = GMP_LIMB_BITS - cnt - 1;;)
105 if ((exp & GMP_LIMB_HIGHBIT) != 0)
107 rn = rn + bn - (mpn_mul (tp, rp, rn, bp, bn) == 0);
108 MP_PTR_SWAP (rp, tp);
114 mpn_sqr (tp, rp, rn);
115 rn = 2 * rn; rn -= tp[rn - 1] == 0;
116 MP_PTR_SWAP (rp, tp);