1
dnl AMD K6 mpn_modexact_1_odd -- exact division style remainder.
3
dnl K6: 10.0 cycles/limb
5
dnl Copyright 2000, 2001 Free Software Foundation, Inc.
7
dnl This file is part of the GNU MP Library.
9
dnl The GNU MP Library is free software; you can redistribute it and/or
10
dnl modify it under the terms of the GNU Lesser General Public License as
11
dnl published by the Free Software Foundation; either version 2.1 of the
12
dnl License, or (at your option) any later version.
14
dnl The GNU MP Library is distributed in the hope that it will be useful,
15
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
16
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
dnl Lesser General Public License for more details.
19
dnl You should have received a copy of the GNU Lesser General Public
20
dnl License along with the GNU MP Library; see the file COPYING.LIB. If
21
dnl not, write to the Free Software Foundation, Inc., 59 Temple Place -
22
dnl Suite 330, Boston, MA 02111-1307, USA.
24
include(`../config.m4')
27
C mp_limb_t mpn_modexact_1_odd (mp_srcptr src, mp_size_t size,
29
C mp_limb_t mpn_modexact_1c_odd (mp_srcptr src, mp_size_t size,
30
C mp_limb_t divisor, mp_limb_t carry);
32
C A special case for high<divisor at the end measured only about 4 cycles
33
C faster, and so isn't used.
35
C A special case for size==1 using a divl rather than the inverse measured
36
C only about 5 cycles faster, and so isn't used. When size==1 and
37
C high<divisor it can skip a division and be a full 24 cycles faster, but
38
C this isn't an important case.
40
defframe(PARAM_CARRY, 16)
41
defframe(PARAM_DIVISOR,12)
42
defframe(PARAM_SIZE, 8)
43
defframe(PARAM_SRC, 4)
48
PROLOGUE(mpn_modexact_1c_odd)
51
movl PARAM_DIVISOR, %ecx
52
pushl %esi FRAME_pushl()
54
movl PARAM_CARRY, %edx
55
jmp LF(mpn_modexact_1_odd,start_1c)
67
PROLOGUE(mpn_modexact_1_odd)
70
movl PARAM_DIVISOR, %ecx
71
pushl %esi FRAME_pushl()
75
pushl %edi FRAME_pushl()
78
movl PARAM_DIVISOR, %esi
80
andl $127, %ecx C d/2, 7 bits
81
pushl %ebp FRAME_pushl()
84
call LF(mpn_modexact_1c_odd,movl_eip_edi)
86
addl $_GLOBAL_OFFSET_TABLE_, %edi
88
movl modlimb_invert_table@GOT(%edi), %edi
90
Zdisp( movzbl, 0,(%ecx,%edi), %edi) C inv 8 bits
94
movzbl modlimb_invert_table(%ecx), %edi C inv 8 bits
96
leal (%edi,%edi), %ecx C 2*inv
98
imull %edi, %edi C inv*inv
101
movl PARAM_SIZE, %ebp
103
imull %esi, %edi C inv*inv*d
105
pushl %ebx FRAME_pushl()
106
leal (%eax,%ebp,4), %ebx C src end
108
subl %edi, %ecx C inv = 2*inv - inv*inv*d
109
leal (%ecx,%ecx), %edi C 2*inv
111
imull %ecx, %ecx C inv*inv
113
movl (%eax), %eax C src low limb
116
imull %esi, %ecx C inv*inv*d
118
subl %ecx, %edi C inv = 2*inv - inv*inv*d
120
ASSERT(e,` C d*inv == 1 mod 2^BITS_PER_MP_LIMB
130
C Rotating the mul to the top of the loop saves 1 cycle, presumably by
131
C hiding the loop control under the imul latency.
133
C The run time is 10 cycles, but decoding is only 9 (and the dependent chain
134
C only 8). It's not clear how to get down to 9 cycles.
136
C The xor and rcl to handle the carry bit could be an sbb instead, with the
137
C the carry bit add becoming a sub, but that doesn't save anything.
142
C ecx carry bit, 0 or 1
143
C edx (high product, being carry limb)
146
C ebp counter, limbs, negative
150
movl (%ebx,%ebp,4), %eax
151
addl %ecx, %edx C apply carry bit to carry limb
152
ASSERT(a, `cmpl %edx, %esi')
156
subl %edx, %eax C apply carry limb
175
leal (%ecx,%edx), %eax