diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2010-11-01 01:35:04 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2010-11-01 01:35:04 -0700 |
commit | 6130e39b18b5f53902e4eab14f6d5cdde5219563 (patch) | |
tree | 0db0628479a1b750e9af1f66cb8379ebd0913d31 /src/aig/kit/kitPla.c | |
parent | f0e77f6797c0504b0da25a56152b707d3357f386 (diff) | |
download | abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.gz abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.bz2 abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.zip |
initial commit of public abc
Diffstat (limited to 'src/aig/kit/kitPla.c')
-rw-r--r-- | src/aig/kit/kitPla.c | 191 |
1 files changed, 186 insertions, 5 deletions
diff --git a/src/aig/kit/kitPla.c b/src/aig/kit/kitPla.c index 776762c2..df6d4e11 100644 --- a/src/aig/kit/kitPla.c +++ b/src/aig/kit/kitPla.c @@ -21,6 +21,9 @@ #include "kit.h" #include "aig.h" +ABC_NAMESPACE_IMPL_START + + //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// @@ -115,7 +118,9 @@ int Kit_PlaIsInv( char * pSop ) int Kit_PlaGetVarNum( char * pSop ) { char * pCur; - for ( pCur = pSop; *pCur != '\n'; pCur++ ); + for ( pCur = pSop; *pCur != '\n'; pCur++ ) + if ( *pCur == 0 ) + return -1; return pCur - pSop - 2; } @@ -205,7 +210,7 @@ void Kit_PlaComplement( char * pSop ) ***********************************************************************/ char * Kit_PlaStart( void * p, int nCubes, int nVars ) { - Aig_MmFlex_t * pMan = p; + Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p; char * pSopCover, * pCube; int i, Length; @@ -237,7 +242,7 @@ char * Kit_PlaStart( void * p, int nCubes, int nVars ) ***********************************************************************/ char * Kit_PlaCreateFromIsop( void * p, int nVars, Vec_Int_t * vCover ) { - Aig_MmFlex_t * pMan = p; + Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p; char * pSop, * pCube; int i, k, Entry, Literal; assert( Vec_IntSize(vCover) > 0 ); @@ -311,7 +316,7 @@ void Kit_PlaToIsop( char * pSop, Vec_Int_t * vCover ) ***********************************************************************/ char * Kit_PlaStoreSop( void * p, char * pSop ) { - Aig_MmFlex_t * pMan = p; + Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p; char * pStore; pStore = Aig_MmFlexEntryFetch( pMan, strlen(pSop) + 1 ); strcpy( pStore, pSop ); @@ -331,7 +336,7 @@ char * Kit_PlaStoreSop( void * p, char * pSop ) ***********************************************************************/ char * Kit_PlaFromTruth( void * p, unsigned * pTruth, int nVars, Vec_Int_t * vCover ) { - Aig_MmFlex_t * pMan = p; + Aig_MmFlex_t * pMan = (Aig_MmFlex_t *)p; char * pSop; int RetValue; if ( Kit_TruthIsConst0(pTruth, nVars) ) @@ -347,8 +352,184 @@ char * Kit_PlaFromTruth( void * p, unsigned * pTruth, int nVars, Vec_Int_t * vCo } +/**Function************************************************************* + + Synopsis [Creates the cover from the ISOP computed from TT.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +char * Kit_PlaFromIsop( Vec_Str_t * vStr, int nVars, Vec_Int_t * vCover ) +{ + int i, k, Entry, Literal; + assert( Vec_IntSize(vCover) > 0 ); + if ( Vec_IntSize(vCover) == 0 ) + return NULL; + Vec_StrClear( vStr ); + Vec_IntForEachEntry( vCover, Entry, i ) + { + for ( k = 0; k < nVars; k++ ) + { + Literal = 3 & (Entry >> (k << 1)); + if ( Literal == 1 ) + Vec_StrPush( vStr, '0' ); + else if ( Literal == 2 ) + Vec_StrPush( vStr, '1' ); + else if ( Literal == 0 ) + Vec_StrPush( vStr, '-' ); + else + assert( 0 ); + } + Vec_StrPush( vStr, ' ' ); + Vec_StrPush( vStr, '1' ); + Vec_StrPush( vStr, '\n' ); + } + Vec_StrPush( vStr, '\0' ); + return Vec_StrArray( vStr ); +} + +/**Function************************************************************* + + Synopsis [Creates the SOP from TT.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +char * Kit_PlaFromTruthNew( unsigned * pTruth, int nVars, Vec_Int_t * vCover, Vec_Str_t * vStr ) +{ + char * pResult; + // transform truth table into the SOP + int RetValue = Kit_TruthIsop( pTruth, nVars, vCover, 1 ); + assert( RetValue == 0 || RetValue == 1 ); + // check the case of constant cover + if ( Vec_IntSize(vCover) == 0 || (Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover,0) == 0) ) + { + assert( RetValue == 0 ); + Vec_StrClear( vStr ); + Vec_StrAppend( vStr, (Vec_IntSize(vCover) == 0) ? " 0\n" : " 1\n" ); + Vec_StrPush( vStr, '\0' ); + return Vec_StrArray( vStr ); + } + pResult = Kit_PlaFromIsop( vStr, nVars, vCover ); + if ( RetValue ) + Kit_PlaComplement( pResult ); + if ( nVars < 6 ) + assert( pTruth[0] == (unsigned)Kit_PlaToTruth6(pResult, nVars) ); + else if ( nVars == 6 ) + assert( *((ABC_UINT64_T*)pTruth) == Kit_PlaToTruth6(pResult, nVars) ); + return pResult; +} + +/**Function************************************************************* + + Synopsis [Converts SOP into a truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +ABC_UINT64_T Kit_PlaToTruth6( char * pSop, int nVars ) +{ + static ABC_UINT64_T Truth[8] = { + 0xAAAAAAAAAAAAAAAA, + 0xCCCCCCCCCCCCCCCC, + 0xF0F0F0F0F0F0F0F0, + 0xFF00FF00FF00FF00, + 0xFFFF0000FFFF0000, + 0xFFFFFFFF00000000, + 0x0000000000000000, + 0xFFFFFFFFFFFFFFFF + }; + ABC_UINT64_T valueAnd, valueOr = Truth[6]; + int v, lit = 0; + assert( nVars < 7 ); + do { + valueAnd = Truth[7]; + for ( v = 0; v < nVars; v++, lit++ ) + { + if ( pSop[lit] == '1' ) + valueAnd &= Truth[v]; + else if ( pSop[lit] == '0' ) + valueAnd &= ~Truth[v]; + else if ( pSop[lit] != '-' ) + assert( 0 ); + } + valueOr |= valueAnd; + assert( pSop[lit] == ' ' ); + lit++; + lit++; + assert( pSop[lit] == '\n' ); + lit++; + } while ( pSop[lit] ); + if ( Kit_PlaIsComplement(pSop) ) + valueOr = ~valueOr; + return valueOr; +} + +/**Fnction************************************************************* + + Synopsis [Converting SOP into a truth table.] + + Description [The SOP is represented as a C-string, as documented in + file "bblif.h". The truth table is returned as a bit-string composed + of 2^nVars bits. For functions of less than 6 variables, the full + machine word is returned. (The truth table looks as if the function + had 5 variables.) The use of this procedure should be limited to + Boolean functions with no more than 16 inputs.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_PlaToTruth( char * pSop, int nVars, Vec_Ptr_t * vVars, unsigned * pTemp, unsigned * pTruth ) +{ + int v, c, nCubes, fCompl = 0; + assert( pSop != NULL ); + assert( nVars >= 0 ); + if ( strlen(pSop) % (nVars + 3) != 0 ) + { + printf( "Kit_PlaToTruth(): SOP is represented incorrectly.\n" ); + return; + } + // iterate through the cubes + Kit_TruthClear( pTruth, nVars ); + nCubes = strlen(pSop) / (nVars + 3); + for ( c = 0; c < nCubes; c++ ) + { + fCompl = (pSop[nVars+1] == '0'); + Kit_TruthFill( pTemp, nVars ); + // iterate through the literals of the cube + for ( v = 0; v < nVars; v++ ) + if ( pSop[v] == '1' ) + Kit_TruthAnd( pTemp, pTemp, (unsigned *)Vec_PtrEntry(vVars, v), nVars ); + else if ( pSop[v] == '0' ) + Kit_TruthSharp( pTemp, pTemp, (unsigned *)Vec_PtrEntry(vVars, v), nVars ); + // add cube to storage + Kit_TruthOr( pTruth, pTruth, pTemp, nVars ); + // go to the next cube + pSop += (nVars + 3); + } + if ( fCompl ) + Kit_TruthNot( pTruth, pTruth, nVars ); +} + + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + |