[BACK]Return to lshift.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / generic

Annotation of OpenXM_contrib/gmp/mpn/generic/lshift.c, Revision 1.1

1.1     ! maekawa     1: /* mpn_lshift -- Shift left low level.
        !             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: /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
        !            26:    and store the USIZE least significant digits of the result at WP.
        !            27:    Return the bits shifted out from the most significant digit.
        !            28:
        !            29:    Argument constraints:
        !            30:    1. 0 < CNT < BITS_PER_MP_LIMB
        !            31:    2. If the result is to be written over the input, WP must be >= UP.
        !            32: */
        !            33:
        !            34: mp_limb_t
        !            35: #if __STDC__
        !            36: mpn_lshift (register mp_ptr wp,
        !            37:            register mp_srcptr up, mp_size_t usize,
        !            38:            register unsigned int cnt)
        !            39: #else
        !            40: mpn_lshift (wp, up, usize, cnt)
        !            41:      register mp_ptr wp;
        !            42:      register mp_srcptr up;
        !            43:      mp_size_t usize;
        !            44:      register unsigned int cnt;
        !            45: #endif
        !            46: {
        !            47:   register mp_limb_t high_limb, low_limb;
        !            48:   register unsigned sh_1, sh_2;
        !            49:   register mp_size_t i;
        !            50:   mp_limb_t retval;
        !            51:
        !            52: #ifdef DEBUG
        !            53:   if (usize == 0 || cnt == 0)
        !            54:     abort ();
        !            55: #endif
        !            56:
        !            57:   sh_1 = cnt;
        !            58: #if 0
        !            59:   if (sh_1 == 0)
        !            60:     {
        !            61:       if (wp != up)
        !            62:        {
        !            63:          /* Copy from high end to low end, to allow specified input/output
        !            64:             overlapping.  */
        !            65:          for (i = usize - 1; i >= 0; i--)
        !            66:            wp[i] = up[i];
        !            67:        }
        !            68:       return 0;
        !            69:     }
        !            70: #endif
        !            71:
        !            72:   wp += 1;
        !            73:   sh_2 = BITS_PER_MP_LIMB - sh_1;
        !            74:   i = usize - 1;
        !            75:   low_limb = up[i];
        !            76:   retval = low_limb >> sh_2;
        !            77:   high_limb = low_limb;
        !            78:   while (--i >= 0)
        !            79:     {
        !            80:       low_limb = up[i];
        !            81:       wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
        !            82:       high_limb = low_limb;
        !            83:     }
        !            84:   wp[i] = high_limb << sh_1;
        !            85:
        !            86:   return retval;
        !            87: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>