1
/* mpn_mod_1_rshift -- mpn remainder under hypothetical right shift.
3
THE FUNCTION IN THIS FILE IS FOR INTERNAL USE AND HAS A MUTABLE
4
INTERFACE. IT IS ONLY SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.
5
IT'S ALMOST GUARANTEED THAT IT'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP
9
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
11
This file is part of the GNU MP Library.
13
The GNU MP Library is free software; you can redistribute it and/or modify
14
it under the terms of the GNU Lesser General Public License as published by
15
the Free Software Foundation; either version 2.1 of the License, or (at your
16
option) any later version.
18
The GNU MP Library is distributed in the hope that it will be useful, but
19
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
21
License for more details.
23
You should have received a copy of the GNU Lesser General Public License
24
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
25
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26
MA 02111-1307, USA. */
33
/* When testing on a CPU with UDIV_NEEDS_NORMALIZATION equal to 0, it can be
34
changed to 1 temporarily to test the code under that case too. */
36
#undef UDIV_NEEDS_NORMALIZATION
37
#define UDIV_NEEDS_NORMALIZATION 1
41
/* Calculate the remainder "(ptr,size >> shift) % divisor". Note ptr,size
42
is unchanged, the shift is only for its effect on the remainder.
43
The shift doesn't even need to be considered until the last limb.
45
This function has the normal size!=0 restriction, unlike the basic
50
mpn_mod_1_rshift (mp_srcptr ptr, mp_size_t size, unsigned shift,
53
mpn_mod_1_rshift (ptr, size, shift, divisor)
63
ASSERT (shift < BITS_PER_MP_LIMB);
67
return (ptr[0] >> shift) % divisor;
69
#if UDIV_NEEDS_NORMALIZATION
74
count_leading_zeros (norm, divisor);
79
return mpn_mod_1 (ptr, size, divisor) >> norm;
83
rem = mpn_mod_1 (ptr+1, size-1, divisor);
84
udiv_qrnnd (quot, rem,
86
(rem << (BITS_PER_MP_LIMB-delta)) | (ptr[0] >> delta),
92
rem = mpn_mod_1 (ptr, size, divisor);
93
udiv_qrnnd (quot, rem,
94
rem >> (BITS_PER_MP_LIMB+delta),
101
#else /* !UDIV_NEEDS_NORMALIZATION */
103
rem = mpn_mod_1 (ptr+1, size-1, divisor);
104
udiv_qrnnd (quot, rem,
106
(rem << (BITS_PER_MP_LIMB-shift)) | (ptr[0] >> shift),