src/opt/res/resSim_old.c File Reference

#include "abc.h"
#include "resInt.h"
Include dependency graph for resSim_old.c:

Go to the source code of this file.

Functions

Res_Sim_tRes_SimAlloc (int nWords)
void Res_SimAdjust (Res_Sim_t *p, Abc_Ntk_t *pAig)
void Res_SimFree (Res_Sim_t *p)
void Res_SimSetRandom (Res_Sim_t *p)
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)
void Res_SimProcessPats (Res_Sim_t *p)
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_SimReportOne (Res_Sim_t *p)
void Res_SimPrintOutPatterns (Res_Sim_t *p, Abc_Ntk_t *pAig)
int Res_SimPrepare (Res_Sim_t *p, Abc_Ntk_t *pAig, int nTruePis, int fVerbose)

Function Documentation

void Res_SimAdjust ( Res_Sim_t p,
Abc_Ntk_t pAig 
)

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

Synopsis [Allocate simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 74 of file resSim_old.c.

00075 {
00076     srand( 0xABC );
00077 
00078     assert( Abc_NtkIsStrash(pAig) );
00079     p->pAig = pAig;
00080     if ( Vec_PtrSize(p->vPats) < Abc_NtkObjNumMax(pAig)+1 )
00081     {
00082         Vec_PtrFree( p->vPats );
00083         p->vPats = Vec_PtrAllocSimInfo( Abc_NtkObjNumMax(pAig)+1, p->nWords );
00084     }
00085     if ( Vec_PtrSize(p->vPats0) < Abc_NtkPiNum(pAig) )
00086     {
00087         Vec_PtrFree( p->vPats0 );
00088         p->vPats0 = Vec_PtrAllocSimInfo( Abc_NtkPiNum(pAig), p->nWords );
00089     }
00090     if ( Vec_PtrSize(p->vPats1) < Abc_NtkPiNum(pAig) )
00091     {
00092         Vec_PtrFree( p->vPats1 );
00093         p->vPats1 = Vec_PtrAllocSimInfo( Abc_NtkPiNum(pAig), p->nWords );
00094     }
00095     if ( Vec_PtrSize(p->vOuts) < Abc_NtkPoNum(pAig) )
00096     {
00097         Vec_PtrFree( p->vOuts );
00098         p->vOuts = Vec_PtrAllocSimInfo( Abc_NtkPoNum(pAig), p->nWordsOut );
00099     }
00100     // clean storage info for patterns
00101     Abc_InfoClear( Vec_PtrEntry(p->vPats0,0), p->nWords * Abc_NtkPiNum(pAig) );
00102     Abc_InfoClear( Vec_PtrEntry(p->vPats1,0), p->nWords * Abc_NtkPiNum(pAig) );
00103     p->nPats0 = 0;
00104     p->nPats1 = 0;
00105 }

Res_Sim_t* Res_SimAlloc ( int  nWords  ) 

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

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

Synopsis [Allocate simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 43 of file resSim_old.c.

00044 {
00045     Res_Sim_t * p;
00046     p = ALLOC( Res_Sim_t, 1 );
00047     memset( p, 0, sizeof(Res_Sim_t) );
00048     // simulation parameters
00049     p->nWords    = nWords;
00050     p->nPats     = 8 * sizeof(unsigned) * p->nWords;
00051     p->nWordsOut = p->nPats * p->nWords;
00052     p->nPatsOut  = p->nPats * p->nPats;
00053     // simulation info
00054     p->vPats     = Vec_PtrAllocSimInfo( 1024, p->nWords );
00055     p->vPats0    = Vec_PtrAllocSimInfo( 128,  p->nWords );
00056     p->vPats1    = Vec_PtrAllocSimInfo( 128,  p->nWords );
00057     p->vOuts     = Vec_PtrAllocSimInfo( 128,  p->nWordsOut );
00058     // resub candidates
00059     p->vCands    = Vec_VecStart( 16 );
00060     return p;
00061 }

void Res_SimDeriveInfoComplement ( Res_Sim_t p  ) 

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

Synopsis [Complement the simulation info if necessary.]

Description []

SideEffects []

SeeAlso []

Definition at line 381 of file resSim_old.c.

00382 {
00383     unsigned * pInfo, * pInfo2;
00384     Abc_Obj_t * pObj;
00385     int i, j, w;
00386     Abc_NtkForEachPo( p->pAig, pObj, i )
00387     {
00388         pInfo = Vec_PtrEntry( p->vPats, pObj->Id );
00389         pInfo2 = Vec_PtrEntry( p->vOuts, i );
00390         for ( j = 0; j < p->nPats; j++, pInfo2 += p->nWords )
00391             if ( Abc_InfoHasBit( pInfo, j ) )
00392                 for ( w = 0; w < p->nWords; w++ )
00393                     pInfo2[w] = ~pInfo2[w];
00394     }
00395 }

void Res_SimDeriveInfoReplicate ( Res_Sim_t p  ) 

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 355 of file resSim_old.c.

00356 {
00357     unsigned * pInfo, * pInfo2;
00358     Abc_Obj_t * pObj;
00359     int i, j, w;
00360     Abc_NtkForEachPo( p->pAig, pObj, i )
00361     {
00362         pInfo = Vec_PtrEntry( p->vPats, pObj->Id );
00363         pInfo2 = Vec_PtrEntry( p->vOuts, i );
00364         for ( j = 0; j < p->nPats; j++ )
00365             for ( w = 0; w < p->nWords; w++ )
00366                 *pInfo2++ = pInfo[w];
00367     }
00368 }

void Res_SimFree ( Res_Sim_t p  ) 

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

Synopsis [Free simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 118 of file resSim_old.c.

00119 {
00120     Vec_PtrFree( p->vPats );
00121     Vec_PtrFree( p->vPats0 );
00122     Vec_PtrFree( p->vPats1 );
00123     Vec_PtrFree( p->vOuts );
00124     Vec_VecFree( p->vCands );
00125     free( p );
00126 }

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 322 of file resSim_old.c.

00323 {
00324     unsigned * pInfo;
00325     int i, w, iWords;
00326     assert( nPats > 0 && nPats < nWords * 8 * (int) sizeof(unsigned) );
00327     // pad the first word
00328     if ( nPats < 8 * sizeof(unsigned) )
00329     {
00330         Vec_PtrForEachEntry( vPats, pInfo, i )
00331             if ( pInfo[0] & 1 )
00332                 pInfo[0] |= ((~0) << nPats);
00333         nPats = 8 * sizeof(unsigned);
00334     }
00335     // pad the empty words
00336     iWords = nPats / (8 * sizeof(unsigned));
00337     Vec_PtrForEachEntry( vPats, pInfo, i )
00338     {
00339         for ( w = iWords; w < nWords; w++ )
00340             pInfo[w] = pInfo[0];
00341     }
00342 }

void Res_SimPerformOne ( Abc_Obj_t pNode,
Vec_Ptr_t vSimInfo,
int  nSimWords 
)

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

Synopsis [Simulates one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 188 of file resSim_old.c.

00189 {
00190     unsigned * pInfo, * pInfo1, * pInfo2;
00191     int k, fComp1, fComp2;
00192     // simulate the internal nodes
00193     assert( Abc_ObjIsNode(pNode) );
00194     pInfo  = Vec_PtrEntry(vSimInfo, pNode->Id);
00195     pInfo1 = Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
00196     pInfo2 = Vec_PtrEntry(vSimInfo, Abc_ObjFaninId1(pNode));
00197     fComp1 = Abc_ObjFaninC0(pNode);
00198     fComp2 = Abc_ObjFaninC1(pNode);
00199     if ( fComp1 && fComp2 )
00200         for ( k = 0; k < nSimWords; k++ )
00201             pInfo[k] = ~pInfo1[k] & ~pInfo2[k];
00202     else if ( fComp1 && !fComp2 )
00203         for ( k = 0; k < nSimWords; k++ )
00204             pInfo[k] = ~pInfo1[k] &  pInfo2[k];
00205     else if ( !fComp1 && fComp2 )
00206         for ( k = 0; k < nSimWords; k++ )
00207             pInfo[k] =  pInfo1[k] & ~pInfo2[k];
00208     else // if ( fComp1 && fComp2 )
00209         for ( k = 0; k < nSimWords; k++ )
00210             pInfo[k] =  pInfo1[k] &  pInfo2[k];
00211 }

void Res_SimPerformRound ( Res_Sim_t p  ) 

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

Synopsis [Performs one round of simulation.]

Description []

SideEffects []

SeeAlso []

Definition at line 252 of file resSim_old.c.

00253 {
00254     Abc_Obj_t * pObj;
00255     int i;
00256     Abc_InfoFill( Vec_PtrEntry(p->vPats,0), p->nWords );
00257     Abc_AigForEachAnd( p->pAig, pObj, i )
00258         Res_SimPerformOne( pObj, p->vPats, p->nWords );
00259     Abc_NtkForEachPo( p->pAig, pObj, i )
00260         Res_SimTransferOne( pObj, p->vPats, p->nWords );
00261 }

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 474 of file resSim_old.c.

00475 {
00476     int Limit;
00477     // prepare the manager
00478     Res_SimAdjust( p, pAig );
00479     // collect 0/1 simulation info
00480     for ( Limit = 0; Limit < 10; Limit++ )
00481     {
00482         Res_SimSetRandom( p );
00483         Res_SimPerformRound( p );
00484         Res_SimProcessPats( p );
00485         if ( !(p->nPats0 < p->nPats || p->nPats1 < p->nPats) )
00486             break;
00487     }
00488 //    printf( "%d   ", Limit );
00489     // report the last set of patterns
00490 //    Res_SimReportOne( p );
00491 //    printf( "\n" );
00492     // quit if there is not enough
00493 //    if ( p->nPats0 < 4 || p->nPats1 < 4 )
00494     if ( p->nPats0 < 4 || p->nPats1 < 4 )
00495     {
00496 //        Res_SimReportOne( p );
00497         return 0;
00498     }
00499     // create bit-matrix info
00500     if ( p->nPats0 < p->nPats )
00501         Res_SimPadSimInfo( p->vPats0, p->nPats0, p->nWords );
00502     if ( p->nPats1 < p->nPats )
00503         Res_SimPadSimInfo( p->vPats1, p->nPats1, p->nWords );
00504     // resimulate 0-patterns
00505     Res_SimSetGiven( p, p->vPats0 );
00506     Res_SimPerformRound( p );
00507     Res_SimDeriveInfoReplicate( p );
00508     // resimulate 1-patterns
00509     Res_SimSetGiven( p, p->vPats1 );
00510     Res_SimPerformRound( p );
00511     Res_SimDeriveInfoComplement( p );
00512     // print output patterns
00513 //    Res_SimPrintOutPatterns( p, pAig );
00514     return 1;
00515 }

void Res_SimPrintOutPatterns ( Res_Sim_t p,
Abc_Ntk_t pAig 
)

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

Synopsis [Prints output patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 450 of file resSim_old.c.

00451 {
00452     Abc_Obj_t * pObj;
00453     unsigned * pInfo2;
00454     int i;
00455     Abc_NtkForEachPo( pAig, pObj, i )
00456     {
00457         pInfo2 = Vec_PtrEntry( p->vOuts, i );
00458         Extra_PrintBinary( stdout, pInfo2, p->nPatsOut );
00459         printf( "\n" );
00460     }
00461 }

void Res_SimProcessPats ( Res_Sim_t p  ) 

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

Synopsis [Processes simulation patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 274 of file resSim_old.c.

00275 {
00276     Abc_Obj_t * pObj;
00277     unsigned * pInfoCare, * pInfoNode;
00278     int i, j, nDcs = 0;
00279     pInfoCare = Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 0)->Id );
00280     pInfoNode = Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 1)->Id );
00281     for ( i = 0; i < p->nPats; i++ )
00282     {
00283         // skip don't-care patterns
00284         if ( !Abc_InfoHasBit(pInfoCare, i) )
00285         {
00286             nDcs++;
00287             continue;
00288         }
00289         // separate offset and onset patterns
00290         if ( !Abc_InfoHasBit(pInfoNode, i) )
00291         {
00292             if ( p->nPats0 >= p->nPats )
00293                 continue;
00294             Abc_NtkForEachPi( p->pAig, pObj, j )
00295                 if ( Abc_InfoHasBit( Vec_PtrEntry(p->vPats, pObj->Id), i ) )
00296                     Abc_InfoSetBit( Vec_PtrEntry(p->vPats0, j), p->nPats0 );
00297             p->nPats0++;
00298         }
00299         else
00300         {
00301             if ( p->nPats1 >= p->nPats )
00302                 continue;
00303             Abc_NtkForEachPi( p->pAig, pObj, j )
00304                 if ( Abc_InfoHasBit( Vec_PtrEntry(p->vPats, pObj->Id), i ) )
00305                     Abc_InfoSetBit( Vec_PtrEntry(p->vPats1, j), p->nPats1 );
00306             p->nPats1++;
00307         }
00308     }
00309 }

void Res_SimReportOne ( Res_Sim_t p  ) 

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

Synopsis [Free simulation engine.]

Description []

SideEffects []

SeeAlso []

Definition at line 408 of file resSim_old.c.

00409 {
00410     unsigned * pInfoCare, * pInfoNode;
00411     int i, nDcs, nOnes, nZeros;
00412     pInfoCare = Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 0)->Id );
00413     pInfoNode = Vec_PtrEntry( p->vPats, Abc_NtkPo(p->pAig, 1)->Id );
00414     nDcs = nOnes = nZeros = 0;
00415     for ( i = 0; i < p->nPats; i++ )
00416     {
00417         // skip don't-care patterns
00418         if ( !Abc_InfoHasBit(pInfoCare, i) )
00419         {
00420             nDcs++;
00421             continue;
00422         }
00423         // separate offset and onset patterns
00424         if ( !Abc_InfoHasBit(pInfoNode, i) )
00425             nZeros++;
00426         else
00427             nOnes++;
00428     }
00429     printf( "On = %3d (%7.2f %%)  ",  nOnes,  100.0*nOnes/p->nPats );
00430     printf( "Off = %3d (%7.2f %%)  ", nZeros, 100.0*nZeros/p->nPats );
00431     printf( "Dc = %3d (%7.2f %%)  ",  nDcs,   100.0*nDcs/p->nPats );
00432     printf( "P0 = %3d ", p->nPats0 );
00433     printf( "P1 = %3d ", p->nPats1 );
00434     if ( p->nPats0 < 4 || p->nPats1 < 4 )
00435         printf( "*" );
00436     printf( "\n" );
00437 }

void Res_SimSetGiven ( Res_Sim_t p,
Vec_Ptr_t vInfo 
)

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

Synopsis [Sets given PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 163 of file resSim_old.c.

00164 {
00165     Abc_Obj_t * pObj;
00166     unsigned * pInfo, * pInfo2;
00167     int i, w;
00168     Abc_NtkForEachPi( p->pAig, pObj, i )
00169     {
00170         pInfo = Vec_PtrEntry( p->vPats, pObj->Id );
00171         pInfo2 = Vec_PtrEntry( vInfo, i );
00172         for ( w = 0; w < p->nWords; w++ )
00173             pInfo[w] = pInfo2[w];
00174     }
00175 }

void Res_SimSetRandom ( Res_Sim_t p  ) 

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

Synopsis [Sets random PI simulation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 140 of file resSim_old.c.

00141 {
00142     Abc_Obj_t * pObj;
00143     unsigned * pInfo;
00144     int i;
00145     Abc_NtkForEachPi( p->pAig, pObj, i )
00146     {
00147         pInfo = Vec_PtrEntry( p->vPats, pObj->Id );
00148         Abc_InfoRandom( pInfo, p->nWords );
00149     }
00150 }

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 224 of file resSim_old.c.

00225 {
00226     unsigned * pInfo, * pInfo1;
00227     int k, fComp1;
00228     // simulate the internal nodes
00229     assert( Abc_ObjIsCo(pNode) );
00230     pInfo  = Vec_PtrEntry(vSimInfo, pNode->Id);
00231     pInfo1 = Vec_PtrEntry(vSimInfo, Abc_ObjFaninId0(pNode));
00232     fComp1 = Abc_ObjFaninC0(pNode);
00233     if ( fComp1 )
00234         for ( k = 0; k < nSimWords; k++ )
00235             pInfo[k] = ~pInfo1[k];
00236     else 
00237         for ( k = 0; k < nSimWords; k++ )
00238             pInfo[k] =  pInfo1[k];
00239 }


Generated on Tue Jan 5 12:19:31 2010 for abc70930 by  doxygen 1.6.1