| 1 |
|
| 2 |
; Copyright 1999, 2000, 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 |
%define UNROLL_LOG2 4 |
| 26 |
%define UNROLL_COUNT (1 << UNROLL_LOG2) |
| 27 |
%define UNROLL_MASK UNROLL_COUNT-1 |
| 28 |
%define UNROLL_BYTES 4*UNROLL_COUNT |
| 29 |
|
| 30 |
%ifdef PIC |
| 31 |
%define UNROLL_THRESHOLD 5 |
| 32 |
%else |
| 33 |
%define UNROLL_THRESHOLD 5 |
| 34 |
%endif |
| 35 |
|
| 36 |
%define PARAM_CARRY esp+frame+20 |
| 37 |
%define PARAM_MULTIPLIER esp+frame+16 |
| 38 |
%define PARAM_SIZE esp+frame+12 |
| 39 |
%define PARAM_SRC esp+frame+8 |
| 40 |
%define PARAM_DST esp+frame+4 |
| 41 |
|
| 42 |
%macro mul_fun 4 |
| 43 |
|
| 44 |
global %1%3 |
| 45 |
global %1%4 |
| 46 |
|
| 47 |
%ifdef DLL |
| 48 |
export %1%3 |
| 49 |
export %1%4 |
| 50 |
%endif |
| 51 |
|
| 52 |
align 32 |
| 53 |
%define frame 0 |
| 54 |
%1%4: |
| 55 |
FR_push ebx |
| 56 |
mov ebx,[PARAM_CARRY] |
| 57 |
jmp %%Lstart_nc |
| 58 |
|
| 59 |
%define frame 0 |
| 60 |
%1%3: |
| 61 |
FR_push ebx |
| 62 |
xor ebx,ebx ; initial carry |
| 63 |
%%Lstart_nc: |
| 64 |
mov ecx,[PARAM_SIZE] |
| 65 |
FR_push esi |
| 66 |
mov esi,[PARAM_SRC] |
| 67 |
FR_push edi |
| 68 |
mov edi,[PARAM_DST] |
| 69 |
FR_push ebp |
| 70 |
cmp ecx,UNROLL_THRESHOLD |
| 71 |
mov ebp,[PARAM_MULTIPLIER] |
| 72 |
jae %%Lunroll |
| 73 |
|
| 74 |
; simple loop |
| 75 |
; this is offset 0x22,so close enough to aligned |
| 76 |
; eax scratch |
| 77 |
; ebx carry |
| 78 |
; ecx counter |
| 79 |
; edx scratch |
| 80 |
; esi src |
| 81 |
; edi dst |
| 82 |
; ebp multiplier |
| 83 |
|
| 84 |
%%Lsimple: |
| 85 |
mov eax,[esi] |
| 86 |
add edi,4 |
| 87 |
mul ebp |
| 88 |
add eax,ebx |
| 89 |
adc edx,0 |
| 90 |
%2 [edi-4],eax |
| 91 |
mov ebx,edx |
| 92 |
adc ebx,0 |
| 93 |
dec ecx |
| 94 |
lea esi,[4+esi] |
| 95 |
jnz %%Lsimple |
| 96 |
pop ebp |
| 97 |
pop edi |
| 98 |
pop esi |
| 99 |
mov eax,ebx |
| 100 |
pop ebx |
| 101 |
ret |
| 102 |
|
| 103 |
; VAR_JUMP holds the computed jump temporarily because there's not enough |
| 104 |
; registers when doing the mul for the initial two carry limbs. |
| 105 |
; |
| 106 |
; The add/adc for the initial carry in %ebx is necessary only for the |
| 107 |
; mpn_add/submul_1c entry points. Duplicating the startup code to |
| 108 |
; eliminiate this for the plain mpn_add/submul_1 doesn't seem like a good |
| 109 |
; idea. |
| 110 |
; |
| 111 |
; overlapping with parameters already fetched |
| 112 |
|
| 113 |
%define VAR_COUNTER PARAM_SIZE |
| 114 |
%define VAR_JUMP PARAM_DST |
| 115 |
|
| 116 |
; VAL1 = ifelse(UNROLL_BYTES,256,128) |
| 117 |
%define VAL1 128 |
| 118 |
; VAL2 = ifelse(UNROLL_BYTES,256,-128) |
| 119 |
%define VAL2 -128 |
| 120 |
|
| 121 |
; this is offset 0x43,so close enough to aligned |
| 122 |
; eax |
| 123 |
; ebx initial carry |
| 124 |
; ecx size |
| 125 |
; edx |
| 126 |
; esi src |
| 127 |
; edi dst |
| 128 |
; ebp |
| 129 |
|
| 130 |
%%Lunroll: |
| 131 |
mov edx,ecx |
| 132 |
dec ecx |
| 133 |
sub edx,2 |
| 134 |
neg ecx |
| 135 |
shr edx,UNROLL_LOG2 |
| 136 |
and ecx,UNROLL_MASK |
| 137 |
mov [VAR_COUNTER],edx |
| 138 |
mov edx,ecx |
| 139 |
|
| 140 |
; 15 code bytes per limb |
| 141 |
|
| 142 |
%ifdef PIC |
| 143 |
call %%Lhere |
| 144 |
%%Lhere: |
| 145 |
shl edx,4 |
| 146 |
neg ecx |
| 147 |
lea edx,[edx+ecx*1] |
| 148 |
add edx,%%Lentry-%%Lhere |
| 149 |
add edx,[esp] |
| 150 |
add esp,4 |
| 151 |
%else |
| 152 |
shl edx,4 |
| 153 |
neg ecx |
| 154 |
lea edx,[%%Lentry+edx+ecx] |
| 155 |
%endif |
| 156 |
mov eax,[esi] ; src low limb |
| 157 |
mov [VAR_JUMP],edx |
| 158 |
lea esi,[VAL1+4+esi+ecx*4] |
| 159 |
mul ebp |
| 160 |
add eax,ebx ; initial carry (from _1c) |
| 161 |
adc edx,0 |
| 162 |
mov ebx,edx ; high carry |
| 163 |
lea edi,[VAL1+edi+ecx*4] |
| 164 |
mov edx,[VAR_JUMP] |
| 165 |
test ecx,1 |
| 166 |
mov ecx,eax ; low carry |
| 167 |
cmovnz ecx,ebx |
| 168 |
cmovnz ebx,eax |
| 169 |
jmp edx |
| 170 |
|
| 171 |
; eax scratch |
| 172 |
; ebx carry hi |
| 173 |
; ecx carry lo |
| 174 |
; edx scratch |
| 175 |
; esi src |
| 176 |
; edi dst |
| 177 |
; ebp multiplier |
| 178 |
; |
| 179 |
; VAR_COUNTER loop counter |
| 180 |
; |
| 181 |
; 15 code bytes per limb |
| 182 |
|
| 183 |
%define CHUNK_COUNT 2 |
| 184 |
|
| 185 |
align 32 |
| 186 |
%%Ltop: |
| 187 |
add edi,UNROLL_BYTES |
| 188 |
%%Lentry: |
| 189 |
%assign disp VAL2 |
| 190 |
%rep UNROLL_COUNT/CHUNK_COUNT |
| 191 |
mov eax,[byte disp+esi] |
| 192 |
mul ebp |
| 193 |
%2 [byte disp+edi],ecx |
| 194 |
adc ebx,eax |
| 195 |
mov ecx,edx |
| 196 |
adc ecx,0 |
| 197 |
mov eax,[byte disp+4+esi] |
| 198 |
mul ebp |
| 199 |
%2 [byte disp+4+edi],ebx |
| 200 |
adc ecx,eax |
| 201 |
mov ebx,edx |
| 202 |
adc ebx,0 |
| 203 |
%assign disp disp+4*CHUNK_COUNT |
| 204 |
%endrep |
| 205 |
|
| 206 |
dec dword [VAR_COUNTER] |
| 207 |
lea esi,[UNROLL_BYTES+esi] |
| 208 |
jns %%Ltop |
| 209 |
|
| 210 |
%assign disp UNROLL_BYTES+VAL2 |
| 211 |
%2 [disp+edi],ecx |
| 212 |
mov eax,ebx |
| 213 |
pop ebp |
| 214 |
pop edi |
| 215 |
pop esi |
| 216 |
pop ebx |
| 217 |
adc eax,0 |
| 218 |
ret |
| 219 |
%endmacro |
| 220 |
|
| 221 |
section .text |
| 222 |
|
| 223 |
mul_fun ___g,add,mpn_addmul_1,mpn_addmul_1c |
| 224 |
mul_fun ___g,sub,mpn_submul_1,mpn_submul_1c |
| 225 |
|
| 226 |
end |