abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFpgaFast.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcFpgaFast.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Fast FPGA mapper.]
10 
11  Author [Sungmin Cho]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcFpgaFast.c,v 1.00 2006/09/02 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "aig/ivy/ivy.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 extern Ivy_Man_t * Abc_NtkIvyBefore( Abc_Ntk_t * pNtk, int fSeq, int fUseDc );
32 
33 static Abc_Ntk_t * Ivy_ManFpgaToAbc( Abc_Ntk_t * pNtk, Ivy_Man_t * pMan );
34 static Abc_Obj_t * Ivy_ManToAbcFast_rec( Abc_Ntk_t * pNtkNew, Ivy_Man_t * pMan, Ivy_Obj_t * pObjIvy, Vec_Int_t * vNodes );
35 
36 static inline void Abc_ObjSetIvy2Abc( Ivy_Man_t * p, int IvyId, Abc_Obj_t * pObjAbc ) { assert(Vec_PtrEntry((Vec_Ptr_t *)p->pCopy, IvyId) == NULL); assert(!Abc_ObjIsComplement(pObjAbc)); Vec_PtrWriteEntry( (Vec_Ptr_t *)p->pCopy, IvyId, pObjAbc ); }
37 static inline Abc_Obj_t * Abc_ObjGetIvy2Abc( Ivy_Man_t * p, int IvyId ) { return (Abc_Obj_t *)Vec_PtrEntry( (Vec_Ptr_t *)p->pCopy, IvyId ); }
38 
39 ////////////////////////////////////////////////////////////////////////
40 /// FUNCTION DEFINITIONS ///
41 ////////////////////////////////////////////////////////////////////////
42 
43 /**Function*************************************************************
44 
45  Synopsis [Performs fast FPGA mapping of the network.]
46 
47  Description [Takes the AIG to be mapped, the LUT size, and verbosity
48  flag. Produces the new network by fast FPGA mapping of the current
49  network. If the current network in ABC in not an AIG, the user should
50  run command "strash" to make sure that the current network into an AIG
51  before calling this procedure.]
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
58 Abc_Ntk_t * Abc_NtkFpgaFast( Abc_Ntk_t * pNtk, int nLutSize, int fRecovery, int fVerbose )
59 {
60  Ivy_Man_t * pMan;
61  Abc_Ntk_t * pNtkNew;
62  // make sure the network is an AIG
63  assert( Abc_NtkIsStrash(pNtk) );
64  // convert the network into the AIG
65  pMan = Abc_NtkIvyBefore( pNtk, 0, 0 );
66  // perform fast FPGA mapping
67  Ivy_FastMapPerform( pMan, nLutSize, fRecovery, fVerbose );
68  // convert back into the ABC network
69  pNtkNew = Ivy_ManFpgaToAbc( pNtk, pMan );
70  Ivy_FastMapStop( pMan );
71  Ivy_ManStop( pMan );
72  // make sure that the final network passes the test
73  if ( pNtkNew != NULL && !Abc_NtkCheck( pNtkNew ) )
74  {
75  printf( "Abc_NtkFastMap: The network check has failed.\n" );
76  Abc_NtkDelete( pNtkNew );
77  return NULL;
78  }
79  return pNtkNew;
80 }
81 
82 /**Function*************************************************************
83 
84  Synopsis [Constructs the ABC network after mapping.]
85 
86  Description []
87 
88  SideEffects []
89 
90  SeeAlso []
91 
92 ***********************************************************************/
94 {
95  Abc_Ntk_t * pNtkNew;
96  Abc_Obj_t * pObjAbc, * pObj;
97  Ivy_Obj_t * pObjIvy;
98  Vec_Int_t * vNodes;
99  int i;
100  // start mapping from Ivy into Abc
101  pMan->pCopy = Vec_PtrStart( Ivy_ManObjIdMax(pMan) + 1 );
102  // start the new ABC network
103  pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_AIG );
104  // transfer the pointers to the basic nodes
105  Abc_ObjSetIvy2Abc( pMan, Ivy_ManConst1(pMan)->Id, Abc_NtkCreateNodeConst1(pNtkNew) );
106  Abc_NtkForEachCi( pNtkNew, pObjAbc, i )
107  Abc_ObjSetIvy2Abc( pMan, Ivy_ManPi(pMan, i)->Id, pObjAbc );
108  // recursively construct the network
109  vNodes = Vec_IntAlloc( 100 );
110  Ivy_ManForEachPo( pMan, pObjIvy, i )
111  {
112  // get the new ABC node corresponding to the old fanin of the PO in IVY
113  pObjAbc = Ivy_ManToAbcFast_rec( pNtkNew, pMan, Ivy_ObjFanin0(pObjIvy), vNodes );
114  // consider the case of complemented fanin of the PO
115  if ( Ivy_ObjFaninC0(pObjIvy) ) // complement
116  {
117  if ( Abc_ObjIsCi(pObjAbc) )
118  pObjAbc = Abc_NtkCreateNodeInv( pNtkNew, pObjAbc );
119  else
120  {
121  // clone the node
122  pObj = Abc_NtkCloneObj( pObjAbc );
123  // set complemented functions
124  pObj->pData = Hop_Not( (Hop_Obj_t *)pObjAbc->pData );
125  // return the new node
126  pObjAbc = pObj;
127  }
128  }
129  Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), pObjAbc );
130  }
131  Vec_IntFree( vNodes );
132  Vec_PtrFree( (Vec_Ptr_t *)pMan->pCopy );
133  pMan->pCopy = NULL;
134  // remove dangling nodes
135  Abc_NtkCleanup( pNtkNew, 0 );
136  // fix CIs feeding directly into COs
137  Abc_NtkLogicMakeSimpleCos( pNtkNew, 0 );
138  return pNtkNew;
139 }
140 
141 /**Function*************************************************************
142 
143  Synopsis [Recursively construct the new node.]
144 
145  Description []
146 
147  SideEffects []
148 
149  SeeAlso []
150 
151 ***********************************************************************/
152 Abc_Obj_t * Ivy_ManToAbcFast_rec( Abc_Ntk_t * pNtkNew, Ivy_Man_t * pMan, Ivy_Obj_t * pObjIvy, Vec_Int_t * vNodes )
153 {
154  Vec_Int_t Supp, * vSupp = &Supp;
155  Abc_Obj_t * pObjAbc, * pFaninAbc;
156  Ivy_Obj_t * pNodeIvy;
157  int i, Entry;
158  // skip the node if it is a constant or already processed
159  pObjAbc = Abc_ObjGetIvy2Abc( pMan, pObjIvy->Id );
160  if ( pObjAbc )
161  return pObjAbc;
162  assert( Ivy_ObjIsAnd(pObjIvy) || Ivy_ObjIsExor(pObjIvy) );
163  // get the support of K-LUT
164  Ivy_FastMapReadSupp( pMan, pObjIvy, vSupp );
165  // create new ABC node and its fanins
166  pObjAbc = Abc_NtkCreateNode( pNtkNew );
167  Vec_IntForEachEntry( vSupp, Entry, i )
168  {
169  pFaninAbc = Ivy_ManToAbcFast_rec( pNtkNew, pMan, Ivy_ManObj(pMan, Entry), vNodes );
170  Abc_ObjAddFanin( pObjAbc, pFaninAbc );
171  }
172  // collect the nodes used in the cut
173  Ivy_ManCollectCut( pMan, pObjIvy, vSupp, vNodes );
174  // create the local function
175  Ivy_ManForEachNodeVec( pMan, vNodes, pNodeIvy, i )
176  {
177  if ( i < Vec_IntSize(vSupp) )
178  pNodeIvy->pEquiv = (Ivy_Obj_t *)Hop_IthVar( (Hop_Man_t *)pNtkNew->pManFunc, i );
179  else
180  pNodeIvy->pEquiv = (Ivy_Obj_t *)Hop_And( (Hop_Man_t *)pNtkNew->pManFunc, (Hop_Obj_t *)Ivy_ObjChild0Equiv(pNodeIvy), (Hop_Obj_t *)Ivy_ObjChild1Equiv(pNodeIvy) );
181  }
182  // set the local function
183  pObjAbc->pData = (Abc_Obj_t *)pObjIvy->pEquiv;
184  // set the node
185  Abc_ObjSetIvy2Abc( pMan, pObjIvy->Id, pObjAbc );
186  return pObjAbc;
187 }
188 
189 ////////////////////////////////////////////////////////////////////////
190 /// END OF FILE ///
191 ////////////////////////////////////////////////////////////////////////
192 
193 
195 
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
static Ivy_Obj_t * Ivy_ManPi(Ivy_Man_t *p, int i)
Definition: ivy.h:201
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Ivy_ManForEachPo(p, pObj, i)
Definition: ivy.h:390
static Abc_Obj_t * Ivy_ManToAbcFast_rec(Abc_Ntk_t *pNtkNew, Ivy_Man_t *pMan, Ivy_Obj_t *pObjIvy, Vec_Int_t *vNodes)
Definition: abcFpgaFast.c:152
static Abc_Obj_t * Abc_ObjGetIvy2Abc(Ivy_Man_t *p, int IvyId)
Definition: abcFpgaFast.c:37
static Abc_Ntk_t * Ivy_ManFpgaToAbc(Abc_Ntk_t *pNtk, Ivy_Man_t *pMan)
Definition: abcFpgaFast.c:93
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition: abcObj.c:633
int Id
Definition: ivy.h:75
ABC_DLL Abc_Obj_t * Abc_NtkCloneObj(Abc_Obj_t *pNode)
Definition: abcObj.c:434
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
ABC_DLL int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:476
static Hop_Obj_t * Hop_Not(Hop_Obj_t *p)
Definition: hop.h:127
void Ivy_ManStop(Ivy_Man_t *p)
Definition: ivyMan.c:238
Definition: hop.h:65
static Ivy_Obj_t * Ivy_ObjChild1Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:276
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
static Abc_Obj_t * Abc_NtkCo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:318
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_NAMESPACE_IMPL_START Ivy_Man_t * Abc_NtkIvyBefore(Abc_Ntk_t *pNtk, int fSeq, int fUseDc)
DECLARATIONS ///.
Definition: abcIvy.c:84
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
void * pManFunc
Definition: abc.h:191
static int Ivy_ManObjIdMax(Ivy_Man_t *p)
Definition: ivy.h:226
void Ivy_FastMapStop(Ivy_Man_t *pAig)
Definition: ivyFastMap.c:194
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition: abcNtk.c:106
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Abc_Ntk_t * Abc_NtkFpgaFast(Abc_Ntk_t *pNtk, int nLutSize, int fRecovery, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcFpgaFast.c:58
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:662
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
Definition: ivy.h:203
static Ivy_Obj_t * Ivy_ObjChild0Equiv(Ivy_Obj_t *pObj)
Definition: ivy.h:275
void Ivy_FastMapPerform(Ivy_Man_t *pAig, int nLimit, int fRecovery, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: ivyFastMap.c:105
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: ivy.h:73
void Ivy_ManCollectCut(Ivy_Man_t *p, Ivy_Obj_t *pRoot, Vec_Int_t *vLeaves, Vec_Int_t *vNodes)
Definition: ivyUtil.c:106
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
static void Abc_ObjSetIvy2Abc(Ivy_Man_t *p, int IvyId, Abc_Obj_t *pObjAbc)
Definition: abcFpgaFast.c:36
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
ABC_DLL int Abc_NtkLogicMakeSimpleCos(Abc_Ntk_t *pNtk, int fDuplicate)
Definition: abcUtil.c:1047
static int Ivy_ObjIsAnd(Ivy_Obj_t *pObj)
Definition: ivy.h:242
static int Ivy_ObjIsExor(Ivy_Obj_t *pObj)
Definition: ivy.h:243
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
#define Ivy_ManForEachNodeVec(p, vIds, pObj, i)
Definition: ivy.h:408
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
void Ivy_FastMapReadSupp(Ivy_Man_t *pAig, Ivy_Obj_t *pObj, Vec_Int_t *vLeaves)
Definition: ivyFastMap.c:793
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
static int Ivy_ObjFaninC0(Ivy_Obj_t *pObj)
Definition: ivy.h:269
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Ivy_Obj_t * pEquiv
Definition: ivy.h:93