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 )
{
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 )
printf( "%7d : ", i );
Abc_TtConfactorTest( p->pFuncs[i], p->nVars, i );
Abc_TtCofactorTest( p->pFuncs[i], p->nVars, i );
if ( fVerbose )
Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
}
......
......@@ -943,9 +943,8 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar
word * pMasks = PPMasks[iVar][jVar];
int shift = (1 << jVar) - (1 << iVar);
pTruth[0] = (pTruth[0] & pMasks[0]) | ((pTruth[0] & pMasks[1]) << shift) | ((pTruth[0] & pMasks[2]) >> shift);
return;
}
else
{
if ( jVar <= 5 )
{
word * pMasks = PPMasks[iVar][jVar];
......@@ -953,8 +952,9 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar
int w, shift = (1 << jVar) - (1 << iVar);
for ( w = 0; w < nWords; w++ )
pTruth[w] = (pTruth[w] & pMasks[0]) | ((pTruth[w] & pMasks[1]) << shift) | ((pTruth[w] & pMasks[2]) >> shift);
return;
}
else if ( iVar <= 5 && jVar > 5 )
if ( iVar <= 5 && jVar > 5 )
{
word low2High, high2Low;
word * pLimit = pTruth + Abc_TtWordNum(nVars);
......@@ -968,8 +968,8 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar
pTruth[j] = (pTruth[j] & ~s_Truths6[iVar]) | high2Low;
pTruth[j+jStep] = (pTruth[j+jStep] & s_Truths6[iVar]) | low2High;
}
return;
}
else
{
word * pLimit = pTruth + Abc_TtWordNum(nVars);
int i, iStep = Abc_TtWordNum(iVar);
......@@ -978,7 +978,7 @@ static inline void Abc_TtSwapVars( word * pTruth, int nVars, int iVar, int jVar
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;
}
}
......@@ -1037,16 +1037,18 @@ static inline void Abc_TtCountOnesInCofs( word * pTruth, int nVars, int * pStore
{
word Temp;
int i, k, Counter, nWords;
memset( pStore, 0, sizeof(int) * nVars );
if ( nVars <= 6 )
{
for ( i = 0; i < nVars; i++ )
if ( pTruth[0] & s_Truths6Neg[i] )
pStore[i] = Abc_TtCountOnes( pTruth[0] & s_Truths6Neg[i] );
else
pStore[i] = 0;
return;
}
assert( nVars > 6 );
nWords = Abc_TtWordNum( nVars );
memset( pStore, 0, sizeof(int) * nVars );
for ( k = 0; k < nWords; k++ )
{
// count 1's for the first six variables
......@@ -1110,16 +1112,21 @@ static inline void Abc_TtCountOnesInCofsSlow( word * pTruth, int nVars, int * pS
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 );
int pStore[16];
// int pStore2[16];
int fOldSwap = 0;
int pStoreIn[17];
int * pStore = pStoreOut ? pStoreOut : pStoreIn;
// int pStore2[17];
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;
assert( nVars <= 16 );
for ( i = 0; i < nVars; i++ )
pCanonPerm[i] = i;
// normalize polarity
nOnes = Abc_TtCountOnesInTruth( pTruth, nVars );
if ( nOnes > nWords * 32 )
......@@ -1130,6 +1137,7 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
}
// normalize phase
Abc_TtCountOnesInCofs( pTruth, nVars, pStore );
pStore[nVars] = nOnes;
// Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore );
// Abc_TtCountOnesInCofsFast( pTruth, nVars, pStore2 );
......@@ -1144,12 +1152,16 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
uCanonPhase |= (1 << i);
pStore[i] = nOnes - pStore[i];
}
/*
if ( fOldSwap )
{
int fChange;
do {
fChange = 0;
for ( i = 0; i < nVars-1; i++ )
{
if ( pStore[i] <= pStore[i+1] )
// if ( pStore[i] <= pStore[i+1] )
if ( pStore[i] >= pStore[i+1] )
continue;
Temp = pCanonPerm[i];
......@@ -1167,18 +1179,21 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
}
Abc_TtSwapAdjacent( pTruth, nWords, i );
fChange = 1;
// nSwaps++;
// nSwaps++;
}
} while ( fChange );
*/
}
else
{
for ( i = 0; i < nVars - 1; i++ )
{
BestK = i + 1;
for ( k = i + 2; k < nVars; k++ )
if ( pStore[BestK] > pStore[k] )
// if ( pStore[BestK] > pStore[k] )
if ( pStore[BestK] < pStore[k] )
BestK = k;
if ( pStore[BestK] >= pStore[i] )
// if ( pStore[i] <= pStore[BestK] )
if ( pStore[i] >= pStore[BestK] )
continue;
Temp = pCanonPerm[i];
......@@ -1195,11 +1210,13 @@ static inline unsigned Abc_TtSemiCanonicize( word * pTruth, int nVars, char * pC
uCanonPhase ^= (1 << BestK);
}
Abc_TtSwapVars( pTruth, nVars, i, BestK );
// nSwaps++;
// nSwaps++;
}
/*
printf( "%d ", nSwaps );
}
// printf( "%d ", nSwaps );
/*
printf( "Minterms: " );
for ( i = 0; i < nVars; 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