| 1 |
|
| 2 |
; Copyright 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 |
extern ___gmp_modlimb_invert_table |
| 26 |
global ___gmpn_modexact_1c_odd |
| 27 |
global ___gmpn_modexact_1_odd |
| 28 |
|
| 29 |
%ifdef DLL |
| 30 |
export ___gmpn_modexact_1c_odd |
| 31 |
export ___gmpn_modexact_1_odd |
| 32 |
%endif |
| 33 |
|
| 34 |
%define PARAM_CARRY esp+frame+16 |
| 35 |
%define PARAM_DIVISOR esp+frame+12 |
| 36 |
%define PARAM_SIZE esp+frame+8 |
| 37 |
%define PARAM_SRC esp+frame+4 |
| 38 |
|
| 39 |
; Not enough room under modexact_1 to make these re-use the parameter |
| 40 |
; space,unfortunately. |
| 41 |
|
| 42 |
%define SAVE_EBX esp+frame-4 |
| 43 |
%define SAVE_ESI esp+frame-8 |
| 44 |
%define SAVE_EDI esp+frame-12 |
| 45 |
%define STACK_SPACE 12 |
| 46 |
%define frame 0 |
| 47 |
|
| 48 |
section .text |
| 49 |
|
| 50 |
align 16 |
| 51 |
|
| 52 |
___gmpn_modexact_1c_odd: |
| 53 |
mov ecx,[PARAM_CARRY] |
| 54 |
jmp Lstart_1c |
| 55 |
|
| 56 |
align 16 |
| 57 |
|
| 58 |
___gmpn_modexact_1_odd: |
| 59 |
xor ecx,ecx |
| 60 |
Lstart_1c: |
| 61 |
mov eax,[PARAM_DIVISOR] |
| 62 |
sub esp,STACK_SPACE |
| 63 |
FR_sesp STACK_SPACE |
| 64 |
|
| 65 |
mov [SAVE_ESI],esi |
| 66 |
mov esi,[PARAM_SRC] |
| 67 |
shr eax,1 ; d/2 |
| 68 |
mov [SAVE_EDI],edi |
| 69 |
and eax,127 |
| 70 |
|
| 71 |
%ifdef PIC |
| 72 |
call Lmovl_eip_edi |
| 73 |
add edi,_GLOBAL_OFFSET_TABLE_ |
| 74 |
mov edi,[___gmp_modlimb_invert_table+edi] |
| 75 |
movzx edi,byte [eax+edi] ; inv 8 bits |
| 76 |
%else |
| 77 |
movzx edi,byte [___gmp_modlimb_invert_table+eax] ; inv 8 bits |
| 78 |
%endif |
| 79 |
|
| 80 |
xor edx,edx ; initial extra carry |
| 81 |
lea eax,[edi+edi] ; 2*inv |
| 82 |
imul edi,edi ; inv*inv |
| 83 |
mov [SAVE_EBX],ebx |
| 84 |
mov ebx,[PARAM_SIZE] |
| 85 |
imul edi,[PARAM_DIVISOR] ; inv*inv*d |
| 86 |
sub eax,edi ; inv = 2*inv - inv*inv*d |
| 87 |
lea edi,[eax+eax] ; 2*inv |
| 88 |
imul eax,eax ; inv*inv |
| 89 |
imul eax,[PARAM_DIVISOR] ; inv*inv*d |
| 90 |
lea esi,[esi+ebx*4] ; src end |
| 91 |
neg ebx ; -size |
| 92 |
sub edi,eax ; inv = 2*inv - inv*inv*d |
| 93 |
|
| 94 |
; The dependent chain here is |
| 95 |
; |
| 96 |
; subl %edx,%eax 1 |
| 97 |
; imull %edi,%eax 4 |
| 98 |
; mull PARAM_DIVISOR 5 |
| 99 |
; ---- |
| 100 |
; total 10 |
| 101 |
; |
| 102 |
; and this is the measured speed. No special scheduling is necessary,out |
| 103 |
; of order execution hides the load latency. |
| 104 |
; |
| 105 |
; eax scratch (src limb) |
| 106 |
; ebx counter,limbs,negative |
| 107 |
; ecx carry bit,0 or 1 |
| 108 |
; edx carry limb,high of last product |
| 109 |
; esi &src[size] |
| 110 |
; edi inverse |
| 111 |
; ebp |
| 112 |
|
| 113 |
Ltop: |
| 114 |
mov eax,[esi+ebx*4] |
| 115 |
sub eax,ecx |
| 116 |
sbb ecx,ecx |
| 117 |
sub eax,edx |
| 118 |
sbb ecx,0 |
| 119 |
imul eax,edi |
| 120 |
neg ecx |
| 121 |
mul dword [PARAM_DIVISOR] |
| 122 |
inc ebx |
| 123 |
jnz Ltop |
| 124 |
mov esi,[SAVE_ESI] |
| 125 |
lea eax,[ecx+edx] |
| 126 |
mov edi,[SAVE_EDI] |
| 127 |
mov ebx,[SAVE_EBX] |
| 128 |
add esp,STACK_SPACE |
| 129 |
ret |
| 130 |
|
| 131 |
%ifdef PIC |
| 132 |
Lmovl_eip_edi: |
| 133 |
mov edi,[esp] |
| 134 |
ret |
| 135 |
%endif |
| 136 |
|
| 137 |
end |