src/misc/mvc/mvcLits.c File Reference

#include "mvc.h"
Include dependency graph for mvcLits.c:

Go to the source code of this file.

Functions

int Mvc_CoverAnyLiteral (Mvc_Cover_t *pCover, Mvc_Cube_t *pMask)
int Mvc_CoverBestLiteral (Mvc_Cover_t *pCover, Mvc_Cube_t *pMask)
int Mvc_CoverWorstLiteral (Mvc_Cover_t *pCover, Mvc_Cube_t *pMask)
Mvc_Cover_tMvc_CoverBestLiteralCover (Mvc_Cover_t *pCover, Mvc_Cover_t *pSimple)
int Mvc_CoverFirstCubeFirstLit (Mvc_Cover_t *pCover)
int Mvc_CoverCountLiterals (Mvc_Cover_t *pCover)
int Mvc_CoverIsOneLiteral (Mvc_Cover_t *pCover)

Function Documentation

int Mvc_CoverAnyLiteral ( Mvc_Cover_t pCover,
Mvc_Cube_t pMask 
)

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

FileName [mvcLits.c]

PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]

Synopsis [Literal counting/updating procedures.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - February 1, 2003.]

Revision [

Id
mvcLits.c,v 1.4 2003/04/03 06:31:50 alanmi Exp

] DECLARATIONS /// FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Find the any literal that occurs more than once.]

Description []

SideEffects []

SeeAlso []

Definition at line 40 of file mvcLits.c.

00041 {
00042     Mvc_Cube_t * pCube;
00043     int nWord, nBit, i;
00044     int nLitsCur;
00045     int fUseFirst = 0;
00046 
00047     // go through each literal
00048     if ( fUseFirst )
00049     {
00050         for ( i = 0; i < pCover->nBits; i++ )
00051             if ( !pMask || Mvc_CubeBitValue(pMask,i) )
00052             {
00053                 // get the word and bit of this literal
00054                 nWord = Mvc_CubeWhichWord(i);
00055                 nBit  = Mvc_CubeWhichBit(i);
00056                 // go through all the cubes
00057                 nLitsCur = 0;
00058                 Mvc_CoverForEachCube( pCover, pCube )
00059                     if ( pCube->pData[nWord] & (1<<nBit) )
00060                     {
00061                         nLitsCur++;
00062                         if ( nLitsCur > 1 )
00063                             return i;
00064                     }
00065             }
00066     }
00067     else
00068     {
00069         for ( i = pCover->nBits - 1; i >=0; i-- )
00070             if ( !pMask || Mvc_CubeBitValue(pMask,i) )
00071             {
00072                 // get the word and bit of this literal
00073                 nWord = Mvc_CubeWhichWord(i);
00074                 nBit  = Mvc_CubeWhichBit(i);
00075                 // go through all the cubes
00076                 nLitsCur = 0;
00077                 Mvc_CoverForEachCube( pCover, pCube )
00078                     if ( pCube->pData[nWord] & (1<<nBit) )
00079                     {
00080                         nLitsCur++;
00081                         if ( nLitsCur > 1 )
00082                             return i;
00083                     }
00084             }
00085     }
00086     return -1;
00087 }

int Mvc_CoverBestLiteral ( Mvc_Cover_t pCover,
Mvc_Cube_t pMask 
)

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

Synopsis [Find the most often occurring literal.]

Description [Find the most often occurring literal among those that occur more than once.]

SideEffects []

SeeAlso []

Definition at line 101 of file mvcLits.c.

00102 {
00103     Mvc_Cube_t * pCube;
00104     int nWord, nBit;
00105     int i, iMax, nLitsMax, nLitsCur;
00106     int fUseFirst = 1;
00107 
00108     // go through each literal
00109     iMax = -1;
00110     nLitsMax = -1;
00111     for ( i = 0; i < pCover->nBits; i++ )
00112         if ( !pMask || Mvc_CubeBitValue(pMask,i) )
00113         {
00114             // get the word and bit of this literal
00115             nWord = Mvc_CubeWhichWord(i);
00116             nBit  = Mvc_CubeWhichBit(i);
00117             // go through all the cubes
00118             nLitsCur = 0;
00119             Mvc_CoverForEachCube( pCover, pCube )
00120                 if ( pCube->pData[nWord] & (1<<nBit) )
00121                     nLitsCur++;
00122 
00123             // check if this is the best literal
00124             if ( fUseFirst )
00125             {
00126                 if ( nLitsMax < nLitsCur )
00127                 {
00128                     nLitsMax = nLitsCur;
00129                     iMax = i;
00130                 }
00131             }
00132             else
00133             {
00134                 if ( nLitsMax <= nLitsCur )
00135                 {
00136                     nLitsMax = nLitsCur;
00137                     iMax = i;
00138                 }
00139             }
00140         }
00141 
00142     if ( nLitsMax > 1 )
00143         return iMax;
00144     return -1;
00145 }

Mvc_Cover_t* Mvc_CoverBestLiteralCover ( Mvc_Cover_t pCover,
Mvc_Cover_t pSimple 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 220 of file mvcLits.c.

00221 {
00222     Mvc_Cover_t * pCoverNew;
00223     Mvc_Cube_t * pCubeNew;
00224     Mvc_Cube_t * pCubeS;
00225     int iLitBest;
00226 
00227     // create the new cover
00228     pCoverNew = Mvc_CoverClone( pCover );
00229     // get the new cube
00230     pCubeNew = Mvc_CubeAlloc( pCoverNew );
00231     // clean the cube
00232     Mvc_CubeBitClean( pCubeNew );
00233 
00234     // get the first cube of pSimple
00235     assert( Mvc_CoverReadCubeNum(pSimple) == 1 );
00236     pCubeS = Mvc_CoverReadCubeHead( pSimple );
00237     // find the best literal among those of pCubeS
00238     iLitBest = Mvc_CoverBestLiteral( pCover, pCubeS );
00239 
00240     // insert this literal into the cube
00241     Mvc_CubeBitInsert( pCubeNew, iLitBest );
00242     // add the cube to the cover
00243     Mvc_CoverAddCubeTail( pCoverNew, pCubeNew );
00244     return pCoverNew;
00245 }

int Mvc_CoverCountLiterals ( Mvc_Cover_t pCover  ) 

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

Synopsis [Returns the number of literals in the cover.]

Description [Allocates storage for literal counters and fills it up using the current information.]

SideEffects []

SeeAlso []

Definition at line 284 of file mvcLits.c.

00285 {
00286     Mvc_Cube_t * pCube;
00287     int nWord, nBit;
00288     int i, CounterTot, CounterCur;
00289 
00290     // allocate/clean the storage for literals
00291 //    Mvc_CoverAllocateArrayLits( pCover );
00292 //    memset( pCover->pLits, 0, pCover->nBits * sizeof(int) );
00293     // go through each literal
00294     CounterTot = 0;
00295     for ( i = 0; i < pCover->nBits; i++ )
00296     {
00297         // get the word and bit of this literal
00298         nWord = Mvc_CubeWhichWord(i);
00299         nBit  = Mvc_CubeWhichBit(i);
00300         // go through all the cubes
00301         CounterCur = 0;
00302         Mvc_CoverForEachCube( pCover, pCube )
00303             if ( pCube->pData[nWord] & (1<<nBit) )
00304                 CounterCur++;
00305         CounterTot += CounterCur;
00306     }
00307     return CounterTot;
00308 }

int Mvc_CoverFirstCubeFirstLit ( Mvc_Cover_t pCover  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 258 of file mvcLits.c.

00259 {
00260     Mvc_Cube_t * pCube;
00261     int iBit, Value;
00262 
00263     // get the first cube
00264     pCube = Mvc_CoverReadCubeHead( pCover );
00265     // get the first literal
00266     Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
00267         if ( Value )
00268             return iBit;
00269     return -1;
00270 }

int Mvc_CoverIsOneLiteral ( Mvc_Cover_t pCover  ) 

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

Synopsis [Returns the number of literals in the cover.]

Description []

SideEffects []

SeeAlso []

Definition at line 321 of file mvcLits.c.

00322 {
00323     Mvc_Cube_t * pCube;
00324     int iBit, Counter, Value;
00325     if ( Mvc_CoverReadCubeNum(pCover) != 1 )
00326         return 0;
00327     pCube = Mvc_CoverReadCubeHead(pCover);
00328     // count literals
00329     Counter = 0;
00330     Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
00331     {
00332         if ( Value )
00333         {
00334             if ( Counter++ )
00335                 return 0;
00336         }
00337     }
00338     return 1;
00339 }

int Mvc_CoverWorstLiteral ( Mvc_Cover_t pCover,
Mvc_Cube_t pMask 
)

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

Synopsis [Find the most often occurring literal.]

Description [Find the most often occurring literal among those that occur more than once.]

SideEffects []

SeeAlso []

Definition at line 159 of file mvcLits.c.

00160 {
00161     Mvc_Cube_t * pCube;
00162     int nWord, nBit;
00163     int i, iMin, nLitsMin, nLitsCur;
00164     int fUseFirst = 1;
00165 
00166     // go through each literal
00167     iMin = -1;
00168     nLitsMin = 1000000;
00169     for ( i = 0; i < pCover->nBits; i++ )
00170         if ( !pMask || Mvc_CubeBitValue(pMask,i) )
00171         {
00172             // get the word and bit of this literal
00173             nWord = Mvc_CubeWhichWord(i);
00174             nBit  = Mvc_CubeWhichBit(i);
00175             // go through all the cubes
00176             nLitsCur = 0;
00177             Mvc_CoverForEachCube( pCover, pCube )
00178                 if ( pCube->pData[nWord] & (1<<nBit) )
00179                     nLitsCur++;
00180 
00181             // skip the literal that does not occur or occurs once
00182             if ( nLitsCur < 2 )
00183                 continue;
00184 
00185             // check if this is the best literal
00186             if ( fUseFirst )
00187             {
00188                 if ( nLitsMin > nLitsCur )
00189                 {
00190                     nLitsMin = nLitsCur;
00191                     iMin = i;
00192                 }
00193             }
00194             else
00195             {
00196                 if ( nLitsMin >= nLitsCur )
00197                 {
00198                     nLitsMin = nLitsCur;
00199                     iMin = i;
00200                 }
00201             }
00202         }
00203 
00204     if ( nLitsMin < 1000000 )
00205         return iMin;
00206     return -1;
00207 }


Generated on Tue Jan 5 12:19:17 2010 for abc70930 by  doxygen 1.6.1