abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
resInt.h File Reference
#include "res.h"

Go to the source code of this file.

Data Structures

struct  Res_Win_t_
 
struct  Res_Sim_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_HEADER_START
struct Res_Win_t_ 
Res_Win_t
 INCLUDES ///. More...
 
typedef struct Res_Sim_t_ Res_Sim_t
 

Functions

void Res_WinDivisors (Res_Win_t *p, int nLevDivMax)
 MACRO DEFINITIONS ///. More...
 
void Res_WinSweepLeafTfo_rec (Abc_Obj_t *pObj, int nLevelLimit)
 
int Res_WinVisitMffc (Abc_Obj_t *pNode)
 
int Res_FilterCandidates (Res_Win_t *pWin, Abc_Ntk_t *pAig, Res_Sim_t *pSim, Vec_Vec_t *vResubs, Vec_Vec_t *vResubsW, int nFaninsMax, int fArea)
 FUNCTION DEFINITIONS ///. More...
 
int Res_FilterCandidatesArea (Res_Win_t *pWin, Abc_Ntk_t *pAig, Res_Sim_t *pSim, Vec_Vec_t *vResubs, Vec_Vec_t *vResubsW, int nFaninsMax)
 
void * Res_SatProveUnsat (Abc_Ntk_t *pAig, Vec_Ptr_t *vFanins)
 FUNCTION DEFINITIONS ///. More...
 
int Res_SatSimulate (Res_Sim_t *p, int nPats, int fOnSet)
 
Res_Sim_tRes_SimAlloc (int nWords)
 DECLARATIONS ///. More...
 
void Res_SimFree (Res_Sim_t *p)
 
int Res_SimPrepare (Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis, int fVerbose)
 
Abc_Ntk_tRes_WndStrash (Res_Win_t *p)
 FUNCTION DEFINITIONS ///. More...
 
void Res_UpdateNetwork (Abc_Obj_t *pObj, Vec_Ptr_t *vFanins, Hop_Obj_t *pFunc, Vec_Vec_t *vLevels)
 
Res_Win_tRes_WinAlloc ()
 DECLARATIONS ///. More...
 
void Res_WinFree (Res_Win_t *p)
 
int Res_WinIsTrivial (Res_Win_t *p)
 
int Res_WinCompute (Abc_Obj_t *pNode, int nWinTfiMax, int nWinTfoMax, Res_Win_t *p)
 

Typedef Documentation

typedef struct Res_Sim_t_ Res_Sim_t

Definition at line 69 of file resInt.h.

typedef typedefABC_NAMESPACE_HEADER_START struct Res_Win_t_ Res_Win_t

INCLUDES ///.

CFile****************************************************************

FileName [resInt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resynthesis package.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 15, 2007.]

Revision [

Id:
resInt.h,v 1.00 2007/01/15 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Definition at line 44 of file resInt.h.

Function Documentation

int Res_FilterCandidates ( Res_Win_t pWin,
Abc_Ntk_t pAig,
Res_Sim_t pSim,
Vec_Vec_t vResubs,
Vec_Vec_t vResubsW,
int  nFaninsMax,
int  fArea 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Finds sets of feasible candidates.]

Description []

SideEffects []

SeeAlso []

Definition at line 49 of file resFilter.c.

50 {
51  Abc_Obj_t * pFanin, * pFanin2, * pFaninTemp;
52  unsigned * pInfo, * pInfoDiv, * pInfoDiv2;
53  int Counter, RetValue, i, i2, d, d2, iDiv, iDiv2, k;
54 
55  // check that the info the node is one
56  pInfo = (unsigned *)Vec_PtrEntry( pSim->vOuts, 1 );
57  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
58  if ( RetValue == 0 )
59  {
60 // printf( "Failed 1!\n" );
61  return 0;
62  }
63 
64  // collect the fanin info
65  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~0 );
66  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
67  if ( RetValue == 0 )
68  {
69 // printf( "Failed 2!\n" );
70  return 0;
71  }
72 
73  // try removing each fanin
74 // printf( "Fanins: " );
75  Counter = 0;
76  Vec_VecClear( vResubs );
77  Vec_VecClear( vResubsW );
78  Abc_ObjForEachFanin( pWin->pNode, pFanin, i )
79  {
80  if ( fArea && Abc_ObjFanoutNum(pFanin) > 1 )
81  continue;
82  // get simulation info without this fanin
83  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~(1 << i) );
84  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
85  if ( RetValue )
86  {
87 // printf( "Node %4d. Candidate fanin %4d.\n", pWin->pNode->Id, pFanin->Id );
88  // collect the nodes
89  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
90  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
91  Abc_ObjForEachFanin( pWin->pNode, pFaninTemp, k )
92  {
93  if ( k != i )
94  {
95  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
96  Vec_VecPush( vResubsW, Counter, pFaninTemp );
97  }
98  }
99  Counter++;
100  if ( Counter == Vec_VecSize(vResubs) )
101  return Counter;
102  }
103  }
104 
105  // try replacing each critical fanin by a non-critical fanin
106  Abc_ObjForEachFanin( pWin->pNode, pFanin, i )
107  {
108  if ( Abc_ObjFanoutNum(pFanin) > 1 )
109  continue;
110  // get simulation info without this fanin
111  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~(1 << i) );
112  // go over the set of divisors
113  for ( d = Abc_ObjFaninNum(pWin->pNode) + 2; d < Abc_NtkPoNum(pAig); d++ )
114  {
115  pInfoDiv = (unsigned *)Vec_PtrEntry( pSim->vOuts, d );
116  iDiv = d - (Abc_ObjFaninNum(pWin->pNode) + 2);
117  if ( !Abc_InfoIsOrOne( pInfo, pInfoDiv, pSim->nWordsOut ) )
118  continue;
119  // collect the nodes
120  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
121  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
122  // collect the remaning fanins and the divisor
123  Abc_ObjForEachFanin( pWin->pNode, pFaninTemp, k )
124  {
125  if ( k != i )
126  {
127  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
128  Vec_VecPush( vResubsW, Counter, pFaninTemp );
129  }
130  }
131  // collect the divisor
132  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d) );
133  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv) );
134  Counter++;
135  if ( Counter == Vec_VecSize(vResubs) )
136  return Counter;
137  }
138  }
139 
140  // consider the case when two fanins can be added instead of one
141  if ( Abc_ObjFaninNum(pWin->pNode) < nFaninsMax )
142  {
143  // try to replace each critical fanin by two non-critical fanins
144  Abc_ObjForEachFanin( pWin->pNode, pFanin, i )
145  {
146  if ( Abc_ObjFanoutNum(pFanin) > 1 )
147  continue;
148  // get simulation info without this fanin
149  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~(1 << i) );
150  // go over the set of divisors
151  for ( d = Abc_ObjFaninNum(pWin->pNode) + 2; d < Abc_NtkPoNum(pAig); d++ )
152  {
153  pInfoDiv = (unsigned *)Vec_PtrEntry( pSim->vOuts, d );
154  iDiv = d - (Abc_ObjFaninNum(pWin->pNode) + 2);
155  // go through the second divisor
156  for ( d2 = d + 1; d2 < Abc_NtkPoNum(pAig); d2++ )
157  {
158  pInfoDiv2 = (unsigned *)Vec_PtrEntry( pSim->vOuts, d2 );
159  iDiv2 = d2 - (Abc_ObjFaninNum(pWin->pNode) + 2);
160  if ( !Abc_InfoIsOrOne3( pInfo, pInfoDiv, pInfoDiv2, pSim->nWordsOut ) )
161  continue;
162  // collect the nodes
163  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
164  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
165  // collect the remaning fanins and the divisor
166  Abc_ObjForEachFanin( pWin->pNode, pFaninTemp, k )
167  {
168  if ( k != i )
169  {
170  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
171  Vec_VecPush( vResubsW, Counter, pFaninTemp );
172  }
173  }
174  // collect the divisor
175  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d) );
176  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d2) );
177  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv) );
178  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv2) );
179  Counter++;
180  if ( Counter == Vec_VecSize(vResubs) )
181  return Counter;
182  }
183  }
184  }
185  }
186 
187  // try to replace two nets by one
188  if ( !fArea )
189  {
190  Abc_ObjForEachFanin( pWin->pNode, pFanin, i )
191  {
192  for ( i2 = i + 1; i2 < Abc_ObjFaninNum(pWin->pNode); i2++ )
193  {
194  pFanin2 = Abc_ObjFanin(pWin->pNode, i2);
195  // get simulation info without these fanins
196  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, (~(1 << i)) & (~(1 << i2)) );
197  // go over the set of divisors
198  for ( d = Abc_ObjFaninNum(pWin->pNode) + 2; d < Abc_NtkPoNum(pAig); d++ )
199  {
200  pInfoDiv = (unsigned *)Vec_PtrEntry( pSim->vOuts, d );
201  iDiv = d - (Abc_ObjFaninNum(pWin->pNode) + 2);
202  if ( !Abc_InfoIsOrOne( pInfo, pInfoDiv, pSim->nWordsOut ) )
203  continue;
204  // collect the nodes
205  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
206  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
207  // collect the remaning fanins and the divisor
208  Abc_ObjForEachFanin( pWin->pNode, pFaninTemp, k )
209  {
210  if ( k != i && k != i2 )
211  {
212  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
213  Vec_VecPush( vResubsW, Counter, pFaninTemp );
214  }
215  }
216  // collect the divisor
217  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d) );
218  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv) );
219  Counter++;
220  if ( Counter == Vec_VecSize(vResubs) )
221  return Counter;
222  }
223  }
224  }
225  }
226  return Counter;
227 }
int nWordsOut
Definition: resInt.h:82
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static ABC_NAMESPACE_IMPL_START unsigned * Res_FilterCollectFaninInfo(Res_Win_t *pWin, Res_Sim_t *pSim, unsigned uMask)
DECLARATIONS ///.
Definition: resFilter.c:383
static void Vec_VecClear(Vec_Vec_t *p)
Definition: vecVec.h:437
static int Counter
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Abc_Obj_t * Abc_NtkPo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:316
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static int Vec_VecSize(Vec_Vec_t *p)
Definition: vecVec.h:222
Vec_Ptr_t * vOuts
Definition: resInt.h:88
static int Abc_InfoIsOne(unsigned *p, int nWords)
Definition: abc.h:240
static int Abc_InfoIsOrOne(unsigned *p, unsigned *q, int nWords)
Definition: abc.h:245
static Abc_Obj_t * Abc_ObjFanin(Abc_Obj_t *pObj, int i)
Definition: abc.h:372
static int Abc_InfoIsOrOne3(unsigned *p, unsigned *q, unsigned *r, int nWords)
Definition: abc.h:246
int Res_FilterCandidatesArea ( Res_Win_t pWin,
Abc_Ntk_t pAig,
Res_Sim_t pSim,
Vec_Vec_t vResubs,
Vec_Vec_t vResubsW,
int  nFaninsMax 
)

Function*************************************************************

Synopsis [Finds sets of feasible candidates.]

Description [This procedure is a special case of the above.]

SideEffects []

SeeAlso []

Definition at line 241 of file resFilter.c.

242 {
243  Abc_Obj_t * pFanin;
244  unsigned * pInfo, * pInfoDiv, * pInfoDiv2;
245  int Counter, RetValue, d, d2, k, iDiv, iDiv2, iBest;
246 
247  // check that the info the node is one
248  pInfo = (unsigned *)Vec_PtrEntry( pSim->vOuts, 1 );
249  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
250  if ( RetValue == 0 )
251  {
252 // printf( "Failed 1!\n" );
253  return 0;
254  }
255 
256  // collect the fanin info
257  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~0 );
258  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
259  if ( RetValue == 0 )
260  {
261 // printf( "Failed 2!\n" );
262  return 0;
263  }
264 
265  // try removing fanins
266 // printf( "Fanins: " );
267  Counter = 0;
268  Vec_VecClear( vResubs );
269  Vec_VecClear( vResubsW );
270  // get the best fanins
271  iBest = Res_FilterCriticalFanin( pWin->pNode );
272  if ( iBest == -1 )
273  return 0;
274 
275  // get the info without the critical fanin
276  pInfo = Res_FilterCollectFaninInfo( pWin, pSim, ~(1 << iBest) );
277  RetValue = Abc_InfoIsOne( pInfo, pSim->nWordsOut );
278  if ( RetValue )
279  {
280 // printf( "Can be done without one!\n" );
281  // collect the nodes
282  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
283  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
284  Abc_ObjForEachFanin( pWin->pNode, pFanin, k )
285  {
286  if ( k != iBest )
287  {
288  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
289  Vec_VecPush( vResubsW, Counter, pFanin );
290  }
291  }
292  Counter++;
293 // printf( "*" );
294  return Counter;
295  }
296 
297  // go through the divisors
298  for ( d = Abc_ObjFaninNum(pWin->pNode) + 2; d < Abc_NtkPoNum(pAig); d++ )
299  {
300  pInfoDiv = (unsigned *)Vec_PtrEntry( pSim->vOuts, d );
301  iDiv = d - (Abc_ObjFaninNum(pWin->pNode) + 2);
302  if ( !Abc_InfoIsOrOne( pInfo, pInfoDiv, pSim->nWordsOut ) )
303  continue;
304 //if ( Abc_ObjLevel(pWin->pNode) <= Abc_ObjLevel( Vec_PtrEntry(pWin->vDivs, iDiv) ) )
305 // printf( "Node level = %d. Divisor level = %d.\n", Abc_ObjLevel(pWin->pNode), Abc_ObjLevel( Vec_PtrEntry(pWin->vDivs, iDiv) ) );
306  // collect the nodes
307  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
308  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
309  // collect the remaning fanins and the divisor
310  Abc_ObjForEachFanin( pWin->pNode, pFanin, k )
311  {
312  if ( k != iBest )
313  {
314  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
315  Vec_VecPush( vResubsW, Counter, pFanin );
316  }
317  }
318  // collect the divisor
319  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d) );
320  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv) );
321  Counter++;
322 
323  if ( Counter == Vec_VecSize(vResubs) )
324  break;
325  }
326 
327  if ( Counter > 0 || Abc_ObjFaninNum(pWin->pNode) >= nFaninsMax )
328  return Counter;
329 
330  // try to find the node pairs
331  for ( d = Abc_ObjFaninNum(pWin->pNode) + 2; d < Abc_NtkPoNum(pAig); d++ )
332  {
333  pInfoDiv = (unsigned *)Vec_PtrEntry( pSim->vOuts, d );
334  iDiv = d - (Abc_ObjFaninNum(pWin->pNode) + 2);
335  // go through the second divisor
336  for ( d2 = d + 1; d2 < Abc_NtkPoNum(pAig); d2++ )
337  {
338  pInfoDiv2 = (unsigned *)Vec_PtrEntry( pSim->vOuts, d2 );
339  iDiv2 = d2 - (Abc_ObjFaninNum(pWin->pNode) + 2);
340 
341  if ( !Abc_InfoIsOrOne3( pInfo, pInfoDiv, pInfoDiv2, pSim->nWordsOut ) )
342  continue;
343  // collect the nodes
344  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,0) );
345  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,1) );
346  // collect the remaning fanins and the divisor
347  Abc_ObjForEachFanin( pWin->pNode, pFanin, k )
348  {
349  if ( k != iBest )
350  {
351  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,2+k) );
352  Vec_VecPush( vResubsW, Counter, pFanin );
353  }
354  }
355  // collect the divisor
356  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d) );
357  Vec_VecPush( vResubs, Counter, Abc_NtkPo(pAig,d2) );
358  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv) );
359  Vec_VecPush( vResubsW, Counter, Vec_PtrEntry(pWin->vDivs, iDiv2) );
360  Counter++;
361 
362  if ( Counter == Vec_VecSize(vResubs) )
363  break;
364  }
365  if ( Counter == Vec_VecSize(vResubs) )
366  break;
367  }
368  return Counter;
369 }
static int Res_FilterCriticalFanin(Abc_Obj_t *pNode)
Definition: resFilter.c:410
int nWordsOut
Definition: resInt.h:82
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static ABC_NAMESPACE_IMPL_START unsigned * Res_FilterCollectFaninInfo(Res_Win_t *pWin, Res_Sim_t *pSim, unsigned uMask)
DECLARATIONS ///.
Definition: resFilter.c:383
static void Vec_VecClear(Vec_Vec_t *p)
Definition: vecVec.h:437
static int Counter
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Abc_Obj_t * Abc_NtkPo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:316
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static int Vec_VecSize(Vec_Vec_t *p)
Definition: vecVec.h:222
Vec_Ptr_t * vOuts
Definition: resInt.h:88
static int Abc_InfoIsOne(unsigned *p, int nWords)
Definition: abc.h:240
static int Abc_InfoIsOrOne(unsigned *p, unsigned *q, int nWords)
Definition: abc.h:245
static int Abc_InfoIsOrOne3(unsigned *p, unsigned *q, unsigned *r, int nWords)
Definition: abc.h:246
void* Res_SatProveUnsat ( Abc_Ntk_t pAig,
Vec_Ptr_t vFanins 
)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Loads AIG into the SAT solver for checking resubstitution.]

Description []

SideEffects []

SeeAlso []

Definition at line 52 of file resSat.c.

53 {
54  void * pCnf = NULL;
55  sat_solver * pSat;
56  Vec_Ptr_t * vNodes;
57  Abc_Obj_t * pObj;
58  int i, nNodes, status;
59 
60  // make sure fanins contain POs of the AIG
61  pObj = (Abc_Obj_t *)Vec_PtrEntry( vFanins, 0 );
62  assert( pObj->pNtk == pAig && Abc_ObjIsPo(pObj) );
63 
64  // collect reachable nodes
65  vNodes = Abc_NtkDfsNodes( pAig, (Abc_Obj_t **)vFanins->pArray, vFanins->nSize );
66 
67  // assign unique numbers to each node
68  nNodes = 0;
69  Abc_AigConst1(pAig)->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)nNodes++;
70  Abc_NtkForEachPi( pAig, pObj, i )
71  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)nNodes++;
72  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
73  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)nNodes++;
74  Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pObj, i ) // useful POs
75  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)nNodes++;
76 
77  // start the solver
78  pSat = sat_solver_new();
79  sat_solver_store_alloc( pSat );
80 
81  // add clause for the constant node
82  Res_SatAddConst1( pSat, (int)(ABC_PTRUINT_T)Abc_AigConst1(pAig)->pCopy, 0 );
83  // add clauses for AND gates
84  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
85  Res_SatAddAnd( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy,
86  (int)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pCopy, (int)(ABC_PTRUINT_T)Abc_ObjFanin1(pObj)->pCopy, Abc_ObjFaninC0(pObj), Abc_ObjFaninC1(pObj) );
87  Vec_PtrFree( vNodes );
88  // add clauses for POs
89  Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pObj, i )
90  Res_SatAddEqual( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy,
91  (int)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pCopy, Abc_ObjFaninC0(pObj) );
92  // add trivial clauses
93  pObj = (Abc_Obj_t *)Vec_PtrEntry(vFanins, 0);
94  Res_SatAddConst1( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy, 0 ); // care-set
95  pObj = (Abc_Obj_t *)Vec_PtrEntry(vFanins, 1);
96  Res_SatAddConst1( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy, 0 ); // on-set
97 
98  // bookmark the clauses of A
100 
101  // duplicate the clauses
102  pObj = (Abc_Obj_t *)Vec_PtrEntry(vFanins, 1);
103  Sat_SolverDoubleClauses( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy );
104  // add the equality constraints
105  Vec_PtrForEachEntryStart( Abc_Obj_t *, vFanins, pObj, i, 2 )
106  Res_SatAddEqual( pSat, (int)(ABC_PTRUINT_T)pObj->pCopy, ((int)(ABC_PTRUINT_T)pObj->pCopy) + nNodes, 0 );
107 
108  // bookmark the roots
110 
111  // solve the problem
112  status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)10000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
113  if ( status == l_False )
114  {
115  pCnf = sat_solver_store_release( pSat );
116 // printf( "unsat\n" );
117  }
118  else if ( status == l_True )
119  {
120 // printf( "sat\n" );
121  }
122  else
123  {
124 // printf( "undef\n" );
125  }
126  sat_solver_delete( pSat );
127  return pCnf;
128 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
void * sat_solver_store_release(sat_solver *s)
Definition: satSolver.c:1949
int Res_SatAddEqual(sat_solver *pSat, int iVar0, int iVar1, int fCompl)
Definition: resSat.c:357
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
#define l_True
Definition: SolverTypes.h:84
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
int Res_SatAddAnd(sat_solver *pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1)
Definition: resSat.c:385
Abc_Obj_t * pCopy
Definition: abc.h:148
void sat_solver_store_alloc(sat_solver *s)
Definition: satSolver.c:1916
if(last==0)
Definition: sparse_int.h:34
void sat_solver_store_mark_clauses_a(sat_solver *s)
Definition: satSolver.c:1944
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void sat_solver_store_mark_roots(sat_solver *s)
Definition: satSolver.c:1939
Abc_Ntk_t * pNtk
Definition: abc.h:130
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
#define l_False
Definition: SolverTypes.h:85
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
ABC_NAMESPACE_IMPL_START int Res_SatAddConst1(sat_solver *pSat, int iVar, int fCompl)
DECLARATIONS ///.
Definition: resSat.c:338
#define assert(ex)
Definition: util_old.h:213
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition: abcDfs.c:120
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Sat_SolverDoubleClauses(sat_solver *p, int iVar)
Definition: satUtil.c:308
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Res_SatSimulate ( Res_Sim_t p,
int  nPatsLimit,
int  fOnSet 
)

Function*************************************************************

Synopsis [Loads AIG into the SAT solver for constrained simulation.]

Description [Returns 1 if the required number of patterns are found. Returns 0 if the solver ran out of time or proved a constant. In the latter, case one of the flags, fConst0 or fConst1, are set to 1.]

SideEffects []

SeeAlso []

Definition at line 212 of file resSat.c.

213 {
214  Vec_Int_t * vLits;
215  Vec_Ptr_t * vPats;
216  sat_solver * pSat;
217  int RetValue = -1; // Suppress "might be used uninitialized"
218  int i, k, value, status, Lit, Var, iPat;
219  abctime clk = Abc_Clock();
220 
221 //printf( "Looking for %s: ", fOnSet? "onset " : "offset" );
222 
223  // decide what problem should be solved
224  Lit = toLitCond( (int)(ABC_PTRUINT_T)Abc_NtkPo(p->pAig,1)->pCopy, !fOnSet );
225  if ( fOnSet )
226  {
227  iPat = p->nPats1;
228  vPats = p->vPats1;
229  }
230  else
231  {
232  iPat = p->nPats0;
233  vPats = p->vPats0;
234  }
235  assert( iPat < nPatsLimit );
236 
237  // derive the SAT solver
238  pSat = (sat_solver *)Res_SatSimulateConstr( p->pAig, fOnSet );
239  pSat->fSkipSimplify = 1;
240  status = sat_solver_simplify( pSat );
241  if ( status == 0 )
242  {
243  if ( iPat == 0 )
244  {
245 // if ( fOnSet )
246 // p->fConst0 = 1;
247 // else
248 // p->fConst1 = 1;
249  RetValue = 0;
250  }
251  goto finish;
252  }
253 
254  // enumerate through the SAT assignments
255  RetValue = 1;
256  vLits = Vec_IntAlloc( 32 );
257  for ( k = iPat; k < nPatsLimit; k++ )
258  {
259  // solve with the assumption
260 // status = sat_solver_solve( pSat, &Lit, &Lit + 1, (ABC_INT64_T)10000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
261  status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)10000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
262  if ( status == l_False )
263  {
264 //printf( "Const %d\n", !fOnSet );
265  if ( k == 0 )
266  {
267  if ( fOnSet )
268  p->fConst0 = 1;
269  else
270  p->fConst1 = 1;
271  RetValue = 0;
272  }
273  break;
274  }
275  else if ( status == l_True )
276  {
277  // save the pattern
278  Vec_IntClear( vLits );
279  for ( i = 0; i < p->nTruePis; i++ )
280  {
281  Var = (int)(ABC_PTRUINT_T)Abc_NtkPi(p->pAig,i)->pCopy;
282 // value = (int)(pSat->model.ptr[Var] == l_True);
283  value = sat_solver_var_value(pSat, Var);
284  if ( value )
285  Abc_InfoSetBit( (unsigned *)Vec_PtrEntry(vPats, i), k );
286  Lit = toLitCond( Var, value );
287  Vec_IntPush( vLits, Lit );
288 // printf( "%d", value );
289  }
290 // printf( "\n" );
291 
292  status = sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) );
293  if ( status == 0 )
294  {
295  k++;
296  RetValue = 1;
297  break;
298  }
299  }
300  else
301  {
302 //printf( "Undecided\n" );
303  if ( k == 0 )
304  RetValue = 0;
305  else
306  RetValue = 1;
307  break;
308  }
309  }
310  Vec_IntFree( vLits );
311 //printf( "Found %d patterns\n", k - iPat );
312 
313  // set the new number of patterns
314  if ( fOnSet )
315  p->nPats1 = k;
316  else
317  p->nPats0 = k;
318 
319 finish:
320 
321  sat_solver_delete( pSat );
322 p->timeSat += Abc_Clock() - clk;
323  return RetValue;
324 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
int fSkipSimplify
Definition: satSolver.h:175
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Ptr_t * vPats0
Definition: resInt.h:86
int nTruePis
Definition: resInt.h:73
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
#define l_True
Definition: SolverTypes.h:84
static abctime Abc_Clock()
Definition: abc_global.h:279
void * Res_SatSimulateConstr(Abc_Ntk_t *pAig, int fOnSet)
Definition: resSat.c:141
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
Abc_Obj_t * pCopy
Definition: abc.h:148
Abc_Ntk_t * pAig
Definition: resInt.h:72
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static lit toLitCond(int v, int c)
Definition: satVec.h:143
Vec_Ptr_t * vPats1
Definition: resInt.h:87
int nPats1
Definition: resInt.h:90
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
int fConst1
Definition: resInt.h:75
abctime timeSat
Definition: resInt.h:94
int fConst0
Definition: resInt.h:74
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static Abc_Obj_t * Abc_NtkPo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:316
#define l_False
Definition: SolverTypes.h:85
int Var
Definition: SolverTypes.h:42
int value
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_NtkPi(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:315
int nPats0
Definition: resInt.h:89
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
Res_Sim_t* Res_SimAlloc ( int  nWords)

DECLARATIONS ///.

CFile****************************************************************

FileName [resSim.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resynthesis package.]

Synopsis [Simulation engine.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 15, 2007.]

Revision [

Id:
resSim.c,v 1.00 2007/01/15 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Allocate simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file resSim.c.

47 {
48  Res_Sim_t * p;
49  p = ABC_ALLOC( Res_Sim_t, 1 );
50  memset( p, 0, sizeof(Res_Sim_t) );
51  // simulation parameters
52  p->nWords = nWords;
53  p->nPats = p->nWords * 8 * sizeof(unsigned);
54  p->nWordsIn = p->nPats;
55  p->nBytesIn = p->nPats * sizeof(unsigned);
56  p->nPatsIn = p->nPats * 8 * sizeof(unsigned);
57  p->nWordsOut = p->nPats * p->nWords;
58  p->nPatsOut = p->nPats * p->nPats;
59  // simulation info
60  p->vPats = Vec_PtrAllocSimInfo( 1024, p->nWordsIn );
61  p->vPats0 = Vec_PtrAllocSimInfo( 128, p->nWords );
62  p->vPats1 = Vec_PtrAllocSimInfo( 128, p->nWords );
63  p->vOuts = Vec_PtrAllocSimInfo( 128, p->nWordsOut );
64  // resub candidates
65  p->vCands = Vec_VecStart( 16 );
66  return p;
67 }
char * memset()
int nWordsOut
Definition: resInt.h:82
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * vPats0
Definition: resInt.h:86
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nWords
Definition: abcNpn.c:127
Vec_Vec_t * vCands
Definition: resInt.h:92
Vec_Ptr_t * vPats1
Definition: resInt.h:87
int nWords
Definition: resInt.h:77
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
Vec_Ptr_t * vPats
Definition: resInt.h:85
int nPatsIn
Definition: resInt.h:80
int nWordsIn
Definition: resInt.h:79
int nBytesIn
Definition: resInt.h:81
Vec_Ptr_t * vOuts
Definition: resInt.h:88
int nPats
Definition: resInt.h:78
int nPatsOut
Definition: resInt.h:83
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
void Res_SimFree ( Res_Sim_t p)

Function*************************************************************

Synopsis [Free simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 127 of file resSim.c.

128 {
129  Vec_PtrFree( p->vPats );
130  Vec_PtrFree( p->vPats0 );
131  Vec_PtrFree( p->vPats1 );
132  Vec_PtrFree( p->vOuts );
133  Vec_VecFree( p->vCands );
134  ABC_FREE( p );
135 }
Vec_Ptr_t * vPats0
Definition: resInt.h:86
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Vec_Vec_t * vCands
Definition: resInt.h:92
Vec_Ptr_t * vPats1
Definition: resInt.h:87
Vec_Ptr_t * vPats
Definition: resInt.h:85
#define ABC_FREE(obj)
Definition: abc_global.h:232
Vec_Ptr_t * vOuts
Definition: resInt.h:88
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Res_SimPrepare ( Res_Sim_t p,
Abc_Ntk_t pAig,
int  nTruePis,
int  fVerbose 
)

Function*************************************************************

Synopsis [Prepares simulation info for candidate filtering.]

Description []

SideEffects []

SeeAlso []

Definition at line 731 of file resSim.c.

732 {
733  int i, nOnes = 0, nZeros = 0, nDcs = 0;
734  if ( fVerbose )
735  printf( "\n" );
736  // prepare the manager
737  Res_SimAdjust( p, pAig, nTruePis );
738  // estimate the number of patterns
740  Res_SimPerformRound( p, p->nWordsIn );
741  Res_SimCountResults( p, &nDcs, &nOnes, &nZeros, fVerbose );
742  // collect the patterns
743  Res_SimCollectPatterns( p, fVerbose );
744  // add more patterns using constraint simulation
745  if ( p->nPats0 < 8 )
746  {
747  if ( !Res_SatSimulate( p, 16, 0 ) )
748  return p->fConst0 || p->fConst1;
749 // return 0;
750 // printf( "Value0 = %d\n", Res_SimVerifyValue( p, 0 ) );
751  }
752  if ( p->nPats1 < 8 )
753  {
754  if ( !Res_SatSimulate( p, 16, 1 ) )
755  return p->fConst0 || p->fConst1;
756 // return 0;
757 // printf( "Value1 = %d\n", Res_SimVerifyValue( p, 1 ) );
758  }
759  // generate additional patterns
760  for ( i = 0; i < 2; i++ )
761  {
762  if ( p->nPats0 > p->nPats*7/8 && p->nPats1 > p->nPats*7/8 )
763  break;
764  Res_SimSetDerivedBytes( p, i==0 );
765  Res_SimPerformRound( p, p->nWordsIn );
766  Res_SimCountResults( p, &nDcs, &nOnes, &nZeros, fVerbose );
767  Res_SimCollectPatterns( p, fVerbose );
768  }
769  // create bit-matrix info
770  if ( p->nPats0 < p->nPats )
771  Res_SimPadSimInfo( p->vPats0, p->nPats0, p->nWords );
772  if ( p->nPats1 < p->nPats )
773  Res_SimPadSimInfo( p->vPats1, p->nPats1, p->nWords );
774  // resimulate 0-patterns
775  Res_SimSetGiven( p, p->vPats0 );
776  Res_SimPerformRound( p, p->nWords );
777 //Res_SimPrintNodePatterns( p, pAig );
779  // resimulate 1-patterns
780  Res_SimSetGiven( p, p->vPats1 );
781  Res_SimPerformRound( p, p->nWords );
782 //Res_SimPrintNodePatterns( p, pAig );
784  // print output patterns
785 // Res_SimPrintOutPatterns( p, pAig );
786  return 1;
787 }
void Res_SimSetGiven(Res_Sim_t *p, Vec_Ptr_t *vInfo)
Definition: resSim.c:344
void Res_SimAdjust(Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis)
Definition: resSim.c:80
Vec_Ptr_t * vPats0
Definition: resInt.h:86
void Res_SimCountResults(Res_Sim_t *p, int *pnDcs, int *pnOnes, int *pnZeros, int fVerbose)
Definition: resSim.c:587
void Res_SimSetRandomBytes(Res_Sim_t *p)
Definition: resSim.c:174
void Res_SimCollectPatterns(Res_Sim_t *p, int fVerbose)
Definition: resSim.c:624
int Res_SatSimulate(Res_Sim_t *p, int nPats, int fOnSet)
Definition: resSat.c:212
Vec_Ptr_t * vPats1
Definition: resInt.h:87
int nPats1
Definition: resInt.h:90
int nWords
Definition: resInt.h:77
int fConst1
Definition: resInt.h:75
int fConst0
Definition: resInt.h:74
int nWordsIn
Definition: resInt.h:79
void Res_SimSetDerivedBytes(Res_Sim_t *p, int fUseWalk)
Definition: resSim.c:211
void Res_SimDeriveInfoReplicate(Res_Sim_t *p)
Definition: resSim.c:491
void Res_SimDeriveInfoComplement(Res_Sim_t *p)
Definition: resSim.c:517
void Res_SimPerformRound(Res_Sim_t *p, int nWords)
Definition: resSim.c:435
int nPats0
Definition: resInt.h:89
int nPats
Definition: resInt.h:78
void Res_SimPadSimInfo(Vec_Ptr_t *vPats, int nPats, int nWords)
Definition: resSim.c:458
void Res_UpdateNetwork ( Abc_Obj_t pObj,
Vec_Ptr_t vFanins,
Hop_Obj_t pFunc,
Vec_Vec_t vLevels 
)

Function*************************************************************

Synopsis [Incrementally updates level of the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 185 of file resCore.c.

186 {
187  Abc_Obj_t * pObjNew, * pFanin;
188  int k;
189 
190  // create the new node
191  pObjNew = Abc_NtkCreateNode( pObj->pNtk );
192  pObjNew->pData = pFunc;
193  Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, k )
194  Abc_ObjAddFanin( pObjNew, pFanin );
195  // replace the old node by the new node
196 //printf( "Replacing node " ); Abc_ObjPrint( stdout, pObj );
197 //printf( "Inserting node " ); Abc_ObjPrint( stdout, pObjNew );
198  // update the level of the node
199  Abc_NtkUpdate( pObj, pObjNew, vLevels );
200 }
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
Abc_Ntk_t * pNtk
Definition: abc.h:130
ABC_DLL void Abc_NtkUpdate(Abc_Obj_t *pObj, Abc_Obj_t *pObjNew, Vec_Vec_t *vLevels)
Definition: abcTiming.c:1311
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Res_Win_t* Res_WinAlloc ( )

DECLARATIONS ///.

CFile****************************************************************

FileName [resWin.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resynthesis package.]

Synopsis [Windowing algorithm.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 15, 2007.]

Revision [

Id:
resWin.c,v 1.00 2007/01/15 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Allocates the window.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file resWin.c.

47 {
48  Res_Win_t * p;
49  // start the manager
50  p = ABC_ALLOC( Res_Win_t, 1 );
51  memset( p, 0, sizeof(Res_Win_t) );
52  // set internal parameters
53  p->nFanoutLimit = 10;
54  p->nLevTfiMinus = 3;
55  // allocate storage
56  p->vRoots = Vec_PtrAlloc( 256 );
57  p->vLeaves = Vec_PtrAlloc( 256 );
58  p->vBranches = Vec_PtrAlloc( 256 );
59  p->vNodes = Vec_PtrAlloc( 256 );
60  p->vDivs = Vec_PtrAlloc( 256 );
61  p->vMatrix = Vec_VecStart( 128 );
62  return p;
63 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
typedefABC_NAMESPACE_HEADER_START struct Res_Win_t_ Res_Win_t
INCLUDES ///.
Definition: resInt.h:44
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Res_WinCompute ( Abc_Obj_t pNode,
int  nWinTfiMax,
int  nWinTfoMax,
Res_Win_t p 
)

Function*************************************************************

Synopsis [Computes the window.]

Description []

SideEffects []

SeeAlso []

Definition at line 451 of file resWin.c.

452 {
453  assert( Abc_ObjIsNode(pNode) );
454  assert( nWinTfiMax > 0 && nWinTfiMax < 10 );
455  assert( nWinTfoMax >= 0 && nWinTfoMax < 10 );
456 
457  // initialize the window
458  p->pNode = pNode;
459  p->nWinTfiMax = nWinTfiMax;
460  p->nWinTfoMax = nWinTfoMax;
461 
462  Vec_PtrClear( p->vBranches );
463  Vec_PtrClear( p->vDivs );
464  Vec_PtrClear( p->vRoots );
465  Vec_PtrPush( p->vRoots, pNode );
466 
467  // compute the leaves
469  return 0;
470 
471  // compute the candidate roots
472  if ( p->nWinTfoMax > 0 && Res_WinComputeRoots(p) )
473  {
474  // mark the paths from the roots to the leaves
475  Res_WinMarkPaths( p );
476  // refine the roots and add branches and missing nodes
477  if ( Res_WinFinalizeRoots( p ) )
478  Res_WinAddMissing( p );
479  }
480 
481  return 1;
482 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * vRoots
Definition: llb3Image.c:51
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
int Res_WinComputeRoots(Res_Win_t *p)
Definition: resWin.c:223
int Res_WinCollectLeavesAndNodes(Res_Win_t *p)
Definition: resWin.c:100
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Res_WinMarkPaths(Res_Win_t *p)
Definition: resWin.c:283
void Res_WinAddMissing(Res_Win_t *p)
Definition: resWin.c:404
int Res_WinFinalizeRoots(Res_Win_t *p)
Definition: resWin.c:343
void Res_WinDivisors ( Res_Win_t p,
int  nLevDivMax 
)

MACRO DEFINITIONS ///.

FUNCTION DECLARATIONS ///

MACRO DEFINITIONS ///.

Function*************************************************************

Synopsis [Adds candidate divisors of the node to its window.]

Description []

SideEffects []

SeeAlso []

Definition at line 48 of file resDivs.c.

49 {
50  Abc_Obj_t * pObj, * pFanout, * pFanin;
51  int k, f, m;
52 
53  // set the maximum level of the divisors
54  p->nLevDivMax = nLevDivMax;
55 
56  // mark the TFI with the current trav ID
57  Abc_NtkIncrementTravId( p->pNode->pNtk );
58  Res_WinMarkTfi( p );
59 
60  // mark with the current trav ID those nodes that should not be divisors:
61  // (1) the node and its TFO
62  // (2) the MFFC of the node
63  // (3) the node's fanins (these are treated as a special case)
64  Abc_NtkIncrementTravId( p->pNode->pNtk );
65  Res_WinSweepLeafTfo_rec( p->pNode, p->nLevDivMax );
66  Res_WinVisitMffc( p->pNode );
67  Abc_ObjForEachFanin( p->pNode, pObj, k )
69 
70  // at this point the nodes are marked with two trav IDs:
71  // nodes to be collected as divisors are marked with previous trav ID
72  // nodes to be avoided as divisors are marked with current trav ID
73 
74  // start collecting the divisors
75  Vec_PtrClear( p->vDivs );
76  Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pObj, k )
77  {
78  assert( (int)pObj->Level >= p->nLevLeafMin );
79  if ( !Abc_NodeIsTravIdPrevious(pObj) )
80  continue;
81  if ( (int)pObj->Level > p->nLevDivMax )
82  continue;
83  Vec_PtrPush( p->vDivs, pObj );
84  }
85  // add the internal nodes to the data structure
86  Vec_PtrForEachEntry( Abc_Obj_t *, p->vNodes, pObj, k )
87  {
88  if ( !Abc_NodeIsTravIdPrevious(pObj) )
89  continue;
90  if ( (int)pObj->Level > p->nLevDivMax )
91  continue;
92  Vec_PtrPush( p->vDivs, pObj );
93  }
94 
95  // explore the fanouts of already collected divisors
96  p->nDivsPlus = 0;
97  Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pObj, k )
98  {
99  // consider fanouts of this node
100  Abc_ObjForEachFanout( pObj, pFanout, f )
101  {
102  // stop if there are too many fanouts
103  if ( f > 20 )
104  break;
105  // skip nodes that are already added
106  if ( Abc_NodeIsTravIdPrevious(pFanout) )
107  continue;
108  // skip nodes in the TFO or in the MFFC of node
109  if ( Abc_NodeIsTravIdCurrent(pFanout) )
110  continue;
111  // skip COs
112  if ( !Abc_ObjIsNode(pFanout) )
113  continue;
114  // skip nodes with large level
115  if ( (int)pFanout->Level > p->nLevDivMax )
116  continue;
117  // skip nodes whose fanins are not divisors
118  Abc_ObjForEachFanin( pFanout, pFanin, m )
119  if ( !Abc_NodeIsTravIdPrevious(pFanin) )
120  break;
121  if ( m < Abc_ObjFaninNum(pFanout) )
122  continue;
123  // add the node to the divisors
124  Vec_PtrPush( p->vDivs, pFanout );
125  Vec_PtrPush( p->vNodes, pFanout );
126  Abc_NodeSetTravIdPrevious( pFanout );
127  p->nDivsPlus++;
128  }
129  }
130 /*
131  printf( "Node level = %d. ", Abc_ObjLevel(p->pNode) );
132  Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs, pObj, k, Vec_PtrSize(p->vDivs)-p->nDivsPlus )
133  printf( "%d ", Abc_ObjLevel(pObj) );
134  printf( "\n" );
135 */
136 //printf( "%d ", p->nDivsPlus );
137 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Abc_NodeSetTravIdPrevious(Abc_Obj_t *p)
Definition: abc.h:410
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_NodeIsTravIdPrevious(Abc_Obj_t *p)
Definition: abc.h:412
unsigned Level
Definition: abc.h:142
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
if(last==0)
Definition: sparse_int.h:34
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
static ABC_NAMESPACE_IMPL_START void Res_WinMarkTfi(Res_Win_t *p)
DECLARATIONS ///.
Definition: resDivs.c:174
void Res_WinSweepLeafTfo_rec(Abc_Obj_t *pObj, int nLevelLimit)
Definition: resDivs.c:196
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int Res_WinVisitMffc(Abc_Obj_t *pNode)
Definition: resDivs.c:272
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:409
void Res_WinFree ( Res_Win_t p)

Function*************************************************************

Synopsis [Frees the window.]

Description []

SideEffects []

SeeAlso []

Definition at line 76 of file resWin.c.

77 {
78  Vec_PtrFree( p->vRoots );
79  Vec_PtrFree( p->vLeaves );
80  Vec_PtrFree( p->vBranches );
81  Vec_PtrFree( p->vNodes );
82  Vec_PtrFree( p->vDivs );
83  Vec_VecFree( p->vMatrix );
84  ABC_FREE( p );
85 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * vRoots
Definition: llb3Image.c:51
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Vec_Ptr_t * vLeaves
Definition: llb3Image.c:50
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Res_WinIsTrivial ( Res_Win_t p)

Function*************************************************************

Synopsis [Returns 1 if the window is trivial (without TFO).]

Description []

SideEffects []

SeeAlso []

Definition at line 435 of file resWin.c.

436 {
437  return Vec_PtrSize(p->vRoots) == 1 && Vec_PtrEntry(p->vRoots, 0) == p->pNode;
438 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * vRoots
Definition: llb3Image.c:51
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Res_WinSweepLeafTfo_rec ( Abc_Obj_t pObj,
int  nLevelLimit 
)

Function*************************************************************

Synopsis [Marks the TFO of the collected nodes up to the given level.]

Description []

SideEffects []

SeeAlso []

Definition at line 196 of file resDivs.c.

197 {
198  Abc_Obj_t * pFanout;
199  int i;
200  if ( Abc_ObjIsCo(pObj) || (int)pObj->Level > nLevelLimit )
201  return;
202  if ( Abc_NodeIsTravIdCurrent(pObj) )
203  return;
204  Abc_NodeSetTravIdCurrent( pObj );
205  Abc_ObjForEachFanout( pObj, pFanout, i )
206  Res_WinSweepLeafTfo_rec( pFanout, nLevelLimit );
207 }
unsigned Level
Definition: abc.h:142
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
void Res_WinSweepLeafTfo_rec(Abc_Obj_t *pObj, int nLevelLimit)
Definition: resDivs.c:196
static void Abc_NodeSetTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:409
int Res_WinVisitMffc ( Abc_Obj_t pNode)

Function*************************************************************

Synopsis [Labels MFFC of the node with the current trav ID.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file resDivs.c.

273 {
274  int Count1, Count2;
275  assert( Abc_ObjIsNode(pNode) );
276  // dereference the node (mark with the current trav ID)
277  Count1 = Res_NodeDeref_rec( pNode );
278  // reference it back
279  Count2 = Res_NodeRef_rec( pNode );
280  assert( Count1 == Count2 );
281  return Count1;
282 }
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
int Res_NodeDeref_rec(Abc_Obj_t *pNode)
Definition: resDivs.c:220
int Res_NodeRef_rec(Abc_Obj_t *pNode)
Definition: resDivs.c:247
#define assert(ex)
Definition: util_old.h:213
Abc_Ntk_t* Res_WndStrash ( Res_Win_t p)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Structurally hashes the given window.]

Description [The first PO is the observability condition. The second is the node's function. The remaining POs are the candidate divisors.]

SideEffects []

SeeAlso []

Definition at line 49 of file resStrash.c.

50 {
51  Vec_Ptr_t * vPairs;
52  Abc_Ntk_t * pAig;
53  Abc_Obj_t * pObj, * pMiter;
54  int i;
55  assert( Abc_NtkHasAig(p->pNode->pNtk) );
56 // Abc_NtkCleanCopy( p->pNode->pNtk );
57  // create the network
59  pAig->pName = Extra_UtilStrsav( "window" );
60  // create the inputs
61  Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pObj, i )
62  pObj->pCopy = Abc_NtkCreatePi( pAig );
63  Vec_PtrForEachEntry( Abc_Obj_t *, p->vBranches, pObj, i )
64  pObj->pCopy = Abc_NtkCreatePi( pAig );
65  // go through the nodes in the topological order
66  Vec_PtrForEachEntry( Abc_Obj_t *, p->vNodes, pObj, i )
67  {
68  pObj->pCopy = Abc_ConvertAigToAig( pAig, pObj );
69  if ( pObj == p->pNode )
70  pObj->pCopy = Abc_ObjNot( pObj->pCopy );
71  }
72  // collect the POs
73  vPairs = Vec_PtrAlloc( 2 * Vec_PtrSize(p->vRoots) );
74  Vec_PtrForEachEntry( Abc_Obj_t *, p->vRoots, pObj, i )
75  {
76  Vec_PtrPush( vPairs, pObj->pCopy );
77  Vec_PtrPush( vPairs, NULL );
78  }
79  // mark the TFO of the node
80  Abc_NtkIncrementTravId( p->pNode->pNtk );
81  Res_WinSweepLeafTfo_rec( p->pNode, (int)p->pNode->Level + p->nWinTfoMax );
82  // update strashing of the node
83  p->pNode->pCopy = Abc_ObjNot( p->pNode->pCopy );
84  Abc_NodeSetTravIdPrevious( p->pNode );
85  // redo strashing in the TFO
86  Vec_PtrForEachEntry( Abc_Obj_t *, p->vNodes, pObj, i )
87  {
88  if ( Abc_NodeIsTravIdCurrent(pObj) )
89  pObj->pCopy = Abc_ConvertAigToAig( pAig, pObj );
90  }
91  // collect the POs
92  Vec_PtrForEachEntry( Abc_Obj_t *, p->vRoots, pObj, i )
93  Vec_PtrWriteEntry( vPairs, 2 * i + 1, pObj->pCopy );
94  // add the miter
95  pMiter = Abc_AigMiter( (Abc_Aig_t *)pAig->pManFunc, vPairs, 0 );
96  Abc_ObjAddFanin( Abc_NtkCreatePo(pAig), pMiter );
97  Vec_PtrFree( vPairs );
98  // add the node
99  Abc_ObjAddFanin( Abc_NtkCreatePo(pAig), p->pNode->pCopy );
100  // add the fanins
101  Abc_ObjForEachFanin( p->pNode, pObj, i )
102  Abc_ObjAddFanin( Abc_NtkCreatePo(pAig), pObj->pCopy );
103  // add the divisors
104  Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pObj, i )
105  Abc_ObjAddFanin( Abc_NtkCreatePo(pAig), pObj->pCopy );
106  // add the names
107  Abc_NtkAddDummyPiNames( pAig );
108  Abc_NtkAddDummyPoNames( pAig );
109  // check the resulting network
110  if ( !Abc_NtkCheck( pAig ) )
111  fprintf( stdout, "Res_WndStrash(): Network check has failed.\n" );
112  return pAig;
113 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Abc_NodeSetTravIdPrevious(Abc_Obj_t *p)
Definition: abc.h:410
Vec_Ptr_t * vRoots
Definition: llb3Image.c:51
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
DECLARATIONS ///.
Definition: abcAig.c:52
char * Extra_UtilStrsav(const char *s)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
static void check(int expr)
Definition: satSolver.c:46
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:398
ABC_DLL Abc_Obj_t * Abc_AigMiter(Abc_Aig_t *pMan, Vec_Ptr_t *vPairs, int fImplic)
Definition: abcAig.c:789
if(last==0)
Definition: sparse_int.h:34
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
Vec_Ptr_t * vLeaves
Definition: llb3Image.c:50
Abc_Ntk_t * Res_WndStrash(Res_Win_t *p)
FUNCTION DEFINITIONS ///.
Definition: resStrash.c:49
static int Abc_NodeIsTravIdCurrent(Abc_Obj_t *p)
Definition: abc.h:411
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
void Res_WinSweepLeafTfo_rec(Abc_Obj_t *pObj, int nLevelLimit)
Definition: resDivs.c:196
#define assert(ex)
Definition: util_old.h:213
static int Abc_NtkHasAig(Abc_Ntk_t *pNtk)
Definition: abc.h:255
static Abc_Obj_t * Abc_ObjNot(Abc_Obj_t *p)
Definition: abc.h:324
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:378
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
char * pName
Definition: abc.h:158
ABC_NAMESPACE_IMPL_START Abc_Obj_t * Abc_ConvertAigToAig(Abc_Ntk_t *pAig, Abc_Obj_t *pObjOld)
DECLARATIONS ///.
Definition: abcFunc.c:1036
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223