1 dnl AMD K7 mpn_divexact_by3 -- mpn division by 3, expecting no remainder.
3 dnl K7: 8.0 cycles/limb
6 dnl Copyright (C) 2000 Free Software Foundation, Inc.
8 dnl This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU Lesser General Public License as
12 dnl published by the Free Software Foundation; either version 2.1 of the
13 dnl License, or (at your option) any later version.
15 dnl The GNU MP Library is distributed in the hope that it will be useful,
16 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 dnl Lesser General Public License for more details.
20 dnl You should have received a copy of the GNU Lesser General Public
21 dnl License along with the GNU MP Library; see the file COPYING.LIB. If
22 dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
23 dnl Suite 330, Boston, MA 02111-1307, USA.
26 include(`../config.m4')
29 C mp_limb_t mpn_divexact_by3c (mp_ptr dst, mp_srcptr src, mp_size_t size,
32 defframe(PARAM_CARRY,16)
33 defframe(PARAM_SIZE, 12)
34 defframe(PARAM_SRC, 8)
35 defframe(PARAM_DST, 4)
37 dnl multiplicative inverse of 3, modulo 2^32
38 deflit(INVERSE_3, 0xAAAAAAAB)
40 dnl ceil(b/3) and floor(b*2/3) where b=2^32
41 deflit(ONE_THIRD_CEIL, 0x55555556)
42 deflit(TWO_THIRDS_FLOOR, 0xAAAAAAAA)
47 PROLOGUE(mpn_divexact_by3c)
51 pushl %ebx defframe_pushl(SAVE_EBX)
53 movl PARAM_CARRY, %ebx
54 pushl %ebp defframe_pushl(SAVE_EBP)
57 pushl %edi defframe_pushl(SAVE_EDI)
59 movl (%ecx), %eax C src low limb
60 pushl %esi defframe_pushl(SAVE_ESI)
63 movl $TWO_THIRDS_FLOOR, %esi
64 leal -4(%ecx,%ebp,4), %ecx C &src[size-1]
72 leal (%edi,%ebp,4), %edi C &dst[size-1]
78 C eax src limb, carry subtracted
79 C ebx carry limb (0 or 1)
82 C esi TWO_THIRDS_FLOOR
84 C ebp counter, limbs, negative
86 imull $INVERSE_3, %eax, %edx
88 movl 4(%ecx,%ebp,4), %eax C next src limb
89 cmpl $ONE_THIRD_CEIL, %edx
91 sbbl $-1, %ebx C +1 if result>=ceil(b/3)
94 sbbl %ebx, %eax C and further 1 if result>=ceil(b*2/3)
95 movl %edx, (%edi,%ebp,4)
104 C eax src limb, carry subtracted
105 C ebx carry limb (0 or 1)
112 imull $INVERSE_3, %eax
114 cmpl $ONE_THIRD_CEIL, %eax
118 sbbl $-1, %ebx C +1 if eax>=ceil(b/3)
122 adcl %ebx, %eax C further +1 if eax>=ceil(b*2/3)