abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mpmGates.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mpmGates.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Configurable technology mapper.]
8 
9  Synopsis [Standard-cell mapping.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 1, 2013.]
16 
17  Revision [$Id: mpmGates.c,v 1.00 2013/06/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "mpmInt.h"
22 #include "misc/st/st.h"
23 #include "map/mio/mio.h"
24 #include "map/scl/sclSize.h"
25 #include "map/scl/sclTime.h"
26 
28 
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// DECLARATIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Finds matches fore each DSD class.]
41 
42  Description []
43 
44  SideEffects []
45 
46  SeeAlso []
47 
48 ***********************************************************************/
50 {
51  int fVerbose = p->pPars->fVeryVerbose;
52  SC_Lib * pLib = (SC_Lib *)pScl;
53  Vec_Wec_t * vClasses;
54  Vec_Int_t * vClass;
55  SC_Cell * pRepr;
56  int i, Config, iClass;
57  word Truth;
58  vClasses = Vec_WecStart( 600 );
59  SC_LibForEachCellClass( pLib, pRepr, i )
60  {
61  if ( pRepr->n_inputs > 6 || pRepr->n_outputs > 1 )
62  {
63  if ( fVerbose )
64  printf( "Skipping cell %s with %d inputs and %d outputs\n", pRepr->pName, pRepr->n_inputs, pRepr->n_outputs );
65  continue;
66  }
67  Truth = *Vec_WrdArray( SC_CellPin(pRepr, pRepr->n_inputs)->vFunc );
68  Config = Mpm_CutCheckDsd6( p, Truth );
69  if ( Config == -1 )
70  {
71  if ( fVerbose )
72  printf( "Skipping cell %s with non-DSD function\n", pRepr->pName );
73  continue;
74  }
75  iClass = Config >> 17;
76  Config = (pRepr->Id << 17) | (Config & 0x1FFFF);
77  // write gate and NPN config for this DSD class
78  vClass = Vec_WecEntry( vClasses, iClass );
79  Vec_IntPush( vClass, Config );
80  if ( !fVerbose )
81  continue;
82 
83  printf( "Gate %5d %-30s : ", pRepr->Id, pRepr->pName );
84  printf( "Class %3d ", iClass );
85  printf( "Area %10.3f ", pRepr->area );
86  Extra_PrintBinary( stdout, (unsigned *)&Config, 17 );
87  printf( " " );
88  Kit_DsdPrintFromTruth( (unsigned *)&Truth, pRepr->n_inputs ); printf( "\n" );
89  }
90  return vClasses;
91 }
92 
93 /**Function*************************************************************
94 
95  Synopsis [Find mapping of DSD classes into Genlib library cells.]
96 
97  Description []
98 
99  SideEffects []
100 
101  SeeAlso []
102 
103 ***********************************************************************/
104 Vec_Ptr_t * Mpm_ManFindCells( Mio_Library_t * pMio, SC_Lib * pScl, Vec_Wec_t * vNpnConfigs )
105 {
106  Vec_Ptr_t * vNpnGatesMio;
107  Vec_Int_t * vClass;
108  Mio_Gate_t * pMioGate;
109  SC_Cell * pCell;
110  int Config, iClass;
111  vNpnGatesMio = Vec_PtrStart( Vec_WecSize(vNpnConfigs) );
112  Vec_WecForEachLevel( vNpnConfigs, vClass, iClass )
113  {
114  if ( Vec_IntSize(vClass) == 0 )
115  continue;
116  Config = Vec_IntEntry(vClass, 0);
117  pCell = SC_LibCell( pScl, (Config >> 17) );
118  pMioGate = Mio_LibraryReadGateByName( pMio, pCell->pName, NULL );
119  if ( pMioGate == NULL )
120  {
121  Vec_PtrFree( vNpnGatesMio );
122  return NULL;
123  }
124  assert( pMioGate != NULL );
125  Vec_PtrWriteEntry( vNpnGatesMio, iClass, pMioGate );
126  }
127  return vNpnGatesMio;
128 }
129 
130 /**Function*************************************************************
131 
132  Synopsis [Derive mapped network as an ABC network.]
133 
134  Description []
135 
136  SideEffects []
137 
138  SeeAlso []
139 
140 ***********************************************************************/
142 {
143  Vec_Int_t * vNodes;
144  Mig_Obj_t * pObj;
145  vNodes = Vec_IntAlloc( 1000 );
146  Mig_ManForEachObj( p->pMig, pObj )
147  if ( Mig_ObjIsNode(pObj) && Mpm_ObjMapRef(p, pObj) )
148  Vec_IntPush( vNodes, Mig_ObjId(pObj) );
149  return vNodes;
150 }
151 Abc_Obj_t * Mpm_ManGetAbcNode( Abc_Ntk_t * pNtk, Vec_Int_t * vCopy, int iMigLit )
152 {
153  Abc_Obj_t * pObj;
154  int iObjId = Vec_IntEntry( vCopy, iMigLit );
155  if ( iObjId >= 0 )
156  return Abc_NtkObj( pNtk, iObjId );
157  iObjId = Vec_IntEntry( vCopy, Abc_LitNot(iMigLit) );
158  assert( iObjId >= 0 );
159  pObj = Abc_NtkCreateNodeInv( pNtk, Abc_NtkObj(pNtk, iObjId) );
160  Vec_IntWriteEntry( vCopy, iMigLit, Abc_ObjId(pObj) );
161  return pObj;
162 }
164 {
165  Abc_Ntk_t * pNtk;
166  Vec_Ptr_t * vNpnGatesMio;
167  Vec_Int_t * vNodes, * vCopy, * vClass;
168  Abc_Obj_t * pObj, * pFanin;
169  Mig_Obj_t * pNode;
170  Mpm_Cut_t * pCutBest;
171  int i, k, iNode, iMigLit, fCompl, Config;
172 
173  // find mapping of SCL cells into MIO cells
174  vNpnGatesMio = Mpm_ManFindCells( pMio, (SC_Lib *)p->pPars->pScl, p->vNpnConfigs );
175  if ( vNpnGatesMio == NULL )
176  {
177  printf( "Genlib library does not match SCL library.\n" );
178  return NULL;
179  }
180 
181  // create mapping for each phase of each node
182  vCopy = Vec_IntStartFull( 2 * Mig_ManObjNum(p->pMig) );
183 
184  // get internal nodes
185  vNodes = Mpm_ManFindMappedNodes( p );
186 
187  // start the network
189  pNtk->pName = Extra_UtilStrsav( p->pMig->pName );
190  pNtk->pManFunc = pMio;
191 
192  // create primary inputs
193  Mig_ManForEachCi( p->pMig, pNode, i )
194  {
195  pObj = Abc_NtkCreatePi(pNtk);
196  Vec_IntWriteEntry( vCopy, Abc_Var2Lit( Mig_ObjId(pNode), 0 ), Abc_ObjId(pObj) );
197  }
198  Abc_NtkAddDummyPiNames( pNtk );
199 
200  // create constant nodes
201  Mig_ManForEachCo( p->pMig, pNode, i )
202  if ( Mig_ObjFaninLit(pNode, 0) == 0 )
203  {
204  pObj = Abc_NtkCreateNodeConst0(pNtk);
205  Vec_IntWriteEntry( vCopy, Abc_Var2Lit( 0, 0 ), Abc_ObjId(pObj) );
206  break;
207  }
208  Mig_ManForEachCo( p->pMig, pNode, i )
209  if ( Mig_ObjFaninLit(pNode, 0) == 1 )
210  {
211  pObj = Abc_NtkCreateNodeConst1(pNtk);
212  Vec_IntWriteEntry( vCopy, Abc_Var2Lit( 0, 1 ), Abc_ObjId(pObj) );
213  break;
214  }
215 
216  // create internal nodes
217  Vec_IntForEachEntry( vNodes, iNode, i )
218  {
219  pCutBest = Mpm_ObjCutBestP( p, Mig_ManObj(p->pMig, iNode) );
220  vClass = Vec_WecEntry( p->vNpnConfigs, Abc_Lit2Var(pCutBest->iFunc) );
221  Config = Vec_IntEntry( vClass, 0 );
222  pObj = Abc_NtkCreateNode( pNtk );
223  pObj->pData = Vec_PtrEntry( vNpnGatesMio, Abc_Lit2Var(pCutBest->iFunc) );
224  assert( pObj->pData != NULL );
225  fCompl = pCutBest->fCompl ^ Abc_LitIsCompl(pCutBest->iFunc) ^ ((Config >> 16) & 1);
226  Config &= 0xFFFF;
227  for ( k = 0; k < (int)pCutBest->nLeaves; k++ )
228  {
229  assert( (Config >> 6) < 720 );
230  iMigLit = pCutBest->pLeaves[ (int)(p->Perm6[Config >> 6][k]) ];
231  pFanin = Mpm_ManGetAbcNode( pNtk, vCopy, Abc_LitNotCond(iMigLit, (Config >> k) & 1) );
232  Abc_ObjAddFanin( pObj, pFanin );
233  }
234  Vec_IntWriteEntry( vCopy, Abc_Var2Lit(iNode, fCompl), Abc_ObjId(pObj) );
235  }
236 
237  // create primary outputs
238  Mig_ManForEachCo( p->pMig, pNode, i )
239  {
240  pObj = Abc_NtkCreatePo(pNtk);
241  pFanin = Mpm_ManGetAbcNode( pNtk, vCopy, Mig_ObjFaninLit(pNode, 0) );
242  Abc_ObjAddFanin( pObj, pFanin );
243  }
244  Abc_NtkAddDummyPoNames( pNtk );
245 
246  // clean up
247  Vec_PtrFree( vNpnGatesMio );
248  Vec_IntFree( vNodes );
249  Vec_IntFree( vCopy );
250  return pNtk;
251 }
252 
253 /**Function*************************************************************
254 
255  Synopsis []
256 
257  Description []
258 
259  SideEffects []
260 
261  SeeAlso []
262 
263 ***********************************************************************/
265 {
266  Abc_Ntk_t * pNew;
267  Mpm_Man_t * p;
268  assert( pPars->fMap4Gates );
269  p = Mpm_ManStart( pMig, pPars );
270  if ( p->pPars->fVerbose )
273  Mpm_ManPrepare( p );
274  Mpm_ManPerform( p );
275  if ( p->pPars->fVerbose )
276  Mpm_ManPrintStats( p );
277  pNew = Mpm_ManDeriveMappedAbcNtk( p, pMio );
278  Mpm_ManStop( p );
279  return pNew;
280 }
281 Abc_Ntk_t * Mpm_ManCellMapping( Gia_Man_t * pGia, Mpm_Par_t * pPars, void * pMio )
282 {
283  Mig_Man_t * p;
284  Abc_Ntk_t * pNew;
285  assert( pMio != NULL );
286  assert( pPars->pLib->LutMax <= MPM_VAR_MAX );
287  assert( pPars->nNumCuts <= MPM_CUT_MAX );
288  if ( pPars->fUseGates )
289  {
290  pGia = Gia_ManDupMuxes( pGia, 2 );
291  p = Mig_ManCreate( pGia );
292  Gia_ManStop( pGia );
293  }
294  else
295  p = Mig_ManCreate( pGia );
296  pNew = Mpm_ManPerformCellMapping( p, pPars, (Mio_Library_t *)pMio );
297  Mig_ManStop( p );
298  return pNew;
299 }
300 
301 ////////////////////////////////////////////////////////////////////////
302 /// END OF FILE ///
303 ////////////////////////////////////////////////////////////////////////
304 
305 
307 
Abc_Ntk_t * Mpm_ManPerformCellMapping(Mig_Man_t *pMig, Mpm_Par_t *pPars, Mio_Library_t *pMio)
Definition: mpmGates.c:264
static unsigned Abc_ObjId(Abc_Obj_t *pObj)
Definition: abc.h:329
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
Definition: mioApi.c:99
Abc_Ntk_t * Mpm_ManDeriveMappedAbcNtk(Mpm_Man_t *p, Mio_Library_t *pMio)
Definition: mpmGates.c:163
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
static int Mig_ManObjNum(Mig_Man_t *p)
Definition: mpmMig.h:109
Mpm_Par_t * pPars
Definition: mpmInt.h:98
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition: vecWec.h:42
int Mpm_CutCheckDsd6(Mpm_Man_t *p, word t)
Definition: mpmDsd.c:905
static Mig_Obj_t * Mig_ManObj(Mig_Man_t *p, int v)
Definition: mpmMig.h:116
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static Llb_Mgr_t * p
Definition: llb3Image.c:950
ABC_NAMESPACE_IMPL_START Vec_Wec_t * Mpm_ManFindDsdMatches(Mpm_Man_t *p, void *pScl)
DECLARATIONS ///.
Definition: mpmGates.c:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Mig_ManForEachCo(p, pObj, i)
Definition: mpmMig.h:329
void Mpm_ManPrepare(Mpm_Man_t *p)
Definition: mpmMap.c:794
static Vec_Wec_t * Vec_WecStart(int nSize)
Definition: vecWec.h:98
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Mig_ObjIsNode(Mig_Obj_t *p)
Definition: mpmMig.h:137
#define Mig_ManForEachObj(p, pObj)
MACRO DEFINITIONS ///.
Definition: mpmMig.h:304
Vec_Ptr_t * Mpm_ManFindCells(Mio_Library_t *pMio, SC_Lib *pScl, Vec_Wec_t *vNpnConfigs)
Definition: mpmGates.c:104
unsigned fCompl
Definition: mpmInt.h:66
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition: abcObj.c:633
int nNumCuts
Definition: mpm.h:61
#define SC_LibForEachCellClass(p, pCell, i)
Definition: sclLib.h:249
int fVerbose
Definition: mpm.h:72
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
static Vec_Int_t * Vec_IntStartFull(int nSize)
Definition: vecInt.h:119
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Mig_ObjId(Mig_Obj_t *p)
Definition: mpmMig.h:146
Abc_Ntk_t * Mpm_ManCellMapping(Gia_Man_t *pGia, Mpm_Par_t *pPars, void *pMio)
Definition: mpmGates.c:281
static int Vec_WecSize(Vec_Wec_t *p)
Definition: vecWec.h:193
char * Extra_UtilStrsav(const char *s)
Abc_Obj_t * Mpm_ManGetAbcNode(Abc_Ntk_t *pNtk, Vec_Int_t *vCopy, int iMigLit)
Definition: mpmGates.c:151
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
void * pScl
Definition: mpm.h:60
Vec_Wrd_t * vFunc
Definition: sclLib.h:177
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
void * pManFunc
Definition: abc.h:191
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:398
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
float area
Definition: sclLib.h:188
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition: vecWec.h:55
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:662
Vec_Wec_t * vNpnConfigs
Definition: mpmInt.h:140
void Mig_ManStop(Mig_Man_t *p)
Definition: mpmMig.c:56
int fUseGates
Definition: mpm.h:63
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition: giaMuxes.c:96
int Id
Definition: sclLib.h:184
STRUCTURE DEFINITIONS ///.
Definition: mioInt.h:61
int fMap4Gates
Definition: mpm.h:71
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
char * pName
Definition: sclLib.h:183
Vec_Int_t * Mpm_ManFindMappedNodes(Mpm_Man_t *p)
Definition: mpmGates.c:141
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
static SC_Pin * SC_CellPin(SC_Cell *p, int i)
Definition: sclLib.h:241
void Mpm_ManStop(Mpm_Man_t *p)
Definition: mpmMan.c:111
void Mpm_ManPrintStats(Mpm_Man_t *p)
Definition: mpmMan.c:173
Definition: mpm.h:57
static SC_Cell * SC_LibCell(SC_Lib *p, int i)
Definition: sclLib.h:240
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Vec_Int_t * Vec_WecEntry(Vec_Wec_t *p, int i)
Definition: vecWec.h:142
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int n_outputs
Definition: sclLib.h:193
Mpm_Man_t * Mpm_ManStart(Mig_Man_t *pMig, Mpm_Par_t *pPars)
DECLARATIONS ///.
Definition: mpmMan.c:45
char * pName
Definition: mpmMig.h:63
char Perm6[720][6]
Definition: mpmInt.h:136
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
#define MPM_CUT_MAX
INCLUDES ///.
Definition: mpmInt.h:50
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Mig_Man_t * pMig
Definition: mpmInt.h:97
static int Mpm_ObjMapRef(Mpm_Man_t *p, Mig_Obj_t *pObj)
Definition: mpmInt.h:189
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
static word * Vec_WrdArray(Vec_Wrd_t *p)
Definition: vecWrd.h:316
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition: abcObj.c:604
void Mpm_ManPerform(Mpm_Man_t *p)
Definition: mpmMap.c:833
Definition: gia.h:95
#define MPM_VAR_MAX
INCLUDES ///.
Definition: mpm.h:40
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
Mpm_LibLut_t * pLib
Definition: mpm.h:59
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define Mig_ManForEachCi(p, pObj, i)
Definition: mpmMig.h:327
int n_inputs
Definition: sclLib.h:192
static Mpm_Cut_t * Mpm_ObjCutBestP(Mpm_Man_t *p, Mig_Obj_t *pObj)
Definition: mpmInt.h:176
int pLeaves[1]
Definition: mpmInt.h:69
#define assert(ex)
Definition: util_old.h:213
int LutMax
Definition: mpm.h:50
unsigned nLeaves
Definition: mpmInt.h:68
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Mig_Man_t * Mig_ManCreate(void *pGia)
FUNCTION DECLARATIONS ///.
Definition: mpmAbc.c:83
void Mpm_ManPrintStatsInit(Mpm_Man_t *p)
Definition: mpmMan.c:166
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:378
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
unsigned iFunc
Definition: mpmInt.h:65
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
int fVeryVerbose
Definition: mpm.h:73
char * pName
Definition: abc.h:158
static int Mig_ObjFaninLit(Mig_Obj_t *p, int i)
Definition: mpmMig.h:183
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223