From 557c63a0f3341a43d62932e98459b65efd1e91b5 Mon Sep 17 00:00:00 2001 From: Sears Russell Date: Thu, 6 Oct 2011 17:11:22 +0000 Subject: [PATCH] remove duplicated implementations of log2 --- src/stasis/CMakeLists.txt | 1 - src/stasis/util/hash.c | 91 --------------------------------------- stasis/util/hash.h | 4 +- stasis/util/log2.h | 13 +++++- 4 files changed, 13 insertions(+), 96 deletions(-) delete mode 100644 src/stasis/util/hash.c diff --git a/src/stasis/CMakeLists.txt b/src/stasis/CMakeLists.txt index ef868aa..c39879b 100644 --- a/src/stasis/CMakeLists.txt +++ b/src/stasis/CMakeLists.txt @@ -5,7 +5,6 @@ ADD_LIBRARY(stasis util/crc32.c util/rw.c util/doubleLinkedList.c util/linkedlist.c - util/hash.c util/log2.c util/histogram.c util/hashFunctions.c diff --git a/src/stasis/util/hash.c b/src/stasis/util/hash.c deleted file mode 100644 index 07e4b41..0000000 --- a/src/stasis/util/hash.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -//#include -/** - @todo Make hash.c 32/64bit little/big-endian clean... - - @file Hash functions for stasis' in memory and persistent hash tables. -*/ - -#ifdef THOMAS_WANG_32 -static inline int thomasWangs32BitMixFunction(int key) -{ - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - return key; -} -#else -#ifdef THOMAS_WANG_64 - -static inline unsigned long thomasWangs64BitMixFunction(unsigned long key) -{ - key += ~(key << 32L); - key ^= (key >> 22L); - key += ~(key << 13L); - key ^= (key >> 8L); - key += (key << 3L); - key ^= (key >> 15L); - key += ~(key << 27L); - key ^= (key >> 31L); - return key; -} - -#endif -#endif - -static const char LogTable256[] = -{ - 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 -}; - -/*Taken from - http://graphics.stanford.edu/~seander/bithacks.html - - @todo extend to handle unsigned long (this will mean 64bit on 64bit - platforms; need compiler macro to test for sizeof(long), test - harness to compare logBase2Slow's output with logBase2's output, - etc...) -*/ -uint32_t logBase2(uint64_t v) { - uint32_t r = 0; // r will be lg(v) - uint32_t t, tt; // temporaries - - if ((tt = v >> 16)) - { - r = (t = v >> 24) ? 24 + LogTable256[t] : 16 + LogTable256[tt & 0xFF]; - } - else - { - r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v]; - } - return r; -} - -uint32_t logBase2Slow(uint64_t v) { - uint32_t r = 0; // r will be lg(v) - - while (v >>= 1) // unroll for more speed... - { - r++; - } - return r; -} diff --git a/stasis/util/hash.h b/stasis/util/hash.h index 3ef2125..a75296b 100644 --- a/stasis/util/hash.h +++ b/stasis/util/hash.h @@ -1,5 +1,6 @@ #include +#include #include #ifndef __HASH_H @@ -13,7 +14,6 @@ static inline unsigned long stasis_util_two_to_the (char x) { return (1 << ((long)x)); } -uint32_t logBase2(uint64_t value); /** This function maps from the length of the bucket list to a appropriate set @@ -21,7 +21,7 @@ uint32_t logBase2(uint64_t value); */ static inline void HASH_ENTRY(_get_size_params)(uint64_t desiredSize, unsigned char * tableBits, uint64_t* nextExtension) { - *tableBits = logBase2(desiredSize)+1; + *tableBits = stasis_log_2_64(desiredSize)+1; *nextExtension = ((desiredSize) - stasis_util_two_to_the(*tableBits-1)); } diff --git a/stasis/util/log2.h b/stasis/util/log2.h index 50713d4..920e455 100644 --- a/stasis/util/log2.h +++ b/stasis/util/log2.h @@ -21,6 +21,15 @@ extern const uint8_t LogTable256[256]; +/*Taken from + http://graphics.stanford.edu/~seander/bithacks.html + + @todo extend to handle unsigned long (this will mean 64bit on 64bit + platforms; need compiler macro to test for sizeof(long), test + harness to compare logBase2Slow's output with logBase2's output, + etc...) +*/ + /** * @param v 32-bit word to find the log of * @return lg_2(v) @@ -31,11 +40,11 @@ static inline uint8_t stasis_log_2_32(uint32_t v) { if ((tt = v >> 16)) { - r = (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt]; + r = ((t = tt >> 8)) ? 24 + LogTable256[t] : 16 + LogTable256[tt]; } else { - r = (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v]; + r = ((t = v >> 8)) ? 8 + LogTable256[t] : LogTable256[v]; } return r; }