abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
resSim.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [resSim.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Resynthesis package.]
8 
9  Synopsis [Simulation engine.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - January 15, 2007.]
16 
17  Revision [$Id: resSim.c,v 1.00 2007/01/15 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "resInt.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// FUNCTION DEFINITIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37  Synopsis [Allocate simulation engine.]
38 
39  Description []
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
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 }
68 
69 /**Function*************************************************************
70 
71  Synopsis [Allocate simulation engine.]
72 
73  Description []
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
80 void Res_SimAdjust( Res_Sim_t * p, Abc_Ntk_t * pAig, int nTruePis )
81 {
82  srand( 0xABC );
83 
84  assert( Abc_NtkIsStrash(pAig) );
85  p->pAig = pAig;
86  p->nTruePis = nTruePis;
87  if ( Vec_PtrSize(p->vPats) < Abc_NtkObjNumMax(pAig)+1 )
88  {
89  Vec_PtrFree( p->vPats );
91  }
92  if ( Vec_PtrSize(p->vPats0) < nTruePis )
93  {
94  Vec_PtrFree( p->vPats0 );
95  p->vPats0 = Vec_PtrAllocSimInfo( nTruePis, p->nWords );
96  }
97  if ( Vec_PtrSize(p->vPats1) < nTruePis )
98  {
99  Vec_PtrFree( p->vPats1 );
100  p->vPats1 = Vec_PtrAllocSimInfo( nTruePis, p->nWords );
101  }
102  if ( Vec_PtrSize(p->vOuts) < Abc_NtkPoNum(pAig) )
103  {
104  Vec_PtrFree( p->vOuts );
106  }
107  // clean storage info for patterns
108  Abc_InfoClear( (unsigned *)Vec_PtrEntry(p->vPats0,0), p->nWords * nTruePis );
109  Abc_InfoClear( (unsigned *)Vec_PtrEntry(p->vPats1,0), p->nWords * nTruePis );
110  p->nPats0 = 0;
111  p->nPats1 = 0;
112  p->fConst0 = 0;
113  p->fConst1 = 0;
114 }
115 
116 /**Function*************************************************************
117 
118  Synopsis [Free simulation engine.]
119 
120  Description []
121 
122  SideEffects []
123 
124  SeeAlso []
125 
126 ***********************************************************************/
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 }
136 
137 
138 /**Function*************************************************************
139 
140  Synopsis [Sets random PI simulation info.]
141 
142  Description []
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
149 void Abc_InfoRandomBytes( unsigned * p, int nWords )
150 {
151  int i, Num;
152  for ( i = nWords - 1; i >= 0; i-- )
153  {
154  Num = rand();
155  p[i] = (Num & 1)? 0xff : 0;
156  p[i] = (p[i] << 8) | ((Num & 2)? 0xff : 0);
157  p[i] = (p[i] << 8) | ((Num & 4)? 0xff : 0);
158  p[i] = (p[i] << 8) | ((Num & 8)? 0xff : 0);
159  }
160 // Extra_PrintBinary( stdout, p, 32 ); printf( "\n" );
161 }
162 
163 /**Function*************************************************************
164 
165  Synopsis [Sets random PI simulation info.]
166 
167  Description []
168 
169  SideEffects []
170 
171  SeeAlso []
172 
173 ***********************************************************************/
175 {
176  Abc_Obj_t * pObj;
177  unsigned * pInfo;
178  int i;
179  Abc_NtkForEachPi( p->pAig, pObj, i )
180  {
181  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
182  if ( i < p->nTruePis )
183  Abc_InfoRandomBytes( pInfo, p->nWordsIn );
184  else
185  Abc_InfoRandom( pInfo, p->nWordsIn );
186  }
187 /*
188  // double-check that all are byte-patterns
189  Abc_NtkForEachPi( p->pAig, pObj, i )
190  {
191  if ( i == p->nTruePis )
192  break;
193  pInfoC = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
194  for ( k = 0; k < p->nBytesIn; k++ )
195  assert( pInfoC[k] == 0 || pInfoC[k] == 0xff );
196  }
197 */
198 }
199 
200 /**Function*************************************************************
201 
202  Synopsis [Sets random PI simulation info.]
203 
204  Description []
205 
206  SideEffects []
207 
208  SeeAlso []
209 
210 ***********************************************************************/
211 void Res_SimSetDerivedBytes( Res_Sim_t * p, int fUseWalk )
212 {
213  Vec_Ptr_t * vPatsSource[2];
214  int nPatsSource[2];
215  Abc_Obj_t * pObj;
216  unsigned char * pInfo;
217  int i, k, z, s, nPats;
218 
219  // set several random patterns
220  assert( p->nBytesIn % 32 == 0 );
221  nPats = p->nBytesIn/8;
222  Abc_NtkForEachPi( p->pAig, pObj, i )
223  {
224  if ( i == p->nTruePis )
225  break;
226  Abc_InfoRandomBytes( (unsigned *)Vec_PtrEntry(p->vPats, pObj->Id), nPats/4 );
227  }
228 
229  // set special patterns
230  if ( fUseWalk )
231  {
232  for ( z = 0; z < 2; z++ )
233  {
234  // set the zero pattern
235  Abc_NtkForEachPi( p->pAig, pObj, i )
236  {
237  if ( i == p->nTruePis )
238  break;
239  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
240  pInfo[nPats] = z ? 0xff : 0;
241  }
242  if ( ++nPats == p->nBytesIn )
243  return;
244  // set the walking zero pattern
245  for ( k = 0; k < p->nTruePis; k++ )
246  {
247  Abc_NtkForEachPi( p->pAig, pObj, i )
248  {
249  if ( i == p->nTruePis )
250  break;
251  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
252  pInfo[nPats] = ((i == k) ^ z) ? 0xff : 0;
253  }
254  if ( ++nPats == p->nBytesIn )
255  return;
256  }
257  }
258  }
259 
260  // decide what patterns to set first
261  if ( p->nPats0 < p->nPats1 )
262  {
263  nPatsSource[0] = p->nPats0;
264  vPatsSource[0] = p->vPats0;
265  nPatsSource[1] = p->nPats1;
266  vPatsSource[1] = p->vPats1;
267  }
268  else
269  {
270  nPatsSource[0] = p->nPats1;
271  vPatsSource[0] = p->vPats1;
272  nPatsSource[1] = p->nPats0;
273  vPatsSource[1] = p->vPats0;
274  }
275  for ( z = 0; z < 2; z++ )
276  {
277  for ( s = nPatsSource[z] - 1; s >= 0; s-- )
278  {
279 // if ( s == 0 )
280 // printf( "Patterns:\n" );
281  // set the given source pattern
282  for ( k = 0; k < p->nTruePis; k++ )
283  {
284  Abc_NtkForEachPi( p->pAig, pObj, i )
285  {
286  if ( i == p->nTruePis )
287  break;
288  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
289  if ( (i == k) ^ Abc_InfoHasBit( (unsigned *)Vec_PtrEntry(vPatsSource[z], i), s ) )
290  {
291  pInfo[nPats] = 0xff;
292 // if ( s == 0 )
293 // printf( "1" );
294  }
295  else
296  {
297  pInfo[nPats] = 0;
298 // if ( s == 0 )
299 // printf( "0" );
300  }
301  }
302 // if ( s == 0 )
303 // printf( "\n" );
304  if ( ++nPats == p->nBytesIn )
305  return;
306  }
307  }
308  }
309  // clean the rest
310  for ( z = nPats; z < p->nBytesIn; z++ )
311  {
312  Abc_NtkForEachPi( p->pAig, pObj, i )
313  {
314  if ( i == p->nTruePis )
315  break;
316  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
317  memset( pInfo + nPats, 0, p->nBytesIn - nPats );
318  }
319  }
320 /*
321  // double-check that all are byte-patterns
322  Abc_NtkForEachPi( p->pAig, pObj, i )
323  {
324  if ( i == p->nTruePis )
325  break;
326  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
327  for ( k = 0; k < p->nBytesIn; k++ )
328  assert( pInfo[k] == 0 || pInfo[k] == 0xff );
329  }
330 */
331 }
332 
333 /**Function*************************************************************
334 
335  Synopsis [Sets given PI simulation info.]
336 
337  Description []
338 
339  SideEffects []
340 
341  SeeAlso []
342 
343 ***********************************************************************/
345 {
346  Abc_Obj_t * pObj;
347  unsigned * pInfo, * pInfo2;
348  int i, w;
349  Abc_NtkForEachPi( p->pAig, pObj, i )
350  {
351  if ( i == p->nTruePis )
352  break;
353  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
354  pInfo2 = (unsigned *)Vec_PtrEntry( vInfo, i );
355  for ( w = 0; w < p->nWords; w++ )
356  pInfo[w] = pInfo2[w];
357  }
358 }
359 
360 /**Function*************************************************************
361 
362  Synopsis [Simulates one node.]
363 
364  Description []
365 
366  SideEffects []
367 
368  SeeAlso []
369 
370 ***********************************************************************/
371 void Res_SimPerformOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords )
372 {
373  unsigned * pInfo, * pInfo1, * pInfo2;
374  int k, fComp1, fComp2;
375  // simulate the internal nodes
376  assert( Abc_ObjIsNode(pNode) );
377  pInfo = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
378  pInfo1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
379  pInfo2 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId1(pNode));
380  fComp1 = Abc_ObjFaninC0(pNode);
381  fComp2 = Abc_ObjFaninC1(pNode);
382  if ( fComp1 && fComp2 )
383  for ( k = 0; k < nSimWords; k++ )
384  pInfo[k] = ~pInfo1[k] & ~pInfo2[k];
385  else if ( fComp1 && !fComp2 )
386  for ( k = 0; k < nSimWords; k++ )
387  pInfo[k] = ~pInfo1[k] & pInfo2[k];
388  else if ( !fComp1 && fComp2 )
389  for ( k = 0; k < nSimWords; k++ )
390  pInfo[k] = pInfo1[k] & ~pInfo2[k];
391  else // if ( fComp1 && fComp2 )
392  for ( k = 0; k < nSimWords; k++ )
393  pInfo[k] = pInfo1[k] & pInfo2[k];
394 }
395 
396 /**Function*************************************************************
397 
398  Synopsis [Simulates one CO node.]
399 
400  Description []
401 
402  SideEffects []
403 
404  SeeAlso []
405 
406 ***********************************************************************/
407 void Res_SimTransferOne( Abc_Obj_t * pNode, Vec_Ptr_t * vSimInfo, int nSimWords )
408 {
409  unsigned * pInfo, * pInfo1;
410  int k, fComp1;
411  // simulate the internal nodes
412  assert( Abc_ObjIsCo(pNode) );
413  pInfo = (unsigned *)Vec_PtrEntry(vSimInfo, pNode->Id);
414  pInfo1 = (unsigned *)Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
415  fComp1 = Abc_ObjFaninC0(pNode);
416  if ( fComp1 )
417  for ( k = 0; k < nSimWords; k++ )
418  pInfo[k] = ~pInfo1[k];
419  else
420  for ( k = 0; k < nSimWords; k++ )
421  pInfo[k] = pInfo1[k];
422 }
423 
424 /**Function*************************************************************
425 
426  Synopsis [Performs one round of simulation.]
427 
428  Description []
429 
430  SideEffects []
431 
432  SeeAlso []
433 
434 ***********************************************************************/
436 {
437  Abc_Obj_t * pObj;
438  int i;
439  Abc_InfoFill( (unsigned *)Vec_PtrEntry(p->vPats,0), nWords );
440  Abc_AigForEachAnd( p->pAig, pObj, i )
441  Res_SimPerformOne( pObj, p->vPats, nWords );
442  Abc_NtkForEachPo( p->pAig, pObj, i )
443  Res_SimTransferOne( pObj, p->vPats, nWords );
444 }
445 
446 
447 /**Function*************************************************************
448 
449  Synopsis [Pads the extra space with duplicated simulation info.]
450 
451  Description []
452 
453  SideEffects []
454 
455  SeeAlso []
456 
457 ***********************************************************************/
458 void Res_SimPadSimInfo( Vec_Ptr_t * vPats, int nPats, int nWords )
459 {
460  unsigned * pInfo;
461  int i, w, iWords;
462  assert( nPats > 0 && nPats < nWords * 8 * (int) sizeof(unsigned) );
463  // pad the first word
464  if ( nPats < 8 * sizeof(unsigned) )
465  {
466  Vec_PtrForEachEntry( unsigned *, vPats, pInfo, i )
467  if ( pInfo[0] & 1 )
468  pInfo[0] |= ((~0) << nPats);
469  nPats = 8 * sizeof(unsigned);
470  }
471  // pad the empty words
472  iWords = nPats / (8 * sizeof(unsigned));
473  Vec_PtrForEachEntry( unsigned *, vPats, pInfo, i )
474  {
475  for ( w = iWords; w < nWords; w++ )
476  pInfo[w] = pInfo[0];
477  }
478 }
479 
480 /**Function*************************************************************
481 
482  Synopsis [Duplicates the simulation info to fill the space.]
483 
484  Description []
485 
486  SideEffects []
487 
488  SeeAlso []
489 
490 ***********************************************************************/
492 {
493  unsigned * pInfo, * pInfo2;
494  Abc_Obj_t * pObj;
495  int i, j, w;
496  Abc_NtkForEachPo( p->pAig, pObj, i )
497  {
498  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
499  pInfo2 = (unsigned *)Vec_PtrEntry( p->vOuts, i );
500  for ( j = 0; j < p->nPats; j++ )
501  for ( w = 0; w < p->nWords; w++ )
502  *pInfo2++ = pInfo[w];
503  }
504 }
505 
506 /**Function*************************************************************
507 
508  Synopsis [Complement the simulation info if necessary.]
509 
510  Description []
511 
512  SideEffects []
513 
514  SeeAlso []
515 
516 ***********************************************************************/
518 {
519  unsigned * pInfo, * pInfo2;
520  Abc_Obj_t * pObj;
521  int i, j, w;
522  Abc_NtkForEachPo( p->pAig, pObj, i )
523  {
524  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
525  pInfo2 = (unsigned *)Vec_PtrEntry( p->vOuts, i );
526  for ( j = 0; j < p->nPats; j++, pInfo2 += p->nWords )
527  if ( Abc_InfoHasBit( pInfo, j ) )
528  for ( w = 0; w < p->nWords; w++ )
529  pInfo2[w] = ~pInfo2[w];
530  }
531 }
532 
533 /**Function*************************************************************
534 
535  Synopsis [Prints output patterns.]
536 
537  Description []
538 
539  SideEffects []
540 
541  SeeAlso []
542 
543 ***********************************************************************/
545 {
546  Abc_Obj_t * pObj;
547  unsigned * pInfo2;
548  int i;
549  Abc_NtkForEachPo( pAig, pObj, i )
550  {
551  pInfo2 = (unsigned *)Vec_PtrEntry( p->vOuts, i );
552  Extra_PrintBinary( stdout, pInfo2, p->nPatsOut );
553  printf( "\n" );
554  }
555 }
556 
557 /**Function*************************************************************
558 
559  Synopsis [Prints output patterns.]
560 
561  Description []
562 
563  SideEffects []
564 
565  SeeAlso []
566 
567 ***********************************************************************/
569 {
570  unsigned * pInfo;
571  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 1)->Id );
572  Extra_PrintBinary( stdout, pInfo, p->nPats );
573  printf( "\n" );
574 }
575 
576 /**Function*************************************************************
577 
578  Synopsis [Counts the number of patters of different type.]
579 
580  Description []
581 
582  SideEffects []
583 
584  SeeAlso []
585 
586 ***********************************************************************/
587 void Res_SimCountResults( Res_Sim_t * p, int * pnDcs, int * pnOnes, int * pnZeros, int fVerbose )
588 {
589  unsigned char * pInfoCare, * pInfoNode;
590  int i, nTotal = 0;
591  pInfoCare = (unsigned char *)Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 0)->Id );
592  pInfoNode = (unsigned char *)Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 1)->Id );
593  for ( i = 0; i < p->nBytesIn; i++ )
594  {
595  if ( !pInfoCare[i] )
596  (*pnDcs)++;
597  else if ( !pInfoNode[i] )
598  (*pnZeros)++;
599  else
600  (*pnOnes)++;
601  }
602  nTotal += *pnDcs;
603  nTotal += *pnZeros;
604  nTotal += *pnOnes;
605  if ( fVerbose )
606  {
607  printf( "Dc = %7.2f %% ", 100.0*(*pnDcs) /nTotal );
608  printf( "On = %7.2f %% ", 100.0*(*pnOnes) /nTotal );
609  printf( "Off = %7.2f %% ", 100.0*(*pnZeros)/nTotal );
610  }
611 }
612 
613 /**Function*************************************************************
614 
615  Synopsis [Counts the number of patters of different type.]
616 
617  Description []
618 
619  SideEffects []
620 
621  SeeAlso []
622 
623 ***********************************************************************/
624 void Res_SimCollectPatterns( Res_Sim_t * p, int fVerbose )
625 {
626  Abc_Obj_t * pObj;
627  unsigned char * pInfoCare, * pInfoNode, * pInfo;
628  int i, j;
629  pInfoCare = (unsigned char *)Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 0)->Id );
630  pInfoNode = (unsigned char *)Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 1)->Id );
631  for ( i = 0; i < p->nBytesIn; i++ )
632  {
633  // skip don't-care patterns
634  if ( !pInfoCare[i] )
635  continue;
636  // separate offset and onset patterns
637  assert( pInfoNode[i] == 0 || pInfoNode[i] == 0xff );
638  if ( !pInfoNode[i] )
639  {
640  if ( p->nPats0 >= p->nPats )
641  continue;
642  Abc_NtkForEachPi( p->pAig, pObj, j )
643  {
644  if ( j == p->nTruePis )
645  break;
646  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
647  assert( pInfo[i] == 0 || pInfo[i] == 0xff );
648  if ( pInfo[i] )
649  Abc_InfoSetBit( (unsigned *)Vec_PtrEntry(p->vPats0, j), p->nPats0 );
650  }
651  p->nPats0++;
652  }
653  else
654  {
655  if ( p->nPats1 >= p->nPats )
656  continue;
657  Abc_NtkForEachPi( p->pAig, pObj, j )
658  {
659  if ( j == p->nTruePis )
660  break;
661  pInfo = (unsigned char *)Vec_PtrEntry( p->vPats, pObj->Id );
662  assert( pInfo[i] == 0 || pInfo[i] == 0xff );
663  if ( pInfo[i] )
664  Abc_InfoSetBit( (unsigned *)Vec_PtrEntry(p->vPats1, j), p->nPats1 );
665  }
666  p->nPats1++;
667  }
668  if ( p->nPats0 >= p->nPats && p->nPats1 >= p->nPats )
669  break;
670  }
671  if ( fVerbose )
672  {
673  printf( "| " );
674  printf( "On = %3d ", p->nPats1 );
675  printf( "Off = %3d ", p->nPats0 );
676  printf( "\n" );
677  }
678 }
679 
680 /**Function*************************************************************
681 
682  Synopsis [Verifies the last pattern.]
683 
684  Description []
685 
686  SideEffects []
687 
688  SeeAlso []
689 
690 ***********************************************************************/
691 int Res_SimVerifyValue( Res_Sim_t * p, int fOnSet )
692 {
693  Abc_Obj_t * pObj;
694  unsigned * pInfo, * pInfo2;
695  int i, value;
696  Abc_NtkForEachPi( p->pAig, pObj, i )
697  {
698  if ( i == p->nTruePis )
699  break;
700  if ( fOnSet )
701  {
702  pInfo2 = (unsigned *)Vec_PtrEntry( p->vPats1, i );
703  value = Abc_InfoHasBit( pInfo2, p->nPats1 - 1 );
704  }
705  else
706  {
707  pInfo2 = (unsigned *)Vec_PtrEntry( p->vPats0, i );
708  value = Abc_InfoHasBit( pInfo2, p->nPats0 - 1 );
709  }
710  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
711  pInfo[0] = value ? ~0 : 0;
712  }
713  Res_SimPerformRound( p, 1 );
714  pObj = Abc_NtkPo( p->pAig, 1 );
715  pInfo = (unsigned *)Vec_PtrEntry( p->vPats, pObj->Id );
716  assert( pInfo[0] == 0 || pInfo[0] == ~0 );
717  return pInfo[0] > 0;
718 }
719 
720 /**Function*************************************************************
721 
722  Synopsis [Prepares simulation info for candidate filtering.]
723 
724  Description []
725 
726  SideEffects []
727 
728  SeeAlso []
729 
730 ***********************************************************************/
731 int Res_SimPrepare( Res_Sim_t * p, Abc_Ntk_t * pAig, int nTruePis, int fVerbose )
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 }
788 
789 ////////////////////////////////////////////////////////////////////////
790 /// END OF FILE ///
791 ////////////////////////////////////////////////////////////////////////
792 
793 
795 
char * memset()
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
int nWordsOut
Definition: resInt.h:82
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Res_SimSetGiven(Res_Sim_t *p, Vec_Ptr_t *vInfo)
Definition: resSim.c:344
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
void Res_SimPrintNodePatterns(Res_Sim_t *p, Abc_Ntk_t *pAig)
Definition: resSim.c:568
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
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
int nTruePis
Definition: resInt.h:73
void Res_SimCountResults(Res_Sim_t *p, int *pnDcs, int *pnOnes, int *pnZeros, int fVerbose)
Definition: resSim.c:587
static void Abc_InfoFill(unsigned *p, int nWords)
Definition: abc.h:237
int Res_SimVerifyValue(Res_Sim_t *p, int fOnSet)
Definition: resSim.c:691
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
int nWords
Definition: abcNpn.c:127
static int Abc_ObjFaninId0(Abc_Obj_t *pObj)
Definition: abc.h:367
int Res_SimPrepare(Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis, int fVerbose)
Definition: resSim.c:731
void Res_SimPerformOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
Definition: resSim.c:371
Vec_Vec_t * vCands
Definition: resInt.h:92
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
ABC_NAMESPACE_IMPL_START Res_Sim_t * Res_SimAlloc(int nWords)
DECLARATIONS ///.
Definition: resSim.c:46
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition: abc.h:485
void Res_SimSetRandomBytes(Res_Sim_t *p)
Definition: resSim.c:174
void Res_SimCollectPatterns(Res_Sim_t *p, int fVerbose)
Definition: resSim.c:624
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
Abc_Ntk_t * pAig
Definition: resInt.h:72
int Res_SatSimulate(Res_Sim_t *p, int nPats, int fOnSet)
Definition: resSat.c:212
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Vec_Ptr_t * vPats1
Definition: resInt.h:87
void Abc_InfoRandomBytes(unsigned *p, int nWords)
Definition: resSim.c:149
int nPats1
Definition: resInt.h:90
int nWords
Definition: resInt.h:77
static Vec_Vec_t * Vec_VecStart(int nSize)
Definition: vecVec.h:168
int fConst1
Definition: resInt.h:75
static void Abc_InfoClear(unsigned *p, int nWords)
Definition: abc.h:236
int fConst0
Definition: resInt.h:74
Vec_Ptr_t * vPats
Definition: resInt.h:85
void Res_SimTransferOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
Definition: resSim.c:407
int nPatsIn
Definition: resInt.h:80
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int nWordsIn
Definition: resInt.h:79
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
void Res_SimFree(Res_Sim_t *p)
Definition: resSim.c:127
void Res_SimSetDerivedBytes(Res_Sim_t *p, int fUseWalk)
Definition: resSim.c:211
void Res_SimPrintOutPatterns(Res_Sim_t *p, Abc_Ntk_t *pAig)
Definition: resSim.c:544
static Abc_Obj_t * Abc_NtkPo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:316
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Id
Definition: abc.h:132
void Res_SimDeriveInfoReplicate(Res_Sim_t *p)
Definition: resSim.c:491
int nBytesIn
Definition: resInt.h:81
void Res_SimDeriveInfoComplement(Res_Sim_t *p)
Definition: resSim.c:517
void Res_SimPerformRound(Res_Sim_t *p, int nWords)
Definition: resSim.c:435
Vec_Ptr_t * vOuts
Definition: resInt.h:88
int value
#define assert(ex)
Definition: util_old.h:213
static void Abc_InfoRandom(unsigned *p, int nWords)
Definition: abc.h:235
static int Abc_ObjFaninId1(Abc_Obj_t *pObj)
Definition: abc.h:368
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
int nPats0
Definition: resInt.h:89
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int nPats
Definition: resInt.h:78
int nPatsOut
Definition: resInt.h:83
void Res_SimPadSimInfo(Vec_Ptr_t *vPats, int nPats, int nWords)
Definition: resSim.c:458
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223