Commit fb3edb47 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

[buddy] * src/bddop.c (apply_rec, appquant_rec): Improve caching by

reordering operands of commutative operators.
parent c42d55e6
2011-06-10 Alexandre Duret-Lutz <adl@lrde.epita.fr>
* src/bddop.c (apply_rec, appquant_rec): Improve caching by
reordering operands of commutative operators.
2011-06-09 Alexandre Duret-Lutz <adl@lrde.epita.fr> 2011-06-09 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Remove some valgrind warnings about uninitialized memory when Remove some valgrind warnings about uninitialized memory when
......
...@@ -570,36 +570,76 @@ static BDD apply_rec(BDD l, BDD r) ...@@ -570,36 +570,76 @@ static BDD apply_rec(BDD l, BDD r)
case bddop_and: case bddop_and:
if (l == r) if (l == r)
return l; return l;
if (ISZERO(l) || ISZERO(r)) /* The operation is commutative, so lets
order the arguments to favor cache hits. */
if (l > r)
{
BDD tmp = l;
l = r;
r = tmp;
}
if (ISZERO(l) /* || ISZERO(r) */)
return 0; return 0;
if (ISONE(l)) if (ISONE(l))
return r; return r;
if (ISONE(r)) /* if (ISONE(r))
return l; return l; */
break; break;
case bddop_or: case bddop_or:
if (l == r) if (l == r)
return l; return 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 (ISONE(l) || ISONE(r)) if (ISONE(l) || ISONE(r))
return 1; return 1;
if (ISZERO(l)) if (ISZERO(l))
return r; return r;
if (ISZERO(r)) /* if (ISZERO(r))
return l; return l; */
break; break;
case bddop_xor: case bddop_xor:
if (l == r) if (l == r)
return 0; 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 (ISZERO(l)) if (ISZERO(l))
return r; return r;
if (ISZERO(r)) /* if (ISZERO(r))
return l; return l; */
break; break;
case bddop_nand: case bddop_nand:
if (ISZERO(l) || ISZERO(r)) /* The operation is commutative, so lets
order the arguments to favor cache hits. */
if (l > r)
{
BDD tmp = l;
l = r;
r = tmp;
}
if (ISZERO(l) /* || ISZERO(r) */)
return 1; return 1;
break; break;
case bddop_nor: case bddop_nor:
/* The operation is commutative, so lets
order the arguments to favor cache hits. */
if (l > r)
{
BDD tmp = l;
l = r;
r = tmp;
}
if (ISONE(l) || ISONE(r)) if (ISONE(l) || ISONE(r))
return 0; return 0;
break; break;
...@@ -611,6 +651,16 @@ static BDD apply_rec(BDD l, BDD r) ...@@ -611,6 +651,16 @@ static BDD apply_rec(BDD l, BDD r)
if (ISONE(r)) if (ISONE(r))
return 1; return 1;
break; 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))
...@@ -2083,40 +2133,90 @@ static int appquant_rec(int l, int r) ...@@ -2083,40 +2133,90 @@ static int appquant_rec(int l, int r)
switch (appexop) switch (appexop)
{ {
case bddop_and: case bddop_and:
if (l == 0 || r == 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 /* || r == 0 */)
return 0; return 0;
if (l == r) if (l == r)
return quant_rec(l); return quant_rec(l);
if (l == 1) if (l == 1)
return quant_rec(r); return quant_rec(r);
if (r == 1) /* if (r == 1)
return quant_rec(l); return quant_rec(l); */
break; break;
case bddop_or: case bddop_or:
if (l == 1 || r == 1) if (l == 1 || r == 1)
return 1; return 1;
if (l == r) if (l == r)
return quant_rec(l); 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) if (l == 0)
return quant_rec(r); return quant_rec(r);
if (r == 0) /* if (r == 0)
return quant_rec(l); return quant_rec(l); */
break; break;
case bddop_xor: case bddop_xor:
if (l == r) if (l == r)
return 0; 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) if (l == 0)
return quant_rec(r); return quant_rec(r);
if (r == 0) /* if (r == 0)
return quant_rec(l); return quant_rec(l); */
break; break;
case bddop_nand: case bddop_nand:
if (l == 0 || r == 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 /* || r == 0 */)
return 1; return 1;
break; break;
case bddop_nor: case bddop_nor:
if (l == 1 || r == 1) if (l == 1 || r == 1)
return 0; 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; break;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment