Changeset 1914
 Timestamp:
 Feb 8, 2012, 5:10:09 PM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/hash_util.hpp
r1912 r1914 8 8 using namespace std; 9 9 10 /* 10 /* Hash Functions Templated on Field Width. 11 11 12 slice<1>  bit slice operation 12 13 FW=1 'pos' and 'lgth' args in terms of bits, … … 23 24 /* WARNING: Casts uint8_t * buffer at pos to uint64_t * and deferences. Segmentation faults w/o sufficient buffer padding. */ 24 25 template<uint32_t FW> 26 IDISA_ALWAYS_INLINE uint64_t mask_hash(const uint8_t * b0, const uint32_t hash_bits, const uint32_t lgth); 27 28 template<uint32_t FW> 25 29 IDISA_ALWAYS_INLINE uint64_t slice(const uint8_t * buffer, const uint32_t pos, const uint32_t lgth); 26 30 27 31 template<uint32_t FW> 28 IDISA_ALWAYS_INLINE uint64_t shift_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t lgth, const uint32_t hash_bits);32 IDISA_ALWAYS_INLINE uint64_t shift_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t hash_bits, const uint32_t lgth); 29 33 30 34 template<> … … 54 58 } 55 59 56 /* WARNING: Length of Symbol Bits >= Length of Hash Bits. */57 60 template<uint32_t FW> 58 IDISA_ALWAYS_INLINE uint64_t shift_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t lgth, const uint32_t hash_bits) { 61 IDISA_ALWAYS_INLINE uint64_t mask_hash(const uint8_t * b0, const uint32_t hash_bits, const uint32_t lgth) { 62 assert(lgth > 0 && lgth*FW <= 64); 63 assert((lgth*FW) > hash_bits); 59 64 65 const uint64_t ONE = 1; 66 uint64_t mask = (ONE << hash_bits)  ONE; 67 #ifndef NDEBUG 68 print_register<uint64_t>("mask", mask); 69 #endif 70 return *((uint64_t *)b0) & mask; 71 } 72 73 template<uint32_t FW> 74 IDISA_ALWAYS_INLINE uint64_t shift_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t hash_bits, const uint32_t lgth) { 60 75 assert(lgth > 0 && lgth*FW <= 64); 61 assert((lgth*FW) > =hash_bits);76 assert((lgth*FW) > hash_bits); 62 77 63 78 uint64_t x0 = slice<FW>(b0,pos,lgth); 64 79 uint64_t x1 = slice<FW>(b1,pos,lgth); 65 uint64_t mask = (1 << hash_bits)  1; 80 const uint64_t ONE = 1; 81 uint64_t mask = (ONE << hash_bits)  ONE; 66 82 67 83 #ifndef NDEBUG … … 72 88 uint64_t masked_x0 = x0 & mask; 73 89 uint64_t shift_masked_x1 = (x1 >> ((lgth*FW)  hash_bits)) & mask; 74 75 90 print_register<uint64_t>("b0", *(uint64_t *)b0); 76 91 print_register<uint64_t>("b1", *(uint64_t *)b1); … … 85 100 } 86 101 87 xor_hash(); 88 xor 102 103 89 104 90 105 #endif // BYTE_UTIL_HPP
Note: See TracChangeset
for help on using the changeset viewer.