Debian Codegraph @

msvc/gmp/mpn/x86i/p6/mmx/rshift.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_rshift
26
27 %ifdef DLL
28 export ___gmpn_rshift
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_rshift:
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 dec eax
53 mov edi,[ebx] ; src low limb
54 jnz Lsimple
55 shrd eax,edi,cl
56 shr 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 align 8
71 Lsimple:
72 movd mm5,[ebx] ; src[0]
73 lea ebx,[ebx+eax*4] ; &src[size-1]
74 movd mm6,ecx ; rshift
75 lea edx,[-4+edx+eax*4] ; &dst[size-2]
76 psllq mm5,32
77 neg eax
78
79 ; This loop is 5 or 8 cycles,with every second load unaligned and a wasted
80 ; cycle waiting for the mm0 result to be ready. For comparison a shrdl is 4
81 ; cycles and would be 8 in a simple loop. Using mmx helps the return value
82 ; and last limb calculations too.
83
84 ; eax counter,limbs,negative
85 ; ebx &src[size-1]
86 ; ecx return value
87 ; edx &dst[size-2]
88 ;
89 ; mm0 scratch
90 ; mm5 return value
91 ; mm6 shift
92
93 Lsimple_top:
94 movq mm0,[ebx+eax*4]
95 inc eax
96 psrlq mm0,mm6
97 movd [edx+eax*4],mm0
98 jnz Lsimple_top
99 movd mm0,[ebx]
100 psrlq mm5,mm6 ; return value
101 psrlq mm0,mm6
102 pop edi
103 movd eax,mm5
104 pop ebx
105 movd [4+edx],mm0
106 emms
107 ret
108
109 ; eax size
110 ; ebx src
111 ; ecx shift
112 ; edx dst
113 ; esi
114 ; edi
115 ; ebp
116
117 align 8
118 Lunroll:
119 movd mm5,[ebx] ; src[0]
120 mov edi,4
121 movd mm6,ecx ; rshift
122 test ebx,edi
123 psllq mm5,32
124 jz Lstart_src_aligned
125
126 ; src isn't aligned,process low limb separately (marked xxx) and
127 ; step src and dst by one limb,making src aligned.
128 ;
129 ; source ebx
130 ; --+-------+-------+-------+
131 ; | xxx |
132 ; --+-------+-------+-------+
133 ; 4mod8 0mod8 4mod8
134 ;
135 ; dest edx
136 ; --+-------+-------+
137 ; | | xxx |
138 ; --+-------+-------+
139
140 movq mm0,[ebx] ; unaligned load
141 psrlq mm0,mm6
142 add ebx,4
143 dec eax
144 movd [edx],mm0
145 add edx,4
146 Lstart_src_aligned:
147 movq mm1,[ebx]
148 test edx,edi
149 psrlq mm5,mm6 ; retval
150 jz Lstart_dst_aligned
151
152 ; dst isn't aligned,add 4 to make it so,and pretend the shift is
153 ; 32 bits extra. Low limb of dst (marked xxx) handled here
154 ; separately.
155 ;
156 ; source ebx
157 ; --+-------+-------+
158 ; | mm1 |
159 ; --+-------+-------+
160 ; 4mod8 0mod8
161 ;
162 ; dest edx
163 ; --+-------+-------+-------+
164 ; | xxx |
165 ; --+-------+-------+-------+
166 ; 4mod8 0mod8 4mod8
167
168 movq mm0,mm1
169 add ecx,32 ; new shift
170 psrlq mm0,mm6
171 movd mm6,ecx
172 movd [edx],mm0
173 add edx,4
174 Lstart_dst_aligned:
175 movq mm3,[8+ebx]
176 neg ecx
177 movq mm2,mm3 ; mm2 src qword
178 add ecx,64
179 movd mm7,ecx
180 psrlq mm1,mm6
181 lea ebx,[-12+ebx+eax*4]
182 lea edx,[-20+edx+eax*4]
183 psllq mm3,mm7
184 sub eax,7 ; size-7
185 por mm3,mm1 ; mm3 ready to store
186 neg eax ; -(size-7)
187 jns Lfinish
188
189 ; This loop is the important bit,the rest is just support. Careful
190 ; instruction scheduling achieves the claimed 1.75 c/l. The
191 ; relevant parts of the pairing rules are:
192 ;
193 ; - mmx loads and stores execute only in the U pipe
194 ; - only one mmx shift in a pair
195 ; - wait one cycle before storing an mmx register result
196 ; - the usual address generation interlock
197 ;
198 ; Two qword calculations are slightly interleaved. The instructions
199 ; marked "C" belong to the second qword,and the "C prev" one is for
200 ; the second qword from the previous iteration.
201
202 ; eax counter,limbs,negative
203 ; ebx &src[size-12]
204 ; ecx
205 ; edx &dst[size-12]
206 ; esi
207 ; edi
208 ;
209 ; mm0
210 ; mm1
211 ; mm2 src qword from -8(%ebx,%eax,4)
212 ; mm3 dst qword ready to store to -8(%edx,%eax,4)
213 ;
214 ; mm5 return value
215 ; mm6 rshift
216 ; mm7 lshift
217
218 align 8
219 Lunroll_loop:
220 movq mm0,[ebx+eax*4]
221 psrlq mm2,mm6
222 movq mm1,mm0
223 psllq mm0,mm7
224 movq [-8+edx+eax*4],mm3
225 por mm0,mm2
226
227 movq mm3,[ebx+eax*4+8]
228 psrlq mm1,mm6
229 movq [edx+eax*4],mm0
230 movq mm2,mm3
231 psllq mm3,mm7
232 add eax,4
233 por mm3,mm1
234 js Lunroll_loop
235
236 Lfinish:
237 ; eax 0 to 3 representing respectively 3 to 0 limbs remaining
238
239 test al,2
240 jnz Lfinish_no_two
241 movq mm0,[ebx+eax*4]
242 psrlq mm2,mm6
243 movq mm1,mm0
244 psllq mm0,mm7
245 movq [-8+edx+eax*4],mm3 ; prev
246 por mm0,mm2
247 movq mm2,mm1
248 movq mm3,mm0
249 add eax,2
250 Lfinish_no_two:
251
252 ; eax 2 or 3 representing respectively 1 or 0 limbs remaining
253 ;
254 ; mm2 src prev qword,from -8(%ebx,%eax,4)
255 ; mm3 dst qword,for -8(%edx,%eax,4)
256
257 test al,1
258 pop edi
259 movd eax,mm5 ; retval
260 jnz Lfinish_zero
261
262 ; One extra limb,destination was aligned.
263 ;
264 ; source ebx
265 ; +-------+---------------+--
266 ; | | mm2 |
267 ; +-------+---------------+--
268 ;
269 ; dest edx
270 ; +-------+---------------+---------------+--
271 ; | | | mm3 |
272 ; +-------+---------------+---------------+--
273 ;
274 ; mm6 = shift
275 ; mm7 = ecx = 64-shift
276
277 ; One extra limb,destination was unaligned.
278 ;
279 ; source ebx
280 ; +-------+---------------+--
281 ; | | mm2 |
282 ; +-------+---------------+--
283 ;
284 ; dest edx
285 ; +---------------+---------------+--
286 ; | | mm3 |
287 ; +---------------+---------------+--
288 ;
289 ; mm6 = shift+32
290 ; mm7 = ecx = 64-(shift+32)
291
292 ; In both cases there's one extra limb of src to fetch and combine
293 ; with mm2 to make a qword at 8(%edx),and in the aligned case
294 ; there's a further extra limb of dst to be formed.
295
296
297 movd mm0,[8+ebx]
298 psrlq mm2,mm6
299 movq mm1,mm0
300 psllq mm0,mm7
301 movq [edx],mm3
302 por mm0,mm2
303 psrlq mm1,mm6
304 and ecx,32
305 pop ebx
306 jz Lfinish_one_unaligned
307
308 ; dst was aligned,must store one extra limb
309 movd [16+edx],mm1
310 Lfinish_one_unaligned:
311
312 movq [8+edx],mm0
313 emms
314 ret
315 Lfinish_zero:
316
317 ; No extra limbs,destination was aligned.
318 ;
319 ; source ebx
320 ; +---------------+--
321 ; | mm2 |
322 ; +---------------+--
323 ;
324 ; dest edx+4
325 ; +---------------+---------------+--
326 ; | | mm3 |
327 ; +---------------+---------------+--
328 ;
329 ; mm6 = shift
330 ; mm7 = ecx = 64-shift
331
332 ; No extra limbs,destination was unaligned.
333 ;
334 ; source ebx
335 ; +---------------+--
336 ; | mm2 |
337 ; +---------------+--
338 ;
339 ; dest edx+4
340 ; +-------+---------------+--
341 ; | | mm3 |
342 ; +-------+---------------+--
343 ;
344 ; mm6 = shift+32
345 ; mm7 = 64-(shift+32)
346
347 ; The movd for the unaligned case is clearly the same data as the
348 ; movq for the aligned case,it's just a choice between whether one
349 ; or two limbs should be written.
350
351 movq [4+edx],mm3
352 psrlq mm2,mm6
353 movd [12+edx],mm2
354 and ecx,32
355 pop ebx
356 jz Lfinish_zero_unaligned
357 movq [12+edx],mm2
358 Lfinish_zero_unaligned:
359 emms
360 ret
361
362 end