[buddy] Inline the "is bdd constant" check performed in copies/constructors.
This avoids a library call to bdd_addref or bdd_delref. * src/kernel.c (bdd_delref_nc, bdd_addref_nc): New function, that work only on BDD that are not constant. * src/cpext.cxx (bdd::operator=): Move... * src/bdd.hh (bdd::operator=): ... here. (bdd::bdd, bdd::~bdd, bdd::operator=): Inline the "is bdd constant" check and call bdd_delref_nc/bdd_addref_nc only otherwise.
This commit is contained in:
parent
2b58fb90c4
commit
1d1872ab90
4 changed files with 104 additions and 59 deletions
|
|
@ -1,3 +1,16 @@
|
||||||
|
2011-04-30 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
||||||
|
|
||||||
|
Inline the "is bdd constant" check performed in copies/constructors.
|
||||||
|
|
||||||
|
This avoids a library call to bdd_addref or bdd_delref.
|
||||||
|
|
||||||
|
* src/kernel.c (bdd_delref_nc, bdd_addref_nc): New function,
|
||||||
|
that work only on BDD that are not constant.
|
||||||
|
* src/cpext.cxx (bdd::operator=): Move...
|
||||||
|
* src/bdd.hh (bdd::operator=): ... here.
|
||||||
|
(bdd::bdd, bdd::~bdd, bdd::operator=): Inline the "is bdd constant"
|
||||||
|
check and call bdd_delref_nc/bdd_addref_nc only otherwise.
|
||||||
|
|
||||||
2011-04-30 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
2011-04-30 Alexandre Duret-Lutz <adl@lrde.epita.fr>
|
||||||
|
|
||||||
Hint gcc about likely/unlikely branches.
|
Hint gcc about likely/unlikely branches.
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,9 @@ extern int bdd_var(BDD) __purefn;
|
||||||
extern BDD bdd_low(BDD) __purefn;
|
extern BDD bdd_low(BDD) __purefn;
|
||||||
extern BDD bdd_high(BDD) __purefn;
|
extern BDD bdd_high(BDD) __purefn;
|
||||||
extern int bdd_varlevel(int) __purefn;
|
extern int bdd_varlevel(int) __purefn;
|
||||||
|
extern BDD bdd_addref_nc(BDD);
|
||||||
extern BDD bdd_addref(BDD);
|
extern BDD bdd_addref(BDD);
|
||||||
|
extern BDD bdd_delref_nc(BDD);
|
||||||
extern BDD bdd_delref(BDD);
|
extern BDD bdd_delref(BDD);
|
||||||
extern void bdd_gbc(void);
|
extern void bdd_gbc(void);
|
||||||
extern int bdd_scanset(BDD, int**, int*);
|
extern int bdd_scanset(BDD, int**, int*);
|
||||||
|
|
@ -453,8 +455,8 @@ class bdd
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bdd(void) { root=0; }
|
bdd(void) { root=0; }
|
||||||
bdd(const bdd &r) { bdd_addref(root=r.root); }
|
bdd(const bdd &r) { root=r.root; if (root > 1) bdd_addref_nc(root); }
|
||||||
~bdd(void) { bdd_delref(root); }
|
~bdd(void) { if (root > 1) bdd_delref_nc(root); }
|
||||||
|
|
||||||
int id(void) const;
|
int id(void) const;
|
||||||
|
|
||||||
|
|
@ -481,7 +483,7 @@ class bdd
|
||||||
private:
|
private:
|
||||||
BDD root;
|
BDD root;
|
||||||
|
|
||||||
bdd(BDD r) { bdd_addref(root=r); }
|
bdd(BDD r) { root=r; if (root > 1) bdd_addref_nc(root); }
|
||||||
bdd operator=(BDD r);
|
bdd operator=(BDD r);
|
||||||
|
|
||||||
friend int bdd_init(int, int);
|
friend int bdd_init(int, int);
|
||||||
|
|
@ -849,6 +851,32 @@ inline int bdd::operator==(const bdd &r) const
|
||||||
inline int bdd::operator!=(const bdd &r) const
|
inline int bdd::operator!=(const bdd &r) const
|
||||||
{ return r.root!=root; }
|
{ return r.root!=root; }
|
||||||
|
|
||||||
|
inline bdd bdd::operator=(const bdd &r)
|
||||||
|
{
|
||||||
|
if (__likely(root != r.root))
|
||||||
|
{
|
||||||
|
if (root > 1)
|
||||||
|
bdd_delref_nc(root);
|
||||||
|
root = r.root;
|
||||||
|
if (root > 1)
|
||||||
|
bdd_addref_nc(root);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bdd bdd::operator=(int r)
|
||||||
|
{
|
||||||
|
if (__likely(root != r))
|
||||||
|
{
|
||||||
|
if (root > 1)
|
||||||
|
bdd_delref_nc(root);
|
||||||
|
root = r;
|
||||||
|
if (root > 1)
|
||||||
|
bdd_addref_nc(root);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
inline bdd bdd_true(void)
|
inline bdd bdd_true(void)
|
||||||
{ return 1; }
|
{ return 1; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,33 +141,6 @@ int bdd_anodecountpp(const bdd *r, int num)
|
||||||
return cou;
|
return cou;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
BDD class functions
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
bdd bdd::operator=(const bdd &r)
|
|
||||||
{
|
|
||||||
if (root != r.root)
|
|
||||||
{
|
|
||||||
bdd_delref(root);
|
|
||||||
root = r.root;
|
|
||||||
bdd_addref(root);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bdd bdd::operator=(int r)
|
|
||||||
{
|
|
||||||
if (root != r)
|
|
||||||
{
|
|
||||||
bdd_delref(root);
|
|
||||||
root = r;
|
|
||||||
bdd_addref(root);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
C++ iostream operators
|
C++ iostream operators
|
||||||
|
|
|
||||||
|
|
@ -1102,6 +1102,20 @@ void bdd_gbc(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BDD bdd_addref_nc(BDD root)
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (!bddrunning)
|
||||||
|
return root;
|
||||||
|
if (root < 2 || root >= bddnodesize)
|
||||||
|
return bdd_error(BDD_ILLBDD);
|
||||||
|
if (LOW(root) == -1)
|
||||||
|
return bdd_error(BDD_ILLBDD);
|
||||||
|
#endif
|
||||||
|
INCREF(root);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NAME {* bdd\_addref *}
|
NAME {* bdd\_addref *}
|
||||||
SECTION {* kernel *}
|
SECTION {* kernel *}
|
||||||
|
|
@ -1131,6 +1145,23 @@ BDD bdd_addref(BDD root)
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Non constant version
|
||||||
|
BDD bdd_delref_nc(BDD root)
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (root < 2 || !bddrunning)
|
||||||
|
return root;
|
||||||
|
if (root >= bddnodesize)
|
||||||
|
return bdd_error(BDD_ILLBDD);
|
||||||
|
if (LOW(root) == -1)
|
||||||
|
return bdd_error(BDD_ILLBDD);
|
||||||
|
|
||||||
|
/* if the following line is present, fails there much earlier */
|
||||||
|
if (!HASREF(root)) bdd_error(BDD_BREAK); /* distinctive */
|
||||||
|
#endif
|
||||||
|
DECREF(root);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NAME {* bdd\_delref *}
|
NAME {* bdd\_delref *}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue