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 2.1 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; see the file COPYING.LIB. If not, write to the Free
23
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
32
mpn_pow_1 (mp_ptr rp, mp_srcptr bp, mp_size_t bn, mp_limb_t exp, mp_ptr tp)
48
MPN_COPY (rp, bp, bn);
53
/* Count number of bits in exp, and compute where to put initial square in
54
order to magically get results in the entry rp. Use simple code,
55
optimized for small exp. For large exp, the bignum operations will take
56
so much time that the slowness of this code will be negligible. */
59
for (x = exp; x != 0; x >>= 1)
73
mpn_sqr_n (rp, bp, bn);
74
rn = 2 * bn; rn -= rp[rn - 1] == 0;
76
for (i = GMP_LIMB_BITS - cnt - 1;;)
79
if ((exp & GMP_LIMB_HIGHBIT) != 0)
81
rp[rn] = mpn_mul_1 (rp, rp, rn, bl);
88
mpn_sqr_n (tp, rp, rn);
89
rn = 2 * rn; rn -= tp[rn - 1] == 0;
95
if (((par ^ cnt) & 1) == 0)
98
mpn_sqr_n (rp, bp, bn);
99
rn = 2 * bn; rn -= rp[rn - 1] == 0;
101
for (i = GMP_LIMB_BITS - cnt - 1;;)
104
if ((exp & GMP_LIMB_HIGHBIT) != 0)
106
rn = rn + bn - (mpn_mul (tp, rp, rn, bp, bn) == 0);
107
MP_PTR_SWAP (rp, tp);
113
mpn_sqr_n (tp, rp, rn);
114
rn = 2 * rn; rn -= tp[rn - 1] == 0;
115
MP_PTR_SWAP (rp, tp);