abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extra.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/st/st.h"

Go to the source code of this file.

Typedefs

typedef unsigned short uint16
 
typedef unsigned int uint32
 
typedef struct Extra_BitMat_t_ Extra_BitMat_t
 
typedef struct Extra_FileReader_t_ Extra_FileReader_t
 
typedef struct Extra_MmFixed_t_ Extra_MmFixed_t
 
typedef struct Extra_MmFlex_t_ Extra_MmFlex_t
 
typedef struct Extra_MmStep_t_ Extra_MmStep_t
 
typedef struct Sdm_Man_t_ Sdm_Man_t
 
typedef struct ProgressBarStruct ProgressBar
 

Functions

Extra_BitMat_tExtra_BitMatrixStart (int nSize)
 
void Extra_BitMatrixClean (Extra_BitMat_t *p)
 
void Extra_BitMatrixStop (Extra_BitMat_t *p)
 
void Extra_BitMatrixPrint (Extra_BitMat_t *p)
 
int Extra_BitMatrixReadSize (Extra_BitMat_t *p)
 
void Extra_BitMatrixInsert1 (Extra_BitMat_t *p, int i, int k)
 
int Extra_BitMatrixLookup1 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixDelete1 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixInsert2 (Extra_BitMat_t *p, int i, int k)
 
int Extra_BitMatrixLookup2 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixDelete2 (Extra_BitMat_t *p, int i, int k)
 
void Extra_BitMatrixOr (Extra_BitMat_t *p, int i, unsigned *pInfo)
 
void Extra_BitMatrixOrTwo (Extra_BitMat_t *p, int i, int j)
 
int Extra_BitMatrixCountOnesUpper (Extra_BitMat_t *p)
 
int Extra_BitMatrixIsDisjoint (Extra_BitMat_t *p1, Extra_BitMat_t *p2)
 
int Extra_BitMatrixIsClique (Extra_BitMat_t *p)
 
char * Extra_FileGetSimilarName (char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
 
char * Extra_FileNameExtension (char *FileName)
 
char * Extra_FileNameAppend (char *pBase, char *pSuffix)
 
char * Extra_FileNameGeneric (char *FileName)
 
char * Extra_FileNameGenericAppend (char *pBase, char *pSuffix)
 
void Extra_FileNameCorrectPath (char *FileName)
 
char * Extra_FileNameWithoutPath (char *FileName)
 
char * Extra_FilePathWithoutName (char *FileName)
 
char * Extra_FileDesignName (char *pFileName)
 
int Extra_FileCheck (char *pFileName)
 
int Extra_FileSize (char *pFileName)
 
char * Extra_FileRead (FILE *pFile)
 
char * Extra_FileRead2 (FILE *pFile, FILE *pFile2)
 
char * Extra_FileReadContents (char *pFileName)
 
char * Extra_FileReadContents2 (char *pFileName, char *pFileName2)
 
int Extra_FileIsType (char *pFileName, char *pS1, char *pS2, char *pS3)
 
char * Extra_TimeStamp ()
 
char * Extra_StringAppend (char *pStrGiven, char *pStrAdd)
 
void Extra_StringClean (char *pStrGiven, char *pCharKeep)
 
unsigned Extra_ReadBinary (char *Buffer)
 
void Extra_PrintBinary (FILE *pFile, unsigned Sign[], int nBits)
 
int Extra_ReadHex (unsigned Sign[], char *pString, int nDigits)
 
int Extra_ReadHexadecimal (unsigned Sign[], char *pString, int nVars)
 
void Extra_PrintHexadecimal (FILE *pFile, unsigned Sign[], int nVars)
 
void Extra_PrintHexadecimalString (char *pString, unsigned Sign[], int nVars)
 
void Extra_PrintHex (FILE *pFile, unsigned *pTruth, int nVars)
 
void Extra_PrintHexReverse (FILE *pFile, unsigned *pTruth, int nVars)
 
void Extra_PrintSymbols (FILE *pFile, char Char, int nTimes, int fPrintNewLine)
 
Extra_FileReader_tExtra_FileReaderAlloc (char *pFileName, char *pCharsComment, char *pCharsStop, char *pCharsClean)
 FUNCTION DEFINITIONS ///. More...
 
void Extra_FileReaderFree (Extra_FileReader_t *p)
 
char * Extra_FileReaderGetFileName (Extra_FileReader_t *p)
 
int Extra_FileReaderGetFileSize (Extra_FileReader_t *p)
 
int Extra_FileReaderGetCurPosition (Extra_FileReader_t *p)
 
void * Extra_FileReaderGetTokens (Extra_FileReader_t *p)
 
int Extra_FileReaderGetLineNumber (Extra_FileReader_t *p, int iToken)
 
Extra_MmFixed_tExtra_MmFixedStart (int nEntrySize)
 
void Extra_MmFixedStop (Extra_MmFixed_t *p)
 
char * Extra_MmFixedEntryFetch (Extra_MmFixed_t *p)
 
void Extra_MmFixedEntryRecycle (Extra_MmFixed_t *p, char *pEntry)
 
void Extra_MmFixedRestart (Extra_MmFixed_t *p)
 
int Extra_MmFixedReadMemUsage (Extra_MmFixed_t *p)
 
int Extra_MmFixedReadMaxEntriesUsed (Extra_MmFixed_t *p)
 
Extra_MmFlex_tExtra_MmFlexStart ()
 
void Extra_MmFlexStop (Extra_MmFlex_t *p)
 
void Extra_MmFlexPrint (Extra_MmFlex_t *p)
 
char * Extra_MmFlexEntryFetch (Extra_MmFlex_t *p, int nBytes)
 
int Extra_MmFlexReadMemUsage (Extra_MmFlex_t *p)
 
Extra_MmStep_tExtra_MmStepStart (int nSteps)
 
void Extra_MmStepStop (Extra_MmStep_t *p)
 
char * Extra_MmStepEntryFetch (Extra_MmStep_t *p, int nBytes)
 
void Extra_MmStepEntryRecycle (Extra_MmStep_t *p, char *pEntry, int nBytes)
 
int Extra_MmStepReadMemUsage (Extra_MmStep_t *p)
 
int Extra_Base2LogDouble (double Num)
 
double Extra_Power2 (int Num)
 
int Extra_Power3 (int Num)
 
int Extra_NumCombinations (int k, int n)
 
int * Extra_DeriveRadixCode (int Number, int Radix, int nDigits)
 
int Extra_CountOnes (unsigned char *pBytes, int nBytes)
 
int Extra_Factorial (int n)
 
char ** Extra_Permutations (int n)
 
unsigned Extra_TruthPermute (unsigned Truth, char *pPerms, int nVars, int fReverse)
 
unsigned Extra_TruthPolarize (unsigned uTruth, int Polarity, int nVars)
 
unsigned Extra_TruthCanonN (unsigned uTruth, int nVars)
 
unsigned Extra_TruthCanonNN (unsigned uTruth, int nVars)
 
unsigned Extra_TruthCanonP (unsigned uTruth, int nVars)
 
unsigned Extra_TruthCanonNP (unsigned uTruth, int nVars)
 
unsigned Extra_TruthCanonNPN (unsigned uTruth, int nVars)
 
void Extra_Truth4VarNPN (unsigned short **puCanons, char **puPhases, char **puPerms, unsigned char **puMap)
 
void Extra_Truth4VarN (unsigned short **puCanons, char ***puPhases, char **ppCounters, int nPhasesMax)
 
unsigned short Extra_TruthPerm4One (unsigned uTruth, int Phase)
 
unsigned Extra_TruthPerm5One (unsigned uTruth, int Phase)
 
void Extra_TruthPerm6One (unsigned *uTruth, int Phase, unsigned *uTruthRes)
 
void Extra_TruthExpand (int nVars, int nWords, unsigned *puTruth, unsigned uPhase, unsigned *puTruthR)
 
void ** Extra_ArrayAlloc (int nCols, int nRows, int Size)
 
unsigned short ** Extra_TruthPerm43 ()
 
unsigned ** Extra_TruthPerm53 ()
 
unsigned ** Extra_TruthPerm54 ()
 
void Extra_BubbleSort (int Order[], int Costs[], int nSize, int fIncreasing)
 
int * Extra_GreyCodeSchedule (int n)
 
int * Extra_PermSchedule (int n)
 
word Extra_Truth6MinimumExact (word t, int *pComp, int *pPerm)
 
word Extra_Truth6MinimumHeuristic (word t)
 
int Extra_TruthCanonFastN (int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
 
int Sdm_ManCanRead ()
 
Sdm_Man_tSdm_ManRead ()
 
void Sdm_ManQuit ()
 
int Sdm_ManComputeFunc (Sdm_Man_t *p, int iDsdLit0, int iDsdLit1, int *pCut, int uMask, int fXor)
 
void Sdm_ManPrintDsdStats (Sdm_Man_t *p, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
int Sdm_ManReadDsdVarNum (Sdm_Man_t *p, int iDsd)
 
int Sdm_ManReadDsdAndNum (Sdm_Man_t *p, int iDsd)
 
int Sdm_ManReadDsdClauseNum (Sdm_Man_t *p, int iDsd)
 
word Sdm_ManReadDsdTruth (Sdm_Man_t *p, int iDsd)
 
char * Sdm_ManReadDsdStr (Sdm_Man_t *p, int iDsd)
 
void Sdm_ManReadCnfCosts (Sdm_Man_t *p, int *pCosts, int nCosts)
 
ProgressBarExtra_ProgressBarStart (FILE *pFile, int nItemsTotal)
 FUNCTION DEFINITIONS ///. More...
 
void Extra_ProgressBarStop (ProgressBar *p)
 
void Extra_ProgressBarUpdate_int (ProgressBar *p, int nItemsCur, char *pString)
 
static void Extra_ProgressBarUpdate (ProgressBar *p, int nItemsCur, char *pString)
 
static int Extra_BitWordNum (int nBits)
 
static int Extra_TruthWordNum (int nVars)
 
static void Extra_TruthSetBit (unsigned *p, int Bit)
 
static void Extra_TruthXorBit (unsigned *p, int Bit)
 
static int Extra_TruthHasBit (unsigned *p, int Bit)
 
static int Extra_WordCountOnes (unsigned uWord)
 
static int Extra_TruthCountOnes (unsigned *pIn, int nVars)
 
static int Extra_TruthIsEqual (unsigned *pIn0, unsigned *pIn1, int nVars)
 
static int Extra_TruthIsConst0 (unsigned *pIn, int nVars)
 
static int Extra_TruthIsConst1 (unsigned *pIn, int nVars)
 
static int Extra_TruthIsImply (unsigned *pIn1, unsigned *pIn2, int nVars)
 
static void Extra_TruthCopy (unsigned *pOut, unsigned *pIn, int nVars)
 
static void Extra_TruthClear (unsigned *pOut, int nVars)
 
static void Extra_TruthFill (unsigned *pOut, int nVars)
 
static void Extra_TruthNot (unsigned *pOut, unsigned *pIn, int nVars)
 
static void Extra_TruthAnd (unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
 
static void Extra_TruthOr (unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
 
static void Extra_TruthSharp (unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
 
static void Extra_TruthNand (unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
 
static void Extra_TruthAndPhase (unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars, int fCompl0, int fCompl1)
 
unsigned ** Extra_TruthElementary (int nVars)
 
void Extra_TruthSwapAdjacentVars (unsigned *pOut, unsigned *pIn, int nVars, int Start)
 
void Extra_TruthStretch (unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
 
void Extra_TruthShrink (unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
 
int Extra_TruthVarInSupport (unsigned *pTruth, int nVars, int iVar)
 
int Extra_TruthSupportSize (unsigned *pTruth, int nVars)
 
int Extra_TruthSupport (unsigned *pTruth, int nVars)
 
void Extra_TruthCofactor0 (unsigned *pTruth, int nVars, int iVar)
 
void Extra_TruthCofactor1 (unsigned *pTruth, int nVars, int iVar)
 
void Extra_TruthExist (unsigned *pTruth, int nVars, int iVar)
 
void Extra_TruthForall (unsigned *pTruth, int nVars, int iVar)
 
void Extra_TruthMux (unsigned *pOut, unsigned *pCof0, unsigned *pCof1, int nVars, int iVar)
 
void Extra_TruthChangePhase (unsigned *pTruth, int nVars, int iVar)
 
int Extra_TruthMinCofSuppOverlap (unsigned *pTruth, int nVars, int *pVarMin)
 
void Extra_TruthCountOnesInCofs (unsigned *pTruth, int nVars, short *pStore)
 
unsigned Extra_TruthHash (unsigned *pIn, int nWords)
 
unsigned Extra_TruthSemiCanonicize (unsigned *pInOut, unsigned *pAux, int nVars, char *pCanonPerm, short *pStore)
 
abctime Extra_CpuTime ()
 
double Extra_CpuTimeDouble ()
 
int Extra_GetSoftDataLimit ()
 FUNCTION DEFINITIONS ///. More...
 
ABC_DLL void Extra_UtilGetoptReset ()
 
int Extra_UtilGetopt (int argc, char *argv[], const char *optstring)
 
char * Extra_UtilPrintTime (long t)
 
char * Extra_UtilStrsav (const char *s)
 
char * Extra_UtilTildeExpand (char *fname)
 
char * Extra_UtilFileSearch (char *file, char *path, char *mode)
 

Variables

ABC_NAMESPACE_HEADER_START
typedef unsigned char 
uint8
 
void(* Extra_UtilMMoutOfMemory )(long size)
 
const char * globalUtilOptarg
 
int globalUtilOptind
 

Typedef Documentation

Definition at line 81 of file extra.h.

Definition at line 132 of file extra.h.

Definition at line 144 of file extra.h.

Definition at line 145 of file extra.h.

Definition at line 146 of file extra.h.

Definition at line 237 of file extra.h.

typedef struct Sdm_Man_t_ Sdm_Man_t

Definition at line 222 of file extra.h.

typedef unsigned short uint16

Definition at line 72 of file extra.h.

typedef unsigned int uint32

Definition at line 73 of file extra.h.

Function Documentation

void** Extra_ArrayAlloc ( int  nCols,
int  nRows,
int  Size 
)

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

Synopsis [Allocated one-memory-chunk array.]

Description []

SideEffects []

SeeAlso []

Definition at line 880 of file extraUtilMisc.c.

881 {
882  void ** pRes;
883  char * pBuffer;
884  int i;
885  assert( nCols > 0 && nRows > 0 && Size > 0 );
886  pBuffer = ABC_ALLOC( char, nCols * (sizeof(void *) + nRows * Size) );
887  pRes = (void **)pBuffer;
888  pRes[0] = pBuffer + nCols * sizeof(void *);
889  for ( i = 1; i < nCols; i++ )
890  pRes[i] = (void *)((char *)pRes[0] + i * nRows * Size);
891  return pRes;
892 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define assert(ex)
Definition: util_old.h:213
int Extra_Base2LogDouble ( double  Num)

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

Synopsis [Finds the smallest integer larger of equal than the logarithm.]

Description []

SideEffects []

SeeAlso []

Definition at line 74 of file extraUtilMisc.c.

75 {
76  double Res;
77  int ResInt;
78 
79  Res = log(Num)/log(2.0);
80  ResInt = (int)Res;
81  if ( ResInt == Res )
82  return ResInt;
83  else
84  return ResInt+1;
85 }
void Extra_BitMatrixClean ( Extra_BitMat_t p)

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

Synopsis [Stops the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file extraUtilBitMatrix.c.

111 {
112  memset( p->ppData[0], 0, sizeof(unsigned) * p->nSize * p->nWords );
113 }
char * memset()
int Extra_BitMatrixCountOnesUpper ( Extra_BitMat_t p)

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

Synopsis [Counts the number of 1's in the upper rectangle.]

Description []

SideEffects []

SeeAlso []

Definition at line 349 of file extraUtilBitMatrix.c.

350 {
351  int i, k, nTotal = 0;
352  for ( i = 0; i < p->nSize; i++ )
353  for ( k = i + 1; k < p->nSize; k++ )
354  nTotal += ( (p->ppData[i][k>>5] & (1 << (k&31))) > 0 );
355  return nTotal;
356 }
int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
void Extra_BitMatrixDelete1 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file extraUtilBitMatrix.c.

231 {
232  p->nDeletes++;
233  if ( i < k )
234  p->ppData[i][k>>p->nBitShift] &= ~(1<<(k & p->uMask));
235  else
236  p->ppData[k][i>>p->nBitShift] &= ~(1<<(i & p->uMask));
237 }
void Extra_BitMatrixDelete2 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 292 of file extraUtilBitMatrix.c.

293 {
294  p->nDeletes++;
295  if ( i > k )
296  p->ppData[i][k>>p->nBitShift] &= ~(1<<(k & p->uMask));
297  else
298  p->ppData[k][i>>p->nBitShift] &= ~(1<<(i & p->uMask));
299 }
void Extra_BitMatrixInsert1 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 190 of file extraUtilBitMatrix.c.

191 {
192  p->nInserts++;
193  if ( i < k )
194  p->ppData[i][k>>p->nBitShift] |= (1<<(k & p->uMask));
195  else
196  p->ppData[k][i>>p->nBitShift] |= (1<<(i & p->uMask));
197 }
void Extra_BitMatrixInsert2 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 252 of file extraUtilBitMatrix.c.

253 {
254  p->nInserts++;
255  if ( i > k )
256  p->ppData[i][k>>p->nBitShift] |= (1<<(k & p->uMask));
257  else
258  p->ppData[k][i>>p->nBitShift] |= (1<<(i & p->uMask));
259 }
int Extra_BitMatrixIsClique ( Extra_BitMat_t pMat)

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

Synopsis [Returns 1 if the matrix is a set of cliques.]

Description [For example pairwise symmetry info should satisfy this property.]

SideEffects []

SeeAlso []

Definition at line 391 of file extraUtilBitMatrix.c.

392 {
393  int v, u, i;
394  for ( v = 0; v < pMat->nSize; v++ )
395  for ( u = v+1; u < pMat->nSize; u++ )
396  {
397  if ( !Extra_BitMatrixLookup1( pMat, v, u ) )
398  continue;
399  // v and u are symmetric
400  for ( i = 0; i < pMat->nSize; i++ )
401  {
402  if ( i == v || i == u )
403  continue;
404  // i is neither v nor u
405  // the symmetry status of i is the same w.r.t. to v and u
406  if ( Extra_BitMatrixLookup1( pMat, i, v ) != Extra_BitMatrixLookup1( pMat, i, u ) )
407  return 0;
408  }
409  }
410  return 1;
411 }
int Extra_BitMatrixLookup1(Extra_BitMat_t *p, int i, int k)
int Extra_BitMatrixIsDisjoint ( Extra_BitMat_t p1,
Extra_BitMat_t p2 
)

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

Synopsis [Returns 1 if the matrices have no entries in common.]

Description []

SideEffects []

SeeAlso []

Definition at line 369 of file extraUtilBitMatrix.c.

370 {
371  int i, w;
372  assert( p1->nSize == p2->nSize );
373  for ( i = 0; i < p1->nSize; i++ )
374  for ( w = 0; w < p1->nWords; w++ )
375  if ( p1->ppData[i][w] & p2->ppData[i][w] )
376  return 0;
377  return 1;
378 }
#define assert(ex)
Definition: util_old.h:213
int Extra_BitMatrixLookup1 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 210 of file extraUtilBitMatrix.c.

211 {
212  p->nLookups++;
213  if ( i < k )
214  return ((p->ppData[i][k>>p->nBitShift] & (1<<(k & p->uMask))) > 0);
215  else
216  return ((p->ppData[k][i>>p->nBitShift] & (1<<(i & p->uMask))) > 0);
217 }
int Extra_BitMatrixLookup2 ( Extra_BitMat_t p,
int  i,
int  k 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file extraUtilBitMatrix.c.

273 {
274  p->nLookups++;
275  if ( i > k )
276  return ((p->ppData[i][k>>p->nBitShift] & (1<<(k & p->uMask))) > 0);
277  else
278  return ((p->ppData[k][i>>p->nBitShift] & (1<<(i & p->uMask))) > 0);
279 }
void Extra_BitMatrixOr ( Extra_BitMat_t p,
int  i,
unsigned *  pInfo 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 313 of file extraUtilBitMatrix.c.

314 {
315  int w;
316  for ( w = 0; w < p->nWords; w++ )
317  p->ppData[i][w] |= pInfo[w];
318 }
void Extra_BitMatrixOrTwo ( Extra_BitMat_t p,
int  i,
int  j 
)

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

Synopsis [Inserts the element into the upper part.]

Description []

SideEffects []

SeeAlso []

Definition at line 331 of file extraUtilBitMatrix.c.

332 {
333  int w;
334  for ( w = 0; w < p->nWords; w++ )
335  p->ppData[i][w] = p->ppData[j][w] = (p->ppData[i][w] | p->ppData[j][w]);
336 }
void Extra_BitMatrixPrint ( Extra_BitMat_t pMat)

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

Synopsis [Prints the bit-matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 144 of file extraUtilBitMatrix.c.

145 {
146  int i, k, nVars;
147  printf( "\n" );
148  nVars = Extra_BitMatrixReadSize( pMat );
149  for ( i = 0; i < nVars; i++ )
150  {
151  for ( k = 0; k <= i; k++ )
152  printf( " " );
153  for ( k = i+1; k < nVars; k++ )
154  if ( Extra_BitMatrixLookup1( pMat, i, k ) )
155  printf( "1" );
156  else
157  printf( "." );
158  printf( "\n" );
159  }
160 }
int Extra_BitMatrixReadSize(Extra_BitMat_t *p)
int Extra_BitMatrixLookup1(Extra_BitMat_t *p, int i, int k)
int Extra_BitMatrixReadSize ( Extra_BitMat_t p)

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

Synopsis [Reads the matrix size.]

Description []

SideEffects []

SeeAlso []

Definition at line 174 of file extraUtilBitMatrix.c.

175 {
176  return p->nSize;
177 }
Extra_BitMat_t* Extra_BitMatrixStart ( int  nSize)

AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Starts the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file extraUtilBitMatrix.c.

82 {
83  Extra_BitMat_t * p;
84  int i;
85  p = ABC_ALLOC( Extra_BitMat_t, 1 );
86  memset( p, 0, sizeof(Extra_BitMat_t) );
87  p->nSize = nSize;
88  p->nBitShift = (sizeof(unsigned) == 4) ? 5: 6;
89  p->uMask = (sizeof(unsigned) == 4) ? 31: 63;
90  p->nWords = nSize / (8 * sizeof(unsigned)) + ((nSize % (8 * sizeof(unsigned))) > 0);
91  p->ppData = ABC_ALLOC( unsigned *, nSize );
92  p->ppData[0] = ABC_ALLOC( unsigned, nSize * p->nWords );
93  memset( p->ppData[0], 0, sizeof(unsigned) * nSize * p->nWords );
94  for ( i = 1; i < nSize; i++ )
95  p->ppData[i] = p->ppData[i-1] + p->nWords;
96  return p;
97 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_BitMatrixStop ( Extra_BitMat_t p)

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

Synopsis [Stops the bit matrix.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file extraUtilBitMatrix.c.

127 {
128  ABC_FREE( p->ppData[0] );
129  ABC_FREE( p->ppData );
130  ABC_FREE( p );
131 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Extra_BitWordNum ( int  nBits)
inlinestatic

Definition at line 248 of file extra.h.

248 { return nBits/(8*sizeof(unsigned)) + ((nBits%(8*sizeof(unsigned))) > 0); }
void Extra_BubbleSort ( int  Order[],
int  Costs[],
int  nSize,
int  fIncreasing 
)

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

Synopsis [Bubble-sorts components by scores in increasing order.]

Description []

SideEffects []

SeeAlso []

Definition at line 2044 of file extraUtilMisc.c.

2045 {
2046  int i, Temp, fChanges;
2047  assert( nSize < 1000 );
2048  for ( i = 0; i < nSize; i++ )
2049  Order[i] = i;
2050  if ( fIncreasing )
2051  {
2052  do {
2053  fChanges = 0;
2054  for ( i = 0; i < nSize - 1; i++ )
2055  {
2056  if ( Costs[Order[i]] <= Costs[Order[i+1]] )
2057  continue;
2058  Temp = Order[i];
2059  Order[i] = Order[i+1];
2060  Order[i+1] = Temp;
2061  fChanges = 1;
2062  }
2063  } while ( fChanges );
2064  }
2065  else
2066  {
2067  do {
2068  fChanges = 0;
2069  for ( i = 0; i < nSize - 1; i++ )
2070  {
2071  if ( Costs[Order[i]] >= Costs[Order[i+1]] )
2072  continue;
2073  Temp = Order[i];
2074  Order[i] = Order[i+1];
2075  Order[i+1] = Temp;
2076  fChanges = 1;
2077  }
2078  } while ( fChanges );
2079  }
2080 }
#define assert(ex)
Definition: util_old.h:213
int Extra_CountOnes ( unsigned char *  pBytes,
int  nBytes 
)

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

Synopsis [Counts the number of ones in the bitstring.]

Description []

SideEffects []

SeeAlso []

Definition at line 185 of file extraUtilMisc.c.

186 {
187  static int bit_count[256] = {
188  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,
189  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,
190  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,
191  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,
192  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,
193  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,
194  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,
195  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
196  };
197 
198  int i, Counter;
199  Counter = 0;
200  for ( i = 0; i < nBytes; i++ )
201  Counter += bit_count[ *(pBytes+i) ];
202  return Counter;
203 }
static int bit_count[256]
Definition: fpgaCut.c:50
static int Counter
abctime Extra_CpuTime ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 350 of file extraUtilUtil.c.

351 {
352  return Abc_Clock();
353 }
static abctime Abc_Clock()
Definition: abc_global.h:279
double Extra_CpuTimeDouble ( )

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

Synopsis [util_cpu_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 381 of file extraUtilUtil.c.

382 {
383  struct rusage ru;
384  getrusage(RUSAGE_SELF, &ru);
385  return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
386 }
int* Extra_DeriveRadixCode ( int  Number,
int  Radix,
int  nDigits 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 160 of file extraUtilMisc.c.

161 {
162  static int Code[100];
163  int i;
164  assert( nDigits < 100 );
165  for ( i = 0; i < nDigits; i++ )
166  {
167  Code[i] = Number % Radix;
168  Number = Number / Radix;
169  }
170  assert( Number == 0 );
171  return Code;
172 }
#define Code
Definition: deflate.h:76
#define assert(ex)
Definition: util_old.h:213
int Extra_Factorial ( int  n)

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

Synopsis [Computes the factorial.]

Description []

SideEffects []

SeeAlso []

Definition at line 216 of file extraUtilMisc.c.

217 {
218  int i, Res = 1;
219  for ( i = 1; i <= n; i++ )
220  Res *= i;
221  return Res;
222 }
int Extra_FileCheck ( char *  pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 281 of file extraUtilFile.c.

282 {
283  FILE * pFile;
284  pFile = fopen( pFileName, "rb" );
285  if ( pFile == NULL )
286  {
287  printf( "Extra_FileCheck(): File \"%s\" does not exist.\n", pFileName );
288  return 0;
289  }
290  fseek( pFile, 0, SEEK_END );
291  if ( ftell( pFile ) == 0 )
292  printf( "Extra_FileCheck(): File \"%s\" is empty.\n", pFileName );
293  fclose( pFile );
294  return 1;
295 }
#define SEEK_END
Definition: zconf.h:392
char* Extra_FileDesignName ( char *  pFileName)

Definition at line 250 of file extraUtilFile.c.

251 {
252  char * pBeg, * pEnd, * pStore, * pCur;
253  // find the first dot
254  for ( pEnd = pFileName; *pEnd; pEnd++ )
255  if ( *pEnd == '.' )
256  break;
257  // find the first char
258  for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- )
259  if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') )
260  break;
261  pBeg++;
262  // fill up storage
263  pStore = ABC_ALLOC( char, pEnd - pBeg + 1 );
264  for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ )
265  *pCur = *pBeg;
266  *pCur = 0;
267  return pStore;
268 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char* Extra_FileGetSimilarName ( char *  pFileNameWrong,
char *  pS1,
char *  pS2,
char *  pS3,
char *  pS4,
char *  pS5 
)

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

FileName [extraUtilFile.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [File management utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Tries to find a file name with a different extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file extraUtilFile.c.

72 {
73  FILE * pFile;
74  char * pFileNameOther;
75  char * pFileGen;
76 
77  if ( pS1 == NULL )
78  return NULL;
79 
80  // get the generic file name
81  pFileGen = Extra_FileNameGeneric( pFileNameWrong );
82  pFileNameOther = Extra_FileNameAppend( pFileGen, pS1 );
83  pFile = fopen( pFileNameOther, "r" );
84  if ( pFile == NULL && pS2 )
85  { // try one more
86  pFileNameOther = Extra_FileNameAppend( pFileGen, pS2 );
87  pFile = fopen( pFileNameOther, "r" );
88  if ( pFile == NULL && pS3 )
89  { // try one more
90  pFileNameOther = Extra_FileNameAppend( pFileGen, pS3 );
91  pFile = fopen( pFileNameOther, "r" );
92  if ( pFile == NULL && pS4 )
93  { // try one more
94  pFileNameOther = Extra_FileNameAppend( pFileGen, pS4 );
95  pFile = fopen( pFileNameOther, "r" );
96  if ( pFile == NULL && pS5 )
97  { // try one more
98  pFileNameOther = Extra_FileNameAppend( pFileGen, pS5 );
99  pFile = fopen( pFileNameOther, "r" );
100  }
101  }
102  }
103  }
104  ABC_FREE( pFileGen );
105  if ( pFile )
106  {
107  fclose( pFile );
108  return pFileNameOther;
109  }
110  // did not find :(
111  return NULL;
112 }
char * Extra_FileNameGeneric(char *FileName)
char * Extra_FileNameAppend(char *pBase, char *pSuffix)
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Extra_FileIsType ( char *  pFileName,
char *  pS1,
char *  pS2,
char *  pS3 
)

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

Synopsis [Returns one if the file has a given extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 420 of file extraUtilFile.c.

421 {
422  int lenS, lenF = strlen(pFileName);
423  lenS = pS1 ? strlen(pS1) : 0;
424  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS1, lenS ) )
425  return 1;
426  lenS = pS2 ? strlen(pS2) : 0;
427  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS2, lenS ) )
428  return 1;
429  lenS = pS3 ? strlen(pS3) : 0;
430  if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS3, lenS ) )
431  return 1;
432  return 0;
433 }
int strncmp()
int strlen()
char* Extra_FileNameAppend ( char *  pBase,
char *  pSuffix 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 146 of file extraUtilFile.c.

147 {
148  static char Buffer[500];
149  assert( strlen(pBase) + strlen(pSuffix) < 500 );
150  sprintf( Buffer, "%s%s", pBase, pSuffix );
151  return Buffer;
152 }
char * sprintf()
#define assert(ex)
Definition: util_old.h:213
int strlen()
void Extra_FileNameCorrectPath ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file extraUtilFile.c.

209 {
210  char * pStart;
211  if ( FileName )
212  for ( pStart = FileName; *pStart; pStart++ )
213  if ( *pStart == '>' || *pStart == '\\' )
214  *pStart = '/';
215 }
char* Extra_FileNameExtension ( char *  FileName)

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

Synopsis [Returns the pointer to the file extension.]

Description []

SideEffects []

SeeAlso []

Definition at line 125 of file extraUtilFile.c.

126 {
127  char * pDot;
128  // find the last "dot" in the file name, if it is present
129  for ( pDot = FileName + strlen(FileName)-1; pDot >= FileName; pDot-- )
130  if ( *pDot == '.' )
131  return pDot + 1;
132  return FileName;
133 }
int strlen()
char* Extra_FileNameGeneric ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file extraUtilFile.c.

166 {
167  char * pDot, * pRes;
168  pRes = Extra_UtilStrsav( FileName );
169  if ( (pDot = strrchr( pRes, '.' )) )
170  *pDot = 0;
171  return pRes;
172 }
char * Extra_UtilStrsav(const char *s)
char * strrchr()
char* Extra_FileNameGenericAppend ( char *  pBase,
char *  pSuffix 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 185 of file extraUtilFile.c.

186 {
187  static char Buffer[1000];
188  char * pDot;
189  assert( strlen(pBase) + strlen(pSuffix) < 1000 );
190  strcpy( Buffer, pBase );
191  if ( (pDot = strrchr( Buffer, '.' )) )
192  *pDot = 0;
193  strcat( Buffer, pSuffix );
194  return Buffer;
195 }
char * strcpy()
char * strcat()
#define assert(ex)
Definition: util_old.h:213
int strlen()
char * strrchr()
char* Extra_FileNameWithoutPath ( char *  FileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 228 of file extraUtilFile.c.

229 {
230  char * pRes;
231  for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
232  if ( *pRes == '\\' || *pRes == '/' )
233  return pRes + 1;
234  return FileName;
235 }
int strlen()
char* Extra_FilePathWithoutName ( char *  FileName)

Definition at line 236 of file extraUtilFile.c.

237 {
238  char * pRes;
239  FileName = Abc_UtilStrsav( FileName );
240  for ( pRes = FileName + strlen(FileName) - 1; pRes >= FileName; pRes-- )
241  if ( *pRes == '\\' || *pRes == '/' )
242  {
243  *pRes = 0;
244  Extra_FileNameCorrectPath( FileName );
245  return FileName;
246  }
247  ABC_FREE( FileName );
248  return NULL;
249 }
void Extra_FileNameCorrectPath(char *FileName)
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
char* Extra_FileRead ( FILE *  pFile)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 336 of file extraUtilFile.c.

337 {
338  int nFileSize;
339  char * pBuffer;
340  int RetValue;
341  // get the file size, in bytes
342  fseek( pFile, 0, SEEK_END );
343  nFileSize = ftell( pFile );
344  // move the file current reading position to the beginning
345  rewind( pFile );
346  // load the contents of the file into memory
347  pBuffer = ABC_ALLOC( char, nFileSize + 3 );
348  RetValue = fread( pBuffer, nFileSize, 1, pFile );
349  // terminate the string with '\0'
350  pBuffer[ nFileSize + 0] = '\n';
351  pBuffer[ nFileSize + 1] = '\0';
352  return pBuffer;
353 }
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
VOID_HACK rewind()
char* Extra_FileRead2 ( FILE *  pFile,
FILE *  pFile2 
)

Definition at line 354 of file extraUtilFile.c.

355 {
356  char * pBuffer;
357  int nSize, nSize2;
358  int RetValue;
359  // get the file size, in bytes
360  fseek( pFile, 0, SEEK_END );
361  nSize = ftell( pFile );
362  rewind( pFile );
363  // get the file size, in bytes
364  fseek( pFile2, 0, SEEK_END );
365  nSize2 = ftell( pFile2 );
366  rewind( pFile2 );
367  // load the contents of the file into memory
368  pBuffer = ABC_ALLOC( char, nSize + nSize2 + 3 );
369  RetValue = fread( pBuffer, nSize, 1, pFile );
370  RetValue = fread( pBuffer + nSize, nSize2, 1, pFile2 );
371  // terminate the string with '\0'
372  pBuffer[ nSize + nSize2 + 0] = '\n';
373  pBuffer[ nSize + nSize2 + 1] = '\0';
374  return pBuffer;
375 }
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
VOID_HACK rewind()
char* Extra_FileReadContents ( char *  pFileName)

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

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 388 of file extraUtilFile.c.

389 {
390  FILE * pFile;
391  char * pBuffer;
392  pFile = fopen( pFileName, "rb" );
393  pBuffer = pFile ? Extra_FileRead( pFile ) : NULL;
394  if ( pFile ) fclose( pFile );
395  return pBuffer;
396 }
char * Extra_FileRead(FILE *pFile)
char* Extra_FileReadContents2 ( char *  pFileName,
char *  pFileName2 
)

Definition at line 397 of file extraUtilFile.c.

398 {
399  FILE * pFile, * pFile2;
400  char * pBuffer;
401  pFile = fopen( pFileName, "rb" );
402  pFile2 = fopen( pFileName2, "rb" );
403  pBuffer = (pFile && pFile2) ? Extra_FileRead2( pFile, pFile2 ) : NULL;
404  if ( pFile ) fclose( pFile );
405  if ( pFile2 ) fclose( pFile2 );
406  return pBuffer;
407 }
char * Extra_FileRead2(FILE *pFile, FILE *pFile2)
Extra_FileReader_t* Extra_FileReaderAlloc ( char *  pFileName,
char *  pCharsComment,
char *  pCharsStop,
char *  pCharsClean 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the file reader.]

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file extraUtilReader.c.

89 {
91  FILE * pFile;
92  char * pChar;
93  int nCharsToRead;
94  int RetValue;
95  // check if the file can be opened
96  pFile = fopen( pFileName, "rb" );
97  if ( pFile == NULL )
98  {
99  printf( "Extra_FileReaderAlloc(): Cannot open input file \"%s\".\n", pFileName );
100  return NULL;
101  }
102  // start the file reader
103  p = ABC_ALLOC( Extra_FileReader_t, 1 );
104  memset( p, 0, sizeof(Extra_FileReader_t) );
105  p->pFileName = pFileName;
106  p->pFile = pFile;
107  // set the character map
108  memset( p->pCharMap, EXTRA_CHAR_NORMAL, 256 );
109  for ( pChar = pCharsComment; *pChar; pChar++ )
110  p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_COMMENT;
111  for ( pChar = pCharsStop; *pChar; pChar++ )
112  p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_STOP;
113  for ( pChar = pCharsClean; *pChar; pChar++ )
114  p->pCharMap[(unsigned char)*pChar] = EXTRA_CHAR_CLEAN;
115  // get the file size, in bytes
116  fseek( pFile, 0, SEEK_END );
117  p->nFileSize = ftell( pFile );
118  rewind( pFile );
119  // allocate the buffer
120  p->pBuffer = ABC_ALLOC( char, EXTRA_BUFFER_SIZE+1 );
122  p->pBufferCur = p->pBuffer;
123  // determine how many chars to read
124  nCharsToRead = EXTRA_MINIMUM(p->nFileSize, EXTRA_BUFFER_SIZE);
125  // load the first part into the buffer
126  RetValue = fread( p->pBuffer, nCharsToRead, 1, p->pFile );
127  p->nFileRead = nCharsToRead;
128  // set the ponters to the end and the stopping point
129  p->pBufferEnd = p->pBuffer + nCharsToRead;
131  // start the arrays
132  p->vTokens = Vec_PtrAlloc( 100 );
133  p->vLines = Vec_IntAlloc( 100 );
134  p->nLineCounter = 1; // 1-based line counting
135  return p;
136 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define SEEK_END
Definition: zconf.h:392
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define EXTRA_OFFSET_SIZE
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
#define EXTRA_MINIMUM(a, b)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define EXTRA_BUFFER_SIZE
DECLARATIONS ///.
VOID_HACK rewind()
void Extra_FileReaderFree ( Extra_FileReader_t p)

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

Synopsis [Stops the file reader.]

Description []

SideEffects []

SeeAlso []

Definition at line 149 of file extraUtilReader.c.

150 {
151  if ( p->pFile )
152  fclose( p->pFile );
153  ABC_FREE( p->pBuffer );
154  Vec_PtrFree( p->vTokens );
155  Vec_IntFree( p->vLines );
156  ABC_FREE( p );
157 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Extra_FileReaderGetCurPosition ( Extra_FileReader_t p)

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

Synopsis [Returns the current reading position.]

Description []

SideEffects []

SeeAlso []

Definition at line 202 of file extraUtilReader.c.

203 {
204  return p->nFileRead - (p->pBufferEnd - p->pBufferCur);
205 }
char* Extra_FileReaderGetFileName ( Extra_FileReader_t p)

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

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 170 of file extraUtilReader.c.

171 {
172  return p->pFileName;
173 }
int Extra_FileReaderGetFileSize ( Extra_FileReader_t p)

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

Synopsis [Returns the file size.]

Description []

SideEffects []

SeeAlso []

Definition at line 186 of file extraUtilReader.c.

187 {
188  return p->nFileSize;
189 }
int Extra_FileReaderGetLineNumber ( Extra_FileReader_t p,
int  iToken 
)

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

Synopsis [Returns the line number for the given token.]

Description []

SideEffects []

SeeAlso []

Definition at line 218 of file extraUtilReader.c.

219 {
220  assert( iToken >= 0 && iToken < p->vTokens->nSize );
221  return p->vLines->pArray[iToken];
222 }
#define assert(ex)
Definition: util_old.h:213
void* Extra_FileReaderGetTokens ( Extra_FileReader_t p)

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

Synopsis [Returns the next set of tokens.]

Description []

SideEffects []

SeeAlso []

Definition at line 236 of file extraUtilReader.c.

237 {
238  Vec_Ptr_t * vTokens;
239  while ( (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens_int( p )) )
240  if ( vTokens->nSize > 0 )
241  break;
242  return vTokens;
243 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void * Extra_FileReaderGetTokens_int(Extra_FileReader_t *p)
int Extra_FileSize ( char *  pFileName)

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

Synopsis [Returns the file size.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 308 of file extraUtilFile.c.

309 {
310  FILE * pFile;
311  int nFileSize;
312  pFile = fopen( pFileName, "rb" );
313  if ( pFile == NULL )
314  {
315  printf( "Extra_FileSize(): The file is unavailable (absent or open).\n" );
316  return 0;
317  }
318  fseek( pFile, 0, SEEK_END );
319  nFileSize = ftell( pFile );
320  fclose( pFile );
321  return nFileSize;
322 }
#define SEEK_END
Definition: zconf.h:392
int Extra_GetSoftDataLimit ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [getSoftDataLimit()]

Description []

SideEffects []

SeeAlso []

Definition at line 64 of file extraUtilUtil.c.

65 {
67 }
#define EXTRA_RLIMIT_DATA_DEFAULT
DECLARATIONS ///.
Definition: extraUtilUtil.c:31
int* Extra_GreyCodeSchedule ( int  n)

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

Synopsis [Computes complementation schedule for 2^n Grey codes.]

Description []

SideEffects []

SeeAlso []

Definition at line 2169 of file extraUtilMisc.c.

2170 {
2171  int * pRes = ABC_ALLOC( int, (1<<n) );
2172  int i, k, b = 0;
2173 // pRes[b++] = -1;
2174  for ( k = 0; k < n; k++ )
2175  for ( pRes[b++] = k, i = 1; i < (1<<k); i++ )
2176  pRes[b++] = pRes[i-1]; // pRes[i];
2177  pRes[b++] = n-1;
2178  assert( b == (1<<n) );
2179 
2180  if ( 0 )
2181  {
2182  unsigned uSign = 0;
2183  for ( b = 0; b < (1<<n); b++ )
2184  {
2185  uSign ^= (1 << pRes[b]);
2186  printf( "%3d %3d ", b, pRes[b] );
2187  Extra_PrintBinary( stdout, &uSign, n );
2188  printf( "\n" );
2189  }
2190  }
2191  return pRes;
2192 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
#define assert(ex)
Definition: util_old.h:213
char* Extra_MmFixedEntryFetch ( Extra_MmFixed_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 202 of file extraUtilMemory.c.

203 {
204  char * pTemp;
205  int i;
206 
207  // check if there are still free entries
208  if ( p->nEntriesUsed == p->nEntriesAlloc )
209  { // need to allocate more entries
210  assert( p->pEntriesFree == NULL );
211  if ( p->nChunks == p->nChunksAlloc )
212  {
213  p->nChunksAlloc *= 2;
214  p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
215  }
216  p->pEntriesFree = ABC_ALLOC( char, p->nEntrySize * p->nChunkSize );
217  p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
218  // transform these entries into a linked list
219  pTemp = p->pEntriesFree;
220  for ( i = 1; i < p->nChunkSize; i++ )
221  {
222  *((char **)pTemp) = pTemp + p->nEntrySize;
223  pTemp += p->nEntrySize;
224  }
225  // set the last link
226  *((char **)pTemp) = NULL;
227  // add the chunk to the chunk storage
228  p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
229  // add to the number of entries allocated
230  p->nEntriesAlloc += p->nChunkSize;
231  }
232  // incrememt the counter of used entries
233  p->nEntriesUsed++;
234  if ( p->nEntriesMax < p->nEntriesUsed )
235  p->nEntriesMax = p->nEntriesUsed;
236  // return the first entry in the free entry list
237  pTemp = p->pEntriesFree;
238  p->pEntriesFree = *((char **)pTemp);
239  return pTemp;
240 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define assert(ex)
Definition: util_old.h:213
void Extra_MmFixedEntryRecycle ( Extra_MmFixed_t p,
char *  pEntry 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 253 of file extraUtilMemory.c.

254 {
255  // decrement the counter of used entries
256  p->nEntriesUsed--;
257  // add the entry to the linked list of free entries
258  *((char **)pEntry) = p->pEntriesFree;
259  p->pEntriesFree = pEntry;
260 }
int Extra_MmFixedReadMaxEntriesUsed ( Extra_MmFixed_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 327 of file extraUtilMemory.c.

328 {
329  return p->nEntriesMax;
330 }
int Extra_MmFixedReadMemUsage ( Extra_MmFixed_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 311 of file extraUtilMemory.c.

312 {
313  return p->nMemoryAlloc;
314 }
void Extra_MmFixedRestart ( Extra_MmFixed_t p)

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

Synopsis []

Description [Relocates all the memory except the first chunk.]

SideEffects []

SeeAlso []

Definition at line 273 of file extraUtilMemory.c.

274 {
275  int i;
276  char * pTemp;
277 
278  // deallocate all chunks except the first one
279  for ( i = 1; i < p->nChunks; i++ )
280  ABC_FREE( p->pChunks[i] );
281  p->nChunks = 1;
282  // transform these entries into a linked list
283  pTemp = p->pChunks[0];
284  for ( i = 1; i < p->nChunkSize; i++ )
285  {
286  *((char **)pTemp) = pTemp + p->nEntrySize;
287  pTemp += p->nEntrySize;
288  }
289  // set the last link
290  *((char **)pTemp) = NULL;
291  // set the free entry list
292  p->pEntriesFree = p->pChunks[0];
293  // set the correct statistics
294  p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
295  p->nMemoryUsed = 0;
296  p->nEntriesAlloc = p->nChunkSize;
297  p->nEntriesUsed = 0;
298 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
Extra_MmFixed_t* Extra_MmFixedStart ( int  nEntrySize)

AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Allocates memory pieces of fixed size.]

Description [The size of the chunk is computed as the minimum of 1024 entries and 64K. Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 122 of file extraUtilMemory.c.

123 {
124  Extra_MmFixed_t * p;
125 
126  p = ABC_ALLOC( Extra_MmFixed_t, 1 );
127  memset( p, 0, sizeof(Extra_MmFixed_t) );
128 
129  p->nEntrySize = nEntrySize;
130  p->nEntriesAlloc = 0;
131  p->nEntriesUsed = 0;
132  p->pEntriesFree = NULL;
133 
134  if ( nEntrySize * (1 << 10) < (1<<16) )
135  p->nChunkSize = (1 << 10);
136  else
137  p->nChunkSize = (1<<16) / nEntrySize;
138  if ( p->nChunkSize < 8 )
139  p->nChunkSize = 8;
140 
141  p->nChunksAlloc = 64;
142  p->nChunks = 0;
143  p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
144 
145  p->nMemoryUsed = 0;
146  p->nMemoryAlloc = 0;
147  return p;
148 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_MmFixedStop ( Extra_MmFixed_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file extraUtilMemory.c.

181 {
182  int i;
183  if ( p == NULL )
184  return;
185  for ( i = 0; i < p->nChunks; i++ )
186  ABC_FREE( p->pChunks[i] );
187  ABC_FREE( p->pChunks );
188  ABC_FREE( p );
189 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
char* Extra_MmFlexEntryFetch ( Extra_MmFlex_t p,
int  nBytes 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 418 of file extraUtilMemory.c.

419 {
420  char * pTemp;
421  // check if there are still free entries
422  if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd )
423  { // need to allocate more entries
424  if ( p->nChunks == p->nChunksAlloc )
425  {
426  p->nChunksAlloc *= 2;
427  p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
428  }
429  if ( nBytes > p->nChunkSize )
430  {
431  // resize the chunk size if more memory is requested than it can give
432  // (ideally, this should never happen)
433  p->nChunkSize = 2 * nBytes;
434  }
435  p->pCurrent = ABC_ALLOC( char, p->nChunkSize );
436  p->pEnd = p->pCurrent + p->nChunkSize;
437  p->nMemoryAlloc += p->nChunkSize;
438  // add the chunk to the chunk storage
439  p->pChunks[ p->nChunks++ ] = p->pCurrent;
440  }
441  assert( p->pCurrent + nBytes <= p->pEnd );
442  // increment the counter of used entries
443  p->nEntriesUsed++;
444  // keep track of the memory used
445  p->nMemoryUsed += nBytes;
446  // return the next entry
447  pTemp = p->pCurrent;
448  p->pCurrent += nBytes;
449  return pTemp;
450 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define assert(ex)
Definition: util_old.h:213
void Extra_MmFlexPrint ( Extra_MmFlex_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 376 of file extraUtilMemory.c.

377 {
378  printf( "Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
379  p->nChunkSize, p->nChunks );
380  printf( " Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
382 }
int Extra_MmFlexReadMemUsage ( Extra_MmFlex_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 463 of file extraUtilMemory.c.

464 {
465  return p->nMemoryAlloc;
466 }
Extra_MmFlex_t* Extra_MmFlexStart ( )

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

Synopsis [Allocates entries of flexible size.]

Description [Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 344 of file extraUtilMemory.c.

345 {
346  Extra_MmFlex_t * p;
347 //printf( "allocing flex\n" );
348  p = ABC_ALLOC( Extra_MmFlex_t, 1 );
349  memset( p, 0, sizeof(Extra_MmFlex_t) );
350 
351  p->nEntriesUsed = 0;
352  p->pCurrent = NULL;
353  p->pEnd = NULL;
354 
355  p->nChunkSize = (1 << 12);
356  p->nChunksAlloc = 64;
357  p->nChunks = 0;
358  p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
359 
360  p->nMemoryUsed = 0;
361  p->nMemoryAlloc = 0;
362  return p;
363 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Extra_MmFlexStop ( Extra_MmFlex_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 395 of file extraUtilMemory.c.

396 {
397  int i;
398  if ( p == NULL )
399  return;
400 //printf( "deleting flex\n" );
401  for ( i = 0; i < p->nChunks; i++ )
402  ABC_FREE( p->pChunks[i] );
403  ABC_FREE( p->pChunks );
404  ABC_FREE( p );
405 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
char* Extra_MmStepEntryFetch ( Extra_MmStep_t p,
int  nBytes 
)

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

Synopsis [Creates the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 555 of file extraUtilMemory.c.

556 {
557  if ( nBytes == 0 )
558  return NULL;
559  if ( nBytes > p->nMapSize )
560  {
561 // printf( "Allocating %d bytes.\n", nBytes );
562 // return ABC_ALLOC( char, nBytes );
563  if ( p->nLargeChunks == p->nLargeChunksAlloc )
564  {
565  if ( p->nLargeChunksAlloc == 0 )
566  p->nLargeChunksAlloc = 32;
567  p->nLargeChunksAlloc *= 2;
569  }
570  p->pLargeChunks[ p->nLargeChunks++ ] = ABC_ALLOC( char, nBytes );
571  return (char *)p->pLargeChunks[ p->nLargeChunks - 1 ];
572  }
573  return Extra_MmFixedEntryFetch( p->pMap[nBytes] );
574 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Extra_MmFixed_t ** pMap
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
void Extra_MmStepEntryRecycle ( Extra_MmStep_t p,
char *  pEntry,
int  nBytes 
)

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

Synopsis [Recycles the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 588 of file extraUtilMemory.c.

589 {
590  if ( nBytes == 0 )
591  return;
592  if ( nBytes > p->nMapSize )
593  {
594 // ABC_FREE( pEntry );
595  return;
596  }
597  Extra_MmFixedEntryRecycle( p->pMap[nBytes], pEntry );
598 }
void Extra_MmFixedEntryRecycle(Extra_MmFixed_t *p, char *pEntry)
Extra_MmFixed_t ** pMap
int Extra_MmStepReadMemUsage ( Extra_MmStep_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 611 of file extraUtilMemory.c.

612 {
613  int i, nMemTotal = 0;
614  for ( i = 0; i < p->nMems; i++ )
615  nMemTotal += p->pMems[i]->nMemoryAlloc;
616  return nMemTotal;
617 }
Extra_MmFixed_t ** pMems
Extra_MmStep_t* Extra_MmStepStart ( int  nSteps)

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

Synopsis [Starts the hierarchical memory manager.]

Description [This manager can allocate entries of any size. Iternally they are mapped into the entries with the number of bytes equal to the power of 2. The smallest entry size is 8 bytes. The next one is 16 bytes etc. So, if the user requests 6 bytes, he gets 8 byte entry. If we asks for 25 bytes, he gets 32 byte entry etc. The input parameters "nSteps" says how many fixed memory managers are employed internally. Calling this procedure with nSteps equal to 10 results in 10 hierarchically arranged internal memory managers, which can allocate up to 4096 (1Kb) entries. Requests for larger entries are handed over to malloc() and then ABC_FREE()ed.]

SideEffects []

SeeAlso []

Definition at line 492 of file extraUtilMemory.c.

493 {
494  Extra_MmStep_t * p;
495  int i, k;
496  p = ABC_ALLOC( Extra_MmStep_t, 1 );
497  memset( p, 0, sizeof(Extra_MmStep_t) );
498  p->nMems = nSteps;
499  // start the fixed memory managers
500  p->pMems = ABC_ALLOC( Extra_MmFixed_t *, p->nMems );
501  for ( i = 0; i < p->nMems; i++ )
502  p->pMems[i] = Extra_MmFixedStart( (8<<i) );
503  // set up the mapping of the required memory size into the corresponding manager
504  p->nMapSize = (4<<p->nMems);
505  p->pMap = ABC_ALLOC( Extra_MmFixed_t *, p->nMapSize+1 );
506  p->pMap[0] = NULL;
507  for ( k = 1; k <= 4; k++ )
508  p->pMap[k] = p->pMems[0];
509  for ( i = 0; i < p->nMems; i++ )
510  for ( k = (4<<i)+1; k <= (8<<i); k++ )
511  p->pMap[k] = p->pMems[i];
512 //for ( i = 1; i < 100; i ++ )
513 //printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize );
514  return p;
515 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
for(p=first;p->value< newval;p=p->next)
Extra_MmFixed_t ** pMems
Extra_MmFixed_t ** pMap
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
void Extra_MmStepStop ( Extra_MmStep_t p)

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

Synopsis [Stops the memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 528 of file extraUtilMemory.c.

529 {
530  int i;
531  for ( i = 0; i < p->nMems; i++ )
532  Extra_MmFixedStop( p->pMems[i] );
533  if ( p->pLargeChunks )
534  {
535  for ( i = 0; i < p->nLargeChunks; i++ )
536  ABC_FREE( p->pLargeChunks[i] );
537  ABC_FREE( p->pLargeChunks );
538  }
539  ABC_FREE( p->pMems );
540  ABC_FREE( p->pMap );
541  ABC_FREE( p );
542 }
void Extra_MmFixedStop(Extra_MmFixed_t *p)
Extra_MmFixed_t ** pMems
#define ABC_FREE(obj)
Definition: abc_global.h:232
Extra_MmFixed_t ** pMap
int Extra_NumCombinations ( int  k,
int  n 
)

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

Synopsis [Finds the number of combinations of k elements out of n.]

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file extraUtilMisc.c.

142 {
143  int i, Res = 1;
144  for ( i = 1; i <= k; i++ )
145  Res = Res * (n-i+1) / i;
146  return Res;
147 } /* end of Extra_NumCombinations */
int* Extra_PermSchedule ( int  n)

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

Synopsis [Computes permutation schedule for n! permutations.]

Description []

SideEffects []

SeeAlso []

Definition at line 2205 of file extraUtilMisc.c.

2206 {
2207  int nFact = Extra_Factorial(n);
2208  int nGroups = nFact / n / 2;
2209  int * pRes = ABC_ALLOC( int, nFact );
2210  int * pRes0, i, k, b = 0;
2211  assert( n > 1 );
2212  if ( n == 2 )
2213  {
2214  pRes[0] = pRes[1] = 0;
2215  return pRes;
2216  }
2217  pRes0 = Extra_PermSchedule( n-1 );
2218  for ( k = 0; k < nGroups; k++ )
2219  {
2220  for ( i = n-1; i > 0; i-- )
2221  pRes[b++] = i-1;
2222  pRes[b++] = pRes0[2*k]+1;
2223  for ( i = 0; i < n-1; i++ )
2224  pRes[b++] = i;
2225  pRes[b++] = pRes0[2*k+1];
2226  }
2227  ABC_FREE( pRes0 );
2228  assert( b == nFact );
2229 
2230  if ( 0 )
2231  {
2232  int Perm[16];
2233  for ( i = 0; i < n; i++ )
2234  Perm[i] = i;
2235  for ( b = 0; b < nFact; b++ )
2236  {
2237  ABC_SWAP( int, Perm[pRes[b]], Perm[pRes[b]+1] );
2238  printf( "%3d %3d ", b, pRes[b] );
2239  for ( i = 0; i < n; i++ )
2240  printf( "%d", Perm[i] );
2241  printf( "\n" );
2242  }
2243  }
2244  return pRes;
2245 }
int Extra_Factorial(int n)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
int * Extra_PermSchedule(int n)
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
char** Extra_Permutations ( int  n)

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

Synopsis [Computes the set of all permutations.]

Description [The number of permutations in the array is n!. The number of entries in each permutation is n. Therefore, the resulting array is a two-dimentional array of the size: n! x n. To free the resulting array, call ABC_FREE() on the pointer returned by this procedure.]

SideEffects []

SeeAlso []

Definition at line 238 of file extraUtilMisc.c.

239 {
240  char Array[50];
241  char ** pRes;
242  int nFact, i;
243  // allocate memory
244  nFact = Extra_Factorial( n );
245  pRes = (char **)Extra_ArrayAlloc( nFact, n, sizeof(char) );
246  // fill in the permutations
247  for ( i = 0; i < n; i++ )
248  Array[i] = i;
249  Extra_Permutations_rec( pRes, nFact, n, Array );
250  // print the permutations
251 /*
252  {
253  int i, k;
254  for ( i = 0; i < nFact; i++ )
255  {
256  printf( "{" );
257  for ( k = 0; k < n; k++ )
258  printf( " %d", pRes[i][k] );
259  printf( " }\n" );
260  }
261  }
262 */
263  return pRes;
264 }
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
int Extra_Factorial(int n)
static ABC_NAMESPACE_IMPL_START void Extra_Permutations_rec(char **pRes, int nFact, int n, char Array[])
double Extra_Power2 ( int  Degree)

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

Synopsis [Returns the power of two as a double.]

Description []

SideEffects []

SeeAlso []

Definition at line 98 of file extraUtilMisc.c.

99 {
100  double Res;
101  assert( Degree >= 0 );
102  if ( Degree < 32 )
103  return (double)(01<<Degree);
104  for ( Res = 1.0; Degree; Res *= 2.0, Degree-- );
105  return Res;
106 }
#define assert(ex)
Definition: util_old.h:213
int Extra_Power3 ( int  Num)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file extraUtilMisc.c.

121 {
122  int i;
123  int Res;
124  Res = 1;
125  for ( i = 0; i < Num; i++ )
126  Res *= 3;
127  return Res;
128 }
void Extra_PrintBinary ( FILE *  pFile,
unsigned  Sign[],
int  nBits 
)

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

Synopsis [Prints the bit string.]

Description []

SideEffects []

SeeAlso []

Definition at line 497 of file extraUtilFile.c.

498 {
499  int Remainder, nWords;
500  int w, i;
501 
502  Remainder = (nBits%(sizeof(unsigned)*8));
503  nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
504 
505  for ( w = nWords-1; w >= 0; w-- )
506  for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
507  fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
508 
509 // fprintf( pFile, "\n" );
510 }
int nWords
Definition: abcNpn.c:127
void Extra_PrintHex ( FILE *  pFile,
unsigned *  pTruth,
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 620 of file extraUtilFile.c.

621 {
622  int nMints, nDigits, Digit, k;
623 
624  // write the number into the file
625  fprintf( pFile, "0x" );
626  nMints = (1 << nVars);
627  nDigits = nMints / 4 + ((nMints % 4) > 0);
628  for ( k = nDigits - 1; k >= 0; k-- )
629  {
630  Digit = ((pTruth[k/8] >> (k * 4)) & 15);
631  if ( Digit < 10 )
632  fprintf( pFile, "%d", Digit );
633  else
634  fprintf( pFile, "%c", 'A' + Digit-10 );
635  }
636 // fprintf( pFile, "\n" );
637 }
void Extra_PrintHexadecimal ( FILE *  pFile,
unsigned  Sign[],
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 565 of file extraUtilFile.c.

566 {
567  int nDigits, Digit, k;
568  // write the number into the file
569  nDigits = (1 << nVars) / 4;
570  for ( k = nDigits - 1; k >= 0; k-- )
571  {
572  Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
573  if ( Digit < 10 )
574  fprintf( pFile, "%d", Digit );
575  else
576  fprintf( pFile, "%c", 'a' + Digit-10 );
577  }
578 // fprintf( pFile, "\n" );
579 }
void Extra_PrintHexadecimalString ( char *  pString,
unsigned  Sign[],
int  nVars 
)

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

Synopsis [Prints the hex unsigned into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 592 of file extraUtilFile.c.

593 {
594  int nDigits, Digit, k;
595  // write the number into the file
596  nDigits = (1 << nVars) / 4;
597  for ( k = nDigits - 1; k >= 0; k-- )
598  {
599  Digit = ((Sign[k/8] >> ((k%8) * 4)) & 15);
600  if ( Digit < 10 )
601  *pString++ = '0' + Digit;
602  else
603  *pString++ = 'a' + Digit-10;
604  }
605 // fprintf( pFile, "\n" );
606  *pString = 0;
607 }
void Extra_PrintHexReverse ( FILE *  pFile,
unsigned *  pTruth,
int  nVars 
)

Definition at line 638 of file extraUtilFile.c.

639 {
640  int nMints, nDigits, Digit, k;
641 
642  // write the number into the file
643  fprintf( pFile, "0x" );
644  nMints = (1 << nVars);
645  nDigits = nMints / 4 + ((nMints % 4) > 0);
646  for ( k = 0; k < nDigits; k++ )
647  {
648  Digit = ((pTruth[k/8] >> (k * 4)) & 15);
649  if ( Digit < 10 )
650  fprintf( pFile, "%d", Digit );
651  else
652  fprintf( pFile, "%c", 'A' + Digit-10 );
653  }
654 // fprintf( pFile, "\n" );
655 }
void Extra_PrintSymbols ( FILE *  pFile,
char  Char,
int  nTimes,
int  fPrintNewLine 
)

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

Synopsis [Returns the composite name of the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 668 of file extraUtilFile.c.

669 {
670  int i;
671  for ( i = 0; i < nTimes; i++ )
672  printf( "%c", Char );
673  if ( fPrintNewLine )
674  printf( "\n" );
675 }
char Char
Definition: bzlib_private.h:43
ProgressBar* Extra_ProgressBarStart ( FILE *  pFile,
int  nItemsTotal 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the progress bar.]

Description [The first parameter is the output stream (pFile), where the progress is printed. The current printing position should be the first one on the given line. The second parameters is the total number of items that correspond to 100% position of the progress bar.]

SideEffects []

SeeAlso []

Definition at line 62 of file extraUtilProgress.c.

63 {
64  ProgressBar * p;
65  if ( !Abc_FrameShowProgress(Abc_FrameGetGlobalFrame()) ) return NULL;
66  p = ABC_ALLOC( ProgressBar, 1 );
67  memset( p, 0, sizeof(ProgressBar) );
68  p->pFile = pFile;
69  p->nItemsTotal = nItemsTotal;
70  p->posTotal = 78;
71  p->posCur = 1;
72  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
73  Extra_ProgressBarShow( p, NULL );
74  return p;
75 }
static void Extra_ProgressBarShow(ProgressBar *p, char *pString)
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DECLARATIONS ///.
void * Abc_FrameGetGlobalFrame()
Definition: mainFrame.c:593
ABC_DLL int Abc_FrameShowProgress(Abc_Frame_t *p)
Definition: mainFrame.c:265
void Extra_ProgressBarStop ( ProgressBar p)

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

Synopsis [Stops the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 118 of file extraUtilProgress.c.

119 {
120  if ( p == NULL ) return;
122  ABC_FREE( p );
123 }
static void Extra_ProgressBarClean(ProgressBar *p)
#define ABC_FREE(obj)
Definition: abc_global.h:232
static void Extra_ProgressBarUpdate ( ProgressBar p,
int  nItemsCur,
char *  pString 
)
inlinestatic

Definition at line 243 of file extra.h.

244 { if ( p && nItemsCur < *((int*)p) ) return; Extra_ProgressBarUpdate_int(p, nItemsCur, pString); }
void Extra_ProgressBarUpdate_int(ProgressBar *p, int nItemsCur, char *pString)
void Extra_ProgressBarUpdate_int ( ProgressBar p,
int  nItemsCur,
char *  pString 
)

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

Synopsis [Updates the progress bar.]

Description []

SideEffects []

SeeAlso []

Definition at line 88 of file extraUtilProgress.c.

89 {
90  if ( p == NULL ) return;
91  if ( nItemsCur < p->nItemsNext )
92  return;
93  if ( nItemsCur >= p->nItemsTotal )
94  {
95  p->posCur = 78;
96  p->nItemsNext = 0x7FFFFFFF;
97  }
98  else
99  {
100  p->posCur += 7;
101  p->nItemsNext = (int)((7.0+p->posCur)*p->nItemsTotal/p->posTotal);
102  }
103  Extra_ProgressBarShow( p, pString );
104 }
static void Extra_ProgressBarShow(ProgressBar *p, char *pString)
unsigned Extra_ReadBinary ( char *  Buffer)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 470 of file extraUtilFile.c.

471 {
472  unsigned Result;
473  int i;
474 
475  Result = 0;
476  for ( i = 0; Buffer[i]; i++ )
477  if ( Buffer[i] == '0' || Buffer[i] == '1' )
478  Result = Result * 2 + Buffer[i] - '0';
479  else
480  {
481  assert( 0 );
482  }
483  return Result;
484 }
#define assert(ex)
Definition: util_old.h:213
int Extra_ReadHex ( unsigned  Sign[],
char *  pString,
int  nDigits 
)

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

Synopsis [Reads the hex unsigned into the bit-string.]

Description []

SideEffects []

SeeAlso []

Definition at line 523 of file extraUtilFile.c.

524 {
525  int Digit, k, c;
526  for ( k = 0; k < nDigits; k++ )
527  {
528  c = nDigits-1-k;
529  if ( pString[c] >= '0' && pString[c] <= '9' )
530  Digit = pString[c] - '0';
531  else if ( pString[c] >= 'A' && pString[c] <= 'F' )
532  Digit = pString[c] - 'A' + 10;
533  else if ( pString[c] >= 'a' && pString[c] <= 'f' )
534  Digit = pString[c] - 'a' + 10;
535  else { assert( 0 ); return 0; }
536  Sign[k/8] |= ( (Digit & 15) << ((k%8) * 4) );
537  }
538  return 1;
539 }
#define assert(ex)
Definition: util_old.h:213
int Extra_ReadHexadecimal ( unsigned  Sign[],
char *  pString,
int  nVars 
)

Definition at line 540 of file extraUtilFile.c.

541 {
542  int nWords, nDigits, k;
543  nWords = Extra_TruthWordNum( nVars );
544  for ( k = 0; k < nWords; k++ )
545  Sign[k] = 0;
546  // read the number from the string
547  nDigits = (1 << nVars) / 4;
548  if ( nDigits == 0 )
549  nDigits = 1;
550  Extra_ReadHex( Sign, pString, nDigits );
551  return 1;
552 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
int Extra_ReadHex(unsigned Sign[], char *pString, int nDigits)
char* Extra_StringAppend ( char *  pStrGiven,
char *  pStrAdd 
)

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

Synopsis [Appends the string.]

Description [Assumes that the given string (pStrGiven) has been allocated before using malloc(). The additional string has not been allocated. Allocs more root, appends the additional part, frees the old given string.]

SideEffects []

SeeAlso []

Definition at line 690 of file extraUtilFile.c.

691 {
692  char * pTemp;
693  if ( pStrGiven )
694  {
695  pTemp = ABC_ALLOC( char, strlen(pStrGiven) + strlen(pStrAdd) + 2 );
696  sprintf( pTemp, "%s%s", pStrGiven, pStrAdd );
697  ABC_FREE( pStrGiven );
698  }
699  else
700  pTemp = Extra_UtilStrsav( pStrAdd );
701  return pTemp;
702 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
int strlen()
void Extra_StringClean ( char *  pStrGiven,
char *  pCharKeep 
)

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

Synopsis [Only keep characters belonging to the second string.]

Description []

SideEffects []

SeeAlso []

Definition at line 715 of file extraUtilFile.c.

716 {
717  char * pTemp, * pChar, * pSave = pStrGiven;
718  for ( pTemp = pStrGiven; *pTemp; pTemp++ )
719  {
720  for ( pChar = pCharKeep; *pChar; pChar++ )
721  if ( *pTemp == *pChar )
722  break;
723  if ( *pChar == 0 )
724  continue;
725  *pSave++ = *pTemp;
726  }
727  *pSave = 0;
728 }
char* Extra_TimeStamp ( )

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

Synopsis [Returns the time stamp.]

Description [The file should be closed.]

SideEffects []

SeeAlso []

Definition at line 446 of file extraUtilFile.c.

447 {
448  static char Buffer[100];
449  char * TimeStamp;
450  time_t ltime;
451  // get the current time
452  time( &ltime );
453  TimeStamp = asctime( localtime( &ltime ) );
454  TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
455  strcpy( Buffer, TimeStamp );
456  return Buffer;
457 }
char * strcpy()
int strlen()
void Extra_Truth4VarN ( unsigned short **  puCanons,
char ***  puPhases,
char **  ppCounters,
int  nPhasesMax 
)

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

Synopsis [Computes NPN canonical forms for 4-variable functions.]

Description []

SideEffects []

SeeAlso []

Definition at line 814 of file extraUtilMisc.c.

815 {
816  unsigned short * uCanons;
817  unsigned uTruth, uPhase;
818  char ** uPhases, * pCounters;
819  int nFuncs, nClasses, i;
820 
821  nFuncs = (1 << 16);
822  uCanons = ABC_ALLOC( unsigned short, nFuncs );
823  memset( uCanons, 0, sizeof(unsigned short) * nFuncs );
824  pCounters = ABC_ALLOC( char, nFuncs );
825  memset( pCounters, 0, sizeof(char) * nFuncs );
826  uPhases = (char **)Extra_ArrayAlloc( nFuncs, nPhasesMax, sizeof(char) );
827  nClasses = 0;
828  for ( uTruth = 0; uTruth < (unsigned)nFuncs; uTruth++ )
829  {
830  // skip already assigned
831  if ( uCanons[uTruth] )
832  {
833  assert( uTruth > uCanons[uTruth] );
834  continue;
835  }
836  nClasses++;
837  for ( i = 0; i < 16; i++ )
838  {
839  uPhase = Extra_TruthPolarize( uTruth, i, 4 );
840  if ( uCanons[uPhase] == 0 && (uTruth || i==0) )
841  {
842  uCanons[uPhase] = uTruth;
843  uPhases[uPhase][0] = i;
844  pCounters[uPhase] = 1;
845  }
846  else
847  {
848  assert( uCanons[uPhase] == uTruth );
849  if ( pCounters[uPhase] < nPhasesMax )
850  uPhases[uPhase][ (int)pCounters[uPhase]++ ] = i;
851  }
852  }
853  }
854  if ( puCanons )
855  *puCanons = uCanons;
856  else
857  ABC_FREE( uCanons );
858  if ( puPhases )
859  *puPhases = uPhases;
860  else
861  ABC_FREE( uPhases );
862  if ( ppCounters )
863  *ppCounters = pCounters;
864  else
865  ABC_FREE( pCounters );
866 // printf( "The number of 4N-classes = %d.\n", nClasses );
867 }
char * memset()
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
void Extra_Truth4VarNPN ( unsigned short **  puCanons,
char **  puPhases,
char **  puPerms,
unsigned char **  puMap 
)

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

Synopsis [Computes NPN canonical forms for 4-variable functions.]

Description []

SideEffects []

SeeAlso []

Definition at line 642 of file extraUtilMisc.c.

643 {
644  unsigned short * uCanons;
645  unsigned char * uMap;
646  unsigned uTruth, uPhase, uPerm;
647  char ** pPerms4, * uPhases, * uPerms;
648  int nFuncs, nClasses;
649  int i, k;
650 
651  nFuncs = (1 << 16);
652  uCanons = ABC_ALLOC( unsigned short, nFuncs );
653  uPhases = ABC_ALLOC( char, nFuncs );
654  uPerms = ABC_ALLOC( char, nFuncs );
655  uMap = ABC_ALLOC( unsigned char, nFuncs );
656  memset( uCanons, 0, sizeof(unsigned short) * nFuncs );
657  memset( uPhases, 0, sizeof(char) * nFuncs );
658  memset( uPerms, 0, sizeof(char) * nFuncs );
659  memset( uMap, 0, sizeof(unsigned char) * nFuncs );
660  pPerms4 = Extra_Permutations( 4 );
661 
662  nClasses = 1;
663  nFuncs = (1 << 15);
664  for ( uTruth = 1; uTruth < (unsigned)nFuncs; uTruth++ )
665  {
666  // skip already assigned
667  if ( uCanons[uTruth] )
668  {
669  assert( uTruth > uCanons[uTruth] );
670  uMap[~uTruth & 0xFFFF] = uMap[uTruth] = uMap[uCanons[uTruth]];
671  continue;
672  }
673  uMap[uTruth] = nClasses++;
674  for ( i = 0; i < 16; i++ )
675  {
676  uPhase = Extra_TruthPolarize( uTruth, i, 4 );
677  for ( k = 0; k < 24; k++ )
678  {
679  uPerm = Extra_TruthPermute( uPhase, pPerms4[k], 4, 0 );
680  if ( uCanons[uPerm] == 0 )
681  {
682  uCanons[uPerm] = uTruth;
683  uPhases[uPerm] = i;
684  uPerms[uPerm] = k;
685 
686  uPerm = ~uPerm & 0xFFFF;
687  uCanons[uPerm] = uTruth;
688  uPhases[uPerm] = i | 16;
689  uPerms[uPerm] = k;
690  }
691  else
692  assert( uCanons[uPerm] == uTruth );
693  }
694  uPhase = Extra_TruthPolarize( ~uTruth & 0xFFFF, i, 4 );
695  for ( k = 0; k < 24; k++ )
696  {
697  uPerm = Extra_TruthPermute( uPhase, pPerms4[k], 4, 0 );
698  if ( uCanons[uPerm] == 0 )
699  {
700  uCanons[uPerm] = uTruth;
701  uPhases[uPerm] = i;
702  uPerms[uPerm] = k;
703 
704  uPerm = ~uPerm & 0xFFFF;
705  uCanons[uPerm] = uTruth;
706  uPhases[uPerm] = i | 16;
707  uPerms[uPerm] = k;
708  }
709  else
710  assert( uCanons[uPerm] == uTruth );
711  }
712  }
713  }
714  uPhases[(1<<16)-1] = 16;
715  assert( nClasses == 222 );
716  ABC_FREE( pPerms4 );
717  if ( puCanons )
718  *puCanons = uCanons;
719  else
720  ABC_FREE( uCanons );
721  if ( puPhases )
722  *puPhases = uPhases;
723  else
724  ABC_FREE( uPhases );
725  if ( puPerms )
726  *puPerms = uPerms;
727  else
728  ABC_FREE( uPerms );
729  if ( puMap )
730  *puMap = uMap;
731  else
732  ABC_FREE( uMap );
733 }
char * memset()
unsigned Extra_TruthPermute(unsigned Truth, char *pPerms, int nVars, int fReverse)
char ** Extra_Permutations(int n)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
word Extra_Truth6MinimumExact ( word  t,
int *  pComp,
int *  pPerm 
)

Definition at line 2286 of file extraUtilMisc.c.

2287 {
2288  word tMin = ~(word)0;
2289  word tCur, tTemp1, tTemp2;
2290  int i, p, c;
2291  for ( i = 0; i < 2; i++ )
2292  {
2293  tCur = i ? ~t : t;
2294  tTemp1 = tCur;
2295  for ( p = 0; p < 720; p++ )
2296  {
2297 // printf( "Trying perm %d:\n", p );
2298 // Kit_DsdPrintFromTruth( &tCur, 6 ), printf( "\n" );;
2299  tTemp2 = tCur;
2300  for ( c = 0; c < 64; c++ )
2301  {
2302  tMin = Abc_MinWord( tMin, tCur );
2303  tCur = Extra_Truth6ChangePhase( tCur, pComp[c] );
2304  }
2305  assert( tTemp2 == tCur );
2306  tCur = Extra_Truth6SwapAdjacent( tCur, pPerm[p] );
2307  }
2308  assert( tTemp1 == tCur );
2309  }
2310  return tMin;
2311 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static word Abc_MinWord(word a, word b)
Definition: abc_global.h:241
static word Extra_Truth6ChangePhase(word t, int v)
static word Extra_Truth6SwapAdjacent(word t, int v)
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int pPerm[13719]
Definition: rwrTemp.c:32
#define assert(ex)
Definition: util_old.h:213
word Extra_Truth6MinimumHeuristic ( word  t)

Definition at line 2374 of file extraUtilMisc.c.

2375 {
2376  word tMin1, tMin2;
2377  int nOnes = Extra_Truth6Ones( t );
2378  if ( nOnes < 32 )
2379  return Extra_Truth6MinimumRoundMany( t );
2380  if ( nOnes > 32 )
2381  return Extra_Truth6MinimumRoundMany( ~t );
2382  tMin1 = Extra_Truth6MinimumRoundMany( t );
2383  tMin2 = Extra_Truth6MinimumRoundMany( ~t );
2384  return Abc_MinWord( tMin1, tMin2 );
2385 }
static word Abc_MinWord(word a, word b)
Definition: abc_global.h:241
static int Extra_Truth6Ones(word t)
static word Extra_Truth6MinimumRoundMany(word t)
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Extra_TruthAnd ( unsigned *  pOut,
unsigned *  pIn0,
unsigned *  pIn1,
int  nVars 
)
inlinestatic

Definition at line 326 of file extra.h.

327 {
328  int w;
329  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
330  pOut[w] = pIn0[w] & pIn1[w];
331 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static void Extra_TruthAndPhase ( unsigned *  pOut,
unsigned *  pIn0,
unsigned *  pIn1,
int  nVars,
int  fCompl0,
int  fCompl1 
)
inlinestatic

Definition at line 350 of file extra.h.

351 {
352  int w;
353  if ( fCompl0 && fCompl1 )
354  {
355  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
356  pOut[w] = ~(pIn0[w] | pIn1[w]);
357  }
358  else if ( fCompl0 && !fCompl1 )
359  {
360  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
361  pOut[w] = ~pIn0[w] & pIn1[w];
362  }
363  else if ( !fCompl0 && fCompl1 )
364  {
365  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
366  pOut[w] = pIn0[w] & ~pIn1[w];
367  }
368  else // if ( !fCompl0 && !fCompl1 )
369  {
370  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
371  pOut[w] = pIn0[w] & pIn1[w];
372  }
373 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
int Extra_TruthCanonFastN ( int  nVarsMax,
int  nVarsReal,
unsigned *  pt,
unsigned **  pptRes,
char **  ppfRes 
)

AutomaticEnd Function********************************************************************

Synopsis [Computes the N-canonical form of the Boolean function up to 6 inputs.]

Description [The N-canonical form is defined as the truth table with the minimum integer value. This function exhaustively enumerates through the complete set of 2^N phase assignments. Returns pointers to the static storage to the truth table and phases. This data should be used before the function is called again.]

SideEffects []

SeeAlso []

Definition at line 374 of file extraUtilCanon.c.

375 {
376  static unsigned uTruthStore6[2];
377  int RetValue;
378  assert( nVarsMax <= 6 );
379  assert( nVarsReal <= nVarsMax );
380  RetValue = Extra_TruthCanonN_rec( nVarsReal <= 3? 3: nVarsReal, (unsigned char *)pt, pptRes, ppfRes, 0 );
381  if ( nVarsMax == 6 && nVarsReal < nVarsMax )
382  {
383  uTruthStore6[0] = **pptRes;
384  uTruthStore6[1] = **pptRes;
385  *pptRes = uTruthStore6;
386  }
387  return RetValue;
388 }
static int Extra_TruthCanonN_rec(int nVars, unsigned char *pt, unsigned **pptRes, char **ppfRes, int Flag)
#define assert(ex)
Definition: util_old.h:213
unsigned Extra_TruthCanonN ( unsigned  uTruth,
int  nVars 
)

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

Synopsis [Computes N-canonical form using brute-force methods.]

Description []

SideEffects []

SeeAlso []

Definition at line 439 of file extraUtilMisc.c.

440 {
441  unsigned uTruthMin, uPhase;
442  int nMints, i;
443  nMints = (1 << nVars);
444  uTruthMin = 0xFFFFFFFF;
445  for ( i = 0; i < nMints; i++ )
446  {
447  uPhase = Extra_TruthPolarize( uTruth, i, nVars );
448  if ( uTruthMin > uPhase )
449  uTruthMin = uPhase;
450  }
451  return uTruthMin;
452 }
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
unsigned Extra_TruthCanonNN ( unsigned  uTruth,
int  nVars 
)

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

Synopsis [Computes NN-canonical form using brute-force methods.]

Description []

SideEffects []

SeeAlso []

Definition at line 465 of file extraUtilMisc.c.

466 {
467  unsigned uTruthMin, uTruthC, uPhase;
468  int nMints, i;
469  nMints = (1 << nVars);
470  uTruthC = (unsigned)( (~uTruth) & ((~((unsigned)0)) >> (32-nMints)) );
471  uTruthMin = 0xFFFFFFFF;
472  for ( i = 0; i < nMints; i++ )
473  {
474  uPhase = Extra_TruthPolarize( uTruth, i, nVars );
475  if ( uTruthMin > uPhase )
476  uTruthMin = uPhase;
477  uPhase = Extra_TruthPolarize( uTruthC, i, nVars );
478  if ( uTruthMin > uPhase )
479  uTruthMin = uPhase;
480  }
481  return uTruthMin;
482 }
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
unsigned Extra_TruthCanonNP ( unsigned  uTruth,
int  nVars 
)

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

Synopsis [Computes NP-canonical form using brute-force methods.]

Description []

SideEffects []

SeeAlso []

Definition at line 538 of file extraUtilMisc.c.

539 {
540  static int nVarsOld, nPerms;
541  static char ** pPerms = NULL;
542 
543  unsigned uTruthMin, uPhase, uPerm;
544  int nMints, k, i;
545 
546  if ( pPerms == NULL )
547  {
548  nPerms = Extra_Factorial( nVars );
549  pPerms = Extra_Permutations( nVars );
550  nVarsOld = nVars;
551  }
552  else if ( nVarsOld != nVars )
553  {
554  ABC_FREE( pPerms );
555  nPerms = Extra_Factorial( nVars );
556  pPerms = Extra_Permutations( nVars );
557  nVarsOld = nVars;
558  }
559 
560  nMints = (1 << nVars);
561  uTruthMin = 0xFFFFFFFF;
562  for ( i = 0; i < nMints; i++ )
563  {
564  uPhase = Extra_TruthPolarize( uTruth, i, nVars );
565  for ( k = 0; k < nPerms; k++ )
566  {
567  uPerm = Extra_TruthPermute( uPhase, pPerms[k], nVars, 0 );
568  if ( uTruthMin > uPerm )
569  uTruthMin = uPerm;
570  }
571  }
572  return uTruthMin;
573 }
unsigned Extra_TruthPermute(unsigned Truth, char *pPerms, int nVars, int fReverse)
char ** Extra_Permutations(int n)
int Extra_Factorial(int n)
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
#define ABC_FREE(obj)
Definition: abc_global.h:232
unsigned Extra_TruthCanonNPN ( unsigned  uTruth,
int  nVars 
)

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

Synopsis [Computes NPN-canonical form using brute-force methods.]

Description []

SideEffects []

SeeAlso []

Definition at line 586 of file extraUtilMisc.c.

587 {
588  static int nVarsOld, nPerms;
589  static char ** pPerms = NULL;
590 
591  unsigned uTruthMin, uTruthC, uPhase, uPerm;
592  int nMints, k, i;
593 
594  if ( pPerms == NULL )
595  {
596  nPerms = Extra_Factorial( nVars );
597  pPerms = Extra_Permutations( nVars );
598  nVarsOld = nVars;
599  }
600  else if ( nVarsOld != nVars )
601  {
602  ABC_FREE( pPerms );
603  nPerms = Extra_Factorial( nVars );
604  pPerms = Extra_Permutations( nVars );
605  nVarsOld = nVars;
606  }
607 
608  nMints = (1 << nVars);
609  uTruthC = (unsigned)( (~uTruth) & ((~((unsigned)0)) >> (32-nMints)) );
610  uTruthMin = 0xFFFFFFFF;
611  for ( i = 0; i < nMints; i++ )
612  {
613  uPhase = Extra_TruthPolarize( uTruth, i, nVars );
614  for ( k = 0; k < nPerms; k++ )
615  {
616  uPerm = Extra_TruthPermute( uPhase, pPerms[k], nVars, 0 );
617  if ( uTruthMin > uPerm )
618  uTruthMin = uPerm;
619  }
620  uPhase = Extra_TruthPolarize( uTruthC, i, nVars );
621  for ( k = 0; k < nPerms; k++ )
622  {
623  uPerm = Extra_TruthPermute( uPhase, pPerms[k], nVars, 0 );
624  if ( uTruthMin > uPerm )
625  uTruthMin = uPerm;
626  }
627  }
628  return uTruthMin;
629 }
unsigned Extra_TruthPermute(unsigned Truth, char *pPerms, int nVars, int fReverse)
char ** Extra_Permutations(int n)
int Extra_Factorial(int n)
unsigned Extra_TruthPolarize(unsigned uTruth, int Polarity, int nVars)
#define ABC_FREE(obj)
Definition: abc_global.h:232
unsigned Extra_TruthCanonP ( unsigned  uTruth,
int  nVars 
)

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

Synopsis [Computes P-canonical form using brute-force methods.]

Description []

SideEffects []

SeeAlso []

Definition at line 495 of file extraUtilMisc.c.

496 {
497  static int nVarsOld, nPerms;
498  static char ** pPerms = NULL;
499 
500  unsigned uTruthMin, uPerm;
501  int k;
502 
503  if ( pPerms == NULL )
504  {
505  nPerms = Extra_Factorial( nVars );
506  pPerms = Extra_Permutations( nVars );
507  nVarsOld = nVars;
508  }
509  else if ( nVarsOld != nVars )
510  {
511  ABC_FREE( pPerms );
512  nPerms = Extra_Factorial( nVars );
513  pPerms = Extra_Permutations( nVars );
514  nVarsOld = nVars;
515  }
516 
517  uTruthMin = 0xFFFFFFFF;
518  for ( k = 0; k < nPerms; k++ )
519  {
520  uPerm = Extra_TruthPermute( uTruth, pPerms[k], nVars, 0 );
521  if ( uTruthMin > uPerm )
522  uTruthMin = uPerm;
523  }
524  return uTruthMin;
525 }
unsigned Extra_TruthPermute(unsigned Truth, char *pPerms, int nVars, int fReverse)
char ** Extra_Permutations(int n)
int Extra_Factorial(int n)
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Extra_TruthChangePhase ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Changes phase of the function w.r.t. one variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 719 of file extraUtilTruth.c.

720 {
721  int nWords = Extra_TruthWordNum( nVars );
722  int i, k, Step;
723  unsigned Temp;
724 
725  assert( iVar < nVars );
726  switch ( iVar )
727  {
728  case 0:
729  for ( i = 0; i < nWords; i++ )
730  pTruth[i] = ((pTruth[i] & 0x55555555) << 1) | ((pTruth[i] & 0xAAAAAAAA) >> 1);
731  return;
732  case 1:
733  for ( i = 0; i < nWords; i++ )
734  pTruth[i] = ((pTruth[i] & 0x33333333) << 2) | ((pTruth[i] & 0xCCCCCCCC) >> 2);
735  return;
736  case 2:
737  for ( i = 0; i < nWords; i++ )
738  pTruth[i] = ((pTruth[i] & 0x0F0F0F0F) << 4) | ((pTruth[i] & 0xF0F0F0F0) >> 4);
739  return;
740  case 3:
741  for ( i = 0; i < nWords; i++ )
742  pTruth[i] = ((pTruth[i] & 0x00FF00FF) << 8) | ((pTruth[i] & 0xFF00FF00) >> 8);
743  return;
744  case 4:
745  for ( i = 0; i < nWords; i++ )
746  pTruth[i] = ((pTruth[i] & 0x0000FFFF) << 16) | ((pTruth[i] & 0xFFFF0000) >> 16);
747  return;
748  default:
749  Step = (1 << (iVar - 5));
750  for ( k = 0; k < nWords; k += 2*Step )
751  {
752  for ( i = 0; i < Step; i++ )
753  {
754  Temp = pTruth[i];
755  pTruth[i] = pTruth[Step+i];
756  pTruth[Step+i] = Temp;
757  }
758  pTruth += 2*Step;
759  }
760  return;
761  }
762 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthClear ( unsigned *  pOut,
int  nVars 
)
inlinestatic

Definition at line 308 of file extra.h.

309 {
310  int w;
311  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
312  pOut[w] = 0;
313 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
void Extra_TruthCofactor0 ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Computes negative cofactor of the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 450 of file extraUtilTruth.c.

451 {
452  int nWords = Extra_TruthWordNum( nVars );
453  int i, k, Step;
454 
455  assert( iVar < nVars );
456  switch ( iVar )
457  {
458  case 0:
459  for ( i = 0; i < nWords; i++ )
460  pTruth[i] = (pTruth[i] & 0x55555555) | ((pTruth[i] & 0x55555555) << 1);
461  return;
462  case 1:
463  for ( i = 0; i < nWords; i++ )
464  pTruth[i] = (pTruth[i] & 0x33333333) | ((pTruth[i] & 0x33333333) << 2);
465  return;
466  case 2:
467  for ( i = 0; i < nWords; i++ )
468  pTruth[i] = (pTruth[i] & 0x0F0F0F0F) | ((pTruth[i] & 0x0F0F0F0F) << 4);
469  return;
470  case 3:
471  for ( i = 0; i < nWords; i++ )
472  pTruth[i] = (pTruth[i] & 0x00FF00FF) | ((pTruth[i] & 0x00FF00FF) << 8);
473  return;
474  case 4:
475  for ( i = 0; i < nWords; i++ )
476  pTruth[i] = (pTruth[i] & 0x0000FFFF) | ((pTruth[i] & 0x0000FFFF) << 16);
477  return;
478  default:
479  Step = (1 << (iVar - 5));
480  for ( k = 0; k < nWords; k += 2*Step )
481  {
482  for ( i = 0; i < Step; i++ )
483  pTruth[Step+i] = pTruth[i];
484  pTruth += 2*Step;
485  }
486  return;
487  }
488 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
void Extra_TruthCofactor1 ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Computes positive cofactor of the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 399 of file extraUtilTruth.c.

400 {
401  int nWords = Extra_TruthWordNum( nVars );
402  int i, k, Step;
403 
404  assert( iVar < nVars );
405  switch ( iVar )
406  {
407  case 0:
408  for ( i = 0; i < nWords; i++ )
409  pTruth[i] = (pTruth[i] & 0xAAAAAAAA) | ((pTruth[i] & 0xAAAAAAAA) >> 1);
410  return;
411  case 1:
412  for ( i = 0; i < nWords; i++ )
413  pTruth[i] = (pTruth[i] & 0xCCCCCCCC) | ((pTruth[i] & 0xCCCCCCCC) >> 2);
414  return;
415  case 2:
416  for ( i = 0; i < nWords; i++ )
417  pTruth[i] = (pTruth[i] & 0xF0F0F0F0) | ((pTruth[i] & 0xF0F0F0F0) >> 4);
418  return;
419  case 3:
420  for ( i = 0; i < nWords; i++ )
421  pTruth[i] = (pTruth[i] & 0xFF00FF00) | ((pTruth[i] & 0xFF00FF00) >> 8);
422  return;
423  case 4:
424  for ( i = 0; i < nWords; i++ )
425  pTruth[i] = (pTruth[i] & 0xFFFF0000) | ((pTruth[i] & 0xFFFF0000) >> 16);
426  return;
427  default:
428  Step = (1 << (iVar - 5));
429  for ( k = 0; k < nWords; k += 2*Step )
430  {
431  for ( i = 0; i < Step; i++ )
432  pTruth[i] = pTruth[Step+i];
433  pTruth += 2*Step;
434  }
435  return;
436  }
437 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthCopy ( unsigned *  pOut,
unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 302 of file extra.h.

303 {
304  int w;
305  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
306  pOut[w] = pIn[w];
307 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_TruthCountOnes ( unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 263 of file extra.h.

264 {
265  int w, Counter = 0;
266  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
267  Counter += Extra_WordCountOnes(pIn[w]);
268  return Counter;
269 }
static int Counter
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_WordCountOnes(unsigned uWord)
Definition: extra.h:255
void Extra_TruthCountOnesInCofs ( unsigned *  pTruth,
int  nVars,
short *  pStore 
)

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

Synopsis [Counts the number of 1's in each cofactor.]

Description [The resulting numbers are stored in the array of shorts, whose length is 2*nVars. The number of 1's is counted in a different space than the original function. For example, if the function depends on k variables, the cofactors are assumed to depend on k-1 variables.]

SideEffects []

SeeAlso []

Definition at line 828 of file extraUtilTruth.c.

829 {
830  int nWords = Extra_TruthWordNum( nVars );
831  int i, k, Counter;
832  memset( pStore, 0, sizeof(short) * 2 * nVars );
833  if ( nVars <= 5 )
834  {
835  if ( nVars > 0 )
836  {
837  pStore[2*0+0] = Extra_WordCountOnes( pTruth[0] & 0x55555555 );
838  pStore[2*0+1] = Extra_WordCountOnes( pTruth[0] & 0xAAAAAAAA );
839  }
840  if ( nVars > 1 )
841  {
842  pStore[2*1+0] = Extra_WordCountOnes( pTruth[0] & 0x33333333 );
843  pStore[2*1+1] = Extra_WordCountOnes( pTruth[0] & 0xCCCCCCCC );
844  }
845  if ( nVars > 2 )
846  {
847  pStore[2*2+0] = Extra_WordCountOnes( pTruth[0] & 0x0F0F0F0F );
848  pStore[2*2+1] = Extra_WordCountOnes( pTruth[0] & 0xF0F0F0F0 );
849  }
850  if ( nVars > 3 )
851  {
852  pStore[2*3+0] = Extra_WordCountOnes( pTruth[0] & 0x00FF00FF );
853  pStore[2*3+1] = Extra_WordCountOnes( pTruth[0] & 0xFF00FF00 );
854  }
855  if ( nVars > 4 )
856  {
857  pStore[2*4+0] = Extra_WordCountOnes( pTruth[0] & 0x0000FFFF );
858  pStore[2*4+1] = Extra_WordCountOnes( pTruth[0] & 0xFFFF0000 );
859  }
860  return;
861  }
862  // nVars >= 6
863  // count 1's for all other variables
864  for ( k = 0; k < nWords; k++ )
865  {
866  Counter = Extra_WordCountOnes( pTruth[k] );
867  for ( i = 5; i < nVars; i++ )
868  if ( k & (1 << (i-5)) )
869  pStore[2*i+1] += Counter;
870  else
871  pStore[2*i+0] += Counter;
872  }
873  // count 1's for the first five variables
874  for ( k = 0; k < nWords/2; k++ )
875  {
876  pStore[2*0+0] += Extra_WordCountOnes( (pTruth[0] & 0x55555555) | ((pTruth[1] & 0x55555555) << 1) );
877  pStore[2*0+1] += Extra_WordCountOnes( (pTruth[0] & 0xAAAAAAAA) | ((pTruth[1] & 0xAAAAAAAA) >> 1) );
878  pStore[2*1+0] += Extra_WordCountOnes( (pTruth[0] & 0x33333333) | ((pTruth[1] & 0x33333333) << 2) );
879  pStore[2*1+1] += Extra_WordCountOnes( (pTruth[0] & 0xCCCCCCCC) | ((pTruth[1] & 0xCCCCCCCC) >> 2) );
880  pStore[2*2+0] += Extra_WordCountOnes( (pTruth[0] & 0x0F0F0F0F) | ((pTruth[1] & 0x0F0F0F0F) << 4) );
881  pStore[2*2+1] += Extra_WordCountOnes( (pTruth[0] & 0xF0F0F0F0) | ((pTruth[1] & 0xF0F0F0F0) >> 4) );
882  pStore[2*3+0] += Extra_WordCountOnes( (pTruth[0] & 0x00FF00FF) | ((pTruth[1] & 0x00FF00FF) << 8) );
883  pStore[2*3+1] += Extra_WordCountOnes( (pTruth[0] & 0xFF00FF00) | ((pTruth[1] & 0xFF00FF00) >> 8) );
884  pStore[2*4+0] += Extra_WordCountOnes( (pTruth[0] & 0x0000FFFF) | ((pTruth[1] & 0x0000FFFF) << 16) );
885  pStore[2*4+1] += Extra_WordCountOnes( (pTruth[0] & 0xFFFF0000) | ((pTruth[1] & 0xFFFF0000) >> 16) );
886  pTruth += 2;
887  }
888 }
char * memset()
int nWords
Definition: abcNpn.c:127
static int Counter
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_WordCountOnes(unsigned uWord)
Definition: extra.h:255
unsigned** Extra_TruthElementary ( int  nVars)

AutomaticStart AutomaticEnd Function*************************************************************

Synopsis [Derive elementary truth tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file extraUtilTruth.c.

78 {
79  unsigned ** pRes;
80  int i, k, nWords;
81  nWords = Extra_TruthWordNum(nVars);
82  pRes = (unsigned **)Extra_ArrayAlloc( nVars, nWords, 4 );
83  for ( i = 0; i < nVars; i++ )
84  {
85  if ( i < 5 )
86  {
87  for ( k = 0; k < nWords; k++ )
88  pRes[i][k] = s_VarMasks[i][1];
89  }
90  else
91  {
92  for ( k = 0; k < nWords; k++ )
93  if ( k & (1 << (i-5)) )
94  pRes[i][k] = ~(unsigned)0;
95  else
96  pRes[i][k] = 0;
97  }
98  }
99  return pRes;
100 }
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static ABC_NAMESPACE_IMPL_START unsigned s_VarMasks[5][2]
void Extra_TruthExist ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Existentially quantifies the variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 502 of file extraUtilTruth.c.

503 {
504  int nWords = Extra_TruthWordNum( nVars );
505  int i, k, Step;
506 
507  assert( iVar < nVars );
508  switch ( iVar )
509  {
510  case 0:
511  for ( i = 0; i < nWords; i++ )
512  pTruth[i] |= ((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1);
513  return;
514  case 1:
515  for ( i = 0; i < nWords; i++ )
516  pTruth[i] |= ((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2);
517  return;
518  case 2:
519  for ( i = 0; i < nWords; i++ )
520  pTruth[i] |= ((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4);
521  return;
522  case 3:
523  for ( i = 0; i < nWords; i++ )
524  pTruth[i] |= ((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8);
525  return;
526  case 4:
527  for ( i = 0; i < nWords; i++ )
528  pTruth[i] |= ((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16);
529  return;
530  default:
531  Step = (1 << (iVar - 5));
532  for ( k = 0; k < nWords; k += 2*Step )
533  {
534  for ( i = 0; i < Step; i++ )
535  {
536  pTruth[i] |= pTruth[Step+i];
537  pTruth[Step+i] = pTruth[i];
538  }
539  pTruth += 2*Step;
540  }
541  return;
542  }
543 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
void Extra_TruthExpand ( int  nVars,
int  nWords,
unsigned *  puTruth,
unsigned  uPhase,
unsigned *  puTruthR 
)

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

Synopsis [Computes a phase of the 8-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 1279 of file extraUtilMisc.c.

1280 {
1281  // elementary truth tables
1282  static unsigned uTruths[8][8] = {
1283  { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
1284  { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
1285  { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
1286  { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
1287  { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 },
1288  { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF },
1289  { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
1290  { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
1291  };
1292  static char Cases[256] = {
1293  0, // 00000000
1294  0, // 00000001
1295  1, // 00000010
1296  0, // 00000011
1297  2, // 00000100
1298  -1, // 00000101
1299  -1, // 00000110
1300  0, // 00000111
1301  3, // 00001000
1302  -1, // 00001001
1303  -1, // 00001010
1304  -1, // 00001011
1305  -1, // 00001100
1306  -1, // 00001101
1307  -1, // 00001110
1308  0, // 00001111
1309  4, // 00010000
1310  -1, // 00010001
1311  -1, // 00010010
1312  -1, // 00010011
1313  -1, // 00010100
1314  -1, // 00010101
1315  -1, // 00010110
1316  -1, // 00010111
1317  -1, // 00011000
1318  -1, // 00011001
1319  -1, // 00011010
1320  -1, // 00011011
1321  -1, // 00011100
1322  -1, // 00011101
1323  -1, // 00011110
1324  0, // 00011111
1325  5, // 00100000
1326  -1, // 00100001
1327  -1, // 00100010
1328  -1, // 00100011
1329  -1, // 00100100
1330  -1, // 00100101
1331  -1, // 00100110
1332  -1, // 00100111
1333  -1, // 00101000
1334  -1, // 00101001
1335  -1, // 00101010
1336  -1, // 00101011
1337  -1, // 00101100
1338  -1, // 00101101
1339  -1, // 00101110
1340  -1, // 00101111
1341  -1, // 00110000
1342  -1, // 00110001
1343  -1, // 00110010
1344  -1, // 00110011
1345  -1, // 00110100
1346  -1, // 00110101
1347  -1, // 00110110
1348  -1, // 00110111
1349  -1, // 00111000
1350  -1, // 00111001
1351  -1, // 00111010
1352  -1, // 00111011
1353  -1, // 00111100
1354  -1, // 00111101
1355  -1, // 00111110
1356  0, // 00111111
1357  6, // 01000000
1358  -1, // 01000001
1359  -1, // 01000010
1360  -1, // 01000011
1361  -1, // 01000100
1362  -1, // 01000101
1363  -1, // 01000110
1364  -1, // 01000111
1365  -1, // 01001000
1366  -1, // 01001001
1367  -1, // 01001010
1368  -1, // 01001011
1369  -1, // 01001100
1370  -1, // 01001101
1371  -1, // 01001110
1372  -1, // 01001111
1373  -1, // 01010000
1374  -1, // 01010001
1375  -1, // 01010010
1376  -1, // 01010011
1377  -1, // 01010100
1378  -1, // 01010101
1379  -1, // 01010110
1380  -1, // 01010111
1381  -1, // 01011000
1382  -1, // 01011001
1383  -1, // 01011010
1384  -1, // 01011011
1385  -1, // 01011100
1386  -1, // 01011101
1387  -1, // 01011110
1388  -1, // 01011111
1389  -1, // 01100000
1390  -1, // 01100001
1391  -1, // 01100010
1392  -1, // 01100011
1393  -1, // 01100100
1394  -1, // 01100101
1395  -1, // 01100110
1396  -1, // 01100111
1397  -1, // 01101000
1398  -1, // 01101001
1399  -1, // 01101010
1400  -1, // 01101011
1401  -1, // 01101100
1402  -1, // 01101101
1403  -1, // 01101110
1404  -1, // 01101111
1405  -1, // 01110000
1406  -1, // 01110001
1407  -1, // 01110010
1408  -1, // 01110011
1409  -1, // 01110100
1410  -1, // 01110101
1411  -1, // 01110110
1412  -1, // 01110111
1413  -1, // 01111000
1414  -1, // 01111001
1415  -1, // 01111010
1416  -1, // 01111011
1417  -1, // 01111100
1418  -1, // 01111101
1419  -1, // 01111110
1420  0, // 01111111
1421  7, // 10000000
1422  -1, // 10000001
1423  -1, // 10000010
1424  -1, // 10000011
1425  -1, // 10000100
1426  -1, // 10000101
1427  -1, // 10000110
1428  -1, // 10000111
1429  -1, // 10001000
1430  -1, // 10001001
1431  -1, // 10001010
1432  -1, // 10001011
1433  -1, // 10001100
1434  -1, // 10001101
1435  -1, // 10001110
1436  -1, // 10001111
1437  -1, // 10010000
1438  -1, // 10010001
1439  -1, // 10010010
1440  -1, // 10010011
1441  -1, // 10010100
1442  -1, // 10010101
1443  -1, // 10010110
1444  -1, // 10010111
1445  -1, // 10011000
1446  -1, // 10011001
1447  -1, // 10011010
1448  -1, // 10011011
1449  -1, // 10011100
1450  -1, // 10011101
1451  -1, // 10011110
1452  -1, // 10011111
1453  -1, // 10100000
1454  -1, // 10100001
1455  -1, // 10100010
1456  -1, // 10100011
1457  -1, // 10100100
1458  -1, // 10100101
1459  -1, // 10100110
1460  -1, // 10100111
1461  -1, // 10101000
1462  -1, // 10101001
1463  -1, // 10101010
1464  -1, // 10101011
1465  -1, // 10101100
1466  -1, // 10101101
1467  -1, // 10101110
1468  -1, // 10101111
1469  -1, // 10110000
1470  -1, // 10110001
1471  -1, // 10110010
1472  -1, // 10110011
1473  -1, // 10110100
1474  -1, // 10110101
1475  -1, // 10110110
1476  -1, // 10110111
1477  -1, // 10111000
1478  -1, // 10111001
1479  -1, // 10111010
1480  -1, // 10111011
1481  -1, // 10111100
1482  -1, // 10111101
1483  -1, // 10111110
1484  -1, // 10111111
1485  -1, // 11000000
1486  -1, // 11000001
1487  -1, // 11000010
1488  -1, // 11000011
1489  -1, // 11000100
1490  -1, // 11000101
1491  -1, // 11000110
1492  -1, // 11000111
1493  -1, // 11001000
1494  -1, // 11001001
1495  -1, // 11001010
1496  -1, // 11001011
1497  -1, // 11001100
1498  -1, // 11001101
1499  -1, // 11001110
1500  -1, // 11001111
1501  -1, // 11010000
1502  -1, // 11010001
1503  -1, // 11010010
1504  -1, // 11010011
1505  -1, // 11010100
1506  -1, // 11010101
1507  -1, // 11010110
1508  -1, // 11010111
1509  -1, // 11011000
1510  -1, // 11011001
1511  -1, // 11011010
1512  -1, // 11011011
1513  -1, // 11011100
1514  -1, // 11011101
1515  -1, // 11011110
1516  -1, // 11011111
1517  -1, // 11100000
1518  -1, // 11100001
1519  -1, // 11100010
1520  -1, // 11100011
1521  -1, // 11100100
1522  -1, // 11100101
1523  -1, // 11100110
1524  -1, // 11100111
1525  -1, // 11101000
1526  -1, // 11101001
1527  -1, // 11101010
1528  -1, // 11101011
1529  -1, // 11101100
1530  -1, // 11101101
1531  -1, // 11101110
1532  -1, // 11101111
1533  -1, // 11110000
1534  -1, // 11110001
1535  -1, // 11110010
1536  -1, // 11110011
1537  -1, // 11110100
1538  -1, // 11110101
1539  -1, // 11110110
1540  -1, // 11110111
1541  -1, // 11111000
1542  -1, // 11111001
1543  -1, // 11111010
1544  -1, // 11111011
1545  -1, // 11111100
1546  -1, // 11111101
1547  -1, // 11111110
1548  0 // 11111111
1549  };
1550  static char Perms[256][8] = {
1551  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00000000
1552  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00000001
1553  { 1, 0, 2, 3, 4, 5, 6, 7 }, // 00000010
1554  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00000011
1555  { 1, 2, 0, 3, 4, 5, 6, 7 }, // 00000100
1556  { 0, 2, 1, 3, 4, 5, 6, 7 }, // 00000101
1557  { 2, 0, 1, 3, 4, 5, 6, 7 }, // 00000110
1558  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00000111
1559  { 1, 2, 3, 0, 4, 5, 6, 7 }, // 00001000
1560  { 0, 2, 3, 1, 4, 5, 6, 7 }, // 00001001
1561  { 2, 0, 3, 1, 4, 5, 6, 7 }, // 00001010
1562  { 0, 1, 3, 2, 4, 5, 6, 7 }, // 00001011
1563  { 2, 3, 0, 1, 4, 5, 6, 7 }, // 00001100
1564  { 0, 3, 1, 2, 4, 5, 6, 7 }, // 00001101
1565  { 3, 0, 1, 2, 4, 5, 6, 7 }, // 00001110
1566  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00001111
1567  { 1, 2, 3, 4, 0, 5, 6, 7 }, // 00010000
1568  { 0, 2, 3, 4, 1, 5, 6, 7 }, // 00010001
1569  { 2, 0, 3, 4, 1, 5, 6, 7 }, // 00010010
1570  { 0, 1, 3, 4, 2, 5, 6, 7 }, // 00010011
1571  { 2, 3, 0, 4, 1, 5, 6, 7 }, // 00010100
1572  { 0, 3, 1, 4, 2, 5, 6, 7 }, // 00010101
1573  { 3, 0, 1, 4, 2, 5, 6, 7 }, // 00010110
1574  { 0, 1, 2, 4, 3, 5, 6, 7 }, // 00010111
1575  { 2, 3, 4, 0, 1, 5, 6, 7 }, // 00011000
1576  { 0, 3, 4, 1, 2, 5, 6, 7 }, // 00011001
1577  { 3, 0, 4, 1, 2, 5, 6, 7 }, // 00011010
1578  { 0, 1, 4, 2, 3, 5, 6, 7 }, // 00011011
1579  { 3, 4, 0, 1, 2, 5, 6, 7 }, // 00011100
1580  { 0, 4, 1, 2, 3, 5, 6, 7 }, // 00011101
1581  { 4, 0, 1, 2, 3, 5, 6, 7 }, // 00011110
1582  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00011111
1583  { 1, 2, 3, 4, 5, 0, 6, 7 }, // 00100000
1584  { 0, 2, 3, 4, 5, 1, 6, 7 }, // 00100001
1585  { 2, 0, 3, 4, 5, 1, 6, 7 }, // 00100010
1586  { 0, 1, 3, 4, 5, 2, 6, 7 }, // 00100011
1587  { 2, 3, 0, 4, 5, 1, 6, 7 }, // 00100100
1588  { 0, 3, 1, 4, 5, 2, 6, 7 }, // 00100101
1589  { 3, 0, 1, 4, 5, 2, 6, 7 }, // 00100110
1590  { 0, 1, 2, 4, 5, 3, 6, 7 }, // 00100111
1591  { 2, 3, 4, 0, 5, 1, 6, 7 }, // 00101000
1592  { 0, 3, 4, 1, 5, 2, 6, 7 }, // 00101001
1593  { 3, 0, 4, 1, 5, 2, 6, 7 }, // 00101010
1594  { 0, 1, 4, 2, 5, 3, 6, 7 }, // 00101011
1595  { 3, 4, 0, 1, 5, 2, 6, 7 }, // 00101100
1596  { 0, 4, 1, 2, 5, 3, 6, 7 }, // 00101101
1597  { 4, 0, 1, 2, 5, 3, 6, 7 }, // 00101110
1598  { 0, 1, 2, 3, 5, 4, 6, 7 }, // 00101111
1599  { 2, 3, 4, 5, 0, 1, 6, 7 }, // 00110000
1600  { 0, 3, 4, 5, 1, 2, 6, 7 }, // 00110001
1601  { 3, 0, 4, 5, 1, 2, 6, 7 }, // 00110010
1602  { 0, 1, 4, 5, 2, 3, 6, 7 }, // 00110011
1603  { 3, 4, 0, 5, 1, 2, 6, 7 }, // 00110100
1604  { 0, 4, 1, 5, 2, 3, 6, 7 }, // 00110101
1605  { 4, 0, 1, 5, 2, 3, 6, 7 }, // 00110110
1606  { 0, 1, 2, 5, 3, 4, 6, 7 }, // 00110111
1607  { 3, 4, 5, 0, 1, 2, 6, 7 }, // 00111000
1608  { 0, 4, 5, 1, 2, 3, 6, 7 }, // 00111001
1609  { 4, 0, 5, 1, 2, 3, 6, 7 }, // 00111010
1610  { 0, 1, 5, 2, 3, 4, 6, 7 }, // 00111011
1611  { 4, 5, 0, 1, 2, 3, 6, 7 }, // 00111100
1612  { 0, 5, 1, 2, 3, 4, 6, 7 }, // 00111101
1613  { 5, 0, 1, 2, 3, 4, 6, 7 }, // 00111110
1614  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 00111111
1615  { 1, 2, 3, 4, 5, 6, 0, 7 }, // 01000000
1616  { 0, 2, 3, 4, 5, 6, 1, 7 }, // 01000001
1617  { 2, 0, 3, 4, 5, 6, 1, 7 }, // 01000010
1618  { 0, 1, 3, 4, 5, 6, 2, 7 }, // 01000011
1619  { 2, 3, 0, 4, 5, 6, 1, 7 }, // 01000100
1620  { 0, 3, 1, 4, 5, 6, 2, 7 }, // 01000101
1621  { 3, 0, 1, 4, 5, 6, 2, 7 }, // 01000110
1622  { 0, 1, 2, 4, 5, 6, 3, 7 }, // 01000111
1623  { 2, 3, 4, 0, 5, 6, 1, 7 }, // 01001000
1624  { 0, 3, 4, 1, 5, 6, 2, 7 }, // 01001001
1625  { 3, 0, 4, 1, 5, 6, 2, 7 }, // 01001010
1626  { 0, 1, 4, 2, 5, 6, 3, 7 }, // 01001011
1627  { 3, 4, 0, 1, 5, 6, 2, 7 }, // 01001100
1628  { 0, 4, 1, 2, 5, 6, 3, 7 }, // 01001101
1629  { 4, 0, 1, 2, 5, 6, 3, 7 }, // 01001110
1630  { 0, 1, 2, 3, 5, 6, 4, 7 }, // 01001111
1631  { 2, 3, 4, 5, 0, 6, 1, 7 }, // 01010000
1632  { 0, 3, 4, 5, 1, 6, 2, 7 }, // 01010001
1633  { 3, 0, 4, 5, 1, 6, 2, 7 }, // 01010010
1634  { 0, 1, 4, 5, 2, 6, 3, 7 }, // 01010011
1635  { 3, 4, 0, 5, 1, 6, 2, 7 }, // 01010100
1636  { 0, 4, 1, 5, 2, 6, 3, 7 }, // 01010101
1637  { 4, 0, 1, 5, 2, 6, 3, 7 }, // 01010110
1638  { 0, 1, 2, 5, 3, 6, 4, 7 }, // 01010111
1639  { 3, 4, 5, 0, 1, 6, 2, 7 }, // 01011000
1640  { 0, 4, 5, 1, 2, 6, 3, 7 }, // 01011001
1641  { 4, 0, 5, 1, 2, 6, 3, 7 }, // 01011010
1642  { 0, 1, 5, 2, 3, 6, 4, 7 }, // 01011011
1643  { 4, 5, 0, 1, 2, 6, 3, 7 }, // 01011100
1644  { 0, 5, 1, 2, 3, 6, 4, 7 }, // 01011101
1645  { 5, 0, 1, 2, 3, 6, 4, 7 }, // 01011110
1646  { 0, 1, 2, 3, 4, 6, 5, 7 }, // 01011111
1647  { 2, 3, 4, 5, 6, 0, 1, 7 }, // 01100000
1648  { 0, 3, 4, 5, 6, 1, 2, 7 }, // 01100001
1649  { 3, 0, 4, 5, 6, 1, 2, 7 }, // 01100010
1650  { 0, 1, 4, 5, 6, 2, 3, 7 }, // 01100011
1651  { 3, 4, 0, 5, 6, 1, 2, 7 }, // 01100100
1652  { 0, 4, 1, 5, 6, 2, 3, 7 }, // 01100101
1653  { 4, 0, 1, 5, 6, 2, 3, 7 }, // 01100110
1654  { 0, 1, 2, 5, 6, 3, 4, 7 }, // 01100111
1655  { 3, 4, 5, 0, 6, 1, 2, 7 }, // 01101000
1656  { 0, 4, 5, 1, 6, 2, 3, 7 }, // 01101001
1657  { 4, 0, 5, 1, 6, 2, 3, 7 }, // 01101010
1658  { 0, 1, 5, 2, 6, 3, 4, 7 }, // 01101011
1659  { 4, 5, 0, 1, 6, 2, 3, 7 }, // 01101100
1660  { 0, 5, 1, 2, 6, 3, 4, 7 }, // 01101101
1661  { 5, 0, 1, 2, 6, 3, 4, 7 }, // 01101110
1662  { 0, 1, 2, 3, 6, 4, 5, 7 }, // 01101111
1663  { 3, 4, 5, 6, 0, 1, 2, 7 }, // 01110000
1664  { 0, 4, 5, 6, 1, 2, 3, 7 }, // 01110001
1665  { 4, 0, 5, 6, 1, 2, 3, 7 }, // 01110010
1666  { 0, 1, 5, 6, 2, 3, 4, 7 }, // 01110011
1667  { 4, 5, 0, 6, 1, 2, 3, 7 }, // 01110100
1668  { 0, 5, 1, 6, 2, 3, 4, 7 }, // 01110101
1669  { 5, 0, 1, 6, 2, 3, 4, 7 }, // 01110110
1670  { 0, 1, 2, 6, 3, 4, 5, 7 }, // 01110111
1671  { 4, 5, 6, 0, 1, 2, 3, 7 }, // 01111000
1672  { 0, 5, 6, 1, 2, 3, 4, 7 }, // 01111001
1673  { 5, 0, 6, 1, 2, 3, 4, 7 }, // 01111010
1674  { 0, 1, 6, 2, 3, 4, 5, 7 }, // 01111011
1675  { 5, 6, 0, 1, 2, 3, 4, 7 }, // 01111100
1676  { 0, 6, 1, 2, 3, 4, 5, 7 }, // 01111101
1677  { 6, 0, 1, 2, 3, 4, 5, 7 }, // 01111110
1678  { 0, 1, 2, 3, 4, 5, 6, 7 }, // 01111111
1679  { 1, 2, 3, 4, 5, 6, 7, 0 }, // 10000000
1680  { 0, 2, 3, 4, 5, 6, 7, 1 }, // 10000001
1681  { 2, 0, 3, 4, 5, 6, 7, 1 }, // 10000010
1682  { 0, 1, 3, 4, 5, 6, 7, 2 }, // 10000011
1683  { 2, 3, 0, 4, 5, 6, 7, 1 }, // 10000100
1684  { 0, 3, 1, 4, 5, 6, 7, 2 }, // 10000101
1685  { 3, 0, 1, 4, 5, 6, 7, 2 }, // 10000110
1686  { 0, 1, 2, 4, 5, 6, 7, 3 }, // 10000111
1687  { 2, 3, 4, 0, 5, 6, 7, 1 }, // 10001000
1688  { 0, 3, 4, 1, 5, 6, 7, 2 }, // 10001001
1689  { 3, 0, 4, 1, 5, 6, 7, 2 }, // 10001010
1690  { 0, 1, 4, 2, 5, 6, 7, 3 }, // 10001011
1691  { 3, 4, 0, 1, 5, 6, 7, 2 }, // 10001100
1692  { 0, 4, 1, 2, 5, 6, 7, 3 }, // 10001101
1693  { 4, 0, 1, 2, 5, 6, 7, 3 }, // 10001110
1694  { 0, 1, 2, 3, 5, 6, 7, 4 }, // 10001111
1695  { 2, 3, 4, 5, 0, 6, 7, 1 }, // 10010000
1696  { 0, 3, 4, 5, 1, 6, 7, 2 }, // 10010001
1697  { 3, 0, 4, 5, 1, 6, 7, 2 }, // 10010010
1698  { 0, 1, 4, 5, 2, 6, 7, 3 }, // 10010011
1699  { 3, 4, 0, 5, 1, 6, 7, 2 }, // 10010100
1700  { 0, 4, 1, 5, 2, 6, 7, 3 }, // 10010101
1701  { 4, 0, 1, 5, 2, 6, 7, 3 }, // 10010110
1702  { 0, 1, 2, 5, 3, 6, 7, 4 }, // 10010111
1703  { 3, 4, 5, 0, 1, 6, 7, 2 }, // 10011000
1704  { 0, 4, 5, 1, 2, 6, 7, 3 }, // 10011001
1705  { 4, 0, 5, 1, 2, 6, 7, 3 }, // 10011010
1706  { 0, 1, 5, 2, 3, 6, 7, 4 }, // 10011011
1707  { 4, 5, 0, 1, 2, 6, 7, 3 }, // 10011100
1708  { 0, 5, 1, 2, 3, 6, 7, 4 }, // 10011101
1709  { 5, 0, 1, 2, 3, 6, 7, 4 }, // 10011110
1710  { 0, 1, 2, 3, 4, 6, 7, 5 }, // 10011111
1711  { 2, 3, 4, 5, 6, 0, 7, 1 }, // 10100000
1712  { 0, 3, 4, 5, 6, 1, 7, 2 }, // 10100001
1713  { 3, 0, 4, 5, 6, 1, 7, 2 }, // 10100010
1714  { 0, 1, 4, 5, 6, 2, 7, 3 }, // 10100011
1715  { 3, 4, 0, 5, 6, 1, 7, 2 }, // 10100100
1716  { 0, 4, 1, 5, 6, 2, 7, 3 }, // 10100101
1717  { 4, 0, 1, 5, 6, 2, 7, 3 }, // 10100110
1718  { 0, 1, 2, 5, 6, 3, 7, 4 }, // 10100111
1719  { 3, 4, 5, 0, 6, 1, 7, 2 }, // 10101000
1720  { 0, 4, 5, 1, 6, 2, 7, 3 }, // 10101001
1721  { 4, 0, 5, 1, 6, 2, 7, 3 }, // 10101010
1722  { 0, 1, 5, 2, 6, 3, 7, 4 }, // 10101011
1723  { 4, 5, 0, 1, 6, 2, 7, 3 }, // 10101100
1724  { 0, 5, 1, 2, 6, 3, 7, 4 }, // 10101101
1725  { 5, 0, 1, 2, 6, 3, 7, 4 }, // 10101110
1726  { 0, 1, 2, 3, 6, 4, 7, 5 }, // 10101111
1727  { 3, 4, 5, 6, 0, 1, 7, 2 }, // 10110000
1728  { 0, 4, 5, 6, 1, 2, 7, 3 }, // 10110001
1729  { 4, 0, 5, 6, 1, 2, 7, 3 }, // 10110010
1730  { 0, 1, 5, 6, 2, 3, 7, 4 }, // 10110011
1731  { 4, 5, 0, 6, 1, 2, 7, 3 }, // 10110100
1732  { 0, 5, 1, 6, 2, 3, 7, 4 }, // 10110101
1733  { 5, 0, 1, 6, 2, 3, 7, 4 }, // 10110110
1734  { 0, 1, 2, 6, 3, 4, 7, 5 }, // 10110111
1735  { 4, 5, 6, 0, 1, 2, 7, 3 }, // 10111000
1736  { 0, 5, 6, 1, 2, 3, 7, 4 }, // 10111001
1737  { 5, 0, 6, 1, 2, 3, 7, 4 }, // 10111010
1738  { 0, 1, 6, 2, 3, 4, 7, 5 }, // 10111011
1739  { 5, 6, 0, 1, 2, 3, 7, 4 }, // 10111100
1740  { 0, 6, 1, 2, 3, 4, 7, 5 }, // 10111101
1741  { 6, 0, 1, 2, 3, 4, 7, 5 }, // 10111110
1742  { 0, 1, 2, 3, 4, 5, 7, 6 }, // 10111111
1743  { 2, 3, 4, 5, 6, 7, 0, 1 }, // 11000000
1744  { 0, 3, 4, 5, 6, 7, 1, 2 }, // 11000001
1745  { 3, 0, 4, 5, 6, 7, 1, 2 }, // 11000010
1746  { 0, 1, 4, 5, 6, 7, 2, 3 }, // 11000011
1747  { 3, 4, 0, 5, 6, 7, 1, 2 }, // 11000100
1748  { 0, 4, 1, 5, 6, 7, 2, 3 }, // 11000101
1749  { 4, 0, 1, 5, 6, 7, 2, 3 }, // 11000110
1750  { 0, 1, 2, 5, 6, 7, 3, 4 }, // 11000111
1751  { 3, 4, 5, 0, 6, 7, 1, 2 }, // 11001000
1752  { 0, 4, 5, 1, 6, 7, 2, 3 }, // 11001001
1753  { 4, 0, 5, 1, 6, 7, 2, 3 }, // 11001010
1754  { 0, 1, 5, 2, 6, 7, 3, 4 }, // 11001011
1755  { 4, 5, 0, 1, 6, 7, 2, 3 }, // 11001100
1756  { 0, 5, 1, 2, 6, 7, 3, 4 }, // 11001101
1757  { 5, 0, 1, 2, 6, 7, 3, 4 }, // 11001110
1758  { 0, 1, 2, 3, 6, 7, 4, 5 }, // 11001111
1759  { 3, 4, 5, 6, 0, 7, 1, 2 }, // 11010000
1760  { 0, 4, 5, 6, 1, 7, 2, 3 }, // 11010001
1761  { 4, 0, 5, 6, 1, 7, 2, 3 }, // 11010010
1762  { 0, 1, 5, 6, 2, 7, 3, 4 }, // 11010011
1763  { 4, 5, 0, 6, 1, 7, 2, 3 }, // 11010100
1764  { 0, 5, 1, 6, 2, 7, 3, 4 }, // 11010101
1765  { 5, 0, 1, 6, 2, 7, 3, 4 }, // 11010110
1766  { 0, 1, 2, 6, 3, 7, 4, 5 }, // 11010111
1767  { 4, 5, 6, 0, 1, 7, 2, 3 }, // 11011000
1768  { 0, 5, 6, 1, 2, 7, 3, 4 }, // 11011001
1769  { 5, 0, 6, 1, 2, 7, 3, 4 }, // 11011010
1770  { 0, 1, 6, 2, 3, 7, 4, 5 }, // 11011011
1771  { 5, 6, 0, 1, 2, 7, 3, 4 }, // 11011100
1772  { 0, 6, 1, 2, 3, 7, 4, 5 }, // 11011101
1773  { 6, 0, 1, 2, 3, 7, 4, 5 }, // 11011110
1774  { 0, 1, 2, 3, 4, 7, 5, 6 }, // 11011111
1775  { 3, 4, 5, 6, 7, 0, 1, 2 }, // 11100000
1776  { 0, 4, 5, 6, 7, 1, 2, 3 }, // 11100001
1777  { 4, 0, 5, 6, 7, 1, 2, 3 }, // 11100010
1778  { 0, 1, 5, 6, 7, 2, 3, 4 }, // 11100011
1779  { 4, 5, 0, 6, 7, 1, 2, 3 }, // 11100100
1780  { 0, 5, 1, 6, 7, 2, 3, 4 }, // 11100101
1781  { 5, 0, 1, 6, 7, 2, 3, 4 }, // 11100110
1782  { 0, 1, 2, 6, 7, 3, 4, 5 }, // 11100111
1783  { 4, 5, 6, 0, 7, 1, 2, 3 }, // 11101000
1784  { 0, 5, 6, 1, 7, 2, 3, 4 }, // 11101001
1785  { 5, 0, 6, 1, 7, 2, 3, 4 }, // 11101010
1786  { 0, 1, 6, 2, 7, 3, 4, 5 }, // 11101011
1787  { 5, 6, 0, 1, 7, 2, 3, 4 }, // 11101100
1788  { 0, 6, 1, 2, 7, 3, 4, 5 }, // 11101101
1789  { 6, 0, 1, 2, 7, 3, 4, 5 }, // 11101110
1790  { 0, 1, 2, 3, 7, 4, 5, 6 }, // 11101111
1791  { 4, 5, 6, 7, 0, 1, 2, 3 }, // 11110000
1792  { 0, 5, 6, 7, 1, 2, 3, 4 }, // 11110001
1793  { 5, 0, 6, 7, 1, 2, 3, 4 }, // 11110010
1794  { 0, 1, 6, 7, 2, 3, 4, 5 }, // 11110011
1795  { 5, 6, 0, 7, 1, 2, 3, 4 }, // 11110100
1796  { 0, 6, 1, 7, 2, 3, 4, 5 }, // 11110101
1797  { 6, 0, 1, 7, 2, 3, 4, 5 }, // 11110110
1798  { 0, 1, 2, 7, 3, 4, 5, 6 }, // 11110111
1799  { 5, 6, 7, 0, 1, 2, 3, 4 }, // 11111000
1800  { 0, 6, 7, 1, 2, 3, 4, 5 }, // 11111001
1801  { 6, 0, 7, 1, 2, 3, 4, 5 }, // 11111010
1802  { 0, 1, 7, 2, 3, 4, 5, 6 }, // 11111011
1803  { 6, 7, 0, 1, 2, 3, 4, 5 }, // 11111100
1804  { 0, 7, 1, 2, 3, 4, 5, 6 }, // 11111101
1805  { 7, 0, 1, 2, 3, 4, 5, 6 }, // 11111110
1806  { 0, 1, 2, 3, 4, 5, 6, 7 } // 11111111
1807  };
1808 
1809  assert( uPhase > 0 && uPhase < (unsigned)(1 << nVars) );
1810 
1811  // the same function
1812  if ( Cases[uPhase] == 0 )
1813  {
1814  int i;
1815  for ( i = 0; i < nWords; i++ )
1816  puTruthR[i] = puTruth[i];
1817  return;
1818  }
1819 
1820  // an elementary variable
1821  if ( Cases[uPhase] > 0 )
1822  {
1823  int i;
1824  for ( i = 0; i < nWords; i++ )
1825  puTruthR[i] = uTruths[(int)Cases[uPhase]][i];
1826  return;
1827  }
1828 
1829  // truth table takes one word
1830  if ( nWords == 1 )
1831  {
1832  int i, k, nMints, iRes;
1833  char * pPerm = Perms[uPhase];
1834  puTruthR[0] = 0;
1835  nMints = (1 << nVars);
1836  for ( i = 0; i < nMints; i++ )
1837  if ( puTruth[0] & (1 << i) )
1838  {
1839  for ( iRes = 0, k = 0; k < nVars; k++ )
1840  if ( i & (1 << pPerm[k]) )
1841  iRes |= (1 << k);
1842  puTruthR[0] |= (1 << iRes);
1843  }
1844  return;
1845  }
1846  else if ( nWords == 2 )
1847  {
1848  int i, k, iRes;
1849  char * pPerm = Perms[uPhase];
1850  puTruthR[0] = puTruthR[1] = 0;
1851  for ( i = 0; i < 32; i++ )
1852  {
1853  if ( puTruth[0] & (1 << i) )
1854  {
1855  for ( iRes = 0, k = 0; k < 6; k++ )
1856  if ( i & (1 << pPerm[k]) )
1857  iRes |= (1 << k);
1858  if ( iRes < 32 )
1859  puTruthR[0] |= (1 << iRes);
1860  else
1861  puTruthR[1] |= (1 << (iRes-32));
1862  }
1863  }
1864  for ( ; i < 64; i++ )
1865  {
1866  if ( puTruth[1] & (1 << (i-32)) )
1867  {
1868  for ( iRes = 0, k = 0; k < 6; k++ )
1869  if ( i & (1 << pPerm[k]) )
1870  iRes |= (1 << k);
1871  if ( iRes < 32 )
1872  puTruthR[0] |= (1 << iRes);
1873  else
1874  puTruthR[1] |= (1 << (iRes-32));
1875  }
1876  }
1877  }
1878  // truth table takes more than one word
1879  else
1880  {
1881  int i, k, nMints, iRes;
1882  char * pPerm = Perms[uPhase];
1883  for ( i = 0; i < nWords; i++ )
1884  puTruthR[i] = 0;
1885  nMints = (1 << nVars);
1886  for ( i = 0; i < nMints; i++ )
1887  if ( puTruth[i>>5] & (1 << (i&31)) )
1888  {
1889  for ( iRes = 0, k = 0; k < 5; k++ )
1890  if ( i & (1 << pPerm[k]) )
1891  iRes |= (1 << k);
1892  puTruthR[iRes>>5] |= (1 << (iRes&31));
1893  }
1894  }
1895 }
int nWords
Definition: abcNpn.c:127
static int pPerm[13719]
Definition: rwrTemp.c:32
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthFill ( unsigned *  pOut,
int  nVars 
)
inlinestatic

Definition at line 314 of file extra.h.

315 {
316  int w;
317  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
318  pOut[w] = ~(unsigned)0;
319 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
void Extra_TruthForall ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Existentially quantifies the variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 556 of file extraUtilTruth.c.

557 {
558  int nWords = Extra_TruthWordNum( nVars );
559  int i, k, Step;
560 
561  assert( iVar < nVars );
562  switch ( iVar )
563  {
564  case 0:
565  for ( i = 0; i < nWords; i++ )
566  pTruth[i] &= ((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1);
567  return;
568  case 1:
569  for ( i = 0; i < nWords; i++ )
570  pTruth[i] &= ((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2);
571  return;
572  case 2:
573  for ( i = 0; i < nWords; i++ )
574  pTruth[i] &= ((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4);
575  return;
576  case 3:
577  for ( i = 0; i < nWords; i++ )
578  pTruth[i] &= ((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8);
579  return;
580  case 4:
581  for ( i = 0; i < nWords; i++ )
582  pTruth[i] &= ((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16);
583  return;
584  default:
585  Step = (1 << (iVar - 5));
586  for ( k = 0; k < nWords; k += 2*Step )
587  {
588  for ( i = 0; i < Step; i++ )
589  {
590  pTruth[i] &= pTruth[Step+i];
591  pTruth[Step+i] = pTruth[i];
592  }
593  pTruth += 2*Step;
594  }
595  return;
596  }
597 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
static int Extra_TruthHasBit ( unsigned *  p,
int  Bit 
)
inlinestatic

Definition at line 253 of file extra.h.

253 { return (p[Bit>>5] & (1<<(Bit & 31))) > 0; }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned Extra_TruthHash ( unsigned *  pIn,
int  nWords 
)

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

Synopsis [Canonicize the truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 902 of file extraUtilTruth.c.

903 {
904  // The 1,024 smallest prime numbers used to compute the hash value
905  // http://www.math.utah.edu/~alfeld/math/primelist.html
906  static int HashPrimes[1024] = { 2, 3, 5,
907  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
908  101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191,
909  193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
910  293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401,
911  409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
912  521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631,
913  641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751,
914  757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877,
915  881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,
916  1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
917  1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193,
918  1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291,
919  1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423,
920  1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493,
921  1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601,
922  1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699,
923  1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811,
924  1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931,
925  1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029,
926  2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137,
927  2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267,
928  2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
929  2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459,
930  2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593,
931  2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693,
932  2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791,
933  2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903,
934  2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023,
935  3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167,
936  3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
937  3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373,
938  3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511,
939  3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607,
940  3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709,
941  3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833,
942  3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931,
943  3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057,
944  4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
945  4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283,
946  4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423,
947  4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547,
948  4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657,
949  4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789,
950  4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931,
951  4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011,
952  5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147,
953  5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279,
954  5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413,
955  5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507,
956  5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647,
957  5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743,
958  5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857,
959  5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007,
960  6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121,
961  6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247,
962  6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343,
963  6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473,
964  6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607,
965  6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733,
966  6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857,
967  6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971,
968  6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103,
969  7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229,
970  7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369,
971  7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517,
972  7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603,
973  7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723,
974  7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873,
975  7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009,
976  8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123,
977  8147, 8161 };
978  int i;
979  unsigned uHashKey;
980  assert( nWords <= 1024 );
981  uHashKey = 0;
982  for ( i = 0; i < nWords; i++ )
983  uHashKey ^= HashPrimes[i] * pIn[i];
984  return uHashKey;
985 }
int nWords
Definition: abcNpn.c:127
#define assert(ex)
Definition: util_old.h:213
static int Extra_TruthIsConst0 ( unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 278 of file extra.h.

279 {
280  int w;
281  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
282  if ( pIn[w] )
283  return 0;
284  return 1;
285 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_TruthIsConst1 ( unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 286 of file extra.h.

287 {
288  int w;
289  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
290  if ( pIn[w] != ~(unsigned)0 )
291  return 0;
292  return 1;
293 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_TruthIsEqual ( unsigned *  pIn0,
unsigned *  pIn1,
int  nVars 
)
inlinestatic

Definition at line 270 of file extra.h.

271 {
272  int w;
273  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
274  if ( pIn0[w] != pIn1[w] )
275  return 0;
276  return 1;
277 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static int Extra_TruthIsImply ( unsigned *  pIn1,
unsigned *  pIn2,
int  nVars 
)
inlinestatic

Definition at line 294 of file extra.h.

295 {
296  int w;
297  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
298  if ( pIn1[w] & ~pIn2[w] )
299  return 0;
300  return 1;
301 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
int Extra_TruthMinCofSuppOverlap ( unsigned *  pTruth,
int  nVars,
int *  pVarMin 
)

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

Synopsis [Computes minimum overlap in supports of cofactors.]

Description []

SideEffects []

SeeAlso []

Definition at line 775 of file extraUtilTruth.c.

776 {
777  static unsigned uCofactor[16];
778  int i, ValueCur, ValueMin, VarMin;
779  unsigned uSupp0, uSupp1;
780  int nVars0, nVars1;
781  assert( nVars <= 9 );
782  ValueMin = 32;
783  VarMin = -1;
784  for ( i = 0; i < nVars; i++ )
785  {
786  // get negative cofactor
787  Extra_TruthCopy( uCofactor, pTruth, nVars );
788  Extra_TruthCofactor0( uCofactor, nVars, i );
789  uSupp0 = Extra_TruthSupport( uCofactor, nVars );
790  nVars0 = Extra_WordCountOnes( uSupp0 );
791 //Extra_PrintBinary( stdout, &uSupp0, 8 ); printf( "\n" );
792  // get positive cofactor
793  Extra_TruthCopy( uCofactor, pTruth, nVars );
794  Extra_TruthCofactor1( uCofactor, nVars, i );
795  uSupp1 = Extra_TruthSupport( uCofactor, nVars );
796  nVars1 = Extra_WordCountOnes( uSupp1 );
797 //Extra_PrintBinary( stdout, &uSupp1, 8 ); printf( "\n" );
798  // get the number of common vars
799  ValueCur = Extra_WordCountOnes( uSupp0 & uSupp1 );
800  if ( ValueMin > ValueCur && nVars0 <= 5 && nVars1 <= 5 )
801  {
802  ValueMin = ValueCur;
803  VarMin = i;
804  }
805  if ( ValueMin == 0 )
806  break;
807  }
808  if ( pVarMin )
809  *pVarMin = VarMin;
810  return ValueMin;
811 }
void Extra_TruthCofactor1(unsigned *pTruth, int nVars, int iVar)
int Extra_TruthSupport(unsigned *pTruth, int nVars)
void Extra_TruthCofactor0(unsigned *pTruth, int nVars, int iVar)
static int Extra_WordCountOnes(unsigned uWord)
Definition: extra.h:255
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
void Extra_TruthMux ( unsigned *  pOut,
unsigned *  pCof0,
unsigned *  pCof1,
int  nVars,
int  iVar 
)

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

Synopsis [Computes negative cofactor of the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 611 of file extraUtilTruth.c.

612 {
613  int nWords = Extra_TruthWordNum( nVars );
614  int i, k, Step;
615 
616  assert( iVar < nVars );
617  switch ( iVar )
618  {
619  case 0:
620  for ( i = 0; i < nWords; i++ )
621  pOut[i] = (pCof0[i] & 0x55555555) | (pCof1[i] & 0xAAAAAAAA);
622  return;
623  case 1:
624  for ( i = 0; i < nWords; i++ )
625  pOut[i] = (pCof0[i] & 0x33333333) | (pCof1[i] & 0xCCCCCCCC);
626  return;
627  case 2:
628  for ( i = 0; i < nWords; i++ )
629  pOut[i] = (pCof0[i] & 0x0F0F0F0F) | (pCof1[i] & 0xF0F0F0F0);
630  return;
631  case 3:
632  for ( i = 0; i < nWords; i++ )
633  pOut[i] = (pCof0[i] & 0x00FF00FF) | (pCof1[i] & 0xFF00FF00);
634  return;
635  case 4:
636  for ( i = 0; i < nWords; i++ )
637  pOut[i] = (pCof0[i] & 0x0000FFFF) | (pCof1[i] & 0xFFFF0000);
638  return;
639  default:
640  Step = (1 << (iVar - 5));
641  for ( k = 0; k < nWords; k += 2*Step )
642  {
643  for ( i = 0; i < Step; i++ )
644  {
645  pOut[i] = pCof0[i];
646  pOut[Step+i] = pCof1[Step+i];
647  }
648  pOut += 2*Step;
649  }
650  return;
651  }
652 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthNand ( unsigned *  pOut,
unsigned *  pIn0,
unsigned *  pIn1,
int  nVars 
)
inlinestatic

Definition at line 344 of file extra.h.

345 {
346  int w;
347  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
348  pOut[w] = ~(pIn0[w] & pIn1[w]);
349 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static void Extra_TruthNot ( unsigned *  pOut,
unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 320 of file extra.h.

321 {
322  int w;
323  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
324  pOut[w] = ~pIn[w];
325 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
static void Extra_TruthOr ( unsigned *  pOut,
unsigned *  pIn0,
unsigned *  pIn1,
int  nVars 
)
inlinestatic

Definition at line 332 of file extra.h.

333 {
334  int w;
335  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
336  pOut[w] = pIn0[w] | pIn1[w];
337 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
unsigned short** Extra_TruthPerm43 ( )

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

Synopsis [Allocated lookup table for truth table permutation.]

Description []

SideEffects []

SeeAlso []

Definition at line 1908 of file extraUtilMisc.c.

1909 {
1910  unsigned short ** pTable;
1911  unsigned uTruth;
1912  int i, k;
1913  pTable = (unsigned short **)Extra_ArrayAlloc( 256, 16, 2 );
1914  for ( i = 0; i < 256; i++ )
1915  {
1916  uTruth = (i << 8) | i;
1917  for ( k = 0; k < 16; k++ )
1918  pTable[i][k] = Extra_TruthPerm4One( uTruth, k );
1919  }
1920  return pTable;
1921 }
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
unsigned short Extra_TruthPerm4One(unsigned uTruth, int Phase)
unsigned short Extra_TruthPerm4One ( unsigned  uTruth,
int  Phase 
)

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

Synopsis [Computes a phase of the 3-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 905 of file extraUtilMisc.c.

906 {
907  // cases
908  static unsigned short Cases[16] = {
909  0, // 0000 - skip
910  0, // 0001 - skip
911  0xCCCC, // 0010 - single var
912  0, // 0011 - skip
913  0xF0F0, // 0100 - single var
914  1, // 0101
915  1, // 0110
916  0, // 0111 - skip
917  0xFF00, // 1000 - single var
918  1, // 1001
919  1, // 1010
920  1, // 1011
921  1, // 1100
922  1, // 1101
923  1, // 1110
924  0 // 1111 - skip
925  };
926  // permutations
927  static int Perms[16][4] = {
928  { 0, 0, 0, 0 }, // 0000 - skip
929  { 0, 0, 0, 0 }, // 0001 - skip
930  { 0, 0, 0, 0 }, // 0010 - single var
931  { 0, 0, 0, 0 }, // 0011 - skip
932  { 0, 0, 0, 0 }, // 0100 - single var
933  { 0, 2, 1, 3 }, // 0101
934  { 2, 0, 1, 3 }, // 0110
935  { 0, 0, 0, 0 }, // 0111 - skip
936  { 0, 0, 0, 0 }, // 1000 - single var
937  { 0, 2, 3, 1 }, // 1001
938  { 2, 0, 3, 1 }, // 1010
939  { 0, 1, 3, 2 }, // 1011
940  { 2, 3, 0, 1 }, // 1100
941  { 0, 3, 1, 2 }, // 1101
942  { 3, 0, 1, 2 }, // 1110
943  { 0, 0, 0, 0 } // 1111 - skip
944  };
945  int i, k, iRes;
946  unsigned uTruthRes;
947  assert( Phase >= 0 && Phase < 16 );
948  if ( Cases[Phase] == 0 )
949  return uTruth;
950  if ( Cases[Phase] > 1 )
951  return Cases[Phase];
952  uTruthRes = 0;
953  for ( i = 0; i < 16; i++ )
954  if ( uTruth & (1 << i) )
955  {
956  for ( iRes = 0, k = 0; k < 4; k++ )
957  if ( i & (1 << Perms[Phase][k]) )
958  iRes |= (1 << k);
959  uTruthRes |= (1 << iRes);
960  }
961  return uTruthRes;
962 }
#define assert(ex)
Definition: util_old.h:213
unsigned** Extra_TruthPerm53 ( )

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

Synopsis [Allocated lookup table for truth table permutation.]

Description []

SideEffects []

SeeAlso []

Definition at line 1934 of file extraUtilMisc.c.

1935 {
1936  unsigned ** pTable;
1937  unsigned uTruth;
1938  int i, k;
1939  pTable = (unsigned **)Extra_ArrayAlloc( 256, 32, 4 );
1940  for ( i = 0; i < 256; i++ )
1941  {
1942  uTruth = (i << 24) | (i << 16) | (i << 8) | i;
1943  for ( k = 0; k < 32; k++ )
1944  pTable[i][k] = Extra_TruthPerm5One( uTruth, k );
1945  }
1946  return pTable;
1947 }
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
unsigned Extra_TruthPerm5One(unsigned uTruth, int Phase)
unsigned** Extra_TruthPerm54 ( )

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

Synopsis [Allocated lookup table for truth table permutation.]

Description []

SideEffects []

SeeAlso []

Definition at line 1960 of file extraUtilMisc.c.

1961 {
1962  unsigned ** pTable;
1963  unsigned uTruth;
1964  int i;
1965  pTable = (unsigned **)Extra_ArrayAlloc( 256*256, 4, 4 );
1966  for ( i = 0; i < 256*256; i++ )
1967  {
1968  uTruth = (i << 16) | i;
1969  pTable[i][0] = Extra_TruthPerm5One( uTruth, 31-8 );
1970  pTable[i][1] = Extra_TruthPerm5One( uTruth, 31-4 );
1971  pTable[i][2] = Extra_TruthPerm5One( uTruth, 31-2 );
1972  pTable[i][3] = Extra_TruthPerm5One( uTruth, 31-1 );
1973  }
1974  return pTable;
1975 }
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
unsigned Extra_TruthPerm5One(unsigned uTruth, int Phase)
unsigned Extra_TruthPerm5One ( unsigned  uTruth,
int  Phase 
)

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

Synopsis [Computes a phase of the 3-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 975 of file extraUtilMisc.c.

976 {
977  // cases
978  static unsigned Cases[32] = {
979  0, // 00000 - skip
980  0, // 00001 - skip
981  0xCCCCCCCC, // 00010 - single var
982  0, // 00011 - skip
983  0xF0F0F0F0, // 00100 - single var
984  1, // 00101
985  1, // 00110
986  0, // 00111 - skip
987  0xFF00FF00, // 01000 - single var
988  1, // 01001
989  1, // 01010
990  1, // 01011
991  1, // 01100
992  1, // 01101
993  1, // 01110
994  0, // 01111 - skip
995  0xFFFF0000, // 10000 - skip
996  1, // 10001
997  1, // 10010
998  1, // 10011
999  1, // 10100
1000  1, // 10101
1001  1, // 10110
1002  1, // 10111 - four var
1003  1, // 11000
1004  1, // 11001
1005  1, // 11010
1006  1, // 11011 - four var
1007  1, // 11100
1008  1, // 11101 - four var
1009  1, // 11110 - four var
1010  0 // 11111 - skip
1011  };
1012  // permutations
1013  static int Perms[32][5] = {
1014  { 0, 0, 0, 0, 0 }, // 00000 - skip
1015  { 0, 0, 0, 0, 0 }, // 00001 - skip
1016  { 0, 0, 0, 0, 0 }, // 00010 - single var
1017  { 0, 0, 0, 0, 0 }, // 00011 - skip
1018  { 0, 0, 0, 0, 0 }, // 00100 - single var
1019  { 0, 2, 1, 3, 4 }, // 00101
1020  { 2, 0, 1, 3, 4 }, // 00110
1021  { 0, 0, 0, 0, 0 }, // 00111 - skip
1022  { 0, 0, 0, 0, 0 }, // 01000 - single var
1023  { 0, 2, 3, 1, 4 }, // 01001
1024  { 2, 0, 3, 1, 4 }, // 01010
1025  { 0, 1, 3, 2, 4 }, // 01011
1026  { 2, 3, 0, 1, 4 }, // 01100
1027  { 0, 3, 1, 2, 4 }, // 01101
1028  { 3, 0, 1, 2, 4 }, // 01110
1029  { 0, 0, 0, 0, 0 }, // 01111 - skip
1030  { 0, 0, 0, 0, 0 }, // 10000 - single var
1031  { 0, 4, 2, 3, 1 }, // 10001
1032  { 4, 0, 2, 3, 1 }, // 10010
1033  { 0, 1, 3, 4, 2 }, // 10011
1034  { 2, 3, 0, 4, 1 }, // 10100
1035  { 0, 3, 1, 4, 2 }, // 10101
1036  { 3, 0, 1, 4, 2 }, // 10110
1037  { 0, 1, 2, 4, 3 }, // 10111 - four var
1038  { 2, 3, 4, 0, 1 }, // 11000
1039  { 0, 3, 4, 1, 2 }, // 11001
1040  { 3, 0, 4, 1, 2 }, // 11010
1041  { 0, 1, 4, 2, 3 }, // 11011 - four var
1042  { 3, 4, 0, 1, 2 }, // 11100
1043  { 0, 4, 1, 2, 3 }, // 11101 - four var
1044  { 4, 0, 1, 2, 3 }, // 11110 - four var
1045  { 0, 0, 0, 0, 0 } // 11111 - skip
1046  };
1047  int i, k, iRes;
1048  unsigned uTruthRes;
1049  assert( Phase >= 0 && Phase < 32 );
1050  if ( Cases[Phase] == 0 )
1051  return uTruth;
1052  if ( Cases[Phase] > 1 )
1053  return Cases[Phase];
1054  uTruthRes = 0;
1055  for ( i = 0; i < 32; i++ )
1056  if ( uTruth & (1 << i) )
1057  {
1058  for ( iRes = 0, k = 0; k < 5; k++ )
1059  if ( i & (1 << Perms[Phase][k]) )
1060  iRes |= (1 << k);
1061  uTruthRes |= (1 << iRes);
1062  }
1063  return uTruthRes;
1064 }
#define assert(ex)
Definition: util_old.h:213
void Extra_TruthPerm6One ( unsigned *  uTruth,
int  Phase,
unsigned *  uTruthRes 
)

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

Synopsis [Computes a phase of the 3-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 1077 of file extraUtilMisc.c.

1078 {
1079  // cases
1080  static unsigned Cases[64] = {
1081  0, // 000000 - skip
1082  0, // 000001 - skip
1083  0xCCCCCCCC, // 000010 - single var
1084  0, // 000011 - skip
1085  0xF0F0F0F0, // 000100 - single var
1086  1, // 000101
1087  1, // 000110
1088  0, // 000111 - skip
1089  0xFF00FF00, // 001000 - single var
1090  1, // 001001
1091  1, // 001010
1092  1, // 001011
1093  1, // 001100
1094  1, // 001101
1095  1, // 001110
1096  0, // 001111 - skip
1097  0xFFFF0000, // 010000 - skip
1098  1, // 010001
1099  1, // 010010
1100  1, // 010011
1101  1, // 010100
1102  1, // 010101
1103  1, // 010110
1104  1, // 010111 - four var
1105  1, // 011000
1106  1, // 011001
1107  1, // 011010
1108  1, // 011011 - four var
1109  1, // 011100
1110  1, // 011101 - four var
1111  1, // 011110 - four var
1112  0, // 011111 - skip
1113  0xFFFFFFFF, // 100000 - single var
1114  1, // 100001
1115  1, // 100010
1116  1, // 100011
1117  1, // 100100
1118  1, // 100101
1119  1, // 100110
1120  1, // 100111
1121  1, // 101000
1122  1, // 101001
1123  1, // 101010
1124  1, // 101011
1125  1, // 101100
1126  1, // 101101
1127  1, // 101110
1128  1, // 101111
1129  1, // 110000
1130  1, // 110001
1131  1, // 110010
1132  1, // 110011
1133  1, // 110100
1134  1, // 110101
1135  1, // 110110
1136  1, // 110111
1137  1, // 111000
1138  1, // 111001
1139  1, // 111010
1140  1, // 111011
1141  1, // 111100
1142  1, // 111101
1143  1, // 111110
1144  0 // 111111 - skip
1145  };
1146  // permutations
1147  static int Perms[64][6] = {
1148  { 0, 0, 0, 0, 0, 0 }, // 000000 - skip
1149  { 0, 0, 0, 0, 0, 0 }, // 000001 - skip
1150  { 0, 0, 0, 0, 0, 0 }, // 000010 - single var
1151  { 0, 0, 0, 0, 0, 0 }, // 000011 - skip
1152  { 0, 0, 0, 0, 0, 0 }, // 000100 - single var
1153  { 0, 2, 1, 3, 4, 5 }, // 000101
1154  { 2, 0, 1, 3, 4, 5 }, // 000110
1155  { 0, 0, 0, 0, 0, 0 }, // 000111 - skip
1156  { 0, 0, 0, 0, 0, 0 }, // 001000 - single var
1157  { 0, 2, 3, 1, 4, 5 }, // 001001
1158  { 2, 0, 3, 1, 4, 5 }, // 001010
1159  { 0, 1, 3, 2, 4, 5 }, // 001011
1160  { 2, 3, 0, 1, 4, 5 }, // 001100
1161  { 0, 3, 1, 2, 4, 5 }, // 001101
1162  { 3, 0, 1, 2, 4, 5 }, // 001110
1163  { 0, 0, 0, 0, 0, 0 }, // 001111 - skip
1164  { 0, 0, 0, 0, 0, 0 }, // 010000 - skip
1165  { 0, 4, 2, 3, 1, 5 }, // 010001
1166  { 4, 0, 2, 3, 1, 5 }, // 010010
1167  { 0, 1, 3, 4, 2, 5 }, // 010011
1168  { 2, 3, 0, 4, 1, 5 }, // 010100
1169  { 0, 3, 1, 4, 2, 5 }, // 010101
1170  { 3, 0, 1, 4, 2, 5 }, // 010110
1171  { 0, 1, 2, 4, 3, 5 }, // 010111 - four var
1172  { 2, 3, 4, 0, 1, 5 }, // 011000
1173  { 0, 3, 4, 1, 2, 5 }, // 011001
1174  { 3, 0, 4, 1, 2, 5 }, // 011010
1175  { 0, 1, 4, 2, 3, 5 }, // 011011 - four var
1176  { 3, 4, 0, 1, 2, 5 }, // 011100
1177  { 0, 4, 1, 2, 3, 5 }, // 011101 - four var
1178  { 4, 0, 1, 2, 3, 5 }, // 011110 - four var
1179  { 0, 0, 0, 0, 0, 0 }, // 011111 - skip
1180  { 0, 0, 0, 0, 0, 0 }, // 100000 - single var
1181  { 0, 2, 3, 4, 5, 1 }, // 100001
1182  { 2, 0, 3, 4, 5, 1 }, // 100010
1183  { 0, 1, 3, 4, 5, 2 }, // 100011
1184  { 2, 3, 0, 4, 5, 1 }, // 100100
1185  { 0, 3, 1, 4, 5, 2 }, // 100101
1186  { 3, 0, 1, 4, 5, 2 }, // 100110
1187  { 0, 1, 2, 4, 5, 3 }, // 100111
1188  { 2, 3, 4, 0, 5, 1 }, // 101000
1189  { 0, 3, 4, 1, 5, 2 }, // 101001
1190  { 3, 0, 4, 1, 5, 2 }, // 101010
1191  { 0, 1, 4, 2, 5, 3 }, // 101011
1192  { 3, 4, 0, 1, 5, 2 }, // 101100
1193  { 0, 4, 1, 2, 5, 3 }, // 101101
1194  { 4, 0, 1, 2, 5, 3 }, // 101110
1195  { 0, 1, 2, 3, 5, 4 }, // 101111
1196  { 2, 3, 4, 5, 0, 1 }, // 110000
1197  { 0, 3, 4, 5, 1, 2 }, // 110001
1198  { 3, 0, 4, 5, 1, 2 }, // 110010
1199  { 0, 1, 4, 5, 2, 3 }, // 110011
1200  { 3, 4, 0, 5, 1, 2 }, // 110100
1201  { 0, 4, 1, 5, 2, 3 }, // 110101
1202  { 4, 0, 1, 5, 2, 3 }, // 110110
1203  { 0, 1, 2, 5, 3, 4 }, // 110111
1204  { 3, 4, 5, 0, 1, 2 }, // 111000
1205  { 0, 4, 5, 1, 2, 3 }, // 111001
1206  { 4, 0, 5, 1, 2, 3 }, // 111010
1207  { 0, 1, 5, 2, 3, 4 }, // 111011
1208  { 4, 5, 0, 1, 2, 3 }, // 111100
1209  { 0, 5, 1, 2, 3, 4 }, // 111101
1210  { 5, 0, 1, 2, 3, 4 }, // 111110
1211  { 0, 0, 0, 0, 0, 0 } // 111111 - skip
1212  };
1213  int i, k, iRes;
1214  assert( Phase >= 0 && Phase < 64 );
1215  if ( Cases[Phase] == 0 )
1216  {
1217  uTruthRes[0] = uTruth[0];
1218  uTruthRes[1] = uTruth[1];
1219  return;
1220  }
1221  if ( Cases[Phase] > 1 )
1222  {
1223  if ( Phase == 32 )
1224  {
1225  uTruthRes[0] = 0x00000000;
1226  uTruthRes[1] = 0xFFFFFFFF;
1227  }
1228  else
1229  {
1230  uTruthRes[0] = Cases[Phase];
1231  uTruthRes[1] = Cases[Phase];
1232  }
1233  return;
1234  }
1235  uTruthRes[0] = 0;
1236  uTruthRes[1] = 0;
1237  for ( i = 0; i < 64; i++ )
1238  {
1239  if ( i < 32 )
1240  {
1241  if ( uTruth[0] & (1 << i) )
1242  {
1243  for ( iRes = 0, k = 0; k < 6; k++ )
1244  if ( i & (1 << Perms[Phase][k]) )
1245  iRes |= (1 << k);
1246  if ( iRes < 32 )
1247  uTruthRes[0] |= (1 << iRes);
1248  else
1249  uTruthRes[1] |= (1 << (iRes-32));
1250  }
1251  }
1252  else
1253  {
1254  if ( uTruth[1] & (1 << (i-32)) )
1255  {
1256  for ( iRes = 0, k = 0; k < 6; k++ )
1257  if ( i & (1 << Perms[Phase][k]) )
1258  iRes |= (1 << k);
1259  if ( iRes < 32 )
1260  uTruthRes[0] |= (1 << iRes);
1261  else
1262  uTruthRes[1] |= (1 << (iRes-32));
1263  }
1264  }
1265  }
1266 }
#define assert(ex)
Definition: util_old.h:213
unsigned Extra_TruthPermute ( unsigned  Truth,
char *  pPerms,
int  nVars,
int  fReverse 
)

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

Synopsis [Permutes the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 352 of file extraUtilMisc.c.

353 {
354  unsigned Result;
355  int * pMints;
356  int * pMintsP;
357  int nMints;
358  int i, m;
359 
360  assert( nVars < 6 );
361  nMints = (1 << nVars);
362  pMints = ABC_ALLOC( int, nMints );
363  pMintsP = ABC_ALLOC( int, nMints );
364  for ( i = 0; i < nMints; i++ )
365  pMints[i] = i;
366 
367  Extra_TruthPermute_int( pMints, nMints, pPerms, nVars, pMintsP );
368 
369  Result = 0;
370  if ( fReverse )
371  {
372  for ( m = 0; m < nMints; m++ )
373  if ( Truth & (1 << pMintsP[m]) )
374  Result |= (1 << m);
375  }
376  else
377  {
378  for ( m = 0; m < nMints; m++ )
379  if ( Truth & (1 << m) )
380  Result |= (1 << pMintsP[m]);
381  }
382 
383  ABC_FREE( pMints );
384  ABC_FREE( pMintsP );
385 
386  return Result;
387 }
void Extra_TruthPermute_int(int *pMints, int nMints, char *pPerm, int nVars, int *pMintsP)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
unsigned Extra_TruthPolarize ( unsigned  uTruth,
int  Polarity,
int  nVars 
)

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

Synopsis [Changes the phase of the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 400 of file extraUtilMisc.c.

401 {
402  // elementary truth tables
403  static unsigned Signs[5] = {
404  0xAAAAAAAA, // 1010 1010 1010 1010 1010 1010 1010 1010
405  0xCCCCCCCC, // 1010 1010 1010 1010 1010 1010 1010 1010
406  0xF0F0F0F0, // 1111 0000 1111 0000 1111 0000 1111 0000
407  0xFF00FF00, // 1111 1111 0000 0000 1111 1111 0000 0000
408  0xFFFF0000 // 1111 1111 1111 1111 0000 0000 0000 0000
409  };
410  unsigned uTruthRes, uCof0, uCof1;
411  int nMints, Shift, v;
412  assert( nVars < 6 );
413  nMints = (1 << nVars);
414  uTruthRes = uTruth;
415  for ( v = 0; v < nVars; v++ )
416  if ( Polarity & (1 << v) )
417  {
418  uCof0 = uTruth & ~Signs[v];
419  uCof1 = uTruth & Signs[v];
420  Shift = (1 << v);
421  uCof0 <<= Shift;
422  uCof1 >>= Shift;
423  uTruth = uCof0 | uCof1;
424  }
425  return uTruth;
426 }
#define assert(ex)
Definition: util_old.h:213
unsigned Extra_TruthSemiCanonicize ( unsigned *  pInOut,
unsigned *  pAux,
int  nVars,
char *  pCanonPerm,
short *  pStore 
)

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

Synopsis [Canonicize the truth table.]

Description [Returns the phase. ]

SideEffects []

SeeAlso []

Definition at line 999 of file extraUtilTruth.c.

1000 {
1001  unsigned * pIn = pInOut, * pOut = pAux, * pTemp;
1002  int nWords = Extra_TruthWordNum( nVars );
1003  int i, Temp, fChange, Counter, nOnes;//, k, j, w, Limit;
1004  unsigned uCanonPhase;
1005 
1006  // canonicize output
1007  uCanonPhase = 0;
1008  nOnes = Extra_TruthCountOnes(pIn, nVars);
1009  if ( (nOnes > nWords * 16) || ((nOnes == nWords * 16) && (pIn[0] & 1)) )
1010  {
1011  uCanonPhase |= (1 << nVars);
1012  Extra_TruthNot( pIn, pIn, nVars );
1013  }
1014 
1015  // collect the minterm counts
1016  Extra_TruthCountOnesInCofs( pIn, nVars, pStore );
1017 
1018  // canonicize phase
1019  for ( i = 0; i < nVars; i++ )
1020  {
1021  if ( pStore[2*i+0] <= pStore[2*i+1] )
1022  continue;
1023  uCanonPhase |= (1 << i);
1024  Temp = pStore[2*i+0];
1025  pStore[2*i+0] = pStore[2*i+1];
1026  pStore[2*i+1] = Temp;
1027  Extra_TruthChangePhase( pIn, nVars, i );
1028  }
1029 
1030 // Extra_PrintHexadecimal( stdout, pIn, nVars );
1031 // printf( "\n" );
1032 
1033  // permute
1034  Counter = 0;
1035  do {
1036  fChange = 0;
1037  for ( i = 0; i < nVars-1; i++ )
1038  {
1039  if ( pStore[2*i] <= pStore[2*(i+1)] )
1040  continue;
1041  Counter++;
1042  fChange = 1;
1043 
1044  Temp = pCanonPerm[i];
1045  pCanonPerm[i] = pCanonPerm[i+1];
1046  pCanonPerm[i+1] = Temp;
1047 
1048  Temp = pStore[2*i];
1049  pStore[2*i] = pStore[2*(i+1)];
1050  pStore[2*(i+1)] = Temp;
1051 
1052  Temp = pStore[2*i+1];
1053  pStore[2*i+1] = pStore[2*(i+1)+1];
1054  pStore[2*(i+1)+1] = Temp;
1055 
1056  Extra_TruthSwapAdjacentVars( pOut, pIn, nVars, i );
1057  pTemp = pIn; pIn = pOut; pOut = pTemp;
1058  }
1059  } while ( fChange );
1060 
1061 /*
1062  Extra_PrintBinary( stdout, &uCanonPhase, nVars+1 ); printf( " : " );
1063  for ( i = 0; i < nVars; i++ )
1064  printf( "%d=%d/%d ", pCanonPerm[i], pStore[2*i], pStore[2*i+1] );
1065  printf( " C = %d\n", Counter );
1066  Extra_PrintHexadecimal( stdout, pIn, nVars );
1067  printf( "\n" );
1068 */
1069 
1070 /*
1071  // process symmetric variable groups
1072  uSymms = 0;
1073  for ( i = 0; i < nVars-1; i++ )
1074  {
1075  if ( pStore[2*i] != pStore[2*(i+1)] ) // i and i+1 cannot be symmetric
1076  continue;
1077  if ( pStore[2*i] != pStore[2*i+1] )
1078  continue;
1079  if ( Extra_TruthVarsSymm( pIn, nVars, i, i+1 ) )
1080  continue;
1081  if ( Extra_TruthVarsAntiSymm( pIn, nVars, i, i+1 ) )
1082  Extra_TruthChangePhase( pIn, nVars, i+1 );
1083  }
1084 */
1085 
1086 /*
1087  // process symmetric variable groups
1088  uSymms = 0;
1089  for ( i = 0; i < nVars-1; i++ )
1090  {
1091  if ( pStore[2*i] != pStore[2*(i+1)] ) // i and i+1 cannot be symmetric
1092  continue;
1093  // i and i+1 can be symmetric
1094  // find the end of this group
1095  for ( k = i+1; k < nVars; k++ )
1096  if ( pStore[2*i] != pStore[2*k] )
1097  break;
1098  Limit = k;
1099  assert( i < Limit-1 );
1100  // go through the variables in this group
1101  for ( j = i + 1; j < Limit; j++ )
1102  {
1103  // check symmetry
1104  if ( Extra_TruthVarsSymm( pIn, nVars, i, j ) )
1105  {
1106  uSymms |= (1 << j);
1107  continue;
1108  }
1109  // they are phase-unknown
1110  if ( pStore[2*i] == pStore[2*i+1] )
1111  {
1112  if ( Extra_TruthVarsAntiSymm( pIn, nVars, i, j ) )
1113  {
1114  Extra_TruthChangePhase( pIn, nVars, j );
1115  uCanonPhase ^= (1 << j);
1116  uSymms |= (1 << j);
1117  continue;
1118  }
1119  }
1120 
1121  // they are not symmetric - move j as far as it goes in the group
1122  for ( k = j; k < Limit-1; k++ )
1123  {
1124  Counter++;
1125 
1126  Temp = pCanonPerm[k];
1127  pCanonPerm[k] = pCanonPerm[k+1];
1128  pCanonPerm[k+1] = Temp;
1129 
1130  assert( pStore[2*k] == pStore[2*(k+1)] );
1131  Extra_TruthSwapAdjacentVars( pOut, pIn, nVars, k );
1132  pTemp = pIn; pIn = pOut; pOut = pTemp;
1133  }
1134  Limit--;
1135  j--;
1136  }
1137  i = Limit - 1;
1138  }
1139 */
1140 
1141  // swap if it was moved an even number of times
1142  if ( Counter & 1 )
1143  Extra_TruthCopy( pOut, pIn, nVars );
1144  return uCanonPhase;
1145 }
void Extra_TruthSwapAdjacentVars(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
int nWords
Definition: abcNpn.c:127
static int Extra_TruthCountOnes(unsigned *pIn, int nVars)
Definition: extra.h:263
static int Counter
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
void Extra_TruthCountOnesInCofs(unsigned *pTruth, int nVars, short *pStore)
static void Extra_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:320
void Extra_TruthChangePhase(unsigned *pTruth, int nVars, int iVar)
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
static void Extra_TruthSetBit ( unsigned *  p,
int  Bit 
)
inlinestatic

Definition at line 251 of file extra.h.

251 { p[Bit>>5] |= (1<<(Bit & 31)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Extra_TruthSharp ( unsigned *  pOut,
unsigned *  pIn0,
unsigned *  pIn1,
int  nVars 
)
inlinestatic

Definition at line 338 of file extra.h.

339 {
340  int w;
341  for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
342  pOut[w] = pIn0[w] & ~pIn1[w];
343 }
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
void Extra_TruthShrink ( unsigned *  pOut,
unsigned *  pIn,
int  nVars,
int  nVarsAll,
unsigned  Phase 
)

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

Synopsis [Shrinks the truth table according to the phase.]

Description [The input and output truth tables are in pIn/pOut. The current number of variables is nVars. The total number of variables in nVarsAll. The last argument (Phase) contains shows what variables should remain.]

SideEffects []

SeeAlso []

Definition at line 268 of file extraUtilTruth.c.

269 {
270  unsigned * pTemp;
271  int i, k, Var = 0, Counter = 0;
272  for ( i = 0; i < nVarsAll; i++ )
273  if ( Phase & (1 << i) )
274  {
275  for ( k = i-1; k >= Var; k-- )
276  {
277  Extra_TruthSwapAdjacentVars( pOut, pIn, nVarsAll, k );
278  pTemp = pIn; pIn = pOut; pOut = pTemp;
279  Counter++;
280  }
281  Var++;
282  }
283  assert( Var == nVars );
284  // swap if it was moved an even number of times
285  if ( !(Counter & 1) )
286  Extra_TruthCopy( pOut, pIn, nVarsAll );
287 }
void Extra_TruthSwapAdjacentVars(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
static int Counter
int Var
Definition: SolverTypes.h:42
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
void Extra_TruthStretch ( unsigned *  pOut,
unsigned *  pIn,
int  nVars,
int  nVarsAll,
unsigned  Phase 
)

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

Synopsis [Expands the truth table according to the phase.]

Description [The input and output truth tables are in pIn/pOut. The current number of variables is nVars. The total number of variables in nVarsAll. The last argument (Phase) contains shows where the variables should go.]

SideEffects []

SeeAlso []

Definition at line 234 of file extraUtilTruth.c.

235 {
236  unsigned * pTemp;
237  int i, k, Var = nVars - 1, Counter = 0;
238  for ( i = nVarsAll - 1; i >= 0; i-- )
239  if ( Phase & (1 << i) )
240  {
241  for ( k = Var; k < i; k++ )
242  {
243  Extra_TruthSwapAdjacentVars( pOut, pIn, nVarsAll, k );
244  pTemp = pIn; pIn = pOut; pOut = pTemp;
245  Counter++;
246  }
247  Var--;
248  }
249  assert( Var == -1 );
250  // swap if it was moved an even number of times
251  if ( !(Counter & 1) )
252  Extra_TruthCopy( pOut, pIn, nVarsAll );
253 }
void Extra_TruthSwapAdjacentVars(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
static int Counter
int Var
Definition: SolverTypes.h:42
#define assert(ex)
Definition: util_old.h:213
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
int Extra_TruthSupport ( unsigned *  pTruth,
int  nVars 
)

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

Synopsis [Returns support of the function.]

Description []

SideEffects []

SeeAlso []

Definition at line 377 of file extraUtilTruth.c.

378 {
379  int i, Support = 0;
380  for ( i = 0; i < nVars; i++ )
381  if ( Extra_TruthVarInSupport( pTruth, nVars, i ) )
382  Support |= (1 << i);
383  return Support;
384 }
int Extra_TruthVarInSupport(unsigned *pTruth, int nVars, int iVar)
int Extra_TruthSupportSize ( unsigned *  pTruth,
int  nVars 
)

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

Synopsis [Returns the number of support vars.]

Description []

SideEffects []

SeeAlso []

Definition at line 358 of file extraUtilTruth.c.

359 {
360  int i, Counter = 0;
361  for ( i = 0; i < nVars; i++ )
362  Counter += Extra_TruthVarInSupport( pTruth, nVars, i );
363  return Counter;
364 }
static int Counter
int Extra_TruthVarInSupport(unsigned *pTruth, int nVars, int iVar)
void Extra_TruthSwapAdjacentVars ( unsigned *  pOut,
unsigned *  pIn,
int  nVars,
int  iVar 
)

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

Synopsis [Swaps two adjacent variables in the truth table.]

Description [Swaps var number Start and var number Start+1 (0-based numbers). The input truth table is pIn. The output truth table is pOut.]

SideEffects []

SeeAlso []

Definition at line 114 of file extraUtilTruth.c.

115 {
116  static unsigned PMasks[4][3] = {
117  { 0x99999999, 0x22222222, 0x44444444 },
118  { 0xC3C3C3C3, 0x0C0C0C0C, 0x30303030 },
119  { 0xF00FF00F, 0x00F000F0, 0x0F000F00 },
120  { 0xFF0000FF, 0x0000FF00, 0x00FF0000 }
121  };
122  int nWords = Extra_TruthWordNum( nVars );
123  int i, k, Step, Shift;
124 
125  assert( iVar < nVars - 1 );
126  if ( iVar < 4 )
127  {
128  Shift = (1 << iVar);
129  for ( i = 0; i < nWords; i++ )
130  pOut[i] = (pIn[i] & PMasks[iVar][0]) | ((pIn[i] & PMasks[iVar][1]) << Shift) | ((pIn[i] & PMasks[iVar][2]) >> Shift);
131  }
132  else if ( iVar > 4 )
133  {
134  Step = (1 << (iVar - 5));
135  for ( k = 0; k < nWords; k += 4*Step )
136  {
137  for ( i = 0; i < Step; i++ )
138  pOut[i] = pIn[i];
139  for ( i = 0; i < Step; i++ )
140  pOut[Step+i] = pIn[2*Step+i];
141  for ( i = 0; i < Step; i++ )
142  pOut[2*Step+i] = pIn[Step+i];
143  for ( i = 0; i < Step; i++ )
144  pOut[3*Step+i] = pIn[3*Step+i];
145  pIn += 4*Step;
146  pOut += 4*Step;
147  }
148  }
149  else // if ( iVar == 4 )
150  {
151  for ( i = 0; i < nWords; i += 2 )
152  {
153  pOut[i] = (pIn[i] & 0x0000FFFF) | ((pIn[i+1] & 0x0000FFFF) << 16);
154  pOut[i+1] = (pIn[i+1] & 0xFFFF0000) | ((pIn[i] & 0xFFFF0000) >> 16);
155  }
156  }
157 }
int nWords
Definition: abcNpn.c:127
static word PMasks[5][3]
Definition: ifDec07.c:44
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
int Extra_TruthVarInSupport ( unsigned *  pTruth,
int  nVars,
int  iVar 
)

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

Synopsis [Returns 1 if TT depends on the given variable.]

Description []

SideEffects []

SeeAlso []

Definition at line 301 of file extraUtilTruth.c.

302 {
303  int nWords = Extra_TruthWordNum( nVars );
304  int i, k, Step;
305 
306  assert( iVar < nVars );
307  switch ( iVar )
308  {
309  case 0:
310  for ( i = 0; i < nWords; i++ )
311  if ( (pTruth[i] & 0x55555555) != ((pTruth[i] & 0xAAAAAAAA) >> 1) )
312  return 1;
313  return 0;
314  case 1:
315  for ( i = 0; i < nWords; i++ )
316  if ( (pTruth[i] & 0x33333333) != ((pTruth[i] & 0xCCCCCCCC) >> 2) )
317  return 1;
318  return 0;
319  case 2:
320  for ( i = 0; i < nWords; i++ )
321  if ( (pTruth[i] & 0x0F0F0F0F) != ((pTruth[i] & 0xF0F0F0F0) >> 4) )
322  return 1;
323  return 0;
324  case 3:
325  for ( i = 0; i < nWords; i++ )
326  if ( (pTruth[i] & 0x00FF00FF) != ((pTruth[i] & 0xFF00FF00) >> 8) )
327  return 1;
328  return 0;
329  case 4:
330  for ( i = 0; i < nWords; i++ )
331  if ( (pTruth[i] & 0x0000FFFF) != ((pTruth[i] & 0xFFFF0000) >> 16) )
332  return 1;
333  return 0;
334  default:
335  Step = (1 << (iVar - 5));
336  for ( k = 0; k < nWords; k += 2*Step )
337  {
338  for ( i = 0; i < Step; i++ )
339  if ( pTruth[i] != pTruth[Step+i] )
340  return 1;
341  pTruth += 2*Step;
342  }
343  return 0;
344  }
345 }
int nWords
Definition: abcNpn.c:127
static int Extra_TruthWordNum(int nVars)
Definition: extra.h:249
#define assert(ex)
Definition: util_old.h:213
static int Extra_TruthWordNum ( int  nVars)
inlinestatic

Definition at line 249 of file extra.h.

249 { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
static void Extra_TruthXorBit ( unsigned *  p,
int  Bit 
)
inlinestatic

Definition at line 252 of file extra.h.

252 { p[Bit>>5] ^= (1<<(Bit & 31)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char* Extra_UtilFileSearch ( char *  file,
char *  path,
char *  mode 
)

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

Synopsis [util_file_search()]

Description []

SideEffects []

SeeAlso []

Definition at line 259 of file extraUtilUtil.c.

263 {
264  int quit;
265  char *buffer, *filename, *save_path, *cp;
266 
267  if (path == 0 || strcmp(path, "") == 0) {
268  path = "."; /* just look in the current directory */
269  }
270 
271  save_path = path = Extra_UtilStrsav(path);
272  quit = 0;
273  do {
274  cp = strchr(path, ':');
275  if (cp != 0) {
276  *cp = '\0';
277  } else {
278  quit = 1;
279  }
280 
281  /* cons up the filename out of the path and file name */
282  if (strcmp(path, ".") == 0) {
283  buffer = Extra_UtilStrsav(file);
284  } else {
285  buffer = ABC_ALLOC(char, strlen(path) + strlen(file) + 4);
286  (void) sprintf(buffer, "%s/%s", path, file);
287  }
288  filename = Extra_UtilTildeExpand(buffer);
289  ABC_FREE(buffer);
290 
291  /* see if we can access it */
292  if (Extra_UtilCheckFile(filename, mode)) {
293  ABC_FREE(save_path);
294  return filename;
295  }
296  ABC_FREE(filename);
297  path = ++cp;
298  } while (! quit);
299 
300  ABC_FREE(save_path);
301  return 0;
302 }
char * filename
Definition: globals.c:40
char * Extra_UtilTildeExpand(char *fname)
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_UtilStrsav(const char *s)
int strcmp()
char * strchr()
char * sprintf()
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Extra_UtilCheckFile(char *filename, const char *mode)
int strlen()
int Extra_UtilGetopt ( int  argc,
char *  argv[],
const char *  optstring 
)

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

Synopsis [util_getopt()]

Description []

SideEffects []

SeeAlso []

Definition at line 98 of file extraUtilUtil.c.

99 {
100  register int c;
101  register const char *place;
102 
103  globalUtilOptarg = NULL;
104 
105  if (pScanStr == NULL || *pScanStr == '\0') {
107  if (globalUtilOptind >= argc) return EOF;
108  place = argv[globalUtilOptind];
109  if (place[0] != '-' || place[1] == '\0') return EOF;
111  if (place[1] == '-' && place[2] == '\0') return EOF;
112  pScanStr = place+1;
113  }
114 
115  c = *pScanStr++;
116  place = strchr(optstring, c);
117  if (place == NULL || c == ':') {
118  (void) fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
119  return '?';
120  }
121  if (*++place == ':') {
122  if (*pScanStr != '\0') {
124  pScanStr = NULL;
125  } else {
126  if (globalUtilOptind >= argc) {
127  (void) fprintf(stderr, "%s: %c requires an argument\n",
128  argv[0], c);
129  return '?';
130  }
133  }
134  }
135  return c;
136 }
const char * globalUtilOptarg
Definition: extraUtilUtil.c:44
int globalUtilOptind
Definition: extraUtilUtil.c:45
char * strchr()
static const char * pScanStr
Definition: extraUtilUtil.c:47
ABC_DLL void Extra_UtilGetoptReset ( )

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

Synopsis [util_getopt_reset()]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file extraUtilUtil.c.

81 {
82  globalUtilOptarg = 0;
83  globalUtilOptind = 0;
84  pScanStr = 0;
85 }
const char * globalUtilOptarg
Definition: extraUtilUtil.c:44
int globalUtilOptind
Definition: extraUtilUtil.c:45
static const char * pScanStr
Definition: extraUtilUtil.c:47
char* Extra_UtilPrintTime ( long  t)

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

Synopsis [util_print_time()]

Description []

SideEffects []

SeeAlso []

Definition at line 149 of file extraUtilUtil.c.

150 {
151  static char s[40];
152 
153  (void) sprintf(s, "%ld.%02ld sec", t/1000, (t%1000)/10);
154  return s;
155 }
char * sprintf()
char* Extra_UtilStrsav ( const char *  s)

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

Synopsis [Extra_UtilStrsav()]

Description []

SideEffects []

SeeAlso []

Definition at line 169 of file extraUtilUtil.c.

170 {
171  if(s == NULL) { /* added 7/95, for robustness */
172  return NULL;
173  }
174  else {
175  return strcpy(ABC_ALLOC(char, strlen(s)+1), s);
176  }
177 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * strcpy()
int strlen()
char* Extra_UtilTildeExpand ( char *  fname)

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

Synopsis [util_tilde_expand()]

Description [The code contributed by Niklas Sorensson.]

SideEffects []

SeeAlso []

Definition at line 190 of file extraUtilUtil.c.

191 {
192  return Extra_UtilStrsav( fname );
193 /*
194  int n_tildes = 0;
195  const char* home;
196  char* expanded;
197  int length;
198  int i, j, k;
199 
200  for (i = 0; i < (int)strlen(fname); i++)
201  if (fname[i] == '~') n_tildes++;
202 
203  home = getenv("HOME");
204  length = n_tildes * strlen(home) + strlen(fname);
205  expanded = ABC_ALLOC(char, length + 1);
206 
207  j = 0;
208  for (i = 0; i < (int)strlen(fname); i++){
209  if (fname[i] == '~'){
210  for (k = 0; k < (int)strlen(home); k++)
211  expanded[j++] = home[k];
212  }else
213  expanded[j++] = fname[i];
214  }
215 
216  expanded[j] = '\0';
217  return expanded;
218 */
219 }
char * Extra_UtilStrsav(const char *s)
static int Extra_WordCountOnes ( unsigned  uWord)
inlinestatic

Definition at line 255 of file extra.h.

256 {
257  uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
258  uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
259  uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
260  uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
261  return (uWord & 0x0000FFFF) + (uWord>>16);
262 }
int Sdm_ManCanRead ( )

Definition at line 1080 of file extraUtilDsd.c.

1081 {
1082  char * pFileName = "dsdfuncs6.dat";
1083  FILE * pFile = fopen( pFileName, "rb" );
1084  if ( pFile == NULL )
1085  return 0;
1086  fclose( pFile );
1087  return 1;
1088 }
int Sdm_ManComputeFunc ( Sdm_Man_t p,
int  iDsdLit0,
int  iDsdLit1,
int *  pCut,
int  uMask,
int  fXor 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 920 of file extraUtilDsd.c.

921 {
922 // int fVerbose = 0;
923  int i, Config, iClass, fCompl, Res;
924  int PermMask = uMask & 0x3FFFF;
925  int ComplMask = uMask >> 18;
926  word Truth0, Truth1p, t0, t1, t;
927  p->nAllDsd++;
928 
929  assert( uMask > 1 );
930  assert( iDsdLit0 < DSD_CLASS_NUM * 2 );
931  assert( iDsdLit1 < DSD_CLASS_NUM * 2 );
932  Truth0 = p->pDsd6[Abc_Lit2Var(iDsdLit0)].uTruth;
933  Truth1p = Vec_WrdEntry( p->vPerm6, Abc_Lit2Var(iDsdLit1) * 720 + Vec_IntEntry(p->vMap2Perm, PermMask ) );
934  if ( ComplMask )
935  for ( i = 0; i < 6; i++ )
936  if ( (ComplMask >> i) & 1 )
937  Truth1p = Abc_Tt6Flip( Truth1p, i );
938  t0 = Abc_LitIsCompl(iDsdLit0) ? ~Truth0 : Truth0;
939  t1 = Abc_LitIsCompl(iDsdLit1) ? ~Truth1p : Truth1p;
940  t = fXor ? t0 ^ t1 : t0 & t1;
941 /*
942 if ( fVerbose )
943 {
944 Sdm_ManPrintPerm( PermMask ); printf( "\n" );
945 Extra_PrintBinary( stdout, &ComplMask, 6 ); printf( "\n" );
946 Kit_DsdPrintFromTruth( (unsigned *)&Truth0, 6 ); printf( "\n" );
947 Kit_DsdPrintFromTruth( (unsigned *)&Truth1p, 6 ); printf( "\n" );
948 Kit_DsdPrintFromTruth( (unsigned *)&t, 6 ); printf( "\n" );
949 }
950 */
951  // find configuration
952  Config = Sdm_ManCheckDsd6( p, t );
953  if ( Config == -1 )
954  {
955  p->nNonDsd++;
956  return -1;
957  }
958 
959  // get the class
960  iClass = Config >> 17;
961  fCompl = (Config >> 16) & 1;
962  Config &= 0xFFFF;
963 
964  // set the function
965  Res = Abc_Var2Lit( iClass, fCompl );
966 
967  // update cut
968  assert( (Config >> 6) < 720 );
969  if ( pCut )
970  {
971  int pLeavesNew[6] = { -1, -1, -1, -1, -1, -1 };
972  assert( pCut[0] <= 6 );
973  for ( i = 0; i < pCut[0]; i++ )
974  pLeavesNew[(int)(p->Perm6[Config >> 6][i])] = Abc_LitNotCond( pCut[i+1], (Config >> i) & 1 );
975  pCut[0] = p->pDsd6[iClass].nVars;
976  for ( i = 0; i < pCut[0]; i++ )
977  assert( pLeavesNew[i] != -1 );
978  for ( i = 0; i < pCut[0]; i++ )
979  pCut[i+1] = pLeavesNew[i];
980  }
981  assert( iClass < DSD_CLASS_NUM );
982  p->nCountDsd[iClass]++;
983  return Res;
984 }
Vec_Int_t * vMap2Perm
Definition: extraUtilDsd.c:654
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Vec_Wrd_t * vPerm6
Definition: extraUtilDsd.c:653
#define DSD_CLASS_NUM
Definition: extraUtilDsd.c:48
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
int Sdm_ManCheckDsd6(Sdm_Man_t *p, word t)
Definition: extraUtilDsd.c:895
int nCountDsd[DSD_CLASS_NUM]
Definition: extraUtilDsd.c:656
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
char Perm6[720][6]
Definition: extraUtilDsd.c:655
static word Abc_Tt6Flip(word Truth, int iVar)
Definition: utilTruth.h:1126
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define assert(ex)
Definition: util_old.h:213
void Sdm_ManPrintDsdStats ( Sdm_Man_t p,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 676 of file extraUtilDsd.c.

677 {
678  int i, Absent = 0;
679  for ( i = 0; i < DSD_CLASS_NUM; i++ )
680  {
681  if ( p->nCountDsd[i] == 0 )
682  {
683  Absent++;
684  continue;
685  }
686  if ( fVerbose )
687  {
688  printf( "%5d : ", i );
689  printf( "%-20s ", p->pDsd6[i].pStr );
690  printf( "%8d ", p->nCountDsd[i] );
691  printf( "\n" );
692  }
693  }
694  printf( "Unused classes = %d (%.2f %%). ", Absent, 100.0 * Absent / DSD_CLASS_NUM );
695  printf( "Non-DSD cuts = %d (%.2f %%). ", p->nNonDsd, 100.0 * p->nNonDsd / Abc_MaxInt(1, p->nAllDsd) );
696  printf( "\n" );
697 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
#define DSD_CLASS_NUM
Definition: extraUtilDsd.c:48
int nCountDsd[DSD_CLASS_NUM]
Definition: extraUtilDsd.c:656
void Sdm_ManQuit ( )

Definition at line 1074 of file extraUtilDsd.c.

1075 {
1076  if ( s_SdmMan != NULL )
1077  Sdm_ManFree( s_SdmMan );
1078  s_SdmMan = NULL;
1079 }
void Sdm_ManFree(Sdm_Man_t *p)
static Sdm_Man_t * s_SdmMan
Sdm_Man_t* Sdm_ManRead ( )

Definition at line 1067 of file extraUtilDsd.c.

1068 {
1069  if ( s_SdmMan == NULL )
1070  s_SdmMan = Sdm_ManAlloc();
1071  memset( s_SdmMan->nCountDsd, 0, sizeof(int) * DSD_CLASS_NUM );
1072  return s_SdmMan;
1073 }
char * memset()
Sdm_Man_t * Sdm_ManAlloc()
#define DSD_CLASS_NUM
Definition: extraUtilDsd.c:48
int nCountDsd[DSD_CLASS_NUM]
Definition: extraUtilDsd.c:656
static Sdm_Man_t * s_SdmMan
void Sdm_ManReadCnfCosts ( Sdm_Man_t p,
int *  pCosts,
int  nCosts 
)

Definition at line 1017 of file extraUtilDsd.c.

1018 {
1019  int i;
1020  assert( nCosts == DSD_CLASS_NUM );
1021  pCosts[0] = pCosts[1] = 0;
1022  for ( i = 2; i < DSD_CLASS_NUM; i++ )
1023  pCosts[i] = Sdm_ManReadDsdClauseNum( p, i );
1024 }
int Sdm_ManReadDsdClauseNum(Sdm_Man_t *p, int iDsd)
#define DSD_CLASS_NUM
Definition: extraUtilDsd.c:48
#define assert(ex)
Definition: util_old.h:213
int Sdm_ManReadDsdAndNum ( Sdm_Man_t p,
int  iDsd 
)

Definition at line 1001 of file extraUtilDsd.c.

1002 {
1003  return p->pDsd6[iDsd].nAnds;
1004 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
int Sdm_ManReadDsdClauseNum ( Sdm_Man_t p,
int  iDsd 
)

Definition at line 1005 of file extraUtilDsd.c.

1006 {
1007  return p->pDsd6[iDsd].nClauses;
1008 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
char* Sdm_ManReadDsdStr ( Sdm_Man_t p,
int  iDsd 
)

Definition at line 1013 of file extraUtilDsd.c.

1014 {
1015  return p->pDsd6[iDsd].pStr;
1016 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
word Sdm_ManReadDsdTruth ( Sdm_Man_t p,
int  iDsd 
)

Definition at line 1009 of file extraUtilDsd.c.

1010 {
1011  return p->pDsd6[iDsd].uTruth;
1012 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650
int Sdm_ManReadDsdVarNum ( Sdm_Man_t p,
int  iDsd 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 997 of file extraUtilDsd.c.

998 {
999  return p->pDsd6[iDsd].nVars;
1000 }
Sdm_Dsd_t * pDsd6
Definition: extraUtilDsd.c:650

Variable Documentation

void(* Extra_UtilMMoutOfMemory)(long size)

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

Synopsis [MMoutOfMemory()]

Description []

SideEffects []

SeeAlso []

Definition at line 336 of file extraUtilUtil.c.

const char* globalUtilOptarg

Definition at line 44 of file extraUtilUtil.c.

int globalUtilOptind

Definition at line 45 of file extraUtilUtil.c.

ABC_NAMESPACE_HEADER_START typedef unsigned char uint8

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

FileName [extra.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Various reusable software utilities.]

Description [This library contains a number of operators and traversal routines developed to extend the functionality of CUDD v.2.3.x, by Fabio Somenzi (http://vlsi.colorado.edu/~fabio/) To compile your code with the library, #include "extra.h" in your source files and link your project to CUDD and this library. Use the library at your own risk and with caution. Note that debugging of some operators still continues.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
extra.h,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 71 of file extra.h.