abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lpkAbcDec.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [lpkAbcDec.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Fast Boolean matching for LUT structures.]
8 
9  Synopsis [The new core procedure.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: lpkAbcDec.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "lpkInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Implements the function.]
37 
38  Description [Returns the node implementing this function.]
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  extern Hop_Obj_t * Kit_TruthToHop( Hop_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory );
48  unsigned * pTruth;
49  Abc_Obj_t * pObjNew;
50  int i;
51  if ( p->fMark )
52  pMan->nMuxes++;
53  else
54  pMan->nDsds++;
55  // create the new node
56  pObjNew = Abc_NtkCreateNode( pNtk );
57  for ( i = 0; i < (int)p->nVars; i++ )
58  Abc_ObjAddFanin( pObjNew, Abc_ObjRegular((Abc_Obj_t *)Vec_PtrEntry(vLeaves, p->pFanins[i])) );
59  Abc_ObjSetLevel( pObjNew, Abc_ObjLevelNew(pObjNew) );
60  // assign the node's function
61  pTruth = Lpk_FunTruth(p, 0);
62  if ( p->nVars == 0 )
63  {
64  pObjNew->pData = Hop_NotCond( Hop_ManConst1((Hop_Man_t *)pNtk->pManFunc), !(pTruth[0] & 1) );
65  return pObjNew;
66  }
67  if ( p->nVars == 1 )
68  {
69  pObjNew->pData = Hop_NotCond( Hop_ManPi((Hop_Man_t *)pNtk->pManFunc, 0), (pTruth[0] & 1) );
70  return pObjNew;
71  }
72  // create the logic function
73  pObjNew->pData = Kit_TruthToHop( (Hop_Man_t *)pNtk->pManFunc, pTruth, p->nVars, NULL );
74  return pObjNew;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Implements the function.]
80 
81  Description [Returns the node implementing this function.]
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
88 Abc_Obj_t * Lpk_Implement_rec( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * pFun )
89 {
90  Abc_Obj_t * pFanin, * pRes;
91  int i;
92  // prepare the leaves of the function
93  for ( i = 0; i < (int)pFun->nVars; i++ )
94  {
95  pFanin = (Abc_Obj_t *)Vec_PtrEntry( vLeaves, pFun->pFanins[i] );
96  if ( !Abc_ObjIsComplement(pFanin) )
97  Lpk_Implement_rec( pMan, pNtk, vLeaves, (Lpk_Fun_t *)pFanin );
98  pFanin = (Abc_Obj_t *)Vec_PtrEntry( vLeaves, pFun->pFanins[i] );
99  assert( Abc_ObjIsComplement(pFanin) );
100  }
101  // construct the function
102  pRes = Lpk_ImplementFun( pMan, pNtk, vLeaves, pFun );
103  // replace the function
104  Vec_PtrWriteEntry( vLeaves, pFun->Id, Abc_ObjNot(pRes) );
105  Lpk_FunFree( pFun );
106  return pRes;
107 }
108 
109 /**Function*************************************************************
110 
111  Synopsis [Implements the function.]
112 
113  Description [Returns the node implementing this function.]
114 
115  SideEffects []
116 
117  SeeAlso []
118 
119 ***********************************************************************/
120 Abc_Obj_t * Lpk_Implement( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld )
121 {
122  Abc_Obj_t * pFanin, * pRes;
123  int i;
124  assert( nLeavesOld < Vec_PtrSize(vLeaves) );
125  // mark implemented nodes
126  Vec_PtrForEachEntryStop( Abc_Obj_t *, vLeaves, pFanin, i, nLeavesOld )
127  Vec_PtrWriteEntry( vLeaves, i, Abc_ObjNot(pFanin) );
128  // recursively construct starting from the first entry
129  pRes = Lpk_Implement_rec( pMan, pNtk, vLeaves, (Lpk_Fun_t *)Vec_PtrEntry( vLeaves, nLeavesOld ) );
130  Vec_PtrShrink( vLeaves, nLeavesOld );
131  return pRes;
132 }
133 
134 /**Function*************************************************************
135 
136  Synopsis [Decomposes the function using recursive MUX decomposition.]
137 
138  Description [Returns the ID of the top-most decomposition node
139  implementing this function, or 0 if there is no decomposition satisfying
140  the constraints on area and delay.]
141 
142  SideEffects []
143 
144  SeeAlso []
145 
146 ***********************************************************************/
148 {
149  Lpk_Res_t * pResMux, * pResDsd;
150  Lpk_Fun_t * p2;
151  abctime clk;
152 
153  // is only called for non-trivial blocks
154  assert( p->nLutK >= 3 && p->nLutK <= 6 );
155  assert( p->nVars > p->nLutK );
156  // skip if area bound is exceeded
157  if ( Lpk_LutNumLuts(p->nVars, p->nLutK) > (int)p->nAreaLim )
158  return 0;
159  // skip if delay bound is exceeded
160  if ( Lpk_SuppDelay(p->uSupp, p->pDelays) > (int)p->nDelayLim )
161  return 0;
162 
163  // compute supports if needed
164  if ( !p->fSupports )
166 
167  // check DSD decomposition
168 clk = Abc_Clock();
169  pResDsd = Lpk_DsdAnalize( pMan, p, pMan->pPars->nVarsShared );
170 pMan->timeEvalDsdAn += Abc_Clock() - clk;
171  if ( pResDsd && (pResDsd->nBSVars == (int)p->nLutK || pResDsd->nBSVars == (int)p->nLutK - 1) &&
172  pResDsd->AreaEst <= (int)p->nAreaLim && pResDsd->DelayEst <= (int)p->nDelayLim )
173  {
174 clk = Abc_Clock();
175  p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
176 pMan->timeEvalDsdSp += Abc_Clock() - clk;
177  assert( p2->nVars <= (int)p->nLutK );
178  if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
179  return 0;
180  return 1;
181  }
182 
183  // check MUX decomposition
184 clk = Abc_Clock();
185  pResMux = Lpk_MuxAnalize( pMan, p );
186 pMan->timeEvalMuxAn += Abc_Clock() - clk;
187 // pResMux = NULL;
188  assert( !pResMux || (pResMux->DelayEst <= (int)p->nDelayLim && pResMux->AreaEst <= (int)p->nAreaLim) );
189  // accept MUX decomposition if it is "good"
190  if ( pResMux && pResMux->nSuppSizeS <= (int)p->nLutK && pResMux->nSuppSizeL <= (int)p->nLutK )
191  pResDsd = NULL;
192  else if ( pResMux && pResDsd )
193  {
194  // compare two decompositions
195  if ( pResMux->AreaEst < pResDsd->AreaEst ||
196  (pResMux->AreaEst == pResDsd->AreaEst && pResMux->nSuppSizeL < pResDsd->nSuppSizeL) ||
197  (pResMux->AreaEst == pResDsd->AreaEst && pResMux->nSuppSizeL == pResDsd->nSuppSizeL && pResMux->DelayEst < pResDsd->DelayEst) )
198  pResDsd = NULL;
199  else
200  pResMux = NULL;
201  }
202  assert( pResMux == NULL || pResDsd == NULL );
203  if ( pResMux )
204  {
205 clk = Abc_Clock();
206  p2 = Lpk_MuxSplit( pMan, p, pResMux->Variable, pResMux->Polarity );
207 pMan->timeEvalMuxSp += Abc_Clock() - clk;
208  if ( p2->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p2 ) )
209  return 0;
210  if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
211  return 0;
212  return 1;
213  }
214  if ( pResDsd )
215  {
216 clk = Abc_Clock();
217  p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
218 pMan->timeEvalDsdSp += Abc_Clock() - clk;
219  assert( p2->nVars <= (int)p->nLutK );
220  if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
221  return 0;
222  return 1;
223  }
224  return 0;
225 }
226 
227 /**Function*************************************************************
228 
229  Synopsis [Removes decomposed nodes from the array of fanins.]
230 
231  Description []
232 
233  SideEffects []
234 
235  SeeAlso []
236 
237 ***********************************************************************/
238 void Lpk_DecomposeClean( Vec_Ptr_t * vLeaves, int nLeavesOld )
239 {
240  Lpk_Fun_t * pFunc;
241  int i;
242  Vec_PtrForEachEntryStart( Lpk_Fun_t *, vLeaves, pFunc, i, nLeavesOld )
243  Lpk_FunFree( pFunc );
244  Vec_PtrShrink( vLeaves, nLeavesOld );
245 }
246 
247 /**Function*************************************************************
248 
249  Synopsis [Decomposes the function using recursive MUX decomposition.]
250 
251  Description []
252 
253  SideEffects []
254 
255  SeeAlso []
256 
257 ***********************************************************************/
258 Abc_Obj_t * Lpk_Decompose( Lpk_Man_t * p, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, unsigned * puSupps, int nLutK, int AreaLim, int DelayLim )
259 {
260  Lpk_Fun_t * pFun;
261  Abc_Obj_t * pObjNew = NULL;
262  int nLeaves = Vec_PtrSize( vLeaves );
263  pFun = Lpk_FunCreate( pNtk, vLeaves, pTruth, nLutK, AreaLim, DelayLim );
264  if ( puSupps[0] || puSupps[1] )
265  {
266 /*
267  int i;
268  Lpk_FunComputeCofSupps( pFun );
269  for ( i = 0; i < nLeaves; i++ )
270  {
271  assert( pFun->puSupps[2*i+0] == puSupps[2*i+0] );
272  assert( pFun->puSupps[2*i+1] == puSupps[2*i+1] );
273  }
274 */
275  memcpy( pFun->puSupps, puSupps, sizeof(unsigned) * 2 * nLeaves );
276  pFun->fSupports = 1;
277  }
278  Lpk_FunSuppMinimize( pFun );
279  if ( pFun->nVars <= pFun->nLutK )
280  pObjNew = Lpk_ImplementFun( p, pNtk, vLeaves, pFun );
281  else if ( Lpk_Decompose_rec(p, pFun) )
282  pObjNew = Lpk_Implement( p, pNtk, vLeaves, nLeaves );
283  Lpk_DecomposeClean( vLeaves, nLeaves );
284  return pObjNew;
285 }
286 
287 
288 ////////////////////////////////////////////////////////////////////////
289 /// END OF FILE ///
290 ////////////////////////////////////////////////////////////////////////
291 
292 
294 
Abc_Obj_t * Lpk_Implement(Lpk_Man_t *pMan, Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, int nLeavesOld)
Definition: lpkAbcDec.c:120
unsigned nAreaLim
Definition: lpkInt.h:150
Lpk_Par_t * pPars
Definition: lpkInt.h:72
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int nCofVars
Definition: lpkInt.h:167
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
void Lpk_FunComputeCofSupps(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:186
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned nVars
Definition: lpkInt.h:148
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int Variable
Definition: lpkInt.h:173
int Lpk_SuppDelay(unsigned uSupp, char *pDelays)
Definition: lpkAbcUtil.c:215
unsigned nLutK
Definition: lpkInt.h:149
int AreaEst
Definition: lpkInt.h:172
abctime timeEvalMuxSp
Definition: lpkInt.h:135
unsigned uSupp
Definition: lpkInt.h:154
unsigned fSupports
Definition: lpkInt.h:152
char * memcpy()
void Lpk_FunFree(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:64
int nBSVars
Definition: lpkInt.h:165
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Abc_ObjSetLevel(Abc_Obj_t *pObj, int Level)
Definition: abc.h:341
Definition: hop.h:65
Hop_Obj_t * Kit_TruthToHop(Hop_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition: kitHop.c:146
Lpk_Fun_t * Lpk_DsdSplit(Lpk_Man_t *pMan, Lpk_Fun_t *p, char *pCofVars, int nCofVars, unsigned uBoundSet)
Definition: lpkAbcDsd.c:564
unsigned BSVars
Definition: lpkInt.h:166
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
unsigned Id
Definition: lpkInt.h:147
static unsigned * Lpk_FunTruth(Lpk_Fun_t *p, int Num)
Definition: lpkInt.h:179
static Hop_Obj_t * Hop_ManPi(Hop_Man_t *p, int i)
Definition: hop.h:134
abctime timeEvalMuxAn
Definition: lpkInt.h:134
void * pManFunc
Definition: abc.h:191
char pCofVars[4]
Definition: lpkInt.h:168
abctime timeEvalDsdSp
Definition: lpkInt.h:137
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Lpk_FunSuppMinimize(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:143
unsigned fMark
Definition: lpkInt.h:153
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Abc_Obj_t * Lpk_Implement_rec(Lpk_Man_t *pMan, Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, Lpk_Fun_t *pFun)
Definition: lpkAbcDec.c:88
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int DelayEst
Definition: lpkInt.h:171
int nSuppSizeS
Definition: lpkInt.h:169
static Abc_Obj_t * Abc_ObjRegular(Abc_Obj_t *p)
Definition: abc.h:323
int Lpk_Decompose_rec(Lpk_Man_t *pMan, Lpk_Fun_t *p)
Definition: lpkAbcDec.c:147
Lpk_Res_t * Lpk_DsdAnalize(Lpk_Man_t *pMan, Lpk_Fun_t *p, int nShared)
Definition: lpkAbcDsd.c:452
Abc_Obj_t * Lpk_Decompose(Lpk_Man_t *p, Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, unsigned *pTruth, unsigned *puSupps, int nLutK, int AreaLim, int DelayLim)
FUNCTION DECLARATIONS ///.
Definition: lpkAbcDec.c:258
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
Definition: vecPtr.h:59
void Lpk_DecomposeClean(Vec_Ptr_t *vLeaves, int nLeavesOld)
Definition: lpkAbcDec.c:238
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
char pDelays[16]
Definition: lpkInt.h:156
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
int Polarity
Definition: lpkInt.h:174
char pFanins[16]
Definition: lpkInt.h:157
static int Lpk_LutNumLuts(int nVarsMax, int nLutK)
Definition: lpkInt.h:178
abctime timeEvalDsdAn
Definition: lpkInt.h:136
#define assert(ex)
Definition: util_old.h:213
Lpk_Fun_t * Lpk_MuxSplit(Lpk_Man_t *pMan, Lpk_Fun_t *p, int Var, int Pol)
Definition: lpkAbcMux.c:164
static Abc_Obj_t * Abc_ObjNot(Abc_Obj_t *p)
Definition: abc.h:324
void * pData
Definition: abc.h:145
ABC_NAMESPACE_IMPL_START Abc_Obj_t * Lpk_ImplementFun(Lpk_Man_t *pMan, Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, Lpk_Fun_t *p)
DECLARATIONS ///.
Definition: lpkAbcDec.c:45
ABC_NAMESPACE_IMPL_START Lpk_Res_t * Lpk_MuxAnalize(Lpk_Man_t *pMan, Lpk_Fun_t *p)
DECLARATIONS ///.
Definition: lpkAbcMux.c:45
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
ABC_INT64_T abctime
Definition: abc_global.h:278
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
unsigned puSupps[32]
Definition: lpkInt.h:155
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
ABC_DLL int Abc_ObjLevelNew(Abc_Obj_t *pObj)
Definition: abcTiming.c:1058
int nSuppSizeL
Definition: lpkInt.h:170
Lpk_Fun_t * Lpk_FunCreate(Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, unsigned *pTruth, int nLutK, int AreaLim, int DelayLim)
Definition: lpkAbcUtil.c:80
unsigned nDelayLim
Definition: lpkInt.h:151