Message-ID: <3DA58143.1020702@riosoftware.com> Date: Thu, 10 Oct 2002 09:31:47 -0400 From: Colin Sarsfield Organization: Rio Software, LLC User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020826 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.delphi.language.basm Subject: Re: Looking for a really fast hash algorithm References: <3d8f7618@newsgroups.borland.com> <3d8fce54$1@newsgroups.borland.com> <3d902010@newsgroups.borland.com> <3d91976b$2@newsgroups.borland.com> <3D92DF1D.794F9EA9@optimalcode.com> <3d95390a$1@newsgroups.borland.com> <3D95B23A.DCF87058@optimalcode.com> <3d95b826$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 204.111.85.64 X-Trace: newsgroups.borland.com 1034256623 204.111.85.64 (10 Oct 2002 06:30:23 -0700) Lines: 40 Path: newsgroups.borland.com!not-for-mail Xref: newsgroups.borland.com borland.public.delphi.language.basm:532 Will DeWitt wrote: > Almost. =) Re-ran the same tests as before and the gap was narrowed down > to less than 1 percent (in one test case it eeked out a lead tho). I made > one or two minor modifications to the code and now it's faster in all > situations (short or long). The first change was right at the top-- I > replaced the lea ecx, [eax-4] / mov edx, [ecx] combo with a simple mov edx, > [eax-4]. I think changed the mov cl,[eax+edx] after @Loop1 to movzx ecx, > [eax+edx]. In this form it beats my original HashASM. =) > > function HashRL3New(const S: string): integer; Here's a function that's about 28% faster :) (on my Athlon XP 1400+) function HashN(const S: String): Integer; var I: Integer; PC1, PC2: PChar; P1, P2: PInteger; begin Result := 0; I := Length(S); P1 := PInteger(@S[1]); P2 := PInteger(@S[Succ(I and $fffffffc)]); while P1 <> P2 do begin Result := Result * 988053892081 + (P1^ and 255) * 991026973 + ((P1^ shr 8) and 255) * 994009 + ((P1^ shr 16) and 255) * 997 + (P1^ shr 24); Inc(P1); end; PC1 := PChar(P1); PC2 := @S[I]; Inc(PC2); while PC1 <> PC2 do begin Result := Result * 997 + Ord(PC1^); Inc(PC1); end; end;