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

#include <giaNewBdd.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 56 of file giaNewBdd.h.

Constructor & Destructor Documentation

◆ Cache()

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

Definition at line 69 of file giaNewBdd.h.

69 : nVerbose(nVerbose) {
70 if(nCacheMaxLog < nCacheSizeLog)
71 fatal_error("nCacheMax must not be smaller than nCacheSize");
72 nMax = (cac)1 << nCacheMaxLog;
73 if(!(nMax << 1))
74 fatal_error("Memout (nCacheMax) in init");
75 nSize = (cac)1 << nCacheSizeLog;
76 if(nVerbose)
77 std::cout << "Allocating " << nSize << " cache entries" << std::endl;
78 vCache.resize(nSize * 3);
79 Mask = nSize - 1;
80 nLookups = 0;
81 nHits = 0;
82 nThold = (nSize == nMax)? SizeMax(): nSize;
83 HitRate = 1;
84 }
unsigned cac
Definition giaNewBdd.h:42

◆ ~Cache()

NewBdd::Cache::~Cache ( )
inline

Definition at line 85 of file giaNewBdd.h.

85 {
86 if(nVerbose)
87 std::cout << "Free " << nSize << " cache entries" << std::endl;
88 }

Member Function Documentation

◆ Clear()

void NewBdd::Cache::Clear ( )
inline

Definition at line 136 of file giaNewBdd.h.

136 {
137 std::fill(vCache.begin(), vCache.end(), 0);
138 }

◆ Insert()

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

Definition at line 123 of file giaNewBdd.h.

123 {
124 cac i = (CacHash(x, y) & Mask) * 3;
125 vCache[i] = x;
126 vCache[i + 1] = y;
127 vCache[i + 2] = z;
128 if(nVerbose >= 3)
129 std::cout << "Cache ent: "
130 << "x = " << std::setw(10) << x << ", "
131 << "y = " << std::setw(10) << y << ", "
132 << "z = " << std::setw(10) << z << ", "
133 << "hash = " << std::hex << (CacHash(x, y) & Mask) << std::dec
134 << std::endl;
135 }

◆ Lookup()

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

Definition at line 89 of file giaNewBdd.h.

89 {
90 nLookups++;
91 if(nLookups > nThold) {
92 double NewHitRate = (double)nHits / nLookups;
93 if(nVerbose >= 2)
94 std::cout << "Cache Hits: " << std::setw(10) << nHits << ", "
95 << "Lookups: " << std::setw(10) << nLookups << ", "
96 << "Rate: " << std::setw(10) << NewHitRate
97 << std::endl;
98 if(NewHitRate > HitRate)
99 Resize();
100 if(nSize == nMax)
101 nThold = SizeMax();
102 else {
103 nThold <<= 1;
104 if(!nThold)
105 nThold = SizeMax();
106 }
107 HitRate = NewHitRate;
108 }
109 cac i = (CacHash(x, y) & Mask) * 3;
110 if(vCache[i] == x && vCache[i + 1] == y) {
111 if(nVerbose >= 3)
112 std::cout << "Cache hit: "
113 << "x = " << std::setw(10) << x << ", "
114 << "y = " << std::setw(10) << y << ", "
115 << "z = " << std::setw(10) << vCache[i + 2] << ", "
116 << "hash = " << std::hex << (CacHash(x, y) & Mask) << std::dec
117 << std::endl;
118 nHits++;
119 return vCache[i + 2];
120 }
121 return LitMax();
122 }
void Resize()
Definition giaNewBdd.h:139
Here is the call graph for this function:

◆ Resize()

void NewBdd::Cache::Resize ( )
inline

Definition at line 139 of file giaNewBdd.h.

139 {
140 cac nSizeOld = nSize;
141 nSize <<= 1;
142 if(nVerbose >= 2)
143 std::cout << "Reallocating " << nSize << " cache entries" << std::endl;
144 vCache.resize(nSize * 3);
145 Mask = nSize - 1;
146 for(cac j = 0; j < nSizeOld; j++) {
147 cac i = j * 3;
148 if(vCache[i] || vCache[i + 1]) {
149 cac hash = (CacHash(vCache[i], vCache[i + 1]) & Mask) * 3;
150 vCache[hash] = vCache[i];
151 vCache[hash + 1] = vCache[i + 1];
152 vCache[hash + 2] = vCache[i + 2];
153 if(nVerbose >= 3)
154 std::cout << "Cache mov: "
155 << "x = " << std::setw(10) << vCache[i] << ", "
156 << "y = " << std::setw(10) << vCache[i + 1] << ", "
157 << "z = " << std::setw(10) << vCache[i + 2] << ", "
158 << "hash = " << std::hex << (CacHash(vCache[i], vCache[i + 1]) & Mask) << std::dec
159 << std::endl;
160 }
161 }
162 }
Here is the caller graph for this function:

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