00001
00019 #include "abc.h"
00020 #include "dec.h"
00021 #include "ivy.h"
00022
00026
00030
00043 Abc_Obj_t * Dec_GraphToNetwork( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph )
00044 {
00045 Abc_Obj_t * pAnd0, * pAnd1;
00046 Dec_Node_t * pNode;
00047 int i;
00048
00049 if ( Dec_GraphIsConst(pGraph) )
00050 return Abc_ObjNotCond( Abc_AigConst1(pNtk), Dec_GraphIsComplement(pGraph) );
00051
00052 if ( Dec_GraphIsVar(pGraph) )
00053 return Abc_ObjNotCond( Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
00054
00055 Dec_GraphForEachNode( pGraph, pNode, i )
00056 {
00057 pAnd0 = Abc_ObjNotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
00058 pAnd1 = Abc_ObjNotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
00059 pNode->pFunc = Abc_AigAnd( pNtk->pManFunc, pAnd0, pAnd1 );
00060 }
00061
00062 return Abc_ObjNotCond( pNode->pFunc, Dec_GraphIsComplement(pGraph) );
00063 }
00064
00077 Abc_Obj_t * Dec_GraphToNetworkNoStrash( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph )
00078 {
00079 Abc_Obj_t * pAnd, * pAnd0, * pAnd1;
00080 Dec_Node_t * pNode;
00081 int i;
00082
00083 if ( Dec_GraphIsConst(pGraph) )
00084 return Abc_ObjNotCond( Abc_AigConst1(pNtk), Dec_GraphIsComplement(pGraph) );
00085
00086 if ( Dec_GraphIsVar(pGraph) )
00087 return Abc_ObjNotCond( Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
00088
00089 Dec_GraphForEachNode( pGraph, pNode, i )
00090 {
00091 pAnd0 = Abc_ObjNotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
00092 pAnd1 = Abc_ObjNotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
00093
00094 pAnd = Abc_NtkCreateNode( pNtk );
00095 Abc_ObjAddFanin( pAnd, pAnd0 );
00096 Abc_ObjAddFanin( pAnd, pAnd1 );
00097 pNode->pFunc = pAnd;
00098 }
00099
00100 return Abc_ObjNotCond( pNode->pFunc, Dec_GraphIsComplement(pGraph) );
00101 }
00102
00117 int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax )
00118 {
00119 Abc_Aig_t * pMan = pRoot->pNtk->pManFunc;
00120 Dec_Node_t * pNode, * pNode0, * pNode1;
00121 Abc_Obj_t * pAnd, * pAnd0, * pAnd1;
00122 int i, Counter, LevelNew, LevelOld;
00123
00124 if ( Dec_GraphIsConst(pGraph) || Dec_GraphIsVar(pGraph) )
00125 return 0;
00126
00127 Dec_GraphForEachLeaf( pGraph, pNode, i )
00128 pNode->Level = Abc_ObjRegular(pNode->pFunc)->Level;
00129
00130 Counter = 0;
00131 Dec_GraphForEachNode( pGraph, pNode, i )
00132 {
00133
00134 pNode0 = Dec_GraphNode( pGraph, pNode->eEdge0.Node );
00135 pNode1 = Dec_GraphNode( pGraph, pNode->eEdge1.Node );
00136
00137 pAnd0 = pNode0->pFunc;
00138 pAnd1 = pNode1->pFunc;
00139 if ( pAnd0 && pAnd1 )
00140 {
00141
00142 pAnd0 = Abc_ObjNotCond( pAnd0, pNode->eEdge0.fCompl );
00143 pAnd1 = Abc_ObjNotCond( pAnd1, pNode->eEdge1.fCompl );
00144 pAnd = Abc_AigAndLookup( pMan, pAnd0, pAnd1 );
00145
00146 if ( Abc_ObjRegular(pAnd) == pRoot )
00147 return -1;
00148 }
00149 else
00150 pAnd = NULL;
00151
00152 if ( pAnd == NULL || Abc_NodeIsTravIdCurrent(Abc_ObjRegular(pAnd)) )
00153 {
00154 if ( ++Counter > NodeMax )
00155 return -1;
00156 }
00157
00158 LevelNew = 1 + ABC_MAX( pNode0->Level, pNode1->Level );
00159 if ( pAnd )
00160 {
00161 if ( Abc_ObjRegular(pAnd) == Abc_AigConst1(pRoot->pNtk) )
00162 LevelNew = 0;
00163 else if ( Abc_ObjRegular(pAnd) == Abc_ObjRegular(pAnd0) )
00164 LevelNew = (int)Abc_ObjRegular(pAnd0)->Level;
00165 else if ( Abc_ObjRegular(pAnd) == Abc_ObjRegular(pAnd1) )
00166 LevelNew = (int)Abc_ObjRegular(pAnd1)->Level;
00167 LevelOld = (int)Abc_ObjRegular(pAnd)->Level;
00168
00169 }
00170 if ( LevelNew > LevelMax )
00171 return -1;
00172 pNode->pFunc = pAnd;
00173 pNode->Level = LevelNew;
00174 }
00175 return Counter;
00176 }
00177
00178
00190 void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, bool fUpdateLevel, int nGain )
00191 {
00192 Abc_Obj_t * pRootNew;
00193 Abc_Ntk_t * pNtk = pRoot->pNtk;
00194 int nNodesNew, nNodesOld;
00195 nNodesOld = Abc_NtkNodeNum(pNtk);
00196
00197 pRootNew = Dec_GraphToNetwork( pNtk, pGraph );
00198
00199 Abc_AigReplace( pNtk->pManFunc, pRoot, pRootNew, fUpdateLevel );
00200
00201 nNodesNew = Abc_NtkNodeNum(pNtk);
00202 assert( nGain <= nNodesOld - nNodesNew );
00203 }
00204
00205
00217 Hop_Obj_t * Dec_GraphToNetworkAig( Hop_Man_t * pMan, Dec_Graph_t * pGraph )
00218 {
00219 Dec_Node_t * pNode;
00220 Hop_Obj_t * pAnd0, * pAnd1;
00221 int i;
00222
00223 if ( Dec_GraphIsConst(pGraph) )
00224 return Hop_NotCond( Hop_ManConst1(pMan), Dec_GraphIsComplement(pGraph) );
00225
00226 if ( Dec_GraphIsVar(pGraph) )
00227 return Hop_NotCond( Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
00228
00229 Dec_GraphForEachNode( pGraph, pNode, i )
00230 {
00231 pAnd0 = Hop_NotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
00232 pAnd1 = Hop_NotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
00233 pNode->pFunc = Hop_And( pMan, pAnd0, pAnd1 );
00234 }
00235
00236 return Hop_NotCond( pNode->pFunc, Dec_GraphIsComplement(pGraph) );
00237 }
00238
00250 Hop_Obj_t * Dec_GraphFactorSop( Hop_Man_t * pMan, char * pSop )
00251 {
00252 Hop_Obj_t * pFunc;
00253 Dec_Graph_t * pFForm;
00254 Dec_Node_t * pNode;
00255 int i;
00256
00257 pFForm = Dec_Factor( pSop );
00258
00259 Dec_GraphForEachLeaf( pFForm, pNode, i )
00260 pNode->pFunc = Hop_IthVar( pMan, i );
00261
00262 pFunc = Dec_GraphToNetworkAig( pMan, pFForm );
00263 Dec_GraphFree( pFForm );
00264 return pFunc;
00265 }
00266
00278 Ivy_Obj_t * Dec_GraphToNetworkIvy( Ivy_Man_t * pMan, Dec_Graph_t * pGraph )
00279 {
00280 Dec_Node_t * pNode;
00281 Ivy_Obj_t * pAnd0, * pAnd1;
00282 int i;
00283
00284 if ( Dec_GraphIsConst(pGraph) )
00285 return Ivy_NotCond( Ivy_ManConst1(pMan), Dec_GraphIsComplement(pGraph) );
00286
00287 if ( Dec_GraphIsVar(pGraph) )
00288 return Ivy_NotCond( Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
00289
00290 Dec_GraphForEachNode( pGraph, pNode, i )
00291 {
00292 pAnd0 = Ivy_NotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
00293 pAnd1 = Ivy_NotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
00294 pNode->pFunc = Ivy_And( pMan, pAnd0, pAnd1 );
00295 }
00296
00297 return Ivy_NotCond( pNode->pFunc, Dec_GraphIsComplement(pGraph) );
00298 }
00299
00300
00304
00305