Browse Source

* make UpdateFnv64 closer to the original algorithm as proposed by Gareth

florian 10 tháng trước cách đây
mục cha
commit
0e0c4bd621
2 tập tin đã thay đổi với 3 bổ sung8 xóa
  1. 2 7
      compiler/fpchash.pas
  2. 1 1
      compiler/ppu.pas

+ 2 - 7
compiler/fpchash.pas

@@ -116,11 +116,6 @@ function InitFnv64: uint64;
 function UpdateFnv64(const InitFnv: uint64; const InBuf; InLen: Integer): uint64;
 const
   M = uint64(1099511628211);
-  { Compiler yells at you for overflows in constants, even with disabled range checks,
-    so there are precalculated values for unrolled loop: M^2, M^3, M^4. }
-  Mp2 = uint64(956575116354345);
-  Mp3 = uint64(624165263380053675);
-  Mp4 = uint64(11527715348014283921);
 var
   pp: pByte;
 begin
@@ -128,13 +123,13 @@ begin
   pp := @InBuf;
   while InLen >= 4 do
    begin
-     result := (result + pp[0]) * Mp4 + pp[1] * Mp3 + pp[2] * Mp2 + pp[3] * M;
+     result := ((((result xor pp[0]) * M xor pp[1]) * M xor pp[2]) * M xor pp[3]) * M;
      pp := pp + 4;
      InLen := InLen - 4;
    end;
   while InLen > 0 do
    begin
-     result := (result + pp^) * M;
+     result := (result xor pp^) * M;
      pp := pp + 1;
      InLen := InLen - 1;
    end;

+ 1 - 1
compiler/ppu.pas

@@ -48,7 +48,7 @@ const
   CurrentPPUVersion = 208;
   { for any other changes to the ppu format, increase this version number
     (it's a cardinal) }
-  CurrentPPULongVersion = 25;
+  CurrentPPULongVersion = 26;
 
 { unit flags }
   uf_big_endian          = $000004;