abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcEspresso.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcEspresso.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Procedures to minimize SOPs using Espresso.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcEspresso.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "misc/espresso/espresso.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static void Abc_NodeEspresso( Abc_Obj_t * pNode );
32 static pset_family Abc_SopToEspresso( char * pSop );
33 static char * Abc_SopFromEspresso( Extra_MmFlex_t * pMan, pset_family Cover );
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Minimizes SOP representations using Espresso.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
51 void 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, 0) )
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 
72 /**Function*************************************************************
73 
74  Synopsis [Minimizes SOP representation of one node.]
75 
76  Description []
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
83 void 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
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 
103 /**Function*************************************************************
104 
105  Synopsis [Converts SOP in ABC into SOP representation in Espresso.]
106 
107  Description []
108 
109  SideEffects []
110 
111  SeeAlso []
112 
113 ***********************************************************************/
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 
159 /**Function*************************************************************
160 
161  Synopsis [Converts SOP representation in Espresso into SOP in ABC.]
162 
163  Description []
164 
165  SideEffects []
166 
167  SeeAlso []
168 
169 ***********************************************************************/
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 
199 /**Function*************************************************************
200 
201  Synopsis [Minimizes the cover using Espresso.]
202 
203  Description []
204 
205  SideEffects []
206 
207  SeeAlso []
208 
209 ***********************************************************************/
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 
249 ////////////////////////////////////////////////////////////////////////
250 /// END OF FILE ///
251 ////////////////////////////////////////////////////////////////////////
252 
253 
255 
ABC_DLL char * Abc_SopStart(Mem_Flex_t *pMan, int nCubes, int nVars)
Definition: abcSop.c:76
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
static int Abc_NtkHasBdd(Abc_Ntk_t *pNtk)
Definition: abc.h:254
pset_family sf_new()
ABC_NAMESPACE_IMPL_START pcover espresso(pcover F, pcover D1, pcover R)
Definition: espresso.c:53
pset set_copy()
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Abc_NtkHasMapping(Abc_Ntk_t *pNtk)
Definition: abc.h:256
pset_family d1merge(INOUT pset_family A, IN int var)
Definition: contain.c:161
void Abc_NtkEspresso(Abc_Ntk_t *pNtk, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcEspresso.c:51
int count
Definition: espresso.h:80
void sf_free()
pcover complement(pcube *T)
Definition: compl.c:49
#define Abc_CubeForEachVar(pCube, Value, i)
Definition: abc.h:529
#define ONE
Definition: espresso.h:414
#define ZERO
Definition: espresso.h:415
#define GETINPUT(c, pos)
Definition: espresso.h:400
ABC_NAMESPACE_IMPL_START pset_family sf_contain(INOUT pset_family A)
Definition: contain.c:37
void * pManFunc
Definition: abc.h:191
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
static pset_family Abc_EspressoMinimize(pset_family pOnset, pset_family pDcset)
Definition: abcEspresso.c:210
ABC_DLL int Abc_NtkMapToSop(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1073
static char * Abc_SopFromEspresso(Extra_MmFlex_t *pMan, pset_family Cover)
Definition: abcEspresso.c:170
void define_cube_size(int n)
Definition: cubehack.c:51
static ABC_NAMESPACE_IMPL_START void Abc_NodeEspresso(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcEspresso.c:83
int sf_size
Definition: espresso.h:78
pcube * cube2list(pcover A, pcover B)
Definition: cofactor.c:306
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
unsigned int * pset
Definition: espresso.h:73
ABC_DLL int Abc_SopIsConst0(char *pSop)
Definition: abcSop.c:676
ABC_DLL int Abc_SopIsConst1(char *pSop)
Definition: abcSop.c:692
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
bool skip_make_sparse
Definition: globals.c:28
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define set_remove(set, e)
Definition: espresso.h:171
Abc_Ntk_t * pNtk
Definition: abc.h:130
ABC_DLL void Abc_SopComplement(char *pSop)
Definition: abcSop.c:600
#define GETSET(family, index)
Definition: espresso.h:161
ABC_DLL int Abc_NtkBddToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:359
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
static pset_family Abc_SopToEspresso(char *pSop)
Definition: abcEspresso.c:114
void * pData
Definition: abc.h:145
ABC_DLL int Abc_SopIsComplement(char *pSop)
Definition: abcSop.c:655
int wsize
Definition: espresso.h:77
pcube * cube1list(pcover A)
Definition: cofactor.c:289