abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mvcUtils.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mvcUtils.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [Various cover handling utilities.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: mvcUtils.c,v 1.7 2003/04/26 20:41:36 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mvc.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 static int bit_count[256] = {
29  0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
30  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
31  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
32  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
33  1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
34  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
35  2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
36  3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
37 };
38 
39 
40 static void Mvc_CoverCopyColumn( Mvc_Cover_t * pCoverOld, Mvc_Cover_t * pCoverNew, int iColOld, int iColNew );
41 
42 
43 ////////////////////////////////////////////////////////////////////////
44 /// FUNCTION DEFINITIONS ///
45 ////////////////////////////////////////////////////////////////////////
46 
47 /**Function*************************************************************
48 
49  Synopsis []
50 
51  Description []
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
58 void Mvc_CoverSupport( Mvc_Cover_t * pCover, Mvc_Cube_t * pSupp )
59 {
60  Mvc_Cube_t * pCube;
61  // clean the support
62  Mvc_CubeBitClean( pSupp );
63  // collect the support
64  Mvc_CoverForEachCube( pCover, pCube )
65  Mvc_CubeBitOr( pSupp, pSupp, pCube );
66 }
67 
68 /**Function*************************************************************
69 
70  Synopsis []
71 
72  Description []
73 
74  SideEffects []
75 
76  SeeAlso []
77 
78 ***********************************************************************/
79 void Mvc_CoverSupportAnd( Mvc_Cover_t * pCover, Mvc_Cube_t * pSupp )
80 {
81  Mvc_Cube_t * pCube;
82  // clean the support
83  Mvc_CubeBitFill( pSupp );
84  // collect the support
85  Mvc_CoverForEachCube( pCover, pCube )
86  Mvc_CubeBitAnd( pSupp, pSupp, pCube );
87 }
88 
89 /**Function*************************************************************
90 
91  Synopsis []
92 
93  Description []
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
101 {
102  Mvc_Cube_t * pSupp;
103  int Counter, i, v0, v1;
104  // compute the support
105  pSupp = Mvc_CubeAlloc( pCover );
106  Mvc_CoverSupportAnd( pCover, pSupp );
107  Counter = pCover->nBits/2;
108  for ( i = 0; i < pCover->nBits/2; i++ )
109  {
110  v0 = Mvc_CubeBitValue( pSupp, 2*i );
111  v1 = Mvc_CubeBitValue( pSupp, 2*i+1 );
112  if ( v0 && v1 )
113  Counter--;
114  }
115  Mvc_CubeFree( pCover, pSupp );
116  return Counter;
117 }
118 
119 /**Function*************************************************************
120 
121  Synopsis []
122 
123  Description []
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
130 int Mvc_CoverSupportVarBelongs( Mvc_Cover_t * pCover, int iVar )
131 {
132  Mvc_Cube_t * pSupp;
133  int RetValue, v0, v1;
134  // compute the support
135  pSupp = Mvc_CubeAlloc( pCover );
136  Mvc_CoverSupportAnd( pCover, pSupp );
137  v0 = Mvc_CubeBitValue( pSupp, 2*iVar );
138  v1 = Mvc_CubeBitValue( pSupp, 2*iVar+1 );
139  RetValue = (int)( !v0 || !v1 );
140  Mvc_CubeFree( pCover, pSupp );
141  return RetValue;
142 }
143 
144 /**Function*************************************************************
145 
146  Synopsis []
147 
148  Description []
149 
150  SideEffects []
151 
152  SeeAlso []
153 
154 ***********************************************************************/
155 void Mvc_CoverCommonCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pComCube )
156 {
157  Mvc_Cube_t * pCube;
158  // clean the support
159  Mvc_CubeBitFill( pComCube );
160  // collect the support
161  Mvc_CoverForEachCube( pCover, pCube )
162  Mvc_CubeBitAnd( pComCube, pComCube, pCube );
163 }
164 
165 /**Function*************************************************************
166 
167  Synopsis []
168 
169  Description []
170 
171  SideEffects []
172 
173  SeeAlso []
174 
175 ***********************************************************************/
177 {
178  int Result;
179  // get the common cube
180  Mvc_CoverAllocateMask( pCover );
181  Mvc_CoverCommonCube( pCover, pCover->pMask );
182  // check whether the common cube is empty
183  Mvc_CubeBitEmpty( Result, pCover->pMask );
184  return Result;
185 }
186 
187 /**Function*************************************************************
188 
189  Synopsis []
190 
191  Description []
192 
193  SideEffects []
194 
195  SeeAlso []
196 
197 ***********************************************************************/
199 {
200  Mvc_Cube_t * pCube;
201  // get the common cube
202  Mvc_CoverAllocateMask( pCover );
203  Mvc_CoverCommonCube( pCover, pCover->pMask );
204  // remove this cube from the cubes in the cover
205  Mvc_CoverForEachCube( pCover, pCube )
206  Mvc_CubeBitSharp( pCube, pCube, pCover->pMask );
207 }
208 
209 /**Function*************************************************************
210 
211  Synopsis []
212 
213  Description []
214 
215  SideEffects []
216 
217  SeeAlso []
218 
219 ***********************************************************************/
221 {
222  Mvc_Cover_t * pRes;
223  Mvc_Cube_t * pCube;
224  // create the new cover
225  pRes = Mvc_CoverClone( pCover );
226  // get the new cube
227  pCube = Mvc_CubeAlloc( pRes );
228  // get the common cube
229  Mvc_CoverCommonCube( pCover, pCube );
230  // add the cube to the cover
231  Mvc_CoverAddCubeTail( pRes, pCube );
232  return pRes;
233 }
234 
235 
236 /**Function*************************************************************
237 
238  Synopsis [Returns 1 if the support of cover2 is contained in the support of cover1.]
239 
240  Description []
241 
242  SideEffects []
243 
244  SeeAlso []
245 
246 ***********************************************************************/
248 {
249  int Result;
250  assert( pCover1->nBits == pCover2->nBits );
251  // set the supports
252  Mvc_CoverAllocateMask( pCover1 );
253  Mvc_CoverSupport( pCover1, pCover1->pMask );
254  Mvc_CoverAllocateMask( pCover2 );
255  Mvc_CoverSupport( pCover2, pCover2->pMask );
256  // check the containment
257  Mvc_CubeBitNotImpl( Result, pCover2->pMask, pCover1->pMask );
258  return !Result;
259 }
260 
261 /**Function*************************************************************
262 
263  Synopsis [Counts the cube sizes.]
264 
265  Description []
266 
267  SideEffects []
268 
269  SeeAlso []
270 
271 ***********************************************************************/
273 {
274  Mvc_Cube_t * pCube;
275  unsigned char * pByte, * pByteStart, * pByteStop;
276  int nBytes, nOnes;
277 
278  // get the number of unsigned chars in the cube's bit strings
279  nBytes = pCover->nBits / (8 * sizeof(unsigned char)) + (int)(pCover->nBits % (8 * sizeof(unsigned char)) > 0);
280  // iterate through the cubes
281  Mvc_CoverForEachCube( pCover, pCube )
282  {
283  // clean the counter of ones
284  nOnes = 0;
285  // set the starting and stopping positions
286  pByteStart = (unsigned char *)pCube->pData;
287  pByteStop = pByteStart + nBytes;
288  // iterate through the positions
289  for ( pByte = pByteStart; pByte < pByteStop; pByte++ )
290  nOnes += bit_count[*pByte];
291  // set the nOnes
292  Mvc_CubeSetSize( pCube, nOnes );
293  }
294  return 1;
295 }
296 
297 /**Function*************************************************************
298 
299  Synopsis [Counts the cube sizes.]
300 
301  Description []
302 
303  SideEffects []
304 
305  SeeAlso []
306 
307 ***********************************************************************/
309 {
310  unsigned char * pByte, * pByteStart, * pByteStop;
311  int nOnes, nBytes, nBits;
312  // get the number of unsigned chars in the cube's bit strings
313  nBits = (pCube->iLast + 1) * sizeof(Mvc_CubeWord_t) * 8 - pCube->nUnused;
314  nBytes = nBits / (8 * sizeof(unsigned char)) + (int)(nBits % (8 * sizeof(unsigned char)) > 0);
315  // clean the counter of ones
316  nOnes = 0;
317  // set the starting and stopping positions
318  pByteStart = (unsigned char *)pCube->pData;
319  pByteStop = pByteStart + nBytes;
320  // iterate through the positions
321  for ( pByte = pByteStart; pByte < pByteStop; pByte++ )
322  nOnes += bit_count[*pByte];
323  return nOnes;
324 }
325 
326 /**Function*************************************************************
327 
328  Synopsis [Counts the differences in each cube pair in the cover.]
329 
330  Description [Takes the cover (pCover) and the array where the
331  diff counters go (pDiffs). The array pDiffs should have as many
332  entries as there are different pairs of cubes in the cover: n(n-1)/2.
333  Fills out the array pDiffs with the following info: For each cube
334  pair, included in the array is the number of literals in both cubes
335  after they are made cube ABC_FREE.]
336 
337  SideEffects []
338 
339  SeeAlso []
340 
341 ***********************************************************************/
342 int Mvc_CoverCountCubePairDiffs( Mvc_Cover_t * pCover, unsigned char pDiffs[] )
343 {
344  Mvc_Cube_t * pCube1;
345  Mvc_Cube_t * pCube2;
346  Mvc_Cube_t * pMask;
347  unsigned char * pByte, * pByteStart, * pByteStop;
348  int nBytes, nOnes;
349  int nCubePairs;
350 
351  // allocate a temporary mask
352  pMask = Mvc_CubeAlloc( pCover );
353  // get the number of unsigned chars in the cube's bit strings
354  nBytes = pCover->nBits / (8 * sizeof(unsigned char)) + (int)(pCover->nBits % (8 * sizeof(unsigned char)) > 0);
355  // iterate through the cubes
356  nCubePairs = 0;
357  Mvc_CoverForEachCube( pCover, pCube1 )
358  {
360  {
361  // find the bit-wise exor of cubes
362  Mvc_CubeBitExor( pMask, pCube1, pCube2 );
363  // set the starting and stopping positions
364  pByteStart = (unsigned char *)pMask->pData;
365  pByteStop = pByteStart + nBytes;
366  // clean the counter of ones
367  nOnes = 0;
368  // iterate through the positions
369  for ( pByte = pByteStart; pByte < pByteStop; pByte++ )
370  nOnes += bit_count[*pByte];
371  // set the nOnes
372  pDiffs[nCubePairs++] = nOnes;
373  }
374  }
375  // deallocate the mask
376  Mvc_CubeFree( pCover, pMask );
377  return 1;
378 }
379 
380 
381 /**Function*************************************************************
382 
383  Synopsis [Creates a new cover containing some literals of the old cover.]
384 
385  Description [Creates the new cover containing the given number (nVarsRem)
386  literals of the old cover. All the bits of the new cover are initialized
387  to "1". The selected bits from the old cover are copied on top. The numbers
388  of the selected bits to copy are given in the array pVarsRem. The i-set
389  entry in this array is the index of the bit in the old cover which goes
390  to the i-th place in the new cover. If the i-th entry in pVarsRem is -1,
391  it means that the i-th bit does not change (remains composed of all 1's).
392  This is a useful feature to speed up remapping covers, which are known
393  to depend only on a subset of input variables.]
394 
395  SideEffects []
396 
397  SeeAlso []
398 
399 ***********************************************************************/
400 Mvc_Cover_t * Mvc_CoverRemap( Mvc_Cover_t * p, int * pVarsRem, int nVarsRem )
401 {
402  Mvc_Cover_t * pCover;
403  Mvc_Cube_t * pCube, * pCubeCopy;
404  int i;
405  // clone the cover
406  pCover = Mvc_CoverAlloc( p->pMem, nVarsRem );
407  // copy the cube list
408  Mvc_CoverForEachCube( p, pCube )
409  {
410  pCubeCopy = Mvc_CubeAlloc( pCover );
411  //Mvc_CubeBitClean( pCubeCopy ); //changed by wjiang
412  Mvc_CubeBitFill( pCubeCopy ); //changed by wjiang
413  Mvc_CoverAddCubeTail( pCover, pCubeCopy );
414  }
415  // copy the corresponding columns
416  for ( i = 0; i < nVarsRem; i++ )
417  {
418  if (pVarsRem[i] < 0)
419  continue; //added by wjiang
420  assert( pVarsRem[i] >= 0 && pVarsRem[i] < p->nBits );
421  Mvc_CoverCopyColumn( p, pCover, pVarsRem[i], i );
422  }
423  return pCover;
424 }
425 
426 /**Function*************************************************************
427 
428  Synopsis [Copies a column from the old cover to the new cover.]
429 
430  Description [Copies the column (iColOld) of the old cover (pCoverOld)
431  into the column (iColNew) of the new cover (pCoverNew). Assumes that
432  the number of cubes is the same in both covers. Makes no assuptions
433  about the current contents of the column in the new cover.]
434 
435  SideEffects []
436 
437  SeeAlso []
438 
439 ***********************************************************************/
440 void Mvc_CoverCopyColumn( Mvc_Cover_t * pCoverOld, Mvc_Cover_t * pCoverNew,
441  int iColOld, int iColNew )
442 {
443  Mvc_Cube_t * pCubeOld, * pCubeNew;
444  int iWordOld, iWordNew, iBitOld, iBitNew;
445 
446  assert( Mvc_CoverReadCubeNum(pCoverOld) == Mvc_CoverReadCubeNum(pCoverNew) );
447 
448  // get the place of the old and new columns
449  iWordOld = Mvc_CubeWhichWord(iColOld);
450  iBitOld = Mvc_CubeWhichBit(iColOld);
451  iWordNew = Mvc_CubeWhichWord(iColNew);
452  iBitNew = Mvc_CubeWhichBit(iColNew);
453 
454  // go through the cubes of both covers
455  pCubeNew = Mvc_CoverReadCubeHead(pCoverNew);
456  Mvc_CoverForEachCube( pCoverOld, pCubeOld )
457  {
458  if ( pCubeOld->pData[iWordOld] & (1<<iBitOld) )
459  pCubeNew->pData[iWordNew] |= (1<<iBitNew);
460  else
461  pCubeNew->pData[iWordNew] &= ~(1<<iBitNew); // added by wjiang
462  pCubeNew = Mvc_CubeReadNext( pCubeNew );
463  }
464 }
465 
466 /**Function*************************************************************
467 
468  Synopsis []
469 
470  Description []
471 
472  SideEffects []
473 
474  SeeAlso []
475 
476 ***********************************************************************/
478 {
479  Mvc_Cube_t * pCube;
480  // complement the cubes
481  Mvc_CoverForEachCube( pCover, pCube )
482  Mvc_CubeBitNot( pCube );
483 }
484 
485 /**Function*************************************************************
486 
487  Synopsis [This function dups the cover and removes DC literals from cubes.]
488 
489  Description []
490 
491  SideEffects []
492 
493  SeeAlso []
494 
495 ***********************************************************************/
497 {
498  Mvc_Cover_t * pCoverNew;
499  Mvc_Cube_t * pCube;
500 
501  pCoverNew = Mvc_CoverDup( pCover );
502  Mvc_CoverForEachCube( pCoverNew, pCube )
503  Mvc_CubeBitRemoveDcs( pCube );
504  return pCoverNew;
505 }
506 
507 /**Function*************************************************************
508 
509  Synopsis [Returns the cofactor w.r.t. to a binary var.]
510 
511  Description []
512 
513  SideEffects []
514 
515  SeeAlso []
516 
517 ***********************************************************************/
518 Mvc_Cover_t * Mvc_CoverCofactor( Mvc_Cover_t * p, int iValue, int iValueOther )
519 {
520  Mvc_Cover_t * pCover;
521  Mvc_Cube_t * pCube, * pCubeCopy;
522  // clone the cover
523  pCover = Mvc_CoverClone( p );
524  // copy the cube list
525  Mvc_CoverForEachCube( p, pCube )
526  if ( Mvc_CubeBitValue( pCube, iValue ) )
527  {
528  pCubeCopy = Mvc_CubeDup( pCover, pCube );
529  Mvc_CoverAddCubeTail( pCover, pCubeCopy );
530  Mvc_CubeBitInsert( pCubeCopy, iValueOther );
531  }
532  return pCover;
533 }
534 
535 /**Function*************************************************************
536 
537  Synopsis [Returns the cover, in which the binary var is complemented.]
538 
539  Description []
540 
541  SideEffects []
542 
543  SeeAlso []
544 
545 ***********************************************************************/
546 Mvc_Cover_t * Mvc_CoverFlipVar( Mvc_Cover_t * p, int iValue0, int iValue1 )
547 {
548  Mvc_Cover_t * pCover;
549  Mvc_Cube_t * pCube, * pCubeCopy;
550  int Value0, Value1, Temp;
551 
552  assert( iValue0 + 1 == iValue1 ); // should be adjacent
553 
554  // clone the cover
555  pCover = Mvc_CoverClone( p );
556  // copy the cube list
557  Mvc_CoverForEachCube( p, pCube )
558  {
559  pCubeCopy = Mvc_CubeDup( pCover, pCube );
560  Mvc_CoverAddCubeTail( pCover, pCubeCopy );
561 
562  // get the bits
563  Value0 = Mvc_CubeBitValue( pCubeCopy, iValue0 );
564  Value1 = Mvc_CubeBitValue( pCubeCopy, iValue1 );
565 
566  // if both bits are one, nothing to swap
567  if ( Value0 && Value1 )
568  continue;
569  // cannot be both zero because they belong to the same var
570  assert( Value0 || Value1 );
571 
572  // swap the bits
573  Temp = Value0;
574  Value0 = Value1;
575  Value1 = Temp;
576 
577  // set the bits after the swap
578  if ( Value0 )
579  Mvc_CubeBitInsert( pCubeCopy, iValue0 );
580  else
581  Mvc_CubeBitRemove( pCubeCopy, iValue0 );
582 
583  if ( Value1 )
584  Mvc_CubeBitInsert( pCubeCopy, iValue1 );
585  else
586  Mvc_CubeBitRemove( pCubeCopy, iValue1 );
587  }
588  return pCover;
589 }
590 
591 /**Function*************************************************************
592 
593  Synopsis [Returns the cover derived by universal quantification.]
594 
595  Description [Returns the cover computed by universal quantification
596  as follows: CoverNew = Univ(B) [Cover & (A==B)]. Removes the second
597  binary var from the support (given by values iValueB0 and iValueB1).
598  Leaves the first binary variable (given by values iValueA0 and iValueA1)
599  in the support.]
600 
601  SideEffects []
602 
603  SeeAlso []
604 
605 ***********************************************************************/
607  int iValueA0, int iValueA1, int iValueB0, int iValueB1 )
608 {
609  Mvc_Cover_t * pCover;
610  Mvc_Cube_t * pCube, * pCubeCopy;
611  int ValueA0, ValueA1, ValueB0, ValueB1;
612 
613  // clone the cover
614  pCover = Mvc_CoverClone( p );
615  // copy the cube list
616  Mvc_CoverForEachCube( p, pCube )
617  {
618  // get the bits
619  ValueA0 = Mvc_CubeBitValue( pCube, iValueA0 );
620  ValueA1 = Mvc_CubeBitValue( pCube, iValueA1 );
621  ValueB0 = Mvc_CubeBitValue( pCube, iValueB0 );
622  ValueB1 = Mvc_CubeBitValue( pCube, iValueB1 );
623 
624  // cannot be both zero because they belong to the same var
625  assert( ValueA0 || ValueA1 );
626  assert( ValueB0 || ValueB1 );
627 
628  // if the values of this var are different, do not add the cube
629  if ( ValueA0 != ValueB0 && ValueA1 != ValueB1 )
630  continue;
631 
632  // create the cube
633  pCubeCopy = Mvc_CubeDup( pCover, pCube );
634  Mvc_CoverAddCubeTail( pCover, pCubeCopy );
635 
636  // insert 1's into for the first var, if both have this value
637  if ( ValueA0 && ValueB0 )
638  Mvc_CubeBitInsert( pCubeCopy, iValueA0 );
639  else
640  Mvc_CubeBitRemove( pCubeCopy, iValueA0 );
641 
642  if ( ValueA1 && ValueB1 )
643  Mvc_CubeBitInsert( pCubeCopy, iValueA1 );
644  else
645  Mvc_CubeBitRemove( pCubeCopy, iValueA1 );
646 
647  // insert 1's into for the second var (the cover does not depend on it)
648  Mvc_CubeBitInsert( pCubeCopy, iValueB0 );
649  Mvc_CubeBitInsert( pCubeCopy, iValueB1 );
650  }
651  return pCover;
652 }
653 
654 #if 0
655 
656 /**Function*************************************************************
657 
658  Synopsis [Derives the cofactors of the cover.]
659 
660  Description [Derives the cofactors w.r.t. a variable and also cubes
661  that do not depend on this variable.]
662 
663  SideEffects []
664 
665  SeeAlso []
666 
667 ***********************************************************************/
668 Mvc_Cover_t ** Mvc_CoverCofactors( Mvc_Data_t * pData, Mvc_Cover_t * pCover, int iVar )
669 {
670  Mvc_Cover_t ** ppCofs;
671  Mvc_Cube_t * pCube, * pCubeNew;
672  int i, nValues, iValueFirst, Res;
673 
674  // start the covers for cofactors
675  iValueFirst = Vm_VarMapReadValuesFirst(pData->pVm, iVar);
676  nValues = Vm_VarMapReadValues(pData->pVm, iVar);
677  ppCofs = ABC_ALLOC( Mvc_Cover_t *, nValues + 1 );
678  for ( i = 0; i <= nValues; i++ )
679  ppCofs[i] = Mvc_CoverClone( pCover );
680 
681  // go through the cubes
682  Mvc_CoverForEachCube( pCover, pCube )
683  {
684  // if the literal if a full literal, add it to last "cofactor"
685  Mvc_CubeBitEqualUnderMask( Res, pCube, pData->ppMasks[iVar], pData->ppMasks[iVar] );
686  if ( Res )
687  {
688  pCubeNew = Mvc_CubeDup(pCover, pCube);
689  Mvc_CoverAddCubeTail( ppCofs[nValues], pCubeNew );
690  continue;
691  }
692 
693  // otherwise, add it to separate values
694  for ( i = 0; i < nValues; i++ )
695  if ( Mvc_CubeBitValue( pCube, iValueFirst + i ) )
696  {
697  pCubeNew = Mvc_CubeDup(pCover, pCube);
698  Mvc_CubeBitOr( pCubeNew, pCubeNew, pData->ppMasks[iVar] );
699  Mvc_CoverAddCubeTail( ppCofs[i], pCubeNew );
700  }
701  }
702  return ppCofs;
703 }
704 
705 /**Function*************************************************************
706 
707  Synopsis [Count the cubes with non-trivial literals with the given value.]
708 
709  Description [The data and the cover are given (pData, pCover). Also given
710  are the variable number and the number of a value of this variable.
711  This procedure returns the number of cubes having a non-trivial literal
712  of this variable that have the given value present.]
713 
714  SideEffects []
715 
716  SeeAlso []
717 
718 ***********************************************************************/
719 int Mvr_CoverCountLitsWithValue( Mvc_Data_t * pData, Mvc_Cover_t * pCover, int iVar, int iValue )
720 {
721  Mvc_Cube_t * pCube;
722  int iValueFirst, Res, Counter;
723 
724  Counter = 0;
725  iValueFirst = Vm_VarMapReadValuesFirst( pData->pVm, iVar );
726  Mvc_CoverForEachCube( pCover, pCube )
727  {
728  // check if the given literal is the full literal
729  Mvc_CubeBitEqualUnderMask( Res, pCube, pData->ppMasks[iVar], pData->ppMasks[iVar] );
730  if ( Res )
731  continue;
732  // this literal is not a full literal; check if it has this value
733  Counter += Mvc_CubeBitValue( pCube, iValueFirst + iValue );
734  }
735  return Counter;
736 }
737 
738 /**Function*************************************************************
739 
740  Synopsis [Creates the expanded cover.]
741 
742  Description [The original cover is expanded by adding some variables.
743  These variables are the additional variables in pVmNew, compared to
744  pCvr->pVm. The resulting cover is the same as the original one, except
745  that it contains the additional variables present as full literals
746  in every cube.]
747 
748  SideEffects []
749 
750  SeeAlso []
751 
752 ***********************************************************************/
753 Mvc_Cover_t * Mvc_CoverCreateExpanded( Mvc_Cover_t * pCover, Vm_VarMap_t * pVmNew )
754 {
755  Mvc_Cover_t * pCoverNew;
756  Mvc_Cube_t * pCube, * pCubeNew;
757  int i, iLast, iLastNew;
758 
759  // create the new cover
760  pCoverNew = Mvc_CoverAlloc( pCover->pMem, Vm_VarMapReadValuesInNum(pVmNew) );
761 
762  // get the cube composed of extra bits
763  Mvc_CoverAllocateMask( pCoverNew );
764  Mvc_CubeBitClean( pCoverNew->pMask );
765  for ( i = pCover->nBits; i < pCoverNew->nBits; i++ )
766  Mvc_CubeBitInsert( pCoverNew->pMask, i );
767 
768  // get the indexes of the last words in both covers
769  iLast = pCover->nWords? pCover->nWords - 1: 0;
770  iLastNew = pCoverNew->nWords? pCoverNew->nWords - 1: 0;
771 
772  // create the cubes of the new cover
773  Mvc_CoverForEachCube( pCover, pCube )
774  {
775  pCubeNew = Mvc_CubeAlloc( pCoverNew );
776  Mvc_CubeBitClean( pCubeNew );
777  // copy the bits (cannot immediately use Mvc_CubeBitCopy,
778  // because covers have different numbers of bits)
779  Mvc_CubeSetLast( pCubeNew, iLast );
780  Mvc_CubeBitCopy( pCubeNew, pCube );
781  Mvc_CubeSetLast( pCubeNew, iLastNew );
782  // add the extra bits
783  Mvc_CubeBitOr( pCubeNew, pCubeNew, pCoverNew->pMask );
784  // add the cube to the new cover
785  Mvc_CoverAddCubeTail( pCoverNew, pCubeNew );
786  }
787  return pCoverNew;
788 }
789 
790 #endif
791 
792 /**Function*************************************************************
793 
794  Synopsis [Transposes the cube cover.]
795 
796  Description [Returns the cube cover that looks like a transposed
797  matrix, compared to the matrix derived from the original cover.]
798 
799  SideEffects []
800 
801  SeeAlso []
802 
803 ***********************************************************************/
805 {
806  Mvc_Cover_t * pRes;
807  Mvc_Cube_t * pCubeRes, * pCube;
808  int nWord, nBit, i, iCube;
809 
810  pRes = Mvc_CoverAlloc( pCover->pMem, Mvc_CoverReadCubeNum(pCover) );
811  for ( i = 0; i < pCover->nBits; i++ )
812  {
813  // get the word and bit of this literal
814  nWord = Mvc_CubeWhichWord(i);
815  nBit = Mvc_CubeWhichBit(i);
816  // get the transposed cube
817  pCubeRes = Mvc_CubeAlloc( pRes );
818  Mvc_CubeBitClean( pCubeRes );
819  iCube = 0;
820  Mvc_CoverForEachCube( pCover, pCube )
821  {
822  if ( pCube->pData[nWord] & (1<<nBit) )
823  Mvc_CubeBitInsert( pCubeRes, iCube );
824  iCube++;
825  }
826  Mvc_CoverAddCubeTail( pRes, pCubeRes );
827  }
828  return pRes;
829 }
830 
831 /**Function*************************************************************
832 
833  Synopsis [Checks that the cubes of the cover have 0's in unused bits.]
834 
835  Description []
836 
837  SideEffects []
838 
839  SeeAlso []
840 
841 ***********************************************************************/
843 {
844  unsigned Unsigned;
845  Mvc_Cube_t * pCube;
846  int nCubes;
847 
848  nCubes = 0;
849  Mvc_CoverForEachCube( pCover, pCube )
850  {
851  if ( pCube->nUnused == 0 )
852  continue;
853 
854  Unsigned = ( pCube->pData[pCube->iLast] &
855  (BITS_FULL << (32-pCube->nUnused)) );
856  if( Unsigned )
857  {
858  printf( "Cube %2d out of %2d contains dirty bits.\n", nCubes,
859  Mvc_CoverReadCubeNum(pCover) );
860  }
861  nCubes++;
862  }
863  return 1;
864 }
865 
866 
867 ////////////////////////////////////////////////////////////////////////
868 /// END OF FILE ///
869 ////////////////////////////////////////////////////////////////////////
870 
871 
873 
#define Mvc_CoverAddCubeTail(pCover, pCube)
Definition: mvc.h:501
#define Mvc_CubeBitEqualUnderMask(Res, Cube1, Cube2, Mask)
Definition: mvc.h:437
void Mvc_CoverCommonCube(Mvc_Cover_t *pCover, Mvc_Cube_t *pComCube)
Definition: mvcUtils.c:155
Mvc_Cover_t * Mvc_CoverTranspose(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:804
void Mvc_CoverMakeCubeFree(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:198
Mvc_Cube_t * Mvc_CubeDup(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcCube.c:94
#define Mvc_CubeWhichWord(Bit)
Definition: mvc.h:135
int Mvc_CoverSetCubeSizes(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:272
#define Mvc_CubeReadNext(Cube)
MACRO DEFINITIONS ///.
Definition: mvc.h:121
int nWords
Definition: mvc.h:85
unsigned int Mvc_CubeWord_t
STRUCTURE DEFINITIONS ///.
Definition: mvc.h:55
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Mvc_CoverSupportAnd(Mvc_Cover_t *pCover, Mvc_Cube_t *pSupp)
Definition: mvcUtils.c:79
#define Mvc_CubeSetLast(Cube, Last)
Definition: mvc.h:127
Mvc_Cover_t ** Mvc_CoverCofactors(Mvc_Data_t *pData, Mvc_Cover_t *pCover, int iVar)
#define Mvc_CubeBitNotImpl(Res, Cube1, Cube2)
Definition: mvc.h:429
#define Mvc_CubeBitOr(CubeR, Cube1, Cube2)
Definition: mvc.h:397
int Mvc_CoverGetCubeSize(Mvc_Cube_t *pCube)
Definition: mvcUtils.c:308
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
for(p=first;p->value< newval;p=p->next)
Mvc_CubeWord_t pData[1]
Definition: mvc.h:71
#define Mvc_CubeSetSize(Cube, Size)
Definition: mvc.h:128
Mvc_Cube_t * Mvc_CubeAlloc(Mvc_Cover_t *pCover)
DECLARATIONS ///.
Definition: mvcCube.c:43
int Mvr_CoverCountLitsWithValue(Mvc_Data_t *pData, Mvc_Cover_t *pCover, int iVar, int iValue)
#define Mvc_CubeBitAnd(CubeR, Cube1, Cube2)
Definition: mvc.h:405
Mvc_Cover_t * Mvc_CoverUnivQuantify(Mvc_Cover_t *p, int iValueA0, int iValueA1, int iValueB0, int iValueB1)
Definition: mvcUtils.c:606
#define Mvc_CubeWhichBit(Bit)
Definition: mvc.h:136
Mvc_Cover_t * Mvc_CoverRemap(Mvc_Cover_t *p, int *pVarsRem, int nVarsRem)
Definition: mvcUtils.c:400
int Mvc_CoverReadCubeNum(Mvc_Cover_t *pCover)
Definition: mvcApi.c:45
Mvc_Cover_t * Mvc_CoverCofactor(Mvc_Cover_t *p, int iValue, int iValueOther)
Definition: mvcUtils.c:518
#define Mvc_CubeBitRemove(Cube, Bit)
Definition: mvc.h:140
#define Mvc_CubeBitFill(Cube)
Definition: mvc.h:385
Mvc_Cube_t * pMask
Definition: mvc.h:92
#define Mvc_CubeBitExor(CubeR, Cube1, Cube2)
Definition: mvc.h:401
unsigned iLast
Definition: mvc.h:66
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Mvc_Cube_t ** ppMasks
Definition: mvc.h:103
Mvc_Cover_t * Mvc_CoverClone(Mvc_Cover_t *pCover)
Definition: mvcCover.c:79
unsigned nUnused
Definition: mvc.h:67
void Mvc_CoverInverse(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:477
Mvc_Cover_t * Mvc_CoverCommonCubeCover(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:220
static int Counter
#define Mvc_CubeBitSharp(CubeR, Cube1, Cube2)
Definition: mvc.h:409
#define Mvc_CubeBitEmpty(Res, Cube)
Definition: mvc.h:413
void Mvc_CoverSupport(Mvc_Cover_t *pCover, Mvc_Cube_t *pSupp)
FUNCTION DEFINITIONS ///.
Definition: mvcUtils.c:58
#define Mvc_CoverForEachCube(Cover, Cube)
Definition: mvc.h:528
#define Mvc_CubeBitCopy(Cube1, Cube2)
Definition: mvc.h:393
Mvc_Cover_t * Mvc_CoverFlipVar(Mvc_Cover_t *p, int iValue0, int iValue1)
Definition: mvcUtils.c:546
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Mvc_CubeBitValue(Cube, Bit)
Definition: mvc.h:138
int Mvc_CoverSupportVarBelongs(Mvc_Cover_t *pCover, int iVar)
Definition: mvcUtils.c:130
int Mvc_CoverCheckSuppContainment(Mvc_Cover_t *pCover1, Mvc_Cover_t *pCover2)
Definition: mvcUtils.c:247
int Mvc_CoverCountCubePairDiffs(Mvc_Cover_t *pCover, unsigned char pDiffs[])
Definition: mvcUtils.c:342
static void Mvc_CoverCopyColumn(Mvc_Cover_t *pCoverOld, Mvc_Cover_t *pCoverNew, int iColOld, int iColNew)
Definition: mvcUtils.c:440
static ABC_NAMESPACE_IMPL_START int bit_count[256]
DECLARATIONS ///.
Definition: mvcUtils.c:28
int nBits
Definition: mvc.h:87
int Mvc_CoverSupportSizeBinary(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:100
int Mvc_CoverIsCubeFree(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:176
#define assert(ex)
Definition: util_old.h:213
Mvc_Cover_t * Mvc_CoverRemoveDontCareLits(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:496
void Mvc_CubeBitRemoveDcs(Mvc_Cube_t *pCube)
Definition: mvcCube.c:159
#define BITS_FULL
Definition: mvc.h:45
void Mvc_CubeFree(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcCube.c:114
#define Mvc_CubeBitNot(Cube)
Definition: mvc.h:389
Mvc_Cover_t * Mvc_CoverAlloc(Mvc_Manager_t *pMem, int nBits)
DECLARATIONS ///.
Definition: mvcCover.c:43
Mvc_Cover_t * Mvc_CoverDup(Mvc_Cover_t *pCover)
Definition: mvcCover.c:112
Mvc_Cube_t * Mvc_CoverReadCubeHead(Mvc_Cover_t *pCover)
Definition: mvcApi.c:46
void Mvc_CoverAllocateMask(Mvc_Cover_t *pCover)
Definition: mvcCover.c:168
int Mvc_UtilsCheckUnusedZeros(Mvc_Cover_t *pCover)
Definition: mvcUtils.c:842
#define Mvc_CubeBitInsert(Cube, Bit)
Definition: mvc.h:139
#define Mvc_CoverForEachCubeStart(Start, Cube)
Definition: mvc.h:542
Mvc_Manager_t * pMem
Definition: mvc.h:93
#define Mvc_CubeBitClean(Cube)
Definition: mvc.h:381