diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-10-02 14:53:56 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-10-02 14:53:56 -0700 |
commit | b612db977c6076df4b91f5e4eec6f615e1cd1d91 (patch) | |
tree | d38c5c24b719c0d627f4431ce4092b06e207fba3 /src/aig | |
parent | 60ad1765ff847ba609500385e4a73c84e37ecdc1 (diff) | |
download | abc-b612db977c6076df4b91f5e4eec6f615e1cd1d91.tar.gz abc-b612db977c6076df4b91f5e4eec6f615e1cd1d91.tar.bz2 abc-b612db977c6076df4b91f5e4eec6f615e1cd1d91.zip |
Separated truth table computation for GIA manager and added new procedures.
Diffstat (limited to 'src/aig')
-rw-r--r-- | src/aig/gia/gia.h | 7 | ||||
-rw-r--r-- | src/aig/gia/giaTruth.c | 295 | ||||
-rw-r--r-- | src/aig/gia/giaUtil.c | 147 | ||||
-rw-r--r-- | src/aig/gia/module.make | 1 |
4 files changed, 301 insertions, 149 deletions
diff --git a/src/aig/gia/gia.h b/src/aig/gia/gia.h index 446f3e4f..ed7351b7 100644 --- a/src/aig/gia/gia.h +++ b/src/aig/gia/gia.h @@ -883,6 +883,11 @@ extern Gia_Man_t * Gia_ManSpeedup( Gia_Man_t * p, int Percentage, int De /*=== giaSwitch.c ============================================================*/ extern float Gia_ManEvaluateSwitching( Gia_Man_t * p ); extern float Gia_ManComputeSwitching( Gia_Man_t * p, int nFrames, int nPref, int fProbOne ); +/*=== giaTruth.c ===========================================================*/ +extern void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj ); +extern unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj ); +extern void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax ); +extern unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vLeaves ); /*=== giaTsim.c ============================================================*/ extern Gia_Man_t * Gia_ManReduceConst( Gia_Man_t * pAig, int fVerbose ); /*=== giaUtil.c ===========================================================*/ @@ -922,8 +927,6 @@ extern Vec_Int_t * Gia_ManGetDangling( Gia_Man_t * p ); extern void Gia_ObjPrint( Gia_Man_t * p, Gia_Obj_t * pObj ); extern void Gia_ManPrint( Gia_Man_t * p ); extern void Gia_ManInvertConstraints( Gia_Man_t * pAig ); -extern void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj ); -extern unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj ); extern int Gia_ManCompare( Gia_Man_t * p1, Gia_Man_t * p2 ); /*=== giaCTas.c ===========================================================*/ diff --git a/src/aig/gia/giaTruth.c b/src/aig/gia/giaTruth.c new file mode 100644 index 00000000..668be083 --- /dev/null +++ b/src/aig/gia/giaTruth.c @@ -0,0 +1,295 @@ +/**CFile**************************************************************** + + FileName [giaTruth.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Scalable AIG package.] + + Synopsis [Truth table computation.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - June 20, 2005.] + + Revision [$Id: giaTruth.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "gia.h" + +ABC_NAMESPACE_IMPL_START + + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static inline word * Gla_ObjTruthElem( Gia_Man_t * p, int i ) { return (word *)Vec_PtrEntry( p->vTtInputs, i ); } +static inline word * Gla_ObjTruthNode( Gia_Man_t * p, Gia_Obj_t * pObj ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * Gia_ObjNum(p, pObj); } +static inline word * Gla_ObjTruthFree1( Gia_Man_t * p ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * 254; } +static inline word * Gla_ObjTruthFree2( Gia_Man_t * p ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * 255; } +static inline word * Gla_ObjTruthConst0( Gia_Man_t * p, word * pDst ) { int w; for ( w = 0; w < p->nTtWords; w++ ) pDst[w] = 0; return pDst; } +static inline word * Gla_ObjTruthDup( Gia_Man_t * p, word * pDst, word * pSrc, int c ) { int w; for ( w = 0; w < p->nTtWords; w++ ) pDst[w] = c ? ~pSrc[w] : pSrc[w]; return pDst; } + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Collects internal nodes reachable from the given node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_ObjCollectInternal_rec( Gia_Man_t * p, Gia_Obj_t * pObj ) +{ + if ( !Gia_ObjIsAnd(pObj) ) + return; + if ( pObj->fMark0 ) + return; + pObj->fMark0 = 1; + Gia_ObjCollectInternal_rec( p, Gia_ObjFanin0(pObj) ); + Gia_ObjCollectInternal_rec( p, Gia_ObjFanin1(pObj) ); + Gia_ObjSetNum( p, pObj, Vec_IntSize(p->vTtNodes) ); + Vec_IntPush( p->vTtNodes, Gia_ObjId(p, pObj) ); +} +void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj ) +{ + Vec_IntClear( p->vTtNodes ); + Gia_ObjCollectInternal_rec( p, pObj ); + assert( Vec_IntSize(p->vTtNodes) < 254 ); +} + +/**Function************************************************************* + + Synopsis [Computing the truth table for GIA object.] + + Description [The truth table should be used by the calling application + (or saved into the user's storage) before this procedure is called again.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj ) +{ + Gia_Obj_t * pTemp, * pRoot; + word * pTruth, * pTruthL, * pTruth0, * pTruth1; + int i; + if ( p->vTtMemory == NULL ) + { + p->nTtVars = Gia_ManPiNum( p ); + p->nTtWords = (p->nTtVars <= 6 ? 1 : (1 << (p->nTtVars - 6))); + p->vTtNums = Vec_StrAlloc( Gia_ManObjNum(p) + 1000 ); + p->vTtNodes = Vec_IntAlloc( 256 ); + p->vTtInputs = Vec_PtrAllocTruthTables( p->nTtVars ); + p->vTtMemory = Vec_WrdStart( p->nTtWords * 256 ); + } + else + { + // make sure the number of primary inputs did not change + // since the truth table computation storage was prepared + assert( p->nTtVars == Gia_ManPiNum(p) ); + } + // collect internal nodes + pRoot = Gia_ObjIsCo(pObj) ? Gia_ObjFanin0(pObj) : pObj; + Gia_ObjCollectInternal( p, pRoot ); + // compute the truth table for internal nodes + Gia_ManForEachObjVec( p->vTtNodes, p, pTemp, i ) + { + pTemp->fMark0 = 0; // unmark nodes marked by Gia_ObjCollectInternal() + pTruth = Gla_ObjTruthNode(p, pTemp); + pTruthL = pTruth + p->nTtWords; + pTruth0 = Gia_ObjIsAnd(Gia_ObjFanin0(pTemp)) ? Gla_ObjTruthNode(p, Gia_ObjFanin0(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjCioId(Gia_ObjFanin0(pTemp)) ); + pTruth1 = Gia_ObjIsAnd(Gia_ObjFanin1(pTemp)) ? Gla_ObjTruthNode(p, Gia_ObjFanin1(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjCioId(Gia_ObjFanin1(pTemp)) ); + if ( Gia_ObjFaninC0(pTemp) ) + { + if ( Gia_ObjFaninC1(pTemp) ) + while ( pTruth < pTruthL ) + *pTruth++ = ~*pTruth0++ & ~*pTruth1++; + else + while ( pTruth < pTruthL ) + *pTruth++ = ~*pTruth0++ & *pTruth1++; + } + else + { + if ( Gia_ObjFaninC1(pTemp) ) + while ( pTruth < pTruthL ) + *pTruth++ = *pTruth0++ & ~*pTruth1++; + else + while ( pTruth < pTruthL ) + *pTruth++ = *pTruth0++ & *pTruth1++; + } + } + // compute the final table + if ( Gia_ObjIsConst0(pRoot) ) + pTruth = Gla_ObjTruthConst0( p, Gla_ObjTruthFree1(p) ); + else if ( Gia_ObjIsPi(p, pRoot) ) + pTruth = Gla_ObjTruthElem( p, Gia_ObjCioId(pRoot) ); + else if ( Gia_ObjIsAnd(pRoot) ) + pTruth = Gla_ObjTruthNode( p, pRoot ); + else + pTruth = NULL; + return (unsigned *)Gla_ObjTruthDup( p, Gla_ObjTruthFree2(p), pTruth, Gia_ObjIsCo(pObj) && Gia_ObjFaninC0(pObj) ); +} + +/**Function************************************************************* + + Synopsis [Testing truth table computation.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_ObjComputeTruthTableTest( Gia_Man_t * p ) +{ + Gia_Obj_t * pObj; + unsigned * pTruth; + clock_t clk = clock(); + int i; + Gia_ManForEachPo( p, pObj, i ) + { + pTruth = Gia_ObjComputeTruthTable( p, pObj ); +// Extra_PrintHex( stdout, pTruth, Gia_ManPiNum(p) ); printf( "\n" ); + } + Abc_PrintTime( 1, "Time", clock() - clk ); +} + + +/**Function************************************************************* + + Synopsis [Collects internal nodes reachable from the given node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_ObjCollectInternalCut_rec( Gia_Man_t * p, Gia_Obj_t * pObj ) +{ + if ( pObj->fMark0 ) + return; + pObj->fMark0 = 1; + assert( Gia_ObjIsAnd(pObj) ); + Gia_ObjCollectInternalCut_rec( p, Gia_ObjFanin0(pObj) ); + Gia_ObjCollectInternalCut_rec( p, Gia_ObjFanin1(pObj) ); + Gia_ObjSetNum( p, pObj, Vec_IntSize(p->vTtNodes) ); + Vec_IntPush( p->vTtNodes, Gia_ObjId(p, pObj) ); +} +void Gia_ObjCollectInternalCut( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vLeaves ) +{ + Gia_Obj_t * pObj; + int i; + assert( Gia_ObjIsAnd(pRoot) ); + assert( pRoot->fMark0 == 0 ); + Gia_ManForEachObjVec( vLeaves, p, pObj, i ) + { + assert( pObj->fMark0 == 0 ); + pObj->fMark0 = 1; + Gia_ObjSetNum( p, pObj, i ); + } + assert( pRoot->fMark0 == 0 ); // the root cannot be one of the leaves + Vec_IntClear( p->vTtNodes ); + Gia_ObjCollectInternalCut_rec( p, pRoot ); + assert( Vec_IntSize(p->vTtNodes) < 254 ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_ObjComputeTruthTableStart( Gia_Man_t * p, int nVarsMax ) +{ + assert( p->vTtMemory == NULL ); + p->nTtVars = nVarsMax; + p->nTtWords = (p->nTtVars <= 6 ? 1 : (1 << (p->nTtVars - 6))); + p->vTtNums = Vec_StrAlloc( Gia_ManObjNum(p) + 1000 ); + p->vTtNodes = Vec_IntAlloc( 256 ); + p->vTtInputs = Vec_PtrAllocTruthTables( p->nTtVars ); + p->vTtMemory = Vec_WrdStart( p->nTtWords * 256 ); +} + +/**Function************************************************************* + + Synopsis [Computes the truth table of pRoot in terms of leaves.] + + Description [The root cannot be one of the leaves.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Gia_ObjComputeTruthTableCut( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vLeaves ) +{ + Gia_Obj_t * pTemp; + word * pTruth, * pTruthL, * pTruth0, * pTruth1; + int i; + assert( p->vTtMemory != NULL ); + assert( p->nTtVars <= Vec_IntSize(vLeaves) ); + // collect internal nodes + Gia_ObjCollectInternalCut( p, pRoot, vLeaves ); + // compute the truth table for internal nodes + Gia_ManForEachObjVec( p->vTtNodes, p, pTemp, i ) + { + pTemp->fMark0 = 0; // unmark nodes marked by Gia_ObjCollectInternal() + pTruth = Gla_ObjTruthNode(p, pTemp); + pTruthL = pTruth + p->nTtWords; + pTruth0 = !Gia_ObjFanin0(pTemp)->fMark0 ? Gla_ObjTruthNode(p, Gia_ObjFanin0(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjNum(p, Gia_ObjFanin0(pTemp)) ); + pTruth1 = !Gia_ObjFanin1(pTemp)->fMark0 ? Gla_ObjTruthNode(p, Gia_ObjFanin1(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjNum(p, Gia_ObjFanin1(pTemp)) ); + if ( Gia_ObjFaninC0(pTemp) ) + { + if ( Gia_ObjFaninC1(pTemp) ) + while ( pTruth < pTruthL ) + *pTruth++ = ~*pTruth0++ & ~*pTruth1++; + else + while ( pTruth < pTruthL ) + *pTruth++ = ~*pTruth0++ & *pTruth1++; + } + else + { + if ( Gia_ObjFaninC1(pTemp) ) + while ( pTruth < pTruthL ) + *pTruth++ = *pTruth0++ & ~*pTruth1++; + else + while ( pTruth < pTruthL ) + *pTruth++ = *pTruth0++ & *pTruth1++; + } + } + // unmark leaves marked by Gia_ObjCollectInternal() + Gia_ManForEachObjVec( vLeaves, p, pTemp, i ) + { + assert( pTemp->fMark0 == 1 ); + pTemp->fMark0 = 0; + } + return (unsigned *)Gla_ObjTruthNode( p, pRoot ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/aig/gia/giaUtil.c b/src/aig/gia/giaUtil.c index e4a4dd09..2898488f 100644 --- a/src/aig/gia/giaUtil.c +++ b/src/aig/gia/giaUtil.c @@ -1155,153 +1155,6 @@ unsigned * Gia_ManComputePoTruthTables( Gia_Man_t * p, int nBytesMax ) /**Function************************************************************* - Synopsis [Collects internal nodes reachable from the given node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Gia_ObjCollectInternal_rec( Gia_Man_t * p, Gia_Obj_t * pObj ) -{ - if ( !Gia_ObjIsAnd(pObj) ) - return; - if ( pObj->fMark0 ) - return; - pObj->fMark0 = 1; - Gia_ObjCollectInternal_rec( p, Gia_ObjFanin0(pObj) ); - Gia_ObjCollectInternal_rec( p, Gia_ObjFanin1(pObj) ); - Gia_ObjSetNum( p, pObj, Vec_IntSize(p->vTtNodes) ); - Vec_IntPush( p->vTtNodes, Gia_ObjId(p, pObj) ); -} -void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj ) -{ - Vec_IntClear( p->vTtNodes ); - Gia_ObjCollectInternal_rec( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Truth table manipulation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline word * Gla_ObjTruthElem( Gia_Man_t * p, int i ) { return (word *)Vec_PtrEntry( p->vTtInputs, i ); } -static inline word * Gla_ObjTruthNode( Gia_Man_t * p, Gia_Obj_t * pObj ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * Gia_ObjNum(p, pObj); } -static inline word * Gla_ObjTruthFree1( Gia_Man_t * p ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * 254; } -static inline word * Gla_ObjTruthFree2( Gia_Man_t * p ) { return Vec_WrdArray(p->vTtMemory) + p->nTtWords * 255; } -static inline word * Gla_ObjTruthConst0( Gia_Man_t * p, word * pDst ) { int w; for ( w = 0; w < p->nTtWords; w++ ) pDst[w] = 0; return pDst; } -static inline word * Gla_ObjTruthDup( Gia_Man_t * p, word * pDst, word * pSrc, int c ) { int w; for ( w = 0; w < p->nTtWords; w++ ) pDst[w] = c ? ~pSrc[w] : pSrc[w]; return pDst; } - -/**Function************************************************************* - - Synopsis [Computing the truth table for GIA object.] - - Description [The truth table should be used by the calling application - (or saved into the user's storage) before this procedure is called again.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Gia_ObjComputeTruthTable( Gia_Man_t * p, Gia_Obj_t * pObj ) -{ - Gia_Obj_t * pTemp, * pRoot; - word * pTruth, * pTruthL, * pTruth0, * pTruth1; - int i; - if ( p->vTtMemory == NULL ) - { - p->nTtVars = Gia_ManPiNum( p ); - p->nTtWords = (p->nTtVars <= 6 ? 1 : (1 << (p->nTtVars - 6))); - p->vTtNums = Vec_StrAlloc( Gia_ManObjNum(p) + 1000 ); - p->vTtNodes = Vec_IntAlloc( 256 ); - p->vTtInputs = Vec_PtrAllocTruthTables( p->nTtVars ); - p->vTtMemory = Vec_WrdStart( p->nTtWords * 256 ); - } - else - { - // make sure the number of primary inputs did not change - // since the truth table computation storage was prepared - assert( p->nTtVars == Gia_ManPiNum(p) ); - } - // collect internal nodes - pRoot = Gia_ObjIsCo(pObj) ? Gia_ObjFanin0(pObj) : pObj; - Gia_ObjCollectInternal( p, pRoot ); - // compute the truth table for internal nodes - Gia_ManForEachObjVec( p->vTtNodes, p, pTemp, i ) - { - pTemp->fMark0 = 0; // unmark node marked by Gia_ObjCollectInternal() - pTruth = Gla_ObjTruthNode(p, pTemp); - pTruthL = pTruth + p->nTtWords; - pTruth0 = Gia_ObjIsAnd(Gia_ObjFanin0(pTemp)) ? Gla_ObjTruthNode(p, Gia_ObjFanin0(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjCioId(Gia_ObjFanin0(pTemp)) ); - pTruth1 = Gia_ObjIsAnd(Gia_ObjFanin1(pTemp)) ? Gla_ObjTruthNode(p, Gia_ObjFanin1(pTemp)) : Gla_ObjTruthElem(p, Gia_ObjCioId(Gia_ObjFanin1(pTemp)) ); - if ( Gia_ObjFaninC0(pTemp) ) - { - if ( Gia_ObjFaninC1(pTemp) ) - while ( pTruth < pTruthL ) - *pTruth++ = ~*pTruth0++ & ~*pTruth1++; - else - while ( pTruth < pTruthL ) - *pTruth++ = ~*pTruth0++ & *pTruth1++; - } - else - { - if ( Gia_ObjFaninC1(pTemp) ) - while ( pTruth < pTruthL ) - *pTruth++ = *pTruth0++ & ~*pTruth1++; - else - while ( pTruth < pTruthL ) - *pTruth++ = *pTruth0++ & *pTruth1++; - } - } - // compute the final table - if ( Gia_ObjIsConst0(pRoot) ) - pTruth = Gla_ObjTruthConst0( p, Gla_ObjTruthFree1(p) ); - else if ( Gia_ObjIsPi(p, pRoot) ) - pTruth = Gla_ObjTruthElem( p, Gia_ObjCioId(pRoot) ); - else if ( Gia_ObjIsAnd(pRoot) ) - pTruth = Gla_ObjTruthNode( p, pRoot ); - else - pTruth = NULL; - return (unsigned *)Gla_ObjTruthDup( p, Gla_ObjTruthFree2(p), pTruth, Gia_ObjIsCo(pObj) && Gia_ObjFaninC0(pObj) ); -} - -/**Function************************************************************* - - Synopsis [Testing truth table computation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Gia_ObjComputeTruthTableTest( Gia_Man_t * p ) -{ - Gia_Obj_t * pObj; - unsigned * pTruth; - clock_t clk = clock(); - int i; - Gia_ManForEachPo( p, pObj, i ) - { - pTruth = Gia_ObjComputeTruthTable( p, pObj ); -// Extra_PrintHex( stdout, pTruth, Gia_ManPiNum(p) ); printf( "\n" ); - } - Abc_PrintTime( 1, "Time", clock() - clk ); -} - - -/**Function************************************************************* - Synopsis [Returns 1 if the manager are structural identical.] Description [] diff --git a/src/aig/gia/module.make b/src/aig/gia/module.make index d35dcde2..5bdd4ff1 100644 --- a/src/aig/gia/module.make +++ b/src/aig/gia/module.make @@ -38,5 +38,6 @@ SRC += src/aig/gia/gia.c \ src/aig/gia/giaSpeedup.c \ src/aig/gia/giaSupMin.c \ src/aig/gia/giaSwitch.c \ + src/aig/gia/giaTruth.c \ src/aig/gia/giaTsim.c \ src/aig/gia/giaUtil.c |