Board index » delphi » basm elf hash

basm elf hash


2005-05-18 07:02:00 PM
delphi253
Does someone have a basm elf hash?
 
 

Re:basm elf hash

Quote
Does someone have a basm elf hash?
Not well tested function below
function ElfHash(const s: string): integer;
asm
mov edx, eax
xor eax, eax
test edx, edx
jz @Ret
sub eax, [edx-4]
jz @Ret
mov ecx, eax
sub edx, eax
xor eax, eax
push ebx
@Loop:
movzx ebx, [edx+ecx]
add ebx, eax
lea eax, [ebx+ebx]
shr ebx, 20
add eax, eax
add eax, eax
add eax, eax
and ebx, $0F00
xor eax, ebx
add ecx, 1
jnz @Loop
shr eax, 4
pop ebx
@Ret:
end;
 

Re:basm elf hash

Function listed below is a little faster on my P4
(it takes 7 tick/char against 7.5 tick/char).
function ElfHash_Sha(const s: string): integer;
asm
mov edx, eax
xor eax, eax
test edx, edx
jz @Ret
sub eax, [edx-4]
jz @Ret
mov ecx, eax
sub edx, eax
xor eax, eax
push ebx
@Loop:
movzx ebx, [edx+ecx]
add ebx, eax
lea eax, [ebx+ebx]
shr ebx, 20
lea eax, [8*eax]
and ebx, $0F00
xor eax, ebx
add ecx, 1
jnz @Loop
shr eax, 4
pop ebx
@Ret:
end;