abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
saigStrSim.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [saigStrSim.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Sequential AIG package.]
8 
9  Synopsis [Structural matching using simulation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: saigStrSim.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "saig.h"
22 #include "proof/ssw/ssw.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 #define SAIG_WORDS 16
32 
33 static inline Aig_Obj_t * Saig_ObjNext( Aig_Obj_t ** ppNexts, Aig_Obj_t * pObj ) { return ppNexts[pObj->Id]; }
34 static inline void Saig_ObjSetNext( Aig_Obj_t ** ppNexts, Aig_Obj_t * pObj, Aig_Obj_t * pNext ) { ppNexts[pObj->Id] = pNext; }
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Computes hash value of the node using its simulation info.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
51 unsigned Saig_StrSimHash( Aig_Obj_t * pObj )
52 {
53  static int s_SPrimes[128] = {
54  1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
55  1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997,
56  2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543,
57  2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089,
58  3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671,
59  3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243,
60  4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871,
61  4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471,
62  5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073,
63  6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689,
64  6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309,
65  7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933,
66  8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
67  };
68  unsigned * pSims;
69  unsigned uHash = 0;
70  int i;
71  assert( SAIG_WORDS <= 128 );
72  pSims = (unsigned *)pObj->pData;
73  for ( i = 0; i < SAIG_WORDS; i++ )
74  uHash ^= pSims[i] * s_SPrimes[i & 0x7F];
75  return uHash;
76 }
77 
78 /**Function*************************************************************
79 
80  Synopsis [Computes hash value of the node using its simulation info.]
81 
82  Description []
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
89 int Saig_StrSimIsEqual( Aig_Obj_t * pObj0, Aig_Obj_t * pObj1 )
90 {
91  unsigned * pSims0 = (unsigned *)pObj0->pData;
92  unsigned * pSims1 = (unsigned *)pObj1->pData;
93  int i;
94  for ( i = 0; i < SAIG_WORDS; i++ )
95  if ( pSims0[i] != pSims1[i] )
96  return 0;
97  return 1;
98 }
99 
100 /**Function*************************************************************
101 
102  Synopsis [Returns 1 if simulation info is zero.]
103 
104  Description []
105 
106  SideEffects []
107 
108  SeeAlso []
109 
110 ***********************************************************************/
112 {
113  unsigned * pSims = (unsigned *)pObj->pData;
114  int i;
115  for ( i = 0; i < SAIG_WORDS; i++ )
116  if ( pSims[i] != 0 )
117  return 0;
118  return 1;
119 }
120 
121 /**Function*************************************************************
122 
123  Synopsis [Returns 1 if simulation info is one.]
124 
125  Description []
126 
127  SideEffects []
128 
129  SeeAlso []
130 
131 ***********************************************************************/
133 {
134  unsigned * pSims = (unsigned *)pObj->pData;
135  int i;
136  for ( i = 0; i < SAIG_WORDS; i++ )
137  if ( pSims[i] != ~0 )
138  return 0;
139  return 1;
140 }
141 
142 /**Function*************************************************************
143 
144  Synopsis [Assigns random simulation info.]
145 
146  Description []
147 
148  SideEffects []
149 
150  SeeAlso []
151 
152 ***********************************************************************/
154 {
155  unsigned * pSims = (unsigned *)pObj->pData;
156  int i;
157  for ( i = 0; i < SAIG_WORDS; i++ )
158  pSims[i] = Aig_ManRandom(0);
159 }
160 
161 /**Function*************************************************************
162 
163  Synopsis [Assigns constant 0 simulation info.]
164 
165  Description []
166 
167  SideEffects []
168 
169  SeeAlso []
170 
171 ***********************************************************************/
173 {
174  unsigned * pSims = (unsigned *)pObj->pData;
175  int i;
176  for ( i = 0; i < SAIG_WORDS; i++ )
177  pSims[i] = ~0;
178 }
179 
180 /**Function*************************************************************
181 
182  Synopsis [Assigns constant 0 simulation info.]
183 
184  Description []
185 
186  SideEffects []
187 
188  SeeAlso []
189 
190 ***********************************************************************/
192 {
193  unsigned * pSims = (unsigned *)pObj->pData;
194  pSims[0] = 0;
195 }
196 
197 /**Function*************************************************************
198 
199  Synopsis [Simulated one node.]
200 
201  Description []
202 
203  SideEffects []
204 
205  SeeAlso []
206 
207 ***********************************************************************/
208 void Saig_StrSimulateNode( Aig_Obj_t * pObj, int i )
209 {
210  unsigned * pSims = (unsigned *)pObj->pData;
211  unsigned * pSims0 = (unsigned *)Aig_ObjFanin0(pObj)->pData;
212  unsigned * pSims1 = (unsigned *)Aig_ObjFanin1(pObj)->pData;
213  if ( Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) )
214  pSims[i] = ~(pSims0[i] | pSims1[i]);
215  else if ( Aig_ObjFaninC0(pObj) && !Aig_ObjFaninC1(pObj) )
216  pSims[i] = (~pSims0[i] & pSims1[i]);
217  else if ( !Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) )
218  pSims[i] = (pSims0[i] & ~pSims1[i]);
219  else // if ( !Aig_ObjFaninC0(pObj) && !Aig_ObjFaninC1(pObj) )
220  pSims[i] = (pSims0[i] & pSims1[i]);
221 }
222 
223 /**Function*************************************************************
224 
225  Synopsis [Saves output of one node.]
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
234 void Saig_StrSimSaveOutput( Aig_Obj_t * pObj, int i )
235 {
236  unsigned * pSims = (unsigned *)pObj->pData;
237  unsigned * pSims0 = (unsigned *)Aig_ObjFanin0(pObj)->pData;
238  if ( Aig_ObjFaninC0(pObj) )
239  pSims[i] = ~pSims0[i];
240  else
241  pSims[i] = pSims0[i];
242 }
243 
244 /**Function*************************************************************
245 
246  Synopsis [Transfers simulation output to another node.]
247 
248  Description []
249 
250  SideEffects []
251 
252  SeeAlso []
253 
254 ***********************************************************************/
255 void Saig_StrSimTransfer( Aig_Obj_t * pObj0, Aig_Obj_t * pObj1 )
256 {
257  unsigned * pSims0 = (unsigned *)pObj0->pData;
258  unsigned * pSims1 = (unsigned *)pObj1->pData;
259  int i;
260  for ( i = 0; i < SAIG_WORDS; i++ )
261  pSims1[i] = pSims0[i];
262 }
263 
264 /**Function*************************************************************
265 
266  Synopsis [Transfers simulation output to another node.]
267 
268  Description []
269 
270  SideEffects []
271 
272  SeeAlso []
273 
274 ***********************************************************************/
275 void Saig_StrSimTransferNext( Aig_Obj_t * pObj0, Aig_Obj_t * pObj1, int i )
276 {
277  unsigned * pSims0 = (unsigned *)pObj0->pData;
278  unsigned * pSims1 = (unsigned *)pObj1->pData;
279  assert( i < SAIG_WORDS - 1 );
280  pSims1[i+1] = pSims0[i];
281 }
282 
283 /**Function*************************************************************
284 
285  Synopsis [Perform one round of simulation.]
286 
287  Description []
288 
289  SideEffects []
290 
291  SeeAlso []
292 
293 ***********************************************************************/
295 {
296  Aig_Obj_t * pObj0, * pObj1;
297  int f, i;
298  // simulate the nodes
299  Aig_ManForEachObj( p0, pObj0, i )
300  {
301  if ( !Aig_ObjIsCi(pObj0) && !Aig_ObjIsNode(pObj0) )
302  continue;
303  pObj1 = Aig_ObjRepr(p0, pObj0);
304  if ( pObj1 == NULL )
305  continue;
306  assert( Aig_ObjRepr(p1, pObj1) == pObj0 );
307  Saig_StrSimAssignRandom( pObj0 );
308  Saig_StrSimTransfer( pObj0, pObj1 );
309  }
310  // simulate the timeframes
311  for ( f = 0; f < SAIG_WORDS; f++ )
312  {
313  // simulate the first AIG
314  Aig_ManForEachNode( p0, pObj0, i )
315  if ( Aig_ObjRepr(p0, pObj0) == NULL )
316  Saig_StrSimulateNode( pObj0, f );
317  Saig_ManForEachLi( p0, pObj0, i )
318  Saig_StrSimSaveOutput( pObj0, f );
319  if ( f < SAIG_WORDS - 1 )
320  Saig_ManForEachLiLo( p0, pObj0, pObj1, i )
321  Saig_StrSimTransferNext( pObj0, pObj1, f );
322  // simulate the second AIG
323  Aig_ManForEachNode( p1, pObj1, i )
324  if ( Aig_ObjRepr(p1, pObj1) == NULL )
325  Saig_StrSimulateNode( pObj1, f );
326  Saig_ManForEachLi( p1, pObj1, i )
327  Saig_StrSimSaveOutput( pObj1, f );
328  if ( f < SAIG_WORDS - 1 )
329  Saig_ManForEachLiLo( p1, pObj1, pObj0, i )
330  Saig_StrSimTransferNext( pObj1, pObj0, f );
331  }
332 }
333 
334 /**Function*************************************************************
335 
336  Synopsis [Checks if the entry exists in the table.]
337 
338  Description []
339 
340  SideEffects []
341 
342  SeeAlso []
343 
344 ***********************************************************************/
345 Aig_Obj_t * Saig_StrSimTableLookup( Aig_Obj_t ** ppTable, Aig_Obj_t ** ppNexts, int nTableSize, Aig_Obj_t * pObj )
346 {
347  Aig_Obj_t * pEntry;
348  int iEntry;
349  // find the hash entry
350  iEntry = Saig_StrSimHash( pObj ) % nTableSize;
351  // check if there are nodes with this signatures
352  for ( pEntry = ppTable[iEntry]; pEntry; pEntry = Saig_ObjNext(ppNexts,pEntry) )
353  if ( Saig_StrSimIsEqual( pEntry, pObj ) )
354  return pEntry;
355  return NULL;
356 }
357 
358 /**Function*************************************************************
359 
360  Synopsis [Inserts the entry into the table.]
361 
362  Description []
363 
364  SideEffects []
365 
366  SeeAlso []
367 
368 ***********************************************************************/
369 void Saig_StrSimTableInsert( Aig_Obj_t ** ppTable, Aig_Obj_t ** ppNexts, int nTableSize, Aig_Obj_t * pObj )
370 {
371  // find the hash entry
372  int iEntry = Saig_StrSimHash( pObj ) % nTableSize;
373  // check if there are nodes with this signatures
374  if ( ppTable[iEntry] == NULL )
375  ppTable[iEntry] = pObj;
376  else
377  {
378  Saig_ObjSetNext( ppNexts, pObj, Saig_ObjNext(ppNexts, ppTable[iEntry]) );
379  Saig_ObjSetNext( ppNexts, ppTable[iEntry], pObj );
380  }
381 }
382 
383 /**Function*************************************************************
384 
385  Synopsis [Perform one round of matching.]
386 
387  Description []
388 
389  SideEffects []
390 
391  SeeAlso []
392 
393 ***********************************************************************/
395 {
396  Aig_Obj_t ** ppTable, ** ppNexts, ** ppCands;
397  Aig_Obj_t * pObj, * pEntry;
398  int i, nTableSize, Counter;
399 
400  // allocate the hash table hashing simulation info into nodes
401  nTableSize = Abc_PrimeCudd( Aig_ManObjNum(p0)/2 );
402  ppTable = ABC_CALLOC( Aig_Obj_t *, nTableSize );
403  ppNexts = ABC_CALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p0) );
404  ppCands = ABC_CALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p0) );
405 
406  // hash nodes of the first AIG
407  Aig_ManForEachObj( p0, pObj, i )
408  {
409  if ( !Aig_ObjIsCi(pObj) && !Aig_ObjIsNode(pObj) )
410  continue;
411  if ( Aig_ObjRepr(p0, pObj) )
412  continue;
413  if ( Saig_StrSimIsZero(pObj) || Saig_StrSimIsOne(pObj) )
414  continue;
415  // check if the entry exists
416  pEntry = Saig_StrSimTableLookup( ppTable, ppNexts, nTableSize, pObj );
417  if ( pEntry == NULL ) // insert
418  Saig_StrSimTableInsert( ppTable, ppNexts, nTableSize, pObj );
419  else // mark the entry as not unique
420  pEntry->fMarkA = 1;
421  }
422 
423  // hash nodes from the second AIG
424  Aig_ManForEachObj( p1, pObj, i )
425  {
426  if ( !Aig_ObjIsCi(pObj) && !Aig_ObjIsNode(pObj) )
427  continue;
428  if ( Aig_ObjRepr(p1, pObj) )
429  continue;
430  if ( Saig_StrSimIsZero(pObj) || Saig_StrSimIsOne(pObj) )
431  continue;
432  // check if the entry exists
433  pEntry = Saig_StrSimTableLookup( ppTable, ppNexts, nTableSize, pObj );
434  if ( pEntry == NULL ) // skip
435  continue;
436  // if there is no candidate, label it
437  if ( Saig_ObjNext( ppCands, pEntry ) == NULL )
438  Saig_ObjSetNext( ppCands, pEntry, pObj );
439  else // mark the entry as not unique
440  pEntry->fMarkA = 1;
441  }
442 
443  // create representatives for the unique entries
444  Counter = 0;
445  for ( i = 0; i < nTableSize; i++ )
446  for ( pEntry = ppTable[i]; pEntry; pEntry = Saig_ObjNext(ppNexts,pEntry) )
447  if ( !pEntry->fMarkA && (pObj = Saig_ObjNext( ppCands, pEntry )) )
448  {
449 // assert( Aig_ObjIsNode(pEntry) == Aig_ObjIsNode(pObj) );
450  if ( Aig_ObjType(pEntry) != Aig_ObjType(pObj) )
451  continue;
452  Aig_ObjSetRepr( p0, pEntry, pObj );
453  Aig_ObjSetRepr( p1, pObj, pEntry );
454  Counter++;
455  }
456 
457  // cleanup
458  Aig_ManCleanMarkA( p0 );
459  ABC_FREE( ppTable );
460  ABC_FREE( ppNexts );
461  ABC_FREE( ppCands );
462  return Counter;
463 }
464 
465 /**Function*************************************************************
466 
467  Synopsis [Counts the number of matched flops.]
468 
469  Description []
470 
471  SideEffects []
472 
473  SeeAlso []
474 
475 ***********************************************************************/
477 {
478  Aig_Obj_t * pObj;
479  int i, Counter = 0;
480  Saig_ManForEachLo( p, pObj, i )
481  if ( Aig_ObjRepr(p, pObj) )
482  Counter++;
483  return Counter;
484 }
485 
486 /**Function*************************************************************
487 
488  Synopsis [Counts the number of matched nodes.]
489 
490  Description []
491 
492  SideEffects []
493 
494  SeeAlso []
495 
496 ***********************************************************************/
498 {
499  Aig_Obj_t * pObj;
500  int i, Counter = 0;
501  Aig_ManForEachNode( p, pObj, i )
502  if ( Aig_ObjRepr(p, pObj) )
503  Counter++;
504  return Counter;
505 }
506 
507 /**Function*************************************************************
508 
509  Synopsis [Performs structural matching of two AIGs using simulation.]
510 
511  Description []
512 
513  SideEffects []
514 
515  SeeAlso []
516 
517 ***********************************************************************/
519 {
520  Aig_Obj_t * pObj;
521  int i;
523  // allocate simulation info
525  Aig_ManForEachObj( p, pObj, i )
526  pObj->pData = Vec_PtrEntry( (Vec_Ptr_t *)p->pData2, i );
527  // set simulation info for constant1 and register outputs
529  Saig_ManForEachLo( p, pObj, i )
531 }
532 
533 /**Function*************************************************************
534 
535  Synopsis [Performs structural matching of two AIGs using simulation.]
536 
537  Description []
538 
539  SideEffects []
540 
541  SeeAlso []
542 
543 ***********************************************************************/
545 {
546  Aig_Obj_t * pObj0, * pObj1;
547  int i;
548  pObj0 = Aig_ManConst1( p0 );
549  pObj1 = Aig_ManConst1( p1 );
550  Aig_ObjSetRepr( p0, pObj0, pObj1 );
551  Aig_ObjSetRepr( p1, pObj1, pObj0 );
552  Saig_ManForEachPi( p0, pObj0, i )
553  {
554  pObj1 = Aig_ManCi( p1, i );
555  Aig_ObjSetRepr( p0, pObj0, pObj1 );
556  Aig_ObjSetRepr( p1, pObj1, pObj0 );
557  }
558 }
559 
560 /**Function*************************************************************
561 
562  Synopsis [Performs structural matching of two AIGs using simulation.]
563 
564  Description []
565 
566  SideEffects []
567 
568  SeeAlso []
569 
570 ***********************************************************************/
572 {
573  Aig_Obj_t * pObj0, * pObj1;
574  Aig_Obj_t * pFanin00, * pFanin01;
575  Aig_Obj_t * pFanin10, * pFanin11;
576  int i, CountAll = 0, CountNot = 0;
578  Aig_ManForEachObj( p0, pObj0, i )
579  {
580  pObj1 = Aig_ObjRepr( p0, pObj0 );
581  if ( pObj1 == NULL )
582  continue;
583  CountAll++;
584  assert( pObj0 == Aig_ObjRepr( p1, pObj1 ) );
585  if ( Aig_ObjIsNode(pObj0) )
586  {
587  assert( Aig_ObjIsNode(pObj1) );
588  pFanin00 = Aig_ObjFanin0(pObj0);
589  pFanin01 = Aig_ObjFanin1(pObj0);
590  pFanin10 = Aig_ObjFanin0(pObj1);
591  pFanin11 = Aig_ObjFanin1(pObj1);
592  if ( Aig_ObjRepr(p0, pFanin00) != pFanin10 ||
593  Aig_ObjRepr(p0, pFanin01) != pFanin11 )
594  {
595  Aig_ObjSetTravIdCurrent(p0, pObj0);
596  CountNot++;
597  }
598  }
599  else if ( Saig_ObjIsLo(p0, pObj0) )
600  {
601  assert( Saig_ObjIsLo(p1, pObj1) );
602  pFanin00 = Aig_ObjFanin0( Saig_ObjLoToLi(p0, pObj0) );
603  pFanin10 = Aig_ObjFanin0( Saig_ObjLoToLi(p1, pObj1) );
604  if ( Aig_ObjRepr(p0, pFanin00) != pFanin10 )
605  {
606  Aig_ObjSetTravIdCurrent(p0, pObj0);
607  CountNot++;
608  }
609  }
610  }
611  // remove irrelevant matches
612  Aig_ManForEachObj( p0, pObj0, i )
613  {
614  pObj1 = Aig_ObjRepr( p0, pObj0 );
615  if ( pObj1 == NULL )
616  continue;
617  assert( pObj0 == Aig_ObjRepr( p1, pObj1 ) );
618  if ( Aig_ObjIsTravIdCurrent( p0, pObj0 ) )
619  {
620  Aig_ObjSetRepr( p0, pObj0, NULL );
621  Aig_ObjSetRepr( p1, pObj1, NULL );
622  }
623  }
624  Abc_Print( 1, "Total matches = %6d. Wrong matches = %6d. Ratio = %5.2f %%\n",
625  CountAll, CountNot, 100.0*CountNot/CountAll );
626 }
627 
628 /**Function*************************************************************
629 
630  Synopsis [Returns the number of dangling nodes removed.]
631 
632  Description []
633 
634  SideEffects []
635 
636  SeeAlso []
637 
638 ***********************************************************************/
640 {
641  Aig_Obj_t * pFanout;
642  int i, iFanout = -1;
643  if ( Aig_ObjIsTravIdCurrent(p, pObj) )
644  return;
645  Aig_ObjSetTravIdCurrent(p, pObj);
646  if ( Saig_ObjIsPo( p, pObj ) )
647  return;
648  if ( Saig_ObjIsLi( p, pObj ) )
649  {
651  return;
652  }
653  assert( Aig_ObjIsCi(pObj) || Aig_ObjIsNode(pObj) );
654  if ( Aig_ObjRepr(p, pObj) == NULL )
655  return;
656  // go through the fanouts
657  Aig_ObjForEachFanout( p, pObj, pFanout, iFanout, i )
659  // go through the fanins
660  if ( !Aig_ObjIsCi( pObj ) )
661  {
664  }
665 }
666 
667 /**Function*************************************************************
668 
669  Synopsis [Performs structural matching of two AIGs using simulation.]
670 
671  Description []
672 
673  SideEffects []
674 
675  SeeAlso []
676 
677 ***********************************************************************/
679 {
680  Aig_Obj_t * pObj0, * pObj1;
681  int i, CountAll = 0, CountNot = 0;
682  // mark nodes reachable through the PIs
685  Saig_ManForEachPi( p0, pObj0, i )
687  // remove irrelevant matches
688  Aig_ManForEachObj( p0, pObj0, i )
689  {
690  pObj1 = Aig_ObjRepr( p0, pObj0 );
691  if ( pObj1 == NULL )
692  continue;
693  CountAll++;
694  assert( pObj0 == Aig_ObjRepr( p1, pObj1 ) );
695  if ( !Aig_ObjIsTravIdCurrent( p0, pObj0 ) )
696  {
697  Aig_ObjSetRepr( p0, pObj0, NULL );
698  Aig_ObjSetRepr( p1, pObj1, NULL );
699  CountNot++;
700  }
701  }
702  Abc_Print( 1, "Total matches = %6d. Wrong matches = %6d. Ratio = %5.2f %%\n",
703  CountAll, CountNot, 100.0*CountNot/CountAll );
704 }
705 
706 
707 
708 /**Function*************************************************************
709 
710  Synopsis [Establishes relationship between nodes using pairing.]
711 
712  Description []
713 
714  SideEffects []
715 
716  SeeAlso []
717 
718 ***********************************************************************/
720 {
721  Aig_Obj_t * pNext, * pObj;
722  int i, k, iFan = -1;
723  Vec_PtrClear( vNodes );
725  Aig_ManForEachObj( p, pObj, i )
726  {
727  if ( !Aig_ObjIsNode(pObj) && !Aig_ObjIsCi(pObj) )
728  continue;
729  if ( Aig_ObjRepr( p, pObj ) != NULL )
730  continue;
731  if ( Saig_ObjIsLo(p, pObj) )
732  {
733  pNext = Saig_ObjLoToLi(p, pObj);
734  pNext = Aig_ObjFanin0(pNext);
735  if ( Aig_ObjRepr( p, pNext ) && !Aig_ObjIsTravIdCurrent(p, pNext) && !Aig_ObjIsConst1(pNext) )
736  {
737  Aig_ObjSetTravIdCurrent(p, pNext);
738  Vec_PtrPush( vNodes, pNext );
739  }
740  }
741  if ( Aig_ObjIsNode(pObj) )
742  {
743  pNext = Aig_ObjFanin0(pObj);
744  if ( Aig_ObjRepr( p, pNext )&& !Aig_ObjIsTravIdCurrent(p, pNext) )
745  {
746  Aig_ObjSetTravIdCurrent(p, pNext);
747  Vec_PtrPush( vNodes, pNext );
748  }
749  pNext = Aig_ObjFanin1(pObj);
750  if ( Aig_ObjRepr( p, pNext ) && !Aig_ObjIsTravIdCurrent(p, pNext) )
751  {
752  Aig_ObjSetTravIdCurrent(p, pNext);
753  Vec_PtrPush( vNodes, pNext );
754  }
755  }
756  Aig_ObjForEachFanout( p, pObj, pNext, iFan, k )
757  {
758  if ( Saig_ObjIsPo(p, pNext) )
759  continue;
760  if ( Saig_ObjIsLi(p, pNext) )
761  pNext = Saig_ObjLiToLo(p, pNext);
762  if ( Aig_ObjRepr( p, pNext ) && !Aig_ObjIsTravIdCurrent(p, pNext) )
763  {
764  Aig_ObjSetTravIdCurrent(p, pNext);
765  Vec_PtrPush( vNodes, pNext );
766  }
767  }
768  }
769 }
770 
771 /**Function*************************************************************
772 
773  Synopsis [Establishes relationship between nodes using pairing.]
774 
775  Description []
776 
777  SideEffects []
778 
779  SeeAlso []
780 
781 ***********************************************************************/
783 {
784  Aig_Obj_t * pObj;
785  int i, Counter = 0;
786  Aig_ManForEachObj( p, pObj, i )
787  {
788  if ( !Aig_ObjIsNode(pObj) && !Aig_ObjIsCi(pObj) )
789  continue;
790  if ( Aig_ObjRepr( p, pObj ) != NULL )
791  continue;
792  Counter++;
793  }
794  return Counter;
795 }
796 
797 /**Function*************************************************************
798 
799  Synopsis [Establishes relationship between nodes using pairing.]
800 
801  Description []
802 
803  SideEffects []
804 
805  SeeAlso []
806 
807 ***********************************************************************/
808 void Ssw_StrSimMatchingExtend( Aig_Man_t * p0, Aig_Man_t * p1, int nDist, int fVerbose )
809 {
810  Vec_Ptr_t * vNodes0, * vNodes1;
811  Aig_Obj_t * pNext0, * pNext1;
812  int d, k;
813  vNodes0 = Vec_PtrAlloc( 1000 );
814  vNodes1 = Vec_PtrAlloc( 1000 );
815  if ( fVerbose )
816  {
817  int nUnmached = Ssw_StrSimMatchingCountUnmached(p0);
818  Abc_Print( 1, "Extending islands by %d steps:\n", nDist );
819  Abc_Print( 1, "%2d : Total = %6d. Unmatched = %6d. Ratio = %6.2f %%\n",
820  0, Aig_ManCiNum(p0) + Aig_ManNodeNum(p0),
821  nUnmached, 100.0 * nUnmached/(Aig_ManCiNum(p0) + Aig_ManNodeNum(p0)) );
822  }
823  for ( d = 0; d < nDist; d++ )
824  {
825  Ssw_StrSimMatchingExtendOne( p0, vNodes0 );
826  Ssw_StrSimMatchingExtendOne( p1, vNodes1 );
827  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes0, pNext0, k )
828  {
829  pNext1 = Aig_ObjRepr( p0, pNext0 );
830  if ( pNext1 == NULL )
831  continue;
832  assert( pNext0 == Aig_ObjRepr( p1, pNext1 ) );
833  if ( Saig_ObjIsPi(p1, pNext1) )
834  continue;
835  Aig_ObjSetRepr( p0, pNext0, NULL );
836  Aig_ObjSetRepr( p1, pNext1, NULL );
837  }
838  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes1, pNext1, k )
839  {
840  pNext0 = Aig_ObjRepr( p1, pNext1 );
841  if ( pNext0 == NULL )
842  continue;
843  assert( pNext1 == Aig_ObjRepr( p0, pNext0 ) );
844  if ( Saig_ObjIsPi(p0, pNext0) )
845  continue;
846  Aig_ObjSetRepr( p0, pNext0, NULL );
847  Aig_ObjSetRepr( p1, pNext1, NULL );
848  }
849  if ( fVerbose )
850  {
851  int nUnmached = Ssw_StrSimMatchingCountUnmached(p0);
852  Abc_Print( 1, "%2d : Total = %6d. Unmatched = %6d. Ratio = %6.2f %%\n",
853  d+1, Aig_ManCiNum(p0) + Aig_ManNodeNum(p0),
854  nUnmached, 100.0 * nUnmached/(Aig_ManCiNum(p0) + Aig_ManNodeNum(p0)) );
855  }
856  }
857  Vec_PtrFree( vNodes0 );
858  Vec_PtrFree( vNodes1 );
859 }
860 
861 
862 /**Function*************************************************************
863 
864  Synopsis [Performs structural matching of two AIGs using simulation.]
865 
866  Description []
867 
868  SideEffects []
869 
870  SeeAlso []
871 
872 ***********************************************************************/
873 Vec_Int_t * Saig_StrSimPerformMatching( Aig_Man_t * p0, Aig_Man_t * p1, int nDist, int fVerbose, Aig_Man_t ** ppMiter )
874 {
876 
877  Vec_Int_t * vPairs;
878  Aig_Man_t * pPart0, * pPart1;
879  Aig_Obj_t * pObj0, * pObj1;
880  int i, nMatches;
881  abctime clk, clkTotal = Abc_Clock();
882  Aig_ManRandom( 1 );
883  // consider the case when a miter is given
884  if ( p1 == NULL )
885  {
886  if ( fVerbose )
887  {
888  Aig_ManPrintStats( p0 );
889  }
890  // demiter the miter
891  if ( !Saig_ManDemiterSimpleDiff( p0, &pPart0, &pPart1 ) )
892  {
893  Abc_Print( 1, "Demitering has failed.\n" );
894  return NULL;
895  }
896  }
897  else
898  {
899  pPart0 = Aig_ManDupSimple( p0 );
900  pPart1 = Aig_ManDupSimple( p1 );
901  }
902  if ( fVerbose )
903  {
904  Aig_ManPrintStats( pPart0 );
905  Aig_ManPrintStats( pPart1 );
906  }
907  // start simulation
908  Saig_StrSimPrepareAig( pPart0 );
909  Saig_StrSimPrepareAig( pPart1 );
910  Saig_StrSimSetInitMatching( pPart0, pPart1 );
911  if ( fVerbose )
912  {
913  Abc_Print( 1, "Allocated %6.2f MB to simulate the first AIG.\n",
914  1.0 * Aig_ManObjNumMax(pPart0) * SAIG_WORDS * sizeof(unsigned) / (1<<20) );
915  Abc_Print( 1, "Allocated %6.2f MB to simulate the second AIG.\n",
916  1.0 * Aig_ManObjNumMax(pPart1) * SAIG_WORDS * sizeof(unsigned) / (1<<20) );
917  }
918  // iterate matching
919  nMatches = 1;
920  for ( i = 0; nMatches > 0; i++ )
921  {
922  clk = Abc_Clock();
923  Saig_StrSimulateRound( pPart0, pPart1 );
924  nMatches = Saig_StrSimDetectUnique( pPart0, pPart1 );
925  if ( fVerbose )
926  {
927  int nFlops = Saig_StrSimCountMatchedFlops(pPart0);
928  int nNodes = Saig_StrSimCountMatchedNodes(pPart0);
929  Abc_Print( 1, "%3d : Match =%6d. FF =%6d. (%6.2f %%) Node =%6d. (%6.2f %%) ",
930  i, nMatches,
931  nFlops, 100.0*nFlops/Aig_ManRegNum(pPart0),
932  nNodes, 100.0*nNodes/Aig_ManNodeNum(pPart0) );
933  ABC_PRT( "Time", Abc_Clock() - clk );
934  }
935  if ( i == 20 )
936  break;
937  }
938  // cleanup
939  Vec_PtrFree( (Vec_Ptr_t *)pPart0->pData2 ); pPart0->pData2 = NULL;
940  Vec_PtrFree( (Vec_Ptr_t *)pPart1->pData2 ); pPart1->pData2 = NULL;
941  // extend the islands
942  Aig_ManFanoutStart( pPart0 );
943  Aig_ManFanoutStart( pPart1 );
944  if ( nDist )
945  Ssw_StrSimMatchingExtend( pPart0, pPart1, nDist, fVerbose );
946  Saig_StrSimSetFinalMatching( pPart0, pPart1 );
947 // Saig_StrSimSetContiguousMatching( pPart0, pPart1 );
948  // copy the results into array
949  vPairs = Vec_IntAlloc( 2*Aig_ManObjNumMax(pPart0) );
950  Aig_ManForEachObj( pPart0, pObj0, i )
951  {
952  pObj1 = Aig_ObjRepr(pPart0, pObj0);
953  if ( pObj1 == NULL )
954  continue;
955  assert( pObj0 == Aig_ObjRepr(pPart1, pObj1) );
956  Vec_IntPush( vPairs, pObj0->Id );
957  Vec_IntPush( vPairs, pObj1->Id );
958  }
959  // this procedure adds matching of PO and LI
960  if ( ppMiter )
961  *ppMiter = Saig_ManWindowExtractMiter( pPart0, pPart1 );
962  Aig_ManFanoutStop( pPart0 );
963  Aig_ManFanoutStop( pPart1 );
964  Aig_ManStop( pPart0 );
965  Aig_ManStop( pPart1 );
966  ABC_PRT( "Total runtime", Abc_Clock() - clkTotal );
967  return vPairs;
968 }
969 
970 
971 ////////////////////////////////////////////////////////////////////////
972 /// END OF FILE ///
973 ////////////////////////////////////////////////////////////////////////
974 
975 
void Ssw_StrSimMatchingExtend(Aig_Man_t *p0, Aig_Man_t *p1, int nDist, int fVerbose)
Definition: saigStrSim.c:808
#define Aig_ObjForEachFanout(p, pObj, pFanout, iFan, i)
Definition: aig.h:427
void Saig_StrSimSetFinalMatching(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigStrSim.c:571
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
Aig_Obj_t * Saig_StrSimTableLookup(Aig_Obj_t **ppTable, Aig_Obj_t **ppNexts, int nTableSize, Aig_Obj_t *pObj)
Definition: saigStrSim.c:345
#define SAIG_WORDS
DECLARATIONS ///.
Definition: saigStrSim.c:31
static Aig_Obj_t * Aig_ObjRepr(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:330
static Aig_Type_t Aig_ObjType(Aig_Obj_t *pObj)
Definition: aig.h:272
void Saig_StrSimSaveOutput(Aig_Obj_t *pObj, int i)
Definition: saigStrSim.c:234
static int Saig_ObjIsLo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:84
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
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
void Saig_StrSimSetInitMatching(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigStrSim.c:544
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
static int Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:295
static int Aig_ManObjNum(Aig_Man_t *p)
Definition: aig.h:258
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition: saig.h:101
static Aig_Obj_t * Saig_ObjLoToLi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:86
static void Saig_ObjSetNext(Aig_Obj_t **ppNexts, Aig_Obj_t *pObj, Aig_Obj_t *pNext)
Definition: saigStrSim.c:34
void * pData
Definition: aig.h:87
void Saig_StrSimTableInsert(Aig_Obj_t **ppTable, Aig_Obj_t **ppNexts, int nTableSize, Aig_Obj_t *pObj)
Definition: saigStrSim.c:369
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
void Aig_ManPrintStats(Aig_Man_t *p)
Definition: aigMan.c:379
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned int fMarkA
Definition: aig.h:79
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
void Saig_StrSimSetContiguousMatching_rec(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saigStrSim.c:639
Aig_Man_t * Saig_ManWindowExtractMiter(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigWnd.c:716
static abctime Abc_Clock()
Definition: abc_global.h:279
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static void Aig_ObjSetTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:293
for(p=first;p->value< newval;p=p->next)
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
static int Saig_ObjIsLi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:85
void Aig_ManFanoutStart(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: aigFanout.c:56
void Saig_StrSimPrepareAig(Aig_Man_t *p)
Definition: saigStrSim.c:518
int Saig_StrSimIsOne(Aig_Obj_t *pObj)
Definition: saigStrSim.c:132
void Aig_ManFanoutStop(Aig_Man_t *p)
Definition: aigFanout.c:89
int Saig_ManDemiterSimpleDiff(Aig_Man_t *p, Aig_Man_t **ppAig0, Aig_Man_t **ppAig1)
Definition: saigMiter.c:660
void Aig_ManIncrementTravId(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigUtil.c:44
void Ssw_StrSimMatchingExtendOne(Aig_Man_t *p, Vec_Ptr_t *vNodes)
Definition: saigStrSim.c:719
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
void Saig_StrSimulateNode(Aig_Obj_t *pObj, int i)
Definition: saigStrSim.c:208
void Saig_StrSimTransferNext(Aig_Obj_t *pObj0, Aig_Obj_t *pObj1, int i)
Definition: saigStrSim.c:275
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
static void Aig_ObjSetRepr(Aig_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pRepr)
Definition: aig.h:331
void Aig_ManReprStart(Aig_Man_t *p, int nIdMax)
DECLARATIONS ///.
Definition: aigRepr.c:45
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
#define Saig_ManForEachLi(p, pObj, i)
Definition: saig.h:98
static Aig_Obj_t * Aig_ManCi(Aig_Man_t *p, int i)
Definition: aig.h:266
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
static int Saig_ObjIsPo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:83
static Aig_Obj_t * Saig_ObjLiToLo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:87
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
int Saig_StrSimCountMatchedFlops(Aig_Man_t *p)
Definition: saigStrSim.c:476
void Saig_StrSimAssignZeroInit(Aig_Obj_t *pObj)
Definition: saigStrSim.c:191
int Saig_StrSimIsZero(Aig_Obj_t *pObj)
Definition: saigStrSim.c:111
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Counter
#define Saig_ManForEachLo(p, pObj, i)
Definition: saig.h:96
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Saig_StrSimTransfer(Aig_Obj_t *pObj0, Aig_Obj_t *pObj1)
Definition: saigStrSim.c:255
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Saig_StrSimDetectUnique(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigStrSim.c:394
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Saig_StrSimIsEqual(Aig_Obj_t *pObj0, Aig_Obj_t *pObj1)
Definition: saigStrSim.c:89
void Saig_StrSimulateRound(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigStrSim.c:294
void Aig_ManCleanMarkA(Aig_Man_t *p)
Definition: aigUtil.c:148
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
int Saig_StrSimCountMatchedNodes(Aig_Man_t *p)
Definition: saigStrSim.c:497
#define assert(ex)
Definition: util_old.h:213
void Saig_StrSimAssignRandom(Aig_Obj_t *pObj)
Definition: saigStrSim.c:153
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Saig_StrSimAssignOne(Aig_Obj_t *pObj)
Definition: saigStrSim.c:172
int Ssw_StrSimMatchingCountUnmached(Aig_Man_t *p)
Definition: saigStrSim.c:782
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
ABC_INT64_T abctime
Definition: abc_global.h:278
unsigned Saig_StrSimHash(Aig_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: saigStrSim.c:51
int Id
Definition: aig.h:85
static int Saig_ObjIsPi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:82
Aig_Man_t * Aig_ManDupSimple(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigDup.c:46
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
static Aig_Obj_t * Saig_ObjNext(Aig_Obj_t **ppNexts, Aig_Obj_t *pObj)
Definition: saigStrSim.c:33
void Saig_StrSimSetContiguousMatching(Aig_Man_t *p0, Aig_Man_t *p1)
Definition: saigStrSim.c:678
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
#define Saig_ManForEachPi(p, pObj, i)
Definition: saig.h:91
Vec_Int_t * Saig_StrSimPerformMatching(Aig_Man_t *p0, Aig_Man_t *p1, int nDist, int fVerbose, Aig_Man_t **ppMiter)
Definition: saigStrSim.c:873