src/map/if/if.h File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "vec.h"
#include "mem.h"
Include dependency graph for if.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  If_Par_t_
struct  If_Lib_t_
struct  If_Man_t_
struct  If_Cut_t_
struct  If_Set_t_
struct  If_Obj_t_

Defines

#define IF_MAX_LUTSIZE   32
#define IF_MAX_FUNC_LUTSIZE   15
#define IF_INFINITY   100000000
#define IF_COST_MAX   ((1<<14)-1)
#define IF_MIN(a, b)   (((a) < (b))? (a) : (b))
#define IF_MAX(a, b)   (((a) > (b))? (a) : (b))
#define IF_FLOAT_LARGE   ((float)1.0e+20)
#define IF_FLOAT_SMALL   ((float)1.0e-20)
#define IF_INT_LARGE   (10000000)
#define If_ManForEachCi(p, pObj, i)   Vec_PtrForEachEntry( p->vCis, pObj, i )
#define If_ManForEachCo(p, pObj, i)   Vec_PtrForEachEntry( p->vCos, pObj, i )
#define If_ManForEachPi(p, pObj, i)   Vec_PtrForEachEntryStop( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )
#define If_ManForEachPo(p, pObj, i)   Vec_PtrForEachEntryStop( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )
#define If_ManForEachLatchInput(p, pObj, i)   Vec_PtrForEachEntryStart( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )
#define If_ManForEachLatchOutput(p, pObj, i)   Vec_PtrForEachEntryStart( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )
#define If_ManForEachObj(p, pObj, i)   Vec_PtrForEachEntry( p->vObjs, pObj, i )
#define If_ManForEachNode(p, pObj, i)   If_ManForEachObj( p, pObj, i ) if ( pObj->Type != IF_AND ) {} else
#define If_ObjForEachCut(pObj, pCut, i)   for ( i = 0; (i < (pObj)->pCutSet->nCuts) && ((pCut) = (pObj)->pCutSet->ppCuts[i]); i++ )
#define If_CutForEachLeaf(p, pCut, pLeaf, i)   for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i++ )
#define If_CutForEachLeafReverse(p, pCut, pLeaf, i)   for ( i = (int)(pCut)->nLeaves - 1; (i >= 0) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i-- )
#define If_CutForEachLeafSeq(p, pCut, pLeaf, Shift, i)   for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i] >> 8)) && (((Shift) = ((pCut)->pLeaves[i] & 255)) >= 0); i++ )

Typedefs

typedef struct If_Man_t_ If_Man_t
typedef struct If_Par_t_ If_Par_t
typedef struct If_Lib_t_ If_Lib_t
typedef struct If_Obj_t_ If_Obj_t
typedef struct If_Cut_t_ If_Cut_t
typedef struct If_Set_t_ If_Set_t

Enumerations

enum  If_Type_t {
  IF_NONE, IF_CONST1, IF_CI, IF_CO,
  IF_AND, IF_VOID
}

Functions

static If_Obj_tIf_Regular (If_Obj_t *p)
static If_Obj_tIf_Not (If_Obj_t *p)
static If_Obj_tIf_NotCond (If_Obj_t *p, int c)
static int If_IsComplement (If_Obj_t *p)
static int If_ManCiNum (If_Man_t *p)
static int If_ManCoNum (If_Man_t *p)
static int If_ManAndNum (If_Man_t *p)
static int If_ManObjNum (If_Man_t *p)
static If_Obj_tIf_ManConst1 (If_Man_t *p)
static If_Obj_tIf_ManCi (If_Man_t *p, int i)
static If_Obj_tIf_ManCo (If_Man_t *p, int i)
static If_Obj_tIf_ManLi (If_Man_t *p, int i)
static If_Obj_tIf_ManLo (If_Man_t *p, int i)
static If_Obj_tIf_ManObj (If_Man_t *p, int i)
static int If_ObjIsConst1 (If_Obj_t *pObj)
static int If_ObjIsCi (If_Obj_t *pObj)
static int If_ObjIsCo (If_Obj_t *pObj)
static int If_ObjIsPi (If_Obj_t *pObj)
static int If_ObjIsLatch (If_Obj_t *pObj)
static int If_ObjIsAnd (If_Obj_t *pObj)
static If_Obj_tIf_ObjFanin0 (If_Obj_t *pObj)
static If_Obj_tIf_ObjFanin1 (If_Obj_t *pObj)
static int If_ObjFaninC0 (If_Obj_t *pObj)
static int If_ObjFaninC1 (If_Obj_t *pObj)
static void * If_ObjCopy (If_Obj_t *pObj)
static void If_ObjSetCopy (If_Obj_t *pObj, void *pCopy)
static void If_ObjSetChoice (If_Obj_t *pObj, If_Obj_t *pEqu)
static If_Cut_tIf_ObjCutBest (If_Obj_t *pObj)
static unsigned If_ObjCutSign (unsigned ObjId)
static float If_ObjArrTime (If_Obj_t *pObj)
static void If_ObjSetArrTime (If_Obj_t *pObj, float ArrTime)
static float If_ObjLValue (If_Obj_t *pObj)
static void If_ObjSetLValue (If_Obj_t *pObj, float LValue)
static void * If_CutData (If_Cut_t *pCut)
static void If_CutSetData (If_Cut_t *pCut, void *pData)
static int If_CutLeaveNum (If_Cut_t *pCut)
static unsigned * If_CutTruth (If_Cut_t *pCut)
static int If_CutTruthWords (int nVarsMax)
static int If_CutPermWords (int nVarsMax)
static float If_CutLutArea (If_Man_t *p, If_Cut_t *pCut)
int If_ManPerformMapping (If_Man_t *p)
int If_ManPerformMappingComb (If_Man_t *p)
float If_CutAreaDerefed (If_Man_t *p, If_Cut_t *pCut, int nLevels)
float If_CutAreaRefed (If_Man_t *p, If_Cut_t *pCut, int nLevels)
float If_CutDeref (If_Man_t *p, If_Cut_t *pCut, int nLevels)
float If_CutRef (If_Man_t *p, If_Cut_t *pCut, int nLevels)
void If_CutPrint (If_Man_t *p, If_Cut_t *pCut)
void If_CutPrintTiming (If_Man_t *p, If_Cut_t *pCut)
float If_CutFlow (If_Man_t *p, If_Cut_t *pCut)
float If_CutAverageRefs (If_Man_t *p, If_Cut_t *pCut)
int If_CutFilter (If_Set_t *pCutSet, If_Cut_t *pCut)
void If_CutSort (If_Man_t *p, If_Set_t *pCutSet, If_Cut_t *pCut)
int If_CutMerge (If_Cut_t *pCut0, If_Cut_t *pCut1, If_Cut_t *pCut)
void If_CutLift (If_Cut_t *pCut)
void If_CutCopy (If_Man_t *p, If_Cut_t *pCutDest, If_Cut_t *pCutSrc)
void If_ManSortCuts (If_Man_t *p, int Mode)
If_Man_tIf_ManStart (If_Par_t *pPars)
void If_ManRestart (If_Man_t *p)
void If_ManStop (If_Man_t *p)
If_Obj_tIf_ManCreateCi (If_Man_t *p)
If_Obj_tIf_ManCreateCo (If_Man_t *p, If_Obj_t *pDriver)
If_Obj_tIf_ManCreateAnd (If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
If_Obj_tIf_ManCreateXor (If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
If_Obj_tIf_ManCreateMux (If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1, If_Obj_t *pCtrl)
void If_ManCreateChoice (If_Man_t *p, If_Obj_t *pRepr)
void If_ManSetupCutTriv (If_Man_t *p, If_Cut_t *pCut, int ObjId)
void If_ManSetupCiCutSets (If_Man_t *p)
If_Set_tIf_ManSetupNodeCutSet (If_Man_t *p, If_Obj_t *pObj)
void If_ManDerefNodeCutSet (If_Man_t *p, If_Obj_t *pObj)
void If_ManDerefChoiceCutSet (If_Man_t *p, If_Obj_t *pObj)
void If_ManSetupSetAll (If_Man_t *p, int nCrossCut)
void If_ObjPerformMappingAnd (If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess)
void If_ObjPerformMappingChoice (If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess)
int If_ManPerformMappingRound (If_Man_t *p, int nCutsUsed, int Mode, int fPreprocess, char *pLabel)
void If_ManImproveMapping (If_Man_t *p)
int If_ManPerformMappingSeq (If_Man_t *p)
float If_CutDelay (If_Man_t *p, If_Cut_t *pCut)
void If_CutPropagateRequired (If_Man_t *p, If_Cut_t *pCut, float Required)
void If_CutComputeTruth (If_Man_t *p, If_Cut_t *pCut, If_Cut_t *pCut0, If_Cut_t *pCut1, int fCompl0, int fCompl1)
void If_ManCleanNodeCopy (If_Man_t *p)
void If_ManCleanCutData (If_Man_t *p)
void If_ManCleanMarkV (If_Man_t *p)
float If_ManDelayMax (If_Man_t *p, int fSeq)
void If_ManComputeRequired (If_Man_t *p)
float If_ManScanMapping (If_Man_t *p)
float If_ManScanMappingSeq (If_Man_t *p)
void If_ManResetOriginalRefs (If_Man_t *p)
int If_ManCrossCut (If_Man_t *p)

Define Documentation

#define IF_COST_MAX   ((1<<14)-1)

Definition at line 51 of file if.h.

#define If_CutForEachLeaf ( p,
pCut,
pLeaf,
 )     for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i++ )

Definition at line 305 of file if.h.

#define If_CutForEachLeafReverse ( p,
pCut,
pLeaf,
 )     for ( i = (int)(pCut)->nLeaves - 1; (i >= 0) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i-- )

Definition at line 307 of file if.h.

#define If_CutForEachLeafSeq ( p,
pCut,
pLeaf,
Shift,
 )     for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i] >> 8)) && (((Shift) = ((pCut)->pLeaves[i] & 255)) >= 0); i++ )

Definition at line 312 of file if.h.

#define IF_FLOAT_LARGE   ((float)1.0e+20)

Definition at line 274 of file if.h.

#define IF_FLOAT_SMALL   ((float)1.0e-20)

Definition at line 275 of file if.h.

#define IF_INFINITY   100000000

Definition at line 49 of file if.h.

#define IF_INT_LARGE   (10000000)

Definition at line 276 of file if.h.

#define If_ManForEachCi ( p,
pObj,
 )     Vec_PtrForEachEntry( p->vCis, pObj, i )

Definition at line 279 of file if.h.

#define If_ManForEachCo ( p,
pObj,
 )     Vec_PtrForEachEntry( p->vCos, pObj, i )

Definition at line 282 of file if.h.

#define If_ManForEachLatchInput ( p,
pObj,
 )     Vec_PtrForEachEntryStart( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )

Definition at line 291 of file if.h.

#define If_ManForEachLatchOutput ( p,
pObj,
 )     Vec_PtrForEachEntryStart( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )

Definition at line 293 of file if.h.

#define If_ManForEachNode ( p,
pObj,
 )     If_ManForEachObj( p, pObj, i ) if ( pObj->Type != IF_AND ) {} else

Definition at line 299 of file if.h.

#define If_ManForEachObj ( p,
pObj,
 )     Vec_PtrForEachEntry( p->vObjs, pObj, i )

Definition at line 296 of file if.h.

#define If_ManForEachPi ( p,
pObj,
 )     Vec_PtrForEachEntryStop( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )

Definition at line 285 of file if.h.

#define If_ManForEachPo ( p,
pObj,
 )     Vec_PtrForEachEntryStop( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )

Definition at line 288 of file if.h.

#define IF_MAX ( a,
 )     (((a) > (b))? (a) : (b))

Definition at line 271 of file if.h.

#define IF_MAX_FUNC_LUTSIZE   15

Definition at line 47 of file if.h.

#define IF_MAX_LUTSIZE   32

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

FileName [if.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [FPGA mapping based on priority cuts.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - November 21, 2006.]

Revision [

Id
if.h,v 1.00 2006/11/21 00:00:00 alanmi Exp

] INCLUDES /// PARAMETERS ///

Definition at line 45 of file if.h.

#define IF_MIN ( a,
 )     (((a) < (b))? (a) : (b))

MACRO DEFINITIONS ///

Definition at line 270 of file if.h.

#define If_ObjForEachCut ( pObj,
pCut,
 )     for ( i = 0; (i < (pObj)->pCutSet->nCuts) && ((pCut) = (pObj)->pCutSet->ppCuts[i]); i++ )

Definition at line 302 of file if.h.


Typedef Documentation

typedef struct If_Cut_t_ If_Cut_t

Definition at line 71 of file if.h.

typedef struct If_Lib_t_ If_Lib_t

Definition at line 69 of file if.h.

typedef struct If_Man_t_ If_Man_t

BASIC TYPES ///

Definition at line 67 of file if.h.

typedef struct If_Obj_t_ If_Obj_t

Definition at line 70 of file if.h.

typedef struct If_Par_t_ If_Par_t

Definition at line 68 of file if.h.

typedef struct If_Set_t_ If_Set_t

Definition at line 72 of file if.h.


Enumeration Type Documentation

enum If_Type_t
Enumerator:
IF_NONE 
IF_CONST1 
IF_CI 
IF_CO 
IF_AND 
IF_VOID 

Definition at line 54 of file if.h.

00054              { 
00055     IF_NONE,     // 0: non-existent object
00056     IF_CONST1,   // 1: constant 1 
00057     IF_CI,       // 2: combinational input
00058     IF_CO,       // 3: combinational output
00059     IF_AND,      // 4: AND node
00060     IF_VOID      // 5: unused object
00061 } If_Type_t;


Function Documentation

float If_CutAreaDerefed ( If_Man_t p,
If_Cut_t pCut,
int  nLevels 
)

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

Synopsis [Computes area of the first level.]

Description [The cut need to be derefed.]

SideEffects []

SeeAlso []

Definition at line 691 of file ifCut.c.

00692 {
00693     float aResult, aResult2;
00694     assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00695     aResult2 = If_CutRef( p, pCut, nLevels );
00696     aResult  = If_CutDeref( p, pCut, nLevels );
00697     assert( aResult > aResult2 - p->fEpsilon );
00698     assert( aResult < aResult2 + p->fEpsilon );
00699     return aResult;
00700 }

float If_CutAreaRefed ( If_Man_t p,
If_Cut_t pCut,
int  nLevels 
)

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

Synopsis [Computes area of the first level.]

Description [The cut need to be derefed.]

SideEffects []

SeeAlso []

Definition at line 713 of file ifCut.c.

00714 {
00715     float aResult, aResult2;
00716     assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00717     aResult2 = If_CutDeref( p, pCut, nLevels );
00718     aResult  = If_CutRef( p, pCut, nLevels );
00719     assert( aResult > aResult2 - p->fEpsilon );
00720     assert( aResult < aResult2 + p->fEpsilon );
00721     return aResult;
00722 }

float If_CutAverageRefs ( If_Man_t p,
If_Cut_t pCut 
)

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

Synopsis [Average number of references of the leaves.]

Description []

SideEffects []

SeeAlso []

Definition at line 574 of file ifCut.c.

00575 {
00576     If_Obj_t * pLeaf;
00577     int nRefsTotal, i;
00578     assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00579     nRefsTotal = 0;
00580     If_CutForEachLeaf( p, pCut, pLeaf, i )
00581         nRefsTotal += pLeaf->nRefs;
00582     return ((float)nRefsTotal)/pCut->nLeaves;
00583 }

void If_CutComputeTruth ( If_Man_t p,
If_Cut_t pCut,
If_Cut_t pCut0,
If_Cut_t pCut1,
int  fCompl0,
int  fCompl1 
)

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

Synopsis [Performs truth table computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 198 of file ifTruth.c.

00199 {
00200     extern void Kit_FactorTest( unsigned * pTruth, int nVars );
00201 
00202     // permute the first table
00203     if ( fCompl0 ^ pCut0->fCompl ) 
00204         If_TruthNot( p->puTemp[0], If_CutTruth(pCut0), pCut->nLimit );
00205     else
00206         If_TruthCopy( p->puTemp[0], If_CutTruth(pCut0), pCut->nLimit );
00207     If_TruthStretch( p->puTemp[2], p->puTemp[0], pCut0->nLeaves, pCut->nLimit, If_CutTruthPhase(pCut, pCut0) );
00208     // permute the second table
00209     if ( fCompl1 ^ pCut1->fCompl ) 
00210         If_TruthNot( p->puTemp[1], If_CutTruth(pCut1), pCut->nLimit );
00211     else
00212         If_TruthCopy( p->puTemp[1], If_CutTruth(pCut1), pCut->nLimit );
00213     If_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nLeaves, pCut->nLimit, If_CutTruthPhase(pCut, pCut1) );
00214     // produce the resulting table
00215     assert( pCut->fCompl == 0 );
00216     if ( pCut->fCompl )
00217         If_TruthNand( If_CutTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nLimit );
00218     else
00219         If_TruthAnd( If_CutTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nLimit );
00220 
00221     // perform 
00222 //    Kit_FactorTest( If_CutTruth(pCut), pCut->nLimit );
00223 //    printf( "%d ", If_CutLeaveNum(pCut) - Kit_TruthSupportSize(If_CutTruth(pCut), If_CutLeaveNum(pCut)) );
00224 }

void If_CutCopy ( If_Man_t p,
If_Cut_t pCutDest,
If_Cut_t pCutSrc 
)

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

Synopsis [Computes area of the first level.]

Description [The cut need to be derefed.]

SideEffects []

SeeAlso []

Definition at line 756 of file ifCut.c.

00757 {
00758     int * pLeaves;
00759     char * pPerm;
00760     unsigned * pTruth;
00761     // save old arrays
00762     pLeaves = pCutDest->pLeaves;
00763     pPerm   = pCutDest->pPerm;
00764     pTruth  = pCutDest->pTruth;
00765     // copy the cut info
00766     memcpy( pCutDest, pCutSrc, p->nCutBytes );
00767     // restore the arrays
00768     pCutDest->pLeaves = pLeaves;
00769     pCutDest->pPerm   = pPerm;
00770     pCutDest->pTruth  = pTruth;
00771 }

static void* If_CutData ( If_Cut_t pCut  )  [inline, static]

Definition at line 256 of file if.h.

00256 { return *(void **)pCut;                }

float If_CutDelay ( If_Man_t p,
If_Cut_t pCut 
)

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Computes delay.]

Description []

SideEffects []

SeeAlso []

Definition at line 44 of file ifTime.c.

00045 {
00046     static int pPinPerm[IF_MAX_LUTSIZE];
00047     static float pPinDelays[IF_MAX_LUTSIZE];
00048     If_Obj_t * pLeaf;
00049     float Delay, DelayCur;
00050     float * pLutDelays;
00051     int i, Shift;
00052     assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00053     Delay = -IF_FLOAT_LARGE;
00054     if ( p->pPars->pLutLib )
00055     {
00056         assert( !p->pPars->fLiftLeaves );
00057         pLutDelays = p->pPars->pLutLib->pLutDelays[pCut->nLeaves];
00058         if ( p->pPars->pLutLib->fVarPinDelays )
00059         {
00060             // compute the delay using sorted pins
00061             If_CutSortInputPins( p, pCut, pPinPerm, pPinDelays );
00062             for ( i = 0; i < (int)pCut->nLeaves; i++ )
00063             {
00064                 DelayCur = pPinDelays[pPinPerm[i]] + pLutDelays[i];
00065                 Delay = IF_MAX( Delay, DelayCur );
00066             }
00067         }
00068         else
00069         {
00070             If_CutForEachLeaf( p, pCut, pLeaf, i )
00071             {
00072                 DelayCur = If_ObjCutBest(pLeaf)->Delay + pLutDelays[0];
00073                 Delay = IF_MAX( Delay, DelayCur );
00074             }
00075         }
00076     }
00077     else
00078     {
00079         if ( pCut->fUser )
00080         {
00081             assert( !p->pPars->fLiftLeaves );
00082             If_CutForEachLeaf( p, pCut, pLeaf, i )
00083             {
00084                 DelayCur = If_ObjCutBest(pLeaf)->Delay + (float)pCut->pPerm[i];
00085                 Delay = IF_MAX( Delay, DelayCur );
00086             }
00087         }
00088         else
00089         {
00090             if ( p->pPars->fLiftLeaves )
00091             {
00092                 If_CutForEachLeafSeq( p, pCut, pLeaf, Shift, i )
00093                 {
00094                     DelayCur = If_ObjCutBest(pLeaf)->Delay - Shift * p->Period;
00095                     Delay = IF_MAX( Delay, DelayCur );
00096                 }
00097             }
00098             else
00099             {
00100                 If_CutForEachLeaf( p, pCut, pLeaf, i )
00101                 {
00102                     DelayCur = If_ObjCutBest(pLeaf)->Delay;
00103                     Delay = IF_MAX( Delay, DelayCur );
00104                 }
00105             }
00106             Delay += 1.0;
00107         }
00108     }
00109     return Delay;
00110 }

float If_CutDeref ( If_Man_t p,
If_Cut_t pCut,
int  nLevels 
)

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

Synopsis [Computes area of the first level.]

Description [The cut need to be derefed.]

SideEffects []

SeeAlso []

Definition at line 596 of file ifCut.c.

00597 {
00598     If_Obj_t * pLeaf;
00599     float Area;
00600     int i;
00601     Area = If_CutLutArea(p, pCut);
00602     If_CutForEachLeaf( p, pCut, pLeaf, i )
00603     {
00604         assert( pLeaf->nRefs > 0 );
00605         if ( --pLeaf->nRefs > 0 || !If_ObjIsAnd(pLeaf) || nLevels == 1 )
00606             continue;
00607         Area += If_CutDeref( p, If_ObjCutBest(pLeaf), nLevels - 1 );
00608     }
00609     return Area;
00610 }

int If_CutFilter ( If_Set_t pCutSet,
If_Cut_t pCut 
)

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

Synopsis [Returns 1 if the cut is contained.]

Description []

SideEffects []

SeeAlso []

Definition at line 91 of file ifCut.c.

00092 { 
00093     If_Cut_t * pTemp;
00094     int i, k;
00095     assert( pCutSet->ppCuts[pCutSet->nCuts] == pCut );
00096     for ( i = 0; i < pCutSet->nCuts; i++ )
00097     {
00098         pTemp = pCutSet->ppCuts[i];
00099         if ( pTemp->nLeaves > pCut->nLeaves )
00100         {
00101             // do not fiter the first cut
00102             if ( i == 0 )
00103                 continue;
00104             // skip the non-contained cuts
00105             if ( (pTemp->uSign & pCut->uSign) != pCut->uSign )
00106                 continue;
00107             // check containment seriously
00108             if ( If_CutCheckDominance( pCut, pTemp ) )
00109             {
00110 //                p->ppCuts[i] = p->ppCuts[p->nCuts-1];
00111 //                p->ppCuts[p->nCuts-1] = pTemp;
00112 //                p->nCuts--;
00113 //                i--;
00114                 // remove contained cut
00115                 for ( k = i; k < pCutSet->nCuts; k++ )
00116                     pCutSet->ppCuts[k] = pCutSet->ppCuts[k+1];
00117                 pCutSet->ppCuts[pCutSet->nCuts] = pTemp;
00118                 pCutSet->nCuts--;
00119                 i--;
00120             }
00121          }
00122         else
00123         {
00124             // skip the non-contained cuts
00125             if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign )
00126                 continue;
00127             // check containment seriously
00128             if ( If_CutCheckDominance( pTemp, pCut ) )
00129                 return 1;
00130         }
00131     }
00132     return 0;
00133 }

float If_CutFlow ( If_Man_t p,
If_Cut_t pCut 
)

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

Synopsis [Computes area flow.]

Description []

SideEffects []

SeeAlso []

Definition at line 541 of file ifCut.c.

00542 {
00543     If_Obj_t * pLeaf;
00544     float Flow;
00545     int i;
00546     assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00547     Flow = If_CutLutArea(p, pCut);
00548     If_CutForEachLeaf( p, pCut, pLeaf, i )
00549     {
00550         if ( pLeaf->nRefs == 0 )
00551             Flow += If_ObjCutBest(pLeaf)->Area;
00552         else if ( p->pPars->fSeqMap ) // seq
00553             Flow += If_ObjCutBest(pLeaf)->Area / pLeaf->nRefs;
00554         else 
00555         {
00556             assert( pLeaf->EstRefs > p->fEpsilon );
00557             Flow += If_ObjCutBest(pLeaf)->Area / pLeaf->EstRefs;
00558         }
00559     }
00560     return Flow;
00561 }

static int If_CutLeaveNum ( If_Cut_t pCut  )  [inline, static]

Definition at line 259 of file if.h.

00259 { return pCut->nLeaves;                             }

void If_CutLift ( If_Cut_t pCut  ) 

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

Synopsis [Moves the cut over the latch.]

Description []

SideEffects []

SeeAlso []

Definition at line 735 of file ifCut.c.

00736 {
00737     unsigned i;
00738     for ( i = 0; i < pCut->nLeaves; i++ )
00739     {
00740         assert( (pCut->pLeaves[i] & 255) < 255 );
00741         pCut->pLeaves[i]++;
00742     }
00743 }

static float If_CutLutArea ( If_Man_t p,
If_Cut_t pCut 
) [inline, static]

Definition at line 264 of file if.h.

00264 { return pCut->fUser? (float)pCut->Cost : (p->pPars->pLutLib? p->pPars->pLutLib->pLutAreas[pCut->nLeaves] : (float)1.0); }

int If_CutMerge ( If_Cut_t pCut0,
If_Cut_t pCut1,
If_Cut_t pCut 
)

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

Synopsis [Prepares the object for FPGA mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 286 of file ifCut.c.

00287 { 
00288     assert( pCut->nLimit > 0 );
00289     // merge the nodes
00290     if ( pCut0->nLeaves < pCut1->nLeaves )
00291     {
00292         if ( !If_CutMergeOrdered( pCut1, pCut0, pCut ) )
00293             return 0;
00294     }
00295     else
00296     {
00297         if ( !If_CutMergeOrdered( pCut0, pCut1, pCut ) )
00298             return 0;
00299     }
00300     pCut->uSign = pCut0->uSign | pCut1->uSign;
00301     return 1;
00302 }

static int If_CutPermWords ( int  nVarsMax  )  [inline, static]

Definition at line 262 of file if.h.

00262 { return nVarsMax / sizeof(int) + ((nVarsMax % sizeof(int)) > 0); }

void If_CutPrint ( If_Man_t p,
If_Cut_t pCut 
)

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

Synopsis [Prints one cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 650 of file ifCut.c.

00651 {
00652     unsigned i;
00653     printf( "{" );
00654     for ( i = 0; i < pCut->nLeaves; i++ )
00655         printf( " %d", pCut->pLeaves[i] );
00656     printf( " }\n" );
00657 }

void If_CutPrintTiming ( If_Man_t p,
If_Cut_t pCut 
)

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

Synopsis [Prints one cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 670 of file ifCut.c.

00671 {
00672     If_Obj_t * pLeaf;
00673     unsigned i;
00674     printf( "{" );
00675     If_CutForEachLeaf( p, pCut, pLeaf, i )
00676         printf( " %d(%.2f/%.2f)", pLeaf->Id, If_ObjCutBest(pLeaf)->Delay, pLeaf->Required );
00677     printf( " }\n" );
00678 }

void If_CutPropagateRequired ( If_Man_t p,
If_Cut_t pCut,
float  ObjRequired 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 123 of file ifTime.c.

00124 {
00125     static int pPinPerm[IF_MAX_LUTSIZE];
00126     static float pPinDelays[IF_MAX_LUTSIZE];
00127     If_Obj_t * pLeaf;
00128     float * pLutDelays;
00129     float Required;
00130     int i;
00131     assert( !p->pPars->fLiftLeaves );
00132     // compute the pins
00133     if ( p->pPars->pLutLib )
00134     {
00135         pLutDelays = p->pPars->pLutLib->pLutDelays[pCut->nLeaves];
00136         if ( p->pPars->pLutLib->fVarPinDelays )
00137         {
00138             // compute the delay using sorted pins
00139             If_CutSortInputPins( p, pCut, pPinPerm, pPinDelays );
00140             for ( i = 0; i < (int)pCut->nLeaves; i++ )
00141             {
00142                 Required = ObjRequired - pLutDelays[i];
00143                 pLeaf = If_ManObj( p, pCut->pLeaves[pPinPerm[i]] );
00144                 pLeaf->Required = IF_MIN( pLeaf->Required, Required );
00145             }
00146         }
00147         else
00148         {
00149             Required = ObjRequired - pLutDelays[0];
00150             If_CutForEachLeaf( p, pCut, pLeaf, i )
00151                 pLeaf->Required = IF_MIN( pLeaf->Required, Required );
00152         }
00153     }
00154     else
00155     {
00156         if ( pCut->fUser )
00157         {
00158             If_CutForEachLeaf( p, pCut, pLeaf, i )
00159             {
00160                 Required = ObjRequired - (float)pCut->pPerm[i];
00161                 pLeaf->Required = IF_MIN( pLeaf->Required, Required );
00162             }
00163         }
00164         else
00165         {
00166             Required = ObjRequired - (float)1.0;
00167             If_CutForEachLeaf( p, pCut, pLeaf, i )
00168                 pLeaf->Required = IF_MIN( pLeaf->Required, Required );
00169         }
00170     }
00171 }

float If_CutRef ( If_Man_t p,
If_Cut_t pCut,
int  nLevels 
)

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

Synopsis [Computes area of the first level.]

Description [The cut need to be derefed.]

SideEffects []

SeeAlso []

Definition at line 623 of file ifCut.c.

00624 {
00625     If_Obj_t * pLeaf;
00626     float Area;
00627     int i;
00628     Area = If_CutLutArea(p, pCut);
00629     If_CutForEachLeaf( p, pCut, pLeaf, i )
00630     {
00631         assert( pLeaf->nRefs >= 0 );
00632         if ( pLeaf->nRefs++ > 0 || !If_ObjIsAnd(pLeaf) || nLevels == 1 )
00633             continue;
00634         Area += If_CutRef( p, If_ObjCutBest(pLeaf), nLevels - 1 );
00635     }
00636     return Area;
00637 }

static void If_CutSetData ( If_Cut_t pCut,
void *  pData 
) [inline, static]

Definition at line 257 of file if.h.

00257 { *(void **)pCut = pData;               }

void If_CutSort ( If_Man_t p,
If_Set_t pCutSet,
If_Cut_t pCut 
)

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

Synopsis [Performs incremental sorting of cuts.]

Description [Currently only the trivial sorting is implemented.]

SideEffects []

SeeAlso []

Definition at line 498 of file ifCut.c.

00499 {
00500 //    int Counter = 0;
00501     int i;
00502 
00503     // the new cut is the last one
00504     assert( pCutSet->ppCuts[pCutSet->nCuts] == pCut );
00505     assert( pCutSet->nCuts <= pCutSet->nCutsMax );
00506 
00507     // cut structure is empty
00508     if ( pCutSet->nCuts == 0 )
00509     {
00510         pCutSet->nCuts++;
00511         return;
00512     }
00513 
00514     // the cut will be added - find its place
00515     for ( i = pCutSet->nCuts-1; i >= 0; i-- )
00516     {
00517 //        Counter++;
00518         if ( If_ManSortCompare( p, pCutSet->ppCuts[i], pCut ) <= 0 )
00519             break;
00520         pCutSet->ppCuts[i+1] = pCutSet->ppCuts[i];
00521         pCutSet->ppCuts[i] = pCut;
00522     }
00523 //    printf( "%d ", Counter );
00524 
00525     // update the number of cuts
00526     if ( pCutSet->nCuts < pCutSet->nCutsMax )
00527         pCutSet->nCuts++;
00528 }

static unsigned* If_CutTruth ( If_Cut_t pCut  )  [inline, static]

Definition at line 260 of file if.h.

00260 { return pCut->pTruth;                              }

static int If_CutTruthWords ( int  nVarsMax  )  [inline, static]

Definition at line 261 of file if.h.

00261 { return nVarsMax <= 5 ? 1 : (1 << (nVarsMax - 5)); }

static int If_IsComplement ( If_Obj_t p  )  [inline, static]

Definition at line 218 of file if.h.

00218 { return (int )(((unsigned long)p) & 01);         }

static int If_ManAndNum ( If_Man_t p  )  [inline, static]

Definition at line 222 of file if.h.

00222 { return p->nObjs[IF_AND];              }

static If_Obj_t* If_ManCi ( If_Man_t p,
int  i 
) [inline, static]

Definition at line 226 of file if.h.

00226 { return (If_Obj_t *)Vec_PtrEntry( p->vCis, i );  }

static int If_ManCiNum ( If_Man_t p  )  [inline, static]

Definition at line 220 of file if.h.

00220 { return p->nObjs[IF_CI];               }

void If_ManCleanCutData ( If_Man_t p  ) 

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

Synopsis [Sets all the cut data to NULL.]

Description []

SideEffects []

SeeAlso []

Definition at line 61 of file ifUtil.c.

00062 {
00063     If_Obj_t * pObj;
00064     int i;
00065     If_ManForEachObj( p, pObj, i )
00066         If_CutSetData( If_ObjCutBest(pObj), NULL );
00067 }

void If_ManCleanMarkV ( If_Man_t p  ) 

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

Synopsis [Sets all visited marks to 0.]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file ifUtil.c.

00081 {
00082     If_Obj_t * pObj;
00083     int i;
00084     If_ManForEachObj( p, pObj, i )
00085         pObj->fVisit = 0;
00086 }

void If_ManCleanNodeCopy ( If_Man_t p  ) 

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

FileName [ifUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [FPGA mapping based on priority cuts.]

Synopsis [Various utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - November 21, 2006.]

Revision [

Id
ifUtil.c,v 1.00 2006/11/21 00:00:00 alanmi Exp

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

Synopsis [Sets all the node copy to NULL.]

Description []

SideEffects []

SeeAlso []

Definition at line 42 of file ifUtil.c.

00043 {
00044     If_Obj_t * pObj;
00045     int i;
00046     If_ManForEachObj( p, pObj, i )
00047         If_ObjSetCopy( pObj, NULL );
00048 }

static If_Obj_t* If_ManCo ( If_Man_t p,
int  i 
) [inline, static]

Definition at line 227 of file if.h.

00227 { return (If_Obj_t *)Vec_PtrEntry( p->vCos, i );  }

void If_ManComputeRequired ( If_Man_t p  ) 

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

Synopsis [Computes the required times of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 143 of file ifUtil.c.

00144 {
00145     If_Obj_t * pObj;
00146     int i, Counter;
00147 
00148     // compute area, clean required times, collect nodes used in the mapping
00149     p->nNets = 0;
00150     p->AreaGlo = If_ManScanMapping( p );
00151 
00152     // consider the case when the required times are given
00153     if ( p->pPars->pTimesReq )
00154     {
00155         assert( !p->pPars->fAreaOnly );
00156         // make sure that the required time hold
00157         Counter = 0;
00158         If_ManForEachCo( p, pObj, i )
00159         {
00160             if ( If_ObjArrTime(If_ObjFanin0(pObj)) > p->pPars->pTimesReq[i] + p->fEpsilon )
00161             {
00162                 Counter++;
00163 //                printf( "Required times are violated for output %d (arr = %d; req = %d).\n", 
00164 //                    i, (int)If_ObjArrTime(If_ObjFanin0(pObj)), (int)p->pPars->pTimesReq[i] );
00165             }
00166             If_ObjFanin0(pObj)->Required = p->pPars->pTimesReq[i];
00167         }
00168         if ( Counter )
00169             printf( "Required times are violated for %d outputs.\n", Counter );
00170     }
00171     else
00172     {
00173         // get the global required times
00174         p->RequiredGlo = If_ManDelayMax( p, 0 );
00175         // update the required times according to the target
00176         if ( p->pPars->DelayTarget != -1 )
00177         {
00178             if ( p->RequiredGlo > p->pPars->DelayTarget + p->fEpsilon )
00179             {
00180                 if ( p->fNextRound == 0 )
00181                 {
00182                     p->fNextRound = 1;
00183                     printf( "Cannot meet the target required times (%4.2f). Mapping continues anyway.\n", p->pPars->DelayTarget );
00184                 }
00185             }
00186             else if ( p->RequiredGlo < p->pPars->DelayTarget - p->fEpsilon )
00187             {
00188                 if ( p->fNextRound == 0 )
00189                 {
00190                     p->fNextRound = 1;
00191                     printf( "Relaxing the required times from (%4.2f) to the target (%4.2f).\n", p->RequiredGlo, p->pPars->DelayTarget );
00192                 }
00193                 p->RequiredGlo = p->pPars->DelayTarget;
00194             }
00195         }
00196         // do not propagate required times if area minimization is requested
00197         if ( p->pPars->fAreaOnly ) 
00198             return;
00199         // set the required times for the POs
00200         if ( p->pPars->fLatchPaths )
00201         {
00202             If_ManForEachLatchInput( p, pObj, i )
00203                 If_ObjFanin0(pObj)->Required = p->RequiredGlo;
00204         }
00205         else 
00206         {
00207             If_ManForEachCo( p, pObj, i )
00208                 If_ObjFanin0(pObj)->Required = p->RequiredGlo;
00209         }
00210     }
00211     // go through the nodes in the reverse topological order
00212     Vec_PtrForEachEntry( p->vMapped, pObj, i )
00213         If_CutPropagateRequired( p, If_ObjCutBest(pObj), pObj->Required );
00214 }

static If_Obj_t* If_ManConst1 ( If_Man_t p  )  [inline, static]

Definition at line 225 of file if.h.

00225 { return p->pConst1;                              }

static int If_ManCoNum ( If_Man_t p  )  [inline, static]

Definition at line 221 of file if.h.

00221 { return p->nObjs[IF_CO];               }

If_Obj_t* If_ManCreateAnd ( If_Man_t p,
If_Obj_t pFan0,
If_Obj_t pFan1 
)

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 201 of file ifMan.c.

00202 {
00203     If_Obj_t * pObj;
00204     // perform constant propagation
00205     if ( pFan0 == pFan1 )
00206         return pFan0;
00207     if ( pFan0 == If_Not(pFan1) )
00208         return If_Not(p->pConst1);
00209     if ( If_Regular(pFan0) == p->pConst1 )
00210         return pFan0 == p->pConst1 ? pFan1 : If_Not(p->pConst1);
00211     if ( If_Regular(pFan1) == p->pConst1 )
00212         return pFan1 == p->pConst1 ? pFan0 : If_Not(p->pConst1);
00213     // get memory for the new object
00214     pObj = If_ManSetupObj( p );
00215     pObj->Type    = IF_AND;
00216     pObj->fCompl0 = If_IsComplement(pFan0); pFan0 = If_Regular(pFan0);
00217     pObj->fCompl1 = If_IsComplement(pFan1); pFan1 = If_Regular(pFan1);
00218     pObj->pFanin0 = pFan0; pFan0->nRefs++; pFan0->nVisits++; pFan0->nVisitsCopy++;
00219     pObj->pFanin1 = pFan1; pFan1->nRefs++; pFan1->nVisits++; pFan1->nVisitsCopy++;
00220     pObj->fPhase  = (pObj->fCompl0 ^ pFan0->fPhase) & (pObj->fCompl1 ^ pFan1->fPhase);
00221     pObj->Level   = 1 + IF_MAX( pFan0->Level, pFan1->Level );
00222     if ( p->nLevelMax < (int)pObj->Level )
00223         p->nLevelMax = (int)pObj->Level;
00224     p->nObjs[IF_AND]++;
00225     return pObj;
00226 }

void If_ManCreateChoice ( If_Man_t p,
If_Obj_t pObj 
)

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

Synopsis [Creates the choice node.]

Description [Should be called after the equivalence class nodes are linked.]

SideEffects []

SeeAlso []

Definition at line 277 of file ifMan.c.

00278 {
00279     If_Obj_t * pTemp;
00280     // mark the node as a representative if its class
00281     assert( pObj->fRepr == 0 );
00282     pObj->fRepr = 1;
00283     // update the level of this node (needed for correct required time computation)
00284     for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
00285     {
00286         pObj->Level = IF_MAX( pObj->Level, pTemp->Level );
00287         pTemp->nVisits++; pTemp->nVisitsCopy++;
00288     }
00289     // mark the largest level
00290     if ( p->nLevelMax < (int)pObj->Level )
00291         p->nLevelMax = (int)pObj->Level;
00292 }

If_Obj_t* If_ManCreateCi ( If_Man_t p  ) 

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

Synopsis [Creates primary input.]

Description []

SideEffects []

SeeAlso []

Definition at line 157 of file ifMan.c.

00158 {
00159     If_Obj_t * pObj;
00160     pObj = If_ManSetupObj( p );
00161     pObj->Type = IF_CI;
00162     Vec_PtrPush( p->vCis, pObj );
00163     p->nObjs[IF_CI]++;
00164     return pObj;
00165 }

If_Obj_t* If_ManCreateCo ( If_Man_t p,
If_Obj_t pDriver 
)

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

Synopsis [Creates primary output with the given driver.]

Description []

SideEffects []

SeeAlso []

Definition at line 178 of file ifMan.c.

00179 {
00180     If_Obj_t * pObj;
00181     pObj = If_ManSetupObj( p );
00182     Vec_PtrPush( p->vCos, pObj );
00183     pObj->Type = IF_CO;
00184     pObj->fCompl0 = If_IsComplement(pDriver); pDriver = If_Regular(pDriver);
00185     pObj->pFanin0 = pDriver; pDriver->nRefs++; 
00186     p->nObjs[IF_CO]++;
00187     return pObj;
00188 }

If_Obj_t* If_ManCreateMux ( If_Man_t p,
If_Obj_t pFan0,
If_Obj_t pFan1,
If_Obj_t pCtrl 
)

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 258 of file ifMan.c.

00259 {
00260     If_Obj_t * pRes1, * pRes2;
00261     pRes1 = If_ManCreateAnd( p, pFan0, If_Not(pCtrl) );
00262     pRes2 = If_ManCreateAnd( p, pFan1, pCtrl );
00263     return If_Not( If_ManCreateAnd( p, If_Not(pRes1), If_Not(pRes2) ) );
00264 }

If_Obj_t* If_ManCreateXor ( If_Man_t p,
If_Obj_t pFan0,
If_Obj_t pFan1 
)

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

Synopsis [Create the new node assuming it does not exist.]

Description []

SideEffects []

SeeAlso []

Definition at line 239 of file ifMan.c.

00240 {
00241     If_Obj_t * pRes1, * pRes2;
00242     pRes1 = If_ManCreateAnd( p, If_Not(pFan0), pFan1 );
00243     pRes2 = If_ManCreateAnd( p, pFan0, If_Not(pFan1) );
00244     return If_Not( If_ManCreateAnd( p, If_Not(pRes1), If_Not(pRes2) ) );
00245 }

int If_ManCrossCut ( If_Man_t p  ) 

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

Synopsis [Computes cross-cut of the circuit.]

Description []

SideEffects []

SeeAlso []

Definition at line 394 of file ifUtil.c.

00395 {
00396     If_Obj_t * pObj, * pFanin;
00397     int i, nCutSize = 0, nCutSizeMax = 0;
00398     If_ManForEachObj( p, pObj, i )
00399     {
00400         if ( !If_ObjIsAnd(pObj) )
00401             continue;
00402         // consider the node
00403         if ( nCutSizeMax < ++nCutSize )
00404             nCutSizeMax = nCutSize;
00405         if ( pObj->nVisits == 0 )
00406             nCutSize--;
00407         // consider the fanins
00408         pFanin = If_ObjFanin0(pObj);
00409         if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00410             nCutSize--;
00411         pFanin = If_ObjFanin1(pObj);
00412         if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00413             nCutSize--;
00414         // consider the choice class
00415         if ( pObj->fRepr )
00416             for ( pFanin = pObj; pFanin; pFanin = pFanin->pEquiv )
00417                 if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00418                     nCutSize--;
00419     }
00420     If_ManForEachObj( p, pObj, i )
00421     {
00422         assert( If_ObjIsCi(pObj) || pObj->fVisit == 0 );
00423         pObj->nVisits = pObj->nVisitsCopy;
00424     }
00425     assert( nCutSize == 0 );
00426 //    printf( "Max cross cut size = %6d.\n", nCutSizeMax );
00427     return nCutSizeMax;
00428 }

float If_ManDelayMax ( If_Man_t p,
int  fSeq 
)

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

Synopsis [Returns the max delay of the POs.]

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file ifUtil.c.

00100 {
00101     If_Obj_t * pObj;
00102     float DelayBest;
00103     int i;
00104     if ( p->pPars->fLatchPaths && p->pPars->nLatches == 0 )
00105     {
00106         printf( "Delay optimization of latch path is not performed because there is no latches.\n" );
00107         p->pPars->fLatchPaths = 0;
00108     }
00109     DelayBest = -IF_FLOAT_LARGE;
00110     if ( fSeq )
00111     {
00112         assert( p->pPars->nLatches > 0 );
00113         If_ManForEachPo( p, pObj, i )
00114             if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00115                  DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00116     }
00117     else if ( p->pPars->fLatchPaths )
00118     {
00119         If_ManForEachLatchInput( p, pObj, i )
00120             if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00121                  DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00122     }
00123     else 
00124     {
00125         If_ManForEachCo( p, pObj, i )
00126             if ( DelayBest < If_ObjArrTime(If_ObjFanin0(pObj)) )
00127                  DelayBest = If_ObjArrTime(If_ObjFanin0(pObj));
00128     }
00129     return DelayBest;
00130 }

void If_ManDerefChoiceCutSet ( If_Man_t p,
If_Obj_t pObj 
)

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

Synopsis [Dereferences cutset of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 508 of file ifMan.c.

00509 {
00510     If_Obj_t * pTemp;
00511     assert( If_ObjIsAnd(pObj) );
00512     assert( pObj->fRepr );
00513     assert( pObj->nVisits > 0 );
00514     // consider the nodes in the choice class
00515     for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
00516     {
00517         assert( pTemp == pObj || pTemp->nVisits == 1 );
00518         if ( --pTemp->nVisits == 0 )
00519         {
00520 //            Mem_FixedEntryRecycle( p->pMemSet, (char *)pTemp->pCutSet );
00521             If_ManCutSetRecycle( p, pTemp->pCutSet );
00522             pTemp->pCutSet = NULL;
00523         }
00524     }
00525 }

void If_ManDerefNodeCutSet ( If_Man_t p,
If_Obj_t pObj 
)

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

Synopsis [Dereferences cutset of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 465 of file ifMan.c.

00466 {
00467     If_Obj_t * pFanin;
00468     assert( If_ObjIsAnd(pObj) );
00469     // consider the node
00470     assert( pObj->nVisits >= 0 );
00471     if ( pObj->nVisits == 0 )
00472     {
00473 //        Mem_FixedEntryRecycle( p->pMemSet, (char *)pObj->pCutSet );
00474         If_ManCutSetRecycle( p, pObj->pCutSet );
00475         pObj->pCutSet = NULL;
00476     }
00477     // consider the first fanin
00478     pFanin = If_ObjFanin0(pObj);
00479     assert( pFanin->nVisits > 0 );
00480     if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00481     {
00482 //        Mem_FixedEntryRecycle( p->pMemSet, (char *)pFanin->pCutSet );
00483         If_ManCutSetRecycle( p, pFanin->pCutSet );
00484         pFanin->pCutSet = NULL;
00485     }
00486     // consider the second fanin
00487     pFanin = If_ObjFanin1(pObj);
00488     assert( pFanin->nVisits > 0 );
00489     if ( !If_ObjIsCi(pFanin) && --pFanin->nVisits == 0 )
00490     {
00491 //        Mem_FixedEntryRecycle( p->pMemSet, (char *)pFanin->pCutSet );
00492         If_ManCutSetRecycle( p, pFanin->pCutSet );
00493         pFanin->pCutSet = NULL;
00494     }
00495 }

void If_ManImproveMapping ( If_Man_t p  ) 

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Improves current mapping using expand/Expand of one cut.]

Description [Assumes current mapping assigned and required times computed.]

SideEffects []

SeeAlso []

Definition at line 49 of file ifReduce.c.

00050 {
00051     int clk;
00052 
00053     clk = clock();
00054     If_ManImproveExpand( p, p->pPars->nLutSize );
00055     If_ManComputeRequired( p );
00056     if ( p->pPars->fVerbose )
00057     {
00058         printf( "E: Del = %7.2f. Ar = %9.1f. Edge = %8d. Cut = %8d. ", 
00059             p->RequiredGlo, p->AreaGlo, p->nNets, p->nCutsMerged );
00060         PRT( "T", clock() - clk );
00061     }
00062  
00063 /*
00064     clk = clock();
00065     If_ManImproveReduce( p, p->pPars->nLutSize );
00066     If_ManComputeRequired( p, 0 );
00067     if ( p->pPars->fVerbose )
00068     {
00069         printf( "R:  Del = %6.2f. Area = %8.2f. Nets = %6d. Cuts = %8d. Lim = %2d. Ave = %5.2f. ", 
00070             p->RequiredGlo, p->AreaGlo, p->nNets, p->nCutsMerged, p->nCutsUsed, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
00071         PRT( "T", clock() - clk );
00072     }
00073 */
00074 /*
00075     clk = clock();
00076     If_ManImproveExpand( p, p->pPars->nLutSize );
00077     If_ManComputeRequired( p, 0 );
00078     if ( p->pPars->fVerbose )
00079     {
00080         printf( "E:  Del = %6.2f. Area = %8.2f. Nets = %6d. Cuts = %8d. Lim = %2d. Ave = %5.2f. ", 
00081             p->RequiredGlo, p->AreaGlo, p->nNets, p->nCutsMerged, p->nCutsUsed, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
00082         PRT( "T", clock() - clk );
00083     }
00084 */
00085 }

static If_Obj_t* If_ManLi ( If_Man_t p,
int  i 
) [inline, static]

Definition at line 228 of file if.h.

00228 { return (If_Obj_t *)Vec_PtrEntry( p->vCos, If_ManCoNum(p) - p->pPars->nLatches + i );  }

static If_Obj_t* If_ManLo ( If_Man_t p,
int  i 
) [inline, static]

Definition at line 229 of file if.h.

00229 { return (If_Obj_t *)Vec_PtrEntry( p->vCis, If_ManCiNum(p) - p->pPars->nLatches + i );  }

static If_Obj_t* If_ManObj ( If_Man_t p,
int  i 
) [inline, static]

Definition at line 230 of file if.h.

00230 { return (If_Obj_t *)Vec_PtrEntry( p->vObjs, i ); }

static int If_ManObjNum ( If_Man_t p  )  [inline, static]

Definition at line 223 of file if.h.

00223 { return Vec_PtrSize(p->vObjs);         }

int If_ManPerformMapping ( If_Man_t p  ) 

FUNCTION DECLARATIONS ///

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 44 of file ifCore.c.

00045 {
00046     p->pPars->fAreaOnly = p->pPars->fArea; // temporary
00047 
00048     // create the CI cutsets
00049     If_ManSetupCiCutSets( p );
00050     // allocate memory for other cutsets
00051     If_ManSetupSetAll( p, If_ManCrossCut(p) );
00052 
00053     // try sequential mapping
00054     if ( p->pPars->fSeqMap )
00055     {
00056         int RetValue;
00057 //        printf( "Currently sequential mapping is not performed.\n" );
00058         RetValue = If_ManPerformMappingSeq( p );
00059         return RetValue;
00060 //        return 1;
00061     }
00062 
00063     return If_ManPerformMappingComb( p );
00064 }

int If_ManPerformMappingComb ( If_Man_t p  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 78 of file ifCore.c.

00079 {
00080     If_Obj_t * pObj;
00081     int clkTotal = clock();
00082     int i;
00083 
00084     // set arrival times and fanout estimates
00085     If_ManForEachCi( p, pObj, i )
00086     {
00087         If_ObjSetArrTime( pObj, p->pPars->pTimesArr[i] );
00088         pObj->EstRefs = (float)1.0;
00089     }
00090 
00091     // delay oriented mapping
00092     if ( p->pPars->fPreprocess && !p->pPars->fArea )
00093     {
00094         // map for delay
00095         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, "Delay" );
00096         // map for delay second option
00097         p->pPars->fFancy = 1;
00098         If_ManResetOriginalRefs( p );
00099         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, "Delay-2" );
00100         p->pPars->fFancy = 0;
00101         // map for area
00102         p->pPars->fArea = 1;
00103         If_ManResetOriginalRefs( p );
00104         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 1, "Area" );
00105         p->pPars->fArea = 0;
00106     }
00107     else
00108         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 0, 0, "Delay" );
00109 
00110     // try to improve area by expanding and reducing the cuts
00111     if ( p->pPars->fExpRed && !p->pPars->fTruth )
00112         If_ManImproveMapping( p );
00113 
00114     // area flow oriented mapping
00115     for ( i = 0; i < p->pPars->nFlowIters; i++ )
00116     {
00117         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 1, 0, "Flow" );
00118         if ( p->pPars->fExpRed && !p->pPars->fTruth )
00119             If_ManImproveMapping( p );
00120     }
00121 
00122     // area oriented mapping
00123     for ( i = 0; i < p->pPars->nAreaIters; i++ )
00124     {
00125         If_ManPerformMappingRound( p, p->pPars->nCutsMax, 2, 0, "Area" );
00126         if ( p->pPars->fExpRed && !p->pPars->fTruth )
00127             If_ManImproveMapping( p );
00128     }
00129 
00130     if ( p->pPars->fVerbose )
00131     {
00132 //        printf( "Total memory = %7.2f Mb. Peak cut memory = %7.2f Mb.  ", 
00133 //            1.0 * (p->nObjBytes + 2*sizeof(void *)) * If_ManObjNum(p) / (1<<20), 
00134 //            1.0 * p->nSetBytes * Mem_FixedReadMaxEntriesUsed(p->pMemSet) / (1<<20) );
00135         PRT( "Total time", clock() - clkTotal );
00136     }
00137 //    printf( "Cross cut memory = %d.\n", Mem_FixedReadMaxEntriesUsed(p->pMemSet) );
00138     s_MappingTime = clock() - clkTotal;
00139     return 1;
00140 }

int If_ManPerformMappingRound ( If_Man_t p,
int  nCutsUsed,
int  Mode,
int  fPreprocess,
char *  pLabel 
)

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

Synopsis [Performs one mapping pass over all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 252 of file ifMap.c.

00253 {
00254 //    ProgressBar * pProgress;
00255     If_Obj_t * pObj;
00256     int i, clk = clock();
00257     assert( Mode >= 0 && Mode <= 2 );
00258     // set the sorting function
00259     if ( Mode || p->pPars->fArea ) // area
00260         p->SortMode = 1;
00261     else if ( p->pPars->fFancy )
00262         p->SortMode = 2;
00263     else
00264         p->SortMode = 0;
00265     // set the cut number
00266     p->nCutsUsed   = nCutsUsed;
00267     p->nCutsMerged = 0;
00268     // map the internal nodes
00269 //    pProgress = Extra_ProgressBarStart( stdout, If_ManObjNum(p) );
00270     If_ManForEachNode( p, pObj, i )
00271     {
00272 //        Extra_ProgressBarUpdate( pProgress, i, pLabel );
00273         If_ObjPerformMappingAnd( p, pObj, Mode, fPreprocess );
00274         if ( pObj->fRepr )
00275             If_ObjPerformMappingChoice( p, pObj, Mode, fPreprocess );
00276     }
00277 //    Extra_ProgressBarStop( pProgress );
00278     // make sure the visit counters are all zero
00279     If_ManForEachNode( p, pObj, i )
00280         assert( pObj->nVisits == 0 );
00281     // compute required times and stats
00282     If_ManComputeRequired( p );
00283     if ( p->pPars->fVerbose )
00284     {
00285         char Symb = fPreprocess? 'P' : ((Mode == 0)? 'D' : ((Mode == 1)? 'F' : 'A'));
00286         printf( "%c: Del = %7.2f. Ar = %9.1f. Edge = %8d. Cut = %8d. ", 
00287             Symb, p->RequiredGlo, p->AreaGlo, p->nNets, p->nCutsMerged );
00288         PRT( "T", clock() - clk );
00289 //    printf( "Max number of cuts = %d. Average number of cuts = %5.2f.\n", 
00290 //        p->nCutsMax, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
00291     }
00292     return 1;
00293 }

int If_ManPerformMappingSeq ( If_Man_t p  ) 

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

Synopsis [Performs sequential mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 332 of file ifSeq.c.

00333 {
00334     int clkTotal = clock();
00335     int PeriodBest;
00336 
00337     p->SortMode = 0;
00338 
00339     // perform combinational mapping to get the upper bound on the clock period
00340     If_ManPerformMappingRound( p, 1, 0, 0, NULL );
00341     p->RequiredGlo = If_ManDelayMax( p, 0 );
00342     p->RequiredGlo2 = p->RequiredGlo;
00343 
00344     // set direct linking of latches with their inputs
00345     If_ManPrepareMappingSeq( p );
00346 
00347     // collect latches
00348     p->vLatchOrder = If_ManCollectLatches( p );
00349 
00350     // set parameters
00351     p->nCutsUsed = p->pPars->nCutsMax;
00352     p->nAttempts = 0;
00353     p->nMaxIters = 50;
00354     p->Period    = (int)p->RequiredGlo;
00355 
00356     // make sure the clock period works
00357     if ( !If_ManBinarySearchPeriod( p ) )
00358     {
00359         printf( "If_ManPerformMappingSeq(): The upper bound on the clock period cannot be computed.\n" );
00360         return 0;
00361     }
00362 
00363     // perform binary search
00364     PeriodBest = If_ManBinarySearch_rec( p, 0, p->Period );
00365 
00366     // recompute the best l-values
00367     if ( p->Period != PeriodBest )
00368     {
00369         p->Period = PeriodBest;
00370         if ( !If_ManBinarySearchPeriod( p ) )
00371         {
00372             printf( "If_ManPerformMappingSeq(): The final clock period cannot be confirmed.\n" );
00373             return 0;
00374         }
00375     }
00376     if ( p->pPars->fVerbose )
00377     {
00378 /*
00379         {
00380             FILE * pTable;
00381             pTable = fopen( "iscas/stats_new.txt", "a+" );
00382 //            fprintf( pTable, "%s ",  pNtk->pName );
00383             fprintf( pTable, "%d ", p->Period );
00384     //        fprintf( pTable, "%.2f ", (float)(s_MappingMem)/(float)(1<<20) );
00385 //            fprintf( pTable, "%.2f", (float)(s_MappingTime)/(float)(CLOCKS_PER_SEC) );
00386 //            fprintf( pTable, "\n" );
00387             fclose( pTable );
00388         }
00389 */
00390         printf( "The best clock period is %3d.  ", p->Period );
00391         PRT( "Sequential time", clock() - clkTotal );
00392     }
00393     p->RequiredGlo = (float)PeriodBest;
00394 
00395     // postprocess it using combinational mapping
00396     If_ManPerformMappingSeqPost( p );
00397     s_MappingTime = clock() - clkTotal;
00398     return 1;
00399 }

void If_ManResetOriginalRefs ( If_Man_t p  ) 

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order in array p->vMapping.]

SideEffects []

SeeAlso []

Definition at line 365 of file ifUtil.c.

00366 {
00367     If_Obj_t * pObj;
00368     int i;
00369     If_ManForEachObj( p, pObj, i )
00370         pObj->nRefs = 0;
00371     If_ManForEachObj( p, pObj, i )
00372     {
00373         if ( If_ObjIsAnd(pObj) )
00374         {
00375             pObj->pFanin0->nRefs++;
00376             pObj->pFanin1->nRefs++;
00377         }
00378         else if ( If_ObjIsCo(pObj) )
00379             pObj->pFanin0->nRefs++;
00380     }
00381 }

void If_ManRestart ( If_Man_t p  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file ifMan.c.

00098 {
00099     FREE( p->pMemCi );
00100     Vec_PtrClear( p->vCis );
00101     Vec_PtrClear( p->vCos );
00102     Vec_PtrClear( p->vObjs );
00103     Vec_PtrClear( p->vMapped );
00104     Vec_PtrClear( p->vTemp );
00105     Mem_FixedRestart( p->pMemObj );
00106     // create the constant node
00107     p->pConst1 = If_ManSetupObj( p );
00108     p->pConst1->Type = IF_CONST1;
00109     p->pConst1->fPhase = 1;
00110     // reset the counter of other nodes
00111     p->nObjs[IF_CI] = p->nObjs[IF_CO] = p->nObjs[IF_AND] = 0;
00112 }

float If_ManScanMapping ( If_Man_t p  ) 

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order in array p->vMapping.]

SideEffects []

SeeAlso []

Definition at line 260 of file ifUtil.c.

00261 {
00262     If_Obj_t * pObj, ** ppStore;
00263     float aArea;
00264     int i;
00265     assert( !p->pPars->fLiftLeaves );
00266     // clean all references
00267     If_ManForEachObj( p, pObj, i )
00268     {
00269         pObj->Required = IF_FLOAT_LARGE;
00270         pObj->nVisits  = pObj->nVisitsCopy;
00271         pObj->nRefs    = 0;
00272     }
00273     // allocate place to store the nodes
00274     ppStore = ALLOC( If_Obj_t *, p->nLevelMax + 1 );
00275     memset( ppStore, 0, sizeof(If_Obj_t *) * (p->nLevelMax + 1) );
00276     // collect nodes reachable from POs in the DFS order through the best cuts
00277     aArea = 0;
00278     If_ManForEachCo( p, pObj, i )
00279         aArea += If_ManScanMapping_rec( p, If_ObjFanin0(pObj), ppStore );
00280     // reconnect the nodes in reverse topological order
00281     Vec_PtrClear( p->vMapped );
00282     for ( i = p->nLevelMax; i >= 0; i-- )
00283         for ( pObj = ppStore[i]; pObj; pObj = pObj->pCopy )
00284             Vec_PtrPush( p->vMapped, pObj );
00285     free( ppStore );
00286     return aArea;
00287 }

float If_ManScanMappingSeq ( If_Man_t p  ) 

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order in array p->vMapping.]

SideEffects []

SeeAlso []

Definition at line 336 of file ifUtil.c.

00337 {
00338     If_Obj_t * pObj;
00339     float aArea;
00340     int i;
00341     assert( p->pPars->fLiftLeaves );
00342     // clean all references
00343     If_ManForEachObj( p, pObj, i )
00344         pObj->nRefs = 0;
00345     // collect nodes reachable from POs in the DFS order through the best cuts
00346     aArea = 0;
00347     Vec_PtrClear( p->vMapped );
00348     If_ManForEachPo( p, pObj, i )
00349         aArea += If_ManScanMappingSeq_rec( p, If_ObjFanin0(pObj), p->vMapped );
00350     return aArea;
00351 }

void If_ManSetupCiCutSets ( If_Man_t p  ) 

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

Synopsis [Prepares memory for one cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 409 of file ifMan.c.

00410 {
00411     If_Obj_t * pObj;
00412     int i;
00413     assert( p->pMemCi == NULL );
00414     // create elementary cuts for the CIs
00415     If_ManForEachCi( p, pObj, i )
00416         If_ManSetupCutTriv( p, &pObj->CutBest, pObj->Id );
00417     // create elementary cutsets for the CIs
00418     p->pMemCi = (If_Set_t *)malloc( If_ManCiNum(p) * (sizeof(If_Set_t) + sizeof(void *)) );
00419     If_ManForEachCi( p, pObj, i )
00420     {
00421         pObj->pCutSet = (If_Set_t *)((char *)p->pMemCi + i * (sizeof(If_Set_t) + sizeof(void *)));
00422         pObj->pCutSet->nCuts = 1;
00423         pObj->pCutSet->nCutsMax = p->pPars->nCutsMax;
00424         pObj->pCutSet->ppCuts = (If_Cut_t **)(pObj->pCutSet + 1);
00425         pObj->pCutSet->ppCuts[0] = &pObj->CutBest;
00426     }
00427 }

void If_ManSetupCutTriv ( If_Man_t p,
If_Cut_t pCut,
int  ObjId 
)

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

Synopsis [Prepares memory for one cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 355 of file ifMan.c.

00356 {
00357     pCut->fCompl     = 0;
00358     pCut->nLimit     = p->pPars->nLutSize;
00359     pCut->nLeaves    = 1;
00360     pCut->pLeaves[0] = p->pPars->fLiftLeaves? (ObjId << 8) : ObjId;
00361     pCut->uSign      = If_ObjCutSign( pCut->pLeaves[0] );
00362     // set up elementary truth table of the unit cut
00363     if ( p->pPars->fTruth )
00364     {
00365         int i, nTruthWords;
00366         nTruthWords = pCut->nLimit <= 5 ? 1 : (1 << (pCut->nLimit - 5));
00367         for ( i = 0; i < nTruthWords; i++ )
00368             If_CutTruth(pCut)[i] = 0xAAAAAAAA;
00369     }
00370 }

If_Set_t* If_ManSetupNodeCutSet ( If_Man_t p,
If_Obj_t pObj 
)

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

Synopsis [Prepares cutset of the node.]

Description [Elementary cutset will be added last.]

SideEffects []

SeeAlso []

Definition at line 440 of file ifMan.c.

00441 {
00442     assert( If_ObjIsAnd(pObj) );
00443     assert( pObj->pCutSet == NULL );
00444 //    pObj->pCutSet = (If_Set_t *)Mem_FixedEntryFetch( p->pMemSet );
00445 //    If_ManSetupSet( p, pObj->pCutSet );
00446 
00447     pObj->pCutSet = If_ManCutSetFetch( p );
00448     pObj->pCutSet->nCuts = 0;
00449     pObj->pCutSet->nCutsMax = p->pPars->nCutsMax;
00450 
00451     return pObj->pCutSet;
00452 }

void If_ManSetupSetAll ( If_Man_t p,
int  nCrossCut 
)

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

Synopsis [Dereferences cutset of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 538 of file ifMan.c.

00539 {
00540     If_Set_t * pCutSet;
00541     int i, nCutSets;
00542     nCutSets = 128 + nCrossCut;
00543     p->pFreeList = p->pMemAnd = pCutSet = (If_Set_t *)malloc( nCutSets * p->nSetBytes );
00544     for ( i = 0; i < nCutSets; i++ )
00545     {
00546         If_ManSetupSet( p, pCutSet );
00547         if ( i == nCutSets - 1 )
00548             pCutSet->pNext = NULL;
00549         else
00550             pCutSet->pNext = (If_Set_t *)( (char *)pCutSet + p->nSetBytes );
00551         pCutSet = pCutSet->pNext;
00552     }
00553     assert( pCutSet == NULL );
00554 
00555     if ( p->pPars->fVerbose )
00556     {
00557         printf( "Node = %7d.  Ch = %5d.  Total mem = %7.2f Mb. Peak cut mem = %7.2f Mb.\n", 
00558             If_ManAndNum(p), p->nChoices,
00559             1.0 * (p->nObjBytes + 2*sizeof(void *)) * If_ManObjNum(p) / (1<<20), 
00560             1.0 * p->nSetBytes * nCrossCut / (1<<20) );
00561     }
00562 //    printf( "Cross cut = %d.\n", nCrossCut );
00563 
00564 }

void If_ManSortCuts ( If_Man_t p,
int  Mode 
)

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

Synopsis [Sorts the cuts.]

Description []

SideEffects []

SeeAlso []

Definition at line 409 of file ifCut.c.

00410 {
00411 /*
00412     // sort the cuts
00413     if ( Mode || p->pPars->fArea ) // area
00414         qsort( p->ppCuts, p->nCuts, sizeof(If_Cut_t *), (int (*)(const void *, const void *))If_CutCompareArea );
00415     else if ( p->pPars->fFancy )
00416         qsort( p->ppCuts, p->nCuts, sizeof(If_Cut_t *), (int (*)(const void *, const void *))If_CutCompareDelayOld );
00417     else
00418         qsort( p->ppCuts, p->nCuts, sizeof(If_Cut_t *), (int (*)(const void *, const void *))If_CutCompareDelay );
00419 */
00420 }

If_Man_t* If_ManStart ( If_Par_t pPars  ) 

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Starts the AIG manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file ifMan.c.

00048 {
00049     If_Man_t * p;
00050     // start the manager
00051     p = ALLOC( If_Man_t, 1 );
00052     memset( p, 0, sizeof(If_Man_t) );
00053     p->pPars = pPars;
00054     p->fEpsilon = (float)0.001;
00055     // allocate arrays for nodes
00056     p->vCis    = Vec_PtrAlloc( 100 );
00057     p->vCos    = Vec_PtrAlloc( 100 );
00058     p->vObjs   = Vec_PtrAlloc( 100 );
00059     p->vMapped = Vec_PtrAlloc( 100 );
00060     p->vTemp   = Vec_PtrAlloc( 100 );
00061     // prepare the memory manager
00062     p->nTruthWords = p->pPars->fTruth? If_CutTruthWords( p->pPars->nLutSize ) : 0;
00063     p->nPermWords  = p->pPars->fUsePerm? If_CutPermWords( p->pPars->nLutSize ) : 0;
00064     p->nObjBytes   = sizeof(If_Obj_t) + sizeof(int) * (p->pPars->nLutSize + p->nPermWords + p->nTruthWords);
00065     p->nCutBytes   = sizeof(If_Cut_t) + sizeof(int) * (p->pPars->nLutSize + p->nPermWords + p->nTruthWords);
00066     p->nSetBytes   = sizeof(If_Set_t) + (sizeof(If_Cut_t *) + p->nCutBytes) * (p->pPars->nCutsMax + 1);
00067     p->pMemObj     = Mem_FixedStart( p->nObjBytes );
00068 //    p->pMemSet     = Mem_FixedStart( p->nSetBytes );
00069     // report expected memory usage
00070     if ( p->pPars->fVerbose )
00071         printf( "Memory (bytes): Truth = %4d. Cut = %4d. Obj = %4d. Set = %4d.\n", 
00072             4 * p->nTruthWords, p->nCutBytes, p->nObjBytes, p->nSetBytes );
00073     // room for temporary truth tables
00074     p->puTemp[0] = p->pPars->fTruth? ALLOC( unsigned, 4 * p->nTruthWords ) : NULL;
00075     p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
00076     p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
00077     p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
00078     // create the constant node
00079     p->pConst1 = If_ManSetupObj( p );
00080     p->pConst1->Type = IF_CONST1;
00081     p->pConst1->fPhase = 1;
00082     p->nObjs[IF_CONST1]++;
00083     return p;
00084 }

void If_ManStop ( If_Man_t p  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 125 of file ifMan.c.

00126 {
00127     Vec_PtrFree( p->vCis );
00128     Vec_PtrFree( p->vCos );
00129     Vec_PtrFree( p->vObjs );
00130     Vec_PtrFree( p->vMapped );
00131     Vec_PtrFree( p->vTemp );
00132     if ( p->vLatchOrder ) Vec_PtrFree( p->vLatchOrder );
00133     if ( p->vLags ) Vec_IntFree( p->vLags );
00134     Mem_FixedStop( p->pMemObj, 0 );
00135     FREE( p->pMemCi );
00136     FREE( p->pMemAnd );
00137     FREE( p->puTemp[0] );
00138     // free pars memory
00139     if ( p->pPars->pTimesArr )
00140         FREE( p->pPars->pTimesArr );
00141     if ( p->pPars->pTimesReq )
00142         FREE( p->pPars->pTimesReq );
00143     free( p );
00144 }

static If_Obj_t* If_Not ( If_Obj_t p  )  [inline, static]

Definition at line 216 of file if.h.

00216 { return (If_Obj_t *)((unsigned long)(p) ^  01);  }

static If_Obj_t* If_NotCond ( If_Obj_t p,
int  c 
) [inline, static]

Definition at line 217 of file if.h.

00217 { return (If_Obj_t *)((unsigned long)(p) ^ (c));  }

static float If_ObjArrTime ( If_Obj_t pObj  )  [inline, static]

Definition at line 250 of file if.h.

00250 { return If_ObjCutBest(pObj)->Delay;    }

static void* If_ObjCopy ( If_Obj_t pObj  )  [inline, static]

Definition at line 243 of file if.h.

00243 { return pObj->pCopy;                   }

static If_Cut_t* If_ObjCutBest ( If_Obj_t pObj  )  [inline, static]

Definition at line 247 of file if.h.

00247 { return &pObj->CutBest;                }

static unsigned If_ObjCutSign ( unsigned  ObjId  )  [inline, static]

Definition at line 248 of file if.h.

00248 { return (1 << (ObjId % 31));           }

static If_Obj_t* If_ObjFanin0 ( If_Obj_t pObj  )  [inline, static]

Definition at line 239 of file if.h.

00239 { return pObj->pFanin0;                 }

static If_Obj_t* If_ObjFanin1 ( If_Obj_t pObj  )  [inline, static]

Definition at line 240 of file if.h.

00240 { return pObj->pFanin1;                 }

static int If_ObjFaninC0 ( If_Obj_t pObj  )  [inline, static]

Definition at line 241 of file if.h.

00241 { return pObj->fCompl0;                 }

static int If_ObjFaninC1 ( If_Obj_t pObj  )  [inline, static]

Definition at line 242 of file if.h.

00242 { return pObj->fCompl1;                 }

static int If_ObjIsAnd ( If_Obj_t pObj  )  [inline, static]

Definition at line 237 of file if.h.

00237 { return pObj->Type == IF_AND;          }

static int If_ObjIsCi ( If_Obj_t pObj  )  [inline, static]

Definition at line 233 of file if.h.

00233 { return pObj->Type == IF_CI;           }

static int If_ObjIsCo ( If_Obj_t pObj  )  [inline, static]

Definition at line 234 of file if.h.

00234 { return pObj->Type == IF_CO;           }

static int If_ObjIsConst1 ( If_Obj_t pObj  )  [inline, static]

Definition at line 232 of file if.h.

00232 { return pObj->Type == IF_CONST1;       }

static int If_ObjIsLatch ( If_Obj_t pObj  )  [inline, static]

Definition at line 236 of file if.h.

00236 { return If_ObjIsCi(pObj) && pObj->pFanin0 != NULL; }

static int If_ObjIsPi ( If_Obj_t pObj  )  [inline, static]

Definition at line 235 of file if.h.

00235 { return If_ObjIsCi(pObj) && pObj->pFanin0 == NULL; }

static float If_ObjLValue ( If_Obj_t pObj  )  [inline, static]

Definition at line 253 of file if.h.

00253 { return pObj->LValue;                  }

void If_ObjPerformMappingAnd ( If_Man_t p,
If_Obj_t pObj,
int  Mode,
int  fPreprocess 
)

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

Synopsis [Finds the best cut for the given node.]

Description [Mapping modes: delay (0), area flow (1), area (2).]

SideEffects []

SeeAlso []

Definition at line 62 of file ifMap.c.

00063 {
00064     If_Set_t * pCutSet;
00065     If_Cut_t * pCut0, * pCut1, * pCut;
00066     int i, k;
00067 
00068     assert( p->pPars->fSeqMap || !If_ObjIsAnd(pObj->pFanin0) || pObj->pFanin0->pCutSet->nCuts > 1 );
00069     assert( p->pPars->fSeqMap || !If_ObjIsAnd(pObj->pFanin1) || pObj->pFanin1->pCutSet->nCuts > 1 );
00070 
00071     // prepare
00072     if ( !p->pPars->fSeqMap )
00073     {
00074         if ( Mode == 0 )
00075             pObj->EstRefs = (float)pObj->nRefs;
00076         else if ( Mode == 1 )
00077             pObj->EstRefs = (float)((2.0 * pObj->EstRefs + pObj->nRefs) / 3.0);
00078     }
00079     if ( Mode && pObj->nRefs > 0 )
00080         If_CutDeref( p, If_ObjCutBest(pObj), IF_INFINITY );
00081 
00082     // prepare the cutset
00083     pCutSet = If_ManSetupNodeCutSet( p, pObj );
00084 
00085     // get the current assigned best cut
00086     pCut = If_ObjCutBest(pObj);
00087     if ( pCut->nLeaves > 0 )
00088     {
00089         // recompute the parameters of the best cut
00090         pCut->Delay = If_CutDelay( p, pCut );
00091         assert( pCut->Delay <= pObj->Required + p->fEpsilon );
00092         pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut, IF_INFINITY ) : If_CutFlow( p, pCut );
00093         // save the best cut from the previous iteration
00094         if ( !fPreprocess )
00095             If_CutCopy( p, pCutSet->ppCuts[pCutSet->nCuts++], pCut );
00096     }
00097 
00098     // generate cuts
00099     If_ObjForEachCut( pObj->pFanin0, pCut0, i )
00100     If_ObjForEachCut( pObj->pFanin1, pCut1, k )
00101     {
00102         // get the next free cut
00103         assert( pCutSet->nCuts <= pCutSet->nCutsMax );
00104         pCut = pCutSet->ppCuts[pCutSet->nCuts];
00105         // make sure K-feasible cut exists
00106         if ( If_WordCountOnes(pCut0->uSign | pCut1->uSign) > p->pPars->nLutSize )
00107             continue;
00108         // merge the nodes
00109         if ( !If_CutMerge( pCut0, pCut1, pCut ) )
00110             continue;
00111         assert( p->pPars->fSeqMap || pCut->nLeaves > 1 );
00112         p->nCutsMerged++;
00113         // check if this cut is contained in any of the available cuts
00114 //        if ( p->pPars->pFuncCost == NULL && If_CutFilter( p, pCut ) ) // do not filter functionality cuts
00115         if ( If_CutFilter( pCutSet, pCut ) )
00116             continue;
00117         // compute the truth table
00118         pCut->fCompl = 0;
00119         if ( p->pPars->fTruth )
00120             If_CutComputeTruth( p, pCut, pCut0, pCut1, pObj->fCompl0, pObj->fCompl1 );
00121         // compute the application-specific cost and depth
00122         pCut->fUser = (p->pPars->pFuncCost != NULL);
00123         pCut->Cost = p->pPars->pFuncCost? p->pPars->pFuncCost(pCut) : 0;
00124         if ( pCut->Cost == IF_COST_MAX )
00125             continue;
00126         // check if the cut satisfies the required times
00127         pCut->Delay = If_CutDelay( p, pCut );
00128 //        printf( "%.2f ", pCut->Delay );
00129         if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon )
00130             continue;
00131         // compute area of the cut (this area may depend on the application specific cost)
00132         pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut, IF_INFINITY ) : If_CutFlow( p, pCut );
00133         pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
00134         // insert the cut into storage
00135         If_CutSort( p, pCutSet, pCut );
00136     } 
00137     assert( pCutSet->nCuts > 0 );
00138 
00139     // add the trivial cut to the set
00140     If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
00141     assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
00142 
00143     // update the best cut
00144     if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
00145         If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
00146     assert( p->pPars->fSeqMap || If_ObjCutBest(pObj)->nLeaves > 1 );
00147 
00148     // ref the selected cut
00149     if ( Mode && pObj->nRefs > 0 )
00150         If_CutRef( p, If_ObjCutBest(pObj), IF_INFINITY );
00151 
00152     // call the user specified function for each cut
00153     if ( p->pPars->pFuncUser )
00154         If_ObjForEachCut( pObj, pCut, i )
00155             p->pPars->pFuncUser( p, pObj, pCut );
00156 
00157     // free the cuts
00158     If_ManDerefNodeCutSet( p, pObj );
00159 }

void If_ObjPerformMappingChoice ( If_Man_t p,
If_Obj_t pObj,
int  Mode,
int  fPreprocess 
)

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

Synopsis [Finds the best cut for the choice node.]

Description []

SideEffects []

SeeAlso []

Definition at line 172 of file ifMap.c.

00173 {
00174     If_Set_t * pCutSet;
00175     If_Obj_t * pTemp;
00176     If_Cut_t * pCutTemp, * pCut;
00177     int i;
00178     assert( pObj->pEquiv != NULL );
00179 
00180     // prepare
00181     if ( Mode && pObj->nRefs > 0 )
00182         If_CutDeref( p, If_ObjCutBest(pObj), IF_INFINITY );
00183 
00184     // remove elementary cuts
00185     for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
00186         pTemp->pCutSet->nCuts--;
00187 
00188     // update the cutset of the node
00189     pCutSet = pObj->pCutSet;
00190 
00191     // generate cuts
00192     for ( pTemp = pObj->pEquiv; pTemp; pTemp = pTemp->pEquiv )
00193     {
00194         assert( pTemp->nRefs == 0 );
00195         assert( p->pPars->fSeqMap || pTemp->pCutSet->nCuts > 0 );
00196         // go through the cuts of this node
00197         If_ObjForEachCut( pTemp, pCutTemp, i )
00198         {
00199             assert( p->pPars->fSeqMap || pCutTemp->nLeaves > 1 );
00200             // get the next free cut
00201             assert( pCutSet->nCuts <= pCutSet->nCutsMax );
00202             pCut = pCutSet->ppCuts[pCutSet->nCuts];
00203             // copy the cut into storage
00204             If_CutCopy( p, pCut, pCutTemp );
00205             // check if this cut is contained in any of the available cuts
00206             if ( If_CutFilter( pCutSet, pCut ) )
00207                 continue;
00208             // check if the cut satisfies the required times
00209             assert( pCut->Delay == If_CutDelay( p, pCut ) );
00210             if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon )
00211                 continue;
00212             // set the phase attribute
00213             assert( pCut->fCompl == 0 );
00214             pCut->fCompl ^= (pObj->fPhase ^ pTemp->fPhase); // why ^= ?
00215             // compute area of the cut (this area may depend on the application specific cost)
00216             pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut, IF_INFINITY ) : If_CutFlow( p, pCut );
00217             pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
00218             // insert the cut into storage
00219             If_CutSort( p, pCutSet, pCut );
00220         }
00221     }
00222     assert( pCutSet->nCuts > 0 );
00223 
00224     // add the trivial cut to the set
00225     If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
00226     assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
00227 
00228     // update the best cut
00229     if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
00230         If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
00231     assert( p->pPars->fSeqMap || If_ObjCutBest(pObj)->nLeaves > 1 );
00232 
00233     // ref the selected cut
00234     if ( Mode && pObj->nRefs > 0 )
00235         If_CutRef( p, If_ObjCutBest(pObj), IF_INFINITY );
00236 
00237     // free the cuts
00238     If_ManDerefChoiceCutSet( p, pObj );
00239 }

static void If_ObjSetArrTime ( If_Obj_t pObj,
float  ArrTime 
) [inline, static]

Definition at line 251 of file if.h.

00251 { If_ObjCutBest(pObj)->Delay = ArrTime; }

static void If_ObjSetChoice ( If_Obj_t pObj,
If_Obj_t pEqu 
) [inline, static]

Definition at line 245 of file if.h.

00245 { pObj->pEquiv = pEqu;                  }

static void If_ObjSetCopy ( If_Obj_t pObj,
void *  pCopy 
) [inline, static]

Definition at line 244 of file if.h.

00244 { pObj->pCopy = pCopy;                  }

static void If_ObjSetLValue ( If_Obj_t pObj,
float  LValue 
) [inline, static]

Definition at line 254 of file if.h.

00254 { pObj->LValue = LValue;                }

static If_Obj_t* If_Regular ( If_Obj_t p  )  [inline, static]

Definition at line 215 of file if.h.

00215 { return (If_Obj_t *)((unsigned long)(p) & ~01);  }


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