Annotation of OpenXM/src/kan96xx/gmp-2.0.2-ssh-2/mpz/mul_2exp.c, Revision 1.1
1.1 ! takayama 1: /* mpz_mul_2exp -- Multiply a bignum by 2**CNT
! 2:
! 3: Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
! 4:
! 5: This file is part of the GNU MP Library.
! 6:
! 7: The GNU MP Library is free software; you can redistribute it and/or modify
! 8: it under the terms of the GNU Library General Public License as published by
! 9: the Free Software Foundation; either version 2 of the License, or (at your
! 10: option) any later version.
! 11:
! 12: The GNU MP Library is distributed in the hope that it will be useful, but
! 13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
! 15: License for more details.
! 16:
! 17: You should have received a copy of the GNU Library General Public License
! 18: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
! 19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 20: MA 02111-1307, USA. */
! 21:
! 22: #include "gmp.h"
! 23: #include "gmp-impl.h"
! 24:
! 25: void
! 26: #if __STDC__
! 27: mpz_mul_2exp (mpz_ptr w, mpz_srcptr u, unsigned long int cnt)
! 28: #else
! 29: mpz_mul_2exp (w, u, cnt)
! 30: mpz_ptr w;
! 31: mpz_srcptr u;
! 32: unsigned long int cnt;
! 33: #endif
! 34: {
! 35: mp_size_t usize = u->_mp_size;
! 36: mp_size_t abs_usize = ABS (usize);
! 37: mp_size_t wsize;
! 38: mp_size_t limb_cnt;
! 39: mp_ptr wp;
! 40: mp_limb_t wlimb;
! 41:
! 42: if (usize == 0)
! 43: {
! 44: w->_mp_size = 0;
! 45: return;
! 46: }
! 47:
! 48: limb_cnt = cnt / BITS_PER_MP_LIMB;
! 49: wsize = abs_usize + limb_cnt + 1;
! 50: if (w->_mp_alloc < wsize)
! 51: _mpz_realloc (w, wsize);
! 52:
! 53: wp = w->_mp_d;
! 54: wsize = abs_usize + limb_cnt;
! 55:
! 56: cnt %= BITS_PER_MP_LIMB;
! 57: if (cnt != 0)
! 58: {
! 59: wlimb = mpn_lshift (wp + limb_cnt, u->_mp_d, abs_usize, cnt);
! 60: if (wlimb != 0)
! 61: {
! 62: wp[wsize] = wlimb;
! 63: wsize++;
! 64: }
! 65: }
! 66: else
! 67: {
! 68: MPN_COPY_DECR (wp + limb_cnt, u->_mp_d, abs_usize);
! 69: }
! 70:
! 71: /* Zero all whole limbs at low end. Do it here and not before calling
! 72: mpn_lshift, not to lose for U == W. */
! 73: MPN_ZERO (wp, limb_cnt);
! 74:
! 75: w->_mp_size = usize >= 0 ? wsize : -wsize;
! 76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>