Commit dc9a2258 by Alan Mishchenko

New AIG optimization package.

parent 3d23bc8c
...@@ -38,8 +38,14 @@ static word s_Truth6[6] = ...@@ -38,8 +38,14 @@ static word s_Truth6[6] =
0xFFFFFFFF00000000 0xFFFFFFFF00000000
}; };
// ! = not; (a + b) = a and b; [a + b] = a xor b; <abc> = ITE( a, b, c ) /*
This code performs truth-table-based decomposition for 6-variable functions.
Representation of operations:
! = not;
(ab) = a and b;
[ab] = a xor b;
<abc> = ITE( a, b, c )
*/
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
...@@ -173,28 +179,6 @@ static inline word Dau_DsdVarPres( word t, int iVar ) ...@@ -173,28 +179,6 @@ static inline word Dau_DsdVarPres( word t, int iVar )
assert( iVar >= 0 && iVar < 6 ); assert( iVar >= 0 && iVar < 6 );
return (t & s_Truth6[iVar]) != ((t << (1<<iVar)) & s_Truth6[iVar]); return (t & s_Truth6[iVar]) != ((t << (1<<iVar)) & s_Truth6[iVar]);
} }
static inline int Dau_DsdPerformReplace2( char * pBuffer, int PosStart, int Pos, int Symb, char * pNext )
{
char * pTemp, * pStop = pTemp = pBuffer + Pos;
int i, Len = strlen(pNext);
do
{
for ( pTemp = pBuffer + Pos - 1; pTemp >= pBuffer + PosStart; pTemp[Len-1] = *pTemp, pTemp-- )
if ( pTemp < pStop && *pTemp == (char)Symb )
{
for ( i = 0; i < Len; i++ )
pTemp[i] = pNext[i];
Pos += Len - 1;
pStop = pTemp;
// check if there is symbol left
for ( ; pTemp >= pBuffer + PosStart; pTemp-- )
if ( *pTemp == (char)Symb )
break;
break;
}
} while ( pTemp >= pBuffer + PosStart );
return Pos;
}
static inline int Dau_DsdPerformReplace( char * pBuffer, int PosStart, int Pos, int Symb, char * pNext ) static inline int Dau_DsdPerformReplace( char * pBuffer, int PosStart, int Pos, int Symb, char * pNext )
{ {
static char pTemp[DAU_MAX_STR+20]; static char pTemp[DAU_MAX_STR+20];
...@@ -218,12 +202,13 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -218,12 +202,13 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
int pVarsNew[6], nVarsNew, PosStart; int pVarsNew[6], nVarsNew, PosStart;
int v, u, vBest, CountBest; int v, u, vBest, CountBest;
assert( Pos < DAU_MAX_STR ); assert( Pos < DAU_MAX_STR );
// copy remaining variables // perform support minimization
nVarsNew = 0; nVarsNew = 0;
for ( v = 0; v < nVars; v++ ) for ( v = 0; v < nVars; v++ )
if ( Dau_DsdVarPres( t, pVars[v] ) ) if ( Dau_DsdVarPres( t, pVars[v] ) )
pVarsNew[ nVarsNew++ ] = pVars[v]; pVarsNew[ nVarsNew++ ] = pVars[v];
assert( nVarsNew > 0 ); assert( nVarsNew > 0 );
// special case when function is a var
if ( nVarsNew == 1 ) if ( nVarsNew == 1 )
{ {
if ( t == s_Truth6[ pVarsNew[0] ] ) if ( t == s_Truth6[ pVarsNew[0] ] )
...@@ -240,12 +225,13 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -240,12 +225,13 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
assert( 0 ); assert( 0 );
return Pos; return Pos;
} }
// decompose on the output side
for ( v = 0; v < nVarsNew; v++ ) for ( v = 0; v < nVarsNew; v++ )
{ {
Cof0[v] = Dau_DsdCof0( t, pVarsNew[v] ); Cof0[v] = Dau_DsdCof0( t, pVarsNew[v] );
Cof1[v] = Dau_DsdCof1( t, pVarsNew[v] ); Cof1[v] = Dau_DsdCof1( t, pVarsNew[v] );
assert( Cof0[v] != Cof1[v] ); assert( Cof0[v] != Cof1[v] );
if ( Cof0[v] == 0 ) if ( Cof0[v] == 0 ) // ax
{ {
pBuffer[Pos++] = '('; pBuffer[Pos++] = '(';
pBuffer[Pos++] = 'a' + pVarsNew[v]; pBuffer[Pos++] = 'a' + pVarsNew[v];
...@@ -253,7 +239,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -253,7 +239,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
pBuffer[Pos++] = ')'; pBuffer[Pos++] = ')';
return Pos; return Pos;
} }
if ( Cof0[v] == ~0 ) if ( Cof0[v] == ~0 ) // !(ax)
{ {
pBuffer[Pos++] = '!'; pBuffer[Pos++] = '!';
pBuffer[Pos++] = '('; pBuffer[Pos++] = '(';
...@@ -262,7 +248,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -262,7 +248,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
pBuffer[Pos++] = ')'; pBuffer[Pos++] = ')';
return Pos; return Pos;
} }
if ( Cof1[v] == 0 ) if ( Cof1[v] == 0 ) // !ax
{ {
pBuffer[Pos++] = '('; pBuffer[Pos++] = '(';
pBuffer[Pos++] = '!'; pBuffer[Pos++] = '!';
...@@ -271,7 +257,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -271,7 +257,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
pBuffer[Pos++] = ')'; pBuffer[Pos++] = ')';
return Pos; return Pos;
} }
if ( Cof1[v] == ~0 ) if ( Cof1[v] == ~0 ) // !(!ax)
{ {
pBuffer[Pos++] = '!'; pBuffer[Pos++] = '!';
pBuffer[Pos++] = '('; pBuffer[Pos++] = '(';
...@@ -281,7 +267,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -281,7 +267,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
pBuffer[Pos++] = ')'; pBuffer[Pos++] = ')';
return Pos; return Pos;
} }
if ( Cof0[v] == ~Cof1[v] ) if ( Cof0[v] == ~Cof1[v] ) // a^x
{ {
pBuffer[Pos++] = '['; pBuffer[Pos++] = '[';
pBuffer[Pos++] = 'a' + pVarsNew[v]; pBuffer[Pos++] = 'a' + pVarsNew[v];
...@@ -290,6 +276,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -290,6 +276,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
return Pos; return Pos;
} }
} }
// decompose on the input side
for ( v = 0; v < nVarsNew; v++ ) for ( v = 0; v < nVarsNew; v++ )
for ( u = v+1; u < nVarsNew; u++ ) for ( u = v+1; u < nVarsNew; u++ )
{ {
...@@ -338,7 +325,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars ...@@ -338,7 +325,7 @@ int Dau_DsdPerform_rec( word t, char * pBuffer, int Pos, int * pVars, int nVars
return Pos; return Pos;
} }
} }
// look for MUX // find best variable for MUX decomposition
vBest = -1; vBest = -1;
CountBest = 10; CountBest = 10;
for ( v = 0; v < nVarsNew; v++ ) for ( v = 0; v < nVarsNew; v++ )
......
Markdown is supported
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