1 /* mpn_rshift -- Shift right a low-level natural-number integer.
3 Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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.
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.
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. */
25 /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
26 and store the USIZE least significant limbs of the result at WP.
27 The bits shifted out to the right are returned.
30 1. 0 < CNT < BITS_PER_MP_LIMB
31 2. If the result is to be written over the input, WP must be <= UP.
36 mpn_rshift (register mp_ptr wp
,
37 register mp_srcptr up
, mp_size_t usize
,
38 register unsigned int cnt
)
40 mpn_rshift (wp
, up
, usize
, cnt
)
42 register mp_srcptr up
;
44 register unsigned int cnt
;
47 register mp_limb_t high_limb
, low_limb
;
48 register unsigned sh_1
, sh_2
;
53 if (usize
== 0 || cnt
== 0)
64 /* Copy from low end to high end, to allow specified input/output
66 for (i
= 0; i
< usize
; i
++)
74 sh_2
= BITS_PER_MP_LIMB
- sh_1
;
76 retval
= high_limb
<< sh_2
;
79 for (i
= 1; i
< usize
; i
++)
82 wp
[i
] = (low_limb
>> sh_1
) | (high_limb
<< sh_2
);
85 wp
[i
] = low_limb
>> sh_1
;