| 1 |
|
| 2 |
; Copyright 2000, 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 |
%define REG_AAAAAAAAAAAAAAAA mm7 |
| 24 |
%define REG_3333333333333333 mm6 |
| 25 |
%define REG_0F0F0F0F0F0F0F0F mm5 |
| 26 |
%define REG_0000000000000000 mm4 |
| 27 |
|
| 28 |
%ifndef PIC |
| 29 |
section .data |
| 30 |
align 8 |
| 31 |
|
| 32 |
Lrodata_AAAAAAAAAAAAAAAA: |
| 33 |
dd 0AAAAAAAAh |
| 34 |
dd 0AAAAAAAAh |
| 35 |
|
| 36 |
Lrodata_3333333333333333: |
| 37 |
dd 033333333h |
| 38 |
dd 033333333h |
| 39 |
|
| 40 |
Lrodata_0F0F0F0F0F0F0F0F: |
| 41 |
dd 00F0F0F0Fh |
| 42 |
dd 00F0F0F0Fh |
| 43 |
%endif |
| 44 |
|
| 45 |
%macro ph_fun 3 |
| 46 |
|
| 47 |
align 32 |
| 48 |
global %1%2 |
| 49 |
|
| 50 |
%ifdef DLL |
| 51 |
export %1%2 |
| 52 |
%endif |
| 53 |
|
| 54 |
%1%2: |
| 55 |
mov ecx,[PARAM_SIZE] |
| 56 |
%ifdef PIC |
| 57 |
mov eax,0xAAAAAAAA |
| 58 |
mov edx,0x33333333 |
| 59 |
movd mm7,eax |
| 60 |
movd mm6,edx |
| 61 |
mov eax,0x0F0F0F0F |
| 62 |
punpckldq mm7,mm7 |
| 63 |
punpckldq mm6,mm6 |
| 64 |
movd mm5,eax |
| 65 |
movd mm4,edx |
| 66 |
punpckldq mm5,mm5 |
| 67 |
%else |
| 68 |
movq mm7,[Lrodata_AAAAAAAAAAAAAAAA] |
| 69 |
movq mm6,[Lrodata_3333333333333333] |
| 70 |
movq mm5,[Lrodata_0F0F0F0F0F0F0F0F] |
| 71 |
%endif |
| 72 |
pxor mm4,mm4 |
| 73 |
mov eax,[PARAM_SRC] |
| 74 |
%if %3 == 1 |
| 75 |
mov edx,[PARAM_SRC2] |
| 76 |
%endif |
| 77 |
pxor mm2,mm2 |
| 78 |
shr ecx,1 |
| 79 |
jnc %%Ltop |
| 80 |
movd mm1,[eax+ecx*8] |
| 81 |
%if %3 == 1 |
| 82 |
movd mm0,[edx+ecx*8] |
| 83 |
pxor mm1,mm0 |
| 84 |
%endif |
| 85 |
or ecx,ecx |
| 86 |
jmp %%Lloaded |
| 87 |
|
| 88 |
; eax src |
| 89 |
; ebx |
| 90 |
; ecx counter,qwords,decrementing |
| 91 |
; edx [hamdist] src2 |
| 92 |
; |
| 93 |
; mm0 (scratch) |
| 94 |
; mm1 (scratch) |
| 95 |
; mm2 total (low dword) |
| 96 |
; mm3 |
| 97 |
; mm4 \ |
| 98 |
; mm5 | special constants |
| 99 |
; mm6 | |
| 100 |
; mm7 / |
| 101 |
|
| 102 |
align 16 |
| 103 |
%%Ltop: |
| 104 |
movq mm1,[eax+ecx*8-8] |
| 105 |
%if %3 == 1 |
| 106 |
pxor mm1,[edx+ecx*8-8] |
| 107 |
%endif |
| 108 |
dec ecx |
| 109 |
%%Lloaded: |
| 110 |
movq mm0,mm1 |
| 111 |
pand mm1,REG_AAAAAAAAAAAAAAAA |
| 112 |
psrlq mm1,1 |
| 113 |
psubd mm0,mm1 ; bit pairs |
| 114 |
movq mm1,mm0 |
| 115 |
psrlq mm0,2 |
| 116 |
pand mm0,REG_3333333333333333 |
| 117 |
pand mm1,REG_3333333333333333 |
| 118 |
paddd mm0,mm1 ; nibbles |
| 119 |
movq mm1,mm0 |
| 120 |
psrlq mm0,4 |
| 121 |
pand mm0,REG_0F0F0F0F0F0F0F0F |
| 122 |
pand mm1,REG_0F0F0F0F0F0F0F0F |
| 123 |
paddd mm0,mm1 ; bytes |
| 124 |
psadbw mm0,mm4 |
| 125 |
paddd mm2,mm0 ; add to total |
| 126 |
jnz %%Ltop |
| 127 |
movd eax,mm2 |
| 128 |
emms |
| 129 |
ret |
| 130 |
%endmacro |
| 131 |
|
| 132 |
section .text |
| 133 |
|
| 134 |
%define PARAM_SIZE esp+frame+8 |
| 135 |
%define PARAM_SRC esp+frame+4 |
| 136 |
%define frame 0 |
| 137 |
|
| 138 |
ph_fun ___g,mpn_popcount,0 |
| 139 |
|
| 140 |
%define PARAM_SIZE esp+frame+12 |
| 141 |
%define PARAM_SRC2 esp+frame+8 |
| 142 |
%define PARAM_SRC esp+frame+4 |
| 143 |
%define frame 0 |
| 144 |
|
| 145 |
ph_fun ___g,mpn_hamdist,1 |
| 146 |
|
| 147 |
end |