Changeset 1919 for trunk/lib/hash.hpp
 Timestamp:
 Feb 11, 2012, 12:01:17 AM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/hash.hpp
r1918 r1919 11 11 Internal static casts of uint8_t * b0 to uint64_t * and deference. */ 12 12 13 static uint32_t bytes2bits(uint32_t bit) { return bit * 8; } 13 14 14 15 static IDISA_ALWAYS_INLINE uint64_t gen_mask(const uint32_t hash_size); 15 static IDISA_ALWAYS_INLINE uint64_t byte_mask_hash(const uint8_t *b0, const uint32_t pos, const uint32_t hash_size);16 //static IDISA_ALWAYS_INLINE uint64_t byte_mask_hash(const uint8_t *b0, const uint32_t pos, const uint32_t hash_size); 16 17 17 18 /* pos (bits) */ 18 19 static IDISA_ALWAYS_INLINE uint64_t bit_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_size); 19 static IDISA_ALWAYS_INLINE uint64_t bit_compress_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size); 20 /* pos (bytes) */ 21 //static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_size); 20 22 21 /* pos (bytes) */ 22 static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_size); 23 static IDISA_ALWAYS_INLINE uint64_t byte_compress_hash(const uint8_t * b0, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size); 23 /* pos (bits) */ 24 static IDISA_ALWAYS_INLINE uint64_t compress_hash(const uint8_t * b0, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size); 24 25 25 26 static IDISA_ALWAYS_INLINE uint64_t gen_mask(const uint32_t hash_size) { … … 34 35 } 35 36 36 static IDISA_ALWAYS_INLINE uint64_t byte_mask_hash(const uint8_t *b0, const uint32_t pos, const uint32_t hash_size) {37 uint64_t mask = gen_mask(hash_size);38 return *((uint64_t *)(b0 + pos)) & mask;39 }37 //static IDISA_ALWAYS_INLINE uint64_t byte_mask_hash(const uint8_t *b0, const uint32_t pos, const uint32_t hash_size) { 38 // uint64_t mask = gen_mask(hash_size); 39 // return *((uint64_t *)(b0 + pos)) & mask; 40 //} 40 41 41 42 /* pos (bits) */ … … 56 57 57 58 /* pos (bytes) */ 59 /* 58 60 static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_size) { 59 61 assert(slice_size > 0 && slice_size <= 64); … … 69 71 return r; 70 72 } 73 */ 71 74 72 static IDISA_ALWAYS_INLINE uint64_t bit_compress_hash(const uint8_t * b0, const uint8_t * b1, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size) {73 assert(slice_size > 0 && slice_size <= 64);74 assert(slice_size >= hash_size); /* negative shifts undefined in C standard, (x1 >> shift) */75 static IDISA_ALWAYS_INLINE uint64_t compress_hash(const uint8_t * b0, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size) { 76 //assert(slice_size > 0 && slice_size <= 64); 77 //assert(slice_size >= hash_size); // negative shifts undefined in C standard 75 78 76 #ifndef NDEBUG 77 cout << endl; 78 cout << "Stream pos (bit): " << pos << endl; 79 cout << "Slice size (bits): " << slice_size << endl; 80 cout << "Hash size (bits): " << hash_size << endl; 81 #endif 82 83 uint64_t x0 = bit_offset_slice(b0,pos,slice_size); 84 uint64_t x1 = bit_offset_slice(b1,pos,slice_size); 85 uint64_t shift = (slice_size  hash_size); 86 uint64_t mask = gen_mask(hash_size); 87 uint64_t r = (x0 ^ (x1 >> shift)) & mask; 88 89 #ifndef NDEBUG 90 print_register<uint64_t>("b0", *(uint64_t *)b0); 91 print_register<uint64_t>("b1", *(uint64_t *)b1); 92 print_register<uint64_t>("x0", x0); 93 print_register<uint64_t>("x1", x1); 94 print_register<uint64_t>("shift x1", (x1 >> shift)); 95 print_register<uint64_t>("r", r); 96 #endif 97 98 return r; 99 } 100 101 static IDISA_ALWAYS_INLINE uint64_t byte_compress_hash(const uint8_t * b0, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size) { 102 assert(slice_size > 0 && slice_size <= 64); 103 assert(slice_size >= hash_size); // negative shifts undefined in C standard 79 assert(hash_size > 0 && hash_size <= 64); 80 assert(slice_size >= hash_size); 104 81 105 82 #ifndef NDEBUG … … 110 87 #endif 111 88 112 uint64_t x0 = *((uint64_t *)(b0+pos)); 113 uint64_t shift = (slice_size  hash_size); // negative shifts undefined in C standard 89 uint64_t x0 = bit_offset_slice(b0,pos,hash_size); 90 uint64_t x1 = bit_offset_slice(b0,pos+slice_sizehash_size,hash_size); 91 92 //uint64_t x0 = //*((uint64_t *)(b0+pos)); 93 //uint64_t shift = (slice_size  hash_size); // negative shifts undefined in C standard 114 94 uint64_t mask = gen_mask(hash_size); 115 uint64_t r = (x0 ^ (x0 >> shift)) & mask;95 uint64_t r = (x0 ^ x1) & mask; 116 96 117 97 #ifndef NDEBUG 118 98 print_register<uint64_t>("b0", *(uint64_t *)(b0)); 119 99 print_register<uint64_t>("x0", x0); 120 print_register<uint64_t>("x0 >> shift", x0>>shift); 100 //print_register<uint64_t>("x0 >> shift", x0>>shift); 101 print_register<uint64_t>("x1", x1); 121 102 print_register<uint64_t>("r", r); 122 103 #endif
Note: See TracChangeset
for help on using the changeset viewer.