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