Changeset 1919
 Timestamp:
 Feb 11, 2012, 12:01:17 AM (7 years ago)
 Location:
 trunk/lib
 Files:

 2 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 
trunk/lib/test/hash_test.cpp
r1918 r1919 101 101 */ 102 102 103 /*104 for(uint32_t mask_bits=1;mask_bits<64;mask_bits++) {105 r = byte_mask_hash((uint8_t *) &b0, 0, mask_bits);106 print_register("r", r);107 }108 */109 110 // Length 8 (bits)111 /*112 hash_size = 8;113 for(uint32_t pos=0;pos<sizeof(uint64_t);pos++) {114 115 r = bit_compress_hash((uint8_t *) &b0,(uint8_t *) &b2, pos*8, 8, hash_size);116 cout << dec << "bit_compress_hash = " << r << endl << endl;117 cout << endl << endl;118 119 }120 */121 122 /*123 103 uint8_t pos, slice; 124 104 hash_size = 8; … … 126 106 slice = 16; 127 107 pos = 0; 128 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);108 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 129 109 130 110 pos = 1; 131 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);111 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 132 112 133 113 slice = 24; 134 114 pos = 0; 135 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);115 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 136 116 137 117 pos = 1; 138 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);118 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 139 119 140 120 slice = 32; 141 121 142 122 pos = 0; 143 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);123 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 144 124 145 125 pos = 1; 146 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size);126 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 147 127 148 128 pos = 2; 149 r = byte_compress_hash((uint8_t *) &b0, pos, slice, hash_size); 150 */ 129 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 130 131 pos = 0; 132 slice = 8*10; 133 hash_size = 16; 134 r = compress_hash((uint8_t *) &b0, pos, slice, hash_size); 135 151 136 152 137 return 1;
Note: See TracChangeset
for help on using the changeset viewer.