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

#include <giaNewBdd.h>

Public Member Functions

lit Bvar2Lit (bvar a) const
 
lit Bvar2Lit (bvar a, bool c) const
 
bvar Lit2Bvar (lit x) const
 
var VarOfBvar (bvar a) const
 
lit ThenOfBvar (bvar a) const
 
lit ElseOfBvar (bvar a) const
 
ref RefOfBvar (bvar a) const
 
lit Const0 () const
 
lit Const1 () const
 
bool IsConst0 (lit x) const
 
bool IsConst1 (lit x) const
 
lit IthVar (var v) const
 
lit LitRegular (lit x) const
 
lit LitIrregular (lit x) const
 
lit LitNot (lit x) const
 
lit LitNotCond (lit x, bool c) const
 
bool LitIsCompl (lit x) const
 
bool LitIsEq (lit x, lit y) const
 
var Var (lit x) const
 
var Level (lit x) const
 
lit Then (lit x) const
 
lit Else (lit x) const
 
ref Ref (lit x) const
 
double OneCount (lit x) const
 
void IncRef (lit x)
 
void DecRef (lit x)
 
bool Resize ()
 
void ResizeUnique (var v)
 
bool Gbc ()
 
 Man (int nVars_, Param p)
 
 ~Man ()
 
void Reorder ()
 
lit And (lit x, lit y)
 
lit Or (lit x, lit y)
 
void SetRef (std::vector< lit > const &vLits)
 
void RemoveRefIfUnused ()
 
void TurnOnReo (int nReo_=0, std::vector< lit > const *vLits=NULL)
 
void TurnOffReo ()
 
var GetNumVars () const
 
void GetOrdering (std::vector< int > &Var2Level_)
 
bvar CountNodes ()
 
bvar CountNodes (std::vector< lit > const &vLits)
 
void PrintStats ()
 

Detailed Description

Definition at line 198 of file giaNewBdd.h.

Constructor & Destructor Documentation

◆ Man()

NewBdd::Man::Man ( int nVars_,
Param p )
inline

Definition at line 664 of file giaNewBdd.h.

664 {
665 nVerbose = p.nVerbose;
666 // parameter sanity check
667 if(p.nObjsMaxLog < p.nObjsAllocLog)
668 fatal_error("nObjsMax must not be smaller than nObjsAlloc");
669 if(nVars_ >= (int)VarMax())
670 fatal_error("Memout (nVars) in init");
671 nVars = nVars_;
672 lit nObjsMaxLit = (lit)1 << p.nObjsMaxLog;
673 if(!nObjsMaxLit)
674 fatal_error("Memout (nObjsMax) in init");
675 if(nObjsMaxLit > (lit)BvarMax())
676 nObjsMax = BvarMax();
677 else
678 nObjsMax = (bvar)nObjsMaxLit;
679 lit nObjsAllocLit = (lit)1 << p.nObjsAllocLog;
680 if(!nObjsAllocLit)
681 fatal_error("Memout (nObjsAlloc) in init");
682 if(nObjsAllocLit > (lit)BvarMax())
683 nObjsAlloc = BvarMax();
684 else
685 nObjsAlloc = (bvar)nObjsAllocLit;
686 if(nObjsAlloc <= (bvar)nVars)
687 fatal_error("nObjsAlloc must be larger than nVars");
688 uniq nUniqueSize = (uniq)1 << p.nUniqueSizeLog;
689 if(!nUniqueSize)
690 fatal_error("Memout (nUniqueSize) in init");
691 // allocation
692 if(nVerbose)
693 std::cout << "Allocating " << nObjsAlloc << " nodes and " << nVars << " x " << nUniqueSize << " unique table entries" << std::endl;
694 vVars.resize(nObjsAlloc);
695 vObjs.resize((lit)nObjsAlloc * 2);
696 vNexts.resize(nObjsAlloc);
697 vMarks.resize(nObjsAlloc);
698 vvUnique.resize(nVars);
699 vUniqueMasks.resize(nVars);
700 vUniqueCounts.resize(nVars);
701 vUniqueTholds.resize(nVars);
702 for(var v = 0; v < nVars; v++) {
703 vvUnique[v].resize(nUniqueSize);
704 vUniqueMasks[v] = nUniqueSize - 1;
705 if((lit)(nUniqueSize * p.UniqueDensity) > (lit)BvarMax())
706 vUniqueTholds[v] = BvarMax();
707 else
708 vUniqueTholds[v] = (bvar)(nUniqueSize * p.UniqueDensity);
709 }
710 if(p.fCountOnes) {
711 if(nVars > 1023)
712 fatal_error("nVars must be less than 1024 to count ones");
713 vOneCounts.resize(nObjsAlloc);
714 }
715 // set up cache
716 cache = new Cache(p.nCacheSizeLog, p.nCacheMaxLog, p.nCacheVerbose);
717 // create nodes for variables
718 nObjs = 1;
719 vVars[0] = VarMax();
720 for(var v = 0; v < nVars; v++)
721 UniqueCreateInt(v, 1, 0);
722 // set up variable order
723 Var2Level.resize(nVars);
724 Level2Var.resize(nVars);
725 for(var v = 0; v < nVars; v++) {
726 if(p.pVar2Level)
727 Var2Level[v] = (*p.pVar2Level)[v];
728 else
729 Var2Level[v] = v;
730 Level2Var[Var2Level[v]] = v;
731 }
732 // set other parameters
733 RemovedHead = 0;
734 nGbc = p.nGbc;
735 nReo = p.nReo;
736 MaxGrowth = p.MaxGrowth;
737 fReoVerbose = p.fReoVerbose;
738 if(nGbc || nReo != BvarMax())
739 vRefs.resize(nObjsAlloc);
740 }
Cube * p
Definition exorList.c:222
unsigned lit
Definition giaNewBdd.h:37
int bvar
Definition giaNewBdd.h:36
unsigned uniq
Definition giaNewBdd.h:41
unsigned short var
Definition giaNewBdd.h:35

◆ ~Man()

NewBdd::Man::~Man ( )
inline

Definition at line 741 of file giaNewBdd.h.

741 {
742 if(nVerbose) {
743 std::cout << "Free " << nObjsAlloc << " nodes (" << nObjs << " live nodes)" << std::endl;
744 std::cout << "Free {";
745 std::string delim;
746 for(var v = 0; v < nVars; v++) {
747 std::cout << delim << vvUnique[v].size();
748 delim = ", ";
749 }
750 std::cout << "} unique table entries" << std::endl;
751 if(!vRefs.empty())
752 std::cout << "Free " << vRefs.size() << " refs" << std::endl;
753 }
754 delete cache;
755 }

Member Function Documentation

◆ And()

lit NewBdd::Man::And ( lit x,
lit y )
inline

Definition at line 767 of file giaNewBdd.h.

767 {
768 if(nObjs > nReo) {
769 Reorder();
770 while(nReo < nObjs) {
771 nReo <<= 1;
772 if((lit)nReo > (lit)BvarMax())
773 nReo = BvarMax();
774 }
775 }
776 return And_rec(x, y);
777 }
void Reorder()
Definition giaNewBdd.h:756
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bvar2Lit() [1/2]

lit NewBdd::Man::Bvar2Lit ( bvar a) const
inline

Definition at line 226 of file giaNewBdd.h.

226{ return (lit)a << 1; }
Here is the caller graph for this function:

◆ Bvar2Lit() [2/2]

lit NewBdd::Man::Bvar2Lit ( bvar a,
bool c ) const
inline

Definition at line 227 of file giaNewBdd.h.

227{ return ((lit)a << 1) ^ (lit)c; }

◆ Const0()

lit NewBdd::Man::Const0 ( ) const
inline

Definition at line 233 of file giaNewBdd.h.

233{ return (lit)0; }
Here is the caller graph for this function:

◆ Const1()

lit NewBdd::Man::Const1 ( ) const
inline

Definition at line 234 of file giaNewBdd.h.

234{ return (lit)1; }
Here is the caller graph for this function:

◆ CountNodes() [1/2]

bvar NewBdd::Man::CountNodes ( )
inline

Definition at line 818 of file giaNewBdd.h.

818 {
819 bvar count = 1;
820 if(!vEdges.empty()) {
821 for(bvar a = 1; a < nObjs; a++)
822 if(EdgeOfBvar(a))
823 count++;
824 return count;
825 }
826 for(bvar a = 1; a <= (bvar)nVars; a++) {
827 count++;
828 SetMarkOfBvar(a);
829 }
830 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
831 if(RefOfBvar(a))
832 count += CountNodes_rec(Bvar2Lit(a));
833 for(bvar a = 1; a <= (bvar)nVars; a++)
834 ResetMarkOfBvar(a);
835 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
836 if(RefOfBvar(a))
837 ResetMark_rec(Bvar2Lit(a));
838 return count;
839 }
ref RefOfBvar(bvar a) const
Definition giaNewBdd.h:232
lit Bvar2Lit(bvar a) const
Definition giaNewBdd.h:226
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CountNodes() [2/2]

bvar NewBdd::Man::CountNodes ( std::vector< lit > const & vLits)
inline

Definition at line 840 of file giaNewBdd.h.

840 {
841 bvar count = 1;
842 for(size_t i = 0; i < vLits.size(); i++)
843 count += CountNodes_rec(vLits[i]);
844 for(size_t i = 0; i < vLits.size(); i++)
845 ResetMark_rec(vLits[i]);
846 return count;
847 }

◆ DecRef()

void NewBdd::Man::DecRef ( lit x)
inline

Definition at line 259 of file giaNewBdd.h.

259{ if(!vRefs.empty() && Ref(x) != RefMax()) vRefs[Lit2Bvar(x)]--; }
bvar Lit2Bvar(lit x) const
Definition giaNewBdd.h:228
ref Ref(lit x) const
Definition giaNewBdd.h:248
Here is the call graph for this function:

◆ Else()

lit NewBdd::Man::Else ( lit x) const
inline

Definition at line 247 of file giaNewBdd.h.

247{ return LitNotCond(vObjs[LitIrregular(x)], LitIsCompl(x)); }
bool LitIsCompl(lit x) const
Definition giaNewBdd.h:242
lit LitIrregular(lit x) const
Definition giaNewBdd.h:239
lit LitNotCond(lit x, bool c) const
Definition giaNewBdd.h:241
Here is the call graph for this function:

◆ ElseOfBvar()

lit NewBdd::Man::ElseOfBvar ( bvar a) const
inline

Definition at line 231 of file giaNewBdd.h.

231{ return vObjs[Bvar2Lit(a, true)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gbc()

bool NewBdd::Man::Gbc ( )
inline

Definition at line 390 of file giaNewBdd.h.

390 {
391 if(nVerbose >= 2)
392 std::cout << "Garbage collect" << std::endl;
393 if(!vEdges.empty()) {
394 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
395 if(!EdgeOfBvar(a) && VarOfBvar(a) != VarMax())
396 RemoveBvar(a);
397 } else {
398 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
399 if(RefOfBvar(a))
400 SetMark_rec(Bvar2Lit(a));
401 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
402 if(!MarkOfBvar(a) && VarOfBvar(a) != VarMax())
403 RemoveBvar(a);
404 for(bvar a = (bvar)nVars + 1; a < nObjs; a++)
405 if(RefOfBvar(a))
406 ResetMark_rec(Bvar2Lit(a));
407 }
408 cache->Clear();
409 return RemovedHead;
410 }
var VarOfBvar(bvar a) const
Definition giaNewBdd.h:229
Here is the call graph for this function:

◆ GetNumVars()

var NewBdd::Man::GetNumVars ( ) const
inline

Definition at line 810 of file giaNewBdd.h.

810 {
811 return nVars;
812 }

◆ GetOrdering()

void NewBdd::Man::GetOrdering ( std::vector< int > & Var2Level_)
inline

Definition at line 813 of file giaNewBdd.h.

813 {
814 Var2Level_.resize(nVars);
815 for(var v = 0; v < nVars; v++)
816 Var2Level_[v] = Var2Level[v];
817 }

◆ IncRef()

void NewBdd::Man::IncRef ( lit x)
inline

Definition at line 258 of file giaNewBdd.h.

258{ if(!vRefs.empty() && Ref(x) != RefMax()) vRefs[Lit2Bvar(x)]++; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsConst0()

bool NewBdd::Man::IsConst0 ( lit x) const
inline

Definition at line 235 of file giaNewBdd.h.

235{ return x == Const0(); }
lit Const0() const
Definition giaNewBdd.h:233
Here is the call graph for this function:

◆ IsConst1()

bool NewBdd::Man::IsConst1 ( lit x) const
inline

Definition at line 236 of file giaNewBdd.h.

236{ return x == Const1(); }
lit Const1() const
Definition giaNewBdd.h:234
Here is the call graph for this function:

◆ IthVar()

lit NewBdd::Man::IthVar ( var v) const
inline

Definition at line 237 of file giaNewBdd.h.

237{ return Bvar2Lit((bvar)v + 1); }
Here is the call graph for this function:

◆ Level()

var NewBdd::Man::Level ( lit x) const
inline

Definition at line 245 of file giaNewBdd.h.

245{ return Var2Level[Var(x)]; }
int Var
Definition exorList.c:228

◆ Lit2Bvar()

bvar NewBdd::Man::Lit2Bvar ( lit x) const
inline

Definition at line 228 of file giaNewBdd.h.

228{ return (bvar)(x >> 1); }
Here is the caller graph for this function:

◆ LitIrregular()

lit NewBdd::Man::LitIrregular ( lit x) const
inline

Definition at line 239 of file giaNewBdd.h.

239{ return x | (lit)1; }
Here is the caller graph for this function:

◆ LitIsCompl()

bool NewBdd::Man::LitIsCompl ( lit x) const
inline

Definition at line 242 of file giaNewBdd.h.

242{ return x & (lit)1; }
Here is the caller graph for this function:

◆ LitIsEq()

bool NewBdd::Man::LitIsEq ( lit x,
lit y ) const
inline

Definition at line 243 of file giaNewBdd.h.

243{ return x == y; }

◆ LitNot()

lit NewBdd::Man::LitNot ( lit x) const
inline

Definition at line 240 of file giaNewBdd.h.

240{ return x ^ (lit)1; }
Here is the caller graph for this function:

◆ LitNotCond()

lit NewBdd::Man::LitNotCond ( lit x,
bool c ) const
inline

Definition at line 241 of file giaNewBdd.h.

241{ return x ^ (lit)c; }
Here is the caller graph for this function:

◆ LitRegular()

lit NewBdd::Man::LitRegular ( lit x) const
inline

Definition at line 238 of file giaNewBdd.h.

238{ return x & ~(lit)1; }
Here is the caller graph for this function:

◆ OneCount()

double NewBdd::Man::OneCount ( lit x) const
inline

Definition at line 249 of file giaNewBdd.h.

249 {
250 if(vOneCounts.empty())
251 fatal_error("fCountOnes was not set");
252 if(LitIsCompl(x))
253 return std::pow(2.0, nVars) - vOneCounts[Lit2Bvar(x)];
254 return vOneCounts[Lit2Bvar(x)];
255 }
Here is the call graph for this function:

◆ Or()

lit NewBdd::Man::Or ( lit x,
lit y )
inline

Definition at line 778 of file giaNewBdd.h.

778 {
779 return LitNot(And(LitNot(x), LitNot(y)));
780 }
lit LitNot(lit x) const
Definition giaNewBdd.h:240
lit And(lit x, lit y)
Definition giaNewBdd.h:767
Here is the call graph for this function:

◆ PrintStats()

void NewBdd::Man::PrintStats ( )
inline

Definition at line 848 of file giaNewBdd.h.

848 {
849 bvar nRemoved = 0;
850 bvar a = RemovedHead;
851 while(a)
852 a = vNexts[a], nRemoved++;
853 bvar nLive = 1;
854 for(var v = 0; v < nVars; v++)
855 nLive += vUniqueCounts[v];
856 std::cout << "ref: " << std::setw(10) << (vRefs.empty()? 0: CountNodes()) << ", "
857 << "used: " << std::setw(10) << nObjs << ", "
858 << "live: " << std::setw(10) << nLive << ", "
859 << "dead: " << std::setw(10) << nRemoved << ", "
860 << "alloc: " << std::setw(10) << nObjsAlloc
861 << std::endl;
862 }
bvar CountNodes()
Definition giaNewBdd.h:818
Here is the call graph for this function:

◆ Ref()

ref NewBdd::Man::Ref ( lit x) const
inline

Definition at line 248 of file giaNewBdd.h.

248{ return vRefs[Lit2Bvar(x)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RefOfBvar()

ref NewBdd::Man::RefOfBvar ( bvar a) const
inline

Definition at line 232 of file giaNewBdd.h.

232{ return vRefs[a]; }
Here is the caller graph for this function:

◆ RemoveRefIfUnused()

void NewBdd::Man::RemoveRefIfUnused ( )
inline

Definition at line 789 of file giaNewBdd.h.

789 {
790 if(!nGbc && nReo == BvarMax())
791 vRefs.clear();
792 }

◆ Reorder()

void NewBdd::Man::Reorder ( )
inline

Definition at line 756 of file giaNewBdd.h.

756 {
757 if(nVerbose >= 2)
758 std::cout << "Reorder" << std::endl;
759 int nGbc_ = nGbc;
760 nGbc = 0;
761 CountEdges();
762 Sift();
763 vEdges.clear();
764 cache->Clear();
765 nGbc = nGbc_;
766 }
Here is the caller graph for this function:

◆ Resize()

bool NewBdd::Man::Resize ( )
inline

Definition at line 333 of file giaNewBdd.h.

333 {
334 if(nObjsAlloc == nObjsMax)
335 return false;
336 lit nObjsAllocLit = (lit)nObjsAlloc << 1;
337 if(nObjsAllocLit > (lit)BvarMax())
338 nObjsAlloc = BvarMax();
339 else
340 nObjsAlloc = (bvar)nObjsAllocLit;
341 if(nVerbose >= 2)
342 std::cout << "Reallocating " << nObjsAlloc << " nodes" << std::endl;
343 vVars.resize(nObjsAlloc);
344 vObjs.resize((lit)nObjsAlloc * 2);
345 vNexts.resize(nObjsAlloc);
346 vMarks.resize(nObjsAlloc);
347 if(!vRefs.empty())
348 vRefs.resize(nObjsAlloc);
349 if(!vEdges.empty())
350 vEdges.resize(nObjsAlloc);
351 if(!vOneCounts.empty())
352 vOneCounts.resize(nObjsAlloc);
353 return true;
354 }

◆ ResizeUnique()

void NewBdd::Man::ResizeUnique ( var v)
inline

Definition at line 355 of file giaNewBdd.h.

355 {
356 uniq nUniqueSize, nUniqueSizeOld;
357 nUniqueSize = nUniqueSizeOld = vvUnique[v].size();
358 nUniqueSize <<= 1;
359 if(!nUniqueSize) {
360 vUniqueTholds[v] = BvarMax();
361 return;
362 }
363 if(nVerbose >= 2)
364 std::cout << "Reallocating " << nUniqueSize << " unique table entries for Var " << v << std::endl;
365 vvUnique[v].resize(nUniqueSize);
366 vUniqueMasks[v] = nUniqueSize - 1;
367 for(uniq i = 0; i < nUniqueSizeOld; i++) {
368 std::vector<bvar>::iterator q, tail, tail1, tail2;
369 q = tail1 = vvUnique[v].begin() + i;
370 tail2 = q + nUniqueSizeOld;
371 while(*q) {
372 uniq hash = UniqHash(ThenOfBvar(*q), ElseOfBvar(*q)) & vUniqueMasks[v];
373 if(hash == i)
374 tail = tail1;
375 else
376 tail = tail2;
377 if(tail != q)
378 *tail = *q, *q = 0;
379 q = vNexts.begin() + *tail;
380 if(tail == tail1)
381 tail1 = q;
382 else
383 tail2 = q;
384 }
385 }
386 vUniqueTholds[v] <<= 1;
387 if((lit)vUniqueTholds[v] > (lit)BvarMax())
388 vUniqueTholds[v] = BvarMax();
389 }
lit ThenOfBvar(bvar a) const
Definition giaNewBdd.h:230
lit ElseOfBvar(bvar a) const
Definition giaNewBdd.h:231
Here is the call graph for this function:

◆ SetRef()

void NewBdd::Man::SetRef ( std::vector< lit > const & vLits)
inline

Definition at line 783 of file giaNewBdd.h.

783 {
784 vRefs.clear();
785 vRefs.resize(nObjsAlloc);
786 for(size_t i = 0; i < vLits.size(); i++)
787 IncRef(vLits[i]);
788 }
void IncRef(lit x)
Definition giaNewBdd.h:258
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Then()

lit NewBdd::Man::Then ( lit x) const
inline

Definition at line 246 of file giaNewBdd.h.

246{ return LitNotCond(vObjs[LitRegular(x)], LitIsCompl(x)); }
lit LitRegular(lit x) const
Definition giaNewBdd.h:238
Here is the call graph for this function:

◆ ThenOfBvar()

lit NewBdd::Man::ThenOfBvar ( bvar a) const
inline

Definition at line 230 of file giaNewBdd.h.

230{ return vObjs[Bvar2Lit(a)]; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TurnOffReo()

void NewBdd::Man::TurnOffReo ( )
inline

Definition at line 807 of file giaNewBdd.h.

807 {
808 nReo = BvarMax();
809 }

◆ TurnOnReo()

void NewBdd::Man::TurnOnReo ( int nReo_ = 0,
std::vector< lit > const * vLits = NULL )
inline

Definition at line 793 of file giaNewBdd.h.

793 {
794 if(nReo_)
795 nReo = nReo_;
796 else
797 nReo = nObjs << 1;
798 if((lit)nReo > (lit)BvarMax())
799 nReo = BvarMax();
800 if(vRefs.empty()) {
801 if(vLits)
802 SetRef(*vLits);
803 else
804 vRefs.resize(nObjsAlloc);
805 }
806 }
void SetRef(std::vector< lit > const &vLits)
Definition giaNewBdd.h:783
Here is the call graph for this function:

◆ Var()

var NewBdd::Man::Var ( lit x) const
inline

Definition at line 244 of file giaNewBdd.h.

244{ return vVars[Lit2Bvar(x)]; }
Here is the call graph for this function:

◆ VarOfBvar()

var NewBdd::Man::VarOfBvar ( bvar a) const
inline

Definition at line 229 of file giaNewBdd.h.

229{ return vVars[a]; }
Here is the caller graph for this function:

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