Changeset 1462


Ignore:
Timestamp:
Sep 21, 2011, 5:32:22 PM (8 years ago)
Author:
vla24
Message:

SymbolTable?: refactored symtab library

Location:
trunk/lib/symtab
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/symtab/Makefile

    r1427 r1462  
    22SSE=-msse2 #-mssse3 #-msse4.2
    33CFLAGS= $(SSE) -O3
    4 SRCFILE=ls_symbol_table.cxx hash_symbol_table.cpp symtab.cxx
     4SRCFILE=ls_symbol_table.cxx hash_symbol_table.cpp symtab.cxx bitstream_hash_table.cpp
    55INCLUDES_IDISA = -I../../../../trunk/libgen/idisa_lib/
    66
  • trunk/lib/symtab/bitstream_hash_table.h

    r1391 r1462  
    2323#define TABLE_SIZE_MASK TABLE_SIZE-1
    2424
    25 #include <stdlib.h>
    26 #include "pbgs_utilities.h"
    27 #include "ls_symbol_table_util.h"
    28 
    29 
    3025class BitStreamHashTable
    3126{
     
    3631
    3732    // Symbol length > 16
    38     inline unsigned int Lookup_Name_17(char * name, const int hashvalue, int L);
     33    unsigned int Lookup_Name_17(char * name, const int hashvalue, int L);
    3934
    40     inline void Insert_Name(char * name, const int hashvalue, const unsigned int gid);
    41     inline void Insert_Name(char * name, const int hashvalue, const unsigned int gid, const unsigned int lgth);
     35    void Insert_Name(char * name, const int hashvalue, const unsigned int gid);
     36    void Insert_Name(char * name, const int hashvalue, const unsigned int gid, const unsigned int lgth);
    4237
    4338    // DEBUG FUNCTIONS
     
    5752private:
    5853    void free_chain(CHAIN* chain);
    59     inline void SetTableSize(unsigned int table_bits, unsigned int table_bits_factor);
    60     inline unsigned int NextLog2(unsigned int x);
    6154};
    62 
    63 BitStreamHashTable::BitStreamHashTable()
    64 {
    65     g_table = (CHAIN**) calloc(TABLE_SIZE, sizeof(CHAIN*));
    66     memset(g_table, 0, TABLE_SIZE*sizeof(CHAIN*));
    67 }
    68 
    69 BitStreamHashTable::~BitStreamHashTable()
    70 {
    71     for(int hash = 0; hash < TABLE_SIZE; hash++)
    72     {
    73         free_chain(g_table[hash]);
    74     }
    75     free(g_table);
    76 }
    77 
    78 // Use this method if L > 16
    79 unsigned int BitStreamHashTable::Lookup_Name_17(char * name, const int hashvalue, int L)
    80 {
    81     unsigned int hash = getIndex(hashvalue);
    82 
    83     // Look up the value in the chain
    84     for(CHAIN* chain = g_table[hash]; chain != NULL; chain = chain->next) {
    85 #if DEBUG_BHT
    86         printf ("Check symbol: %s\n", chain->key);
    87 #endif
    88         if( simd_compare ((unsigned char*)chain->key, (unsigned char*)name, L) )
    89         {
    90 #if DEBUG_BHT
    91             printf ("Found GID: %i\n", chain->GID);
    92 #endif
    93             return chain->GID;
    94         }
    95     }
    96 
    97 #if DEBUG_BHT
    98     printf ("Not Found GID: %i\n", 0);
    99 #endif
    100     return 0;
    101 }
    102 
    103 inline void BitStreamHashTable::Insert_Name(char * name, const int hashvalue, const unsigned int gid)
    104 {
    105     unsigned int hash = getIndex(hashvalue);
    106 
    107     // If it was not found, add it
    108     CHAIN* next = g_table[hash];
    109     g_table[hash] = (CHAIN*) malloc(sizeof(CHAIN*));
    110     g_table[hash]->next = next;
    111     g_table[hash]->key = name;
    112     g_table[hash]->GID = gid;
    113 
    114 #if DEBUG_BHT
    115     printf ("Given GID: %i | Stored GID: %i\n", gid, g_table[hash]->GID);
    116 #endif
    117 }
    118 
    119 inline void BitStreamHashTable::Insert_Name(char * name, const int hashvalue, const unsigned int gid, const unsigned int lgth)
    120 {
    121     unsigned int hash = getIndex(hashvalue);
    122 
    123     // If it was not found, add it
    124     CHAIN* next = g_table[hash];
    125     g_table[hash] = (CHAIN*) malloc(sizeof(CHAIN*));
    126     g_table[hash]->next = next;
    127     g_table[hash]->key = name;
    128     g_table[hash]->GID = gid;
    129     g_table[hash]->lgth = lgth;
    130 
    131 #if DEBUG_BHT
    132     printf ("Given GID: %i | Stored GID: %i\n", gid, g_table[hash]->GID);
    133 #endif
    134 }
    13555
    13656inline unsigned int BitStreamHashTable::getIndex(const int hashvalue)
     
    13959}
    14060
    141 inline unsigned int BitStreamHashTable::NextLog2(unsigned int x)
    142 {
    143     // Henry Warren, "Hacker's Delight", ch. 5.3
    144     if(x <= 1) return x;
    145     x--;
    146     unsigned int n = 0;
    147     unsigned int y;
    148     y = x >>16; if(y) {n += 16; x = y;}
    149     y = x >> 8; if(y) {n +=  8; x = y;}
    150     y = x >> 4; if(y) {n +=  4; x = y;}
    151     y = x >> 2; if(y) {n +=  2; x = y;}
    152     y = x >> 1; if(y) return n + 2;
    153     return n + x;
    154 }
    155 
    156 void BitStreamHashTable::Print_Symbol_Table_Distribution()
    157 {
    158     for(int hash = 0; hash < TABLE_SIZE; hash++)
    159     {
    160         int items = 0;
    161         for(CHAIN* chain = g_table[hash]; chain != NULL; chain = chain->next)
    162         {
    163             items++;
    164         }
    165         if (items >= 1)
    166         {
    167             fprintf (stderr, "\tBucket: %i | #items: %i\n", hash, items);
    168         }
    169     }
    170 }
    171 
    172 void BitStreamHashTable::free_chain(CHAIN* chain)
    173 {
    174     if (chain == NULL)
    175     {
    176         return;
    177     }
    178 
    179     if (chain->next != NULL)
    180     {
    181         free_chain(chain->next);
    182     }
    183     free(chain);
    184     chain = NULL;
    185 }
    186 
    18761#endif // BITSTREAM_HASH_TABLE_H
  • trunk/lib/symtab/bitstream_id_hash_table.h

    r1391 r1462  
    1616
    1717#include "bitstream_hash_table.h"
     18#include "pbgs_utilities.h"
    1819
    1920class BitStreamIdentityHashTable : public BitStreamHashTable
     
    2728
    2829template <int L>
    29         inline unsigned int BitStreamIdentityHashTable::Lookup_Name(char * name, const int hashvalue)
     30        unsigned int BitStreamIdentityHashTable::Lookup_Name(char * name, const int hashvalue)
    3031{
    3132    unsigned int hash = getIndex(hashvalue);
  • trunk/lib/symtab/bitstream_log_hash_table.h

    r1391 r1462  
    2020
    2121#include "bitstream_hash_table.h"
     22#include "pbgs_utilities.h"
    2223
    2324class BitStreamLogHashTable : public BitStreamHashTable
  • trunk/lib/symtab/library_conversion.h

    r1441 r1462  
    88#include "../lib_simd.h"
    99#endif
    10 
    11 #include <stdio.h>
    1210
    1311template <int fw>
     
    7674#endif
    7775}
    78 
    79 /* Prints the SIMD register representation of a SIMD value. */
    80 template <int fw>
    81 void simdLibConvert<fw>::print_simd_register(const char * var_name, SIMD_type v) {
    82   union {SIMD_type vec; unsigned char elems[sizeof(SIMD_type)];} x;
    83   x.vec = v;
    84   unsigned char c;
    85   printf("%30s = ", var_name);
    86   for(int i=sizeof(SIMD_type)-1; i>=0; i--) {
    87     c = x.elems[i];
    88     printf("%02X ", c);
    89   }
    90   printf("\n");
    91 }
    9276#endif // LIBRARY_CONVERSION_H
  • trunk/lib/symtab/ls_symbol_table.cxx

    r1427 r1462  
    13971397        for(i=0;i<total_bytes;i+=sizeof(SIMD_type)) {
    13981398                SIMD_type value = sisd_load_aligned((SIMD_type *)&this->symbol_values_->get(L,i));
    1399                 simdLibConvert<1>::print_simd_register("Symbol", value);
     1399                print_simd_register("Symbol", value);
    14001400        }
    14011401        printf("\n");
  • trunk/lib/symtab/pbgs_utilities.h

    r1428 r1462  
    1515#ifndef PBGS_UTILITIES_H_
    1616#define PBGS_UTILITIES_H_
     17#define USE_FUNCTION_TEMPLATES //Used in ls_symbol_table_compare.h
    1718//#define USE_MASK_COMPARE    //Comparison using masking technique.
    1819                              //This technique only applies for USE_LOG_SORT
Note: See TracChangeset for help on using the changeset viewer.