Debian Codegraph @

msvc/gmp/mpn/x86i/p6/dive_1.asm

raw
1
2 ; Copyright 2001, 2002 Free Software Foundation, Inc.
3 ;
4 ; This file is part of the GNU MP Library.
5 ;
6 ; The GNU MP Library is free software; you can redistribute it and/or
7 ; modify it under the terms of the GNU Lesser General Public License as
8 ; published by the Free Software Foundation; either version 2.1 of the
9 ; License, or (at your option) any later version.
10 ;
11 ; The GNU MP Library is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ; Lesser General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU Lesser General Public
17 ; License along with the GNU MP Library; see the file COPYING.LIB. If
18 ; not, write to the Free Software Foundation, Inc., 59 Temple Place -
19 ; Suite 330, Boston, MA 02111-1307, USA.
20 ;
21 ; Translation of AT&T syntax code by Brian Gladman
22
23 %include "..\x86i.inc"
24
25 extern ___gmp_modlimb_invert_table
26 global ___gmpn_divexact_1
27
28 %ifdef DLL
29 export ___gmpn_divexact_1
30 %endif
31
32 %define PARAM_DIVISOR esp+frame+16
33 %define PARAM_SIZE esp+frame+12
34 %define PARAM_SRC esp+frame+8
35 %define PARAM_DST esp+frame+4
36
37 %define SAVE_EBX esp+frame-4
38 %define SAVE_ESI esp+frame-8
39 %define SAVE_EDI esp+frame-12
40 %define SAVE_EBP esp+frame-16
41 %define VAR_INVERSE esp+frame-20
42 %define STACK_SPACE 20
43 %define frame 0
44
45 section .text
46
47 align 16
48
49 ___gmpn_divexact_1:
50 mov eax,[PARAM_DIVISOR]
51 sub esp,STACK_SPACE
52 FR_sesp STACK_SPACE
53 mov [SAVE_ESI],esi
54 mov esi,[PARAM_SRC]
55 mov [SAVE_EBX],ebx
56 mov ebx,[PARAM_SIZE]
57 bsf ecx,eax ; trailing twos
58 mov [SAVE_EBP],ebp
59 shr eax,cl ; d without twos
60 mov edx,eax
61 shr eax,1 ; d/2 without twos
62 mov [PARAM_DIVISOR],edx
63 and eax,127
64
65 %ifdef PIC
66 call Lmovl_eip_ebp
67 add ebp,_GLOBAL_OFFSET_TABLE_
68 mov ebp,[___gmp_modlimb_invert_table+edx+ebp]
69 movzx ebp,byte [eax+ebp] ; inv 8 bits
70 %else
71 movzx ebp,byte [___gmp_modlimb_invert_table+eax] ; inv 8 bits
72 %endif
73
74 lea eax,[ebp+ebp] ; 2*inv
75 imul ebp,ebp ; inv*inv
76 mov [SAVE_EDI],edi
77 mov edi,[PARAM_DST]
78 lea esi,[esi+ebx*4] ; src end
79 imul ebp,[PARAM_DIVISOR] ; inv*inv*d
80 sub eax,ebp ; inv = 2*inv - inv*inv*d
81 lea ebp,[eax+eax] ; 2*inv
82 imul eax,eax ; inv*inv
83 lea edi,[edi+ebx*4] ; dst end
84 neg ebx ; -size
85 mov [PARAM_DST],edi
86 imul eax,[PARAM_DIVISOR] ; inv*inv*d
87 sub ebp,eax ; inv = 2*inv - inv*inv*d
88
89 mov [VAR_INVERSE],ebp
90 mov eax,[esi+ebx*4] ; src[0]
91 or ecx,ecx
92 jnz Leven
93 jmp Lodd_entry ; ecx initial carry is zero
94
95 ; The dependent chain here is
96 ;
97 ; subl %edx,%eax 1
98 ; imull %ebp,%eax 4
99 ; mull PARAM_DIVISOR 5
100 ; ----
101 ; total 10
102 ;
103 ; and this is the measured speed. No special scheduling is necessary,out
104 ; of order execution hides the load latency.
105 ;
106 ; eax scratch (src limb)
107 ; ebx counter,limbs,negative
108 ; ecx carry bit
109 ; edx carry limb,high of last product
110 ; esi &src[size]
111 ; edi &dst[size]
112
113 Lodd_top:
114 mul dword [PARAM_DIVISOR]
115 mov eax,[esi+ebx*4]
116 sub eax,ecx
117 sbb ecx,ecx
118 sub eax,edx
119 sbb ecx,0
120 Lodd_entry:
121 imul eax,[VAR_INVERSE]
122 mov [edi+ebx*4],eax
123 neg ecx
124 inc ebx
125 jnz Lodd_top
126 mov esi,[SAVE_ESI]
127 mov edi,[SAVE_EDI]
128 mov ebp,[SAVE_EBP]
129 mov ebx,[SAVE_EBX]
130 add esp,STACK_SPACE
131 ret
132
133 ; eax src[0]
134 ; ebx counter,limbs,negative
135 ; ecx shift
136
137 Leven:
138 xor ebp,ebp ; initial carry bit
139 xor edx,edx ; initial carry limb (for size==1)
140 inc ebx
141 jz Leven_one
142 mov edi,[esi+ebx*4] ; src[1]
143 shrd eax,edi,cl
144 jmp Leven_entry
145
146 ; eax scratch
147 ; ebx counter,limbs,negative
148 ; ecx shift
149 ; edx scratch
150 ; esi &src[size]
151 ; edi &dst[size] and scratch
152 ; ebp carry bit
153
154 Leven_top:
155 mov edi,[esi+ebx*4]
156 mul dword [PARAM_DIVISOR]
157 mov eax,[-4+esi+ebx*4]
158 shrd eax,edi,cl
159 sub eax,ebp
160 sbb ebp,ebp
161 sub eax,edx
162 sbb ebp,0
163
164 Leven_entry:
165 imul eax,[VAR_INVERSE]
166 mov edi,[PARAM_DST]
167 neg ebp
168 mov [-4+edi+ebx*4],eax
169 inc ebx
170 jnz Leven_top
171 mul dword [PARAM_DIVISOR]
172 mov eax,[-4+esi]
173 Leven_one:
174 shr eax,cl
175 mov esi,[SAVE_ESI]
176 sub eax,ebp
177 mov ebp,[SAVE_EBP]
178 sub eax,edx
179 mov ebx,[SAVE_EBX]
180 imul eax,[VAR_INVERSE]
181 mov [-4+edi],eax
182 mov edi,[SAVE_EDI]
183 add esp,STACK_SPACE
184 ret
185
186 %ifdef PIC
187 Lmovl_eip_ebp:
188 mov ebp,[esp]
189 ret
190 %endif
191
192 end