Debian Codegraph @

msvc/gmp/mpn/x86i/p6/mmx/lshift.asm

raw
1
2 ; Copyright 2001 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 global ___gmpn_lshift
26
27 %ifdef DLL
28 export ___gmpn_lshift
29 %endif
30
31 %define PARAM_SHIFT esp+frame+16
32 %define PARAM_SIZE esp+frame+12
33 %define PARAM_SRC esp+frame+8
34 %define PARAM_DST esp+frame+4
35 %define frame 8
36
37 ; minimum 5,because the unrolled loop can't handle less
38 %define UNROLL_THRESHOLD 5
39
40 section .text
41 align 8
42
43 ___gmpn_lshift:
44 push ebx
45 push edi
46 mov eax,[PARAM_SIZE]
47 mov edx,[PARAM_DST]
48 mov ebx,[PARAM_SRC]
49 mov ecx,[PARAM_SHIFT]
50 cmp eax,UNROLL_THRESHOLD
51 jae Lunroll
52 mov edi,[-4+ebx+eax*4] ; src high limb
53 dec eax
54 jnz Lsimple
55 shld eax,edi,cl
56 shl edi,cl
57 mov [edx],edi ; dst low limb
58 pop edi ; risk of data cache bank clash
59 pop ebx
60 ret
61
62 ; eax size-1
63 ; ebx src
64 ; ecx shift
65 ; edx dst
66 ; esi
67 ; edi
68 ; ebp
69
70 Lsimple:
71 movd mm5,[ebx+eax*4] ; src high limb
72 movd mm6,ecx ; lshift
73 neg ecx
74 psllq mm5,mm6
75 add ecx,32
76 movd mm7,ecx
77 psrlq mm5,32 ; retval
78
79 ; eax counter,limbs,negative
80 ; ebx src
81 ; ecx
82 ; edx dst
83 ; esi
84 ; edi
85 ;
86 ; mm0 scratch
87 ; mm5 return value
88 ; mm6 shift
89 ; mm7 32-shift
90
91 Lsimple_top:
92 movq mm0,[ebx+eax*4-4]
93 dec eax
94 psrlq mm0,mm7
95 movd [4+edx+eax*4],mm0
96 jnz Lsimple_top
97 movd mm0,[ebx]
98 movd eax,mm5
99 psllq mm0,mm6
100 pop edi
101 pop ebx
102 movd [edx],mm0
103 emms
104 ret
105
106 ; eax size
107 ; ebx src
108 ; ecx shift
109 ; edx dst
110 ; esi
111 ; edi
112 ; ebp
113
114 align 8
115 Lunroll:
116 movd mm5,[ebx+eax*4-4] ; src high limb
117 lea edi,[ebx+eax*4]
118 movd mm6,ecx ; lshift
119 and edi,4
120 psllq mm5,mm6
121 jz Lstart_src_aligned
122
123 ; src isn't aligned,process high limb separately (marked xxx) to
124 ; make it so.
125 ;
126 ; source -8(ebx,%eax,4)
127 ; |
128 ; +-------+-------+-------+--
129 ; | |
130 ; +-------+-------+-------+--
131 ; 0mod8 4mod8 0mod8
132 ;
133 ; dest
134 ; -4(edx,%eax,4)
135 ; |
136 ; +-------+-------+--
137 ; | xxx | |
138 ; +-------+-------+--
139
140 movq mm0,[ebx+eax*4-8] ; unaligned load
141 psllq mm0,mm6
142 dec eax
143 psrlq mm0,32
144 movd [edx+eax*4],mm0
145 Lstart_src_aligned:
146 movq mm1,[ebx+eax*4-8] ; src high qword
147 lea edi,[edx+eax*4]
148 and edi,4
149 psrlq mm5,32 ; return value
150 movq mm3,[ebx+eax*4-16] ; src second highest qword
151 jz Lstart_dst_aligned
152
153 ; dst isn't aligned,subtract 4 to make it so,and pretend the shift
154 ; is 32 bits extra. High limb of dst (marked xxx) handled here
155 ; separately.
156 ;
157 ; source -8(ebx,%eax,4)
158 ; |
159 ; +-------+-------+--
160 ; | mm1 |
161 ; +-------+-------+--
162 ; 0mod8 4mod8
163 ;
164 ; dest
165 ; -4(edx,%eax,4)
166 ; |
167 ; +-------+-------+-------+--
168 ; | xxx | |
169 ; +-------+-------+-------+--
170 ; 0mod8 4mod8 0mod8
171
172 movq mm0,mm1
173 add ecx,32 ; new shift
174 psllq mm0,mm6
175 movd mm6,ecx
176 psrlq mm0,32
177
178 ; wasted cycle here waiting for %mm0
179
180 movd [-4+edx+eax*4],mm0
181 sub edx,4
182 Lstart_dst_aligned:
183
184 psllq mm1,mm6
185 neg ecx ; -shift
186 add ecx,64 ; 64-shift
187 movq mm2,mm3
188 movd mm7,ecx
189 sub eax,8 ; size-8
190 psrlq mm3,mm7
191 por mm3,mm1 ; mm3 ready to store
192 jc Lfinish
193
194 ; The comments in mpn_rshift apply here too.
195
196 ; eax counter,limbs
197 ; ebx src
198 ; ecx
199 ; edx dst
200 ; esi
201 ; edi
202 ;
203 ; mm0
204 ; mm1
205 ; mm2 src qword from 16(%ebx,%eax,4)
206 ; mm3 dst qword ready to store to 24(%edx,%eax,4)
207 ;
208 ; mm5 return value
209 ; mm6 lshift
210 ; mm7 rshift
211
212 align 8
213 Lunroll_loop:
214 movq mm0,[ebx+eax*4+8]
215 psllq mm2,mm6
216 movq mm1,mm0
217 psrlq mm0,mm7
218 movq [24+edx+eax*4],mm3
219 por mm0,mm2
220 movq mm3,[ebx+eax*4]
221 psllq mm1,mm6
222 movq [16+edx+eax*4],mm0
223 movq mm2,mm3
224 psrlq mm3,mm7
225 sub eax,4
226 por mm3,mm1
227 jnc Lunroll_loop
228 Lfinish:
229 ; eax -4 to -1 representing respectively 0 to 3 limbs remaining
230
231 test al,2
232 jz Lfinish_no_two
233 movq mm0,[ebx+eax*4+8]
234 psllq mm2,mm6
235 movq mm1,mm0
236 psrlq mm0,mm7
237 movq [24+edx+eax*4],mm3 ; prev
238 por mm0,mm2
239 movq mm2,mm1
240 movq mm3,mm0
241 sub eax,2
242 Lfinish_no_two:
243
244 ; eax -4 or -3 representing respectively 0 or 1 limbs remaining
245 ; mm2 src prev qword,from 16(%ebx,%eax,4)
246 ; mm3 dst qword,for 24(%edx,%eax,4)
247
248 test al,1
249 movd eax,mm5 ; retval
250 pop edi
251 jz Lfinish_zero
252
253 ; One extra src limb,destination was aligned.
254 ;
255 ; source ebx
256 ; --+---------------+-------+
257 ; | mm2 | |
258 ; --+---------------+-------+
259 ;
260 ; dest edx+12 edx+4 edx
261 ; --+---------------+---------------+-------+
262 ; | mm3 | | |
263 ; --+---------------+---------------+-------+
264 ;
265 ; mm6 = shift
266 ; mm7 = ecx = 64-shift
267
268 ; One extra src limb,destination was unaligned.
269 ;
270 ; source ebx
271 ; --+---------------+-------+
272 ; | mm2 | |
273 ; --+---------------+-------+
274 ;
275 ; dest edx+12 edx+4
276 ; --+---------------+---------------+
277 ; | mm3 | |
278 ; --+---------------+---------------+
279 ;
280 ; mm6 = shift+32
281 ; mm7 = ecx = 64-(shift+32)
282
283
284 ; In both cases there's one extra limb of src to fetch and combine
285 ; with mm2 to make a qword at 4(%edx),and in the aligned case
286 ; there's an extra limb of dst to be formed from that extra src limb
287 ; left shifted.
288
289 movd mm0,[ebx]
290 psllq mm2,mm6
291 movq [12+edx],mm3
292 psllq mm0,32
293 movq mm1,mm0
294 psrlq mm0,mm7
295 por mm0,mm2
296 psllq mm1,mm6
297 movq [4+edx],mm0
298 psrlq mm1,32
299 and ecx,32
300 pop ebx
301 jz Lfinish_one_unaligned
302 movd [edx],mm1
303 Lfinish_one_unaligned:
304 emms
305 ret
306 Lfinish_zero:
307
308 ; No extra src limbs,destination was aligned.
309 ;
310 ; source ebx
311 ; --+---------------+
312 ; | mm2 |
313 ; --+---------------+
314 ;
315 ; dest edx+8 edx
316 ; --+---------------+---------------+
317 ; | mm3 | |
318 ; --+---------------+---------------+
319 ;
320 ; mm6 = shift
321 ; mm7 = ecx = 64-shift
322
323 ; No extra src limbs,destination was unaligned.
324 ;
325 ; source ebx
326 ; --+---------------+
327 ; | mm2 |
328 ; --+---------------+
329 ;
330 ; dest edx+8 edx+4
331 ; --+---------------+-------+
332 ; | mm3 | |
333 ; --+---------------+-------+
334 ;
335 ; mm6 = shift+32
336 ; mm7 = ecx = 64-(shift+32)
337
338 ; The movd for the unaligned case writes the same data to 4(%edx)
339 ; that the movq does for the aligned case.
340
341 movq [8+edx],mm3
342 and ecx,32
343 psllq mm2,mm6
344 jz Lfinish_zero_unaligned
345 movq [edx],mm2
346 Lfinish_zero_unaligned:
347 psrlq mm2,32
348 pop ebx
349 movd eax,mm5 ; retval
350 movd [4+edx],mm2
351 emms
352 ret
353
354 end