ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rrr::NewBdd::Cache Class Reference

#include <rrrBddManager.h>

Public Member Functions

 Cache (int nCacheSizeLog, int nCacheMaxLog, int nVerbose)
 
 ~Cache ()
 
lit Lookup (lit x, lit y)
 
void Insert (lit x, lit y, lit z)
 
void Clear ()
 
void Resize ()
 

Detailed Description

Definition at line 36 of file rrrBddManager.h.

Constructor & Destructor Documentation

◆ Cache()

rrr::NewBdd::Cache::Cache ( int nCacheSizeLog,
int nCacheMaxLog,
int nVerbose )
inline

Definition at line 49 of file rrrBddManager.h.

49 : nVerbose(nVerbose) {
50 if(nCacheMaxLog < nCacheSizeLog)
51 fatal_error("nCacheMax must not be smaller than nCacheSize");
52 nMax = (cac)1 << nCacheMaxLog;
53 if(!(nMax << 1))
54 fatal_error("Memout (nCacheMax) in init");
55 nSize = (cac)1 << nCacheSizeLog;
56 if(nVerbose)
57 std::cout << "Allocating " << nSize << " cache entries" << std::endl;
58 vCache.resize(nSize * 3);
59 Mask = nSize - 1;
60 nLookups = 0;
61 nHits = 0;
62 nThold = (nSize == nMax)? SizeMax(): nSize;
63 HitRate = 1;
64 }
unsigned cac

◆ ~Cache()

rrr::NewBdd::Cache::~Cache ( )
inline

Definition at line 65 of file rrrBddManager.h.

65 {
66 if(nVerbose)
67 std::cout << "Free " << nSize << " cache entries" << std::endl;
68 }

Member Function Documentation

◆ Clear()

void rrr::NewBdd::Cache::Clear ( )
inline

Definition at line 116 of file rrrBddManager.h.

116 {
117 std::fill(vCache.begin(), vCache.end(), 0);
118 }

◆ Insert()

void rrr::NewBdd::Cache::Insert ( lit x,
lit y,
lit z )
inline

Definition at line 103 of file rrrBddManager.h.

103 {
104 cac i = (CacHash(x, y) & Mask) * 3;
105 vCache[i] = x;
106 vCache[i + 1] = y;
107 vCache[i + 2] = z;
108 if(nVerbose >= 3)
109 std::cout << "Cache ent: "
110 << "x = " << std::setw(10) << x << ", "
111 << "y = " << std::setw(10) << y << ", "
112 << "z = " << std::setw(10) << z << ", "
113 << "hash = " << std::hex << (CacHash(x, y) & Mask) << std::dec
114 << std::endl;
115 }

◆ Lookup()

lit rrr::NewBdd::Cache::Lookup ( lit x,
lit y )
inline

Definition at line 69 of file rrrBddManager.h.

69 {
70 nLookups++;
71 if(nLookups > nThold) {
72 double NewHitRate = (double)nHits / nLookups;
73 if(nVerbose >= 2)
74 std::cout << "Cache Hits: " << std::setw(10) << nHits << ", "
75 << "Lookups: " << std::setw(10) << nLookups << ", "
76 << "Rate: " << std::setw(10) << NewHitRate
77 << std::endl;
78 if(NewHitRate > HitRate)
79 Resize();
80 if(nSize == nMax)
81 nThold = SizeMax();
82 else {
83 nThold <<= 1;
84 if(!nThold)
85 nThold = SizeMax();
86 }
87 HitRate = NewHitRate;
88 }
89 cac i = (CacHash(x, y) & Mask) * 3;
90 if(vCache[i] == x && vCache[i + 1] == y) {
91 if(nVerbose >= 3)
92 std::cout << "Cache hit: "
93 << "x = " << std::setw(10) << x << ", "
94 << "y = " << std::setw(10) << y << ", "
95 << "z = " << std::setw(10) << vCache[i + 2] << ", "
96 << "hash = " << std::hex << (CacHash(x, y) & Mask) << std::dec
97 << std::endl;
98 nHits++;
99 return vCache[i + 2];
100 }
101 return LitMax();
102 }
Here is the call graph for this function:

◆ Resize()

void rrr::NewBdd::Cache::Resize ( )
inline

Definition at line 119 of file rrrBddManager.h.

119 {
120 cac nSizeOld = nSize;
121 nSize <<= 1;
122 if(nVerbose >= 2)
123 std::cout << "Reallocating " << nSize << " cache entries" << std::endl;
124 vCache.resize(nSize * 3);
125 Mask = nSize - 1;
126 for(cac j = 0; j < nSizeOld; j++) {
127 cac i = j * 3;
128 if(vCache[i] || vCache[i + 1]) {
129 cac hash = (CacHash(vCache[i], vCache[i + 1]) & Mask) * 3;
130 vCache[hash] = vCache[i];
131 vCache[hash + 1] = vCache[i + 1];
132 vCache[hash + 2] = vCache[i + 2];
133 if(nVerbose >= 3)
134 std::cout << "Cache mov: "
135 << "x = " << std::setw(10) << vCache[i] << ", "
136 << "y = " << std::setw(10) << vCache[i + 1] << ", "
137 << "z = " << std::setw(10) << vCache[i + 2] << ", "
138 << "hash = " << std::hex << (CacHash(vCache[i], vCache[i + 1]) & Mask) << std::dec
139 << std::endl;
140 }
141 }
142 }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: