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