00001
00021 #include "abc.h"
00022 #include "espresso.h"
00023
00027
00028 static void Abc_NodeEspresso( Abc_Obj_t * pNode );
00029 static pset_family Abc_SopToEspresso( char * pSop );
00030 static char * Abc_SopFromEspresso( Extra_MmFlex_t * pMan, pset_family Cover );
00031 static pset_family Abc_EspressoMinimize( pset_family pOnset, pset_family pDcset );
00032
00036
00048 void Abc_NtkEspresso( Abc_Ntk_t * pNtk, int fVerbose )
00049 {
00050 Abc_Obj_t * pNode;
00051 int i;
00052 assert( Abc_NtkIsLogic(pNtk) );
00053
00054 if ( Abc_NtkHasMapping(pNtk) )
00055 Abc_NtkMapToSop(pNtk);
00056 else if ( Abc_NtkHasBdd(pNtk) )
00057 {
00058 if ( !Abc_NtkBddToSop(pNtk, 0) )
00059 {
00060 printf( "Abc_NtkEspresso(): Converting to SOPs has failed.\n" );
00061 return;
00062 }
00063 }
00064
00065 Abc_NtkForEachNode( pNtk, pNode, i )
00066 if ( i ) Abc_NodeEspresso( pNode );
00067 }
00068
00080 void Abc_NodeEspresso( Abc_Obj_t * pNode )
00081 {
00082 extern void define_cube_size( int n );
00083 pset_family Cover;
00084 int fCompl;
00085
00086 assert( Abc_ObjIsNode(pNode) );
00087
00088 define_cube_size( Abc_ObjFaninNum(pNode) );
00089
00090 fCompl = Abc_SopIsComplement( pNode->pData );
00091 Cover = Abc_SopToEspresso( pNode->pData );
00092
00093 Cover = Abc_EspressoMinimize( Cover, NULL );
00094
00095 pNode->pData = Abc_SopFromEspresso( pNode->pNtk->pManFunc, Cover );
00096 if ( fCompl ) Abc_SopComplement( pNode->pData );
00097 sf_free(Cover);
00098 }
00099
00111 pset_family Abc_SopToEspresso( char * pSop )
00112 {
00113 char * pCube;
00114 pset_family Cover;
00115 pset set;
00116 int nCubes, nVars, Value, v;
00117
00118 if ( pSop == NULL )
00119 return NULL;
00120
00121 nVars = Abc_SopGetVarNum(pSop);
00122 nCubes = Abc_SopGetCubeNum(pSop);
00123 assert( cube.size == 2 * nVars );
00124
00125 if ( Abc_SopIsConst0(pSop) )
00126 {
00127 Cover = sf_new(0, cube.size);
00128 return Cover;
00129 }
00130 if ( Abc_SopIsConst1(pSop) )
00131 {
00132 Cover = sf_new(1, cube.size);
00133 set = GETSET(Cover, Cover->count++);
00134 set_copy( set, cube.fullset );
00135 return Cover;
00136 }
00137
00138
00139 Cover = sf_new(nCubes, cube.size);
00140
00141 Abc_SopForEachCube( pSop, nVars, pCube )
00142 {
00143 set = GETSET(Cover, Cover->count++);
00144 set_copy( set, cube.fullset );
00145 Abc_CubeForEachVar( pCube, Value, v )
00146 {
00147 if ( Value == '0' )
00148 set_remove(set, 2*v+1);
00149 else if ( Value == '1' )
00150 set_remove(set, 2*v);
00151 }
00152 }
00153 return Cover;
00154 }
00155
00167 char * Abc_SopFromEspresso( Extra_MmFlex_t * pMan, pset_family Cover )
00168 {
00169 pset set;
00170 char * pSop, * pCube;
00171 int Lit, nVars, nCubes, i, k;
00172
00173 nVars = Cover->sf_size/2;
00174 nCubes = Cover->count;
00175
00176 pSop = Abc_SopStart( pMan, nCubes, nVars );
00177
00178
00179 i = 0;
00180 Abc_SopForEachCube( pSop, nVars, pCube )
00181 {
00182 set = GETSET(Cover, i++);
00183 for ( k = 0; k < nVars; k++ )
00184 {
00185 Lit = GETINPUT(set, k);
00186 if ( Lit == ZERO )
00187 pCube[k] = '0';
00188 else if ( Lit == ONE )
00189 pCube[k] = '1';
00190 }
00191 }
00192 return pSop;
00193 }
00194
00195
00207 pset_family Abc_EspressoMinimize( pset_family pOnset, pset_family pDcset )
00208 {
00209 pset_family pOffset;
00210 int fNewDcset, i;
00211 int fSimple = 0;
00212 int fSparse = 0;
00213
00214 if ( fSimple )
00215 {
00216 for ( i = 0; i < cube.num_vars; i++ )
00217 pOnset = d1merge( pOnset, i );
00218 pOnset = sf_contain( pOnset );
00219 return pOnset;
00220 }
00221
00222
00223 fNewDcset = (pDcset == NULL);
00224 if ( pDcset == NULL )
00225 pDcset = sf_new( 1, cube.size );
00226 pDcset->wsize = pOnset->wsize;
00227 pDcset->sf_size = pOnset->sf_size;
00228
00229
00230 if ( pDcset->sf_size == 0 || pDcset->count == 0 )
00231 pOffset = complement(cube1list(pOnset));
00232 else
00233 pOffset = complement(cube2list(pOnset, pDcset));
00234
00235
00236 skip_make_sparse = !fSparse;
00237 pOnset = espresso( pOnset, pDcset, pOffset );
00238
00239
00240 sf_free( pOffset );
00241 if ( fNewDcset )
00242 sf_free( pDcset );
00243 return pOnset;
00244 }
00245
00249
00250