abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkBidec.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [nwkBidec.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Logic network representation.]
8 
9  Synopsis [Bi-decomposition of local functions.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: nwkBidec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "nwk.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static inline int Extra_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
31 static inline void Extra_TruthNot( unsigned * pOut, unsigned * pIn, int nVars )
32 {
33  int w;
34  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
35  pOut[w] = ~pIn[w];
36 }
37 static inline void Extra_TruthOr( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
38 {
39  int w;
40  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
41  pOut[w] = pIn0[w] | pIn1[w];
42 }
43 static inline void Extra_TruthSharp( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
44 {
45  int w;
46  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
47  pOut[w] = pIn0[w] & ~pIn1[w];
48 }
49 
50 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) ); }
51 
52 ////////////////////////////////////////////////////////////////////////
53 /// FUNCTION DEFINITIONS ///
54 ////////////////////////////////////////////////////////////////////////
55 
56 /**Function*************************************************************
57 
58  Synopsis [Resynthesizes nodes using bi-decomposition.]
59 
60  Description []
61 
62  SideEffects []
63 
64  SeeAlso []
65 
66 ***********************************************************************/
67 Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb )
68 {
69  unsigned * pTruth;
70  Bdc_Fun_t * pFunc;
71  int nNodes, i;
72  assert( nVars <= 16 );
73  // derive truth table
74  pTruth = Hop_ManConvertAigToTruth( pHop, Hop_Regular(pRoot), nVars, vTruth, 0 );
75  if ( Hop_IsComplement(pRoot) )
76  for ( i = Abc_TruthWordNum(nVars)-1; i >= 0; i-- )
77  pTruth[i] = ~pTruth[i];
78  // perform power-aware decomposition
79  if ( dProb >= 0.0 )
80  {
81  float Prob = (float)2.0 * dProb * (1.0 - dProb);
82  assert( Prob >= 0.0 && Prob <= 0.5 );
83  if ( Prob >= 0.4 )
84  {
85  Extra_TruthNot( puCare, puCare, nVars );
86  if ( dProb > 0.5 ) // more 1s than 0s
87  Extra_TruthOr( pTruth, pTruth, puCare, nVars );
88  else
89  Extra_TruthSharp( pTruth, pTruth, puCare, nVars );
90  Extra_TruthNot( puCare, puCare, nVars );
91  // decompose truth table
92  Bdc_ManDecompose( p, pTruth, NULL, nVars, NULL, 1000 );
93  }
94  else
95  {
96  // decompose truth table
97  Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
98  }
99  }
100  else
101  {
102  // decompose truth table
103  Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
104  }
105  // convert back into HOP
106  Bdc_FuncSetCopy( Bdc_ManFunc( p, 0 ), Hop_ManConst1( pHop ) );
107  for ( i = 0; i < nVars; i++ )
108  Bdc_FuncSetCopy( Bdc_ManFunc( p, i+1 ), Hop_ManPi( pHop, i ) );
109  nNodes = Bdc_ManNodeNum(p);
110  for ( i = nVars + 1; i < nNodes; i++ )
111  {
112  pFunc = Bdc_ManFunc( p, i );
114  }
115  return Bdc_FunCopyHop( Bdc_ManRoot(p) );
116 }
117 
118 /**Function*************************************************************
119 
120  Synopsis [Resynthesizes nodes using bi-decomposition.]
121 
122  Description []
123 
124  SideEffects []
125 
126  SeeAlso []
127 
128 ***********************************************************************/
129 void Nwk_ManBidecResyn( Nwk_Man_t * pNtk, int fVerbose )
130 {
131  Bdc_Par_t Pars = {0}, * pPars = &Pars;
132  Bdc_Man_t * p;
133  Nwk_Obj_t * pObj;
134  Vec_Int_t * vTruth;
135  int i, nGainTotal = 0, nNodes1, nNodes2;
136  abctime clk = Abc_Clock();
137  pPars->nVarsMax = Nwk_ManGetFaninMax( pNtk );
138  pPars->fVerbose = fVerbose;
139  if ( pPars->nVarsMax < 2 )
140  {
141  printf( "Resynthesis is not performed for networks whose nodes are less than 2 inputs.\n" );
142  return;
143  }
144  if ( pPars->nVarsMax > 15 )
145  {
146  if ( fVerbose )
147  printf( "Resynthesis is not performed for nodes with more than 15 inputs.\n" );
148  pPars->nVarsMax = 15;
149  }
150  vTruth = Vec_IntAlloc( 0 );
151  p = Bdc_ManAlloc( pPars );
152  Nwk_ManForEachNode( pNtk, pObj, i )
153  {
154  if ( Nwk_ObjFaninNum(pObj) > 15 )
155  continue;
156  nNodes1 = Hop_DagSize(pObj->pFunc);
157  pObj->pFunc = Nwk_NodeIfNodeResyn( p, pNtk->pManHop, pObj->pFunc, Nwk_ObjFaninNum(pObj), vTruth, NULL, -1.0 );
158  nNodes2 = Hop_DagSize(pObj->pFunc);
159  nGainTotal += nNodes1 - nNodes2;
160  }
161  Bdc_ManFree( p );
162  Vec_IntFree( vTruth );
163  if ( fVerbose )
164  {
165  printf( "Total gain in AIG nodes = %d. ", nGainTotal );
166  ABC_PRT( "Total runtime", Abc_Clock() - clk );
167  }
168 }
169 
170 
171 ////////////////////////////////////////////////////////////////////////
172 /// END OF FILE ///
173 ////////////////////////////////////////////////////////////////////////
174 
175 
177 
Bdc_Fun_t * Bdc_ManRoot(Bdc_Man_t *p)
Definition: bdcCore.c:47
void Nwk_ManBidecResyn(Nwk_Man_t *pNtk, int fVerbose)
Definition: nwkBidec.c:129
static Hop_Obj_t * Bdc_FunCopyHop(Bdc_Fun_t *pObj)
Definition: nwkBidec.c:50
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
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
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_TruthWordNum(int nVars)
Definition: abc_global.h:256
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
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
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 Bdc_FuncSetCopy(Bdc_Fun_t *p, void *pCopy)
Definition: bdcCore.c:54
Hop_Man_t * pManHop
Definition: nwk.h:73
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
Definition: nwk.h:61
static void Extra_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: nwkBidec.c:31
#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: nwkBidec.c:43
Bdc_Fun_t * Bdc_FuncFanin0(Bdc_Fun_t *p)
Definition: bdcCore.c:50
ABC_DLL int Nwk_ManGetFaninMax(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:71
#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
static ABC_NAMESPACE_IMPL_START int Extra_TruthWordNum(int nVars)
DECLARATIONS ///.
Definition: nwkBidec.c:30
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static void Extra_TruthOr(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: nwkBidec.c:37
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
Hop_Obj_t * Nwk_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: nwkBidec.c:67
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 * 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
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
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192