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
24 ABC_NAMESPACE_IMPL_START
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
Abc_ObjSetIvy2Abc(Ivy_Man_t * p,int IvyId,Abc_Obj_t * pObjAbc)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 ); }
Abc_ObjGetIvy2Abc(Ivy_Man_t * p,int IvyId)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 ***********************************************************************/
Abc_NtkFpgaFast(Abc_Ntk_t * pNtk,int nLutSize,int fRecovery,int fVerbose)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 ***********************************************************************/
Ivy_ManFpgaToAbc(Abc_Ntk_t * pNtk,Ivy_Man_t * pMan)93 Abc_Ntk_t * Ivy_ManFpgaToAbc( Abc_Ntk_t * pNtk, Ivy_Man_t * pMan )
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 ***********************************************************************/
Ivy_ManToAbcFast_rec(Abc_Ntk_t * pNtkNew,Ivy_Man_t * pMan,Ivy_Obj_t * pObjIvy,Vec_Int_t * vNodes)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
194 ABC_NAMESPACE_IMPL_END
195
196