Skip to content

Commit

Permalink
Implement hash functions MultiplyRotateLR, MultiplyShiftL, MultiplySh…
Browse files Browse the repository at this point in the history
…iftLR.
  • Loading branch information
tpn committed Feb 17, 2020
1 parent 13569cf commit 3edb7ab
Show file tree
Hide file tree
Showing 14 changed files with 589 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/PerfectHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,21 @@ IsValidSeedMasks(
3, \
DECL_SEED_MASKS(0, 0, 0x1f1f, 0, 0, 0, 0, 0) \
) \
ENTRY( \
MultiplyRotateLR, \
3, \
DECL_SEED_MASKS(0, 0, 0x1f1f, 0, 0, 0, 0, 0) \
) \
ENTRY( \
MultiplyShiftR, \
3, \
DECL_SEED_MASKS(0, 0, 0x1f1f, 0, 0, 0, 0, 0) \
) \
ENTRY( \
MultiplyShiftLR, \
3, \
DECL_SEED_MASKS(0, 0, 0x1f1f, 0, 0, 0, 0, 0) \
) \
LAST_ENTRY(Scratch, 3, NO_SEED_MASKS)

#define PERFECT_HASH_HASH_FUNCTION_TABLE_ENTRY(ENTRY) \
Expand Down
3 changes: 3 additions & 0 deletions include/PerfectHashErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ Module Name:
// 19 ShiftMultiplyXorShift2 (6)
// 20 RotateMultiplyXorRotate2 (6)
// 21 MultiplyRotateR (3)
// 22 MultiplyRotateLR (3)
// 23 MultiplyShiftR (3)
// 24 MultiplyShiftLR (3)
//
// 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,29 @@

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

DownsizedKey = DOWNSIZE_KEY(Key);

Vertex1 = DownsizedKey * SEED1;
Vertex1 = _rotl(Vertex1, SEED3_BYTE1);

Vertex2 = DownsizedKey * SEED2;
Vertex2 = _rotr(Vertex2, SEED3_BYTE2);

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 = Vertex1 << SEED3_BYTE1;

Vertex2 = DownsizedKey * SEED2;
Vertex2 = Vertex2 >> SEED3_BYTE2;

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 = Vertex1 >> SEED3_BYTE1;

Vertex2 = DownsizedKey * SEED2;
Vertex2 = Vertex2 >> SEED3_BYTE2;

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,59 @@
//
// Auto-generated.
//

DECLSPEC_ALIGN(16)
const CHAR CompiledPerfectHashTableChm01IndexMultiplyRotateLRAndCSourceRawCStr[] =
"\n"
"//\n"
"// Begin CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd.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 = _rotl(Vertex1, SEED3_BYTE1);\n"
"\n"
" Vertex2 = DownsizedKey * SEED2;\n"
" Vertex2 = _rotr(Vertex2, SEED3_BYTE2);\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 CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd.c.\n"
"//\n"
"\n"
;

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

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

DECLSPEC_ALIGN(16)
const CHAR CompiledPerfectHashTableChm01IndexMultiplyShiftLRAndCSourceRawCStr[] =
"\n"
"//\n"
"// Begin CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd.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 = Vertex1 << SEED3_BYTE1;\n"
"\n"
" Vertex2 = DownsizedKey * SEED2;\n"
" Vertex2 = Vertex2 >> SEED3_BYTE2;\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 CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd.c.\n"
"//\n"
"\n"
;

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

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

DECLSPEC_ALIGN(16)
const CHAR CompiledPerfectHashTableChm01IndexMultiplyShiftRAndCSourceRawCStr[] =
"\n"
"//\n"
"// Begin CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd.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 = Vertex1 >> SEED3_BYTE1;\n"
"\n"
" Vertex2 = DownsizedKey * SEED2;\n"
" Vertex2 = Vertex2 >> SEED3_BYTE2;\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 CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd.c.\n"
"//\n"
"\n"
;

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

#ifndef RawCString
#define RawCString (&CompiledPerfectHashTableChm01IndexMultiplyShiftRAndCSourceRawCString)
#endif
3 changes: 3 additions & 0 deletions src/PerfectHash/CompiledPerfectHashTableIndexRoutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "CompiledPerfectHashTableChm01IndexShiftMultiplyXorShift2And_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexRotateMultiplyXorRotate2And_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyRotateRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd_CSource_RawCString.h"
#include "CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h"

//
// Keep this last.
Expand Down
3 changes: 3 additions & 0 deletions src/PerfectHash/PerfectHash.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
<ClInclude Include="CompiledPerfectHashTableChm01IndexShiftMultiplyXorShift2And_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexRotateMultiplyXorRotate2And_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyRotateRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableIndexRoutines.h" />
<ClInclude Include="CompiledPerfectHashTableRoutinesPost_CSource_RawCString.h" />
<ClInclude Include="CompiledPerfectHashTableRoutinesPre_CSource_RawCString.h" />
Expand Down
9 changes: 9 additions & 0 deletions src/PerfectHash/PerfectHash.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,15 @@
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyRotateRAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyRotateLRAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftRAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="CompiledPerfectHashTableChm01IndexMultiplyShiftLRAnd_CSource_RawCString.h">
<Filter>Private Header Files %28Auto-Generated%29</Filter>
</ClInclude>
<ClInclude Include="ExtractArg.h">
<Filter>Private Header Files</Filter>
</ClInclude>
Expand Down
3 changes: 3 additions & 0 deletions src/PerfectHash/PerfectHashErrors.mc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ Hash Functions:
19 ShiftMultiplyXorShift2 (6)
20 RotateMultiplyXorRotate2 (6)
21 MultiplyRotateR (3)
22 MultiplyRotateLR (3)
23 MultiplyShiftR (3)
24 MultiplyShiftLR (3)
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 3edb7ab

Please sign in to comment.