1 dnl AMD K7 mpn_mod_34lsub1 -- remainder modulo 2^24-1.
3 dnl Copyright 2000, 2001, 2002, 2004, 2005, 2008 Free Software Foundation,
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 3 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 License
19 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
21 include(`../config.m4')
29 C mp_limb_t mpn_mod_34lsub1 (mp_srcptr src, mp_size_t size)
31 C The loop form below and the 64 byte code alignment seem necessary for the
32 C claimed speed. This is a bit strange, since normally k7 isn't very
33 C sensitive to such things. Perhaps there has to be 6 instructions in the
34 C first 16 bytes for the BTB entry or something.
36 defframe(PARAM_SIZE, 8)
37 defframe(PARAM_SRC, 4)
39 dnl re-use parameter space
40 define(SAVE_EDI, `PARAM_SIZE')
44 PROLOGUE(mpn_mod_34lsub1)
58 shrl $24, %eax C src[0] low
60 andl $0xFFFFFF, %edx C src[0] high
65 shrl $16, %edx C src[1] high
68 shll $8, %ecx C src[1] low
83 pushl %ebx FRAME_pushl()
88 pushl %esi FRAME_pushl()
89 xorl %esi, %esi C and clear carry flag
92 C code offset 0x40 at this point
123 C ecx is -2, -1 or 0 representing 0, 1 or 2 more limbs, respectively
126 movl $0xFFFFFFFF, %edi
131 movl $0xFFFFFF00, %edi
135 movl $0xFFFF0000, %edi
146 sbbl %ecx, %ecx C carry
147 movl %eax, %edx C 0mod3
148 shrl $24, %eax C 0mod3 high
150 andl %edi, %ecx C carry masked
151 andl $0x00FFFFFF, %edx C 0mod3 low
152 movl %ebx, %edi C 1mod3
154 subl %ecx, %eax C apply carry
155 shrl $16, %ebx C 1mod3 high
158 addl %edx, %eax C apply 0mod3 low
159 movl %esi, %edx C 2mod3
160 shll $8, %edi C 1mod3 low
162 addl %ebx, %eax C apply 1mod3 high
163 shrl $8, %esi C 2mod3 high
164 movzbl %dl, %edx C 2mod3 low
166 addl %edi, %eax C apply 1mod3 low
167 shll $16, %edx C 2mod3 low
169 addl %esi, %eax C apply 2mod3 high
170 popl %esi FRAME_popl()
173 addl %edx, %eax C apply 2mod3 low
174 popl %ebx FRAME_popl()