ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcEspresso.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
23
25
26
30
31static void Abc_NodeEspresso( Abc_Obj_t * pNode );
32static pset_family Abc_SopToEspresso( char * pSop );
33static char * Abc_SopFromEspresso( Extra_MmFlex_t * pMan, pset_family Cover );
34static pset_family Abc_EspressoMinimize( pset_family pOnset, pset_family pDcset );
35
39
51void Abc_NtkEspresso( Abc_Ntk_t * pNtk, int fVerbose )
52{
53 Abc_Obj_t * pNode;
54 int i;
55 assert( Abc_NtkIsLogic(pNtk) );
56 // convert the network to have SOPs
57 if ( Abc_NtkHasMapping(pNtk) )
58 Abc_NtkMapToSop(pNtk);
59 else if ( Abc_NtkHasBdd(pNtk) )
60 {
61 if ( !Abc_NtkBddToSop(pNtk, -1, ABC_INFINITY, 1) )
62 {
63 printf( "Abc_NtkEspresso(): Converting to SOPs has failed.\n" );
64 return;
65 }
66 }
67 // minimize SOPs of all nodes
68 Abc_NtkForEachNode( pNtk, pNode, i )
69 if ( i ) Abc_NodeEspresso( pNode );
70}
71
83void Abc_NodeEspresso( Abc_Obj_t * pNode )
84{
85 extern void define_cube_size( int n );
86 pset_family Cover;
87 int fCompl;
88
89 assert( Abc_ObjIsNode(pNode) );
90 // define the cube for this node
91 define_cube_size( Abc_ObjFaninNum(pNode) );
92 // create the Espresso cover
93 fCompl = Abc_SopIsComplement( pNode->pData );
94 Cover = Abc_SopToEspresso( pNode->pData );
95 // perform minimization
96 Cover = Abc_EspressoMinimize( Cover, NULL ); // deletes also cover
97 // convert back onto the node's SOP representation
98 pNode->pData = Abc_SopFromEspresso( pNode->pNtk->pManFunc, Cover );
99 if ( fCompl ) Abc_SopComplement( pNode->pData );
100 sf_free(Cover);
101}
102
114pset_family Abc_SopToEspresso( char * pSop )
115{
116 char * pCube;
117 pset_family Cover;
118 pset set;
119 int nCubes, nVars, Value, v;
120
121 if ( pSop == NULL )
122 return NULL;
123
124 nVars = Abc_SopGetVarNum(pSop);
125 nCubes = Abc_SopGetCubeNum(pSop);
126 assert( cube.size == 2 * nVars );
127
128 if ( Abc_SopIsConst0(pSop) )
129 {
130 Cover = sf_new(0, cube.size);
131 return Cover;
132 }
133 if ( Abc_SopIsConst1(pSop) )
134 {
135 Cover = sf_new(1, cube.size);
136 set = GETSET(Cover, Cover->count++);
137 set_copy( set, cube.fullset );
138 return Cover;
139 }
140
141 // create the cover
142 Cover = sf_new(nCubes, cube.size);
143 // fill in the cubes
144 Abc_SopForEachCube( pSop, nVars, pCube )
145 {
146 set = GETSET(Cover, Cover->count++);
147 set_copy( set, cube.fullset );
148 Abc_CubeForEachVar( pCube, Value, v )
149 {
150 if ( Value == '0' )
151 set_remove(set, 2*v+1);
152 else if ( Value == '1' )
153 set_remove(set, 2*v);
154 }
155 }
156 return Cover;
157}
158
170char * Abc_SopFromEspresso( Extra_MmFlex_t * pMan, pset_family Cover )
171{
172 pset set;
173 char * pSop, * pCube;
174 int Lit, nVars, nCubes, i, k;
175
176 nVars = Cover->sf_size/2;
177 nCubes = Cover->count;
178
179 pSop = Abc_SopStart( pMan, nCubes, nVars );
180
181 // go through the cubes
182 i = 0;
183 Abc_SopForEachCube( pSop, nVars, pCube )
184 {
185 set = GETSET(Cover, i++);
186 for ( k = 0; k < nVars; k++ )
187 {
188 Lit = GETINPUT(set, k);
189 if ( Lit == ZERO )
190 pCube[k] = '0';
191 else if ( Lit == ONE )
192 pCube[k] = '1';
193 }
194 }
195 return pSop;
196}
197
198
210pset_family Abc_EspressoMinimize( pset_family pOnset, pset_family pDcset )
211{
212 pset_family pOffset;
213 int fNewDcset, i;
214 int fSimple = 0;
215 int fSparse = 0;
216
217 if ( fSimple )
218 {
219 for ( i = 0; i < cube.num_vars; i++ )
220 pOnset = d1merge( pOnset, i );
221 pOnset = sf_contain( pOnset );
222 return pOnset;
223 }
224
225 // create the dcset
226 fNewDcset = (pDcset == NULL);
227 if ( pDcset == NULL )
228 pDcset = sf_new( 1, cube.size );
229 pDcset->wsize = pOnset->wsize;
230 pDcset->sf_size = pOnset->sf_size;
231
232 // derive the offset
233 if ( pDcset->sf_size == 0 || pDcset->count == 0 )
234 pOffset = complement(cube1list(pOnset));
235 else
236 pOffset = complement(cube2list(pOnset, pDcset));
237
238 // perform minimization
239 skip_make_sparse = !fSparse;
240 pOnset = espresso( pOnset, pDcset, pOffset );
241
242 // free covers
243 sf_free( pOffset );
244 if ( fNewDcset )
245 sf_free( pDcset );
246 return pOnset;
247}
248
252
253
255
void Abc_NtkEspresso(Abc_Ntk_t *pNtk, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcEspresso.c:51
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL char * Abc_SopStart(Mem_Flex_t *pMan, int nCubes, int nVars)
Definition abcSop.c:82
ABC_DLL int Abc_SopIsConst0(char *pSop)
Definition abcSop.c:724
ABC_DLL void Abc_SopComplement(char *pSop)
Definition abcSop.c:648
#define Abc_CubeForEachVar(pCube, Value, i)
Definition abc.h:536
ABC_DLL int Abc_NtkMapToSop(Abc_Ntk_t *pNtk)
Definition abcFunc.c:1228
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition abc.h:538
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
ABC_DLL int Abc_SopIsComplement(char *pSop)
Definition abcSop.c:703
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition abcSop.c:537
ABC_DLL int Abc_SopIsConst1(char *pSop)
Definition abcSop.c:740
ABC_DLL int Abc_NtkBddToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit, int fCubeSort)
Definition abcFunc.c:866
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void define_cube_size(int n)
Definition cubehack.c:51
#define ONE
Definition espresso.h:414
pset_family sf_new()
pset_family sf_contain()
pset_family d1merge()
pcube * cube2list()
void sf_free()
#define GETSET(family, index)
Definition espresso.h:161
pcover espresso()
#define set_remove(set, e)
Definition espresso.h:171
bool skip_make_sparse
Definition globals.c:28
struct set_family * pset_family
#define ZERO
Definition espresso.h:415
unsigned int * pset
Definition espresso.h:73
#define GETINPUT(c, pos)
Definition espresso.h:400
pset set_copy()
pcube * cube1list()
pcover complement()
struct Extra_MmFlex_t_ Extra_MmFlex_t
Definition extra.h:148
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
Definition exor.h:123
int count
Definition espresso.h:80
int wsize
Definition espresso.h:77
int sf_size
Definition espresso.h:78
#define assert(ex)
Definition util_old.h:213