00001
00021 #include "abc.h"
00022 #include "fxu.h"
00023
00027
00028 static bool Abc_NtkFxuCheck( Abc_Ntk_t * pNtk );
00029 static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
00030 static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
00031
00035
00036
00053 bool Abc_NtkFastExtract( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
00054 {
00055 assert( Abc_NtkIsLogic(pNtk) );
00056
00057
00058 if ( Abc_NtkIsSopLogic(pNtk) )
00059 {
00060
00061
00062 }
00063
00064 if ( !Abc_NtkToSop(pNtk, 0) )
00065 {
00066 printf( "Abc_NtkFastExtract(): Converting to SOPs has failed.\n" );
00067 return 0;
00068 }
00069
00070 if ( !Abc_NtkFxuCheck(pNtk) )
00071 {
00072 printf( "Abc_NtkFastExtract: Nodes have duplicated or complemented fanins. FXU is not performed.\n" );
00073 return 0;
00074 }
00075
00076 Abc_NtkCleanup( pNtk, 0 );
00077
00078 Abc_NtkFxuCollectInfo( pNtk, p );
00079
00080 if ( Fxu_FastExtract(p) > 0 )
00081 {
00082
00083 Abc_NtkFxuReconstruct( pNtk, p );
00084
00085 if ( !Abc_NtkCheck( pNtk ) )
00086 printf( "Abc_NtkFastExtract: The network check has failed.\n" );
00087 return 1;
00088 }
00089 else
00090 printf( "Warning: The network has not been changed by \"fx\".\n" );
00091 return 0;
00092 }
00093
00094
00106 bool Abc_NtkFxuCheck( Abc_Ntk_t * pNtk )
00107 {
00108 Abc_Obj_t * pNode, * pFanin1, * pFanin2;
00109 int n, i, k;
00110 Abc_NtkForEachNode( pNtk, pNode, n )
00111 {
00112 Abc_ObjForEachFanin( pNode, pFanin1, i )
00113 {
00114 if ( i < 2 && Abc_ObjFaninC(pNode, i) )
00115 return 0;
00116 Abc_ObjForEachFanin( pNode, pFanin2, k )
00117 {
00118 if ( i == k )
00119 continue;
00120 if ( pFanin1 == pFanin2 )
00121 return 0;
00122 }
00123 }
00124 }
00125 return 1;
00126 }
00127
00139 void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
00140 {
00141 Abc_Obj_t * pNode;
00142 int i;
00143
00144 p->pManSop = pNtk->pManFunc;
00145 p->vSops = Vec_PtrAlloc(0);
00146 p->vFanins = Vec_PtrAlloc(0);
00147 p->vSopsNew = Vec_PtrAlloc(0);
00148 p->vFaninsNew = Vec_PtrAlloc(0);
00149 Vec_PtrFill( p->vSops, Abc_NtkObjNumMax(pNtk), NULL );
00150 Vec_PtrFill( p->vFanins, Abc_NtkObjNumMax(pNtk), NULL );
00151 Vec_PtrFill( p->vSopsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
00152 Vec_PtrFill( p->vFaninsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
00153
00154 Abc_NtkForEachNode( pNtk, pNode, i )
00155 {
00156 if ( Abc_SopGetVarNum(pNode->pData) < 2 )
00157 continue;
00158 if ( Abc_SopGetCubeNum(pNode->pData) < 1 )
00159 continue;
00160 p->vSops->pArray[i] = pNode->pData;
00161 p->vFanins->pArray[i] = &pNode->vFanins;
00162 }
00163 p->nNodesOld = Abc_NtkObjNumMax(pNtk);
00164 }
00165
00177 void Abc_NtkFxuFreeInfo( Fxu_Data_t * p )
00178 {
00179 int i;
00180
00181 if ( p->vFaninsNew )
00182 for ( i = 0; i < p->vFaninsNew->nSize; i++ )
00183 if ( p->vFaninsNew->pArray[i] )
00184 Vec_IntFree( p->vFaninsNew->pArray[i] );
00185
00186 if ( p->vSops ) Vec_PtrFree( p->vSops );
00187 if ( p->vSopsNew ) Vec_PtrFree( p->vSopsNew );
00188 if ( p->vFanins ) Vec_PtrFree( p->vFanins );
00189 if ( p->vFaninsNew ) Vec_PtrFree( p->vFaninsNew );
00190 FREE( p );
00191 }
00192
00204 void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
00205 {
00206 Vec_Int_t * vFanins;
00207 Abc_Obj_t * pNode, * pFanin;
00208 int i, k;
00209
00210 assert( p->vFanins->nSize < p->vFaninsNew->nSize );
00211
00212 for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
00213 {
00214
00215 pNode = Abc_NtkCreateNode( pNtk );
00216 assert( i == (int)pNode->Id );
00217 }
00218
00219 for ( i = 0; i < p->vFanins->nSize; i++ )
00220 {
00221
00222 vFanins = p->vFaninsNew->pArray[i];
00223 if ( vFanins == NULL )
00224 continue;
00225
00226 pNode = Abc_NtkObj( pNtk, i );
00227 Abc_ObjRemoveFanins( pNode );
00228
00229 vFanins = p->vFaninsNew->pArray[i];
00230 for ( k = 0; k < vFanins->nSize; k++ )
00231 {
00232 pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
00233 Abc_ObjAddFanin( pNode, pFanin );
00234 }
00235 pNode->pData = p->vSopsNew->pArray[i];
00236 assert( pNode->pData != NULL );
00237 }
00238
00239 for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
00240 {
00241
00242 pNode = Abc_NtkObj( pNtk, i );
00243
00244 vFanins = p->vFaninsNew->pArray[i];
00245 for ( k = 0; k < vFanins->nSize; k++ )
00246 {
00247 pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
00248 Abc_ObjAddFanin( pNode, pFanin );
00249 }
00250 pNode->pData = p->vSopsNew->pArray[i];
00251 assert( pNode->pData != NULL );
00252 }
00253 }
00254
00255
00259
00260