summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2015-09-27 19:16:08 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2015-09-27 19:16:08 -0700
commit1ba16ff782064619d40cba68dd24cbe291aaf538 (patch)
tree448638b6847368373bb64c4faee2e4cafcaaff11 /src
parente3eea01dbb4c64d84b5ac46c92a9df55093cd7e0 (diff)
downloadabc-1ba16ff782064619d40cba68dd24cbe291aaf538.tar.gz
abc-1ba16ff782064619d40cba68dd24cbe291aaf538.tar.bz2
abc-1ba16ff782064619d40cba68dd24cbe291aaf538.zip
Experiments with LUT structure mapping.
Diffstat (limited to 'src')
-rw-r--r--src/aig/gia/gia.h3
-rw-r--r--src/aig/gia/giaOf.c999
-rw-r--r--src/aig/gia/module.make1
-rw-r--r--src/base/abci/abc.c233
-rw-r--r--src/misc/vec/vecInt.h40
5 files changed, 1276 insertions, 0 deletions
diff --git a/src/aig/gia/gia.h b/src/aig/gia/gia.h
index 79a322c4..b36b6278 100644
--- a/src/aig/gia/gia.h
+++ b/src/aig/gia/gia.h
@@ -280,6 +280,9 @@ struct Jf_Par_t_
int nAreaTuner;
int nReqTimeFlex;
int nVerbLimit;
+ int nDelayLut1;
+ int nDelayLut2;
+ int nFastEdges;
int DelayTarget;
int fAreaOnly;
int fPinPerm;
diff --git a/src/aig/gia/giaOf.c b/src/aig/gia/giaOf.c
new file mode 100644
index 00000000..016719ac
--- /dev/null
+++ b/src/aig/gia/giaOf.c
@@ -0,0 +1,999 @@
+/**CFile****************************************************************
+
+ FileName [giaOf.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Scalable AIG package.]
+
+ Synopsis [LUT structure mapper.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: giaOf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include <float.h>
+#include "gia.h"
+#include "misc/st/st.h"
+#include "map/mio/mio.h"
+#include "misc/util/utilTruth.h"
+#include "misc/extra/extra.h"
+#include "base/main/main.h"
+#include "misc/vec/vecMem.h"
+#include "misc/vec/vecWec.h"
+#include "opt/dau/dau.h"
+
+ABC_NAMESPACE_IMPL_START
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+#define OF_LEAF_MAX 6
+#define OF_CUT_MAX 32
+#define OF_NO_LEAF 31
+#define OF_NO_FUNC 0x3FFFFFF
+#define OF_INFINITY FLT_MAX
+#define OF_CUT_EXTRA 3 // size; delay1, delay2
+
+typedef struct Of_Cut_t_ Of_Cut_t;
+struct Of_Cut_t_
+{
+ word Sign; // signature
+ int Delay; // delay
+ float Flow; // flow
+ unsigned iFunc : 26; // function (OF_NO_FUNC)
+ unsigned Useless : 1; // function
+ unsigned nLeaves : 5; // leaf number (OF_NO_LEAF)
+ int pLeaves[OF_LEAF_MAX+1]; // leaves
+};
+typedef struct Of_Man_t_ Of_Man_t;
+struct Of_Man_t_
+{
+ // user data
+ Gia_Man_t * pGia; // derived manager
+ Jf_Par_t * pPars; // parameters
+ // cut data
+ Vec_Mem_t * vTtMem; // truth tables
+ Vec_Int_t vBests1; // best cuts
+ Vec_Int_t vBests2; // best cuts
+ Vec_Int_t vDelays1; // node delays
+ Vec_Int_t vDelays2; // node delays
+ // cut storage
+ Vec_Ptr_t vPages; // cut memory
+ Vec_Int_t vCutSets; // cut offsets
+ Vec_Flt_t vCutFlows; // temporary cut area
+ Vec_Int_t vCutDelays; // temporary cut delay
+ int iCur; // current position
+ int Iter; // mapping iterations
+ int fUseEla; // use exact area
+ int nInvs; // the inverter count
+ // statistics
+ abctime clkStart; // starting time
+ double CutCount[6]; // cut counts
+ int nCutUseAll; // objects with useful cuts
+};
+
+#define OF_NUM 10
+#define OF_NUMINV 0.1
+
+static inline int Of_Flt2Int( float f ) { return (int)(OF_NUM*f); }
+static inline float Of_Int2Flt( int i ) { return OF_NUMINV*i; }
+
+static inline int Of_ObjCutBest1( Of_Man_t * p, int i ) { return Vec_IntEntry( &p->vBests1, i ); }
+static inline int Of_ObjCutBest2( Of_Man_t * p, int i ) { return Vec_IntEntry( &p->vBests2, i ); }
+static inline void Of_ObjSetCutBest1( Of_Man_t * p, int i, int x ) { Vec_IntWriteEntry( &p->vBests1, i, x ); }
+static inline void Of_ObjSetCutBest2( Of_Man_t * p, int i, int x ) { Vec_IntWriteEntry( &p->vBests2, i, x ); }
+
+static inline int Of_ObjDelay1( Of_Man_t * p, int i ) { return Vec_IntEntry( &p->vDelays1, i ); }
+static inline int Of_ObjDelay2( Of_Man_t * p, int i ) { return Vec_IntEntry( &p->vDelays2, i ); }
+static inline void Of_ObjSetDelay1( Of_Man_t * p, int i, int x ) { Vec_IntWriteEntry( &p->vDelays1, i, x ); }
+static inline void Of_ObjSetDelay2( Of_Man_t * p, int i, int x ) { Vec_IntWriteEntry( &p->vDelays2, i, x ); }
+
+static inline int * Of_ManCutSet( Of_Man_t * p, int i ) { return (int *)Vec_PtrEntry(&p->vPages, i >> 16) + (i & 0xFFFF); }
+static inline int Of_ObjCutSetId( Of_Man_t * p, int i ) { return Vec_IntEntry( &p->vCutSets, i ); }
+static inline int * Of_ObjCutSet( Of_Man_t * p, int i ) { return Of_ManCutSet(p, Of_ObjCutSetId(p, i)); }
+static inline int Of_ObjHasCuts( Of_Man_t * p, int i ) { return (int)(Vec_IntEntry(&p->vCutSets, i) > 0); }
+
+static inline float Of_ObjCutFlow( Of_Man_t * p, int i ) { return Vec_FltEntry(&p->vCutFlows, i); }
+static inline int Of_ObjCutDelay( Of_Man_t * p, int i ) { return Vec_IntEntry(&p->vCutDelays, i); }
+static inline void Of_ObjSetCutFlow( Of_Man_t * p, int i, float a ) { Vec_FltWriteEntry(&p->vCutFlows, i, a); }
+static inline void Of_ObjSetCutDelay( Of_Man_t * p, int i, int d ) { Vec_IntWriteEntry(&p->vCutDelays, i, d); }
+
+static inline int Of_CutSize( int * pCut ) { return pCut[0] & OF_NO_LEAF; }
+static inline int Of_CutFunc( int * pCut ) { return ((unsigned)pCut[0] >> 5); }
+static inline int * Of_CutLeaves( int * pCut ) { return pCut + 1; }
+static inline int Of_CutSetBoth( int n, int f ) { return n | (f << 5); }
+static inline int Of_CutHandle( int * pCutSet, int * pCut ) { assert( pCut > pCutSet ); return pCut - pCutSet; }
+static inline int * Of_CutFromHandle( int * pCutSet, int h ) { assert( h > 0 ); return pCutSet + h; }
+
+static inline int Of_CutDelay1( int * pCut ) { return pCut[1 + Of_CutSize(pCut)]; }
+static inline int Of_CutDelay2( int * pCut ) { return pCut[2 + Of_CutSize(pCut)]; }
+static inline void Of_CutSetDelay1( int * pCut, int d ) { pCut[1 + Of_CutSize(pCut)] = d; }
+static inline void Of_CutSetDelay2( int * pCut, int d ) { pCut[2 + Of_CutSize(pCut)] = d; }
+
+static inline int Of_CutVar( int * pCut, int v ) { return Abc_Lit2Var(Of_CutLeaves(pCut)[v]); }
+static inline int Of_CutFlag( int * pCut, int v ) { return Abc_LitIsCompl(Of_CutLeaves(pCut)[v]); }
+static inline int Of_CutCleanFlag( int * pCut, int v ) { Of_CutLeaves(pCut)[v] = Abc_LitRegular(Of_CutLeaves(pCut)[v]); }
+static inline int Of_CutSetFlag( int * pCut, int v ) { Of_CutLeaves(pCut)[v] |= 1; }
+
+#define Of_SetForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += Of_CutSize(pCut) + OF_CUT_EXTRA )
+#define Of_ObjForEachCut( pCuts, i, nCuts ) for ( i = 0, i < nCuts; i++ )
+#define Of_CutForEachVar( pCut, iVar, i ) for ( i = 0; i < Of_CutSize(pCut) && (iVar = Of_CutVar(pCut,i)); i++ )
+#define Of_CutForEachVarFlag( pCut, iVar, Flag, i ) for ( i = 0; i < Of_CutSize(pCut) && (iVar = Of_CutVar(pCut,i)) && ((Flag = Of_CutFlag(pCut,i)), 1); i++ )
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Of_Man_t * Of_StoCreate( Gia_Man_t * pGia, Jf_Par_t * pPars )
+{
+ extern void Mf_ManSetFlowRefs( Gia_Man_t * p, Vec_Int_t * vRefs );
+ Of_Man_t * p;
+ Vec_Int_t * vFlowRefs;
+ assert( pPars->nCutNum > 1 && pPars->nCutNum <= OF_CUT_MAX );
+ assert( pPars->nLutSize > 1 && pPars->nLutSize <= OF_LEAF_MAX );
+ ABC_FREE( pGia->pRefs );
+ Vec_IntFreeP( &pGia->vCellMapping );
+ if ( Gia_ManHasChoices(pGia) )
+ Gia_ManSetPhase(pGia);
+ // create references
+ ABC_FREE( pGia->pRefs );
+ vFlowRefs = Vec_IntAlloc(0);
+ Mf_ManSetFlowRefs( pGia, vFlowRefs );
+ pGia->pRefs= Vec_IntReleaseArray(vFlowRefs);
+ Vec_IntFree(vFlowRefs);
+ // create
+ p = ABC_CALLOC( Of_Man_t, 1 );
+ p->clkStart = Abc_Clock();
+ p->pGia = pGia;
+ p->pPars = pPars;
+ Vec_IntFill( &p->vBests1, Gia_ManObjNum(pGia), -1 );
+ Vec_IntFill( &p->vBests2, Gia_ManObjNum(pGia), -1 );
+ Vec_IntFill( &p->vDelays1, Gia_ManObjNum(pGia), -1 );
+ Vec_IntFill( &p->vDelays2, Gia_ManObjNum(pGia), -1 );
+ p->iCur = 2;
+ // other
+ Vec_PtrGrow( &p->vPages, 256 ); // cut memory
+ Vec_IntFill( &p->vCutSets, Gia_ManObjNum(pGia), 0 ); // cut offsets
+ Vec_FltFill( &p->vCutFlows, Gia_ManObjNum(pGia), 0 ); // cut area
+ Vec_IntFill( &p->vCutDelays,Gia_ManObjNum(pGia), 0 ); // cut delay
+ p->vTtMem = Vec_MemAllocForTT( 6, 0 );
+ return p;
+}
+void Of_StoDelete( Of_Man_t * p )
+{
+ Vec_PtrFreeData( &p->vPages );
+ ABC_FREE( p->vPages.pArray );
+ ABC_FREE( p->vCutSets.pArray );
+ ABC_FREE( p->vCutFlows.pArray );
+ ABC_FREE( p->vCutDelays.pArray );
+ Vec_IntErase( &p->vBests1 );
+ Vec_IntErase( &p->vBests2 );
+ Vec_IntErase( &p->vDelays1 );
+ Vec_IntErase( &p->vDelays2 );
+ // matching
+ Vec_MemHashFree( p->vTtMem );
+ Vec_MemFree( p->vTtMem );
+ ABC_FREE( p );
+}
+
+
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Of_CutComputeTruth6( Of_Man_t * p, Of_Cut_t * pCut0, Of_Cut_t * pCut1, int fCompl0, int fCompl1, Of_Cut_t * pCutR, int fIsXor )
+{
+// extern int Of_ManTruthCanonicize( word * t, int nVars );
+ int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
+ word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
+ word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
+ if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
+ if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
+ t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t = fIsXor ? t0 ^ t1 : t0 & t1;
+ if ( (fCompl = (int)(t & 1)) ) t = ~t;
+ pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
+ assert( (int)(t & 1) == 0 );
+ truthId = Vec_MemHashInsert(p->vTtMem, &t);
+ pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
+ assert( (int)pCutR->nLeaves <= nOldSupp );
+ return (int)pCutR->nLeaves < nOldSupp;
+}
+static inline int Of_CutComputeTruthMux6( Of_Man_t * p, Of_Cut_t * pCut0, Of_Cut_t * pCut1, Of_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Of_Cut_t * pCutR )
+{
+ int nOldSupp = pCutR->nLeaves, truthId, fCompl; word t;
+ word t0 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut0->iFunc));
+ word t1 = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut1->iFunc));
+ word tC = *Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCutC->iFunc));
+ if ( Abc_LitIsCompl(pCut0->iFunc) ^ fCompl0 ) t0 = ~t0;
+ if ( Abc_LitIsCompl(pCut1->iFunc) ^ fCompl1 ) t1 = ~t1;
+ if ( Abc_LitIsCompl(pCutC->iFunc) ^ fComplC ) tC = ~tC;
+ t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ tC = Abc_Tt6Expand( tC, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
+ t = (tC & t1) | (~tC & t0);
+ if ( (fCompl = (int)(t & 1)) ) t = ~t;
+ pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
+ assert( (int)(t & 1) == 0 );
+ truthId = Vec_MemHashInsert(p->vTtMem, &t);
+ pCutR->iFunc = Abc_Var2Lit( truthId, fCompl );
+ assert( (int)pCutR->nLeaves <= nOldSupp );
+ return (int)pCutR->nLeaves < nOldSupp;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Of_CutCountBits( word i )
+{
+ i = i - ((i >> 1) & 0x5555555555555555);
+ i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
+ i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
+ return (i*(0x0101010101010101))>>56;
+}
+static inline word Of_CutGetSign( int * pLeaves, int nLeaves )
+{
+ word Sign = 0; int i;
+ for ( i = 0; i < nLeaves; i++ )
+ Sign |= ((word)1) << (pLeaves[i] & 0x3F);
+ return Sign;
+}
+static inline int Of_CutCreateUnit( Of_Cut_t * p, int i )
+{
+ p->Delay = 0;
+ p->Flow = 0;
+ p->iFunc = 2;
+ p->nLeaves = 1;
+ p->pLeaves[0] = i;
+ p->Useless = 0;
+ p->Sign = ((word)1) << (i & 0x3F);
+ return 1;
+}
+static inline void Of_Cutprintf( Of_Man_t * p, Of_Cut_t * pCut )
+{
+ int i, nDigits = Abc_Base10Log(Gia_ManObjNum(p->pGia));
+ printf( "%d {", pCut->nLeaves );
+ for ( i = 0; i < (int)pCut->nLeaves; i++ )
+ printf( " %*d", nDigits, pCut->pLeaves[i] );
+ for ( ; i < (int)p->pPars->nLutSize; i++ )
+ printf( " %*s", nDigits, " " );
+ printf( " } Useless = %d. D = %4d A = %9.4f F = %6d ",
+ pCut->Useless, pCut->Delay, pCut->Flow, pCut->iFunc );
+ if ( p->vTtMem )
+ Dau_DsdPrintFromTruth( Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut->iFunc)), pCut->nLeaves );
+ else
+ printf( "\n" );
+}
+static inline int Of_ManPrepareCuts( Of_Cut_t * pCuts, Of_Man_t * p, int iObj, int fAddUnit )
+{
+ if ( Of_ObjHasCuts(p, iObj) )
+ {
+ Of_Cut_t * pMfCut = pCuts;
+ int i, * pCut, * pList = Of_ObjCutSet(p, iObj);
+ Of_SetForEachCut( pList, pCut, i )
+ {
+ pMfCut->Delay = 0;
+ pMfCut->Flow = 0;
+ pMfCut->iFunc = Of_CutFunc( pCut );
+ pMfCut->nLeaves = Of_CutSize( pCut );
+ pMfCut->Sign = Of_CutGetSign( pCut+1, Of_CutSize(pCut) );
+ memcpy( pMfCut->pLeaves, pCut+1, sizeof(int) * Of_CutSize(pCut) );
+ pMfCut++;
+ }
+ if ( fAddUnit && pCuts->nLeaves > 1 )
+ return pList[0] + Of_CutCreateUnit( pMfCut, iObj );
+ return pList[0];
+ }
+ return Of_CutCreateUnit( pCuts, iObj );
+}
+static inline int Of_ManSaveCuts( Of_Man_t * p, Of_Cut_t ** pCuts, int nCuts, int fUseful )
+{
+ int i, * pPlace, iCur, nInts = 1, nCutsNew = 0;
+ for ( i = 0; i < nCuts; i++ )
+ if ( !fUseful || !pCuts[i]->Useless )
+ nInts += pCuts[i]->nLeaves + OF_CUT_EXTRA, nCutsNew++;
+ if ( (p->iCur & 0xFFFF) + nInts > 0xFFFF )
+ p->iCur = ((p->iCur >> 16) + 1) << 16;
+ if ( Vec_PtrSize(&p->vPages) == (p->iCur >> 16) )
+ Vec_PtrPush( &p->vPages, ABC_ALLOC(int, (1<<16)) );
+ iCur = p->iCur; p->iCur += nInts;
+ pPlace = Of_ManCutSet( p, iCur );
+ *pPlace++ = nCutsNew;
+ for ( i = 0; i < nCuts; i++ )
+ if ( !fUseful || !pCuts[i]->Useless )
+ {
+ *pPlace++ = Of_CutSetBoth( pCuts[i]->nLeaves, pCuts[i]->iFunc );
+ memcpy( pPlace, pCuts[i]->pLeaves, sizeof(int) * pCuts[i]->nLeaves );
+ pPlace += pCuts[i]->nLeaves;
+ memset( pPlace, 0xFF, sizeof(int) * (OF_CUT_EXTRA - 1) );
+ pPlace += OF_CUT_EXTRA - 1;
+ }
+ return iCur;
+}
+static inline int Of_ManCountUseful( Of_Cut_t ** pCuts, int nCuts )
+{
+ int i, Count = 0;
+ for ( i = 0; i < nCuts; i++ )
+ Count += !pCuts[i]->Useless;
+ return Count;
+}
+static inline void Of_ManLiftCuts( Of_Man_t * p, int iObj )
+{
+ int i, k, * pCut, * pList = Of_ObjCutSet(p, iObj);
+ assert( Of_ObjHasCuts(p, iObj) );
+ Of_SetForEachCut( pList, pCut, i )
+ {
+ for ( k = 1; k <= Of_CutSize(pCut); k++ )
+ pCut[k] = Abc_Var2Lit(pCut[k], 0);
+ }
+}
+
+/**Function*************************************************************
+
+ Synopsis [Check correctness of cuts.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Of_CutCheck( Of_Cut_t * pBase, Of_Cut_t * pCut ) // check if pCut is contained in pBase
+{
+ int nSizeB = pBase->nLeaves;
+ int nSizeC = pCut->nLeaves;
+ int i, * pB = pBase->pLeaves;
+ int k, * pC = pCut->pLeaves;
+ for ( i = 0; i < nSizeC; i++ )
+ {
+ for ( k = 0; k < nSizeB; k++ )
+ if ( pC[i] == pB[k] )
+ break;
+ if ( k == nSizeB )
+ return 0;
+ }
+ return 1;
+}
+static inline int Of_SetCheckArray( Of_Cut_t ** ppCuts, int nCuts )
+{
+ Of_Cut_t * pCut0, * pCut1;
+ int i, k, m, n, Value;
+ assert( nCuts > 0 );
+ for ( i = 0; i < nCuts; i++ )
+ {
+ pCut0 = ppCuts[i];
+ assert( pCut0->nLeaves <= OF_LEAF_MAX );
+ assert( pCut0->Sign == Of_CutGetSign(pCut0->pLeaves, pCut0->nLeaves) );
+ // check duplicates
+ for ( m = 0; m < (int)pCut0->nLeaves; m++ )
+ for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
+ assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
+ // check pairs
+ for ( k = 0; k < nCuts; k++ )
+ {
+ pCut1 = ppCuts[k];
+ if ( pCut0 == pCut1 )
+ continue;
+ // check containments
+ Value = Of_CutCheck( pCut0, pCut1 );
+ assert( Value == 0 );
+ }
+ }
+ return 1;
+}
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+static inline int Of_CutMergeOrder( Of_Cut_t * pCut0, Of_Cut_t * pCut1, Of_Cut_t * pCut, int nLutSize )
+{
+ int nSize0 = pCut0->nLeaves;
+ int nSize1 = pCut1->nLeaves;
+ int i, * pC0 = pCut0->pLeaves;
+ int k, * pC1 = pCut1->pLeaves;
+ int c, * pC = pCut->pLeaves;
+ // the case of the largest cut sizes
+ if ( nSize0 == nLutSize && nSize1 == nLutSize )
+ {
+ for ( i = 0; i < nSize0; i++ )
+ {
+ if ( pC0[i] != pC1[i] ) return 0;
+ pC[i] = pC0[i];
+ }
+ pCut->nLeaves = nLutSize;
+ pCut->iFunc = OF_NO_FUNC;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+ }
+ // compare two cuts with different numbers
+ i = k = c = 0;
+ if ( nSize0 == 0 ) goto FlushCut1;
+ if ( nSize1 == 0 ) goto FlushCut0;
+ while ( 1 )
+ {
+ if ( c == nLutSize ) return 0;
+ if ( pC0[i] < pC1[k] )
+ {
+ pC[c++] = pC0[i++];
+ if ( i >= nSize0 ) goto FlushCut1;
+ }
+ else if ( pC0[i] > pC1[k] )
+ {
+ pC[c++] = pC1[k++];
+ if ( k >= nSize1 ) goto FlushCut0;
+ }
+ else
+ {
+ pC[c++] = pC0[i++]; k++;
+ if ( i >= nSize0 ) goto FlushCut1;
+ if ( k >= nSize1 ) goto FlushCut0;
+ }
+ }
+
+FlushCut0:
+ if ( c + nSize0 > nLutSize + i ) return 0;
+ while ( i < nSize0 )
+ pC[c++] = pC0[i++];
+ pCut->nLeaves = c;
+ pCut->iFunc = OF_NO_FUNC;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+
+FlushCut1:
+ if ( c + nSize1 > nLutSize + k ) return 0;
+ while ( k < nSize1 )
+ pC[c++] = pC1[k++];
+ pCut->nLeaves = c;
+ pCut->iFunc = OF_NO_FUNC;
+ pCut->Sign = pCut0->Sign | pCut1->Sign;
+ return 1;
+}
+static inline int Of_CutMergeOrderMux( Of_Cut_t * pCut0, Of_Cut_t * pCut1, Of_Cut_t * pCut2, Of_Cut_t * pCut, int nLutSize )
+{
+ int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
+ int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
+ int x2, i2 = 0, nSize2 = pCut2->nLeaves, * pC2 = pCut2->pLeaves;
+ int xMin, c = 0, * pC = pCut->pLeaves;
+ while ( 1 )
+ {
+ x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
+ x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
+ x2 = (i2 == nSize2) ? ABC_INFINITY : pC2[i2];
+ xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
+ if ( xMin == ABC_INFINITY ) break;
+ if ( c == nLutSize ) return 0;
+ pC[c++] = xMin;
+ if (x0 == xMin) i0++;
+ if (x1 == xMin) i1++;
+ if (x2 == xMin) i2++;
+ }
+ pCut->nLeaves = c;
+ pCut->iFunc = OF_NO_FUNC;
+ pCut->Sign = pCut0->Sign | pCut1->Sign | pCut2->Sign;
+ return 1;
+}
+static inline int Of_SetCutIsContainedOrder( Of_Cut_t * pBase, Of_Cut_t * pCut ) // check if pCut is contained in pBase
+{
+ int i, nSizeB = pBase->nLeaves;
+ int k, nSizeC = pCut->nLeaves;
+ if ( nSizeB == nSizeC )
+ {
+ for ( i = 0; i < nSizeB; i++ )
+ if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
+ return 0;
+ return 1;
+ }
+ assert( nSizeB > nSizeC );
+ if ( nSizeC == 0 )
+ return 1;
+ for ( i = k = 0; i < nSizeB; i++ )
+ {
+ if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
+ return 0;
+ if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
+ {
+ if ( ++k == nSizeC )
+ return 1;
+ }
+ }
+ return 0;
+}
+static inline int Of_SetLastCutIsContained( Of_Cut_t ** pCuts, int nCuts )
+{
+ int i;
+ for ( i = 0; i < nCuts; i++ )
+ if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Of_SetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
+ return 1;
+ return 0;
+}
+static inline int Of_SetLastCutContainsArea( Of_Cut_t ** pCuts, int nCuts )
+{
+ int i, k, fChanges = 0;
+ for ( i = 0; i < nCuts; i++ )
+ if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Of_SetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
+ pCuts[i]->nLeaves = OF_NO_LEAF, fChanges = 1;
+ if ( !fChanges )
+ return nCuts;
+ for ( i = k = 0; i <= nCuts; i++ )
+ {
+ if ( pCuts[i]->nLeaves == OF_NO_LEAF )
+ continue;
+ if ( k < i )
+ ABC_SWAP( Of_Cut_t *, pCuts[k], pCuts[i] );
+ k++;
+ }
+ return k - 1;
+}
+static inline int Of_CutCompareArea( Of_Cut_t * pCut0, Of_Cut_t * pCut1 )
+{
+ if ( pCut0->Useless < pCut1->Useless ) return -1;
+ if ( pCut0->Useless > pCut1->Useless ) return 1;
+ if ( pCut0->Delay < pCut1->Delay ) return -1;
+ if ( pCut0->Delay > pCut1->Delay ) return 1;
+ if ( pCut0->Flow < pCut1->Flow ) return -1;
+ if ( pCut0->Flow > pCut1->Flow ) return 1;
+ if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
+ if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
+ return 0;
+}
+static inline void Of_SetSortByArea( Of_Cut_t ** pCuts, int nCuts )
+{
+ int i;
+ for ( i = nCuts; i > 0; i-- )
+ {
+ if ( Of_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )//!= 1 )
+ return;
+ ABC_SWAP( Of_Cut_t *, pCuts[i - 1], pCuts[i] );
+ }
+}
+static inline int Of_SetAddCut( Of_Cut_t ** pCuts, int nCuts, int nCutNum )
+{
+ if ( nCuts == 0 )
+ return 1;
+ nCuts = Of_SetLastCutContainsArea(pCuts, nCuts);
+ Of_SetSortByArea( pCuts, nCuts );
+ return Abc_MinInt( nCuts + 1, nCutNum - 1 );
+}
+static inline int Of_CutArea( Of_Man_t * p, int nLeaves )
+{
+ if ( nLeaves < 2 )
+ return 0;
+ return nLeaves + p->pPars->nAreaTuner;
+}
+static inline void Of_CutParams( Of_Man_t * p, Of_Cut_t * pCut, int nGiaRefs )
+{
+ int i, nLeaves = pCut->nLeaves;
+ assert( nLeaves <= p->pPars->nLutSize );
+ pCut->Delay = 0;
+ pCut->Flow = 0;
+ for ( i = 0; i < nLeaves; i++ )
+ {
+ pCut->Delay = Abc_MaxInt( pCut->Delay, Of_ObjCutDelay(p, pCut->pLeaves[i]) );
+ pCut->Flow += Of_ObjCutFlow(p, pCut->pLeaves[i]);
+ }
+ pCut->Delay += (int)(nLeaves > 1);
+ pCut->Flow = (pCut->Flow + Of_CutArea(p, nLeaves)) / (nGiaRefs ? nGiaRefs : 1);
+}
+void Of_ObjMergeOrder( Of_Man_t * p, int iObj )
+{
+ Of_Cut_t pCuts0[OF_CUT_MAX], pCuts1[OF_CUT_MAX], pCuts[OF_CUT_MAX], * pCutsR[OF_CUT_MAX];
+ Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
+ int nGiaRefs = 2*Gia_ObjRefNumId(p->pGia, iObj);
+ int nLutSize = p->pPars->nLutSize;
+ int nCutNum = p->pPars->nCutNum;
+ int nCuts0 = Of_ManPrepareCuts(pCuts0, p, Gia_ObjFaninId0(pObj, iObj), 1);
+ int nCuts1 = Of_ManPrepareCuts(pCuts1, p, Gia_ObjFaninId1(pObj, iObj), 1);
+ int fComp0 = Gia_ObjFaninC0(pObj);
+ int fComp1 = Gia_ObjFaninC1(pObj);
+ int iSibl = Gia_ObjSibl(p->pGia, iObj);
+ Of_Cut_t * pCut0, * pCut1, * pCut0Lim = pCuts0 + nCuts0, * pCut1Lim = pCuts1 + nCuts1;
+ int i, nCutsUse, nCutsR = 0;
+ assert( !Gia_ObjIsBuf(pObj) );
+ for ( i = 0; i < nCutNum; i++ )
+ pCutsR[i] = pCuts + i;
+ if ( iSibl )
+ {
+ Of_Cut_t pCuts2[OF_CUT_MAX];
+ Gia_Obj_t * pObjE = Gia_ObjSiblObj(p->pGia, iObj);
+ int fCompE = Gia_ObjPhase(pObj) ^ Gia_ObjPhase(pObjE);
+ int nCuts2 = Of_ManPrepareCuts(pCuts2, p, iSibl, 0);
+ Of_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
+ for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
+ {
+ *pCutsR[nCutsR] = *pCut2;
+ pCutsR[nCutsR]->iFunc = Abc_LitNotCond( pCutsR[nCutsR]->iFunc, fCompE );
+ Of_CutParams( p, pCutsR[nCutsR], nGiaRefs );
+ nCutsR = Of_SetAddCut( pCutsR, nCutsR, nCutNum );
+ }
+ }
+ if ( Gia_ObjIsMuxId(p->pGia, iObj) )
+ {
+ Of_Cut_t pCuts2[OF_CUT_MAX];
+ int nCuts2 = Of_ManPrepareCuts(pCuts2, p, Gia_ObjFaninId2(p->pGia, iObj), 1);
+ int fComp2 = Gia_ObjFaninC2(p->pGia, pObj);
+ Of_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
+ p->CutCount[0] += nCuts0 * nCuts1 * nCuts2;
+ for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
+ for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
+ for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
+ {
+ if ( Of_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > nLutSize )
+ continue;
+ p->CutCount[1]++;
+ if ( !Of_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
+ continue;
+ if ( Of_SetLastCutIsContained(pCutsR, nCutsR) )
+ continue;
+ p->CutCount[2]++;
+ if ( Of_CutComputeTruthMux6(p, pCut0, pCut1, pCut2, fComp0, fComp1, fComp2, pCutsR[nCutsR]) )
+ pCutsR[nCutsR]->Sign = Of_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
+ Of_CutParams( p, pCutsR[nCutsR], nGiaRefs );
+ nCutsR = Of_SetAddCut( pCutsR, nCutsR, nCutNum );
+ }
+ }
+ else
+ {
+ int fIsXor = Gia_ObjIsXor(pObj);
+ p->CutCount[0] += nCuts0 * nCuts1;
+ for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
+ for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
+ {
+ if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nLutSize && Of_CutCountBits(pCut0->Sign | pCut1->Sign) > nLutSize )
+ continue;
+ p->CutCount[1]++;
+ if ( !Of_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
+ continue;
+ if ( Of_SetLastCutIsContained(pCutsR, nCutsR) )
+ continue;
+ p->CutCount[2]++;
+ if ( Of_CutComputeTruth6(p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
+ pCutsR[nCutsR]->Sign = Of_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
+ Of_CutParams( p, pCutsR[nCutsR], nGiaRefs );
+ nCutsR = Of_SetAddCut( pCutsR, nCutsR, nCutNum );
+ }
+ }
+ // debug printout
+ if ( 0 )
+// if ( iObj % 10000 == 0 )
+// if ( iObj == 1090 )
+ {
+ printf( "*** Obj = %d Useful = %d\n", iObj, Of_ManCountUseful(pCutsR, nCutsR) );
+ for ( i = 0; i < nCutsR; i++ )
+ Of_Cutprintf( p, pCutsR[i] );
+ printf( "\n" );
+ }
+ // verify
+ assert( nCutsR > 0 && nCutsR < nCutNum );
+ //assert( Of_SetCheckArray(pCutsR, nCutsR) );
+ // store the cutset
+ Of_ObjSetCutFlow( p, iObj, pCutsR[0]->Flow );
+ Of_ObjSetCutDelay( p, iObj, pCutsR[0]->Delay );
+ *Vec_IntEntryP(&p->vCutSets, iObj) = Of_ManSaveCuts(p, pCutsR, nCutsR, 0);
+ p->CutCount[3] += nCutsR;
+ nCutsUse = Of_ManCountUseful(pCutsR, nCutsR);
+ p->CutCount[4] += nCutsUse;
+ p->nCutUseAll += nCutsUse == nCutsR;
+}
+void Of_ManComputeCuts( Of_Man_t * p )
+{
+ Gia_Obj_t * pObj; int i, iFanin;
+ Gia_ManForEachAnd( p->pGia, pObj, i )
+ if ( Gia_ObjIsBuf(pObj) )
+ {
+ iFanin = Gia_ObjFaninId0(pObj, i);
+ Of_ObjSetCutFlow( p, i, Of_ObjCutFlow(p, iFanin) );
+ Of_ObjSetCutDelay( p, i, Of_ObjCutDelay(p, iFanin) );
+ }
+ else
+ Of_ObjMergeOrder( p, i );
+ Gia_ManForEachAnd( p->pGia, pObj, i )
+ if ( !Gia_ObjIsBuf(pObj) )
+ Of_ManLiftCuts( p, i );
+}
+
+
+
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Of_ManPrintStats( Of_Man_t * p, char * pTitle )
+{
+ if ( !p->pPars->fVerbose )
+ return;
+ printf( "%s : ", pTitle );
+ printf( "Delay =%8.2f ", p->pPars->MapDelay );
+ printf( "Area =%12.2f ", p->pPars->MapArea );
+ printf( "Gate =%6d ", (int)p->pPars->Area );
+ printf( "Inv =%6d ", (int)p->nInvs );
+ printf( "Edge =%7d ", (int)p->pPars->Edge );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
+ fflush( stdout );
+}
+void Of_ManPrintInit( Of_Man_t * p )
+{
+ int nChoices;
+ if ( !p->pPars->fVerbose )
+ return;
+ printf( "LutSize = %d ", p->pPars->nLutSize );
+ printf( "CutNum = %d ", p->pPars->nCutNum );
+ printf( "Iter = %d ", p->pPars->nRounds + p->pPars->nRoundsEla );
+ printf( "Coarse = %d ", p->pPars->fCoarsen );
+ printf( "Funcs = %d ", Vec_MemEntryNum(p->vTtMem) );
+ nChoices = Gia_ManChoiceNum( p->pGia );
+ if ( nChoices )
+ printf( "Choices = %d ", nChoices );
+ printf( "\n" );
+ printf( "Computing cuts...\r" );
+ fflush( stdout );
+}
+void Of_ManPrintQuit( Of_Man_t * p )
+{
+ float MemGia = Gia_ManMemory(p->pGia) / (1<<20);
+ float MemMan = 16.0 * sizeof(int) * Gia_ManObjNum(p->pGia) / (1<<20);
+ float MemCuts = 1.0 * sizeof(int) * (1 << 16) * Vec_PtrSize(&p->vPages) / (1<<20);
+ float MemTt = p->vTtMem ? Vec_MemMemory(p->vTtMem) / (1<<20) : 0;
+ if ( p->CutCount[0] == 0 )
+ p->CutCount[0] = 1;
+ if ( !p->pPars->fVerbose )
+ return;
+ printf( "CutPair = %.0f ", p->CutCount[0] );
+ printf( "Merge = %.0f (%.1f) ", p->CutCount[1], 1.0*p->CutCount[1]/Gia_ManAndNum(p->pGia) );
+ printf( "Eval = %.0f (%.1f) ", p->CutCount[2], 1.0*p->CutCount[2]/Gia_ManAndNum(p->pGia) );
+ printf( "Cut = %.0f (%.1f) ", p->CutCount[3], 1.0*p->CutCount[3]/Gia_ManAndNum(p->pGia) );
+ printf( "Use = %.0f (%.1f) ", p->CutCount[4], 1.0*p->CutCount[4]/Gia_ManAndNum(p->pGia) );
+ printf( "Mat = %.0f (%.1f) ", p->CutCount[5], 1.0*p->CutCount[5]/Gia_ManAndNum(p->pGia) );
+// printf( "Equ = %d (%.2f %%) ", p->nCutUseAll, 100.0*p->nCutUseAll /p->CutCount[0] );
+ printf( "\n" );
+ printf( "Gia = %.2f MB ", MemGia );
+ printf( "Man = %.2f MB ", MemMan );
+ printf( "Cut = %.2f MB ", MemCuts );
+ printf( "TT = %.2f MB ", MemTt );
+ printf( "Total = %.2f MB ", MemGia + MemMan + MemCuts + MemTt );
+// printf( "\n" );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
+ fflush( stdout );
+}
+
+
+/**Function*************************************************************
+
+ Synopsis [Technology mappping.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Of_ManCutMatch( Of_Man_t * p, int iObj, int * pCut, int * pDelay1, int * pDelay2 )
+{
+ // Delay1 - main delay; Delay2 - precomputed LUT delay in terms of Delay1 for the fanins
+ int Delays[6], Perm[6];
+ int DelayLut1 = p->pPars->nDelayLut1;
+ int DelayLut2 = p->pPars->nDelayLut2;
+ int k, iVar, Flag, Delay, DelayMax = 0;
+ Of_CutForEachVarFlag( pCut, iVar, Flag, k )
+ {
+ Delays[k] = Of_ObjDelay1(p, iVar) + DelayLut1;
+ Perm[k] = iVar;
+// printf( "%3d%s ", iVar, Flag ? "*" : " " );
+ }
+ for ( ; k < p->pPars->nLutSize; k++ )
+ {
+ Delays[k] = -ABC_INFINITY;
+ Perm[k] = -1;
+// printf( " " );
+ }
+
+ Vec_IntSelectSortCost2Reverse( Perm, Of_CutSize(pCut), Delays );
+ *pDelay1 = *pDelay2 = 0;
+ for ( k = 0; k < Of_CutSize(pCut); k++ )
+ {
+ Delay = (k < p->pPars->nFastEdges && Gia_ObjIsAndNotBuf(Gia_ManObj(p->pGia, Perm[k]))) ? Of_ObjDelay2(p, Perm[k]) + DelayLut2 : Delays[k];// + DelayLut2;
+ *pDelay1 = Abc_MaxInt( *pDelay1, Delay );
+ *pDelay2 = Abc_MaxInt( *pDelay2, Delays[k] );
+ }
+// printf( " %5.2f", Of_Int2Flt(*pDelay1) );
+// printf( " %5.2f\n", Of_Int2Flt(*pDelay2) );
+ *pDelay1 = Abc_MinInt( *pDelay1, *pDelay2 );
+ assert( *pDelay1 <= *pDelay2 );
+ Of_CutSetDelay1( pCut, *pDelay1 );
+ Of_CutSetDelay2( pCut, *pDelay2 );
+}
+int Of_ManObjMatch( Of_Man_t * p, int iObj )
+{
+ int Delay1 = ABC_INFINITY, Delay2 = ABC_INFINITY;
+ int Delay1This, Delay2This;
+ int i, * pCut, * pList = Of_ObjCutSet(p, iObj);
+ Of_SetForEachCut( pList, pCut, i )
+ {
+ Of_ManCutMatch( p, iObj, pCut, &Delay1This, &Delay2This );
+ Delay1 = Abc_MinInt( Delay1, Delay1This );
+ Delay2 = Abc_MinInt( Delay2, Delay2This );
+ }
+ Of_ObjSetDelay1( p, iObj, Delay1 );
+ Of_ObjSetDelay2( p, iObj, Delay2 );
+ return Delay1;
+}
+void Of_ManComputeMapping( Of_Man_t * p )
+{
+ int Time = 0;
+ Gia_Obj_t * pObj; int i;
+ Gia_ManForEachAnd( p->pGia, pObj, i )
+ if ( Gia_ObjIsBuf(pObj) )
+ {
+ Of_ObjSetDelay1( p, i, Of_ObjDelay1(p, Gia_ObjFaninId0(pObj, i)) );
+ Of_ObjSetDelay2( p, i, Of_ObjDelay2(p, Gia_ObjFaninId0(pObj, i)) );
+ }
+ else
+ Time = Abc_MaxInt( Time, Of_ManObjMatch(p, i) );
+ printf( "Best delay = %.2f\n", Of_Int2Flt(Time) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Technology mappping.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Of_ManDeriveMapping( Of_Man_t * p )
+{
+}
+
+/**Function*************************************************************
+
+ Synopsis [Technology mappping.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Of_ManSetDefaultPars( Jf_Par_t * pPars )
+{
+ memset( pPars, 0, sizeof(Jf_Par_t) );
+ pPars->nLutSize = 4;
+ pPars->nCutNum = 16;
+ pPars->nProcNum = 0;
+ pPars->nRounds = 1;
+ pPars->nRoundsEla = 0;
+ pPars->nRelaxRatio = 0;
+ pPars->nCoarseLimit = 3;
+ pPars->nAreaTuner = 1;
+ pPars->DelayTarget = -1;
+ pPars->nDelayLut1 = 10;
+ pPars->nDelayLut2 = 2;
+ pPars->nFastEdges = 1;
+ pPars->fAreaOnly = 0;
+ pPars->fOptEdge = 1;
+ pPars->fCoarsen = 0;
+ pPars->fCutMin = 1;
+ pPars->fGenCnf = 0;
+ pPars->fPureAig = 0;
+ pPars->fVerbose = 0;
+ pPars->fVeryVerbose = 0;
+ pPars->nLutSizeMax = OF_LEAF_MAX;
+ pPars->nCutNumMax = OF_CUT_MAX;
+ pPars->MapDelayTarget = -1;
+ pPars->Epsilon = (float)0.01;
+}
+Gia_Man_t * Of_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars )
+{
+ Gia_Man_t * pNew = NULL, * pCls;
+ Of_Man_t * p; int i, Id;
+ if ( Gia_ManHasChoices(pGia) )
+ pPars->fCoarsen = 0;
+ pCls = pPars->fCoarsen ? Gia_ManDupMuxes(pGia, pPars->nCoarseLimit) : pGia;
+ p = Of_StoCreate( pCls, pPars );
+ if ( pPars->fVerbose && pPars->fCoarsen )
+ {
+ printf( "Initial " ); Gia_ManPrintMuxStats( pGia ); printf( "\n" );
+ printf( "Derived " ); Gia_ManPrintMuxStats( pCls ); printf( "\n" );
+ }
+ Of_ManPrintInit( p );
+ Of_ManComputeCuts( p );
+ Of_ManPrintQuit( p );
+
+ Gia_ManForEachCiId( p->pGia, Id, i )
+ {
+ int Time = Of_Flt2Int(p->pGia->vInArrs ? Abc_MaxFloat(0.0, Vec_FltEntry(p->pGia->vInArrs, i)) : 0.0);
+ Of_ObjSetDelay1( p, Id, Time );
+ Of_ObjSetDelay2( p, Id, Time );
+ }
+
+ for ( p->Iter = 0; p->Iter < p->pPars->nRounds; p->Iter++ )
+ {
+ Of_ManComputeMapping( p );
+ //Of_ManSetMapRefs( p );
+ Of_ManPrintStats( p, p->Iter ? "Area " : "Delay" );
+ }
+ p->fUseEla = 1;
+ for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla; p->Iter++ )
+ {
+ Of_ManComputeMapping( p );
+ //Of_ManUpdateStats( p );
+ Of_ManPrintStats( p, "Ela " );
+ }
+
+ pNew = NULL; //Of_ManDeriveMapping( p );
+// Gia_ManMappingVerify( pNew );
+ Of_StoDelete( p );
+ if ( pCls != pGia )
+ Gia_ManStop( pCls );
+ if ( pNew == NULL )
+ return Gia_ManDup( pGia );
+ return pNew;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
+ABC_NAMESPACE_IMPL_END
+
diff --git a/src/aig/gia/module.make b/src/aig/gia/module.make
index 0aecc70d..07038a09 100644
--- a/src/aig/gia/module.make
+++ b/src/aig/gia/module.make
@@ -46,6 +46,7 @@ SRC += src/aig/gia/giaAig.c \
src/aig/gia/giaMini.c \
src/aig/gia/giaMuxes.c \
src/aig/gia/giaNf.c \
+ src/aig/gia/giaOf.c \
src/aig/gia/giaPat.c \
src/aig/gia/giaPf.c \
src/aig/gia/giaQbf.c \
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index c8152d0e..55fe1ee9 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -413,6 +413,7 @@ static int Abc_CommandAbc9Kf ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandAbc9Lf ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Mf ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Nf ( Abc_Frame_t * pAbc, int argc, char ** argv );
+static int Abc_CommandAbc9Of ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Unmap ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Struct ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Trace ( Abc_Frame_t * pAbc, int argc, char ** argv );
@@ -1032,6 +1033,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "ABC9", "&lf", Abc_CommandAbc9Lf, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&mf", Abc_CommandAbc9Mf, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&nf", Abc_CommandAbc9Nf, 0 );
+ Cmd_CommandAdd( pAbc, "ABC9", "&of", Abc_CommandAbc9Of, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&unmap", Abc_CommandAbc9Unmap, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&struct", Abc_CommandAbc9Struct, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&trace", Abc_CommandAbc9Trace, 0 );
@@ -34024,6 +34026,237 @@ usage:
SeeAlso []
***********************************************************************/
+int Abc_CommandAbc9Of( Abc_Frame_t * pAbc, int argc, char ** argv )
+{
+ extern void Of_ManSetDefaultPars( Jf_Par_t * pPars );
+ extern Gia_Man_t * Of_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars );
+ char Buffer[200];
+ Jf_Par_t Pars, * pPars = &Pars;
+ Gia_Man_t * pNew; int c;
+ Of_ManSetDefaultPars( pPars );
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "KCFARLEDNMQekmpgtvwh" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'K':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nLutSize = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
+ {
+ Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
+ goto usage;
+ }
+ break;
+ case 'C':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nCutNum = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
+ {
+ Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
+ goto usage;
+ }
+ break;
+ case 'F':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nRounds = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nRounds < 0 )
+ goto usage;
+ break;
+ case 'A':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nRoundsEla = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nRoundsEla < 0 )
+ goto usage;
+ break;
+ case 'R':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
+ return 0;
+ }
+ pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nRelaxRatio < 0 )
+ goto usage;
+ break;
+ case 'L':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
+ return 0;
+ }
+ pPars->nCoarseLimit = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nCoarseLimit < 0 )
+ goto usage;
+ break;
+ case 'E':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( 1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
+ return 0;
+ }
+ pPars->nAreaTuner = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nAreaTuner < 0 )
+ goto usage;
+ break;
+ case 'D':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
+ goto usage;
+ }
+ pPars->DelayTarget = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->DelayTarget <= 0.0 )
+ goto usage;
+ break;
+ case 'N':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nDelayLut1 = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nDelayLut1 < 0 )
+ goto usage;
+ break;
+ case 'M':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nDelayLut2 = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nDelayLut2 < 0 )
+ goto usage;
+ break;
+ case 'Q':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-Q\" should be followed by a positive integer.\n" );
+ goto usage;
+ }
+ pPars->nFastEdges = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( pPars->nFastEdges < 0 )
+ goto usage;
+ break;
+ case 'e':
+ pPars->fOptEdge ^= 1;
+ break;
+ case 'k':
+ pPars->fCoarsen ^= 1;
+ break;
+ case 'm':
+ pPars->fCutMin ^= 1;
+ break;
+ case 'p':
+ pPars->fPower ^= 1;
+ break;
+ case 'g':
+ pPars->fPureAig ^= 1;
+ break;
+ case 't':
+ pPars->fDoAverage ^= 1;
+ break;
+ case 'v':
+ pPars->fVerbose ^= 1;
+ break;
+ case 'w':
+ pPars->fVeryVerbose ^= 1;
+ break;
+ case 'h':
+ default:
+ goto usage;
+ }
+ }
+
+ if ( pAbc->pGia == NULL )
+ {
+ Abc_Print( -1, "Empty GIA network.\n" );
+ return 1;
+ }
+ if ( Gia_ManHasMapping(pAbc->pGia) )
+ {
+ Abc_Print( -1, "Current AIG has mapping. Run \"&st\".\n" );
+ return 1;
+ }
+
+ pNew = Of_ManPerformMapping( pAbc->pGia, pPars );
+ if ( pNew == NULL )
+ {
+ Abc_Print( -1, "Abc_CommandAbc9Of(): Mapping into LUTs has failed.\n" );
+ return 1;
+ }
+ Abc_FrameUpdateGia( pAbc, pNew );
+ return 0;
+
+usage:
+ if ( pPars->DelayTarget == -1 )
+ sprintf(Buffer, "best possible" );
+ else
+ sprintf(Buffer, "%d", pPars->DelayTarget );
+ Abc_Print( -2, "usage: &of [-KCFARLEDNMQ num] [-kmpgtvwh]\n" );
+ Abc_Print( -2, "\t performs technology mapping of the network\n" );
+ Abc_Print( -2, "\t-K num : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
+ Abc_Print( -2, "\t-C num : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
+ Abc_Print( -2, "\t-F num : the number of area flow rounds [default = %d]\n", pPars->nRounds );
+ Abc_Print( -2, "\t-A num : the number of exact area rounds [default = %d]\n", pPars->nRoundsEla );
+ Abc_Print( -2, "\t-R num : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
+ Abc_Print( -2, "\t-L num : the fanout limit for coarsening XOR/MUX (num >= 2) [default = %d]\n", pPars->nCoarseLimit );
+ Abc_Print( -2, "\t-E num : the area/edge tradeoff parameter (0 <= num <= 100) [default = %d]\n", pPars->nAreaTuner );
+ Abc_Print( -2, "\t-D num : sets the delay constraint for the mapping [default = %s]\n", Buffer );
+ Abc_Print( -2, "\t-N num : delay of the first LUT [default = %d]\n", pPars->nDelayLut1 );
+ Abc_Print( -2, "\t-M num : delay of the second LUT [default = %d]\n", pPars->nDelayLut2 );
+ Abc_Print( -2, "\t-Q num : the number of fast non-routable edges [default = %d]\n", pPars->nFastEdges );
+ Abc_Print( -2, "\t-e : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
+ Abc_Print( -2, "\t-k : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
+ Abc_Print( -2, "\t-m : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
+ Abc_Print( -2, "\t-p : toggles power-aware cut selection heuristics [default = %s]\n", pPars->fPower? "yes": "no" );
+ Abc_Print( -2, "\t-g : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
+ Abc_Print( -2, "\t-t : toggles optimizing average rather than maximum level [default = %s]\n", pPars->fDoAverage? "yes": "no" );
+ Abc_Print( -2, "\t-v : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
+ Abc_Print( -2, "\t-w : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
+ Abc_Print( -2, "\t-h : prints the command usage\n");
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int Abc_CommandAbc9Unmap( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Gia_ManTestStruct( Gia_Man_t * p );
diff --git a/src/misc/vec/vecInt.h b/src/misc/vec/vecInt.h
index 8ef1c364..3d7c33fc 100644
--- a/src/misc/vec/vecInt.h
+++ b/src/misc/vec/vecInt.h
@@ -1843,6 +1843,20 @@ static inline void Vec_IntSelectSort( int * pArray, int nSize )
pArray[best_i] = temp;
}
}
+static inline void Vec_IntSelectSortReverse( int * pArray, int nSize )
+{
+ int temp, i, j, best_i;
+ for ( i = 0; i < nSize-1; i++ )
+ {
+ best_i = i;
+ for ( j = i+1; j < nSize; j++ )
+ if ( pArray[j] > pArray[best_i] )
+ best_i = j;
+ temp = pArray[i];
+ pArray[i] = pArray[best_i];
+ pArray[best_i] = temp;
+ }
+}
/**Function*************************************************************
@@ -1867,6 +1881,19 @@ static inline void Vec_IntSelectSortCost( int * pArray, int nSize, Vec_Int_t * v
ABC_SWAP( int, pArray[i], pArray[best_i] );
}
}
+static inline void Vec_IntSelectSortCostReverse( int * pArray, int nSize, Vec_Int_t * vCosts )
+{
+ int i, j, best_i;
+ for ( i = 0; i < nSize-1; i++ )
+ {
+ best_i = i;
+ for ( j = i+1; j < nSize; j++ )
+ if ( Vec_IntEntry(vCosts, pArray[j]) > Vec_IntEntry(vCosts, pArray[best_i]) )
+ best_i = j;
+ ABC_SWAP( int, pArray[i], pArray[best_i] );
+ }
+}
+
static inline void Vec_IntSelectSortCost2( int * pArray, int nSize, int * pCosts )
{
int i, j, best_i;
@@ -1880,6 +1907,19 @@ static inline void Vec_IntSelectSortCost2( int * pArray, int nSize, int * pCosts
ABC_SWAP( int, pCosts[i], pCosts[best_i] );
}
}
+static inline void Vec_IntSelectSortCost2Reverse( int * pArray, int nSize, int * pCosts )
+{
+ int i, j, best_i;
+ for ( i = 0; i < nSize-1; i++ )
+ {
+ best_i = i;
+ for ( j = i+1; j < nSize; j++ )
+ if ( pCosts[j] > pCosts[best_i] )
+ best_i = j;
+ ABC_SWAP( int, pArray[i], pArray[best_i] );
+ ABC_SWAP( int, pCosts[i], pCosts[best_i] );
+ }
+}
/**Function*************************************************************