1 1.1 mrg /* mpn_lshift -- Shift left low level. 2 1.1 mrg 3 1.1 mrg Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1 mrg This file is part of the GNU MP Library. 6 1.1 mrg 7 1.1 mrg The GNU MP Library is free software; you can redistribute it and/or modify 8 1.1 mrg it under the terms of the GNU Lesser General Public License as published by 9 1.1 mrg the Free Software Foundation; either version 2.1 of the License, or (at your 10 1.1 mrg option) any later version. 11 1.1 mrg 12 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but 13 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 1.1 mrg License for more details. 16 1.1 mrg 17 1.1 mrg You should have received a copy of the GNU Lesser General Public License 18 1.1 mrg along with the GNU MP Library; see the file COPYING.LIB. If not, write to 19 1.1 mrg the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 20 1.1 mrg MA 02111-1307, USA. */ 21 1.1 mrg 22 1.1 mrg #include <config.h> 23 1.1 mrg #include "gmp-impl.h" 24 1.1 mrg 25 1.1 mrg /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left 26 1.1 mrg and store the USIZE least significant digits of the result at WP. 27 1.1 mrg Return the bits shifted out from the most significant digit. 28 1.1 mrg 29 1.1 mrg Argument constraints: 30 1.1 mrg 1. 0 < CNT < BITS_PER_MP_LIMB 31 1.1 mrg 2. If the result is to be written over the input, WP must be >= UP. 32 1.1 mrg */ 33 1.1 mrg 34 1.1 mrg mp_limb_t 35 1.1 mrg #if __STDC__ 36 1.1 mrg mpn_lshift (register mp_ptr wp, 37 1.1 mrg register mp_srcptr up, mp_size_t usize, 38 1.1 mrg register unsigned int cnt) 39 1.1 mrg #else 40 1.1 mrg mpn_lshift (wp, up, usize, cnt) 41 1.1 mrg register mp_ptr wp; 42 1.1 mrg register mp_srcptr up; 43 1.1 mrg mp_size_t usize; 44 1.1 mrg register unsigned int cnt; 45 1.1 mrg #endif 46 1.1 mrg { 47 1.1 mrg register mp_limb_t high_limb, low_limb; 48 1.1 mrg register unsigned sh_1, sh_2; 49 1.1 mrg register mp_size_t i; 50 1.1 mrg mp_limb_t retval; 51 1.1 mrg 52 1.1 mrg #ifdef DEBUG 53 1.1 mrg if (usize == 0 || cnt == 0) 54 1.1 mrg abort (); 55 1.1 mrg #endif 56 1.1 mrg 57 1.1 mrg sh_1 = cnt; 58 1.1 mrg #if 0 59 1.1 mrg if (sh_1 == 0) 60 1.1 mrg { 61 1.1 mrg if (wp != up) 62 1.1 mrg { 63 1.1 mrg /* Copy from high end to low end, to allow specified input/output 64 1.1 mrg overlapping. */ 65 1.1 mrg for (i = usize - 1; i >= 0; i--) 66 1.1 mrg wp[i] = up[i]; 67 1.1 mrg } 68 1.1 mrg return 0; 69 1.1 mrg } 70 1.1 mrg #endif 71 1.1 mrg 72 1.1 mrg wp += 1; 73 1.1 mrg sh_2 = BITS_PER_MP_LIMB - sh_1; 74 1.1 mrg i = usize - 1; 75 1.1 mrg low_limb = up[i]; 76 1.1 mrg retval = low_limb >> sh_2; 77 1.1 mrg high_limb = low_limb; 78 1.1 mrg while (--i >= 0) 79 1.1 mrg { 80 1.1 mrg low_limb = up[i]; 81 1.1 mrg wp[i] = (high_limb << sh_1) | (low_limb >> sh_2); 82 1.1 mrg high_limb = low_limb; 83 1.1 mrg } 84 1.1 mrg wp[i] = high_limb << sh_1; 85 1.1 mrg 86 1.1 mrg return retval; 87 1.1 mrg } 88