Changeset 1914 for trunk


Ignore:
Timestamp:
Feb 8, 2012, 5:10:09 PM (7 years ago)
Author:
ksherdy
Message:

Added mask_hash function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/hash_util.hpp

    r1912 r1914  
    88using namespace std;
    99
    10 /*
     10/*  Hash Functions Templated on Field Width.
     11
    1112    slice<1> - bit slice operation
    1213    FW=1 'pos' and 'lgth' args in terms of bits,
     
    2324/* WARNING: Casts uint8_t * buffer at pos to uint64_t * and deferences. Segmentation faults w/o sufficient buffer padding.  */
    2425template<uint32_t FW>
     26IDISA_ALWAYS_INLINE uint64_t mask_hash(const uint8_t * b0, const uint32_t hash_bits, const uint32_t lgth);
     27
     28template<uint32_t FW>
    2529IDISA_ALWAYS_INLINE uint64_t slice(const uint8_t * buffer, const uint32_t pos, const uint32_t lgth);
    2630
    2731template<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);
     32IDISA_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);
    2933
    3034template<>
     
    5458}
    5559
    56 /* WARNING: Length of Symbol Bits >= Length of Hash Bits.  */
    5760template<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) {
     61IDISA_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);
    5964
     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
     73template<uint32_t FW>
     74IDISA_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) {
    6075    assert(lgth > 0 && lgth*FW <= 64);
    61     assert((lgth*FW) >= hash_bits);
     76    assert((lgth*FW) > hash_bits);
    6277
    6378    uint64_t x0 = slice<FW>(b0,pos,lgth);
    6479    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;
    6682
    6783#ifndef NDEBUG
     
    7288    uint64_t masked_x0 = x0 & mask;
    7389    uint64_t shift_masked_x1 = (x1 >> ((lgth*FW) - hash_bits)) & mask;
    74 
    7590    print_register<uint64_t>("b0", *(uint64_t *)b0);
    7691    print_register<uint64_t>("b1", *(uint64_t *)b1);
     
    85100}
    86101
    87 xor_hash();
    88 xor
     102
     103
    89104
    90105#endif // BYTE_UTIL_HPP
Note: See TracChangeset for help on using the changeset viewer.