abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
amapLib.c File Reference
#include "amapInt.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Amap_Lib_t
Amap_LibAlloc ()
 DECLARATIONS ///. More...
 
void Amap_LibFree (Amap_Lib_t *p)
 
int Amap_LibNumPinsMax (Amap_Lib_t *p)
 
void Amap_LibWritePin (FILE *pFile, Amap_Pin_t *pPin)
 
void Amap_LibWriteGate (FILE *pFile, Amap_Gat_t *pGate, int fPrintDsd)
 
void Amap_LibWrite (FILE *pFile, Amap_Lib_t *pLib, int fPrintDsd)
 
int Amap_LibCompareGatesByArea (Amap_Gat_t **pp1, Amap_Gat_t **pp2)
 
Vec_Ptr_tAmap_LibSortGatesByArea (Amap_Lib_t *pLib)
 
Amap_Gat_tAmap_LibFindGate (Amap_Lib_t *p, unsigned uTruth)
 
Vec_Ptr_tAmap_LibSelectGates (Amap_Lib_t *p, int fVerbose)
 
void Amap_LibPrintSelectedGates (Amap_Lib_t *p, int fAllGates)
 
Amap_Lib_tAmap_LibReadAndPrepare (char *pFileName, char *pBuffer, int fVerbose, int fVeryVerbose)
 

Function Documentation

DECLARATIONS ///.

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

FileName [amapLib.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Technology mapper for standard cells.]

Synopsis [Standard-cell library.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Allocs a library.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file amapLib.c.

46 {
47  Amap_Lib_t * p;
48  p = (Amap_Lib_t *)ABC_ALLOC( Amap_Lib_t, 1 );
49  memset( p, 0, sizeof(Amap_Lib_t) );
50  p->vGates = Vec_PtrAlloc( 100 );
51  p->pMemGates = Aig_MmFlexStart();
52  p->pMemSet = Aig_MmFlexStart();
53  return p;
54 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
typedefABC_NAMESPACE_HEADER_START struct Amap_Lib_t_ Amap_Lib_t
INCLUDES ///.
Definition: amap.h:42
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
int Amap_LibCompareGatesByArea ( Amap_Gat_t **  pp1,
Amap_Gat_t **  pp2 
)

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

Synopsis [Compares two gates by area.]

Description []

SideEffects []

SeeAlso []

Definition at line 199 of file amapLib.c.

200 {
201  double Diff = (*pp1)->dArea - (*pp2)->dArea;
202  if ( Diff < 0.0 )
203  return -1;
204  if ( Diff > 0.0 )
205  return 1;
206  return 0;
207 }
Amap_Gat_t* Amap_LibFindGate ( Amap_Lib_t p,
unsigned  uTruth 
)

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

Synopsis [Finds min-area gate with the given function.]

Description []

SideEffects []

SeeAlso []

Definition at line 240 of file amapLib.c.

241 {
242  Amap_Gat_t * pGate;
243  int i;
244  Vec_PtrForEachEntry( Amap_Gat_t *, p->vSorted, pGate, i )
245  if ( pGate->nPins <= 5 && pGate->pFunc[0] == uTruth )
246  return pGate;
247  return NULL;
248 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
if(last==0)
Definition: sparse_int.h:34
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Amap_LibFree ( Amap_Lib_t p)

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

Synopsis [Deallocs a library.]

Description []

SideEffects []

SeeAlso []

Definition at line 67 of file amapLib.c.

68 {
69  if ( p == NULL )
70  return;
71  if ( p->vSelect )
72  Vec_PtrFree( p->vSelect );
73  if ( p->vSorted )
74  Vec_PtrFree( p->vSorted );
75  if ( p->vGates )
76  Vec_PtrFree( p->vGates );
77  if ( p->vRules )
78  Vec_VecFree( (Vec_Vec_t *)p->vRules );
79  if ( p->vRulesX )
80  Vec_VecFree( (Vec_Vec_t *)p->vRulesX );
81  if ( p->vRules3 )
82  Vec_IntFree( p->vRules3 );
83  Aig_MmFlexStop( p->pMemGates, 0 );
84  Aig_MmFlexStop( p->pMemSet, 0 );
85  ABC_FREE( p->pRules );
86  ABC_FREE( p->pRulesX );
87  ABC_FREE( p->pNodes );
88  ABC_FREE( p->pName );
89  ABC_FREE( p );
90 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Amap_LibNumPinsMax ( Amap_Lib_t p)

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

Synopsis [Returns the largest gate size.]

Description []

SideEffects []

SeeAlso []

Definition at line 103 of file amapLib.c.

104 {
105  Amap_Gat_t * pGate;
106  int i, Counter = 0;
107  Amap_LibForEachGate( p, pGate, i )
108  if ( Counter < (int)pGate->nPins )
109  Counter = pGate->nPins;
110  return Counter;
111 }
#define Amap_LibForEachGate(pLib, pGate, i)
Definition: amapInt.h:293
static Llb_Mgr_t * p
Definition: llb3Image.c:950
if(last==0)
Definition: sparse_int.h:34
static int Counter
void Amap_LibPrintSelectedGates ( Amap_Lib_t p,
int  fAllGates 
)

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

Synopsis [Selects gates useful for area-only mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 302 of file amapLib.c.

303 {
304  Vec_Ptr_t * vArray;
305  Amap_Gat_t * pGate;
306  int i;
307  vArray = fAllGates? p->vGates : p->vSelect;
308  Vec_PtrForEachEntry( Amap_Gat_t *, vArray, pGate, i )
309  {
310  printf( "%3d :%12s %d %9.2f ", i, pGate->pName, pGate->nPins, pGate->dArea );
311  printf( "%4s=%40s ", pGate->pOutName, pGate->pForm );
312  printf( "DSD: " );
313  Kit_DsdPrintFromTruth( pGate->pFunc, pGate->nPins );
314  printf( "\n" );
315  }
316 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
char * pForm
Definition: amapInt.h:157
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * pOutName
Definition: amapInt.h:155
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
unsigned * pFunc
Definition: amapInt.h:158
unsigned nPins
Definition: amapInt.h:161
double dArea
Definition: amapInt.h:156
char * pName
Definition: amapInt.h:154
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Amap_Lib_t* Amap_LibReadAndPrepare ( char *  pFileName,
char *  pBuffer,
int  fVerbose,
int  fVeryVerbose 
)

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

Synopsis [Parses equations for the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 329 of file amapLib.c.

330 {
331  Amap_Lib_t * p;
332  abctime clk = Abc_Clock();
333  if ( pBuffer == NULL )
334  p = Amap_LibReadFile( pFileName, fVerbose );
335  else
336  {
337  p = Amap_LibReadBuffer( pBuffer, fVerbose );
338  if ( p )
339  p->pName = Abc_UtilStrsav( pFileName );
340  }
341  if ( fVerbose )
342  printf( "Read %d gates from file \"%s\".\n", Vec_PtrSize(p->vGates), pFileName );
343  if ( p == NULL )
344  return NULL;
345  if ( !Amap_LibParseEquations( p, fVerbose ) )
346  {
347  Amap_LibFree( p );
348  return NULL;
349  }
350  p->vSorted = Amap_LibSortGatesByArea( p );
351  p->vSelect = Amap_LibSelectGates( p, fVerbose );
352  if ( fVerbose )
353  {
354  printf( "Selected %d functionally unique gates. ", Vec_PtrSize(p->vSelect) );
355  ABC_PRT( "Time", Abc_Clock() - clk );
356 // Amap_LibPrintSelectedGates( p, 0 );
357  }
358  clk = Abc_Clock();
359  Amap_LibCreateRules( p, fVeryVerbose );
360  if ( fVerbose )
361  {
362  printf( "Created %d rules and %d matches. ", p->nNodes, p->nSets );
363  ABC_PRT( "Time", Abc_Clock() - clk );
364  }
365  return p;
366 }
Amap_Lib_t * Amap_LibReadFile(char *pFileName, int fVerbose)
Definition: amapRead.c:473
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Amap_LibFree(Amap_Lib_t *p)
Definition: amapLib.c:67
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Vec_Ptr_t * Amap_LibSortGatesByArea(Amap_Lib_t *pLib)
Definition: amapLib.c:220
typedefABC_NAMESPACE_HEADER_START struct Amap_Lib_t_ Amap_Lib_t
INCLUDES ///.
Definition: amap.h:42
Vec_Ptr_t * Amap_LibSelectGates(Amap_Lib_t *p, int fVerbose)
Definition: amapLib.c:261
#define ABC_PRT(a, t)
Definition: abc_global.h:220
Amap_Lib_t * Amap_LibReadBuffer(char *pBuffer, int fVerbose)
Definition: amapRead.c:446
int Amap_LibParseEquations(Amap_Lib_t *p, int fVerbose)
Definition: amapParse.c:392
void Amap_LibCreateRules(Amap_Lib_t *p, int fVeryVerbose)
Definition: amapRule.c:426
ABC_INT64_T abctime
Definition: abc_global.h:278
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
Vec_Ptr_t* Amap_LibSelectGates ( Amap_Lib_t p,
int  fVerbose 
)

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

Synopsis [Selects gates useful for area-only mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 261 of file amapLib.c.

262 {
263  Vec_Ptr_t * vSelect;
264  Amap_Gat_t * pGate, * pGate2;
265  int i, k;//, clk = Abc_Clock();
266  p->pGate0 = Amap_LibFindGate( p, 0 );
267  p->pGate1 = Amap_LibFindGate( p, ~0 );
268  p->pGateBuf = Amap_LibFindGate( p, 0xAAAAAAAA );
269  p->pGateInv = Amap_LibFindGate( p, ~0xAAAAAAAA );
270  vSelect = Vec_PtrAlloc( 100 );
271  Vec_PtrForEachEntry( Amap_Gat_t *, p->vSorted, pGate, i )
272  {
273  if ( pGate->pFunc == NULL || pGate->pTwin != NULL )
274  continue;
275  Vec_PtrForEachEntryStop( Amap_Gat_t *, p->vSorted, pGate2, k, i )
276  {
277  if ( pGate2->pFunc == NULL || pGate2->pTwin != NULL )
278  continue;
279  if ( pGate2->nPins != pGate->nPins )
280  continue;
281  if ( !memcmp( pGate2->pFunc, pGate->pFunc, sizeof(unsigned) * Abc_TruthWordNum(pGate->nPins) ) )
282  break;
283  }
284  if ( k < i )
285  continue;
286  Vec_PtrPush( vSelect, pGate );
287  }
288  return vSelect;
289 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Amap_Gat_t * Amap_LibFindGate(Amap_Lib_t *p, unsigned uTruth)
Definition: amapLib.c:240
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_TruthWordNum(int nVars)
Definition: abc_global.h:256
Amap_Gat_t * pTwin
Definition: amapInt.h:153
int memcmp()
unsigned * pFunc
Definition: amapInt.h:158
unsigned nPins
Definition: amapInt.h:161
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
Definition: vecPtr.h:59
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Vec_Ptr_t* Amap_LibSortGatesByArea ( Amap_Lib_t pLib)

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

Synopsis [Compares gates by area.]

Description []

SideEffects []

SeeAlso []

Definition at line 220 of file amapLib.c.

221 {
222  Vec_Ptr_t * vSorted;
223  vSorted = Vec_PtrDup( pLib->vGates );
224  qsort( (void *)Vec_PtrArray(vSorted), Vec_PtrSize(vSorted), sizeof(void *),
225  (int (*)(const void *, const void *)) Amap_LibCompareGatesByArea );
226  return vSorted;
227 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Vec_Ptr_t * Vec_PtrDup(Vec_Ptr_t *pVec)
Definition: vecPtr.h:169
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int Amap_LibCompareGatesByArea(Amap_Gat_t **pp1, Amap_Gat_t **pp2)
Definition: amapLib.c:199
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
void Amap_LibWrite ( FILE *  pFile,
Amap_Lib_t pLib,
int  fPrintDsd 
)

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

Synopsis [Writes library.]

Description []

SideEffects []

SeeAlso []

Definition at line 179 of file amapLib.c.

180 {
181  Amap_Gat_t * pGate;
182  int i;
183  fprintf( pFile, "# The genlib library \"%s\".\n", pLib->pName );
184  Amap_LibForEachGate( pLib, pGate, i )
185  Amap_LibWriteGate( pFile, pGate, fPrintDsd );
186 }
#define Amap_LibForEachGate(pLib, pGate, i)
Definition: amapInt.h:293
void Amap_LibWriteGate(FILE *pFile, Amap_Gat_t *pGate, int fPrintDsd)
Definition: amapLib.c:150
void Amap_LibWriteGate ( FILE *  pFile,
Amap_Gat_t pGate,
int  fPrintDsd 
)

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

Synopsis [Writes one gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 150 of file amapLib.c.

151 {
152  Amap_Pin_t * pPin;
153  fprintf( pFile, "GATE " );
154  fprintf( pFile, "%12s ", pGate->pName );
155  fprintf( pFile, "%10.2f ", pGate->dArea );
156  fprintf( pFile, "%s=%s;\n", pGate->pOutName, pGate->pForm );
157  if ( fPrintDsd )
158  {
159  if ( pGate->pFunc == NULL )
160  printf( "Truth table is not available.\n" );
161  else
162  Kit_DsdPrintFromTruth( pGate->pFunc, pGate->nPins );
163  }
164  Amap_GateForEachPin( pGate, pPin )
165  Amap_LibWritePin( pFile, pPin );
166 }
char * pForm
Definition: amapInt.h:157
#define Amap_GateForEachPin(pGate, pPin)
Definition: amapInt.h:296
char * pOutName
Definition: amapInt.h:155
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
unsigned * pFunc
Definition: amapInt.h:158
unsigned nPins
Definition: amapInt.h:161
double dArea
Definition: amapInt.h:156
void Amap_LibWritePin(FILE *pFile, Amap_Pin_t *pPin)
Definition: amapLib.c:124
char * pName
Definition: amapInt.h:154
void Amap_LibWritePin ( FILE *  pFile,
Amap_Pin_t pPin 
)

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

Synopsis [Writes one pin.]

Description []

SideEffects []

SeeAlso []

Definition at line 124 of file amapLib.c.

125 {
126  char * pPhaseNames[10] = { "UNKNOWN", "INV", "NONINV" };
127  fprintf( pFile, " PIN " );
128  fprintf( pFile, "%9s ", pPin->pName );
129  fprintf( pFile, "%10s ", pPhaseNames[pPin->Phase] );
130  fprintf( pFile, "%6d ", (int)pPin->dLoadInput );
131  fprintf( pFile, "%6d ", (int)pPin->dLoadMax );
132  fprintf( pFile, "%6.2f ", pPin->dDelayBlockRise );
133  fprintf( pFile, "%6.2f ", pPin->dDelayFanoutRise );
134  fprintf( pFile, "%6.2f ", pPin->dDelayBlockFall );
135  fprintf( pFile, "%6.2f", pPin->dDelayFanoutFall );
136  fprintf( pFile, "\n" );
137 }
double dLoadInput
Definition: amapInt.h:142
int Phase
Definition: amapInt.h:141
double dDelayBlockRise
Definition: amapInt.h:144
double dLoadMax
Definition: amapInt.h:143
double dDelayFanoutFall
Definition: amapInt.h:147
char * pName
Definition: amapInt.h:140
double dDelayFanoutRise
Definition: amapInt.h:145
double dDelayBlockFall
Definition: amapInt.h:146