00001
00021 #include "abc.h"
00022 #include "fpgaInt.h"
00023
00027
00028 static Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose );
00029 static Abc_Ntk_t * Abc_NtkFromFpga( Fpga_Man_t * pMan, Abc_Ntk_t * pNtk );
00030 static Abc_Obj_t * Abc_NodeFromFpga_rec( Abc_Ntk_t * pNtkNew, Fpga_Node_t * pNodeFpga );
00031
00035
00047 Abc_Ntk_t * Abc_NtkFpga( Abc_Ntk_t * pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose )
00048 {
00049 int fShowSwitching = 1;
00050 Abc_Ntk_t * pNtkNew;
00051 Fpga_Man_t * pMan;
00052 Vec_Int_t * vSwitching;
00053 float * pSwitching = NULL;
00054
00055 assert( Abc_NtkIsStrash(pNtk) );
00056
00057
00058 if ( Abc_NtkGetChoiceNum( pNtk ) )
00059 printf( "Performing FPGA mapping with choices.\n" );
00060
00061
00062 fShowSwitching |= fSwitching;
00063 if ( fShowSwitching )
00064 {
00065 extern Vec_Int_t * Sim_NtkComputeSwitching( Abc_Ntk_t * pNtk, int nPatterns );
00066 vSwitching = Sim_NtkComputeSwitching( pNtk, 4096 );
00067 pSwitching = (float *)vSwitching->pArray;
00068 }
00069
00070
00071 pMan = Abc_NtkToFpga( pNtk, fRecovery, pSwitching, fLatchPaths, fVerbose );
00072 if ( pSwitching ) Vec_IntFree( vSwitching );
00073 if ( pMan == NULL )
00074 return NULL;
00075 Fpga_ManSetSwitching( pMan, fSwitching );
00076 Fpga_ManSetLatchPaths( pMan, fLatchPaths );
00077 Fpga_ManSetLatchNum( pMan, Abc_NtkLatchNum(pNtk) );
00078 Fpga_ManSetDelayTarget( pMan, DelayTarget );
00079 if ( !Fpga_Mapping( pMan ) )
00080 {
00081 Fpga_ManFree( pMan );
00082 return NULL;
00083 }
00084
00085
00086 pNtkNew = Abc_NtkFromFpga( pMan, pNtk );
00087 if ( pNtkNew == NULL )
00088 return NULL;
00089 Fpga_ManFree( pMan );
00090
00091
00092 Abc_NtkMinimumBase( pNtkNew );
00093
00094 if ( pNtk->pExdc )
00095 pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
00096
00097
00098 if ( !Abc_NtkCheck( pNtkNew ) )
00099 {
00100 printf( "Abc_NtkFpga: The network check has failed.\n" );
00101 Abc_NtkDelete( pNtkNew );
00102 return NULL;
00103 }
00104 return pNtkNew;
00105 }
00106
00118 Fpga_Man_t * Abc_NtkToFpga( Abc_Ntk_t * pNtk, int fRecovery, float * pSwitching, int fLatchPaths, int fVerbose )
00119 {
00120 Fpga_Man_t * pMan;
00121 ProgressBar * pProgress;
00122 Fpga_Node_t * pNodeFpga;
00123 Vec_Ptr_t * vNodes;
00124 Abc_Obj_t * pNode, * pFanin, * pPrev;
00125 float * pfArrivals;
00126 int i;
00127
00128 assert( Abc_NtkIsStrash(pNtk) );
00129
00130
00131 pMan = Fpga_ManCreate( Abc_NtkCiNum(pNtk), Abc_NtkCoNum(pNtk), fVerbose );
00132 if ( pMan == NULL )
00133 return NULL;
00134 Fpga_ManSetAreaRecovery( pMan, fRecovery );
00135 Fpga_ManSetOutputNames( pMan, Abc_NtkCollectCioNames(pNtk, 1) );
00136 pfArrivals = Abc_NtkGetCiArrivalFloats(pNtk);
00137 if ( fLatchPaths )
00138 {
00139 for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
00140 pfArrivals[i] = -FPGA_FLOAT_LARGE;
00141 }
00142 Fpga_ManSetInputArrivals( pMan, pfArrivals );
00143
00144
00145 Abc_NtkCleanCopy( pNtk );
00146 Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)Fpga_ManReadConst1(pMan);
00147 Abc_NtkForEachCi( pNtk, pNode, i )
00148 {
00149 pNodeFpga = Fpga_ManReadInputs(pMan)[i];
00150 pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
00151 if ( pSwitching )
00152 Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
00153 }
00154
00155
00156 vNodes = Abc_AigDfs( pNtk, 0, 0 );
00157 pProgress = Extra_ProgressBarStart( stdout, vNodes->nSize );
00158 Vec_PtrForEachEntry( vNodes, pNode, i )
00159 {
00160 Extra_ProgressBarUpdate( pProgress, i, NULL );
00161
00162 pNodeFpga = Fpga_NodeAnd( pMan,
00163 Fpga_NotCond( Abc_ObjFanin0(pNode)->pCopy, Abc_ObjFaninC0(pNode) ),
00164 Fpga_NotCond( Abc_ObjFanin1(pNode)->pCopy, Abc_ObjFaninC1(pNode) ) );
00165 assert( pNode->pCopy == NULL );
00166
00167 pNode->pCopy = (Abc_Obj_t *)pNodeFpga;
00168 if ( pSwitching )
00169 Fpga_NodeSetSwitching( pNodeFpga, pSwitching[pNode->Id] );
00170
00171 if ( Abc_AigNodeIsChoice( pNode ) )
00172 for ( pPrev = pNode, pFanin = pNode->pData; pFanin; pPrev = pFanin, pFanin = pFanin->pData )
00173 {
00174 Fpga_NodeSetNextE( (Fpga_Node_t *)pPrev->pCopy, (Fpga_Node_t *)pFanin->pCopy );
00175 Fpga_NodeSetRepr( (Fpga_Node_t *)pFanin->pCopy, (Fpga_Node_t *)pNode->pCopy );
00176 }
00177 }
00178 Extra_ProgressBarStop( pProgress );
00179 Vec_PtrFree( vNodes );
00180
00181
00182 Abc_NtkForEachCo( pNtk, pNode, i )
00183 Fpga_ManReadOutputs(pMan)[i] = (Fpga_Node_t *)Abc_ObjFanin0(pNode)->pCopy;
00184 return pMan;
00185 }
00186
00198 Abc_Ntk_t * Abc_NtkFromFpga( Fpga_Man_t * pMan, Abc_Ntk_t * pNtk )
00199 {
00200 ProgressBar * pProgress;
00201 Abc_Ntk_t * pNtkNew;
00202 Abc_Obj_t * pNode, * pNodeNew;
00203 int i, nDupGates;
00204
00205 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
00206
00207 Fpga_CutsCleanSign( pMan );
00208 Fpga_ManCleanData0( pMan );
00209 Abc_NtkForEachCi( pNtk, pNode, i )
00210 Fpga_NodeSetData0( Fpga_ManReadInputs(pMan)[i], (char *)pNode->pCopy );
00211
00212
00213 Fpga_NodeSetData0( Fpga_ManReadConst1(pMan), (char *)Abc_NtkCreateNodeConst1(pNtkNew) );
00214
00215 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
00216 Abc_NtkForEachCo( pNtk, pNode, i )
00217 {
00218 Extra_ProgressBarUpdate( pProgress, i, NULL );
00219 pNodeNew = Abc_NodeFromFpga_rec( pNtkNew, Fpga_ManReadOutputs(pMan)[i] );
00220 assert( !Abc_ObjIsComplement(pNodeNew) );
00221 Abc_ObjFanin0(pNode)->pCopy = pNodeNew;
00222 }
00223 Extra_ProgressBarStop( pProgress );
00224
00225 Abc_NtkFinalize( pNtk, pNtkNew );
00226
00227 pNodeNew = (Abc_Obj_t *)Fpga_NodeReadData0(Fpga_ManReadConst1(pMan));
00228 if ( Abc_ObjFanoutNum(pNodeNew) == 0 )
00229 Abc_NtkDeleteObj( pNodeNew );
00230
00231 nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
00232
00233
00234 return pNtkNew;
00235 }
00236
00248 Abc_Obj_t * Abc_NodeFromFpga_rec( Abc_Ntk_t * pNtkNew, Fpga_Node_t * pNodeFpga )
00249 {
00250 Fpga_Cut_t * pCutBest;
00251 Fpga_Node_t ** ppLeaves;
00252 Abc_Obj_t * pNodeNew;
00253 int i, nLeaves;
00254 assert( !Fpga_IsComplement(pNodeFpga) );
00255
00256 pNodeNew = (Abc_Obj_t *)Fpga_NodeReadData0( pNodeFpga );
00257 if ( pNodeNew )
00258 return pNodeNew;
00259 assert( Fpga_NodeIsAnd(pNodeFpga) );
00260
00261 pCutBest = Fpga_NodeReadCutBest( pNodeFpga );
00262 ppLeaves = Fpga_CutReadLeaves( pCutBest );
00263 nLeaves = Fpga_CutReadLeavesNum( pCutBest );
00264
00265 pNodeNew = Abc_NtkCreateNode( pNtkNew );
00266 for ( i = 0; i < nLeaves; i++ )
00267 Abc_ObjAddFanin( pNodeNew, Abc_NodeFromFpga_rec(pNtkNew, ppLeaves[i]) );
00268
00269 pNodeNew->pData = Fpga_TruthsCutBdd( pNtkNew->pManFunc, pCutBest ); Cudd_Ref( pNodeNew->pData );
00270 Fpga_NodeSetData0( pNodeFpga, (char *)pNodeNew );
00271 return pNodeNew;
00272 }
00273
00277
00278