ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcFpga.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "map/fpga/fpgaInt.h"
23
24#ifdef ABC_USE_CUDD
25#include "bdd/extrab/extraBdd.h"
26#endif
27
29
30
34
35static Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose );
36static Abc_Ntk_t * Abc_NtkFromFpga( Fpga_Man_t * pMan, Abc_Ntk_t * pNtk );
37static Abc_Obj_t * Abc_NodeFromFpga_rec( Abc_Ntk_t * pNtkNew, Fpga_Node_t * pNodeFpga );
38
42
54Abc_Ntk_t * Abc_NtkFpga( Abc_Ntk_t * pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose )
55{
56 int fShowSwitching = 1;
57 Abc_Ntk_t * pNtkNew;
58 Fpga_Man_t * pMan;
59 Vec_Int_t * vSwitching = NULL;
60 float * pSwitching = NULL;
61 int Num;
62
63 assert( Abc_NtkIsStrash(pNtk) );
64
65 // print a warning about choice nodes
66 if ( (Num = Abc_NtkGetChoiceNum( pNtk )) )
67 Abc_Print( 0, "Performing LUT mapping with %d choices.\n", Num );
68
69 // compute switching activity
70 fShowSwitching |= fSwitching;
71 if ( fShowSwitching )
72 {
73 extern Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns );
74 vSwitching = Sim_NtkComputeSwitching( pNtk, 4096 );
75 pSwitching = (float *)vSwitching->pArray;
76 }
77
78 // perform FPGA mapping
79 pMan = Abc_NtkToFpga( pNtk, fRecovery, pSwitching, fLatchPaths, fVerbose );
80 if ( pSwitching ) { assert(vSwitching); Vec_IntFree( vSwitching ); }
81 if ( pMan == NULL )
82 return NULL;
83 Fpga_ManSetSwitching( pMan, fSwitching );
84 Fpga_ManSetLatchPaths( pMan, fLatchPaths );
85 Fpga_ManSetLatchNum( pMan, Abc_NtkLatchNum(pNtk) );
86 Fpga_ManSetDelayTarget( pMan, DelayTarget );
87 if ( !Fpga_Mapping( pMan ) )
88 {
89 Fpga_ManFree( pMan );
90 return NULL;
91 }
92
93 // transform the result of mapping into a BDD network
94 pNtkNew = Abc_NtkFromFpga( pMan, pNtk );
95 if ( pNtkNew == NULL )
96 return NULL;
97 Fpga_ManFree( pMan );
98
99 // make the network minimum base
100 Abc_NtkMinimumBase( pNtkNew );
101
102 if ( pNtk->pExdc )
103 pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
104
105 // make sure that everything is okay
106 if ( !Abc_NtkCheck( pNtkNew ) )
107 {
108 printf( "Abc_NtkFpga: The network check has failed.\n" );
109 Abc_NtkDelete( pNtkNew );
110 return NULL;
111 }
112 return pNtkNew;
113}
114
126Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose )
127{
128 Fpga_Man_t * pMan;
129 ProgressBar * pProgress;
130 Fpga_Node_t * pNodeFpga;
131 Vec_Ptr_t * vNodes;
132 Abc_Obj_t * pNode, * pFanin, * pPrev;
133 float * pfArrivals;
134 int i;
135
136 assert( Abc_NtkIsStrash(pNtk) );
137
138 // start the mapping manager and set its parameters
139 pMan = Fpga_ManCreate( Abc_NtkCiNum(pNtk), Abc_NtkCoNum(pNtk), fVerbose );
140 if ( pMan == NULL )
141 return NULL;
142 Fpga_ManSetAreaRecovery( pMan, fRecovery );
144 pfArrivals = Abc_NtkGetCiArrivalFloats(pNtk);
145 if ( fLatchPaths )
146 {
147 for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
148 pfArrivals[i] = -FPGA_FLOAT_LARGE;
149 }
150 Fpga_ManSetInputArrivals( pMan, pfArrivals );
151
152 // create PIs and remember them in the old nodes
153 Abc_NtkCleanCopy( pNtk );
155 Abc_NtkForEachCi( pNtk, pNode, i )
156 {
157 pNodeFpga = Fpga_ManReadInputs(pMan)[i];
158 pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
159 if ( pSwitching )
160 Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
161 }
162
163 // load the AIG into the mapper
164 vNodes = Abc_AigDfs( pNtk, 0, 0 );
165 pProgress = Extra_ProgressBarStart( stdout, vNodes->nSize );
166 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
167 {
168 Extra_ProgressBarUpdate( pProgress, i, NULL );
169 // add the node to the mapper
170 pNodeFpga = Fpga_NodeAnd( pMan,
171 Fpga_NotCond( Abc_ObjFanin0(pNode)->pCopy, Abc_ObjFaninC0(pNode) ),
172 Fpga_NotCond( Abc_ObjFanin1(pNode)->pCopy, Abc_ObjFaninC1(pNode) ) );
173 assert( pNode->pCopy == NULL );
174 // remember the node
175 pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
176 if ( pSwitching )
177 Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
178 // set up the choice node
179 if ( Abc_AigNodeIsChoice( pNode ) )
180 for ( pPrev = pNode, pFanin = (Abc_Obj_t *)pNode->pData; pFanin; pPrev = pFanin, pFanin = (Abc_Obj_t *)pFanin->pData )
181 {
182 Fpga_NodeSetNextE( (Fpga_Node_t *)pPrev->pCopy, (Fpga_Node_t *)pFanin->pCopy );
183 Fpga_NodeSetRepr( (Fpga_Node_t *)pFanin->pCopy, (Fpga_Node_t *)pNode->pCopy );
184 }
185 }
186 Extra_ProgressBarStop( pProgress );
187 Vec_PtrFree( vNodes );
188
189 // set the primary outputs without copying the phase
190 Abc_NtkForEachCo( pNtk, pNode, i )
191 Fpga_ManReadOutputs(pMan)[i] = (Fpga_Node_t *)Abc_ObjFanin0(pNode)->pCopy;
192 return pMan;
193}
194
206Abc_Ntk_t * Abc_NtkFromFpga( Fpga_Man_t * pMan, Abc_Ntk_t * pNtk )
207{
208 ProgressBar * pProgress;
209 Abc_Ntk_t * pNtkNew;
210 Abc_Obj_t * pNode, * pNodeNew;
211 int i, nDupGates;
212 // create the new network
213 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
214 // make the mapper point to the new network
215 Fpga_CutsCleanSign( pMan );
216 Fpga_ManCleanData0( pMan );
217 Abc_NtkForEachCi( pNtk, pNode, i )
218 Fpga_NodeSetData0( Fpga_ManReadInputs(pMan)[i], (char *)pNode->pCopy );
219 // set the constant node
220// if ( Fpga_NodeReadRefs(Fpga_ManReadConst1(pMan)) > 0 )
222 // process the nodes in topological order
223 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
224 Abc_NtkForEachCo( pNtk, pNode, i )
225 {
226 Extra_ProgressBarUpdate( pProgress, i, NULL );
227 pNodeNew = Abc_NodeFromFpga_rec( pNtkNew, Fpga_ManReadOutputs(pMan)[i] );
228 assert( !Abc_ObjIsComplement(pNodeNew) );
229 Abc_ObjFanin0(pNode)->pCopy = pNodeNew;
230 }
231 Extra_ProgressBarStop( pProgress );
232 // finalize the new network
233 Abc_NtkFinalize( pNtk, pNtkNew );
234 // remove the constant node if not used
236 if ( Abc_ObjFanoutNum(pNodeNew) == 0 )
237 Abc_NtkDeleteObj( pNodeNew );
238 // decouple the PO driver nodes to reduce the number of levels
239 nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
240 if ( nDupGates && Fpga_ManReadVerbose(pMan) )
241 printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
242 return pNtkNew;
243}
244
256Abc_Obj_t * Abc_NodeFromFpga_rec( Abc_Ntk_t * pNtkNew, Fpga_Node_t * pNodeFpga )
257{
258 Fpga_Cut_t * pCutBest;
259 Fpga_Node_t ** ppLeaves;
260 Abc_Obj_t * pNodeNew;
261 int i, nLeaves;
262 assert( !Fpga_IsComplement(pNodeFpga) );
263 // return if the result if known
264 pNodeNew = (Abc_Obj_t *)Fpga_NodeReadData0( pNodeFpga );
265 if ( pNodeNew )
266 return pNodeNew;
267 assert( Fpga_NodeIsAnd(pNodeFpga) );
268 // get the parameters of the best cut
269 pCutBest = Fpga_NodeReadCutBest( pNodeFpga );
270 ppLeaves = Fpga_CutReadLeaves( pCutBest );
271 nLeaves = Fpga_CutReadLeavesNum( pCutBest );
272 // create a new node
273 pNodeNew = Abc_NtkCreateNode( pNtkNew );
274 for ( i = 0; i < nLeaves; i++ )
275 Abc_ObjAddFanin( pNodeNew, Abc_NodeFromFpga_rec(pNtkNew, ppLeaves[i]) );
276 // derive the function of this node
277 pNodeNew->pData = Fpga_TruthsCutBdd( pNtkNew->pManFunc, pCutBest ); Cudd_Ref( (DdNode *)pNodeNew->pData );
278 Fpga_NodeSetData0( pNodeFpga, (char *)pNodeNew );
279 return pNodeNew;
280}
281
285
286
288
Abc_Ntk_t * Abc_NtkFpga(Abc_Ntk_t *pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcFpga.c:54
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Vec_Ptr_t * Abc_AigDfs(Abc_Ntk_t *pNtk, int fCollectAll, int fCollectCos)
Definition abcDfs.c:1198
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition abcObj.c:170
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition abcUtil.c:463
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition abcNtk.c:355
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL int Abc_NtkLogicMakeSimpleCos(Abc_Ntk_t *pNtk, int fDuplicate)
Definition abcUtil.c:1080
ABC_DLL char ** Abc_NtkCollectCioNames(Abc_Ntk_t *pNtk, int fCollectCos)
Definition abcNames.c:285
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition abcMinBase.c:892
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
@ ABC_FUNC_BDD
Definition abc.h:66
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition abcNtk.c:472
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
ABC_DLL float * Abc_NtkGetCiArrivalFloats(Abc_Ntk_t *pNtk)
Definition abcTiming.c:789
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
#define FPGA_FLOAT_LARGE
Definition fpgaInt.h:65
struct Fpga_NodeStruct_t_ Fpga_Node_t
Definition fpga.h:44
void Fpga_ManFree(Fpga_Man_t *pMan)
Definition fpgaCreate.c:217
Fpga_Node_t * Fpga_ManReadConst1(Fpga_Man_t *p)
Definition fpgaCreate.c:55
Fpga_Cut_t * Fpga_NodeReadCutBest(Fpga_Node_t *p)
Definition fpgaCreate.c:105
struct Fpga_ManStruct_t_ Fpga_Man_t
STRUCTURE DEFINITIONS ///.
Definition fpga.h:43
#define Fpga_NotCond(p, c)
Definition fpga.h:60
int Fpga_CutReadLeavesNum(Fpga_Cut_t *p)
Definition fpgaCreate.c:141
char * Fpga_NodeReadData0(Fpga_Node_t *p)
Definition fpgaCreate.c:99
Fpga_Node_t ** Fpga_CutReadLeaves(Fpga_Cut_t *p)
Definition fpgaCreate.c:142
void Fpga_ManSetDelayTarget(Fpga_Man_t *p, float DelayTarget)
Definition fpgaCreate.c:72
struct Fpga_CutStruct_t_ Fpga_Cut_t
Definition fpga.h:46
Fpga_Node_t ** Fpga_ManReadInputs(Fpga_Man_t *p)
Definition fpgaCreate.c:53
void Fpga_NodeSetRepr(Fpga_Node_t *p, Fpga_Node_t *pRepr)
Definition fpgaCreate.c:111
void Fpga_ManSetInputArrivals(Fpga_Man_t *p, float *pArrivals)
Definition fpgaCreate.c:62
#define Fpga_IsComplement(p)
GLOBAL VARIABLES ///.
Definition fpga.h:57
Fpga_Node_t ** Fpga_ManReadOutputs(Fpga_Man_t *p)
Definition fpgaCreate.c:54
void Fpga_NodeSetNextE(Fpga_Node_t *p, Fpga_Node_t *pNextE)
Definition fpgaCreate.c:110
void Fpga_ManSetOutputNames(Fpga_Man_t *p, char **ppNames)
Definition fpgaCreate.c:61
void Fpga_ManSetSwitching(Fpga_Man_t *p, int fSwitching)
Definition fpgaCreate.c:69
int Fpga_ManReadVerbose(Fpga_Man_t *p)
Definition fpgaCreate.c:57
void * Fpga_TruthsCutBdd(void *dd, Fpga_Cut_t *pCut)
Definition fpgaTruth.c:79
int Fpga_Mapping(Fpga_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition fpgaCore.c:53
void Fpga_CutsCleanSign(Fpga_Man_t *pMan)
Definition fpgaCut.c:797
void Fpga_ManSetAreaRecovery(Fpga_Man_t *p, int fAreaRecovery)
Definition fpgaCreate.c:63
void Fpga_NodeSetData0(Fpga_Node_t *p, char *pData)
Definition fpgaCreate.c:108
int Fpga_NodeIsAnd(Fpga_Node_t *p)
Definition fpgaCreate.c:127
Fpga_Man_t * Fpga_ManCreate(int nInputs, int nOutputs, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition fpgaCreate.c:163
void Fpga_ManSetLatchPaths(Fpga_Man_t *p, int fLatchPaths)
Definition fpgaCreate.c:70
void Fpga_NodeSetSwitching(Fpga_Node_t *p, float Switching)
Definition fpgaCreate.c:112
void Fpga_ManSetLatchNum(Fpga_Man_t *p, int nLatches)
Definition fpgaCreate.c:71
Fpga_Node_t * Fpga_NodeAnd(Fpga_Man_t *p, Fpga_Node_t *p1, Fpga_Node_t *p2)
Definition fpgaCreate.c:470
void Fpga_ManCleanData0(Fpga_Man_t *pMan)
Definition fpgaUtils.c:657
Vec_Int_t * Sim_NtkComputeSwitching(Abc_Ntk_t *pNtk, int nPatterns)
FUNCTION DEFINITIONS ///.
Definition simSwitch.c:52
Abc_Ntk_t * pExdc
Definition abc.h:201
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
int Id
Definition abc.h:132
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55