Changeset 1278


Ignore:
Timestamp:
Aug 4, 2011, 4:30:07 PM (8 years ago)
Author:
vla24
Message:

refactored some code

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • proto/SymbolTable/README_SymbolTable

    r1232 r1278  
    1 STANDARD LIBRARY LENGTH SORTING
     1STANDARD LIBRARY SYMBOL TABLE
    22
    33A symbol table using STL C library.
  • proto/SymbolTable/symtab_pbgs_log_template.cpp

    r1270 r1278  
    22#define TEMPLATED_SIMD_LIB
    33
    4 //#define USE_MASK_COMPARE    //Comparison using masking technique.
     4#define USE_MASK_COMPARE    //Comparison using masking technique.
    55
    66#define DEBUG 0
     
    268268    strncpy ( symbol, source + start, lgth );
    269269    symbol[lgth] ='\0';
    270     printf ("%s | start: %i[%i] | end: %i[%i] | lgth: %i | hashvalue: %i | gid: %i | symbol: %s\n", __FUNCTION__, start, start - block_base, end, end - block_base, lgth, hashvalue, gid, symbol);
     270    printf ("%s | start: %i[%i] | lgth: %i | hashvalue: %i | gid: %i | symbol: %s\n", __FUNCTION__, start, start - block_base, lgth, hashvalue, gid, symbol);
    271271#endif
    272272    return 0;
  • trunk/lib/symtab/bitstream_hash_table.h

    r1270 r1278  
    186186        {
    187187#else
    188         if( equal_compare_4 ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
     188        if( equal_compare<uint16_t>((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
    189189        {
    190190#endif
     
    211211        printf ("Check symbol: %s\n", chain->key);
    212212#endif
    213         if( equal_compare_8 ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
     213        if( equal_compare<uint32_t> ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
    214214        {
    215215#if DEBUG_BHT
     
    235235        printf ("Check symbol: %s\n", chain->key);
    236236#endif
    237         if( equal_compare_16 ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
     237        if( equal_compare<uint64_t> ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
    238238        {
    239239#if DEBUG_BHT
     
    261261        printf ("Check symbol: %s\n", chain->key);
    262262#endif
    263         if( equal_compare_32 ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
     263        if( equal_compare<SIMD_type> ((unsigned char*)chain->key, (unsigned char*)name, chain->lgth, L) )
    264264        {
    265265#if DEBUG_BHT
  • trunk/lib/symtab/equal_compare.h

    r1229 r1278  
    2424// Equivalent symbol-at-a-time comparison methods implemented using C++ function templates.     
    2525
     26template<class T>
     27inline bool equal_compare(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, int symbol_lgth);
    2628
    2729#if defined (USE_IDENTITY_SORT) || defined (USE_DIV_SORT)
     
    7173inline bool equal_compare_4(const unsigned char * key, const unsigned char * symbol, int symbol_lgth) {
    7274    return ((* ((uint32_t *) key)) ==
    73             ((* ((uint32_t *) symbol)) & ((0xFFFFFF | (3-symbol_lgth)) << ((4-symbol_lgth) * LOW_BYTE_SHIFT)) )); // s4int32()
     75            ((* ((uint32_t *) symbol)) & ((0xFFFFFF | (3-symbol_lgth)) << ((4-symbol_lgth) * LOW_BYTE_SHIFT)) ));
    7476}
     77#endif //USE_MASK_COMPARE
    7578
    76 #else
    77 
    78 inline bool equal_compare_4(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, int symbol_lgth) {
     79template<class T>
     80inline bool equal_compare(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, int symbol_lgth)
     81{
    7982#if DEBUG_EQUAL_COMPARE
    80     uint16_t* s1 = (uint16_t*) symbol;
    81     uint16_t* k1 = (uint16_t*) key;
    82     uint16_t* s2 = (uint16_t*) (symbol + symbol_lgth - 2);
    83     uint16_t* k2 = (uint16_t*) (key + key_lgth - 2);
    84 
    85     print_general_register_32("key",*((uint32_t*)key));
    86     print_general_register_32("symbol",*((uint32_t*)symbol));
    87     print_general_register_32("s1",*((uint32_t*)s1));
    88     print_general_register_32("k1",*((uint32_t*)k1));
    89     print_general_register_32("s2",*((uint32_t*)s2));
    90     print_general_register_32("k2",*((uint32_t*)k2));
     83    int constant = sizeof(T);
     84    T* s1 = (T*) symbol;
     85    T* k1 = (T*) key;
     86    T* s2 = (T*) (symbol + symbol_lgth - constant);
     87    T* k2 = (T*) (key + key_lgth - constant);
    9188
    9289    return !((*s1 ^ *k1) | (*s2 ^ *k2));
    9390#else
    94     return !((*((uint16_t*) symbol) ^ *((uint16_t*) key)) |
    95              (*((uint16_t*) (symbol + symbol_lgth - 2)) ^ *((uint16_t*) (key + key_lgth - 2))));
    96 #endif
    97 }
    98 
    99 #endif //USE_MASK_COMPARE
    100 
    101 inline bool equal_compare_8(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, const unsigned int symbol_lgth) {
    102 #if DEBUG_EQUAL_COMPARE
    103     uint32_t* s1 = (uint32_t*) symbol;
    104     uint32_t* k1 = (uint32_t*) key;
    105     uint32_t* s2 = (uint32_t*) (symbol + symbol_lgth - 4);
    106     uint32_t* k2 = (uint32_t*) (key + key_lgth - 4);
    107 
    108     print_general_register_64("key",*((uint64_t*)key));
    109     print_general_register_64("symbol",*((uint64_t*)symbol));
    110     print_general_register_32("s1",*s1);
    111     print_general_register_32("k1",*k1);
    112     print_general_register_32("s2",*s2);
    113     print_general_register_32("k2",*k2);
    114 
    115     return !((*s1 ^ *k1) | (*s2 ^ *k2));
    116 #else
    117     return !((*((uint32_t*) symbol) ^ *((uint32_t*) key)) |
    118              (*((uint32_t*) (symbol + symbol_lgth - 4)) ^ *((uint32_t*) (key + key_lgth - 4))));
    119 #endif
    120 
    121 }
    122 
    123 inline bool equal_compare_16(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, int symbol_lgth) {
    124 #if DEBUG_EQUAL_COMPARE
    125     uint64_t* s1 = (uint64_t*) symbol;
    126     uint64_t* k1 = (uint64_t*) key;
    127     uint64_t* s2 = (uint64_t*) (symbol + symbol_lgth - 8);
    128     uint64_t* k2 = (uint64_t*) (key + key_lgth - 8);
    129 
    130     print_general_register_64("s1",*s1);
    131     print_general_register_64("k1",*k1);
    132     print_general_register_64("s2",*s2);
    133     print_general_register_64("k2",*k2);
    134 
    135     return !((*s1 ^ *k1) | (*s2 ^ *k2));
    136 #else
    137     return !((*((uint64_t*) symbol) ^ *((uint64_t*) key)) |
    138              (*((uint64_t*) (symbol + symbol_lgth - 8)) ^ *((uint64_t*) (key + key_lgth - 8))));
     91    return !((*((T*) symbol) ^ *((T*) key)) |
     92             (*((T*) (symbol + symbol_lgth - sizeof(T))) ^ *((T*) (key + key_lgth - sizeof(T)))));
    13993#endif
    14094}
     
    14296#endif //#if defined (USE_LOG_SORT) && !defined (USE_TEMPLATE)
    14397
    144 inline bool equal_compare_32(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, const unsigned int symbol_lgth) {
     98template<>
     99inline bool equal_compare<SIMD_type>(const unsigned char * key, const unsigned char * symbol, const unsigned int key_lgth, int symbol_lgth) {
    145100#if DEBUG_EQUAL_COMPARE
    146101    SIMD_type* s1 = (SIMD_type*) symbol;
  • trunk/lib/symtab/pbgs_log_symbol_table.h

    r1229 r1278  
    138138        GID = m_globalNameCount;
    139139
     140        char* c = m_pool.Insert(name, length);
    140141#ifdef USE_MASK_COMPARE
    141         char* c = m_pool.Insert(name, length, 4-length);
    142142        m_hashTable[2].Insert_Name(c, hashvalue, m_globalNameCount);
    143143#else
    144         char* c = m_pool.Insert(name, length);
    145144        m_hashTable[2].Insert_Name(c, hashvalue, m_globalNameCount, length);
    146145#endif
Note: See TracChangeset for help on using the changeset viewer.