summaryrefslogtreecommitdiffstats
path: root/src/aig/gia
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2016-01-16 17:35:46 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2016-01-16 17:35:46 -0800
commitf5ee46eb3c2c691e4bafc5b7a7dbe3be16bef5dd (patch)
tree751dbb7242b7716919c744748c0ef09ed43581b5 /src/aig/gia
parent579bcccc651bb1d1ebe4011259f75ba32f76921a (diff)
downloadabc-f5ee46eb3c2c691e4bafc5b7a7dbe3be16bef5dd.tar.gz
abc-f5ee46eb3c2c691e4bafc5b7a7dbe3be16bef5dd.tar.bz2
abc-f5ee46eb3c2c691e4bafc5b7a7dbe3be16bef5dd.zip
New command to dump LUT network.
Diffstat (limited to 'src/aig/gia')
-rw-r--r--src/aig/gia/gia.h1
-rw-r--r--src/aig/gia/giaTruth.c42
-rw-r--r--src/aig/gia/giaUtil.c92
3 files changed, 135 insertions, 0 deletions
diff --git a/src/aig/gia/gia.h b/src/aig/gia/gia.h
index 17660aa3..19c984a3 100644
--- a/src/aig/gia/gia.h
+++ b/src/aig/gia/gia.h
@@ -1408,6 +1408,7 @@ extern Gia_Man_t * Gia_ManUpdateExtraAig2( void * pTime, Gia_Man_t * pAi
extern Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * vBoxPres, int fSeq );
extern int Gia_ManVerifyWithBoxes( Gia_Man_t * pGia, int nBTLimit, int nTimeLim, int fSeq, int fVerbose, char * pFileSpec );
/*=== giaTruth.c ===========================================================*/
+extern word Gia_LutComputeTruth6( Gia_Man_t * p, int iObj, Vec_Wrd_t * vTruths );
extern word Gia_ObjComputeTruthTable6Lut( Gia_Man_t * p, int iObj, Vec_Wrd_t * vTemp );
extern word Gia_ObjComputeTruthTable6( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vSupp, Vec_Wrd_t * vTruths );
extern void Gia_ObjCollectInternal( Gia_Man_t * p, Gia_Obj_t * pObj );
diff --git a/src/aig/gia/giaTruth.c b/src/aig/gia/giaTruth.c
index f05e2f68..56cf8785 100644
--- a/src/aig/gia/giaTruth.c
+++ b/src/aig/gia/giaTruth.c
@@ -54,6 +54,48 @@ static inline word * Gla_ObjTruthDup( Gia_Man_t * p, word * pDst, word * pSrc, i
/**Function*************************************************************
+ Synopsis [Compute truth table.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+word Gia_LutComputeTruth6_rec( Gia_Man_t * p, int iNode, Vec_Wrd_t * vTruths )
+{
+ Gia_Obj_t * pObj;
+ word Truth0, Truth1;
+ if ( Gia_ObjIsTravIdCurrentId(p, iNode) )
+ return Vec_WrdEntry(vTruths, iNode);
+ Gia_ObjSetTravIdCurrentId(p, iNode);
+ pObj = Gia_ManObj( p, iNode );
+ assert( Gia_ObjIsAnd(pObj) );
+ Truth0 = Gia_LutComputeTruth6_rec( p, Gia_ObjFaninId0p(p, pObj), vTruths );
+ Truth1 = Gia_LutComputeTruth6_rec( p, Gia_ObjFaninId1p(p, pObj), vTruths );
+ if ( Gia_ObjFaninC0(pObj) )
+ Truth0 = ~Truth0;
+ if ( Gia_ObjFaninC1(pObj) )
+ Truth1 = ~Truth1;
+ Vec_WrdWriteEntry( vTruths, iNode, Truth0 & Truth1 );
+ return Truth0 & Truth1;
+}
+word Gia_LutComputeTruth6( Gia_Man_t * p, int iObj, Vec_Wrd_t * vTruths )
+{
+ int k, iFan;
+ assert( Gia_ObjIsLut(p, iObj) );
+ Gia_ManIncrementTravId( p );
+ Gia_LutForEachFanin( p, iObj, iFan, k )
+ {
+ Vec_WrdWriteEntry( vTruths, iFan, s_Truths6[k] );
+ Gia_ObjSetTravIdCurrentId( p, iFan );
+ }
+ return Gia_LutComputeTruth6_rec( p, iObj, vTruths );
+}
+
+/**Function*************************************************************
+
Synopsis [Computes truth table of a 6-LUT.]
Description []
diff --git a/src/aig/gia/giaUtil.c b/src/aig/gia/giaUtil.c
index ff44eecf..ee960c63 100644
--- a/src/aig/gia/giaUtil.c
+++ b/src/aig/gia/giaUtil.c
@@ -1930,6 +1930,98 @@ Vec_Int_t * Gia_ManPoXSim( Gia_Man_t * p, int nFrames, int fVerbose )
return vRes;
}
+#define MAX_LUT_SIZE 8
+typedef struct Gia_MapLut_t_
+{
+ int Type; // node type: PI=1, PO=2, LUT=3
+ int Out; // ID
+ int StartId; // -1
+ int nFans; // fanin count
+ float Delay; // 0.0
+ int pFans[MAX_LUT_SIZE]; // fanin IDs
+ unsigned pTruth[MAX_LUT_SIZE<6?1:(1<<(MAX_LUT_SIZE-5))]; // the truth table
+} Gia_MapLut_t;
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Gia_AigerWriteLut( Gia_Man_t * p, char * pFileName )
+{
+ Gia_Obj_t * pObj;
+ int i, k, iFan, iLut = 0;
+ int LutSizeMax = Gia_ManLutSizeMax( p );
+ int nUints = Abc_TruthWordNum(LutSizeMax);
+ int nLuts = 1 + Gia_ManCiNum(p) + Gia_ManCoNum(p) + Gia_ManLutNum(p);
+ Gia_MapLut_t * pLuts = ABC_CALLOC( Gia_MapLut_t, nLuts );
+ Vec_Wrd_t * vTruths = Vec_WrdStart( Gia_ManObjNum(p) );
+ assert( LutSizeMax <= 6 );
+ // set obj numbers
+ // constant
+ pLuts->Type = 3;
+ memset( pLuts->pTruth, 0xFF, sizeof(unsigned) * nUints );
+ Gia_ManFillValue(p);
+ Gia_ManConst0(p)->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
+ iLut++;
+ // inputs
+ Gia_ManForEachCi( p, pObj, i )
+ {
+ pLuts[iLut].Type = 1;
+ memset( pLuts[iLut].pTruth, 0xAA, sizeof(unsigned) * nUints );
+ pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
+ iLut++;
+ }
+ // nodes
+ Gia_ManForEachObj( p, pObj, i )
+ if ( i && Gia_ObjIsLut(p, i) )
+ {
+ pLuts[iLut].Type = 3;
+ Gia_LutForEachFanin( p, i, iFan, k )
+ pLuts[iLut].pFans[k] = Gia_ManObj(p, iFan)->Value;
+ pLuts[iLut].nFans = k;
+ *(word *)pLuts[iLut].pTruth = Gia_LutComputeTruth6(p, i, vTruths);
+ pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
+ iLut++;
+ }
+ // outputs
+ Gia_ManForEachCo( p, pObj, i )
+ {
+ pLuts[iLut].Type = 2;
+ pLuts[iLut].pFans[0] = Gia_ObjFanin0(pObj)->Value;
+ if ( Gia_ObjFaninC0(pObj) ^ Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
+ memset( pLuts[iLut].pTruth, 0x55, sizeof(unsigned) * nUints );
+ else
+ memset( pLuts[iLut].pTruth, 0xAA, sizeof(unsigned) * nUints );
+ pLuts[iLut].nFans = 1;
+ pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
+ iLut++;
+ }
+ assert( iLut == nLuts );
+ // dump into a file
+ {
+ FILE * pFile = fopen( pFileName, "wb" );
+ if ( pFile == NULL )
+ printf( "Cannot open file \"%s\" for writing.\n", pFileName );
+ else
+ {
+ int nSize1 = nLuts * sizeof(Gia_MapLut_t);
+ int nSize2 = fwrite( pLuts, 1, nSize1, pFile );
+ assert( nSize1 == nSize2 );
+ printf( "Successfully dumped %d bytes of binary data.\n", nSize1 );
+ }
+ fclose( pFile );
+ }
+ ABC_FREE( pLuts );
+ Vec_WrdFree( vTruths );
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////