1 dnl x86 mpn_mod_1 -- mpn by limb remainder.
4 dnl Copyright (C) 1999, 2000 Free Software Foundation, Inc.
6 dnl This file is part of the GNU MP Library.
8 dnl The GNU MP Library is free software; you can redistribute it and/or
9 dnl modify it under the terms of the GNU Lesser General Public License as
10 dnl published by the Free Software Foundation; either version 2.1 of the
11 dnl License, or (at your option) any later version.
13 dnl The GNU MP Library is distributed in the hope that it will be useful,
14 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
15 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 dnl Lesser General Public License for more details.
18 dnl You should have received a copy of the GNU Lesser General Public
19 dnl License along with the GNU MP Library; see the file COPYING.LIB. If
20 dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
21 dnl Suite 330, Boston, MA 02111-1307, USA.
28 dnl 486 approx 42 maybe
30 dnl The following have their own optimized mod_1 implementations, but for
31 dnl reference the code here runs as follows.
37 include(`../config.m4')
40 C mp_limb_t mpn_mod_1 (mp_srcptr src, mp_size_t size, mp_limb_t divisor);
41 C mp_limb_t mpn_mod_1c (mp_srcptr src, mp_size_t size, mp_limb_t divisor,
44 C Divide src,size by divisor and return the remainder. The quotient is
47 C See mpn/x86/divrem_1.asm for some comments.
49 defframe(PARAM_CARRY, 16)
50 defframe(PARAM_DIVISOR,12)
51 defframe(PARAM_SIZE, 8)
52 defframe(PARAM_SRC, 4)
61 pushl %ebx FRAME_pushl()
64 pushl %esi FRAME_pushl()
66 movl PARAM_DIVISOR, %esi
69 movl PARAM_CARRY, %edx
86 pushl %ebx FRAME_pushl()
89 pushl %esi FRAME_pushl()
94 movl PARAM_DIVISOR, %esi
95 movl -4(%ebx,%ecx,4), %eax C src high limb
99 sbbl %edx, %edx C -1 if high<divisor
101 addl %edx, %ecx C skip one division if high<divisor
104 andl %eax, %edx C carry if high<divisor
108 C eax scratch (quotient)
111 C edx carry (remainder)
116 movl -4(%ebx,%ecx,4), %eax
120 loop_or_decljnz L(top)