Skip to content

Commit

Permalink
Implement Multiply and MultiplyXor hash functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpn committed Feb 19, 2020
1 parent 04b4b0b commit 08fbeab
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/PerfectHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,8 @@ IsValidSeedMasks(
3, \
DECL_SEED_MASKS(0, 0, 0x1f1f, 0, 0, 0, 0, 0) \
) \
ENTRY(Multiply, 2, NO_SEED_MASKS) \
ENTRY(MultiplyXor, 4, NO_SEED_MASKS) \
LAST_ENTRY(Scratch, 3, NO_SEED_MASKS)

#define PERFECT_HASH_HASH_FUNCTION_TABLE_ENTRY(ENTRY) \
Expand Down
2 changes: 2 additions & 0 deletions include/PerfectHashErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ Module Name:
// 22 MultiplyRotateLR (3)
// 23 MultiplyShiftR (3)
// 24 MultiplyShiftLR (3)
// 25 Multiply (2)
// 26 MultiplyXor (4)
//
// N.B. The lowest latency hash functions with good solving ability, in order of
// ascending latency, are: Crc32RotateX, Crc32RotateXY, Crc32RotateWXYZ.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

DECLARE_INDEX_ROUTINE()
{
CPHINDEX Index;
CPHDKEY Vertex1;
CPHDKEY Vertex2;
CPHDKEY MaskedLow;
CPHDKEY MaskedHigh;
CPHDKEY DownsizedKey;

DownsizedKey = DOWNSIZE_KEY(Key);

Vertex1 = DownsizedKey * SEED1;

Vertex2 = DownsizedKey * SEED2;

MaskedLow = Vertex1 & HASH_MASK;
MaskedHigh = Vertex2 & HASH_MASK;

Vertex1 = TABLE_DATA[MaskedLow];
Vertex2 = TABLE_DATA[MaskedHigh];

Index = (CPHINDEX)((Vertex1 + Vertex2) & INDEX_MASK);

return Index;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

DECLARE_INDEX_ROUTINE()
{
CPHINDEX Index;
CPHDKEY Vertex1;
CPHDKEY Vertex2;
CPHDKEY MaskedLow;
CPHDKEY MaskedHigh;
CPHDKEY DownsizedKey;

DownsizedKey = DOWNSIZE_KEY(Key);

Vertex1 = DownsizedKey * SEED1;
Vertex1 ^= SEED2;

Vertex2 = DownsizedKey * SEED3;
Vertex2 ^= SEED4;

MaskedLow = Vertex1 & HASH_MASK;
MaskedHigh = Vertex2 & HASH_MASK;

Vertex1 = TABLE_DATA[MaskedLow];
Vertex2 = TABLE_DATA[MaskedHigh];

Index = (CPHINDEX)((Vertex1 + Vertex2) & INDEX_MASK);

return Index;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Auto-generated.
//

DECLSPEC_ALIGN(16)
const CHAR CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCStr[] =
"\n"
"//\n"
"// Begin CompiledPerfectHashTableChm01IndexMultiplyAnd.c.\n"
"//\n"
"\n"
"\n"
"DECLARE_INDEX_ROUTINE()\n"
"{\n"
" CPHINDEX Index;\n"
" CPHDKEY Vertex1;\n"
" CPHDKEY Vertex2;\n"
" CPHDKEY MaskedLow;\n"
" CPHDKEY MaskedHigh;\n"
" CPHDKEY DownsizedKey;\n"
"\n"
" DownsizedKey = DOWNSIZE_KEY(Key);\n"
"\n"
" Vertex1 = DownsizedKey * SEED1;\n"
"\n"
" Vertex2 = DownsizedKey * SEED2;\n"
"\n"
" MaskedLow = Vertex1 & HASH_MASK;\n"
" MaskedHigh = Vertex2 & HASH_MASK;\n"
"\n"
" Vertex1 = TABLE_DATA[MaskedLow];\n"
" Vertex2 = TABLE_DATA[MaskedHigh];\n"
"\n"
" Index = (CPHINDEX)((Vertex1 + Vertex2) & INDEX_MASK);\n"
"\n"
" return Index;\n"
"}\n"
"\n"
"\n"
"//\n"
"// End CompiledPerfectHashTableChm01IndexMultiplyAnd.c.\n"
"//\n"
"\n"
;

const STRING CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCString = {
sizeof(CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCStr) - sizeof(CHAR),
sizeof(CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCStr),
#ifdef _WIN64
0,
#endif
(PCHAR)&CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCStr,
};

#ifndef RawCString
#define RawCString (&CompiledPerfectHashTableChm01IndexMultiplyAndCSourceRawCString)
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Auto-generated.
//

DECLSPEC_ALIGN(16)
const CHAR CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCStr[] =
"\n"
"//\n"
"// Begin CompiledPerfectHashTableChm01IndexMultiplyXorAnd.c.\n"
"//\n"
"\n"
"\n"
"DECLARE_INDEX_ROUTINE()\n"
"{\n"
" CPHINDEX Index;\n"
" CPHDKEY Vertex1;\n"
" CPHDKEY Vertex2;\n"
" CPHDKEY MaskedLow;\n"
" CPHDKEY MaskedHigh;\n"
" CPHDKEY DownsizedKey;\n"
"\n"
" DownsizedKey = DOWNSIZE_KEY(Key);\n"
"\n"
" Vertex1 = DownsizedKey * SEED1;\n"
" Vertex1 ^= SEED2;\n"
"\n"
" Vertex2 = DownsizedKey * SEED3;\n"
" Vertex2 ^= SEED4;\n"
"\n"
" MaskedLow = Vertex1 & HASH_MASK;\n"
" MaskedHigh = Vertex2 & HASH_MASK;\n"
"\n"
" Vertex1 = TABLE_DATA[MaskedLow];\n"
" Vertex2 = TABLE_DATA[MaskedHigh];\n"
"\n"
" Index = (CPHINDEX)((Vertex1 + Vertex2) & INDEX_MASK);\n"
"\n"
" return Index;\n"
"}\n"
"\n"
"\n"
"//\n"
"// End CompiledPerfectHashTableChm01IndexMultiplyXorAnd.c.\n"
"//\n"
"\n"
;

const STRING CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCString = {
sizeof(CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCStr) - sizeof(CHAR),
sizeof(CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCStr),
#ifdef _WIN64
0,
#endif
(PCHAR)&CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCStr,
};

#ifndef RawCString
#define RawCString (&CompiledPerfectHashTableChm01IndexMultiplyXorAndCSourceRawCString)
#endif
2 changes: 2 additions & 0 deletions src/PerfectHash/CompiledPerfectHashTableIndexRoutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyXorAnd_CSource_RawCString.h"

//
// Keep this last.
Expand Down
4 changes: 3 additions & 1 deletion src/PerfectHash/PerfectHash.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyXorAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableIndexRoutines.h" />
<ClInclude Include="CompiledPerfectHashTableRoutinesPost_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableRoutinesPre_CSource_RawCString.h" />
Expand Down Expand Up @@ -271,4 +273,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>
</Project>
8 changes: 7 additions & 1 deletion src/PerfectHash/PerfectHash.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyXorAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="ExtractArg.h">
<Filter>Private Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -566,4 +572,4 @@
<Filter>Resource Files</Filter>
</Natvis>
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions src/PerfectHash/PerfectHashErrors.mc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ Hash Functions:
22 MultiplyRotateLR (3)
23 MultiplyShiftR (3)
24 MultiplyShiftLR (3)
25 Multiply (2)
26 MultiplyXor (4)
N.B. The lowest latency hash functions with good solving ability, in order of
ascending latency, are: Crc32RotateX, Crc32RotateXY, Crc32RotateWXYZ.
Expand Down
Binary file modified src/PerfectHash/PerfectHashErrors_English.bin
Binary file not shown.
Loading

0 comments on commit 08fbeab

Please sign in to comment.