abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mapperLib.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mapperLib.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Generic technology mapping engine.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - June 1, 2004.]
14 
15  Revision [$Id: mapperLib.c,v 1.6 2005/01/23 06:59:44 alanmi Exp $]
16 
17 ***********************************************************************/
18 #define _BSD_SOURCE
19 
20 #ifndef WIN32
21 #include <unistd.h>
22 #endif
23 
24 #include "mapperInt.h"
25 #include "map/super/super.h"
26 #include "map/mapper/mapperInt.h"
27 
29 
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// DECLARATIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// FUNCTION DEFINITIONS ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41  Synopsis [Reads in the supergate library and prepares it for use.]
42 
43  Description [The supergates library comes in a .super file. This file
44  contains descriptions of supergates along with some relevant information.
45  This procedure reads the supergate file, canonicizes the supergates,
46  and constructs an additional lookup table, which can be used to map
47  truth tables of the cuts into the pair (phase, supergate). The phase
48  indicates how the current truth table should be phase assigned to
49  match the canonical form of the supergate. The resulting phase is the
50  bitwise EXOR of the phase needed to canonicize the supergate and the
51  phase needed to transform the truth table into its canonical form.]
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
58 Map_SuperLib_t * Map_SuperLibCreate( Mio_Library_t * pGenlib, Vec_Str_t * vStr, char * pFileName, char * pExcludeFile, int fAlgorithm, int fVerbose )
59 {
60  Map_SuperLib_t * p;
61  abctime clk;
62 
63  // start the supergate library
64  p = ABC_ALLOC( Map_SuperLib_t, 1 );
65  memset( p, 0, sizeof(Map_SuperLib_t) );
66  p->pName = Abc_UtilStrsav(pFileName);
67  p->fVerbose = fVerbose;
68  p->mmSupers = Extra_MmFixedStart( sizeof(Map_Super_t) );
72 
73  // start the hash table
74  p->tTableC = Map_SuperTableCreate( p );
75  p->tTable = Map_SuperTableCreate( p );
76 
77  // read the supergate library from file
78 clk = Abc_Clock();
79  if ( vStr != NULL )
80  {
81  // read the supergate library from file
82  int Status = Map_LibraryReadFileTreeStr( p, pGenlib, vStr, pFileName );
83  if ( Status == 0 )
84  {
85  Map_SuperLibFree( p );
86  return NULL;
87  }
88  // prepare the info about the library
89  Status = Map_LibraryDeriveGateInfo( p, NULL );
90  if ( Status == 0 )
91  {
92  Map_SuperLibFree( p );
93  return NULL;
94  }
95  assert( p->nVarsMax > 0 );
96  }
97  else if ( fAlgorithm )
98  {
99  if ( !Map_LibraryReadTree( p, pGenlib, pFileName, pExcludeFile ) )
100  {
101  Map_SuperLibFree( p );
102  return NULL;
103  }
104  }
105  else
106  {
107  if ( pExcludeFile != 0 )
108  {
109  Map_SuperLibFree( p );
110  printf ("Error: Exclude file support not present for old format. Stop.\n");
111  return NULL;
112  }
113  if ( !Map_LibraryRead( p, pFileName ) )
114  {
115  Map_SuperLibFree( p );
116  return NULL;
117  }
118  }
119  assert( p->nVarsMax > 0 );
120 
121  // report the stats
122  if ( fVerbose )
123  {
124  printf( "Loaded %d unique %d-input supergates from \"%s\". ",
125  p->nSupersReal, p->nVarsMax, pFileName );
126  ABC_PRT( "Time", Abc_Clock() - clk );
127  }
128 
129  // assign the interver parameters
136 
137  // assign the interver supergate
139  memset( p->pSuperInv, 0, sizeof(Map_Super_t) );
140  p->pSuperInv->Num = -1;
141  p->pSuperInv->nGates = 1;
142  p->pSuperInv->nFanins = 1;
143  p->pSuperInv->nFanLimit = 10;
144  p->pSuperInv->pFanins[0] = p->ppSupers[0];
145  p->pSuperInv->pRoot = p->pGateInv;
146  p->pSuperInv->Area = p->AreaInv;
147  p->pSuperInv->tDelayMax = p->tDelayInv;
149  p->pSuperInv->tDelaysR[0].Fall = p->tDelayInv.Rise;
150  p->pSuperInv->tDelaysF[0].Rise = p->tDelayInv.Fall;
152  return p;
153 }
154 
155 
156 /**Function*************************************************************
157 
158  Synopsis [Deallocates the supergate library.]
159 
160  Description []
161 
162  SideEffects []
163 
164  SeeAlso []
165 
166 ***********************************************************************/
168 {
169  if ( p == NULL ) return;
170  if ( p->pGenlib )
171  {
172  if ( p->pGenlib != Abc_FrameReadLibGen() )
174  p->pGenlib = NULL;
175  }
176  if ( p->tTableC )
178  if ( p->tTable )
183  ABC_FREE( p->ppSupers );
184  ABC_FREE( p->pName );
185  ABC_FREE( p );
186 }
187 
188 /**Function*************************************************************
189 
190  Synopsis [Derives the library from the genlib library.]
191 
192  Description []
193 
194  SideEffects []
195 
196  SeeAlso []
197 
198 ***********************************************************************/
199 int Map_SuperLibDeriveFromGenlib( Mio_Library_t * pLib, int fVerbose )
200 {
201  Map_SuperLib_t * pLibSuper;
202  Vec_Str_t * vStr;
203  char * pFileName;
204  if ( pLib == NULL )
205  return 0;
206 
207  // compute supergates
208  vStr = Super_PrecomputeStr( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0 );
209  if ( vStr == NULL )
210  return 0;
211 
212  // create supergate library
213  pFileName = Extra_FileNameGenericAppend( Mio_LibraryReadName(pLib), ".super" );
214  pLibSuper = Map_SuperLibCreate( pLib, vStr, pFileName, NULL, 1, 0 );
215  Vec_StrFree( vStr );
216 
217  // replace the library
219  Abc_FrameSetLibSuper( pLibSuper );
220  return 1;
221 }
222 
223 /**Function*************************************************************
224 
225  Synopsis [Derives the library from the genlib library.]
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
234 int Map_SuperLibDeriveFromGenlib2( Mio_Library_t * pLib, int fVerbose )
235 {
237  char * pFileName;
238  if ( pLib == NULL )
239  return 0;
240  // compute supergates
241  pFileName = Extra_FileNameGenericAppend(Mio_LibraryReadName(pLib), ".super");
242  Super_Precompute( pLib, 5, 1, 100000000, 10000000, 10000000, 100, 1, 0, pFileName );
243  // assuming that it terminated successfully
244  if ( Cmd_CommandExecute( pAbc, pFileName ) )
245  {
246  fprintf( stdout, "Cannot execute command \"read_super %s\".\n", pFileName );
247  return 0;
248  }
249  return 1;
250 }
251 
252 ////////////////////////////////////////////////////////////////////////
253 /// END OF FILE ///
254 ////////////////////////////////////////////////////////////////////////
255 
256 
258 
char * memset()
#define MAP_NO_VAR
Definition: mapperInt.h:53
ABC_DLL void Abc_FrameSetLibSuper(void *pLib)
Definition: mainFrame.c:84
float Mio_LibraryReadAreaBuf(Mio_Library_t *pLib)
Definition: mioApi.c:61
int Map_LibraryDeriveGateInfo(Map_SuperLib_t *pLib, st__table *tExcludeGate)
Definition: mapperTree.c:586
ABC_DLL void * Abc_FrameReadLibGen()
Definition: mainFrame.c:56
void Mio_LibraryDelete(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition: mioUtils.c:48
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
unsigned nFanins
Definition: mapperInt.h:280
Map_Super_t * pSuperInv
Definition: mapperInt.h:192
void Extra_MmFixedStop(Extra_MmFixed_t *p)
Extra_MmFlex_t * Extra_MmFlexStart()
void Super_Precompute(Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: superGate.c:140
Map_Time_t tDelaysF[6]
Definition: mapperInt.h:291
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
float Mio_LibraryReadAreaInv(Mio_Library_t *pLib)
Definition: mioApi.c:60
float Mio_LibraryReadDelayInvFall(Mio_Library_t *pLib)
Definition: mioApi.c:54
static abctime Abc_Clock()
Definition: abc_global.h:279
Map_Super_t ** ppSupers
Definition: mapperInt.h:179
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
char * Mio_LibraryReadName(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition: mioApi.c:43
Map_Time_t tDelayMax
Definition: mapperInt.h:292
int Map_LibraryReadTree(Map_SuperLib_t *pLib, Mio_Library_t *pGenlib, char *pFileName, char *pExcludeFile)
Definition: mapperTree.c:525
unsigned uTruths[6][2]
Definition: mapperInt.h:184
Mio_Gate_t * pRoot
Definition: mapperInt.h:288
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
int Map_SuperLibDeriveFromGenlib2(Mio_Library_t *pLib, int fVerbose)
Definition: mapperLib.c:234
ABC_NAMESPACE_IMPL_START Map_SuperLib_t * Map_SuperLibCreate(Mio_Library_t *pGenlib, Vec_Str_t *vStr, char *pFileName, char *pExcludeFile, int fAlgorithm, int fVerbose)
DECLARATIONS ///.
Definition: mapperLib.c:58
Mio_Library_t * pGenlib
Definition: mapperInt.h:169
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
Map_HashTable_t * Map_SuperTableCreate(Map_SuperLib_t *pLib)
FUNCTION DEFINITIONS ///.
Definition: mapperTable.c:48
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
unsigned nFanLimit
Definition: mapperInt.h:282
int Map_LibraryRead(Map_SuperLib_t *p, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: mapperSuper.c:50
Vec_Str_t * Super_PrecomputeStr(Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose)
Definition: superGate.c:172
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Extra_MmFixed_t * mmSupers
Definition: mapperInt.h:195
void * Abc_FrameGetGlobalFrame()
Definition: mainFrame.c:593
void Map_SuperLibFree(Map_SuperLib_t *p)
Definition: mapperLib.c:167
ABC_DLL void * Abc_FrameReadLibSuper()
Definition: mainFrame.c:58
Map_Super_t * pFanins[6]
Definition: mapperInt.h:287
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
Map_HashTable_t * tTable
Definition: mapperInt.h:181
Mio_Gate_t * pGateInv
Definition: mapperInt.h:188
float Mio_LibraryReadDelayInvRise(Mio_Library_t *pLib)
Definition: mioApi.c:53
Extra_MmFixed_t * mmEntries
Definition: mapperInt.h:196
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Map_SuperLibDeriveFromGenlib(Mio_Library_t *pLib, int fVerbose)
Definition: mapperLib.c:199
void Map_SuperTableFree(Map_HashTable_t *p)
Definition: mapperTable.c:74
#define assert(ex)
Definition: util_old.h:213
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
Map_Time_t tDelaysR[6]
Definition: mapperInt.h:290
int Map_LibraryReadFileTreeStr(Map_SuperLib_t *pLib, Mio_Library_t *pGenlib, Vec_Str_t *vStr, char *pFileName)
Definition: mapperTree.c:391
Map_HashTable_t * tTableC
Definition: mapperInt.h:180
ABC_INT64_T abctime
Definition: abc_global.h:278
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
Mio_Gate_t * Mio_LibraryReadInv(Mio_Library_t *pLib)
Definition: mioApi.c:48
Extra_MmFlex_t * mmForms
Definition: mapperInt.h:197
void Extra_MmFlexStop(Extra_MmFlex_t *p)
void Map_MappingSetupTruthTables(unsigned uTruths[][2])
Definition: mapperUtils.c:335
#define MAP_MAX(a, b)
Definition: mapperInt.h:57
Map_Time_t tDelayInv
Definition: mapperInt.h:189