abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFpga.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcFpga.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Interface with the FPGA mapping package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcFpga.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "map/fpga/fpgaInt.h"
23 #include "misc/extra/extraBdd.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 static Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose );
33 static Abc_Ntk_t * Abc_NtkFromFpga( Fpga_Man_t * pMan, Abc_Ntk_t * pNtk );
34 static Abc_Obj_t * Abc_NodeFromFpga_rec( Abc_Ntk_t * pNtkNew, Fpga_Node_t * pNodeFpga );
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Interface with the FPGA mapping package.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
51 Abc_Ntk_t * Abc_NtkFpga( Abc_Ntk_t * pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose )
52 {
53  int fShowSwitching = 1;
54  Abc_Ntk_t * pNtkNew;
55  Fpga_Man_t * pMan;
56  Vec_Int_t * vSwitching = NULL;
57  float * pSwitching = NULL;
58  int Num;
59 
60  assert( Abc_NtkIsStrash(pNtk) );
61 
62  // print a warning about choice nodes
63  if ( (Num = Abc_NtkGetChoiceNum( pNtk )) )
64  Abc_Print( 0, "Performing LUT mapping with %d choices.\n", Num );
65 
66  // compute switching activity
67  fShowSwitching |= fSwitching;
68  if ( fShowSwitching )
69  {
70  extern Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns );
71  vSwitching = Sim_NtkComputeSwitching( pNtk, 4096 );
72  pSwitching = (float *)vSwitching->pArray;
73  }
74 
75  // perform FPGA mapping
76  pMan = Abc_NtkToFpga( pNtk, fRecovery, pSwitching, fLatchPaths, fVerbose );
77  if ( pSwitching ) { assert(vSwitching); Vec_IntFree( vSwitching ); }
78  if ( pMan == NULL )
79  return NULL;
80  Fpga_ManSetSwitching( pMan, fSwitching );
81  Fpga_ManSetLatchPaths( pMan, fLatchPaths );
82  Fpga_ManSetLatchNum( pMan, Abc_NtkLatchNum(pNtk) );
83  Fpga_ManSetDelayTarget( pMan, DelayTarget );
84  if ( !Fpga_Mapping( pMan ) )
85  {
86  Fpga_ManFree( pMan );
87  return NULL;
88  }
89 
90  // transform the result of mapping into a BDD network
91  pNtkNew = Abc_NtkFromFpga( pMan, pNtk );
92  if ( pNtkNew == NULL )
93  return NULL;
94  Fpga_ManFree( pMan );
95 
96  // make the network minimum base
97  Abc_NtkMinimumBase( pNtkNew );
98 
99  if ( pNtk->pExdc )
100  pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
101 
102  // make sure that everything is okay
103  if ( !Abc_NtkCheck( pNtkNew ) )
104  {
105  printf( "Abc_NtkFpga: The network check has failed.\n" );
106  Abc_NtkDelete( pNtkNew );
107  return NULL;
108  }
109  return pNtkNew;
110 }
111 
112 /**Function*************************************************************
113 
114  Synopsis [Load the network into FPGA manager.]
115 
116  Description []
117 
118  SideEffects []
119 
120  SeeAlso []
121 
122 ***********************************************************************/
123 Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose )
124 {
125  Fpga_Man_t * pMan;
126  ProgressBar * pProgress;
127  Fpga_Node_t * pNodeFpga;
128  Vec_Ptr_t * vNodes;
129  Abc_Obj_t * pNode, * pFanin, * pPrev;
130  float * pfArrivals;
131  int i;
132 
133  assert( Abc_NtkIsStrash(pNtk) );
134 
135  // start the mapping manager and set its parameters
136  pMan = Fpga_ManCreate( Abc_NtkCiNum(pNtk), Abc_NtkCoNum(pNtk), fVerbose );
137  if ( pMan == NULL )
138  return NULL;
139  Fpga_ManSetAreaRecovery( pMan, fRecovery );
141  pfArrivals = Abc_NtkGetCiArrivalFloats(pNtk);
142  if ( fLatchPaths )
143  {
144  for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
145  pfArrivals[i] = -FPGA_FLOAT_LARGE;
146  }
147  Fpga_ManSetInputArrivals( pMan, pfArrivals );
148 
149  // create PIs and remember them in the old nodes
150  Abc_NtkCleanCopy( pNtk );
152  Abc_NtkForEachCi( pNtk, pNode, i )
153  {
154  pNodeFpga = Fpga_ManReadInputs(pMan)[i];
155  pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
156  if ( pSwitching )
157  Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
158  }
159 
160  // load the AIG into the mapper
161  vNodes = Abc_AigDfs( pNtk, 0, 0 );
162  pProgress = Extra_ProgressBarStart( stdout, vNodes->nSize );
163  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
164  {
165  Extra_ProgressBarUpdate( pProgress, i, NULL );
166  // add the node to the mapper
167  pNodeFpga = Fpga_NodeAnd( pMan,
168  Fpga_NotCond( Abc_ObjFanin0(pNode)->pCopy, Abc_ObjFaninC0(pNode) ),
169  Fpga_NotCond( Abc_ObjFanin1(pNode)->pCopy, Abc_ObjFaninC1(pNode) ) );
170  assert( pNode->pCopy == NULL );
171  // remember the node
172  pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
173  if ( pSwitching )
174  Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
175  // set up the choice node
176  if ( Abc_AigNodeIsChoice( pNode ) )
177  for ( pPrev = pNode, pFanin = (Abc_Obj_t *)pNode->pData; pFanin; pPrev = pFanin, pFanin = (Abc_Obj_t *)pFanin->pData )
178  {
179  Fpga_NodeSetNextE( (Fpga_Node_t *)pPrev->pCopy, (Fpga_Node_t *)pFanin->pCopy );
180  Fpga_NodeSetRepr( (Fpga_Node_t *)pFanin->pCopy, (Fpga_Node_t *)pNode->pCopy );
181  }
182  }
183  Extra_ProgressBarStop( pProgress );
184  Vec_PtrFree( vNodes );
185 
186  // set the primary outputs without copying the phase
187  Abc_NtkForEachCo( pNtk, pNode, i )
188  Fpga_ManReadOutputs(pMan)[i] = (Fpga_Node_t *)Abc_ObjFanin0(pNode)->pCopy;
189  return pMan;
190 }
191 
192 /**Function*************************************************************
193 
194  Synopsis [Creates the mapped network.]
195 
196  Description []
197 
198  SideEffects []
199 
200  SeeAlso []
201 
202 ***********************************************************************/
204 {
205  ProgressBar * pProgress;
206  Abc_Ntk_t * pNtkNew;
207  Abc_Obj_t * pNode, * pNodeNew;
208  int i, nDupGates;
209  // create the new network
210  pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
211  // make the mapper point to the new network
212  Fpga_CutsCleanSign( pMan );
213  Fpga_ManCleanData0( pMan );
214  Abc_NtkForEachCi( pNtk, pNode, i )
215  Fpga_NodeSetData0( Fpga_ManReadInputs(pMan)[i], (char *)pNode->pCopy );
216  // set the constant node
217 // if ( Fpga_NodeReadRefs(Fpga_ManReadConst1(pMan)) > 0 )
219  // process the nodes in topological order
220  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
221  Abc_NtkForEachCo( pNtk, pNode, i )
222  {
223  Extra_ProgressBarUpdate( pProgress, i, NULL );
224  pNodeNew = Abc_NodeFromFpga_rec( pNtkNew, Fpga_ManReadOutputs(pMan)[i] );
225  assert( !Abc_ObjIsComplement(pNodeNew) );
226  Abc_ObjFanin0(pNode)->pCopy = pNodeNew;
227  }
228  Extra_ProgressBarStop( pProgress );
229  // finalize the new network
230  Abc_NtkFinalize( pNtk, pNtkNew );
231  // remove the constant node if not used
232  pNodeNew = (Abc_Obj_t *)Fpga_NodeReadData0(Fpga_ManReadConst1(pMan));
233  if ( Abc_ObjFanoutNum(pNodeNew) == 0 )
234  Abc_NtkDeleteObj( pNodeNew );
235  // decouple the PO driver nodes to reduce the number of levels
236  nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
237  if ( nDupGates && Fpga_ManReadVerbose(pMan) )
238  printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
239  return pNtkNew;
240 }
241 
242 /**Function*************************************************************
243 
244  Synopsis [Derive one node after FPGA mapping.]
245 
246  Description []
247 
248  SideEffects []
249 
250  SeeAlso []
251 
252 ***********************************************************************/
254 {
255  Fpga_Cut_t * pCutBest;
256  Fpga_Node_t ** ppLeaves;
257  Abc_Obj_t * pNodeNew;
258  int i, nLeaves;
259  assert( !Fpga_IsComplement(pNodeFpga) );
260  // return if the result if known
261  pNodeNew = (Abc_Obj_t *)Fpga_NodeReadData0( pNodeFpga );
262  if ( pNodeNew )
263  return pNodeNew;
264  assert( Fpga_NodeIsAnd(pNodeFpga) );
265  // get the parameters of the best cut
266  pCutBest = Fpga_NodeReadCutBest( pNodeFpga );
267  ppLeaves = Fpga_CutReadLeaves( pCutBest );
268  nLeaves = Fpga_CutReadLeavesNum( pCutBest );
269  // create a new node
270  pNodeNew = Abc_NtkCreateNode( pNtkNew );
271  for ( i = 0; i < nLeaves; i++ )
272  Abc_ObjAddFanin( pNodeNew, Abc_NodeFromFpga_rec(pNtkNew, ppLeaves[i]) );
273  // derive the function of this node
274  pNodeNew->pData = Fpga_TruthsCutBdd( pNtkNew->pManFunc, pCutBest ); Cudd_Ref( (DdNode *)pNodeNew->pData );
275  Fpga_NodeSetData0( pNodeFpga, (char *)pNodeNew );
276  return pNodeNew;
277 }
278 
279 ////////////////////////////////////////////////////////////////////////
280 /// END OF FILE ///
281 ////////////////////////////////////////////////////////////////////////
282 
283 
285 
void Fpga_ManSetAreaRecovery(Fpga_Man_t *p, int fAreaRecovery)
Definition: fpgaCreate.c:63
Fpga_Node_t ** Fpga_ManReadInputs(Fpga_Man_t *p)
Definition: fpgaCreate.c:53
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 Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
void Fpga_CutsCleanSign(Fpga_Man_t *pMan)
Definition: fpgaCut.c:797
Definition: cudd.h:278
void Fpga_NodeSetData0(Fpga_Node_t *p, char *pData)
Definition: fpgaCreate.c:108
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcMinBase.c:48
Abc_Ntk_t * pExdc
Definition: abc.h:201
void Fpga_ManSetLatchNum(Fpga_Man_t *p, int nLatches)
Definition: fpgaCreate.c:71
void Fpga_NodeSetNextE(Fpga_Node_t *p, Fpga_Node_t *pNextE)
Definition: fpgaCreate.c:110
#define Fpga_NotCond(p, c)
Definition: fpga.h:60
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
void Fpga_ManCleanData0(Fpga_Man_t *pMan)
Definition: fpgaUtils.c:657
#define FPGA_FLOAT_LARGE
Definition: fpgaInt.h:65
ABC_DLL char ** Abc_NtkCollectCioNames(Abc_Ntk_t *pNtk, int fCollectCos)
Definition: abcNames.c:278
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition: abcObj.c:633
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static int Abc_NtkCiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:287
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
Fpga_Node_t * Fpga_ManReadConst1(Fpga_Man_t *p)
Definition: fpgaCreate.c:55
Abc_Ntk_t * Abc_NtkFpga(Abc_Ntk_t *pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcFpga.c:51
void Fpga_NodeSetSwitching(Fpga_Node_t *p, float Switching)
Definition: fpgaCreate.c:112
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:430
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
void Fpga_ManSetLatchPaths(Fpga_Man_t *p, int fLatchPaths)
Definition: fpgaCreate.c:70
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
static Abc_Obj_t * Abc_NodeFromFpga_rec(Abc_Ntk_t *pNtkNew, Fpga_Node_t *pNodeFpga)
Definition: abcFpga.c:253
void * pManFunc
Definition: abc.h:191
DECLARATIONS ///.
void Fpga_NodeSetRepr(Fpga_Node_t *p, Fpga_Node_t *pRepr)
Definition: fpgaCreate.c:111
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition: abcNtk.c:106
Abc_Obj_t * pCopy
Definition: abc.h:148
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
void Fpga_ManSetInputArrivals(Fpga_Man_t *p, float *pArrivals)
Definition: fpgaCreate.c:62
Fpga_Cut_t * Fpga_NodeReadCutBest(Fpga_Node_t *p)
Definition: fpgaCreate.c:105
int Fpga_ManReadVerbose(Fpga_Man_t *p)
Definition: fpgaCreate.c:57
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition: abcNtk.c:302
static ABC_NAMESPACE_IMPL_START Fpga_Man_t * Abc_NtkToFpga(Abc_Ntk_t *pNtk, int fRecovery, float *pSwitching, int fLatchPaths, int fVerbose)
DECLARATIONS ///.
Definition: abcFpga.c:123
int Fpga_Mapping(Fpga_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: fpgaCore.c:53
Fpga_Node_t ** Fpga_ManReadOutputs(Fpga_Man_t *p)
Definition: fpgaCreate.c:54
static Abc_Ntk_t * Abc_NtkFromFpga(Fpga_Man_t *pMan, Abc_Ntk_t *pNtk)
Definition: abcFpga.c:203
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
void Extra_ProgressBarStop(ProgressBar *p)
Vec_Int_t * Sim_NtkComputeSwitching(Abc_Ntk_t *pNtk, int nPatterns)
FUNCTION DEFINITIONS ///.
Definition: simSwitch.c:52
ABC_DLL Vec_Ptr_t * Abc_AigDfs(Abc_Ntk_t *pNtk, int fCollectAll, int fCollectCos)
Definition: abcDfs.c:1014
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Fpga_ManFree(Fpga_Man_t *pMan)
Definition: fpgaCreate.c:217
int Fpga_NodeIsAnd(Fpga_Node_t *p)
Definition: fpgaCreate.c:127
Fpga_Node_t * Fpga_NodeAnd(Fpga_Man_t *p, Fpga_Node_t *p1, Fpga_Node_t *p2)
Definition: fpgaCreate.c:470
ABC_DLL int Abc_NtkLogicMakeSimpleCos(Abc_Ntk_t *pNtk, int fDuplicate)
Definition: abcUtil.c:1047
Fpga_Node_t ** Fpga_CutReadLeaves(Fpga_Cut_t *p)
Definition: fpgaCreate.c:142
static int Abc_AigNodeIsChoice(Abc_Obj_t *pNode)
Definition: abc.h:398
char * Fpga_NodeReadData0(Fpga_Node_t *p)
Definition: fpgaCreate.c:99
void Fpga_ManSetDelayTarget(Fpga_Man_t *p, float DelayTarget)
Definition: fpgaCreate.c:72
ABC_DLL float * Abc_NtkGetCiArrivalFloats(Abc_Ntk_t *pNtk)
Definition: abcTiming.c:658
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
STRUCTURE DEFINITIONS ///.
Definition: fpgaInt.h:99
int Id
Definition: abc.h:132
static int Abc_NtkPiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:285
void Fpga_ManSetOutputNames(Fpga_Man_t *p, char **ppNames)
Definition: fpgaCreate.c:61
int Fpga_CutReadLeavesNum(Fpga_Cut_t *p)
Definition: fpgaCreate.c:141
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Fpga_Man_t * Fpga_ManCreate(int nInputs, int nOutputs, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: fpgaCreate.c:163
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
void * Fpga_TruthsCutBdd(void *dd, Fpga_Cut_t *pCut)
Definition: fpgaTruth.c:79
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
void * pData
Definition: abc.h:145
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Fpga_ManSetSwitching(Fpga_Man_t *p, int fSwitching)
Definition: fpgaCreate.c:69
static int Abc_ObjIsComplement(Abc_Obj_t *p)
Definition: abc.h:322
#define Fpga_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fpga.h:57
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223