Skip to content

Commit

Permalink
Merge pull request #41 from cmuratori/v0.4
Browse files Browse the repository at this point in the history
Starting the v0.4 branch
  • Loading branch information
cmuratori authored Nov 11, 2018
2 parents 5ceaf14 + ed8c632 commit 7a871d7
Show file tree
Hide file tree
Showing 18 changed files with 2,363 additions and 1,598 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ matrix:
# test if meow_hash.h compiles as C
- touch test.c
- |-
"${CC}" -c -maes -include meow_intrinsics.h -include meow_hash.h test.c
"${CC}" -c -mssse3 -maes -include meow_intrinsics.h -include meow_hash.h test.c
# build & test
- cmd.exe /C build.bat
- build_clang/meow_test.exe
Expand All @@ -50,7 +50,7 @@ matrix:
script:
# test if meow_hash.h compiles as C
- touch test.c
- ${CC} -c -maes -include meow_intrinsics.h -include meow_hash.h test.c
- ${CC} -c -mssse3 -maes -include meow_intrinsics.h -include meow_hash.h test.c
# build & test
- ./build.sh
- build/meow_test.exe
Expand All @@ -75,7 +75,7 @@ matrix:
script:
# test if meow_hash.h compiles as C
- touch test.c
- ${CC} -c -maes -include meow_intrinsics.h -include meow_hash.h test.c
- ${CC} -c -mssse3 -maes -include meow_intrinsics.h -include meow_hash.h test.c
# build & test
- ./build.sh
- ./build/meow_test
Expand All @@ -99,7 +99,7 @@ matrix:
script:
# test if meow_hash.h compiles as C
- touch test.c
- ${CC} -c -maes -include meow_intrinsics.h -include meow_hash.h test.c
- ${CC} -c -mssse3 -maes -include meow_intrinsics.h -include meow_hash.h test.c
# build & test
- ./build.sh
- ./build/meow_test
Expand Down Expand Up @@ -149,7 +149,7 @@ matrix:
script:
# test if meow_hash.h compiles as C
- touch test.c
- ${CC} -c -maes -include meow_intrinsics.h -include meow_hash.h test.c
- ${CC} -c -mssse3 -maes -include meow_intrinsics.h -include meow_hash.h test.c
# build & test
- ./build.sh
- ./build/meow_test
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Meow hash 0.3/snowshoe
# Meow hash 0.4/himalayan
This is the official x64 implementation of the Meow hash, an extremely fast non-cryptographic hash. See https://mollyrocket.com/meowhash for usage, implementation, and license details.

This version is v0.3 and is EXPERIMENTAL. It is only designed for testing and comment right now. Updates will be coming which finalize the hash function, but for right now it is still considered in flux. This version builds on Windows/MSVC, Linux/CLANG, and Mac/CLANG, and supports x64 and ARM processors with AES instructions. An ANSI-only (slow) version will be added eventually.
This version is v0.4 and is EXPERIMENTAL. It is only designed for testing and comment right now. Updates will be coming which finalize the hash function, but for right now it is still considered in flux. This version builds on Windows/MSVC, Linux/CLANG, and Mac/CLANG, and supports x64 and ARM processors with AES instructions and (much slower) vanilla C for compatibility.
18 changes: 11 additions & 7 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ echo Building with MSVC

if not exist "build_msvc" mkdir build_msvc
pushd build_msvc
cl %* -I../ -nologo -FC -Oi -O2 -Zi ..\meow_example.cpp
cl %* -I../ -nologo -EHsc -FC -Oi -O2 -Zi ..\utils\meow_test.cpp
cl %* -I../ -nologo -FC -Oi /O2 -Zi -arch:AVX ..\utils\meow_search.cpp
cl %* -I../ -nologo -FC -Oi /O2 -Zi -arch:AVX2 ..\utils\meow_bench.cpp
cl %* -I../ -nologo -EHsc -FC -Oi -O2 -Zi ..\meow_example.cpp
cl %* -I../ -nologo -EHsc -FC -Oi -O2 -Zi ..\more\meow_more_example.cpp
REM cl %* -I../ -nologo -EHsc -FC -Oi -O2 -Zi ..\more\megapaw_example.cpp
cl %* -I../ -nologo -EHsc -FC -Oi -O2 -Zi ..\more\meow_test.cpp
cl %* -I../ -nologo -FC -Oi /O2 -Zi -arch:AVX ..\more\meow_search.cpp
cl %* -I../ -nologo -FC -Oi /O2 -Zi -arch:AVX2 ..\more\meow_bench.cpp
popd

:SkipMSVC
Expand All @@ -26,9 +28,11 @@ echo Building with CLANG
if not exist "build_clang" mkdir build_clang
pushd build_clang
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -msse4 ..\meow_example.cpp -o meow_example.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -msse4 ..\utils\meow_test.cpp -o meow_test.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -mavx ..\utils\meow_search.cpp -o meow_search.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -mavx2 ..\utils\meow_bench.cpp -o meow_bench.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -msse4 ..\more\meow_more_example.cpp -o meow_more_example.exe
REM clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -msse4 ..\more\megapaw_example.cpp -o megapaw_example.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -msse4 ..\more\meow_test.cpp -o meow_test.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -mavx ..\more\meow_search.cpp -o meow_search.exe
clang++ %* -I../ -Wno-deprecated-declarations -g -O3 -maes -mavx2 ..\more\meow_bench.cpp -o meow_bench.exe
popd

echo -------------------
Expand Down
7 changes: 4 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CXX=${CXX:-clang++}

mkdir -p build
${CXX} $* -I. meow_example.cpp -O3 -mavx -maes -o build/meow_example
${CXX} $* -I. utils/meow_test.cpp -O3 -mavx -maes -o build/meow_test
${CXX} $* -I. utils/meow_search.cpp -O3 -mavx -maes -o build/meow_search
${CXX} $* -I. utils/meow_bench.cpp -O3 -mavx -maes -o build/meow_bench
${CXX} $* -I. more/meow_more_example.cpp -O3 -mavx -maes -o build/meow_more_example
${CXX} $* -I. more/meow_test.cpp -O3 -mavx -maes -o build/meow_test
${CXX} $* -I. more/meow_search.cpp -O3 -mavx -maes -o build/meow_search
${CXX} $* -I. more/meow_bench.cpp -O3 -mavx2 -maes -o build/meow_bench
73 changes: 12 additions & 61 deletions meow_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,10 @@
//

#include "meow_intrinsics.h" // NOTE(casey): Platform prerequisites for the Meow hash code (replace with your own, if you want)

#include "meow_hash.h" // NOTE(casey): The Meow hash code itself

//
// NOTE(casey): Step 2 (optional) - for future-proofing, detect which Meow hash the CPU can run
//
// This is COMPLETELY OPTIONAL - you can instead just always call MeowHash1 to use
// the 128-bit-wide version exclusively.
//

static meow_hash_implementation *MeowHash = MeowHash1;

int MeowHashSpecializeForCPU(void)
{
int Result = 0;

#if MEOW_HASH_AVX512
try
{
char Garbage[64];
MeowHash4(0, sizeof(Garbage), Garbage);
MeowHash = MeowHash4;
Result = 512;
}
catch(...)
#endif
{
#if MEOW_HASH_AVX512
try
{
char Garbage[64];
MeowHash2(0, sizeof(Garbage), Garbage);
MeowHash = MeowHash2;
Result = 256;
}
catch(...)
#endif
{
MeowHash = MeowHash1;
Result = 128;
}
}

return(Result);
}

//
// NOTE(casey): Step 3 - use the Meow hash in a variety of ways!
// NOTE(casey): Step 2 - use the Meow hash in a variety of ways!
//
// Example functions below:
// PrintHash - how to print a Meow hash to stdout, from highest-order 32-bits to lowest
Expand All @@ -90,14 +46,13 @@ static entire_file ReadEntireFile(char *Filename);
static void FreeEntireFile(entire_file *File);

static void
PrintHash(meow_u128 Hash)
PrintHash(meow_hash Hash)
{
meow_u32 *HashU32 = (meow_u32 *)&Hash;
printf(" %08X-%08X-%08X-%08X\n",
HashU32[3],
HashU32[2],
HashU32[1],
HashU32[0]);
MeowU32From(Hash, 3),
MeowU32From(Hash, 2),
MeowU32From(Hash, 1),
MeowU32From(Hash, 0));
}

static void
Expand All @@ -114,11 +69,11 @@ HashTestBuffer(void)
}

// NOTE(casey): Ask Meow for the hash
meow_u128 Hash = MeowHash(0, Size, Buffer);
meow_hash Hash = MeowHash_Accelerated(0, Size, Buffer);

// NOTE(casey): Extract example smaller hash sizes you might want:
long long unsigned Hash64 = MeowU64From(Hash);
int unsigned Hash32 = MeowU32From(Hash);
long long unsigned Hash64 = MeowU64From(Hash, 0);
int unsigned Hash32 = MeowU32From(Hash, 0);

// NOTE(casey): Print the hash
printf(" Hash of a test buffer:\n");
Expand All @@ -135,7 +90,7 @@ HashOneFile(char *FilenameA)
if(A.Contents)
{
// NOTE(casey): Ask Meow for the hash
meow_u128 HashA = MeowHash(0, A.Size, A.Contents);
meow_hash HashA = MeowHash_Accelerated(0, A.Size, A.Contents);

// NOTE(casey): Print the hash
printf(" Hash of \"%s\":\n", FilenameA);
Expand All @@ -154,8 +109,8 @@ CompareTwoFiles(char *FilenameA, char *FilenameB)
if(A.Contents && B.Contents)
{
// NOTE(casey): Hash both files
meow_u128 HashA = MeowHash(0, A.Size, A.Contents);
meow_u128 HashB = MeowHash(0, B.Size, B.Contents);
meow_hash HashA = MeowHash_Accelerated(0, A.Size, A.Contents);
meow_hash HashB = MeowHash_Accelerated(0, B.Size, B.Contents);

// NOTE(casey): Check for match
int HashesMatch = MeowHashesAreEqual(HashA, HashB);
Expand Down Expand Up @@ -209,10 +164,6 @@ main(int ArgCount, char **Args)
printf("See https://mollyrocket.com/meowhash for details.\n");
printf("\n");

// NOTE(casey): Detect which MeowHash to call - do this only once, at startup.
int BitWidth = MeowHashSpecializeForCPU();
printf("Using %u-bit Meow implementation\n", BitWidth);

// NOTE(casey): Look at our arguments to decide which example to run
if(ArgCount < 2)
{
Expand Down
Loading

0 comments on commit 7a871d7

Please sign in to comment.