Commit ce3f8cb1 by Alan Mishchenko

Improvements to the truth table computations.

parent 42e767c2
This diff was suppressed by a .gitattributes entry.
...@@ -202,10 +202,10 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose ) ...@@ -202,10 +202,10 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
{ {
for ( i = 0; i < p->nFuncs; i++ ) for ( i = 0; i < p->nFuncs; i++ )
{ {
extern void Abc_TtConfactorTest( word * pTruth, int nVars, int i ); extern void Abc_TtCofactorTest( word * pTruth, int nVars, int i );
if ( fVerbose ) if ( fVerbose )
printf( "%7d : ", i ); printf( "%7d : ", i );
Abc_TtConfactorTest( p->pFuncs[i], p->nVars, i ); Abc_TtCofactorTest( p->pFuncs[i], p->nVars, i );
if ( fVerbose ) if ( fVerbose )
Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" ); Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
} }
......
...@@ -943,43 +943,43 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar ...@@ -943,43 +943,43 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar
word * pMasks = PPMasks[iVar][jVar]; word * pMasks = PPMasks[iVar][jVar];
int shift = (1 << jVar) - (1 << iVar); int shift = (1 << jVar) - (1 << iVar);
pTruth[0] = (pTruth[0] & pMasks[0]) | ((pTruth[0] & pMasks[1]) << shift) | ((pTruth[0] & pMasks[2]) >> shift); pTruth[0] = (pTruth[0] & pMasks[0]) | ((pTruth[0] & pMasks[1]) << shift) | ((pTruth[0] & pMasks[2]) >> shift);
return;
} }
else if ( jVar <= 5 )
{ {
if ( jVar <= 5 ) word * pMasks = PPMasks[iVar][jVar];
{ int nWords = Abc_TtWordNum(nVars);
word * pMasks = PPMasks[iVar][jVar]; int w, shift = (1 << jVar) - (1 << iVar);
int nWords = Abc_TtWordNum(nVars); for ( w = 0; w < nWords; w++ )
int w, shift = (1 << jVar) - (1 << iVar); pTruth[w] = (pTruth[w] & pMasks[0]) | ((pTruth[w] & pMasks[1]) << shift) | ((pTruth[w] & pMasks[2]) >> shift);
for ( w = 0; w < nWords; w++ ) return;
pTruth[w] = (pTruth[w] & pMasks[0]) | ((pTruth[w] & pMasks[1]) << shift) | ((pTruth[w] & pMasks[2]) >> shift); }
} if ( iVar <= 5 && jVar > 5 )
else if ( iVar <= 5 && jVar > 5 ) {
{ word low2High, high2Low;
word low2High, high2Low; word * pLimit = pTruth + Abc_TtWordNum(nVars);
word * pLimit = pTruth + Abc_TtWordNum(nVars); int j, jStep = Abc_TtWordNum(jVar);
int j, jStep = Abc_TtWordNum(jVar); int shift = 1 << iVar;
int shift = 1 << iVar; for ( ; pTruth < pLimit; pTruth += 2*jStep )
for ( ; pTruth < pLimit; pTruth += 2*jStep ) for ( j = 0; j < jStep; j++ )
for ( j = 0; j < jStep; j++ ) {
{ low2High = (pTruth[j] & s_Truths6[iVar]) >> shift;
low2High = (pTruth[j] & s_Truths6[iVar]) >> shift; high2Low = (pTruth[j+jStep] << shift) & s_Truths6[iVar];
high2Low = (pTruth[j+jStep] << shift) & s_Truths6[iVar]; pTruth[j] = (pTruth[j] & ~s_Truths6[iVar]) | high2Low;
pTruth[j] = (pTruth[j] & ~s_Truths6[iVar]) | high2Low; pTruth[j+jStep] = (pTruth[j+jStep] & s_Truths6[iVar]) | low2High;
pTruth[j+jStep] = (pTruth[j+jStep] & s_Truths6[iVar]) | low2High; }
} return;
}
else
{
word * pLimit = pTruth + Abc_TtWordNum(nVars);
int i, iStep = Abc_TtWordNum(iVar);
int j, jStep = Abc_TtWordNum(jVar);
for ( ; pTruth < pLimit; pTruth += 2*jStep )
for ( i = 0; i < jStep; i += 2*iStep )
for ( j = 0; j < iStep; j++ )
ABC_SWAP( word, pTruth[iStep + i + j], pTruth[jStep + i + j] );
}
} }
{
word * pLimit = pTruth + Abc_TtWordNum(nVars);
int i, iStep = Abc_TtWordNum(iVar);
int j, jStep = Abc_TtWordNum(jVar);
for ( ; pTruth < pLimit; pTruth += 2*jStep )
for ( i = 0; i < jStep; i += 2*iStep )
for ( j = 0; j < iStep; j++ )
ABC_SWAP( word, pTruth[iStep + i + j], pTruth[jStep + i + j] );
return;
}
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -1037,16 +1037,18 @@ static inline void Abc_TtCountOnesInCofs( word * pTruth, int nVars, int * pStore ...@@ -1037,16 +1037,18 @@ static inline void Abc_TtCountOnesInCofs( word * pTruth, int nVars, int * pStore
{ {
word Temp; word Temp;
int i, k, Counter, nWords; int i, k, Counter, nWords;
memset( pStore, 0, sizeof(int) * nVars );
if ( nVars <= 6 ) if ( nVars <= 6 )
{ {
for ( i = 0; i < nVars; i++ ) for ( i = 0; i < nVars; i++ )
if ( pTruth[0] & s_Truths6Neg[i] ) if ( pTruth[0] & s_Truths6Neg[i] )
pStore[i] = Abc_TtCountOnes( pTruth[0] & s_Truths6Neg[i] ); pStore[i] = Abc_TtCountOnes( pTruth[0] & s_Truths6Neg[i] );
else
pStore[i] = 0;
return; return;
} }
assert( nVars > 6 ); assert( nVars > 6 );
nWords = Abc_TtWordNum( nVars ); nWords = Abc_TtWordNum( nVars );
memset( pStore, 0, sizeof(int) * nVars );
for ( k = 0; k < nWords; k++ ) for ( k = 0; k < nWords; k++ )
{ {
// count 1's for the first six variables // count 1's for the first six variables
...@@ -1110,16 +1112,21 @@ static inline void Abc_TtCountOnesInCofsSlow( word * pTruth, int nVars, int * pS ...@@ -1110,16 +1112,21 @@ static inline void Abc_TtCountOnesInCofsSlow( word * pTruth, int nVars, int * pS
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pCanonPerm ) static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pCanonPerm, int * pStoreOut )
{ {
extern int Abc_TtCountOnesInCofsFast( word * pTruth, int nVars, int * pStore ); extern int Abc_TtCountOnesInCofsFast( word * pTruth, int nVars, int * pStore );
int pStore[16]; int fOldSwap = 0;
// int pStore2[16]; int pStoreIn[17];
int * pStore = pStoreOut ? pStoreOut : pStoreIn;
// int pStore2[17];
int nWords = Abc_TtWordNum( nVars ); int nWords = Abc_TtWordNum( nVars );
int i, k, BestK, Temp, nOnes;//, nSwaps = 0;//, fChange; int i, Temp, nOnes;//, fChange;//, nSwaps = 0;//;
int k, BestK;
unsigned uCanonPhase = 0; unsigned uCanonPhase = 0;
assert( nVars <= 16 ); assert( nVars <= 16 );
for ( i = 0; i < nVars; i++ )
pCanonPerm[i] = i;
// normalize polarity // normalize polarity
nOnes = Abc_TtCountOnesInTruth( pTruth, nVars ); nOnes = Abc_TtCountOnesInTruth( pTruth, nVars );
if ( nOnes > nWords * 32 ) if ( nOnes > nWords * 32 )
...@@ -1130,6 +1137,7 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC ...@@ -1130,6 +1137,7 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
} }
// normalize phase // normalize phase
Abc_TtCountOnesInCofs( pTruth, nVars, pStore ); Abc_TtCountOnesInCofs( pTruth, nVars, pStore );
pStore[nVars] = nOnes;
// Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore ); // Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore );
// Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore2 ); // Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore2 );
...@@ -1144,62 +1152,71 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC ...@@ -1144,62 +1152,71 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
uCanonPhase |= (1 << i); uCanonPhase |= (1 << i);
pStore[i] = nOnes - pStore[i]; pStore[i] = nOnes - pStore[i];
} }
/*
do { if ( fOldSwap )
fChange = 0; {
for ( i = 0; i < nVars-1; i++ ) int fChange;
{ do {
if ( pStore[i] <= pStore[i+1] ) fChange = 0;
continue; for ( i = 0; i < nVars-1; i++ )
{
// if ( pStore[i] <= pStore[i+1] )
if ( pStore[i] >= pStore[i+1] )
continue;
Temp = pCanonPerm[i]; Temp = pCanonPerm[i];
pCanonPerm[i] = pCanonPerm[i+1]; pCanonPerm[i] = pCanonPerm[i+1];
pCanonPerm[i+1] = Temp; pCanonPerm[i+1] = Temp;
Temp = pStore[i]; Temp = pStore[i];
pStore[i] = pStore[i+1]; pStore[i] = pStore[i+1];
pStore[i+1] = Temp; pStore[i+1] = Temp;
if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> (i+1)) & 1) ) if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> (i+1)) & 1) )
{ {
uCanonPhase ^= (1 << i); uCanonPhase ^= (1 << i);
uCanonPhase ^= (1 << (i+1)); uCanonPhase ^= (1 << (i+1));
}
Abc_TtSwapAdjacent( pTruth, nWords, i );
fChange = 1;
// nSwaps++;
} }
Abc_TtSwapAdjacent( pTruth, nWords, i ); } while ( fChange );
fChange = 1; }
// nSwaps++; else
}
} while ( fChange );
*/
for ( i = 0; i < nVars - 1; i++ )
{ {
BestK = i + 1; for ( i = 0; i < nVars - 1; i++ )
for ( k = i + 2; k < nVars; k++ ) {
if ( pStore[BestK] > pStore[k] ) BestK = i + 1;
BestK = k; for ( k = i + 2; k < nVars; k++ )
if ( pStore[BestK] >= pStore[i] ) // if ( pStore[BestK] > pStore[k] )
continue; if ( pStore[BestK] < pStore[k] )
BestK = k;
// if ( pStore[i] <= pStore[BestK] )
if ( pStore[i] >= pStore[BestK] )
continue;
Temp = pCanonPerm[i]; Temp = pCanonPerm[i];
pCanonPerm[i] = pCanonPerm[BestK]; pCanonPerm[i] = pCanonPerm[BestK];
pCanonPerm[BestK] = Temp; pCanonPerm[BestK] = Temp;
Temp = pStore[i]; Temp = pStore[i];
pStore[i] = pStore[BestK]; pStore[i] = pStore[BestK];
pStore[BestK] = Temp; pStore[BestK] = Temp;
if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> BestK) & 1) ) if ( ((uCanonPhase >> i) & 1) != ((uCanonPhase >> BestK) & 1) )
{ {
uCanonPhase ^= (1 << i); uCanonPhase ^= (1 << i);
uCanonPhase ^= (1 << BestK); uCanonPhase ^= (1 << BestK);
}
Abc_TtSwapVars( pTruth, nVars, i, BestK );
// nSwaps++;
} }
Abc_TtSwapVars( pTruth, nVars, i, BestK );
// nSwaps++;
} }
/*
printf( "%d ", nSwaps );
// printf( "%d ", nSwaps );
/*
printf( "Minterms: " ); printf( "Minterms: " );
for ( i = 0; i < nVars; i++ ) for ( i = 0; i < nVars; i++ )
printf( "%d ", pStore[i] ); printf( "%d ", pStore[i] );
......
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