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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Res_Sim_t
Res_SimAlloc (int nWords)
 DECLARATIONS ///. More...
 
void Res_SimAdjust (Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis)
 
void Res_SimFree (Res_Sim_t *p)
 
void Abc_InfoRandomBytes (unsigned *p, int nWords)
 
void Res_SimSetRandomBytes (Res_Sim_t *p)
 
void Res_SimSetDerivedBytes (Res_Sim_t *p, int fUseWalk)
 
void Res_SimSetGiven (Res_Sim_t *p, Vec_Ptr_t *vInfo)
 
void Res_SimPerformOne (Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
 
void Res_SimTransferOne (Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
 
void Res_SimPerformRound (Res_Sim_t *p, int nWords)
 
void Res_SimPadSimInfo (Vec_Ptr_t *vPats, int nPats, int nWords)
 
void Res_SimDeriveInfoReplicate (Res_Sim_t *p)
 
void Res_SimDeriveInfoComplement (Res_Sim_t *p)
 
void Res_SimPrintOutPatterns (Res_Sim_t *p, Abc_Ntk_t *pAig)
 
void Res_SimPrintNodePatterns (Res_Sim_t *p, Abc_Ntk_t *pAig)
 
void Res_SimCountResults (Res_Sim_t *p, int *pnDcs, int *pnOnes, int *pnZeros, int fVerbose)
 
void Res_SimCollectPatterns (Res_Sim_t *p, int fVerbose)
 
int Res_SimVerifyValue (Res_Sim_t *p, int fOnSet)
 
int Res_SimPrepare (Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis, int fVerbose)
 

Function Documentation

void Abc_InfoRandomBytes ( unsigned *  p,
int  nWords 
)

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

Synopsis [Sets random PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 149 of file resSim.c.

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 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nWords
Definition: abcNpn.c:127
void Res_SimAdjust ( Res_Sim_t p,
Abc_Ntk_t pAig,
int  nTruePis 
)

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

Synopsis [Allocate simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file resSim.c.

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 }
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
int nWordsOut
Definition: resInt.h:82
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
Vec_Ptr_t * vPats0
Definition: resInt.h:86
int nTruePis
Definition: resInt.h:73
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Abc_Ntk_t * pAig
Definition: resInt.h:72
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
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
int nWordsIn
Definition: resInt.h:79
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
Vec_Ptr_t * vOuts
Definition: resInt.h:88
#define assert(ex)
Definition: util_old.h:213
int nPats0
Definition: resInt.h:89
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
ABC_NAMESPACE_IMPL_START 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_SimCollectPatterns ( Res_Sim_t p,
int  fVerbose 
)

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

Synopsis [Counts the number of patters of different type.]

Description []

SideEffects []

SeeAlso []

Definition at line 624 of file resSim.c.

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 }
Vec_Ptr_t * vPats0
Definition: resInt.h:86
int nTruePis
Definition: resInt.h:73
Abc_Ntk_t * pAig
Definition: resInt.h:72
Vec_Ptr_t * vPats1
Definition: resInt.h:87
int nPats1
Definition: resInt.h:90
Vec_Ptr_t * vPats
Definition: resInt.h:85
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
static Abc_Obj_t * Abc_NtkPo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:316
int Id
Definition: abc.h:132
int nBytesIn
Definition: resInt.h:81
#define assert(ex)
Definition: util_old.h:213
int nPats0
Definition: resInt.h:89
int nPats
Definition: resInt.h:78
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
void Res_SimCountResults ( Res_Sim_t p,
int *  pnDcs,
int *  pnOnes,
int *  pnZeros,
int  fVerbose 
)

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

Synopsis [Counts the number of patters of different type.]

Description []

SideEffects []

SeeAlso []

Definition at line 587 of file resSim.c.

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 }
Abc_Ntk_t * pAig
Definition: resInt.h:72
Vec_Ptr_t * vPats
Definition: resInt.h:85
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
int Id
Definition: abc.h:132
int nBytesIn
Definition: resInt.h:81
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
void Res_SimDeriveInfoComplement ( Res_Sim_t p)

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

Synopsis [Complement the simulation info if necessary.]

Description []

SideEffects []

SeeAlso []

Definition at line 517 of file resSim.c.

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 }
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
Abc_Ntk_t * pAig
Definition: resInt.h:72
int nWords
Definition: resInt.h:77
Vec_Ptr_t * vPats
Definition: resInt.h:85
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
Vec_Ptr_t * vOuts
Definition: resInt.h:88
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
int nPats
Definition: resInt.h:78
void Res_SimDeriveInfoReplicate ( Res_Sim_t p)

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

Synopsis [Duplicates the simulation info to fill the space.]

Description []

SideEffects []

SeeAlso []

Definition at line 491 of file resSim.c.

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 }
Abc_Ntk_t * pAig
Definition: resInt.h:72
int nWords
Definition: resInt.h:77
Vec_Ptr_t * vPats
Definition: resInt.h:85
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
Vec_Ptr_t * vOuts
Definition: resInt.h:88
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
int nPats
Definition: resInt.h:78
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
void Res_SimPadSimInfo ( Vec_Ptr_t vPats,
int  nPats,
int  nWords 
)

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

Synopsis [Pads the extra space with duplicated simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 458 of file resSim.c.

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 }
int nWords
Definition: abcNpn.c:127
if(last==0)
Definition: sparse_int.h:34
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Res_SimPerformOne ( Abc_Obj_t pNode,
Vec_Ptr_t vSimInfo,
int  nSimWords 
)

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

Synopsis [Simulates one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 371 of file resSim.c.

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 }
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
static int Abc_ObjFaninId0(Abc_Obj_t *pObj)
Definition: abc.h:367
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
#define assert(ex)
Definition: util_old.h:213
static int Abc_ObjFaninId1(Abc_Obj_t *pObj)
Definition: abc.h:368
void Res_SimPerformRound ( Res_Sim_t p,
int  nWords 
)

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

Synopsis [Performs one round of simulation.]

Description []

SideEffects []

SeeAlso []

Definition at line 435 of file resSim.c.

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 }
static void Abc_InfoFill(unsigned *p, int nWords)
Definition: abc.h:237
int nWords
Definition: abcNpn.c:127
void Res_SimPerformOne(Abc_Obj_t *pNode, Vec_Ptr_t *vSimInfo, int nSimWords)
Definition: resSim.c:371
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition: abc.h:485
Abc_Ntk_t * pAig
Definition: resInt.h:72
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
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
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_SimPrintNodePatterns ( Res_Sim_t p,
Abc_Ntk_t pAig 
)

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

Synopsis [Prints output patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 568 of file resSim.c.

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 }
Abc_Ntk_t * pAig
Definition: resInt.h:72
Vec_Ptr_t * vPats
Definition: resInt.h:85
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
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
int Id
Definition: abc.h:132
int nPats
Definition: resInt.h:78
void Res_SimPrintOutPatterns ( Res_Sim_t p,
Abc_Ntk_t pAig 
)

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

Synopsis [Prints output patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 544 of file resSim.c.

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 }
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
Vec_Ptr_t * vOuts
Definition: resInt.h:88
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
int nPatsOut
Definition: resInt.h:83
void Res_SimSetDerivedBytes ( Res_Sim_t p,
int  fUseWalk 
)

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

Synopsis [Sets random PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 211 of file resSim.c.

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 }
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
Vec_Ptr_t * vPats0
Definition: resInt.h:86
int nTruePis
Definition: resInt.h:73
Abc_Ntk_t * pAig
Definition: resInt.h:72
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
Vec_Ptr_t * vPats
Definition: resInt.h:85
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
int nBytesIn
Definition: resInt.h:81
#define assert(ex)
Definition: util_old.h:213
int nPats0
Definition: resInt.h:89
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
void Res_SimSetGiven ( Res_Sim_t p,
Vec_Ptr_t vInfo 
)

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

Synopsis [Sets given PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 344 of file resSim.c.

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 }
int nTruePis
Definition: resInt.h:73
Abc_Ntk_t * pAig
Definition: resInt.h:72
int nWords
Definition: resInt.h:77
Vec_Ptr_t * vPats
Definition: resInt.h:85
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
void Res_SimSetRandomBytes ( Res_Sim_t p)

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

Synopsis [Sets random PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 174 of file resSim.c.

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 }
Abc_Ntk_t * pAig
Definition: resInt.h:72
void Abc_InfoRandomBytes(unsigned *p, int nWords)
Definition: resSim.c:149
Vec_Ptr_t * vPats
Definition: resInt.h:85
int nWordsIn
Definition: resInt.h:79
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
static void Abc_InfoRandom(unsigned *p, int nWords)
Definition: abc.h:235
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
void Res_SimTransferOne ( Abc_Obj_t pNode,
Vec_Ptr_t vSimInfo,
int  nSimWords 
)

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

Synopsis [Simulates one CO node.]

Description []

SideEffects []

SeeAlso []

Definition at line 407 of file resSim.c.

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 }
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
static int Abc_ObjFaninId0(Abc_Obj_t *pObj)
Definition: abc.h:367
static int Abc_ObjIsCo(Abc_Obj_t *pObj)
Definition: abc.h:352
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int Id
Definition: abc.h:132
#define assert(ex)
Definition: util_old.h:213
int Res_SimVerifyValue ( Res_Sim_t p,
int  fOnSet 
)

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

Synopsis [Verifies the last pattern.]

Description []

SideEffects []

SeeAlso []

Definition at line 691 of file resSim.c.

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 }
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
Vec_Ptr_t * vPats0
Definition: resInt.h:86
int nTruePis
Definition: resInt.h:73
Abc_Ntk_t * pAig
Definition: resInt.h:72
Vec_Ptr_t * vPats1
Definition: resInt.h:87
int nPats1
Definition: resInt.h:90
Vec_Ptr_t * vPats
Definition: resInt.h:85
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
int Id
Definition: abc.h:132
void Res_SimPerformRound(Res_Sim_t *p, int nWords)
Definition: resSim.c:435
int value
#define assert(ex)
Definition: util_old.h:213
int nPats0
Definition: resInt.h:89
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513