[buddy] consolidate shortcuts for binary operation
* src/bddop.c (apply_rec, appquant_rec): Define missing shortcuts for bddop_less, bddop_diff, bddop_revimpl and define them once.
This commit is contained in:
parent
75c33defb3
commit
84b16aa6bd
1 changed files with 108 additions and 187 deletions
|
|
@ -569,105 +569,114 @@ static BDD apply_rec(BDD l, BDD r)
|
||||||
BddCacheData *entry;
|
BddCacheData *entry;
|
||||||
BDD res;
|
BDD res;
|
||||||
|
|
||||||
switch (applyop)
|
#define APPLY_SHORTCUTS(op, rec) \
|
||||||
{
|
switch (op) \
|
||||||
case bddop_and:
|
{ \
|
||||||
if (l == r)
|
case bddop_and: \
|
||||||
return l;
|
if (l == r) \
|
||||||
/* The operation is commutative, so lets
|
return rec(l); \
|
||||||
order the arguments to favor cache hits. */
|
if (l > r) \
|
||||||
if (l > r)
|
{ \
|
||||||
{
|
BDD tmp = l; \
|
||||||
BDD tmp = l;
|
l = r; \
|
||||||
l = r;
|
r = tmp; \
|
||||||
r = tmp;
|
} \
|
||||||
}
|
if (ISZERO(l) /* || ISZERO(r) */) \
|
||||||
if (ISZERO(l) /* || ISZERO(r) */)
|
return 0; \
|
||||||
return 0;
|
if (ISONE(l)) \
|
||||||
if (ISONE(l))
|
return rec(r); \
|
||||||
return r;
|
break; \
|
||||||
/* if (ISONE(r))
|
case bddop_or: \
|
||||||
return l; */
|
if (l == r) \
|
||||||
break;
|
return rec(l); \
|
||||||
case bddop_or:
|
if (l > r) \
|
||||||
if (l == r)
|
{ \
|
||||||
return l;
|
BDD tmp = l; \
|
||||||
/* The operation is commutative, so lets
|
l = r; \
|
||||||
order the arguments to favor cache hits. */
|
r = tmp; \
|
||||||
if (l > r)
|
} \
|
||||||
{
|
if (ISONE(l) || ISONE(r)) \
|
||||||
BDD tmp = l;
|
return 1; \
|
||||||
l = r;
|
if (ISZERO(l)) \
|
||||||
r = tmp;
|
return rec(r); \
|
||||||
}
|
break; \
|
||||||
if (ISONE(l) || ISONE(r))
|
case bddop_xor: \
|
||||||
return 1;
|
if (l == r) \
|
||||||
if (ISZERO(l))
|
return 0; \
|
||||||
return r;
|
if (l > r) \
|
||||||
/* if (ISZERO(r))
|
{ \
|
||||||
return l; */
|
BDD tmp = l; \
|
||||||
break;
|
l = r; \
|
||||||
case bddop_xor:
|
r = tmp; \
|
||||||
if (l == r)
|
} \
|
||||||
return 0;
|
if (ISZERO(l)) \
|
||||||
/* The operation is commutative, so lets
|
return rec(r); \
|
||||||
order the arguments to favor cache hits. */
|
break; \
|
||||||
if (l > r)
|
case bddop_nand: \
|
||||||
{
|
if (l > r) \
|
||||||
BDD tmp = l;
|
{ \
|
||||||
l = r;
|
BDD tmp = l; \
|
||||||
r = tmp;
|
l = r; \
|
||||||
}
|
r = tmp; \
|
||||||
if (ISZERO(l))
|
} \
|
||||||
return r;
|
if (ISZERO(l)) \
|
||||||
/* if (ISZERO(r))
|
return 1; \
|
||||||
return l; */
|
break; \
|
||||||
break;
|
case bddop_nor: \
|
||||||
case bddop_nand:
|
if (l > r) \
|
||||||
/* The operation is commutative, so lets
|
{ \
|
||||||
order the arguments to favor cache hits. */
|
BDD tmp = l; \
|
||||||
if (l > r)
|
l = r; \
|
||||||
{
|
r = tmp; \
|
||||||
BDD tmp = l;
|
} \
|
||||||
l = r;
|
if (ISONE(l) || ISONE(r)) \
|
||||||
r = tmp;
|
return 0; \
|
||||||
}
|
break; \
|
||||||
if (ISZERO(l) /* || ISZERO(r) */)
|
case bddop_invimp: /* l << r = r >> l */ \
|
||||||
return 1;
|
{ \
|
||||||
break;
|
BDD tmp = l; \
|
||||||
case bddop_nor:
|
l = r; \
|
||||||
/* The operation is commutative, so lets
|
r = tmp; \
|
||||||
order the arguments to favor cache hits. */
|
op = bddop_imp; \
|
||||||
if (l > r)
|
} \
|
||||||
{
|
/* fall through */ \
|
||||||
BDD tmp = l;
|
case bddop_imp: \
|
||||||
l = r;
|
if (ISONE(r) || ISZERO(l)) \
|
||||||
r = tmp;
|
return 1; \
|
||||||
}
|
if (ISONE(l)) \
|
||||||
if (ISONE(l) || ISONE(r))
|
return rec(r); \
|
||||||
return 0;
|
break; \
|
||||||
break;
|
case bddop_biimp: \
|
||||||
case bddop_imp:
|
if (l == r) \
|
||||||
if (ISZERO(l))
|
return 1; \
|
||||||
return 1;
|
if (l > r) \
|
||||||
if (ISONE(l))
|
{ \
|
||||||
return r;
|
BDD tmp = l; \
|
||||||
if (ISONE(r))
|
l = r; \
|
||||||
return 1;
|
r = tmp; \
|
||||||
break;
|
} \
|
||||||
case bddop_biimp:
|
if (ISCONST(l)) \
|
||||||
/* The operation is commutative, so lets
|
return 0; \
|
||||||
order the arguments to favor cache hits. */
|
break; \
|
||||||
if (l > r)
|
case bddop_less: /* l < r = r - l */ \
|
||||||
{
|
{ \
|
||||||
BDD tmp = l;
|
BDD tmp = l; \
|
||||||
l = r;
|
l = r; \
|
||||||
r = tmp;
|
r = tmp; \
|
||||||
}
|
op = bddop_diff; \
|
||||||
break;
|
} \
|
||||||
}
|
/* fall through */ \
|
||||||
|
case bddop_diff: /* l - r = l &! r */ \
|
||||||
|
if (l == r || ISONE(r)) \
|
||||||
|
return 0; \
|
||||||
|
if (ISZERO(r)) \
|
||||||
|
return rec(l); \
|
||||||
|
break; \
|
||||||
|
}
|
||||||
|
|
||||||
if (ISCONST(l) && ISCONST(r))
|
APPLY_SHORTCUTS(applyop, /* id */);
|
||||||
|
|
||||||
|
if (__unlikely(ISCONST(l) && ISCONST(r)))
|
||||||
res = oprres[applyop][l<<1 | r];
|
res = oprres[applyop][l<<1 | r];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -2204,95 +2213,7 @@ static int appquant_rec(int l, int r)
|
||||||
BddCacheData *entry;
|
BddCacheData *entry;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
switch (appexop)
|
APPLY_SHORTCUTS(appexop, quant_rec);
|
||||||
{
|
|
||||||
case bddop_and:
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
if (l == 0 /* || r == 0 */)
|
|
||||||
return 0;
|
|
||||||
if (l == r)
|
|
||||||
return quant_rec(l);
|
|
||||||
if (l == 1)
|
|
||||||
return quant_rec(r);
|
|
||||||
/* if (r == 1)
|
|
||||||
return quant_rec(l); */
|
|
||||||
break;
|
|
||||||
case bddop_or:
|
|
||||||
if (l == 1 || r == 1)
|
|
||||||
return 1;
|
|
||||||
if (l == r)
|
|
||||||
return quant_rec(l);
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
if (l == 0)
|
|
||||||
return quant_rec(r);
|
|
||||||
/* if (r == 0)
|
|
||||||
return quant_rec(l); */
|
|
||||||
break;
|
|
||||||
case bddop_xor:
|
|
||||||
if (l == r)
|
|
||||||
return 0;
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
if (l == 0)
|
|
||||||
return quant_rec(r);
|
|
||||||
/* if (r == 0)
|
|
||||||
return quant_rec(l); */
|
|
||||||
break;
|
|
||||||
case bddop_nand:
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
if (l == 0 /* || r == 0 */)
|
|
||||||
return 1;
|
|
||||||
break;
|
|
||||||
case bddop_nor:
|
|
||||||
if (l == 1 || r == 1)
|
|
||||||
return 0;
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case bddop_biimp:
|
|
||||||
/* The operation is commutative, so lets
|
|
||||||
order the arguments to favor cache hits. */
|
|
||||||
if (l > r)
|
|
||||||
{
|
|
||||||
BDD tmp = l;
|
|
||||||
l = r;
|
|
||||||
r = tmp;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ISCONST(l) && ISCONST(r))
|
if (ISCONST(l) && ISCONST(r))
|
||||||
res = oprres[appexop][(l<<1) | r];
|
res = oprres[appexop][(l<<1) | r];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue