abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcBidec.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcBidec.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Interface to bi-decomposition.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcBidec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "bool/bdc/bdc.h"
23 #include "bool/kit/kit.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 static inline Hop_Obj_t * Bdc_FunCopyHop( Bdc_Fun_t * pObj ) { return Hop_NotCond( (Hop_Obj_t *)Bdc_FuncCopy(Bdc_Regular(pObj)), Bdc_IsComplement(pObj) ); }
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Resynthesizes nodes using bi-decomposition.]
41 
42  Description []
43 
44  SideEffects []
45 
46  SeeAlso []
47 
48 ***********************************************************************/
49 Hop_Obj_t * Abc_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb )
50 {
51  unsigned * pTruth;
52  Bdc_Fun_t * pFunc;
53  int nNodes, i;
54  assert( nVars <= 16 );
55  // derive truth table
56  pTruth = Hop_ManConvertAigToTruth( pHop, Hop_Regular(pRoot), nVars, vTruth, 0 );
57  if ( Hop_IsComplement(pRoot) )
58  Extra_TruthNot( pTruth, pTruth, nVars );
59  // perform power-aware decomposition
60  if ( dProb >= 0.0 )
61  {
62  float Prob = (float)2.0 * dProb * (1.0 - dProb);
63  assert( Prob >= 0.0 && Prob <= 0.5 );
64  if ( Prob >= 0.4 )
65  {
66  Extra_TruthNot( puCare, puCare, nVars );
67  if ( dProb > 0.5 ) // more 1s than 0s
68  Extra_TruthOr( pTruth, pTruth, puCare, nVars );
69  else
70  Extra_TruthSharp( pTruth, pTruth, puCare, nVars );
71  Extra_TruthNot( puCare, puCare, nVars );
72  // decompose truth table
73  Bdc_ManDecompose( p, pTruth, NULL, nVars, NULL, 1000 );
74  }
75  else
76  {
77  // decompose truth table
78  Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
79  }
80  }
81  else
82  {
83  // decompose truth table
84  Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
85  }
86  // convert back into HOP
87  Bdc_FuncSetCopy( Bdc_ManFunc( p, 0 ), Hop_ManConst1( pHop ) );
88  for ( i = 0; i < nVars; i++ )
89  Bdc_FuncSetCopy( Bdc_ManFunc( p, i+1 ), Hop_ManPi( pHop, i ) );
90  nNodes = Bdc_ManNodeNum(p);
91  for ( i = nVars + 1; i < nNodes; i++ )
92  {
93  pFunc = Bdc_ManFunc( p, i );
95  }
96  return Bdc_FunCopyHop( Bdc_ManRoot(p) );
97 }
98 
99 /**Function*************************************************************
100 
101  Synopsis [Resynthesizes nodes using bi-decomposition.]
102 
103  Description []
104 
105  SideEffects []
106 
107  SeeAlso []
108 
109 ***********************************************************************/
110 void Abc_NtkBidecResyn( Abc_Ntk_t * pNtk, int fVerbose )
111 {
112  Bdc_Par_t Pars = {0}, * pPars = &Pars;
113  Bdc_Man_t * p;
114  Abc_Obj_t * pObj;
115  Vec_Int_t * vTruth;
116  int i, nGainTotal = 0, nNodes1, nNodes2;
117  abctime clk = Abc_Clock();
118  assert( Abc_NtkIsLogic(pNtk) );
119  if ( !Abc_NtkToAig(pNtk) )
120  return;
121  pPars->nVarsMax = Abc_NtkGetFaninMax( pNtk );
122  pPars->fVerbose = fVerbose;
123  if ( pPars->nVarsMax > 15 )
124  {
125  if ( fVerbose )
126  printf( "Resynthesis is not performed for nodes with more than 15 inputs.\n" );
127  pPars->nVarsMax = 15;
128  }
129  vTruth = Vec_IntAlloc( 0 );
130  p = Bdc_ManAlloc( pPars );
131  Abc_NtkForEachNode( pNtk, pObj, i )
132  {
133  if ( Abc_ObjFaninNum(pObj) > 15 )
134  continue;
135  nNodes1 = Hop_DagSize((Hop_Obj_t *)pObj->pData);
136  pObj->pData = Abc_NodeIfNodeResyn( p, (Hop_Man_t *)pNtk->pManFunc, (Hop_Obj_t *)pObj->pData, Abc_ObjFaninNum(pObj), vTruth, NULL, -1.0 );
137  nNodes2 = Hop_DagSize((Hop_Obj_t *)pObj->pData);
138  nGainTotal += nNodes1 - nNodes2;
139  }
140  Bdc_ManFree( p );
141  Vec_IntFree( vTruth );
142  if ( fVerbose )
143  {
144  printf( "Total gain in AIG nodes = %d. ", nGainTotal );
145  ABC_PRT( "Total runtime", Abc_Clock() - clk );
146  }
147 }
148 
149 
150 ////////////////////////////////////////////////////////////////////////
151 /// END OF FILE ///
152 ////////////////////////////////////////////////////////////////////////
153 
154 
156 
static void Extra_TruthOr(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:332
Bdc_Fun_t * Bdc_ManRoot(Bdc_Man_t *p)
Definition: bdcCore.c:47
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
int Hop_DagSize(Hop_Obj_t *pObj)
Definition: hopDfs.c:279
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition: bdcCore.c:68
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
ABC_DLL int Abc_NtkGetFaninMax(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:453
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Definition: bdcCore.c:291
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: hop.h:65
Bdc_Fun_t * Bdc_ManFunc(Bdc_Man_t *p, int i)
DECLARATIONS ///.
Definition: bdcCore.c:46
static Hop_Obj_t * Hop_ManPi(Hop_Man_t *p, int i)
Definition: hop.h:134
void * pManFunc
Definition: abc.h:191
void Bdc_FuncSetCopy(Bdc_Fun_t *p, void *pCopy)
Definition: bdcCore.c:54
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
typedefABC_NAMESPACE_HEADER_START struct Bdc_Fun_t_ Bdc_Fun_t
INCLUDES ///.
Definition: bdc.h:42
static ABC_NAMESPACE_IMPL_START Hop_Obj_t * Bdc_FunCopyHop(Bdc_Fun_t *pObj)
DECLARATIONS ///.
Definition: abcBidec.c:32
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static void Extra_TruthSharp(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:338
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
Bdc_Fun_t * Bdc_FuncFanin0(Bdc_Fun_t *p)
Definition: bdcCore.c:50
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Bdc_IsComplement(Bdc_Fun_t *p)
Definition: bdc.h:54
Definition: bdc.h:45
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
#define ABC_PRT(a, t)
Definition: abc_global.h:220
void Abc_NtkBidecResyn(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcBidec.c:110
Hop_Obj_t * Abc_NodeIfNodeResyn(Bdc_Man_t *p, Hop_Man_t *pHop, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, unsigned *puCare, float dProb)
FUNCTION DEFINITIONS ///.
Definition: abcBidec.c:49
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1192
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition: hopTruth.c:143
int Bdc_ManNodeNum(Bdc_Man_t *p)
Definition: bdcCore.c:48
#define assert(ex)
Definition: util_old.h:213
void Bdc_ManFree(Bdc_Man_t *p)
Definition: bdcCore.c:113
Bdc_Fun_t * Bdc_FuncFanin1(Bdc_Fun_t *p)
Definition: bdcCore.c:51
void * pData
Definition: abc.h:145
void * Bdc_FuncCopy(Bdc_Fun_t *p)
Definition: bdcCore.c:52
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
ABC_INT64_T abctime
Definition: abc_global.h:278
static void Extra_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:320
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
static Bdc_Fun_t * Bdc_Regular(Bdc_Fun_t *p)
Definition: bdc.h:55