1 dnl AMD K6 mpn_mod_34lsub1 -- mpn remainder modulo 2**24-1.
3 dnl Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
20 include(`../config.m4')
23 C K6: 2.66 cycles/limb
26 C mp_limb_t mpn_mod_34lsub1 (mp_srcptr src, mp_size_t size)
28 C An attempt was made to use a loop like
37 C with %ecx starting from floor(size/3), but it still measured 2.66 c/l.
38 C The form used instead can save about 6 cycles by not dividing by 3.
40 C In the code used, putting the "leal"s at the top of the loop is necessary
41 C for the claimed speed, anywhere else costs an extra cycle per loop.
42 C Perhaps a tight loop like this needs short decode instructions at the
43 C branch target, which would explain the leal/loop form above taking 8
44 C cycles instead of 7 too.
46 defframe(PARAM_SIZE, 8)
47 defframe(PARAM_SRC, 4)
49 dnl re-use parameter space
50 define(SAVE_EBX, `PARAM_SIZE')
51 define(SAVE_ESI, `PARAM_SRC')
55 PROLOGUE(mpn_mod_34lsub1)
64 Zdisp( movl, 0,(%edx), %eax) C avoid code cache line boundary
70 shrl $24, %eax C src[0] high
71 andl $0x00FFFFFF, %ecx C src[0] low
77 andl $0x00FFFF00, %edx C src[1] high
79 shrl $16, %ecx C src[1] low
98 pushl %edi FRAME_pushl()
101 xorl %edi, %edi C and clear carry flag
107 C edx src, incrementing
123 C ecx is -3, -2 or -1 representing 0, 1 or 2 more limbs, respectively
128 js L(combine) C 0 more
130 Zdisp( adcl, 0,(%edx), %ebx) C avoid code cache line crossings
135 js L(combine) C 1 more
145 shll %cl, %edx C carry
146 movl %ebx, %eax C 0mod3
148 shrl $24, %eax C 0mod3 high
149 andl $0x00FFFFFF, %ebx C 0mod3 low
151 subl %edx, %eax C apply carry
152 movl %esi, %ecx C 1mod3
154 shrl $16, %esi C 1mod3 high
155 addl %ebx, %eax C apply 0mod3 low
157 andl $0x0000FFFF, %ecx
158 addl %esi, %eax C apply 1mod3 high
160 shll $8, %ecx C 1mod3 low
161 movl %edi, %edx C 2mod3
163 shrl $8, %edx C 2mod3 high
164 addl %ecx, %eax C apply 1mod3 low
166 addl %edx, %eax C apply 2mod3 high
167 andl $0x000000FF, %edi
169 shll $16, %edi C 2mod3 low
172 addl %edi, %eax C apply 2mod3 low