Commit efdd26f8 by Alan Mishchenko

Scalable SOP manipulation package.

parent 5f77e7ae
......@@ -867,6 +867,10 @@ SOURCE=.\src\base\pla\plaCom.c
# End Source File
# Begin Source File
SOURCE=.\src\base\pla\plaFxch.c
# End Source File
# Begin Source File
SOURCE=.\src\base\pla\plaHash.c
# End Source File
# Begin Source File
......@@ -883,6 +887,10 @@ SOURCE=.\src\base\pla\plaRead.c
# End Source File
# Begin Source File
SOURCE=.\src\base\pla\plaSimple.c
# End Source File
# Begin Source File
SOURCE=.\src\base\pla\plaWrite.c
# End Source File
# End Group
......
......@@ -1091,12 +1091,12 @@ void Fx_ManUpdate( Fx_Man_t * p, int iDiv, int * fWarning )
if ( Vec_IntSize(vDiv) == 2 || fCompl )
{
Vec_IntPush( vCube, Abc_Var2Lit(iVarNew, 1) );
Vec_IntPush( vLitN, Vec_WecLevelId(p->vCubes, vCube) );
Vec_IntPush( vLitN, Vec_WecLevelId(p->vCubes, vCube) ); // MAKE SURE vCube IS SORTED BY ID
}
else
{
Vec_IntPush( vCube, Abc_Var2Lit(iVarNew, 0) );
Vec_IntPush( vLitP, Vec_WecLevelId(p->vCubes, vCube) );
Vec_IntPush( vLitP, Vec_WecLevelId(p->vCubes, vCube) ); // MAKE SURE vCube IS SORTED BY ID
}
p->nLits -= Vec_IntSize(vDiv) + Vec_IntSize(vCube2) - 2;
// remove second cube
......@@ -1106,6 +1106,8 @@ void Fx_ManUpdate( Fx_Man_t * p, int iDiv, int * fWarning )
assert( k == Vec_IntSize(p->vCubesD) / 2 );
Vec_IntShrink( p->vCubesD, k );
Vec_IntSort( p->vCubesD, 0 );
//Vec_IntSort( vLitN, 0 );
//Vec_IntSort( vLitP, 0 );
// add cost of single-cube divisors
Fx_ManForEachCubeVec( p->vCubesS, p->vCubes, vCube, i )
......
SRC += src/base/pla/plaCom.c \
src/base/pla/plaHash.c \
src/base/pla/plaFxch.c \
src/base/pla/plaMan.c \
src/base/pla/plaMerge.c \
src/base/pla/plaSimple.c \
src/base/pla/plaRead.c \
src/base/pla/plaWrite.c
......@@ -74,20 +74,33 @@ struct Pla_Man_t_
Vec_Int_t vHashes; // hash values
Vec_Wrd_t vInBits; // input bits
Vec_Wrd_t vOutBits; // output bits
Vec_Wec_t vLits; // cubes as interger arrays
Vec_Wec_t vOccurs; // occurent counters for the literals
Vec_Wec_t vCubeLits; // cubes as interger arrays
Vec_Wec_t vOccurs; // occurence counters for the literals
Vec_Int_t vDivs; // divisor definitions
};
static inline char * Pla_ManName( Pla_Man_t * p ) { return p->pName; }
static inline int Pla_ManInNum( Pla_Man_t * p ) { return p->nIns; }
static inline int Pla_ManOutNum( Pla_Man_t * p ) { return p->nOuts; }
static inline int Pla_ManCubeNum( Pla_Man_t * p ) { return Vec_IntSize( &p->vCubes ); }
static inline int Pla_ManDivNum( Pla_Man_t * p ) { return Vec_IntSize( &p->vDivs ); }
static inline word * Pla_CubeIn( Pla_Man_t * p, int i ) { return Vec_WrdEntryP(&p->vInBits, i * p->nInWords); }
static inline word * Pla_CubeOut( Pla_Man_t * p, int i ) { return Vec_WrdEntryP(&p->vOutBits, i * p->nOutWords); }
static inline int Pla_CubeGetLit( word * p, int k ) { return (int)(p[k>>5] >> ((k<<1) & 63)) & 3; }
static inline void Pla_CubeSetLit( word * p, int k, Pla_Lit_t d ) { p[k>>5] |= (((word)d)<<((k<<1) & 63)); }
static inline void Pla_CubeXorLit( word * p, int k, Pla_Lit_t d ) { p[k>>5] ^= (((word)d)<<((k<<1) & 63)); }
static inline int Pla_CubeNum( int hCube ) { return hCube >> 8; }
static inline int Pla_CubeLit( int hCube ) { return hCube & 0xFF; }
static inline int Pla_CubeHandle( int iCube, int iLit ) { assert( !(iCube >> 24) && !(iLit >> 8) ); return iCube << 8 | iLit; }
// read/write/flip i-th bit of a bit string table
static inline int Pla_TtGetBit( word * p, int i ) { return (int)(p[i>>6] >> (i & 63)) & 1; }
static inline void Pla_TtSetBit( word * p, int i ) { p[i>>6] |= (((word)1)<<(i & 63)); }
static inline void Pla_TtXorBit( word * p, int i ) { p[i>>6] ^= (((word)1)<<(i & 63)); }
// read/write/flip i-th literal in a cube
static inline int Pla_CubeGetLit( word * p, int i ) { return (int)(p[i>>5] >> ((i<<1) & 63)) & 3; }
static inline void Pla_CubeSetLit( word * p, int i, Pla_Lit_t d ) { p[i>>5] |= (((word)d)<<((i<<1) & 63)); }
static inline void Pla_CubeXorLit( word * p, int i, Pla_Lit_t d ) { p[i>>5] ^= (((word)d)<<((i<<1) & 63)); }
////////////////////////////////////////////////////////////////////////
......@@ -170,6 +183,23 @@ static inline int Pla_CubesAreConsensus( word * p, word * q, int nWords, int * p
}
return fFound;
}
static inline int Pla_TtCountOnesOne( word x )
{
x = x - ((x >> 1) & ABC_CONST(0x5555555555555555));
x = (x & ABC_CONST(0x3333333333333333)) + ((x >> 2) & ABC_CONST(0x3333333333333333));
x = (x + (x >> 4)) & ABC_CONST(0x0F0F0F0F0F0F0F0F);
x = x + (x >> 8);
x = x + (x >> 16);
x = x + (x >> 32);
return (int)(x & 0xFF);
}
static inline int Pla_TtCountOnes( word * p, int nWords )
{
int i, Count = 0;
for ( i = 0; i < nWords; i++ )
Count += Pla_TtCountOnesOne( p[i] );
return Count;
}
/**Function*************************************************************
......@@ -202,8 +232,9 @@ static inline void Pla_ManFree( Pla_Man_t * p )
Vec_IntErase( &p->vHashes );
Vec_WrdErase( &p->vInBits );
Vec_WrdErase( &p->vOutBits );
Vec_WecErase( &p->vLits );
Vec_WecErase( &p->vCubeLits );
Vec_WecErase( &p->vOccurs );
Vec_IntErase( &p->vDivs );
ABC_FREE( p->pName );
ABC_FREE( p->pSpec );
ABC_FREE( p );
......@@ -226,26 +257,33 @@ static inline int Pla_ManLitOutNum( Pla_Man_t * p )
}
static inline void Pla_ManPrintStats( Pla_Man_t * p, int fVerbose )
{
printf( "%-16s : ", p->pName );
printf( "%-16s : ", Pla_ManName(p) );
printf( "In =%4d ", Pla_ManInNum(p) );
printf( "Out =%4d ", Pla_ManOutNum(p) );
printf( "Cube =%8d ", Pla_ManCubeNum(p) );
printf( "LitIn =%8d ", Pla_ManLitInNum(p) );
printf( "LitOut =%8d ", Pla_ManLitOutNum(p) );
printf( "Div =%6d ", Pla_ManDivNum(p) );
printf( "\n" );
}
/*=== plaFxch.c ========================================================*/
extern int Pla_ManPerformFxch( Pla_Man_t * p );
/*=== plaHash.c ========================================================*/
extern int Pla_ManHashDist1NumTest( Pla_Man_t * p );
extern void Pla_ManComputeDist1Test( Pla_Man_t * p );
/*=== plaMan.c ========================================================*/
extern Pla_Man_t * Pla_ManPrimeDetector( int nVars );
extern Vec_Bit_t * Pla_ManPrimesTable( int nVars );
extern Pla_Man_t * Pla_ManPrimesDetector( int nVars );
extern Pla_Man_t * Pla_ManGenerate( int nIns, int nOuts, int nCubes, int fVerbose );
extern void Pla_ManConvertFromBits( Pla_Man_t * p );
extern void Pla_ManConvertToBits( Pla_Man_t * p );
extern int Pla_ManDist1NumTest( Pla_Man_t * p );
/*=== plaMerge.c ========================================================*/
extern int Pla_ManDist1Merge( Pla_Man_t * p );
/*=== plaSimple.c ========================================================*/
extern int Pla_ManFxPerformSimple( int nVars );
/*=== plaRead.c ========================================================*/
extern Pla_Man_t * Pla_ReadPla( char * pFileName );
/*=== plaWrite.c ========================================================*/
......
......@@ -359,7 +359,7 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
}
}
if ( fPrimes )
p = Pla_ManPrimeDetector( nInputs );
p = Pla_ManPrimesDetector( nInputs );
else
{
Gia_ManRandom( 1 );
......@@ -444,12 +444,23 @@ usage:
int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Pla_Man_t * p = Pla_AbcGetMan(pAbc);
int c, fVerbose = 0;
int c, nVars = 4, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
{
switch ( c )
{
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
nVars = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nVars < 0 )
goto usage;
break;
case 'v':
fVerbose ^= 1;
break;
......@@ -459,18 +470,22 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage;
}
}
/*
if ( p == NULL )
{
Abc_Print( 1, "Abc_CommandTest(): There is no current design.\n" );
return 0;
}
Pla_ManHashDist1NumTest( p );
*/
//Pla_ManFxPerformSimple( nVars );
//Pla_ManConvertFromBits( p );
//Pla_ManConvertToBits( p );
Pla_ManPerformFxch( p );
return 0;
usage:
Abc_Print( -2, "usage: |test [-vh]\n" );
Abc_Print( -2, "usage: |test [-N num] [-vh]\n" );
Abc_Print( -2, "\t experiments with SOPs\n" );
Abc_Print( -2, "\t-N num : the number of variables [default = %d]\n", nVars );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
......
......@@ -63,7 +63,7 @@ static unsigned s_PlaHashValues[PLA_HASH_VALUE_NUM] =
0xd0fa29f1,0x804cac5e,0x2c226798,0x462f624c,0xad05b377,0x22924fcd,0xfbea205c,0x1b47586d
};
static inline int Pla_HashValue( int i ) { assert( i >= 0 && i < PLA_HASH_VALUE_NUM ); return s_PlaHashValues[i] & 0xFFFFFF; }
static inline int Pla_HashValue( int i ) { assert( i >= 0 && i < PLA_HASH_VALUE_NUM ); return s_PlaHashValues[i] & 0x3FFFFFF; }
#define PLA_LIT_UNUSED 0xFFFF
......@@ -107,7 +107,7 @@ static inline Tab_Obj_t * Tab_ManEntry( Tab_Man_t * p, int i ) { return i ? p
static inline Tab_Man_t * Tab_ManAlloc( int LogSize, Pla_Man_t * pMan )
{
Tab_Man_t * p = ABC_CALLOC( Tab_Man_t, 1 );
assert( LogSize >= 4 && LogSize <= 24 );
assert( LogSize >= 4 && LogSize <= 26 );
p->SizeMask = (1 << LogSize) - 1;
p->pBins = ABC_CALLOC( Tab_Obj_t, p->SizeMask + 1 );
p->nBins = 1;
......@@ -119,11 +119,12 @@ static inline void Tab_ManFree( Tab_Man_t * p )
ABC_FREE( p->pBins );
ABC_FREE( p );
}
static inline void Tab_ManHashInsert( Tab_Man_t * p, int Value, int iCube )
static inline void Tab_ManHashInsert( Tab_Man_t * p, int Value, int iCube, int iVar )
{
Tab_Obj_t * pBin = Tab_ManBin( p, Value );
Tab_Obj_t * pCell = p->pBins + p->nBins;
pCell->Cube = iCube;
pCell->VarA = iVar;
pCell->Next = pBin->Table;
pBin->Table = p->nBins++;
}
......@@ -131,10 +132,17 @@ static inline int Tab_ManHashLookup( Tab_Man_t * p, int Value, Vec_Int_t * vCube
{
Tab_Obj_t * pEnt, * pBin = Tab_ManBin( p, Value );
for ( pEnt = Tab_ManEntry(p, pBin->Table); pEnt; pEnt = Tab_ManEntry(p, pEnt->Next) )
if ( Vec_IntEqual( Vec_WecEntry(&p->pMan->vLits, pEnt->Cube), vCube ) )
if ( Vec_IntEqual( Vec_WecEntry(&p->pMan->vCubeLits, pEnt->Cube), vCube ) )
return 1;
return 0;
}
static inline void Tab_ManHashCollect( Tab_Man_t * p, int iBin, Vec_Int_t * vEntries )
{
Tab_Obj_t * pEnt, * pBin = Tab_ManBin( p, iBin );
Vec_IntClear( vEntries );
for ( pEnt = Tab_ManEntry(p, pBin->Table); pEnt; pEnt = Tab_ManEntry(p, pEnt->Next) )
Vec_IntPushTwo( vEntries, pEnt->Cube, pEnt->VarA );
}
/**Function*************************************************************
......@@ -160,11 +168,11 @@ void Pla_ManHashCubes( Pla_Man_t * p, Tab_Man_t * pTab )
Vec_Int_t * vCube; int i, Value;
Vec_IntClear( &p->vHashes );
Vec_IntGrow( &p->vHashes, Pla_ManCubeNum(p) );
Vec_WecForEachLevel( &p->vLits, vCube, i )
Vec_WecForEachLevel( &p->vCubeLits, vCube, i )
{
Value = Pla_CubeHashValue(vCube);
Vec_IntPush( &p->vHashes, Value );
Tab_ManHashInsert( pTab, Value, i );
Tab_ManHashInsert( pTab, Value, i, PLA_LIT_UNUSED );
}
}
int Pla_ManHashDistance1( Pla_Man_t * p )
......@@ -174,11 +182,11 @@ int Pla_ManHashDistance1( Pla_Man_t * p )
Vec_Int_t * vCubeCopy = Vec_IntAlloc( p->nIns );
int nBits = Abc_Base2Log( Pla_ManCubeNum(p) ) + 2;
int i, k, Lit, Value, ValueCopy, Count = 0;
assert( nBits <= 24 );
assert( nBits <= 26 );
pTab = Tab_ManAlloc( nBits, p );
Pla_ManConvertFromBits( p );
Pla_ManHashCubes( p, pTab );
Vec_WecForEachLevel( &p->vLits, vCube, i )
Vec_WecForEachLevel( &p->vCubeLits, vCube, i )
{
Vec_IntClear( vCubeCopy );
Vec_IntAppend( vCubeCopy, vCube );
......@@ -210,6 +218,126 @@ int Pla_ManHashDist1NumTest( Pla_Man_t * p )
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Pla_PrintCube( Vec_Int_t * vLits, int nVars, int iVar )
{
int v, Lit;
Vec_Str_t * vStr = Vec_StrStart( nVars + 1 );
Vec_StrFill( vStr, nVars, '-' );
Vec_IntForEachEntry( vLits, Lit, v )
Vec_StrWriteEntry( vStr, Abc_Lit2Var(Lit), (char)(Abc_LitIsCompl(Lit) ? '0' : '1') );
fprintf( stdout, "%s %d\n", Vec_StrArray(vStr), iVar );
Vec_StrFree( vStr );
}
void Pla_ManHashCubes2( Pla_Man_t * p, Tab_Man_t * pTab )
{
Vec_Int_t * vCube;
int i, v, Lit, Value;
Vec_WecForEachLevel( &p->vCubeLits, vCube, i )
{
Value = Pla_CubeHashValue(vCube);
Vec_IntForEachEntry( vCube, Lit, v )
{
Value -= Pla_HashValue(Lit);
Tab_ManHashInsert( pTab, Value, i, v );
Value += Pla_HashValue(Lit);
}
}
}
void Vec_IntCopySkip( Vec_Int_t * vCube, int iVar, Vec_Int_t * vRes )
{
int i;
Vec_IntClear( vRes );
for ( i = 0; i < Vec_IntSize(vCube); i++ )
if ( i != iVar )
Vec_IntPush( vRes, Vec_IntEntry(vCube, i) );
}
Vec_Int_t * Pla_ManComputeDistance1Int( Pla_Man_t * p )
{
Tab_Man_t * pTab;
Vec_Int_t * vCube1, * vCube2;
Vec_Int_t * vTemp1 = Vec_IntAlloc( 100 );
Vec_Int_t * vTemp2 = Vec_IntAlloc( 100 );
Vec_Int_t * vPairs = Vec_IntAlloc( 1000 );
Vec_Int_t * vCounts = Vec_IntStart( Vec_WecSize(&p->vCubeLits) );
Vec_Int_t * vEntries = Vec_IntAlloc( p->nIns );
int nBits = Abc_Base2Log( Vec_WecSizeSize(&p->vCubeLits) ) + 2;
int v, i, k, Count = 0;
int iCube1, iCube2, iVar1, iVar2;
assert( nBits <= 26 );
pTab = Tab_ManAlloc( nBits, p );
//Pla_ManConvertFromBits( p );
Pla_ManHashCubes2( p, pTab );
// iterate through the hash bins
for ( v = 0; v <= pTab->SizeMask; v++ )
{
Tab_ManHashCollect( pTab, v, vEntries );
for ( i = 0; i < Vec_IntSize(vEntries)/2; i++ )
for ( k = i+1; k < Vec_IntSize(vEntries)/2; k++ )
{
iCube1 = Vec_IntEntry(vEntries, 2*i);
iCube2 = Vec_IntEntry(vEntries, 2*k);
iVar1 = Vec_IntEntry(vEntries, 2*i+1);
iVar2 = Vec_IntEntry(vEntries, 2*k+1);
vCube1 = Vec_WecEntry(&p->vCubeLits, iCube1);
vCube2 = Vec_WecEntry(&p->vCubeLits, iCube2);
/*
Pla_PrintCube( vCube1, p->nIns, iVar1 );
Pla_PrintCube( vCube2, p->nIns, iVar2 );
printf( "\n" );
*/
if ( Vec_IntSize(vCube1) != Vec_IntSize(vCube2) )
continue;
Vec_IntCopySkip( vCube1, iVar1, vTemp1 );
Vec_IntCopySkip( vCube2, iVar2, vTemp2 );
if ( !Vec_IntEqual( vTemp1, vTemp2 ) )
continue;
printf( "%d %d ", iCube1, iCube2 );
Vec_IntPushTwo( vPairs, iCube1, iVar1 );
Vec_IntPushTwo( vPairs, iCube2, iVar2 );
Vec_IntAddToEntry( vCounts, iCube1, 1 );
Vec_IntAddToEntry( vCounts, iCube2, 1 );
}
}
Vec_IntPrint( vCounts );
Vec_IntFree( vCounts );
Vec_IntFree( vTemp1 );
Vec_IntFree( vTemp2 );
Vec_IntFree( vEntries );
Tab_ManFree( pTab );
return vPairs;
}
Vec_Int_t * Pla_ManComputeDistance1( Pla_Man_t * p )
{
abctime clk = Abc_Clock();
Vec_Int_t * vPairs = Pla_ManComputeDistance1Int( p );
printf( "Found %d pairs among %d cubes using cube hashing. ", Vec_IntSize(vPairs)/4, Pla_ManCubeNum(p) );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
return vPairs;
}
void Pla_ManComputeDist1Test( Pla_Man_t * p )
{
Vec_Int_t * vPairs;
Pla_ManConvertFromBits( p );
vPairs = Pla_ManComputeDistance1( p );
Vec_IntFree( vPairs );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
......@@ -41,19 +41,28 @@ ABC_NAMESPACE_IMPL_START
SeeAlso []
***********************************************************************/
Vec_Int_t * Pla_GenPrimes( int nVars )
Vec_Bit_t * Pla_ManPrimesTable( int nVars )
{
int i, n, nBits = ( 1 << nVars );
Vec_Bit_t * vMap = Vec_BitStart( nBits );
Vec_Int_t * vPrimes = Vec_IntAlloc( 1000 );
Vec_BitWriteEntry(vMap, 0, 1);
Vec_BitWriteEntry(vMap, 1, 1);
int i, n, nBits = 1 << nVars;
Vec_Bit_t * vMap = Vec_BitStartFull( Abc_MaxInt(64, nBits) );
for ( i = nBits; i < 64; i++ )
Vec_BitWriteEntry( vMap, i, 0 );
Vec_BitShrink( vMap, nBits );
Vec_BitWriteEntry( vMap, 0, 0 );
Vec_BitWriteEntry( vMap, 1, 0 );
for ( n = 2; n < nBits; n++ )
if ( !Vec_BitEntry(vMap, n) )
if ( Vec_BitEntry(vMap, n) )
for ( i = 2*n; i < nBits; i += n )
Vec_BitWriteEntry(vMap, i, 1);
Vec_BitWriteEntry( vMap, i, 0 );
return vMap;
}
Vec_Int_t * Pla_GenPrimes( int nVars )
{
int n, nBits = ( 1 << nVars );
Vec_Int_t * vPrimes = Vec_IntAlloc( 1000 );
Vec_Bit_t * vMap = Pla_ManPrimesTable( nVars );
for ( n = 2; n < nBits; n++ )
if ( !Vec_BitEntry(vMap, n) )
if ( Vec_BitEntry(vMap, n) )
Vec_IntPush( vPrimes, n );
printf( "Primes up to 2^%d = %d\n", nVars, Vec_IntSize(vPrimes) );
// Abc_GenCountHits1( vMap, vPrimes, nVars );
......@@ -75,7 +84,7 @@ Pla_Man_t * Pla_GenFromMinterms( char * pName, Vec_Int_t * vMints, int nVars )
Pla_CubeSetLit( pCube, 0, PLA_LIT_ONE );
return p;
}
Pla_Man_t * Pla_ManPrimeDetector( int nVars )
Pla_Man_t * Pla_ManPrimesDetector( int nVars )
{
char pName[1000];
Pla_Man_t * p;
......@@ -117,10 +126,13 @@ Vec_Bit_t * Pla_GenRandom( int nVars, int nNums, int fNonZero )
}
Pla_Man_t * Pla_ManGenerate( int nInputs, int nOutputs, int nCubes, int fVerbose )
{
Pla_Man_t * p;
Vec_Bit_t * vBits;
int i, k, Count;
word * pCube;
Pla_Man_t * p = Pla_ManAlloc( "rand", nInputs, nOutputs, nCubes );
char Buffer[1000];
sprintf( Buffer, "%s_%d_%d_%d", "rand", nInputs, nOutputs, nCubes );
p = Pla_ManAlloc( Buffer, nInputs, nOutputs, nCubes );
// generate nCube random input minterms
vBits = Pla_GenRandom( nInputs, nCubes, 0 );
for ( i = Count = 0; i < Vec_BitSize(vBits); i++ )
......@@ -167,26 +179,40 @@ Pla_Man_t * Pla_ManGenerate( int nInputs, int nOutputs, int nCubes, int fVerbose
***********************************************************************/
void Pla_ManConvertFromBits( Pla_Man_t * p )
{
word * pCube; int i, k, Lit;
Vec_WecClear( &p->vLits );
Vec_Int_t * vCube;
word * pCube; int i, k, Lit, Count;
Vec_WecClear( &p->vCubeLits );
Vec_WecClear( &p->vOccurs );
Vec_WecInit( &p->vLits, Pla_ManCubeNum(p) );
Vec_WecInit( &p->vCubeLits, Pla_ManCubeNum(p) );
Vec_WecInit( &p->vOccurs, 2*Pla_ManInNum(p) );
Pla_ForEachCubeIn( p, pCube, i )
{
vCube = Vec_WecEntry( &p->vCubeLits, i );
Count = 0;
Pla_CubeForEachLitIn( p, pCube, Lit, k )
if ( Lit != PLA_LIT_DASH )
Count++;
Vec_IntGrow( vCube, Count );
Count = 0;
Pla_CubeForEachLitIn( p, pCube, Lit, k )
if ( Lit != PLA_LIT_DASH )
{
Lit = Abc_Var2Lit( k, Lit == PLA_LIT_ZERO );
Vec_WecPush( &p->vLits, i, Lit );
Vec_WecPush( &p->vCubeLits, i, Lit );
// Vec_WecPush( &p->vOccurs, Lit, Pla_CubeHandle(i, Count++) );
Vec_WecPush( &p->vOccurs, Lit, i );
}
assert( Vec_IntSize(vCube) == Vec_IntCap(vCube) );
}
}
void Pla_ManConvertToBits( Pla_Man_t * p )
{
Vec_Int_t * vCube; int i, k, Lit;
Vec_IntFillNatural( &p->vCubes, Vec_WecSize(&p->vLits) );
Vec_IntFillNatural( &p->vCubes, Vec_WecSize(&p->vCubeLits) );
Vec_WrdFill( &p->vInBits, Pla_ManCubeNum(p) * p->nInWords, 0 );
Vec_WecForEachLevel( &p->vLits, vCube, i )
Vec_WecForEachLevel( &p->vCubeLits, vCube, i )
Vec_IntForEachEntry( vCube, Lit, k )
Pla_CubeSetLit( Pla_CubeIn(p, i), Abc_Lit2Var(Lit), Abc_LitIsCompl(Lit) ? PLA_LIT_ZERO : PLA_LIT_ONE );
}
......
......@@ -49,7 +49,7 @@ Vec_Str_t * Pla_WritePlaInt( Pla_Man_t * p )
int i, k, Lit;
// write comments
Vec_StrPrintStr( vOut, "# SOP \"" );
Vec_StrPrintStr( vOut, p->pName );
Vec_StrPrintStr( vOut, Pla_ManName(p) );
Vec_StrPrintStr( vOut, "\" written via PLA package in ABC on " );
Vec_StrPrintStr( vOut, Extra_TimeStamp() );
Vec_StrPrintStr( vOut, "\n\n" );
......
......@@ -124,7 +124,7 @@ static inline Vec_Bit_t * Vec_BitStartFull( int nSize )
{
Vec_Bit_t * p;
nSize = (nSize >> 5) + ((nSize & 31) > 0);
p = Vec_BitAlloc( nSize );
p = Vec_BitAlloc( nSize * 32 );
p->nSize = nSize * 32;
memset( p->pArray, 0xff, sizeof(int) * nSize );
return p;
......
......@@ -225,6 +225,18 @@ static inline Vec_Flt_t * Vec_FltDupArray( Vec_Flt_t * pVec )
SeeAlso []
***********************************************************************/
static inline void Vec_FltZero( Vec_Flt_t * p )
{
p->pArray = NULL;
p->nSize = 0;
p->nCap = 0;
}
static inline void Vec_FltErase( Vec_Flt_t * p )
{
ABC_FREE( p->pArray );
p->nSize = 0;
p->nCap = 0;
}
static inline void Vec_FltFree( Vec_Flt_t * p )
{
ABC_FREE( p->pArray );
......
......@@ -1338,6 +1338,16 @@ static inline void Vec_IntSort( Vec_Int_t * p, int fReverse )
qsort( (void *)p->pArray, p->nSize, sizeof(int),
(int (*)(const void *, const void *)) Vec_IntSortCompare1 );
}
static inline void Vec_IntSortPairs( Vec_Int_t * p, int fReverse )
{
assert( Vec_IntSize(p) % 2 == 0 );
if ( fReverse )
qsort( (void *)p->pArray, p->nSize/2, 2*sizeof(int),
(int (*)(const void *, const void *)) Vec_IntSortCompare2 );
else
qsort( (void *)p->pArray, p->nSize/2, 2*sizeof(int),
(int (*)(const void *, const void *)) Vec_IntSortCompare1 );
}
/**Function*************************************************************
......@@ -1394,6 +1404,36 @@ static inline int Vec_IntCountUnique( Vec_Int_t * p )
/**Function*************************************************************
Synopsis [Counts the number of unique pairs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Vec_IntUniqifyPairs( Vec_Int_t * p )
{
int i, k, RetValue;
assert( p->nSize % 2 == 0 );
if ( p->nSize < 4 )
return 0;
Vec_IntSortPairs( p, 0 );
for ( i = k = 1; i < p->nSize/2; i++ )
if ( p->pArray[2*i] != p->pArray[2*(i-1)] || p->pArray[2*i+1] != p->pArray[2*(i-1)+1] )
{
p->pArray[2*k] = p->pArray[2*i];
p->pArray[2*k+1] = p->pArray[2*i+1];
k++;
}
RetValue = p->nSize/2 - k;
p->nSize = 2*k;
return RetValue;
}
/**Function*************************************************************
Synopsis [Counts the number of unique entries.]
Description []
......@@ -1891,6 +1931,13 @@ static inline void Vec_IntAppend( Vec_Int_t * vVec1, Vec_Int_t * vVec2 )
Vec_IntForEachEntry( vVec2, Entry, i )
Vec_IntPush( vVec1, Entry );
}
static inline void Vec_IntAppendSkip( Vec_Int_t * vVec1, Vec_Int_t * vVec2, int iVar )
{
int Entry, i;
Vec_IntForEachEntry( vVec2, Entry, i )
if ( i != iVar )
Vec_IntPush( vVec1, Entry );
}
ABC_NAMESPACE_HEADER_END
......
......@@ -961,6 +961,25 @@ static inline word Vec_WrdSum( Vec_Wrd_t * p )
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Vec_WrdCountZero( Vec_Wrd_t * p )
{
int i, Counter = 0;
for ( i = 0; i < p->nSize; i++ )
Counter += (p->pArray[i] == 0);
return Counter;
}
/**Function*************************************************************
Synopsis [Checks if two vectors are equal.]
Description []
......
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