#ifndef SAMPLE_PREFETCHER_H #define SAMPLE_PREFETCHER_H #include #include #include template struct Container { int theHeight,theWidth,theKeyShift; unsigned long long theTagMask; // dictates number of bits used to tag elements (includes lower index bits for simulation purposes only) unsigned long long theIndexMask; // based only on Height of structure typedef std::pair Item; typedef std::list ListType; std::vector theItems; typedef typename ListType::iterator Iter; Container( int aHeight , int aWidth , int aKeyShift , int aTagBits ) : theHeight(aHeight) , theWidth(aWidth) , theKeyShift(aKeyShift) , theTagMask((1ULL<> 22); key += (key << 4); key ^= (key >> 9); key += (key << 10); key ^= (key >> 2); key += (key << 7); key ^= (key >> 12); return key; } int index(KeyType aKey) { return (inthash(aKey >> theKeyShift) & theIndexMask); } int tag(KeyType aKey) { return (inthash(aKey >> theKeyShift) & theTagMask); } Iter find(KeyType aKey) { ListType& aList(theItems[index(aKey)]); KeyType aTag = tag(aKey); for(Iter i=aList.begin();i!=aList.end();i++) { //fprintf(stderr,"search for %llx in %llx [%d:%d/%d]\n",aKey,i->first,index(aKey),theHeight,theWidth); if (i->first == aTag) { aList.push_front(*i); aList.erase(i); return aList.begin(); } } return end(); } bool erase(KeyType aKey) { ListType& aList(theItems[index(aKey)]); KeyType aTag = tag(aKey); for(Iter i=aList.begin();i!=aList.end();i++) { if (i->first == aTag) { aList.erase(i); aList.resize(theWidth); return true; } } return false; } }; #endif