abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
covMinEsop.c File Reference
#include "covInt.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Min_EsopRewrite (Min_Man_t *p)
 DECLARATIONS ///. More...
 
void Min_EsopMinimize (Min_Man_t *p)
 FUNCTION DEFINITIONS ///. More...
 
int Min_EsopAddCubeInt (Min_Man_t *p, Min_Cube_t *pCube)
 
void Min_EsopAddCube (Min_Man_t *p, Min_Cube_t *pCube)
 

Function Documentation

void Min_EsopAddCube ( Min_Man_t p,
Min_Cube_t pCube 
)

Function*************************************************************

Synopsis [Adds the cube to storage.]

Description []

SideEffects []

SeeAlso []

Definition at line 291 of file covMinEsop.c.

292 {
293  assert( pCube != p->pBubble );
294  assert( (int)pCube->nLits == Min_CubeCountLits(pCube) );
295  while ( Min_EsopAddCubeInt( p, pCube ) );
296 }
int Min_EsopAddCubeInt(Min_Man_t *p, Min_Cube_t *pCube)
Definition: covMinEsop.c:220
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Min_CubeCountLits(Min_Cube_t *pCube)
Definition: covInt.h:224
unsigned nLits
Definition: covInt.h:59
#define assert(ex)
Definition: util_old.h:213
int Min_EsopAddCubeInt ( Min_Man_t p,
Min_Cube_t pCube 
)

Function*************************************************************

Synopsis [Adds the cube to storage.]

Description [Returns 0 if the cube is added or removed. Returns 1 if the cube is glued with some other cube and has to be added again. Do not forget to clean the storage!]

SideEffects []

SeeAlso []

Definition at line 220 of file covMinEsop.c.

221 {
222  Min_Cube_t * pThis, ** ppPrev;
223  // try to find the identical cube
224  Min_CoverForEachCubePrev( p->ppStore[pCube->nLits], pThis, ppPrev )
225  {
226  if ( Min_CubesAreEqual( pCube, pThis ) )
227  {
228  *ppPrev = pThis->pNext;
229  Min_CubeRecycle( p, pCube );
230  Min_CubeRecycle( p, pThis );
231  p->nCubes--;
232  return 0;
233  }
234  }
235  // find a distance-1 cube if it exists
236  if ( pCube->nLits < pCube->nVars )
237  Min_CoverForEachCubePrev( p->ppStore[pCube->nLits+1], pThis, ppPrev )
238  {
239  if ( Min_CubesDistOne( pCube, pThis, p->pTemp ) )
240  {
241  *ppPrev = pThis->pNext;
242  Min_CubesTransform( pCube, pThis, p->pTemp );
243  pCube->nLits++;
244  Min_CubeRecycle( p, pThis );
245  p->nCubes--;
246  return 1;
247  }
248  }
249  Min_CoverForEachCubePrev( p->ppStore[pCube->nLits], pThis, ppPrev )
250  {
251  if ( Min_CubesDistOne( pCube, pThis, p->pTemp ) )
252  {
253  *ppPrev = pThis->pNext;
254  Min_CubesTransform( pCube, pThis, p->pTemp );
255  pCube->nLits--;
256  Min_CubeRecycle( p, pThis );
257  p->nCubes--;
258  return 1;
259  }
260  }
261  if ( pCube->nLits > 0 )
262  Min_CoverForEachCubePrev( p->ppStore[pCube->nLits-1], pThis, ppPrev )
263  {
264  if ( Min_CubesDistOne( pCube, pThis, p->pTemp ) )
265  {
266  *ppPrev = pThis->pNext;
267  Min_CubesTransform( pCube, pThis, p->pTemp );
268  Min_CubeRecycle( p, pThis );
269  p->nCubes--;
270  return 1;
271  }
272  }
273  // add the cube
274  pCube->pNext = p->ppStore[pCube->nLits];
275  p->ppStore[pCube->nLits] = pCube;
276  p->nCubes++;
277  return 0;
278 }
static void Min_CubeRecycle(Min_Man_t *p, Min_Cube_t *pCube)
Definition: covInt.h:189
unsigned nVars
Definition: covInt.h:57
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Min_Cube_t * pNext
Definition: covInt.h:56
static int Min_CubesDistOne(Min_Cube_t *pCube0, Min_Cube_t *pCube1, Min_Cube_t *pTemp)
Definition: covInt.h:349
static void Min_CubesTransform(Min_Cube_t *pCube, Min_Cube_t *pDist, Min_Cube_t *pMask)
Definition: covInt.h:542
unsigned nLits
Definition: covInt.h:59
#define Min_CoverForEachCubePrev(pCover, pCube, ppPrev)
Definition: covInt.h:75
static int Min_CubesAreEqual(Min_Cube_t *pCube0, Min_Cube_t *pCube1)
Definition: covInt.h:502
void Min_EsopMinimize ( Min_Man_t p)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file covMinEsop.c.

48 {
49  int nCubesInit, nCubesOld, nIter;
50  if ( p->nCubes < 3 )
51  return;
52  nIter = 0;
53  nCubesInit = p->nCubes;
54  do {
55  nCubesOld = p->nCubes;
56  Min_EsopRewrite( p );
57  nIter++;
58  }
59  while ( 100.0*(nCubesOld - p->nCubes)/nCubesOld > 3.0 );
60 
61 // printf( "%d:%d->%d ", nIter, nCubesInit, p->nCubes );
62 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static ABC_NAMESPACE_IMPL_START void Min_EsopRewrite(Min_Man_t *p)
DECLARATIONS ///.
Definition: covMinEsop.c:79
void Min_EsopRewrite ( Min_Man_t p)
static

DECLARATIONS ///.

CFile****************************************************************

FileName [covMinEsop.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Mapping into network of SOPs/ESOPs.]

Synopsis [ESOP manipulation.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
covMinEsop.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Function*************************************************************

Synopsis [Performs one round of rewriting using distance 2 cubes.]

Description [The weakness of this procedure is that it tries each cube with only one distance-2 cube. If this pair does not lead to improvement the cube is inserted into the cover anyhow, and we try another pair. A possible improvement would be to try this cube with all distance-2 cubes, until an improvement is found, or until all such cubes are tried.]

SideEffects []

SeeAlso []

Definition at line 79 of file covMinEsop.c.

80 {
81  Min_Cube_t * pCube, ** ppPrev;
82  Min_Cube_t * pThis, ** ppPrevT;
83  int v00, v01, v10, v11, Var0, Var1, Index, nCubesOld;
84  int nPairs = 0;
85 
86  // insert the bubble before the first cube
87  p->pBubble->pNext = p->ppStore[0];
88  p->ppStore[0] = p->pBubble;
89  p->pBubble->nLits = 0;
90 
91  // go through the cubes
92  while ( 1 )
93  {
94  // get the index of the bubble
95  Index = p->pBubble->nLits;
96 
97  // find the bubble
98  Min_CoverForEachCubePrev( p->ppStore[Index], pCube, ppPrev )
99  if ( pCube == p->pBubble )
100  break;
101  assert( pCube == p->pBubble );
102 
103  // remove the bubble, get the next cube after the bubble
104  *ppPrev = p->pBubble->pNext;
105  pCube = p->pBubble->pNext;
106  if ( pCube == NULL )
107  for ( Index++; Index <= p->nVars; Index++ )
108  if ( p->ppStore[Index] )
109  {
110  ppPrev = &(p->ppStore[Index]);
111  pCube = p->ppStore[Index];
112  break;
113  }
114  // stop if there is no more cubes
115  if ( pCube == NULL )
116  break;
117 
118  // find the first dist2 cube
119  Min_CoverForEachCubePrev( pCube->pNext, pThis, ppPrevT )
120  if ( Min_CubesDistTwo( pCube, pThis, &Var0, &Var1 ) )
121  break;
122  if ( pThis == NULL && Index < p->nVars )
123  Min_CoverForEachCubePrev( p->ppStore[Index+1], pThis, ppPrevT )
124  if ( Min_CubesDistTwo( pCube, pThis, &Var0, &Var1 ) )
125  break;
126  if ( pThis == NULL && Index < p->nVars - 1 )
127  Min_CoverForEachCubePrev( p->ppStore[Index+2], pThis, ppPrevT )
128  if ( Min_CubesDistTwo( pCube, pThis, &Var0, &Var1 ) )
129  break;
130  // continue if there is no dist2 cube
131  if ( pThis == NULL )
132  {
133  // insert the bubble after the cube
134  p->pBubble->pNext = pCube->pNext;
135  pCube->pNext = p->pBubble;
136  p->pBubble->nLits = pCube->nLits;
137  continue;
138  }
139  nPairs++;
140 
141  // remove the cubes, insert the bubble instead of pCube
142  *ppPrevT = pThis->pNext;
143  *ppPrev = p->pBubble;
144  p->pBubble->pNext = pCube->pNext;
145  p->pBubble->nLits = pCube->nLits;
146  p->nCubes -= 2;
147 
148  // Exorlink-2:
149  // A{v00} B{v01} + A{v10} B{v11} =
150  // A{v00+v10} B{v01} + A{v10} B{v01+v11} =
151  // A{v00} B{v01+v11} + A{v00+v10} B{v11}
152 
153  // save the dist2 parameters
154  v00 = Min_CubeGetVar( pCube, Var0 );
155  v01 = Min_CubeGetVar( pCube, Var1 );
156  v10 = Min_CubeGetVar( pThis, Var0 );
157  v11 = Min_CubeGetVar( pThis, Var1 );
158 //printf( "\n" );
159 //Min_CubeWrite( stdout, pCube );
160 //Min_CubeWrite( stdout, pThis );
161 
162  // derive the first pair of resulting cubes
163  Min_CubeXorVar( pCube, Var0, v10 );
164  pCube->nLits -= (v00 != 3);
165  pCube->nLits += ((v00 ^ v10) != 3);
166  Min_CubeXorVar( pThis, Var1, v01 );
167  pThis->nLits -= (v11 != 3);
168  pThis->nLits += ((v01 ^ v11) != 3);
169 
170  // add the cubes
171  nCubesOld = p->nCubes;
172  Min_EsopAddCube( p, pCube );
173  Min_EsopAddCube( p, pThis );
174  // check if the cubes were absorbed
175  if ( p->nCubes < nCubesOld + 2 )
176  continue;
177 
178  // pull out both cubes
179  assert( pThis == p->ppStore[pThis->nLits] );
180  p->ppStore[pThis->nLits] = pThis->pNext;
181  assert( pCube == p->ppStore[pCube->nLits] );
182  p->ppStore[pCube->nLits] = pCube->pNext;
183  p->nCubes -= 2;
184 
185  // derive the second pair of resulting cubes
186  Min_CubeXorVar( pCube, Var0, v10 );
187  pCube->nLits -= ((v00 ^ v10) != 3);
188  pCube->nLits += (v00 != 3);
189  Min_CubeXorVar( pCube, Var1, v11 );
190  pCube->nLits -= (v01 != 3);
191  pCube->nLits += ((v01 ^ v11) != 3);
192 
193  Min_CubeXorVar( pThis, Var0, v00 );
194  pThis->nLits -= (v10 != 3);
195  pThis->nLits += ((v00 ^ v10) != 3);
196  Min_CubeXorVar( pThis, Var1, v01 );
197  pThis->nLits -= ((v01 ^ v11) != 3);
198  pThis->nLits += (v11 != 3);
199 
200  // add them anyhow
201  Min_EsopAddCube( p, pCube );
202  Min_EsopAddCube( p, pThis );
203  }
204 // printf( "Pairs = %d ", nPairs );
205 }
static void Min_CubeXorVar(Min_Cube_t *p, int Var, int Value)
Definition: covInt.h:87
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Min_Cube_t * pNext
Definition: covInt.h:56
for(p=first;p->value< newval;p=p->next)
static int Min_CubesDistTwo(Min_Cube_t *pCube0, Min_Cube_t *pCube1, int *pVar0, int *pVar1)
Definition: covInt.h:390
static int Min_CubeGetVar(Min_Cube_t *p, int Var)
Definition: covInt.h:86
if(last==0)
Definition: sparse_int.h:34
unsigned nLits
Definition: covInt.h:59
#define Min_CoverForEachCubePrev(pCover, pCube, ppPrev)
Definition: covInt.h:75
#define assert(ex)
Definition: util_old.h:213
void Min_EsopAddCube(Min_Man_t *p, Min_Cube_t *pCube)
Definition: covMinEsop.c:291