| 1 |
|
| 2 |
; Copyright 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software |
| 3 |
; Foundation, Inc. |
| 4 |
; |
| 5 |
; This file is part of the GNU MP Library. |
| 6 |
; |
| 7 |
; The GNU MP Library is free software; you can redistribute it and/or |
| 8 |
; modify it under the terms of the GNU Lesser General Public License as |
| 9 |
; published by the Free Software Foundation; either version 2.1 of the |
| 10 |
; License, or (at your option) any later version. |
| 11 |
; |
| 12 |
; The GNU MP Library is distributed in the hope that it will be useful, |
| 13 |
; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
; Lesser General Public License for more details. |
| 16 |
; |
| 17 |
; You should have received a copy of the GNU Lesser General Public |
| 18 |
; License along with the GNU MP Library; see the file COPYING.LIB. If |
| 19 |
; not, write to the Free Software Foundation, Inc., 59 Temple Place - |
| 20 |
; Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
; |
| 22 |
; Translation of AT&T syntax code by Brian Gladman |
| 23 |
|
| 24 |
%include "x86i.inc" |
| 25 |
|
| 26 |
; mp_limb_t M4_function_n (mp_ptr dst,mp_srcptr src1,mp_srcptr src2, |
| 27 |
; mp_size_t size); |
| 28 |
; mp_limb_t M4_function_nc (mp_ptr dst,mp_srcptr src1,mp_srcptr src2, |
| 29 |
; mp_size_t size,mp_limb_t carry); |
| 30 |
|
| 31 |
%define PARAM_SPACE 20 |
| 32 |
%define PARAM_CARRY esp+frame+20 |
| 33 |
%define PARAM_SIZE esp+frame+16 |
| 34 |
%define PARAM_SRC2 esp+frame+12 |
| 35 |
%define PARAM_SRC1 esp+frame+8 |
| 36 |
%define PARAM_DST esp+frame+4 |
| 37 |
|
| 38 |
%macro mac_sub 4 |
| 39 |
|
| 40 |
global %1%4 |
| 41 |
%ifdef DLL |
| 42 |
export %1%4 |
| 43 |
%endif |
| 44 |
|
| 45 |
align 8 |
| 46 |
%1%4: |
| 47 |
%assign frame 0 |
| 48 |
FR_push edi |
| 49 |
FR_push esi |
| 50 |
mov edi,[PARAM_DST] |
| 51 |
mov esi,[PARAM_SRC1] |
| 52 |
mov edx,[PARAM_SRC2] |
| 53 |
mov ecx,[PARAM_SIZE] |
| 54 |
mov eax,ecx |
| 55 |
shr ecx,3 ; compute count for unrolled %%4 |
| 56 |
neg eax |
| 57 |
and eax,7 ; get index where to start %%4 |
| 58 |
jz %%3 ; necessary special case for 0 |
| 59 |
inc ecx ; adjust %%4 count |
| 60 |
shl eax,2 ; adjustment for pointers... |
| 61 |
sub edi,eax ; ... since they are offset ... |
| 62 |
sub esi,eax ; ... by a constant when we ... |
| 63 |
sub edx,eax ; ... enter the %%4 |
| 64 |
shr eax,2 ; restore previous value |
| 65 |
|
| 66 |
; Calculate start address in %%4 |
| 67 |
|
| 68 |
%ifdef PIC |
| 69 |
call %%1 |
| 70 |
%%1: |
| 71 |
lea eax,[%%4-%%1-3+eax+eax*8] |
| 72 |
add eax,[esp] |
| 73 |
add esp,4 |
| 74 |
%else |
| 75 |
lea eax,[%%4-3+eax+eax*8] |
| 76 |
%endif |
| 77 |
|
| 78 |
; These lines initialize carry from the 5th parameter. Should be |
| 79 |
; possible to simplify. |
| 80 |
|
| 81 |
FR_push ebp |
| 82 |
mov ebp,[PARAM_CARRY] |
| 83 |
shr ebp,1 ; shift bit 0 into carry |
| 84 |
FR_pop ebp |
| 85 |
jmp eax ; jump into %%4 |
| 86 |
|
| 87 |
global %1%3 |
| 88 |
%ifdef DLL |
| 89 |
export %1%3 |
| 90 |
%endif |
| 91 |
align 8 |
| 92 |
%1%3: |
| 93 |
%assign frame 0 |
| 94 |
FR_push edi |
| 95 |
FR_push esi |
| 96 |
mov edi,[PARAM_DST] |
| 97 |
mov esi,[PARAM_SRC1] |
| 98 |
mov edx,[PARAM_SRC2] |
| 99 |
mov ecx,[PARAM_SIZE] |
| 100 |
mov eax,ecx |
| 101 |
shr ecx,3 ; compute count for unrolled %%4 |
| 102 |
neg eax |
| 103 |
and eax,7 ; get index where to start %%4 |
| 104 |
jz %%4 ; necessary special case for 0 |
| 105 |
inc ecx ; adjust %%4 count |
| 106 |
shl eax,2 ; adjustment for pointers... |
| 107 |
sub edi,eax ; ... since they are offset ... |
| 108 |
sub esi,eax ; ... by a constant when we ... |
| 109 |
sub edx,eax ; ... enter the %%4 |
| 110 |
shr eax,2 ; restore previous value |
| 111 |
|
| 112 |
; Calculate start address in %%4 for PIC. |
| 113 |
; Due to limitations in some assemblers,%%4-%%2-3 |
| 114 |
; cannot be put into the leal |
| 115 |
|
| 116 |
%ifdef PIC |
| 117 |
call %%2 |
| 118 |
%%2: |
| 119 |
lea eax,[%%4-%%2-3+eax+eax*8] |
| 120 |
add eax,[esp] |
| 121 |
add esp,4 |
| 122 |
%else |
| 123 |
lea eax,[%%4-3+eax+eax*8] |
| 124 |
%endif |
| 125 |
jmp eax ; jump into %%4 |
| 126 |
%%3: |
| 127 |
FR_push ebp |
| 128 |
mov ebp,[PARAM_CARRY] |
| 129 |
shr ebp,1 ; shift bit 0 into carry |
| 130 |
FR_pop ebp |
| 131 |
|
| 132 |
align 8 |
| 133 |
%%4: |
| 134 |
mov eax,[esi] |
| 135 |
%2 eax,[edx] |
| 136 |
mov [edi],eax |
| 137 |
mov eax,[4+esi] |
| 138 |
%2 eax,[edx+4] |
| 139 |
mov [4+edi],eax |
| 140 |
mov eax,[8+esi] |
| 141 |
%2 eax,[edx+8] |
| 142 |
mov [8+edi],eax |
| 143 |
mov eax,[12+esi] |
| 144 |
%2 eax,[edx+12] |
| 145 |
mov [12+edi],eax |
| 146 |
mov eax,[16+esi] |
| 147 |
%2 eax,[edx+16] |
| 148 |
mov [16+edi],eax |
| 149 |
mov eax,[20+esi] |
| 150 |
%2 eax,[edx+20] |
| 151 |
mov [20+edi],eax |
| 152 |
mov eax,[24+esi] |
| 153 |
%2 eax,[edx+24] |
| 154 |
mov [24+edi],eax |
| 155 |
mov eax,[28+esi] |
| 156 |
%2 eax,[edx+28] |
| 157 |
mov [28+edi],eax |
| 158 |
lea edi,[32+edi] |
| 159 |
lea esi,[32+esi] |
| 160 |
lea edx,[32+edx] |
| 161 |
dec ecx |
| 162 |
jnz %%4 |
| 163 |
sbb eax,eax |
| 164 |
neg eax |
| 165 |
pop esi |
| 166 |
pop edi |
| 167 |
ret |
| 168 |
%endmacro |
| 169 |
|
| 170 |
section .text |
| 171 |
|
| 172 |
mac_sub ___g,adc,mpn_add_n,mpn_add_nc |
| 173 |
mac_sub ___g,sbb,mpn_sub_n,mpn_sub_nc |
| 174 |
|
| 175 |
end |