summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-13 23:23:14 +0000
committeraappleby@google.com <aappleby@google.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2011-04-13 23:23:14 +0000
commita27c28138be78f35f76ea9c13c6354be47097985 (patch)
tree41f069b6c91274a082b0a53466f3921bce02c9f7
parent510b8528df1cc38c289abf5e9c3c689e979a6cc3 (diff)
downloadsrc-a27c28138be78f35f76ea9c13c6354be47097985.tar.gz
Enable all gcc warnings except strict aliasing, fix build issues
git-svn-id: http://smhasher.googlecode.com/svn/trunk@133 77a7d1d3-4c08-bdc2-d393-d5859734b01a
-rw-r--r--Bitvec.cpp2
-rw-r--r--CMakeLists.txt1
-rw-r--r--City.cpp4
-rw-r--r--Random.h7
-rw-r--r--SpeedTest.cpp4
-rw-r--r--Types.h24
-rw-r--r--main.cpp49
7 files changed, 47 insertions, 44 deletions
diff --git a/Bitvec.cpp b/Bitvec.cpp
index 16feaa7..6c74bcc 100644
--- a/Bitvec.cpp
+++ b/Bitvec.cpp
@@ -239,7 +239,7 @@ void lshift32 ( void * blob, int len, int c )
int nbytes = len;
int ndwords = nbytes / 4;
- uint32_t * k = (uint32_t*)blob;
+ uint32_t * k = reinterpret_cast<uint32_t*>(blob);
if(c == 0) return;
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 88f9cce..2b5df45 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,7 @@ project(SMHasher)
cmake_minimum_required(VERSION 2.4)
set(CMAKE_BUILD_TYPE Release)
+set(CMAKE_CXX_FLAGS "-g -fno-strict-aliasing -Wall")
add_library(
SMHasherSupport
diff --git a/City.cpp b/City.cpp
index 2f089d3..9043440 100644
--- a/City.cpp
+++ b/City.cpp
@@ -27,7 +27,7 @@
// possible hash functions, by using SIMD instructions, or by
// compromising on hash quality.
-#include "city.h"
+#include "City.h"
#include <algorithm>
@@ -318,4 +318,4 @@ void CityHash128_test ( const void * key, int len, uint32_t seed, void * out )
s.first = seed;
*(uint128*)out = CityHash128WithSeed((const char*)key,len,s);
-} \ No newline at end of file
+}
diff --git a/Random.h b/Random.h
index 619c453..e5a78fb 100644
--- a/Random.h
+++ b/Random.h
@@ -71,15 +71,16 @@ struct Rand
void rand_p ( void * blob, int bytes )
{
- uint32_t * blocks = (uint32_t*)blob;
+ uint32_t * blocks = reinterpret_cast<uint32_t*>(blob);
while(bytes >= 4)
{
- *blocks++ = rand_u32();
+ blocks[0] = rand_u32();
+ blocks++;
bytes -= 4;
}
- uint8_t * tail = (uint8_t*)blocks;
+ uint8_t * tail = reinterpret_cast<uint8_t*>(blocks);
for(int i = 0; i < bytes; i++)
{
diff --git a/SpeedTest.cpp b/SpeedTest.cpp
index 5f218f8..fc71a36 100644
--- a/SpeedTest.cpp
+++ b/SpeedTest.cpp
@@ -96,9 +96,9 @@ void FilterOutliers ( std::vector<double> & v )
{
std::sort(v.begin(),v.end());
- int len = 0;
+ size_t len = 0;
- for(int x = 0x40000000; x; x = x >> 1 )
+ for(size_t x = 0x40000000; x; x = x >> 1 )
{
if((len | x) >= v.size()) continue;
diff --git a/Types.h b/Types.h
index 8814093..ee7ae9d 100644
--- a/Types.h
+++ b/Types.h
@@ -195,7 +195,7 @@ public:
Blob()
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] = 0;
}
@@ -203,7 +203,7 @@ public:
Blob ( int x )
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] = 0;
}
@@ -213,7 +213,7 @@ public:
Blob ( const Blob & k )
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] = k.bytes[i];
}
@@ -221,7 +221,7 @@ public:
Blob & operator = ( const Blob & k )
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] = k.bytes[i];
}
@@ -235,18 +235,18 @@ public:
set(&t,16);
}
- void set ( const void * blob, int len )
+ void set ( const void * blob, size_t len )
{
const uint8_t * k = (const uint8_t*)blob;
len = len > sizeof(bytes) ? sizeof(bytes) : len;
- for(int i = 0; i < len; i++)
+ for(size_t i = 0; i < len; i++)
{
bytes[i] = k[i];
}
- for(int i = len; i < sizeof(bytes); i++)
+ for(size_t i = len; i < sizeof(bytes); i++)
{
bytes[i] = 0;
}
@@ -267,7 +267,7 @@ public:
bool operator < ( const Blob & k ) const
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
if(bytes[i] < k.bytes[i]) return true;
if(bytes[i] > k.bytes[i]) return false;
@@ -278,7 +278,7 @@ public:
bool operator == ( const Blob & k ) const
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
if(bytes[i] != k.bytes[i]) return false;
}
@@ -298,7 +298,7 @@ public:
{
Blob t;
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
t.bytes[i] = bytes[i] ^ k.bytes[i];
}
@@ -308,7 +308,7 @@ public:
Blob & operator ^= ( const Blob & k )
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] ^= k.bytes[i];
}
@@ -323,7 +323,7 @@ public:
Blob & operator &= ( const Blob & k )
{
- for(int i = 0; i < sizeof(bytes); i++)
+ for(size_t i = 0; i < sizeof(bytes); i++)
{
bytes[i] &= k.bytes[i];
}
diff --git a/main.cpp b/main.cpp
index ffe04b3..03f3e42 100644
--- a/main.cpp
+++ b/main.cpp
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <time.h>
+#include <unistd.h>
//-----------------------------------------------------------------------------
// Configuration. TODO - move these to command-line flags
@@ -40,7 +41,7 @@ struct HashInfo
const char * desc;
};
-HashInfo g_hashes[] =
+HashInfo g_hashes[] =
{
{ DoNothingHash, 32, 0x00000000, "donothing32", "Do-Nothing function (only valid for measuring call overhead)" },
{ DoNothingHash, 64, 0x00000000, "donothing64", "Do-Nothing function (only valid for measuring call overhead)" },
@@ -56,7 +57,7 @@ HashInfo g_hashes[] =
{ SuperFastHash, 32, 0x980ACD1D, "superfast", "Paul Hsieh's SuperFastHash" },
{ MurmurOAAT_test, 32, 0x5363BD98, "MurmurOAAT", "Murmur one-at-a-time" },
{ Crap8_test, 32, 0x743E97A1, "Crap8", "Crap8" },
-
+
{ CityHash64_test, 64, 0x45754A6F, "City64", "Google CityHash128WithSeed" },
{ CityHash128_test, 128, 0x94B0EF46, "City128", "Google CityHash128WithSeed" },
@@ -75,9 +76,9 @@ HashInfo g_hashes[] =
};
-HashInfo * findHash ( const char * name )
+HashInfo * findHash ( const char * name )
{
- for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
+ for(size_t i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
{
if(_stricmp(name,g_hashes[i].name) == 0) return &g_hashes[i];
}
@@ -92,7 +93,7 @@ void SelfTest ( void )
{
bool pass = true;
- for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
+ for(size_t i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
{
HashInfo * info = & g_hashes[i];
@@ -103,10 +104,10 @@ void SelfTest ( void )
{
printf("Self-test FAILED!\n");
- for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
+ for(size_t i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
{
HashInfo * info = & g_hashes[i];
-
+
printf("%16s - ",info->name);
pass &= VerificationTest(info->hash,info->hashbits,info->verification,true);
}
@@ -192,7 +193,7 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
//-----------------------------------------------------------------------------
// Avalanche tests
-
+
if(g_testAvalanche || g_testAll)
{
printf("[[[ Avalanche Tests ]]]\n\n");
@@ -255,7 +256,7 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+2,8,10000000,drawDiagram);
result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+3,8,10000000,drawDiagram);
result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+4,8,10000000,drawDiagram);
-
+
if(!result) printf("*********FAIL*********\n");
printf("\n");
}
@@ -296,7 +297,7 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
result &= SparseKeyTest< 48,hashtype>(hash,5,true,true,true,drawDiagram);
result &= SparseKeyTest< 56,hashtype>(hash,5,true,true,true,drawDiagram);
result &= SparseKeyTest< 64,hashtype>(hash,5,true,true,true,drawDiagram);
- result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram);
+ result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram);
result &= SparseKeyTest< 256,hashtype>(hash,3,true,true,true,drawDiagram);
result &= SparseKeyTest<2048,hashtype>(hash,2,true,true,true,drawDiagram);
@@ -319,8 +320,8 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
uint32_t blocks[] =
{
- 0x00000000,
-
+ 0x00000000,
+
0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
};
@@ -338,8 +339,8 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
uint32_t blocks[] =
{
- 0x00000000,
-
+ 0x00000000,
+
0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000
};
@@ -357,8 +358,8 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
uint32_t blocks[] =
{
- 0x00000000,
-
+ 0x00000000,
+
0x80000000,
};
@@ -376,8 +377,8 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
uint32_t blocks[] =
{
- 0x00000000,
-
+ 0x00000000,
+
0x00000001,
};
@@ -395,8 +396,8 @@ void test ( hashfunc<hashtype> hash, HashInfo * info )
uint32_t blocks[] =
{
- 0x00000000,
-
+ 0x00000000,
+
0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
0x80000000, 0x40000000, 0xC0000000, 0x20000000, 0xA0000000, 0x60000000, 0xE0000000
@@ -495,9 +496,9 @@ void VerifyHash ( const void * key, int len, uint32_t seed, void * out )
{
g_inputVCode = MurmurOAAT(key,len,g_inputVCode);
g_inputVCode = MurmurOAAT(&seed,sizeof(uint32_t),g_inputVCode);
-
+
g_hashUnderTest->hash(key,len,seed,out);
-
+
g_outputVCode = MurmurOAAT(out,g_hashUnderTest->hashbits/8,g_outputVCode);
}
@@ -506,7 +507,7 @@ void VerifyHash ( const void * key, int len, uint32_t seed, void * out )
void testHash ( const char * name )
{
HashInfo * pInfo = findHash(name);
-
+
if(pInfo == NULL)
{
printf("Invalid hash '%s' specified\n",name);
@@ -552,7 +553,7 @@ int main ( int argc, char ** argv )
{
hashToTest = argv[1];
}
-
+
// Code runs on the 3rd CPU by default
SetAffinity((1 << 2));