ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
saigSwitch.c File Reference
#include "saig.h"
#include "base/main/main.h"
Include dependency graph for saigSwitch.c:

Go to the source code of this file.

Classes

struct  Saig_SimObj_t_
 
struct  Aig_CMan_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Saig_SimObj_t_ Saig_SimObj_t
 DECLARATIONS ///.
 
typedef struct Aig_CMan_t_ Aig_CMan_t
 

Functions

Saig_SimObj_tSaig_ManCreateMan (Aig_Man_t *p)
 FUNCTION DEFINITIONS ///.
 
void Saig_ManSimulateFrames (Saig_SimObj_t *pAig, int nFrames, int nPref)
 
float Saig_ManComputeSwitching (int nOnes, int nSimWords)
 
float Saig_ManComputeProbOne (int nOnes, int nSimWords)
 
float Saig_ManComputeProbOnePlus (int nOnes, int nSimWords, int fCompl)
 
Vec_Int_tSaig_ManComputeSwitchProb4s (Aig_Man_t *p, int nFrames, int nPref, int fProbOne)
 
Aig_CMan_tAig_CManStart (int nIns, int nNodes, int nOuts)
 
void Aig_CManStop (Aig_CMan_t *p)
 
void Aig_CManRestart (Aig_CMan_t *p)
 
void Aig_CManStoreNum (Aig_CMan_t *p, unsigned x)
 
int Aig_CManRestoreNum (Aig_CMan_t *p)
 
void Aig_CManAddNode (Aig_CMan_t *p, int iFan0, int iFan1)
 
void Aig_CManAddPo (Aig_CMan_t *p, int iFan0)
 
void Aig_CManGetNode (Aig_CMan_t *p, int *piFan0, int *piFan1)
 
int Aig_CManGetPo (Aig_CMan_t *p)
 
Aig_CMan_tAig_CManCreate (Aig_Man_t *p)
 

Typedef Documentation

◆ Aig_CMan_t

typedef struct Aig_CMan_t_ Aig_CMan_t

Definition at line 331 of file saigSwitch.c.

◆ Saig_SimObj_t

typedef typedefABC_NAMESPACE_IMPL_START struct Saig_SimObj_t_ Saig_SimObj_t

DECLARATIONS ///.

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

FileName [saigSwitch.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Sequential AIG package.]

Synopsis [Returns switching propabilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
saigSwitch.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file saigSwitch.c.

Function Documentation

◆ Aig_CManAddNode()

void Aig_CManAddNode ( Aig_CMan_t * p,
int iFan0,
int iFan1 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 466 of file saigSwitch.c.

467{
468 assert( iFan0 < iFan1 );
469 assert( iFan1 < (p->iNode << 1) );
470 Aig_CManStoreNum( p, (p->iNode++ << 1) - iFan1 );
471 Aig_CManStoreNum( p, iFan1 - iFan0 );
472}
Cube * p
Definition exorList.c:222
void Aig_CManStoreNum(Aig_CMan_t *p, unsigned x)
Definition saigSwitch.c:425
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Aig_CManAddPo()

void Aig_CManAddPo ( Aig_CMan_t * p,
int iFan0 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 485 of file saigSwitch.c.

486{
487 if ( p->iPrev == -1 )
488 Aig_CManStoreNum( p, p->iNode - iFan0 );
489 else if ( p->iPrev <= iFan0 )
490 Aig_CManStoreNum( p, (iFan0 - p->iPrev) << 1 );
491 else
492 Aig_CManStoreNum( p,((p->iPrev - iFan0) << 1) | 1 );
493 p->iPrev = iFan0;
494 p->iNode++;
495}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Aig_CManCreate()

Aig_CMan_t * Aig_CManCreate ( Aig_Man_t * p)

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

Synopsis [Compute switching probabilities of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 547 of file saigSwitch.c.

548{
549 Aig_CMan_t * pCMan;
550 Aig_Obj_t * pObj;
551 int i;
552 pCMan = Aig_CManStart( Aig_ManCiNum(p), Aig_ManNodeNum(p), Aig_ManCoNum(p) );
553 Aig_ManForEachNode( p, pObj, i )
554 Aig_CManAddNode( pCMan,
555 (Aig_ObjFaninId0(pObj) << 1) | Aig_ObjFaninC0(pObj),
556 (Aig_ObjFaninId1(pObj) << 1) | Aig_ObjFaninC1(pObj) );
557 Aig_ManForEachCo( p, pObj, i )
558 Aig_CManAddPo( pCMan,
559 (Aig_ObjFaninId0(pObj) << 1) | Aig_ObjFaninC0(pObj) );
560 printf( "\nBytes alloc = %5d. Bytes used = %7d. Ave per node = %4.2f. \n",
561 pCMan->nBytes, (int)(pCMan->pCur - pCMan->Data),
562 1.0 * (pCMan->pCur - pCMan->Data) / (pCMan->nNodes + pCMan->nOuts ) );
563// Aig_CManStop( pCMan );
564 return pCMan;
565}
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
void Aig_CManAddNode(Aig_CMan_t *p, int iFan0, int iFan1)
Definition saigSwitch.c:466
Aig_CMan_t * Aig_CManStart(int nIns, int nNodes, int nOuts)
Definition saigSwitch.c:361
struct Aig_CMan_t_ Aig_CMan_t
Definition saigSwitch.c:331
void Aig_CManAddPo(Aig_CMan_t *p, int iFan0)
Definition saigSwitch.c:485
unsigned char Data[0]
Definition saigSwitch.c:346
unsigned char * pCur
Definition saigSwitch.c:342
Here is the call graph for this function:

◆ Aig_CManGetNode()

void Aig_CManGetNode ( Aig_CMan_t * p,
int * piFan0,
int * piFan1 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 508 of file saigSwitch.c.

509{
510 *piFan1 = (p->iNode++ << 1) - Aig_CManRestoreNum( p );
511 *piFan0 = *piFan1 - Aig_CManRestoreNum( p );
512}
int Aig_CManRestoreNum(Aig_CMan_t *p)
Definition saigSwitch.c:447
Here is the call graph for this function:

◆ Aig_CManGetPo()

int Aig_CManGetPo ( Aig_CMan_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 525 of file saigSwitch.c.

526{
527 int Num = Aig_CManRestoreNum( p );
528 if ( p->iPrev == -1 )
529 p->iPrev = p->iNode;
530 p->iNode++;
531 if ( Num & 1 )
532 return p->iPrev = p->iPrev + (Num >> 1);
533 return p->iPrev = p->iPrev - (Num >> 1);
534}
Here is the call graph for this function:

◆ Aig_CManRestart()

void Aig_CManRestart ( Aig_CMan_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 405 of file saigSwitch.c.

406{
407 assert( p->iNode == 1 + p->nIns + p->nNodes + p->nOuts );
408 p->iNode = 1 + p->nIns;
409 p->iPrev = -1;
410 p->pCur = p->Data;
411}

◆ Aig_CManRestoreNum()

int Aig_CManRestoreNum ( Aig_CMan_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 447 of file saigSwitch.c.

448{
449 int ch, i, x = 0;
450 for ( i = 0; (ch = *p->pCur++) & 0x80; i++ )
451 x |= (ch & 0x7f) << (7 * i);
452 return x | (ch << (7 * i));
453}
Here is the caller graph for this function:

◆ Aig_CManStart()

Aig_CMan_t * Aig_CManStart ( int nIns,
int nNodes,
int nOuts )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 361 of file saigSwitch.c.

362{
363 Aig_CMan_t * p;
364 p = (Aig_CMan_t *)ABC_ALLOC( char, sizeof(Aig_CMan_t) + 2*(2*nNodes + nOuts) );
365 memset( p, 0, sizeof(Aig_CMan_t) );
366 // set parameters
367 p->nIns = nIns;
368 p->nOuts = nOuts;
369 p->nNodes = nNodes;
370 p->nBytes = 2*(2*nNodes + nOuts);
371 // prepare the manager
372 p->iNode = 1 + p->nIns;
373 p->iPrev = -1;
374 p->pCur = p->Data;
375 return p;
376}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Aig_CManStop()

void Aig_CManStop ( Aig_CMan_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 389 of file saigSwitch.c.

390{
391 ABC_FREE( p );
392}
#define ABC_FREE(obj)
Definition abc_global.h:267

◆ Aig_CManStoreNum()

void Aig_CManStoreNum ( Aig_CMan_t * p,
unsigned x )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 425 of file saigSwitch.c.

426{
427 while ( x & ~0x7f )
428 {
429 *p->pCur++ = (x & 0x7f) | 0x80;
430 x >>= 7;
431 }
432 *p->pCur++ = x;
433 assert( p->pCur - p->Data < p->nBytes - 10 );
434}
Here is the caller graph for this function:

◆ Saig_ManComputeProbOne()

float Saig_ManComputeProbOne ( int nOnes,
int nSimWords )

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

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 229 of file saigSwitch.c.

230{
231 int nTotal = 32 * nSimWords;
232 return (float)nOnes / nTotal;
233}
int nTotal
DECLARATIONS ///.
Definition cutTruth.c:37
Here is the caller graph for this function:

◆ Saig_ManComputeProbOnePlus()

float Saig_ManComputeProbOnePlus ( int nOnes,
int nSimWords,
int fCompl )

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

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 246 of file saigSwitch.c.

247{
248 int nTotal = 32 * nSimWords;
249 if ( fCompl )
250 return (float)(nTotal-nOnes) / nTotal;
251 else
252 return (float)nOnes / nTotal;
253}

◆ Saig_ManComputeSwitching()

float Saig_ManComputeSwitching ( int nOnes,
int nSimWords )

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

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 212 of file saigSwitch.c.

213{
214 int nTotal = 32 * nSimWords;
215 return (float)2.0 * nOnes / nTotal * (nTotal - nOnes) / nTotal;
216}
Here is the caller graph for this function:

◆ Saig_ManComputeSwitchProb4s()

Vec_Int_t * Saig_ManComputeSwitchProb4s ( Aig_Man_t * p,
int nFrames,
int nPref,
int fProbOne )

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

Synopsis [Compute switching probabilities of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 266 of file saigSwitch.c.

267{
268 Saig_SimObj_t * pAig, * pEntry;
269 Vec_Int_t * vSwitching;
270 float * pSwitching;
271 int nFramesReal;
272 abctime clk;//, clkTotal = Abc_Clock();
273 vSwitching = Vec_IntStart( Aig_ManObjNumMax(p) );
274 pSwitching = (float *)vSwitching->pArray;
275clk = Abc_Clock();
276 pAig = Saig_ManCreateMan( p );
277//ABC_PRT( "\nCreation ", Abc_Clock() - clk );
278
279 Aig_ManRandom( 1 );
280 // get the number of frames to simulate
281 // if the parameter "seqsimframes" is defined, use it
282 // otherwise, use the given number of frames "nFrames"
283 nFramesReal = nFrames;
284 if ( Abc_FrameReadFlag("seqsimframes") )
285 nFramesReal = atoi( Abc_FrameReadFlag("seqsimframes") );
286 if ( nFramesReal <= nPref )
287 {
288 printf( "The total number of frames (%d) should exceed prefix (%d).\n", nFramesReal, nPref );\
289 printf( "Setting the total number of frames to be %d.\n", nFrames );
290 nFramesReal = nFrames;
291 }
292//printf( "Simulating %d frames.\n", nFramesReal );
293clk = Abc_Clock();
294 Saig_ManSimulateFrames( pAig, nFramesReal, nPref );
295//ABC_PRT( "Simulation", Abc_Clock() - clk );
296clk = Abc_Clock();
297 for ( pEntry = pAig; pEntry->Type != AIG_OBJ_VOID; pEntry++ )
298 {
299/*
300 if ( pEntry->Type == AIG_OBJ_AND )
301 {
302 Saig_SimObj_t * pObj0 = pAig + Saig_SimObjFanin0( pEntry );
303 Saig_SimObj_t * pObj1 = pAig + Saig_SimObjFanin1( pEntry );
304 printf( "%5.2f = %5.2f * %5.2f (%7.4f)\n",
305 Saig_ManComputeProbOnePlus( pEntry->Number, nFrames - nPref, 0 ),
306 Saig_ManComputeProbOnePlus( pObj0->Number, nFrames - nPref, Saig_SimObjFaninC0(pEntry) ),
307 Saig_ManComputeProbOnePlus( pObj1->Number, nFrames - nPref, Saig_SimObjFaninC1(pEntry) ),
308 Saig_ManComputeProbOnePlus( pEntry->Number, nFrames - nPref, 0 ) -
309 Saig_ManComputeProbOnePlus( pObj0->Number, nFrames - nPref, Saig_SimObjFaninC0(pEntry) ) *
310 Saig_ManComputeProbOnePlus( pObj1->Number, nFrames - nPref, Saig_SimObjFaninC1(pEntry) )
311 );
312 }
313*/
314 if ( fProbOne )
315 pSwitching[pEntry-pAig] = Saig_ManComputeProbOne( pEntry->Number, nFramesReal - nPref );
316 else
317 pSwitching[pEntry-pAig] = Saig_ManComputeSwitching( pEntry->Number, nFramesReal - nPref );
318//printf( "%3d : %7.2f\n", pEntry-pAig, pSwitching[pEntry-pAig] );
319 }
320 ABC_FREE( pAig );
321//ABC_PRT( "Switch ", Abc_Clock() - clk );
322//ABC_PRT( "TOTAL ", Abc_Clock() - clkTotal );
323
324// Aig_CManCreate( p );
325 return vSwitching;
326}
ABC_INT64_T abctime
Definition abc_global.h:332
@ AIG_OBJ_VOID
Definition aig.h:65
unsigned Aig_ManRandom(int fReset)
Definition aigUtil.c:1170
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition mainFrame.c:69
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
typedefABC_NAMESPACE_IMPL_START struct Saig_SimObj_t_ Saig_SimObj_t
DECLARATIONS ///.
Definition saigSwitch.c:32
Saig_SimObj_t * Saig_ManCreateMan(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition saigSwitch.c:66
float Saig_ManComputeProbOne(int nOnes, int nSimWords)
Definition saigSwitch.c:229
float Saig_ManComputeSwitching(int nOnes, int nSimWords)
Definition saigSwitch.c:212
void Saig_ManSimulateFrames(Saig_SimObj_t *pAig, int nFrames, int nPref)
Definition saigSwitch.c:172
Here is the call graph for this function:

◆ Saig_ManCreateMan()

Saig_SimObj_t * Saig_ManCreateMan ( Aig_Man_t * p)

FUNCTION DEFINITIONS ///.

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

Synopsis [Creates fast simulation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 66 of file saigSwitch.c.

67{
68 Saig_SimObj_t * pAig, * pEntry;
69 Aig_Obj_t * pObj;
70 int i;
71 pAig = ABC_CALLOC( Saig_SimObj_t, Aig_ManObjNumMax(p)+1 );
72// printf( "Allocating %7.2f MB.\n", 1.0 * sizeof(Saig_SimObj_t) * (Aig_ManObjNumMax(p)+1)/(1<<20) );
73 Aig_ManForEachObj( p, pObj, i )
74 {
75 pEntry = pAig + i;
76 pEntry->Type = pObj->Type;
77 if ( Aig_ObjIsCi(pObj) || i == 0 )
78 {
79 if ( Saig_ObjIsLo(p, pObj) )
80 {
81 pEntry->iFan0 = (Saig_ObjLoToLi(p, pObj)->Id << 1);
82 pEntry->iFan1 = -1;
83 }
84 continue;
85 }
86 pEntry->iFan0 = (Aig_ObjFaninId0(pObj) << 1) | Aig_ObjFaninC0(pObj);
87 if ( Aig_ObjIsCo(pObj) )
88 continue;
89 assert( Aig_ObjIsNode(pObj) );
90 pEntry->iFan1 = (Aig_ObjFaninId1(pObj) << 1) | Aig_ObjFaninC1(pObj);
91 }
92 pEntry = pAig + Aig_ManObjNumMax(p);
93 pEntry->Type = AIG_OBJ_VOID;
94 return pAig;
95}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
unsigned int Type
Definition aig.h:77
Here is the caller graph for this function:

◆ Saig_ManSimulateFrames()

void Saig_ManSimulateFrames ( Saig_SimObj_t * pAig,
int nFrames,
int nPref )

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

Synopsis [Simulates the timeframes.]

Description []

SideEffects []

SeeAlso []

Definition at line 172 of file saigSwitch.c.

173{
174 Saig_SimObj_t * pEntry;
175 int f;
176 for ( f = 0; f < nFrames; f++ )
177 {
178 for ( pEntry = pAig; pEntry->Type != AIG_OBJ_VOID; pEntry++ )
179 {
180 if ( pEntry->Type == AIG_OBJ_AND )
181 Saig_ManSimulateNode( pAig, pEntry );
182 else if ( pEntry->Type == AIG_OBJ_CO )
183 Saig_ManSimulateOneInput( pAig, pEntry );
184 else if ( pEntry->Type == AIG_OBJ_CI )
185 {
186 if ( pEntry->iFan0 == 0 ) // true PI
187 pEntry->pData[0] = Aig_ManRandom( 0 );
188 else if ( f > 0 ) // register output
189 Saig_ManSimulateOneInput( pAig, pEntry );
190 }
191 else if ( pEntry->Type == AIG_OBJ_CONST1 )
192 pEntry->pData[0] = ~0;
193 else if ( pEntry->Type != AIG_OBJ_NONE )
194 assert( 0 );
195 if ( f >= nPref )
196 pEntry->Number += Aig_WordCountOnes( pEntry->pData[0] );
197 }
198 }
199}
@ AIG_OBJ_CO
Definition aig.h:61
@ AIG_OBJ_AND
Definition aig.h:63
@ AIG_OBJ_NONE
Definition aig.h:58
@ AIG_OBJ_CI
Definition aig.h:60
@ AIG_OBJ_CONST1
Definition aig.h:59
Here is the call graph for this function:
Here is the caller graph for this function: