Changeset 1936 for trunk/lib/hash.hpp
 Timestamp:
 Feb 16, 2012, 8:56:53 PM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/hash.hpp
r1919 r1936 9 9 10 10 /* WARNING: Pad 8 bytes. 11 Internal static casts of uint8_t * b 0to uint64_t * and deference. */11 Internal static casts of uint8_t * base to uint64_t * and deference. */ 12 12 13 static uint32_t bytes2bits(uint32_t bit) { return bit* 8; }13 static int32_t bytes2bits(int32_t bits) { return bits * 8; } 14 14 15 15 static IDISA_ALWAYS_INLINE uint64_t gen_mask(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);17 16 18 /* pos (bits) */ 19 static IDISA_ALWAYS_INLINE uint64_t bit_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_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); 17 /* offset (bits) */ 18 static IDISA_ALWAYS_INLINE uint64_t bit_offset_slice(const uint8_t * base, const int32_t offset, const uint32_t slice_size); 22 19 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); 20 /* offset (bytes) */ 21 //static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * base, const int32_t offset, const uint32_t slice_size); 22 23 /* offset (bits) */ 24 static IDISA_ALWAYS_INLINE uint64_t compress_hash(const uint8_t * base, const int32_t offset, const uint32_t slice_size, const uint32_t hash_size); 25 25 26 26 static IDISA_ALWAYS_INLINE uint64_t gen_mask(const uint32_t hash_size) { … … 35 35 } 36 36 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 //} 37 /* offset (bits) */ 38 static IDISA_ALWAYS_INLINE uint64_t bit_offset_slice(const uint8_t * base, const int32_t offset, const uint32_t slice_size) { 39 assert(slice_size > 0 && slice_size <= 64); 40 assert(offset & (81) >= 0); // negative shifts undefined in C standard 41 41 42 /* pos (bits) */ 43 static IDISA_ALWAYS_INLINE uint64_t bit_offset_slice(const uint8_t * buffer, const uint32_t pos, const uint32_t slice_size) { 44 assert(slice_size > 0 && slice_size <= 64); 45 46 uint64_t shift = *((uint64_t *)(buffer + (pos/8))) >> (pos & 81); 42 uint64_t shift = *((uint64_t *)(base + (offset/8))) >> (offset & (81)); 47 43 uint64_t mask = gen_mask(slice_size); 48 44 uint64_t r = shift & mask; … … 56 52 } 57 53 58 /* pos (bytes) */ 54 static IDISA_ALWAYS_INLINE uint64_t compress_hash(const uint8_t * base, const int32_t offset, const uint32_t slice_size, const uint32_t hash_size) { 55 //assert(slice_size > 0 && slice_size <= 64); 56 //assert(slice_size >= hash_size); // negative shifts undefined in C standard 57 58 assert(hash_size > 0 && hash_size <= 64); 59 assert(slice_size >= hash_size); 60 61 #ifndef NDEBUG 62 cout << endl; 63 cout << "Stream offset (byte): " << offset << endl; 64 cout << "Slice size (bits): " << slice_size << endl; 65 cout << "Hash size (bits): " << hash_size << endl; 66 #endif 67 68 uint64_t x0 = bit_offset_slice(base,offset,hash_size); 69 uint64_t x1 = bit_offset_slice(base,offset+slice_sizehash_size,hash_size); 70 71 //uint64_t x0 = //*((uint64_t *)(base+offset)); 72 //uint64_t shift = (slice_size  hash_size); // negative shifts undefined in C standard 73 uint64_t mask = gen_mask(hash_size); 74 uint64_t r = (x0 ^ x1) & mask; 75 76 #ifndef NDEBUG 77 print_register<uint64_t>("base", *(uint64_t *)(base)); 78 print_register<uint64_t>("x0", x0); 79 //print_register<uint64_t>("x0 >> shift", x0>>shift); 80 print_register<uint64_t>("x1", x1); 81 print_register<uint64_t>("r", r); 82 #endif 83 84 return r; 85 } 86 87 #endif // BYTE_UTIL_HPP 88 89 /* offset (bytes) */ 59 90 /* 60 static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * b uffer, const uint32_t pos, const uint32_t slice_size) {91 static IDISA_ALWAYS_INLINE uint64_t byte_offset_slice(const uint8_t * base, const int32_t offset, const uint32_t slice_size) { 61 92 assert(slice_size > 0 && slice_size <= 64); 62 93 63 uint64_t shift = *((uint64_t *)(b uffer+pos));94 uint64_t shift = *((uint64_t *)(base+offset)); 64 95 uint64_t mask = gen_mask(slice_size); 65 96 uint64_t r = shift & mask; … … 73 104 */ 74 105 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 standard78 79 assert(hash_size > 0 && hash_size <= 64);80 assert(slice_size >= hash_size);81 82 #ifndef NDEBUG83 cout << endl;84 cout << "Stream pos (byte): " << pos << endl;85 cout << "Slice size (bits): " << slice_size << endl;86 cout << "Hash size (bits): " << hash_size << endl;87 #endif88 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 standard94 uint64_t mask = gen_mask(hash_size);95 uint64_t r = (x0 ^ x1) & mask;96 97 #ifndef NDEBUG98 print_register<uint64_t>("b0", *(uint64_t *)(b0));99 print_register<uint64_t>("x0", x0);100 //print_register<uint64_t>("x0 >> shift", x0>>shift);101 print_register<uint64_t>("x1", x1);102 print_register<uint64_t>("r", r);103 #endif104 105 return r;106 }107 108 #endif // BYTE_UTIL_HPP109 110 106 /* 111 static IDISA_ALWAYS_INLINE uint64_t bit_expand_hash(const uint8_t * b 0, const uint8_t * b1, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size);112 static IDISA_ALWAYS_INLINE uint64_t bit_expand_hash(const uint8_t * b 0, const uint8_t * b1, const uint32_t pos, const uint32_t slice_size, const uint32_t hash_size) {107 static IDISA_ALWAYS_INLINE uint64_t bit_expand_hash(const uint8_t * base, const uint8_t * base1, const int32_t offset, const uint32_t slice_size, const uint32_t hash_size); 108 static IDISA_ALWAYS_INLINE uint64_t bit_expand_hash(const uint8_t * base, const uint8_t * base1, const int32_t offset, const uint32_t slice_size, const uint32_t hash_size) { 113 109 assert(slice_size > 0 && slice_size <= 64); 114 110 //assert(slice_size <= hash_size); 115 111 116 uint64_t x0 = bit_offset_slice(b 0,pos,slice_size);117 uint64_t x1 = bit_offset_slice(b 1,pos,slice_size);112 uint64_t x0 = bit_offset_slice(base,offset,slice_size); 113 uint64_t x1 = bit_offset_slice(base1,offset,slice_size); 118 114 uint64_t mask = gen_mask(hash_size); 119 115 … … 130 126 131 127 #ifndef NDEBUG 132 cout << "Stream pos (bit): " << pos<< endl;128 cout << "Stream offset (bit): " << offset << endl; 133 129 cout << "Symbol lgth (bits): " << slice_size << endl; 134 130 cout << "Hash size (bits): " << hash_size << endl; 135 131 cout << "Shift (bits): " << shift << endl; 136 132 137 print_register<uint64_t>("b 0", *(uint64_t *)b0);138 print_register<uint64_t>("b 1", *(uint64_t *)b1);133 print_register<uint64_t>("base", *(uint64_t *)base); 134 print_register<uint64_t>("base1", *(uint64_t *)base1); 139 135 print_register<uint64_t>("x0", x0); 140 136 print_register<uint64_t>("x1", x1);
Note: See TracChangeset
for help on using the changeset viewer.