abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fraigInt.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/util/abc_global.h"
#include "fraig.h"
#include "sat/msat/msat.h"

Go to the source code of this file.

Data Structures

struct  Fraig_ManStruct_t_
 
struct  Fraig_NodeStruct_t_
 
struct  Fraig_NodeVecStruct_t_
 
struct  Fraig_HashTableStruct_t_
 

Macros

#define FRAIG_ENABLE_FANOUTS
 INCLUDES ///. More...
 
#define FRAIG_PATTERNS_RANDOM   2048
 
#define FRAIG_PATTERNS_DYNAMIC   2048
 
#define FRAIG_MAX_PRIMES   1024
 
#define FRAIG_WORDS_STORE   5
 
#define FRAIG_MASK(n)   ((~((unsigned)0)) >> (32-(n)))
 
#define FRAIG_FULL   (~((unsigned)0))
 
#define FRAIG_NUM_WORDS(n)   (((n)>>5) + (((n)&31) > 0))
 
#define FRAIG_RANDOM_UNSIGNED   Aig_ManRandom(0)
 
#define Fraig_BitStringSetBit(p, i)   ((p)[(i)>>5] |= (1<<((i) & 31)))
 
#define Fraig_BitStringXorBit(p, i)   ((p)[(i)>>5] ^= (1<<((i) & 31)))
 
#define Fraig_BitStringHasBit(p, i)   (((p)[(i)>>5] & (1<<((i) & 31))) > 0)
 
#define Fraig_NodeSetVarStr(p, i)   Fraig_BitStringSetBit(Fraig_Regular(p)->pSuppStr,i)
 
#define Fraig_NodeHasVarStr(p, i)   Fraig_BitStringHasBit(Fraig_Regular(p)->pSuppStr,i)
 
#define Fraig_PrintTime(a, t)   printf( "%s = ", (a) ); printf( "%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC) )
 
#define Fraig_HashKey2(a, b, TSIZE)   (((ABC_PTRUINT_T)(a) + (ABC_PTRUINT_T)(b) * 12582917) % TSIZE)
 
#define Fraig_NodeReadNextFanout(pNode, pFanout)
 
#define Fraig_NodeReadNextFanoutPlace(pNode, pFanout)
 
#define Fraig_NodeForEachFanout(pNode, pFanout)
 
#define Fraig_NodeForEachFanoutSafe(pNode, pFanout, pFanout2)
 
#define Fraig_TableBinForEachEntryS(pBin, pEnt)
 
#define Fraig_TableBinForEachEntrySafeS(pBin, pEnt, pEnt2)
 
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
 
#define Fraig_TableBinForEachEntrySafeF(pBin, pEnt, pEnt2)
 
#define Fraig_TableBinForEachEntryD(pBin, pEnt)
 
#define Fraig_TableBinForEachEntrySafeD(pBin, pEnt, pEnt2)
 
#define Fraig_TableBinForEachEntryE(pBin, pEnt)
 
#define Fraig_TableBinForEachEntrySafeE(pBin, pEnt, pEnt2)
 

Typedefs

typedef struct Fraig_MemFixed_t_ Fraig_MemFixed_t
 STRUCTURE DEFINITIONS ///. More...
 

Functions

unsigned Aig_ManRandom (int fReset)
 GLOBAL VARIABLES ///. More...
 
Fraig_Node_tFraig_NodeAndCanon (Fraig_Man_t *pMan, Fraig_Node_t *p1, Fraig_Node_t *p2)
 FUNCTION DEFINITIONS ///. More...
 
void Fraig_NodeAddFaninFanout (Fraig_Node_t *pFanin, Fraig_Node_t *pFanout)
 DECLARATIONS ///. More...
 
void Fraig_NodeRemoveFaninFanout (Fraig_Node_t *pFanin, Fraig_Node_t *pFanoutToRemove)
 
int Fraig_NodeGetFanoutNum (Fraig_Node_t *pNode)
 
void Fraig_FeedBackInit (Fraig_Man_t *p)
 FUNCTION DEFINITIONS ///. More...
 
void Fraig_FeedBack (Fraig_Man_t *p, int *pModel, Msat_IntVec_t *vVars, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
 
void Fraig_FeedBackTest (Fraig_Man_t *p)
 
int Fraig_FeedBackCompress (Fraig_Man_t *p)
 
int * Fraig_ManAllocCounterExample (Fraig_Man_t *p)
 
int * Fraig_ManSaveCounterExample (Fraig_Man_t *p, Fraig_Node_t *pNode)
 
void Fraig_ManCreateSolver (Fraig_Man_t *p)
 
Fraig_MemFixed_tFraig_MemFixedStart (int nEntrySize)
 FUNCTION DEFINITIONS ///. More...
 
void Fraig_MemFixedStop (Fraig_MemFixed_t *p, int fVerbose)
 
char * Fraig_MemFixedEntryFetch (Fraig_MemFixed_t *p)
 
void Fraig_MemFixedEntryRecycle (Fraig_MemFixed_t *p, char *pEntry)
 
void Fraig_MemFixedRestart (Fraig_MemFixed_t *p)
 
int Fraig_MemFixedReadMemUsage (Fraig_MemFixed_t *p)
 
Fraig_Node_tFraig_NodeCreateConst (Fraig_Man_t *p)
 FUNCTION DEFINITIONS ///. More...
 
Fraig_Node_tFraig_NodeCreatePi (Fraig_Man_t *p)
 
Fraig_Node_tFraig_NodeCreate (Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
 
void Fraig_NodeSimulate (Fraig_Node_t *pNode, int iWordStart, int iWordStop, int fUseRand)
 
int Fraig_NodeIsImplication (Fraig_Man_t *p, Fraig_Node_t *pOld, Fraig_Node_t *pNew, int nBTLimit)
 
Fraig_HashTable_tFraig_HashTableCreate (int nSize)
 FUNCTION DEFINITIONS ///. More...
 
void Fraig_HashTableFree (Fraig_HashTable_t *p)
 
int Fraig_HashTableLookupS (Fraig_Man_t *pMan, Fraig_Node_t *p1, Fraig_Node_t *p2, Fraig_Node_t **ppNodeRes)
 
Fraig_Node_tFraig_HashTableLookupF (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
Fraig_Node_tFraig_HashTableLookupF0 (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
void Fraig_HashTableInsertF0 (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
int Fraig_CompareSimInfo (Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int iWordLast, int fUseRand)
 
int Fraig_CompareSimInfoUnderMask (Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int iWordLast, int fUseRand, unsigned *puMask)
 
int Fraig_FindFirstDiff (Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int fCompl, int iWordLast, int fUseRand)
 
void Fraig_CollectXors (Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int iWordLast, int fUseRand, unsigned *puMask)
 
void Fraig_TablePrintStatsS (Fraig_Man_t *pMan)
 
void Fraig_TablePrintStatsF (Fraig_Man_t *pMan)
 
void Fraig_TablePrintStatsF0 (Fraig_Man_t *pMan)
 
int Fraig_TableRehashF0 (Fraig_Man_t *pMan, int fLinkEquiv)
 
int Fraig_NodeCountPis (Msat_IntVec_t *vVars, int nVarsPi)
 
int Fraig_NodeCountSuppVars (Fraig_Man_t *p, Fraig_Node_t *pNode, int fSuppStr)
 
int Fraig_NodesCompareSupps (Fraig_Man_t *p, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
 
int Fraig_NodeAndSimpleCase_rec (Fraig_Node_t *pOld, Fraig_Node_t *pNew)
 
int Fraig_NodeIsExorType (Fraig_Node_t *pNode)
 
void Fraig_ManSelectBestChoice (Fraig_Man_t *p)
 
int Fraig_BitStringCountOnes (unsigned *pString, int nWords)
 
void Fraig_PrintBinary (FILE *pFile, unsigned *pSign, int nBits)
 
int Fraig_NodeIsExor (Fraig_Node_t *pNode)
 
int Fraig_NodeIsMuxType (Fraig_Node_t *pNode)
 
Fraig_Node_tFraig_NodeRecognizeMux (Fraig_Node_t *pNode, Fraig_Node_t **ppNodeT, Fraig_Node_t **ppNodeE)
 
int Fraig_ManCountExors (Fraig_Man_t *pMan)
 
int Fraig_ManCountMuxes (Fraig_Man_t *pMan)
 
int Fraig_NodeSimsContained (Fraig_Man_t *pMan, Fraig_Node_t *pNode1, Fraig_Node_t *pNode2)
 
int Fraig_NodeIsInSupergate (Fraig_Node_t *pOld, Fraig_Node_t *pNew)
 
Fraig_NodeVec_tFraig_CollectSupergate (Fraig_Node_t *pNode, int fStopAtMux)
 
int Fraig_CountPis (Fraig_Man_t *p, Msat_IntVec_t *vVarNums)
 
void Fraig_ManIncrementTravId (Fraig_Man_t *pMan)
 
void Fraig_NodeSetTravIdCurrent (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
int Fraig_NodeIsTravIdCurrent (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
int Fraig_NodeIsTravIdPrevious (Fraig_Man_t *pMan, Fraig_Node_t *pNode)
 
void Fraig_NodeVecSortByRefCount (Fraig_NodeVec_t *p)
 

Variables

int s_FraigPrimes [FRAIG_MAX_PRIMES]
 DECLARATIONS ///. More...
 

Macro Definition Documentation

#define Fraig_BitStringHasBit (   p,
 
)    (((p)[(i)>>5] & (1<<((i) & 31))) > 0)

Definition at line 81 of file fraigInt.h.

#define Fraig_BitStringSetBit (   p,
 
)    ((p)[(i)>>5] |= (1<<((i) & 31)))

Definition at line 79 of file fraigInt.h.

#define Fraig_BitStringXorBit (   p,
 
)    ((p)[(i)>>5] ^= (1<<((i) & 31)))

Definition at line 80 of file fraigInt.h.

#define FRAIG_ENABLE_FANOUTS

INCLUDES ///.

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

FileName [fraigInt.h]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [Internal declarations of the FRAIG package.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id:
fraigInt.h,v 1.15 2005/07/08 01:01:31 alanmi Exp

]PARAMETERS ///MACRO DEFINITIONS ///

Definition at line 57 of file fraigInt.h.

#define FRAIG_FULL   (~((unsigned)0))

Definition at line 71 of file fraigInt.h.

#define Fraig_HashKey2 (   a,
  b,
  TSIZE 
)    (((ABC_PTRUINT_T)(a) + (ABC_PTRUINT_T)(b) * 12582917) % TSIZE)

Definition at line 92 of file fraigInt.h.

#define FRAIG_MASK (   n)    ((~((unsigned)0)) >> (32-(n)))

Definition at line 70 of file fraigInt.h.

#define FRAIG_MAX_PRIMES   1024

Definition at line 60 of file fraigInt.h.

#define Fraig_NodeForEachFanout (   pNode,
  pFanout 
)
Value:
for ( pFanout = (pNode)->pFanPivot; pFanout; \
pFanout = Fraig_NodeReadNextFanout(pNode, pFanout) )
#define Fraig_NodeReadNextFanout(pNode, pFanout)
Definition: fraigInt.h:279

Definition at line 288 of file fraigInt.h.

#define Fraig_NodeForEachFanoutSafe (   pNode,
  pFanout,
  pFanout2 
)
Value:
for ( pFanout = (pNode)->pFanPivot, \
pFanout2 = Fraig_NodeReadNextFanout(pNode, pFanout); \
pFanout; \
pFanout = pFanout2, \
pFanout2 = Fraig_NodeReadNextFanout(pNode, pFanout) )
#define Fraig_NodeReadNextFanout(pNode, pFanout)
Definition: fraigInt.h:279

Definition at line 292 of file fraigInt.h.

#define Fraig_NodeHasVarStr (   p,
 
)    Fraig_BitStringHasBit(Fraig_Regular(p)->pSuppStr,i)

Definition at line 87 of file fraigInt.h.

#define Fraig_NodeReadNextFanout (   pNode,
  pFanout 
)
Value:
( ( pFanout == NULL )? NULL : \
((Fraig_Regular((pFanout)->p1) == (pNode))? \
(pFanout)->pFanFanin1 : (pFanout)->pFanFanin2) )
#define Fraig_Regular(p)
Definition: fraig.h:108

Definition at line 279 of file fraigInt.h.

#define Fraig_NodeReadNextFanoutPlace (   pNode,
  pFanout 
)
Value:
( (Fraig_Regular((pFanout)->p1) == (pNode))? \
&(pFanout)->pFanFanin1 : &(pFanout)->pFanFanin2 )
#define Fraig_Regular(p)
Definition: fraig.h:108

Definition at line 284 of file fraigInt.h.

#define Fraig_NodeSetVarStr (   p,
 
)    Fraig_BitStringSetBit(Fraig_Regular(p)->pSuppStr,i)

Definition at line 86 of file fraigInt.h.

#define FRAIG_NUM_WORDS (   n)    (((n)>>5) + (((n)&31) > 0))

Definition at line 72 of file fraigInt.h.

#define FRAIG_PATTERNS_DYNAMIC   2048

Definition at line 59 of file fraigInt.h.

#define FRAIG_PATTERNS_RANDOM   2048

Definition at line 58 of file fraigInt.h.

#define Fraig_PrintTime (   a,
 
)    printf( "%s = ", (a) ); printf( "%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC) )

Definition at line 90 of file fraigInt.h.

#define FRAIG_RANDOM_UNSIGNED   Aig_ManRandom(0)

Definition at line 76 of file fraigInt.h.

#define Fraig_TableBinForEachEntryD (   pBin,
  pEnt 
)
Value:
for ( pEnt = pBin; \
pEnt; \
pEnt = pEnt->pNextD )

Definition at line 323 of file fraigInt.h.

#define Fraig_TableBinForEachEntryE (   pBin,
  pEnt 
)
Value:
for ( pEnt = pBin; \
pEnt; \
pEnt = pEnt->pNextE )

Definition at line 334 of file fraigInt.h.

#define Fraig_TableBinForEachEntryF (   pBin,
  pEnt 
)
Value:
for ( pEnt = pBin; \
pEnt; \
pEnt = pEnt->pNextF )

Definition at line 312 of file fraigInt.h.

#define Fraig_TableBinForEachEntryS (   pBin,
  pEnt 
)
Value:
for ( pEnt = pBin; \
pEnt; \
pEnt = pEnt->pNextS )

Definition at line 301 of file fraigInt.h.

#define Fraig_TableBinForEachEntrySafeD (   pBin,
  pEnt,
  pEnt2 
)
Value:
for ( pEnt = pBin, \
pEnt2 = pEnt? pEnt->pNextD: NULL; \
pEnt; \
pEnt = pEnt2, \
pEnt2 = pEnt? pEnt->pNextD: NULL )

Definition at line 327 of file fraigInt.h.

#define Fraig_TableBinForEachEntrySafeE (   pBin,
  pEnt,
  pEnt2 
)
Value:
for ( pEnt = pBin, \
pEnt2 = pEnt? pEnt->pNextE: NULL; \
pEnt; \
pEnt = pEnt2, \
pEnt2 = pEnt? pEnt->pNextE: NULL )

Definition at line 338 of file fraigInt.h.

#define Fraig_TableBinForEachEntrySafeF (   pBin,
  pEnt,
  pEnt2 
)
Value:
for ( pEnt = pBin, \
pEnt2 = pEnt? pEnt->pNextF: NULL; \
pEnt; \
pEnt = pEnt2, \
pEnt2 = pEnt? pEnt->pNextF: NULL )

Definition at line 316 of file fraigInt.h.

#define Fraig_TableBinForEachEntrySafeS (   pBin,
  pEnt,
  pEnt2 
)
Value:
for ( pEnt = pBin, \
pEnt2 = pEnt? pEnt->pNextS: NULL; \
pEnt; \
pEnt = pEnt2, \
pEnt2 = pEnt? pEnt->pNextS: NULL )

Definition at line 305 of file fraigInt.h.

#define FRAIG_WORDS_STORE   5

Definition at line 67 of file fraigInt.h.

Typedef Documentation

STRUCTURE DEFINITIONS ///.

Definition at line 101 of file fraigInt.h.

Function Documentation

unsigned Aig_ManRandom ( int  fReset)

GLOBAL VARIABLES ///.

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

Synopsis [Creates a sequence of random numbers.]

Description []

SideEffects []

SeeAlso [http://www.codeproject.com/KB/recipes/SimpleRNG.aspx]

Definition at line 1157 of file aigUtil.c.

1158 {
1159  static unsigned int m_z = NUMBER1;
1160  static unsigned int m_w = NUMBER2;
1161  if ( fReset )
1162  {
1163  m_z = NUMBER1;
1164  m_w = NUMBER2;
1165  }
1166  m_z = 36969 * (m_z & 65535) + (m_z >> 16);
1167  m_w = 18000 * (m_w & 65535) + (m_w >> 16);
1168  return (m_z << 16) + m_w;
1169 }
#define NUMBER1
Definition: aigUtil.c:1143
#define NUMBER2
Definition: aigUtil.c:1144
int Fraig_BitStringCountOnes ( unsigned *  pString,
int  nWords 
)

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

Synopsis [Creates the constant 1 node.]

Description []

SideEffects []

SeeAlso []

Definition at line 288 of file fraigUtil.c.

289 {
290  unsigned char * pSuppBytes = (unsigned char *)pString;
291  int i, nOnes, nBytes = sizeof(unsigned) * nWords;
292  // count the number of ones in the simulation vector
293  for ( i = nOnes = 0; i < nBytes; i++ )
294  nOnes += bit_count[pSuppBytes[i]];
295  return nOnes;
296 }
int nWords
Definition: abcNpn.c:127
static ABC_NAMESPACE_IMPL_START int bit_count[256]
DECLARATIONS ///.
Definition: fraigUtil.c:29
Fraig_NodeVec_t* Fraig_CollectSupergate ( Fraig_Node_t pNode,
int  fStopAtMux 
)

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

Synopsis [Returns the array of nodes to be combined into one multi-input AND-gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 960 of file fraigUtil.c.

961 {
962  Fraig_NodeVec_t * vSuper;
963  vSuper = Fraig_NodeVecAlloc( 8 );
964  Fraig_CollectSupergate_rec( pNode, vSuper, 1, fStopAtMux );
965  return vSuper;
966 }
void Fraig_CollectSupergate_rec(Fraig_Node_t *pNode, Fraig_NodeVec_t *vSuper, int fFirst, int fStopAtMux)
Definition: fraigUtil.c:933
Fraig_NodeVec_t * Fraig_NodeVecAlloc(int nCap)
DECLARATIONS ///.
Definition: fraigVec.c:43
void Fraig_CollectXors ( Fraig_Node_t pNode1,
Fraig_Node_t pNode2,
int  iWordLast,
int  fUseRand,
unsigned *  puMask 
)

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

Synopsis [Compares two pieces of simulation info.]

Description [Returns 1 if they are equal.]

SideEffects []

SeeAlso []

Definition at line 478 of file fraigTable.c.

479 {
480  unsigned * pSims1, * pSims2;
481  int i;
482  assert( !Fraig_IsComplement(pNode1) );
483  assert( !Fraig_IsComplement(pNode2) );
484  // get hold of simulation info
485  pSims1 = fUseRand? pNode1->puSimR : pNode1->puSimD;
486  pSims2 = fUseRand? pNode2->puSimR : pNode2->puSimD;
487  // check the simulation info
488  for ( i = 0; i < iWordLast; i++ )
489  puMask[i] = ( pSims1[i] ^ pSims2[i] );
490 }
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define assert(ex)
Definition: util_old.h:213
int Fraig_CompareSimInfo ( Fraig_Node_t pNode1,
Fraig_Node_t pNode2,
int  iWordLast,
int  fUseRand 
)

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

Synopsis [Compares two pieces of simulation info.]

Description [Returns 1 if they are equal.]

SideEffects []

SeeAlso []

Definition at line 351 of file fraigTable.c.

352 {
353  int i;
354  assert( !Fraig_IsComplement(pNode1) );
355  assert( !Fraig_IsComplement(pNode2) );
356  if ( fUseRand )
357  {
358  // if their signatures differ, skip
359  if ( pNode1->uHashR != pNode2->uHashR )
360  return 0;
361  // check the simulation info
362  for ( i = 0; i < iWordLast; i++ )
363  if ( pNode1->puSimR[i] != pNode2->puSimR[i] )
364  return 0;
365  }
366  else
367  {
368  // if their signatures differ, skip
369  if ( pNode1->uHashD != pNode2->uHashD )
370  return 0;
371  // check the simulation info
372  for ( i = 0; i < iWordLast; i++ )
373  if ( pNode1->puSimD[i] != pNode2->puSimD[i] )
374  return 0;
375  }
376  return 1;
377 }
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define assert(ex)
Definition: util_old.h:213
int Fraig_CompareSimInfoUnderMask ( Fraig_Node_t pNode1,
Fraig_Node_t pNode2,
int  iWordLast,
int  fUseRand,
unsigned *  puMask 
)

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

Synopsis [Compares two pieces of simulation info.]

Description [Returns 1 if they are equal.]

SideEffects []

SeeAlso []

Definition at line 451 of file fraigTable.c.

452 {
453  unsigned * pSims1, * pSims2;
454  int i;
455  assert( !Fraig_IsComplement(pNode1) );
456  assert( !Fraig_IsComplement(pNode2) );
457  // get hold of simulation info
458  pSims1 = fUseRand? pNode1->puSimR : pNode1->puSimD;
459  pSims2 = fUseRand? pNode2->puSimR : pNode2->puSimD;
460  // check the simulation info
461  for ( i = 0; i < iWordLast; i++ )
462  if ( (pSims1[i] & puMask[i]) != (pSims2[i] & puMask[i]) )
463  return 0;
464  return 1;
465 }
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define assert(ex)
Definition: util_old.h:213
int Fraig_CountPis ( Fraig_Man_t p,
Msat_IntVec_t vVarNums 
)

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

Synopsis [Count the number of PI variables.]

Description []

SideEffects []

SeeAlso []

Definition at line 817 of file fraigUtil.c.

818 {
819  int * pVars, nVars, i, Counter;
820 
821  nVars = Msat_IntVecReadSize(vVarNums);
822  pVars = Msat_IntVecReadArray(vVarNums);
823  Counter = 0;
824  for ( i = 0; i < nVars; i++ )
825  Counter += Fraig_NodeIsVar( p->vNodes->pArray[pVars[i]] );
826  return Counter;
827 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition: msatVec.c:233
static int Counter
int * Msat_IntVecReadArray(Msat_IntVec_t *p)
Definition: msatVec.c:217
int Fraig_NodeIsVar(Fraig_Node_t *p)
Definition: fraigApi.c:152
void Fraig_FeedBack ( Fraig_Man_t p,
int *  pModel,
Msat_IntVec_t vVars,
Fraig_Node_t pOld,
Fraig_Node_t pNew 
)

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

Synopsis [Processes the feedback from teh solver.]

Description [Array pModel gives the value of each variable in the SAT solver. Array vVars is the array of integer numbers of variables involves in this conflict.]

SideEffects []

SeeAlso []

Definition at line 80 of file fraigFeed.c.

81 {
82  int nVarsPi, nWords;
83  int i;
84  abctime clk = Abc_Clock();
85 
86  // get the number of PI vars in the feedback (also sets the PI values)
87  nVarsPi = Fraig_FeedBackPrepare( p, pModel, vVars );
88 
89  // set the PI values
90  nWords = Fraig_FeedBackInsert( p, nVarsPi );
91  assert( p->iWordStart + nWords <= p->nWordsDyna );
92 
93  // resimulates the words from p->iWordStart to iWordStop
94  for ( i = 1; i < p->vNodes->nSize; i++ )
95  if ( Fraig_NodeIsAnd(p->vNodes->pArray[i]) )
96  Fraig_NodeSimulate( p->vNodes->pArray[i], p->iWordStart, p->iWordStart + nWords, 0 );
97 
98  if ( p->fDoSparse )
99  Fraig_TableRehashF0( p, 0 );
100 
101  if ( !p->fChoicing )
102  Fraig_FeedBackVerify( p, pOld, pNew );
103 
104  // if there is no room left, compress the patterns
105  if ( p->iWordStart + nWords == p->nWordsDyna )
106  p->iWordStart = Fraig_FeedBackCompress( p );
107  else // otherwise, update the starting word
108  p->iWordStart += nWords;
109 
110 p->timeFeed += Abc_Clock() - clk;
111 }
int Fraig_FeedBackCompress(Fraig_Man_t *p)
Definition: fraigFeed.c:278
void Fraig_NodeSimulate(Fraig_Node_t *pNode, int iWordStart, int iWordStop, int fUseRand)
Definition: fraigNode.c:226
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Fraig_FeedBackVerify(Fraig_Man_t *p, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
Definition: fraigFeed.c:252
static int Fraig_FeedBackInsert(Fraig_Man_t *p, int nVarsPi)
Definition: fraigFeed.c:167
static abctime Abc_Clock()
Definition: abc_global.h:279
int nWords
Definition: abcNpn.c:127
static ABC_NAMESPACE_IMPL_START int Fraig_FeedBackPrepare(Fraig_Man_t *p, int *pModel, Msat_IntVec_t *vVars)
DECLARATIONS ///.
Definition: fraigFeed.c:125
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
int Fraig_TableRehashF0(Fraig_Man_t *pMan, int fLinkEquiv)
Definition: fraigTable.c:604
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
int Fraig_FeedBackCompress ( Fraig_Man_t p)

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

Synopsis [Compress the simulation patterns.]

Description []

SideEffects []

SeeAlso []

Definition at line 278 of file fraigFeed.c.

279 {
280  unsigned * pSims;
281  unsigned uHash;
282  int i, w, t, nPats, * pPats;
283  int fPerformChecks = (p->nBTLimit == -1);
284 
285  // solve the covering problem
286  if ( fPerformChecks )
287  {
289  if ( p->fDoSparse )
291  }
292 
293  // solve the covering problem
294  Fraig_FeedBackCovering( p, p->vPatsReal );
295 
296 
297  // get the number of additional patterns
298  nPats = Msat_IntVecReadSize( p->vPatsReal );
299  pPats = Msat_IntVecReadArray( p->vPatsReal );
300  // get the new starting word
301  p->iWordStart = FRAIG_NUM_WORDS( p->iPatsPerm + nPats );
302 
303  // set the simulation info for the PIs
304  for ( i = 0; i < p->vInputs->nSize; i++ )
305  {
306  // get hold of the simulation info for this PI
307  pSims = p->vInputs->pArray[i]->puSimD;
308  // clean the storage for the new patterns
309  for ( w = p->iWordPerm; w < p->iWordStart; w++ )
310  p->pSimsTemp[w] = 0;
311  // set the patterns
312  for ( t = 0; t < nPats; t++ )
313  if ( Fraig_BitStringHasBit( pSims, pPats[t] ) )
314  {
315  // check if this pattern falls into temporary storage
316  if ( p->iPatsPerm + t < p->iWordPerm * 32 )
317  Fraig_BitStringSetBit( pSims, p->iPatsPerm + t );
318  else
319  Fraig_BitStringSetBit( p->pSimsTemp, p->iPatsPerm + t );
320  }
321  // copy the pattern
322  for ( w = p->iWordPerm; w < p->iWordStart; w++ )
323  pSims[w] = p->pSimsTemp[w];
324  // recompute the hashing info
325  uHash = 0;
326  for ( w = 0; w < p->iWordStart; w++ )
327  uHash ^= pSims[w] * s_FraigPrimes[w];
328  p->vInputs->pArray[i]->uHashD = uHash;
329  }
330 
331  // update info about the permanently stored patterns
332  p->iWordPerm = p->iWordStart;
333  p->iPatsPerm += nPats;
334  assert( p->iWordPerm == FRAIG_NUM_WORDS( p->iPatsPerm ) );
335 
336  // resimulate and recompute the hash values
337  for ( i = 1; i < p->vNodes->nSize; i++ )
338  if ( Fraig_NodeIsAnd(p->vNodes->pArray[i]) )
339  {
340  p->vNodes->pArray[i]->uHashD = 0;
341  Fraig_NodeSimulate( p->vNodes->pArray[i], 0, p->iWordPerm, 0 );
342  }
343 
344  // double-check that the nodes are still distinguished
345  if ( fPerformChecks )
347 
348  // rehash the values in the F0 table
349  if ( p->fDoSparse )
350  {
351  Fraig_TableRehashF0( p, 0 );
352  if ( fPerformChecks )
354  }
355 
356  // check if we need to resize the simulation info
357  // if less than FRAIG_WORDS_STORE words are left, reallocate simulation info
358  if ( p->iWordPerm + FRAIG_WORDS_STORE > p->nWordsDyna )
360 
361  // set the real patterns
362  Msat_IntVecClear( p->vPatsReal );
363  memset( p->pSimsReal, 0, sizeof(unsigned)*p->nWordsDyna );
364  for ( w = 0; w < p->iWordPerm; w++ )
365  p->pSimsReal[w] = FRAIG_FULL;
366  if ( p->iPatsPerm % 32 > 0 )
367  p->pSimsReal[p->iWordPerm-1] = FRAIG_MASK( p->iPatsPerm % 32 );
368 // printf( "The number of permanent words = %d.\n", p->iWordPerm );
369  return p->iWordStart;
370 }
char * memset()
#define FRAIG_FULL
Definition: fraigInt.h:71
#define FRAIG_WORDS_STORE
Definition: fraigInt.h:67
#define Fraig_BitStringHasBit(p, i)
Definition: fraigInt.h:81
void Fraig_NodeSimulate(Fraig_Node_t *pNode, int iWordStart, int iWordStop, int fUseRand)
Definition: fraigNode.c:226
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Fraig_ReallocateSimulationInfo(Fraig_Man_t *p)
Definition: fraigFeed.c:711
void Msat_IntVecClear(Msat_IntVec_t *p)
Definition: msatVec.c:335
static void Fraig_FeedBackCheckTable(Fraig_Man_t *p)
Definition: fraigFeed.c:636
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition: msatVec.c:233
#define Fraig_BitStringSetBit(p, i)
Definition: fraigInt.h:79
static void Fraig_FeedBackCheckTableF0(Fraig_Man_t *p)
Definition: fraigFeed.c:674
static void Fraig_FeedBackCovering(Fraig_Man_t *p, Msat_IntVec_t *vPats)
Definition: fraigFeed.c:386
if(last==0)
Definition: sparse_int.h:34
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
#define FRAIG_NUM_WORDS(n)
Definition: fraigInt.h:72
#define FRAIG_MASK(n)
Definition: fraigInt.h:70
int * Msat_IntVecReadArray(Msat_IntVec_t *p)
Definition: msatVec.c:217
int Fraig_TableRehashF0(Fraig_Man_t *pMan, int fLinkEquiv)
Definition: fraigTable.c:604
#define assert(ex)
Definition: util_old.h:213
int s_FraigPrimes[FRAIG_MAX_PRIMES]
DECLARATIONS ///.
Definition: fraigPrime.c:30
void Fraig_FeedBackInit ( Fraig_Man_t p)

FUNCTION DEFINITIONS ///.

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

Synopsis [Initializes the feedback information.]

Description []

SideEffects []

SeeAlso []

Definition at line 57 of file fraigFeed.c.

58 {
59  p->vCones = Fraig_NodeVecAlloc( 500 );
60  p->vPatsReal = Msat_IntVecAlloc( 1000 );
61  p->pSimsReal = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
62  memset( p->pSimsReal, 0, sizeof(unsigned) * p->nWordsDyna );
63  p->pSimsTemp = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
64  p->pSimsDiff = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
65 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Fraig_NodeVec_t * Fraig_NodeVecAlloc(int nCap)
DECLARATIONS ///.
Definition: fraigVec.c:43
Msat_IntVec_t * Msat_IntVecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: msatVec.c:48
char * Fraig_MemFixedEntryFetch(Fraig_MemFixed_t *p)
Definition: fraigMem.c:131
void Fraig_FeedBackTest ( Fraig_Man_t p)
int Fraig_FindFirstDiff ( Fraig_Node_t pNode1,
Fraig_Node_t pNode2,
int  fCompl,
int  iWordLast,
int  fUseRand 
)

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

Synopsis [Find the number of the different pattern.]

Description [Returns -1 if there is no such pattern]

SideEffects []

SeeAlso []

Definition at line 390 of file fraigTable.c.

391 {
392  int i, v;
393  assert( !Fraig_IsComplement(pNode1) );
394  assert( !Fraig_IsComplement(pNode2) );
395  // take into account possible internal complementation
396  fCompl ^= pNode1->fInv;
397  fCompl ^= pNode2->fInv;
398  // find the pattern
399  if ( fCompl )
400  {
401  if ( fUseRand )
402  {
403  for ( i = 0; i < iWordLast; i++ )
404  if ( pNode1->puSimR[i] != ~pNode2->puSimR[i] )
405  for ( v = 0; v < 32; v++ )
406  if ( (pNode1->puSimR[i] ^ ~pNode2->puSimR[i]) & (1 << v) )
407  return i * 32 + v;
408  }
409  else
410  {
411  for ( i = 0; i < iWordLast; i++ )
412  if ( pNode1->puSimD[i] != ~pNode2->puSimD[i] )
413  for ( v = 0; v < 32; v++ )
414  if ( (pNode1->puSimD[i] ^ ~pNode2->puSimD[i]) & (1 << v) )
415  return i * 32 + v;
416  }
417  }
418  else
419  {
420  if ( fUseRand )
421  {
422  for ( i = 0; i < iWordLast; i++ )
423  if ( pNode1->puSimR[i] != pNode2->puSimR[i] )
424  for ( v = 0; v < 32; v++ )
425  if ( (pNode1->puSimR[i] ^ pNode2->puSimR[i]) & (1 << v) )
426  return i * 32 + v;
427  }
428  else
429  {
430  for ( i = 0; i < iWordLast; i++ )
431  if ( pNode1->puSimD[i] != pNode2->puSimD[i] )
432  for ( v = 0; v < 32; v++ )
433  if ( (pNode1->puSimD[i] ^ pNode2->puSimD[i]) & (1 << v) )
434  return i * 32 + v;
435  }
436  }
437  return -1;
438 }
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define assert(ex)
Definition: util_old.h:213
Fraig_HashTable_t* Fraig_HashTableCreate ( int  nSize)

FUNCTION DEFINITIONS ///.

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

Synopsis [Allocates the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file fraigTable.c.

47 {
49  // allocate the table
50  p = ABC_ALLOC( Fraig_HashTable_t, 1 );
51  memset( p, 0, sizeof(Fraig_HashTable_t) );
52  // allocate and clean the bins
53  p->nBins = Abc_PrimeCudd(nSize);
54  p->pBins = ABC_ALLOC( Fraig_Node_t *, p->nBins );
55  memset( p->pBins, 0, sizeof(Fraig_Node_t *) * p->nBins );
56  return p;
57 }
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Fraig_HashTableFree ( Fraig_HashTable_t p)

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

Synopsis [Deallocates the supergate hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file fraigTable.c.

71 {
72  ABC_FREE( p->pBins );
73  ABC_FREE( p );
74 }
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Fraig_HashTableInsertF0 ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis [Insert the entry in the functional hash table.]

Description [Unconditionally add the node to the corresponding linked list in the table.]

SideEffects []

SeeAlso []

Definition at line 237 of file fraigTable.c.

238 {
239  Fraig_HashTable_t * p = pMan->pTableF0;
240  unsigned Key = pNode->uHashD % p->nBins;
241 
242  pNode->pNextF = p->pBins[Key];
243  p->pBins[Key] = pNode;
244  p->nEntries++;
245 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
Fraig_Node_t * pNextF
Definition: fraigInt.h:239
Fraig_Node_t* Fraig_HashTableLookupF ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis [Insert the entry in the functional hash table.]

Description [If the entry with the same key exists, return it right away. If the entry with the same key does not exists, inserts it and returns NULL. ]

SideEffects []

SeeAlso []

Definition at line 136 of file fraigTable.c.

137 {
138  Fraig_HashTable_t * p = pMan->pTableF;
139  Fraig_Node_t * pEnt, * pEntD;
140  unsigned Key;
141 
142  // go through the hash table entries
143  Key = pNode->uHashR % p->nBins;
144  Fraig_TableBinForEachEntryF( p->pBins[Key], pEnt )
145  {
146  // if their simulation info differs, skip
147  if ( !Fraig_CompareSimInfo( pNode, pEnt, pMan->nWordsRand, 1 ) )
148  continue;
149  // equivalent up to the complement
150  Fraig_TableBinForEachEntryD( pEnt, pEntD )
151  {
152  // if their simulation info differs, skip
153  if ( !Fraig_CompareSimInfo( pNode, pEntD, pMan->iWordStart, 0 ) )
154  continue;
155  // found a simulation-equivalent node
156  return pEntD;
157  }
158  // did not find a simulation equivalent node
159  // add the node to the corresponding linked list
160  pNode->pNextD = pEnt->pNextD;
161  pEnt->pNextD = pNode;
162  // return NULL, because there is no functional equivalence in this case
163  return NULL;
164  }
165 
166  // check if it is a good time for table resizing
167  if ( p->nEntries >= 2 * p->nBins )
168  {
169  Fraig_TableResizeF( p, 1 );
170  Key = pNode->uHashR % p->nBins;
171  }
172 
173  // add the node to the corresponding linked list in the table
174  pNode->pNextF = p->pBins[Key];
175  p->pBins[Key] = pNode;
176  p->nEntries++;
177  // return NULL, because there is no functional equivalence in this case
178  return NULL;
179 }
static void Fraig_TableResizeF(Fraig_HashTable_t *p, int fUseSimR)
Definition: fraigTable.c:303
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Fraig_CompareSimInfo(Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int iWordLast, int fUseRand)
Definition: fraigTable.c:351
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
Fraig_Node_t * pNextD
Definition: fraigInt.h:240
#define Fraig_TableBinForEachEntryD(pBin, pEnt)
Definition: fraigInt.h:323
Fraig_Node_t * pNextF
Definition: fraigInt.h:239
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
Definition: fraigInt.h:312
Fraig_Node_t* Fraig_HashTableLookupF0 ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis [Insert the entry in the functional hash table.]

Description [If the entry with the same key exists, return it right away. If the entry with the same key does not exists, inserts it and returns NULL. ]

SideEffects []

SeeAlso []

Definition at line 193 of file fraigTable.c.

194 {
195  Fraig_HashTable_t * p = pMan->pTableF0;
196  Fraig_Node_t * pEnt;
197  unsigned Key;
198 
199  // go through the hash table entries
200  Key = pNode->uHashD % p->nBins;
201  Fraig_TableBinForEachEntryF( p->pBins[Key], pEnt )
202  {
203  // if their simulation info differs, skip
204  if ( !Fraig_CompareSimInfo( pNode, pEnt, pMan->iWordStart, 0 ) )
205  continue;
206  // found a simulation-equivalent node
207  return pEnt;
208  }
209 
210  // check if it is a good time for table resizing
211  if ( p->nEntries >= 2 * p->nBins )
212  {
213  Fraig_TableResizeF( p, 0 );
214  Key = pNode->uHashD % p->nBins;
215  }
216 
217  // add the node to the corresponding linked list in the table
218  pNode->pNextF = p->pBins[Key];
219  p->pBins[Key] = pNode;
220  p->nEntries++;
221  // return NULL, because there is no functional equivalence in this case
222  return NULL;
223 }
static void Fraig_TableResizeF(Fraig_HashTable_t *p, int fUseSimR)
Definition: fraigTable.c:303
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Fraig_CompareSimInfo(Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int iWordLast, int fUseRand)
Definition: fraigTable.c:351
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
Fraig_Node_t * pNextF
Definition: fraigInt.h:239
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
Definition: fraigInt.h:312
int Fraig_HashTableLookupS ( Fraig_Man_t pMan,
Fraig_Node_t p1,
Fraig_Node_t p2,
Fraig_Node_t **  ppNodeRes 
)

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

Synopsis [Looks up an entry in the structural hash table.]

Description [If the entry with the same children does not exists, creates it, inserts it into the table, and returns 0. If the entry with the same children exists, finds it, and return 1. In both cases, the new/old entry is returned in ppNodeRes.]

SideEffects []

SeeAlso []

Definition at line 90 of file fraigTable.c.

91 {
92  Fraig_HashTable_t * p = pMan->pTableS;
93  Fraig_Node_t * pEnt;
94  unsigned Key;
95 
96  // order the arguments
97  if ( Fraig_Regular(p1)->Num > Fraig_Regular(p2)->Num )
98  pEnt = p1, p1 = p2, p2 = pEnt;
99 
100  Key = Fraig_HashKey2( p1, p2, p->nBins );
101  Fraig_TableBinForEachEntryS( p->pBins[Key], pEnt )
102  if ( pEnt->p1 == p1 && pEnt->p2 == p2 )
103  {
104  *ppNodeRes = pEnt;
105  return 1;
106  }
107  // check if it is a good time for table resizing
108  if ( p->nEntries >= 2 * p->nBins )
109  {
110  Fraig_TableResizeS( p );
111  Key = Fraig_HashKey2( p1, p2, p->nBins );
112  }
113  // create the new node
114  pEnt = Fraig_NodeCreate( pMan, p1, p2 );
115  // add the node to the corresponding linked list in the table
116  pEnt->pNextS = p->pBins[Key];
117  p->pBins[Key] = pEnt;
118  *ppNodeRes = pEnt;
119  p->nEntries++;
120  return 0;
121 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Fraig_TableBinForEachEntryS(pBin, pEnt)
Definition: fraigInt.h:301
Fraig_Node_t * Fraig_NodeCreate(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigNode.c:160
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
if(last==0)
Definition: sparse_int.h:34
#define Fraig_HashKey2(a, b, TSIZE)
Definition: fraigInt.h:92
static ABC_NAMESPACE_IMPL_START void Fraig_TableResizeS(Fraig_HashTable_t *p)
DECLARATIONS ///.
Definition: fraigTable.c:259
Fraig_Node_t * pNextS
Definition: fraigInt.h:238
#define Fraig_Regular(p)
Definition: fraig.h:108
int* Fraig_ManAllocCounterExample ( Fraig_Man_t p)

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

Synopsis [Generated trivial counter example.]

Description []

SideEffects []

SeeAlso []

Definition at line 787 of file fraigFeed.c.

788 {
789  int * pModel;
790  pModel = ABC_ALLOC( int, p->vInputs->nSize );
791  memset( pModel, 0, sizeof(int) * p->vInputs->nSize );
792  return pModel;
793 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Fraig_ManCountExors ( Fraig_Man_t pMan)

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

Synopsis [Counts the number of EXOR type nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 742 of file fraigUtil.c.

743 {
744  int i, nExors;
745  nExors = 0;
746  for ( i = 0; i < pMan->vNodes->nSize; i++ )
747  nExors += Fraig_NodeIsExorType( pMan->vNodes->pArray[i] );
748  return nExors;
749 
750 }
int Fraig_NodeIsExorType(Fraig_Node_t *pNode)
Definition: fraigUtil.c:558
int Fraig_ManCountMuxes ( Fraig_Man_t pMan)

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

Synopsis [Counts the number of EXOR type nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 763 of file fraigUtil.c.

764 {
765  int i, nMuxes;
766  nMuxes = 0;
767  for ( i = 0; i < pMan->vNodes->nSize; i++ )
768  nMuxes += Fraig_NodeIsMuxType( pMan->vNodes->pArray[i] );
769  return nMuxes;
770 
771 }
static int nMuxes
Definition: abcSat.c:36
int Fraig_NodeIsMuxType(Fraig_Node_t *pNode)
Definition: fraigUtil.c:591
void Fraig_ManCreateSolver ( Fraig_Man_t p)

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

Synopsis [Prepares the SAT solver to run on the two nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 325 of file fraigMan.c.

326 {
327  extern abctime timeSelect;
328  extern abctime timeAssign;
329  assert( p->pSat == NULL );
330  // allocate data for SAT solving
331  p->pSat = Msat_SolverAlloc( 500, 1, 1, 1, 1, 0 );
332  p->vVarsInt = Msat_SolverReadConeVars( p->pSat );
333  p->vAdjacents = Msat_SolverReadAdjacents( p->pSat );
334  p->vVarsUsed = Msat_SolverReadVarsUsed( p->pSat );
335  timeSelect = 0;
336  timeAssign = 0;
337 }
Msat_IntVec_t * Msat_SolverReadVarsUsed(Msat_Solver_t *p)
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Msat_IntVec_t * Msat_SolverReadConeVars(Msat_Solver_t *p)
Msat_Solver_t * Msat_SolverAlloc(int nVars, double dClaInc, double dClaDecay, double dVarInc, double dVarDecay, int fVerbose)
ABC_NAMESPACE_IMPL_START abctime timeSelect
DECLARATIONS ///.
Definition: fraigMan.c:28
abctime timeAssign
Definition: fraigMan.c:29
Msat_ClauseVec_t * Msat_SolverReadAdjacents(Msat_Solver_t *p)
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
void Fraig_ManIncrementTravId ( Fraig_Man_t pMan)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 980 of file fraigUtil.c.

981 {
982  pMan->nTravIds2++;
983 }
int* Fraig_ManSaveCounterExample ( Fraig_Man_t p,
Fraig_Node_t pNode 
)

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

Synopsis [Saves the counter example.]

Description []

SideEffects []

SeeAlso []

Definition at line 860 of file fraigFeed.c.

861 {
862  int * pModel;
863  int iPattern;
864  int i, fCompl;
865 
866  // the node can be complemented
867  fCompl = Fraig_IsComplement(pNode);
868  // because we compare with constant 0, p->pConst1 should also be complemented
869  fCompl = !fCompl;
870 
871  // derive the model
872  pModel = Fraig_ManAllocCounterExample( p );
873  iPattern = Fraig_FindFirstDiff( p->pConst1, Fraig_Regular(pNode), fCompl, p->nWordsRand, 1 );
874  if ( iPattern >= 0 )
875  {
876  for ( i = 0; i < p->vInputs->nSize; i++ )
877  if ( Fraig_BitStringHasBit( p->vInputs->pArray[i]->puSimR, iPattern ) )
878  pModel[i] = 1;
879 /*
880 printf( "SAT solver's pattern:\n" );
881 for ( i = 0; i < p->vInputs->nSize; i++ )
882  printf( "%d", pModel[i] );
883 printf( "\n" );
884 */
885  assert( Fraig_ManSimulateBitNode( p, pNode, pModel ) );
886  return pModel;
887  }
888  iPattern = Fraig_FindFirstDiff( p->pConst1, Fraig_Regular(pNode), fCompl, p->iWordStart, 0 );
889  if ( iPattern >= 0 )
890  {
891  for ( i = 0; i < p->vInputs->nSize; i++ )
892  if ( Fraig_BitStringHasBit( p->vInputs->pArray[i]->puSimD, iPattern ) )
893  pModel[i] = 1;
894 /*
895 printf( "SAT solver's pattern:\n" );
896 for ( i = 0; i < p->vInputs->nSize; i++ )
897  printf( "%d", pModel[i] );
898 printf( "\n" );
899 */
900  assert( Fraig_ManSimulateBitNode( p, pNode, pModel ) );
901  return pModel;
902  }
903  ABC_FREE( pModel );
904  return NULL;
905 }
int * Fraig_ManAllocCounterExample(Fraig_Man_t *p)
Definition: fraigFeed.c:787
#define Fraig_BitStringHasBit(p, i)
Definition: fraigInt.h:81
int Fraig_ManSimulateBitNode(Fraig_Man_t *p, Fraig_Node_t *pNode, int *pModel)
Definition: fraigFeed.c:832
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Fraig_FindFirstDiff(Fraig_Node_t *pNode1, Fraig_Node_t *pNode2, int fCompl, int iWordLast, int fUseRand)
Definition: fraigTable.c:390
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
void Fraig_ManSelectBestChoice ( Fraig_Man_t p)
char* Fraig_MemFixedEntryFetch ( Fraig_MemFixed_t p)

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

Synopsis [Extracts one entry from the memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 131 of file fraigMem.c.

132 {
133  char * pTemp;
134  int i;
135 
136  // check if there are still free entries
137  if ( p->nEntriesUsed == p->nEntriesAlloc )
138  { // need to allocate more entries
139  assert( p->pEntriesFree == NULL );
140  if ( p->nChunks == p->nChunksAlloc )
141  {
142  p->nChunksAlloc *= 2;
143  p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
144  }
145  p->pEntriesFree = ABC_ALLOC( char, p->nEntrySize * p->nChunkSize );
146  p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
147  // transform these entries into a linked list
148  pTemp = p->pEntriesFree;
149  for ( i = 1; i < p->nChunkSize; i++ )
150  {
151  *((char **)pTemp) = pTemp + p->nEntrySize;
152  pTemp += p->nEntrySize;
153  }
154  // set the last link
155  *((char **)pTemp) = NULL;
156  // add the chunk to the chunk storage
157  p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
158  // add to the number of entries allocated
159  p->nEntriesAlloc += p->nChunkSize;
160  }
161  // incrememt the counter of used entries
162  p->nEntriesUsed++;
163  if ( p->nEntriesMax < p->nEntriesUsed )
164  p->nEntriesMax = p->nEntriesUsed;
165  // return the first entry in the free entry list
166  pTemp = p->pEntriesFree;
167  p->pEntriesFree = *((char **)pTemp);
168  return pTemp;
169 }
char * pEntriesFree
Definition: fraigMem.c:35
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char ** pChunks
Definition: fraigMem.c:41
#define assert(ex)
Definition: util_old.h:213
void Fraig_MemFixedEntryRecycle ( Fraig_MemFixed_t p,
char *  pEntry 
)

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

Synopsis [Returns one entry into the memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file fraigMem.c.

183 {
184  // decrement the counter of used entries
185  p->nEntriesUsed--;
186  // add the entry to the linked list of free entries
187  *((char **)pEntry) = p->pEntriesFree;
188  p->pEntriesFree = pEntry;
189 }
char * pEntriesFree
Definition: fraigMem.c:35
int Fraig_MemFixedReadMemUsage ( Fraig_MemFixed_t p)

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

Synopsis [Reports the memory usage.]

Description []

SideEffects []

SeeAlso []

Definition at line 240 of file fraigMem.c.

241 {
242  return p->nMemoryAlloc;
243 }
void Fraig_MemFixedRestart ( Fraig_MemFixed_t p)

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

Synopsis [Frees all associated memory and resets the manager.]

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

SideEffects []

SeeAlso []

Definition at line 202 of file fraigMem.c.

203 {
204  int i;
205  char * pTemp;
206 
207  // deallocate all chunks except the first one
208  for ( i = 1; i < p->nChunks; i++ )
209  ABC_FREE( p->pChunks[i] );
210  p->nChunks = 1;
211  // transform these entries into a linked list
212  pTemp = p->pChunks[0];
213  for ( i = 1; i < p->nChunkSize; i++ )
214  {
215  *((char **)pTemp) = pTemp + p->nEntrySize;
216  pTemp += p->nEntrySize;
217  }
218  // set the last link
219  *((char **)pTemp) = NULL;
220  // set the free entry list
221  p->pEntriesFree = p->pChunks[0];
222  // set the correct statistics
223  p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
224  p->nMemoryUsed = 0;
225  p->nEntriesAlloc = p->nChunkSize;
226  p->nEntriesUsed = 0;
227 }
char * pEntriesFree
Definition: fraigMem.c:35
char ** pChunks
Definition: fraigMem.c:41
#define ABC_FREE(obj)
Definition: abc_global.h:232
Fraig_MemFixed_t* Fraig_MemFixedStart ( int  nEntrySize)

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the internal memory manager.]

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

SideEffects []

SeeAlso []

Definition at line 63 of file fraigMem.c.

64 {
66 
67  p = ABC_ALLOC( Fraig_MemFixed_t, 1 );
68  memset( p, 0, sizeof(Fraig_MemFixed_t) );
69 
70  p->nEntrySize = nEntrySize;
71  p->nEntriesAlloc = 0;
72  p->nEntriesUsed = 0;
73  p->pEntriesFree = NULL;
74 
75  if ( nEntrySize * (1 << 10) < (1<<16) )
76  p->nChunkSize = (1 << 10);
77  else
78  p->nChunkSize = (1<<16) / nEntrySize;
79  if ( p->nChunkSize < 8 )
80  p->nChunkSize = 8;
81 
82  p->nChunksAlloc = 64;
83  p->nChunks = 0;
84  p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
85 
86  p->nMemoryUsed = 0;
87  p->nMemoryAlloc = 0;
88  return p;
89 }
char * pEntriesFree
Definition: fraigMem.c:35
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
DECLARATIONS ///.
Definition: fraigMem.c:28
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char ** pChunks
Definition: fraigMem.c:41
void Fraig_MemFixedStop ( Fraig_MemFixed_t p,
int  fVerbose 
)

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

Synopsis [Stops the internal memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 102 of file fraigMem.c.

103 {
104  int i;
105  if ( p == NULL )
106  return;
107  if ( fVerbose )
108  {
109  printf( "Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n",
110  p->nEntrySize, p->nChunkSize, p->nChunks );
111  printf( " Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n",
113  }
114  for ( i = 0; i < p->nChunks; i++ )
115  ABC_FREE( p->pChunks[i] );
116  ABC_FREE( p->pChunks );
117  ABC_FREE( p );
118 }
char ** pChunks
Definition: fraigMem.c:41
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Fraig_NodeAddFaninFanout ( Fraig_Node_t pFanin,
Fraig_Node_t pFanout 
)

DECLARATIONS ///.

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

FileName [fraigFanout.c]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [Procedures to manipulate fanouts of the FRAIG nodes.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id:
fraigFanout.c,v 1.5 2005/07/08 01:01:31 alanmi Exp

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

Synopsis [Add the fanout to the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file fraigFanout.c.

46 {
47  Fraig_Node_t * pPivot;
48 
49  // pFanins is a fanin of pFanout
50  assert( !Fraig_IsComplement(pFanin) );
51  assert( !Fraig_IsComplement(pFanout) );
52  assert( Fraig_Regular(pFanout->p1) == pFanin || Fraig_Regular(pFanout->p2) == pFanin );
53 
54  pPivot = pFanin->pFanPivot;
55  if ( pPivot == NULL )
56  {
57  pFanin->pFanPivot = pFanout;
58  return;
59  }
60 
61  if ( Fraig_Regular(pPivot->p1) == pFanin )
62  {
63  if ( Fraig_Regular(pFanout->p1) == pFanin )
64  {
65  pFanout->pFanFanin1 = pPivot->pFanFanin1;
66  pPivot->pFanFanin1 = pFanout;
67  }
68  else // if ( Fraig_Regular(pFanout->p2) == pFanin )
69  {
70  pFanout->pFanFanin2 = pPivot->pFanFanin1;
71  pPivot->pFanFanin1 = pFanout;
72  }
73  }
74  else // if ( Fraig_Regular(pPivot->p2) == pFanin )
75  {
76  assert( Fraig_Regular(pPivot->p2) == pFanin );
77  if ( Fraig_Regular(pFanout->p1) == pFanin )
78  {
79  pFanout->pFanFanin1 = pPivot->pFanFanin2;
80  pPivot->pFanFanin2 = pFanout;
81  }
82  else // if ( Fraig_Regular(pFanout->p2) == pFanin )
83  {
84  pFanout->pFanFanin2 = pPivot->pFanFanin2;
85  pPivot->pFanFanin2 = pFanout;
86  }
87  }
88 }
Fraig_Node_t * pFanFanin1
Definition: fraigInt.h:257
Fraig_Node_t * p2
Definition: fraigInt.h:233
Fraig_Node_t * p1
Definition: fraigInt.h:232
Fraig_Node_t * pFanFanin2
Definition: fraigInt.h:258
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_Regular(p)
Definition: fraig.h:108
Fraig_Node_t * pFanPivot
Definition: fraigInt.h:256
#define assert(ex)
Definition: util_old.h:213
Fraig_Node_t* Fraig_NodeAndCanon ( Fraig_Man_t pMan,
Fraig_Node_t p1,
Fraig_Node_t p2 
)

FUNCTION DEFINITIONS ///.

FUNCTION DEFINITIONS ///.

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

FileName [fraigCanon.c]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [AND-node creation and elementary AND-operation.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id:
fraigCanon.c,v 1.4 2005/07/08 01:01:31 alanmi Exp

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

Synopsis [The internal AND operation for the two FRAIG nodes.]

Description [This procedure is the core of the FRAIG package, because it performs the two-step canonicization of FRAIG nodes. The first step involves the lookup in the structural hash table (which hashes two ANDs into a node that has them as fanins, if such a node exists). If the node is not found in the structural hash table, an attempt is made to find a functionally equivalent node in another hash table (which hashes the simulation info into the nodes, which has this simulation info). Some tricks used on the way are described in the comments to the code and in the paper "FRAIGs: Functionally reduced AND-INV graphs".]

SideEffects []

SeeAlso []

Definition at line 52 of file fraigCanon.c.

53 {
54  Fraig_Node_t * pNodeNew, * pNodeOld, * pNodeRepr;
55  int fUseSatCheck;
56 // int RetValue;
57 
58  // check for trivial cases
59  if ( p1 == p2 )
60  return p1;
61  if ( p1 == Fraig_Not(p2) )
62  return Fraig_Not(pMan->pConst1);
63  if ( Fraig_NodeIsConst(p1) )
64  {
65  if ( p1 == pMan->pConst1 )
66  return p2;
67  return Fraig_Not(pMan->pConst1);
68  }
69  if ( Fraig_NodeIsConst(p2) )
70  {
71  if ( p2 == pMan->pConst1 )
72  return p1;
73  return Fraig_Not(pMan->pConst1);
74  }
75 /*
76  // check for less trivial cases
77  if ( Fraig_IsComplement(p1) )
78  {
79  if ( RetValue = Fraig_NodeIsInSupergate( Fraig_Regular(p1), p2 ) )
80  {
81  if ( RetValue == -1 )
82  pMan->nImplies0++;
83  else
84  pMan->nImplies1++;
85 
86  if ( RetValue == -1 )
87  return p2;
88  }
89  }
90  else
91  {
92  if ( RetValue = Fraig_NodeIsInSupergate( p1, p2 ) )
93  {
94  if ( RetValue == 1 )
95  pMan->nSimplifies1++;
96  else
97  pMan->nSimplifies0++;
98 
99  if ( RetValue == 1 )
100  return p1;
101  return Fraig_Not(pMan->pConst1);
102  }
103  }
104 
105  if ( Fraig_IsComplement(p2) )
106  {
107  if ( RetValue = Fraig_NodeIsInSupergate( Fraig_Regular(p2), p1 ) )
108  {
109  if ( RetValue == -1 )
110  pMan->nImplies0++;
111  else
112  pMan->nImplies1++;
113 
114  if ( RetValue == -1 )
115  return p1;
116  }
117  }
118  else
119  {
120  if ( RetValue = Fraig_NodeIsInSupergate( p2, p1 ) )
121  {
122  if ( RetValue == 1 )
123  pMan->nSimplifies1++;
124  else
125  pMan->nSimplifies0++;
126 
127  if ( RetValue == 1 )
128  return p2;
129  return Fraig_Not(pMan->pConst1);
130  }
131  }
132 */
133  // perform level-one structural hashing
134  if ( Fraig_HashTableLookupS( pMan, p1, p2, &pNodeNew ) ) // the node with these children is found
135  {
136  // if the existent node is part of the cone of unused logic
137  // (that is logic feeding the node which is equivalent to the given node)
138  // return the canonical representative of this node
139  // determine the phase of the given node, with respect to its canonical form
140  pNodeRepr = Fraig_Regular(pNodeNew)->pRepr;
141  if ( pMan->fFuncRed && pNodeRepr )
142  return Fraig_NotCond( pNodeRepr, Fraig_IsComplement(pNodeNew) ^ Fraig_NodeComparePhase(Fraig_Regular(pNodeNew), pNodeRepr) );
143  // otherwise, the node is itself a canonical representative, return it
144  return pNodeNew;
145  }
146  // the same node is not found, but the new one is created
147 
148  // if one level hashing is requested (without functionality hashing), return
149  if ( !pMan->fFuncRed )
150  return pNodeNew;
151 
152  // check if the new node is unique using the simulation info
153  if ( pNodeNew->nOnes == 0 || pNodeNew->nOnes == (unsigned)pMan->nWordsRand * 32 )
154  {
155  pMan->nSatZeros++;
156  if ( !pMan->fDoSparse ) // if we do not do sparse functions, skip
157  return pNodeNew;
158  // check the sparse function simulation hash table
159  pNodeOld = Fraig_HashTableLookupF0( pMan, pNodeNew );
160  if ( pNodeOld == NULL ) // the node is unique (it is added to the table)
161  return pNodeNew;
162  }
163  else
164  {
165  // check the simulation hash table
166  pNodeOld = Fraig_HashTableLookupF( pMan, pNodeNew );
167  if ( pNodeOld == NULL ) // the node is unique
168  return pNodeNew;
169  }
170  assert( pNodeOld->pRepr == 0 );
171  // there is another node which looks the same according to simulation
172 
173  // use SAT to resolve the ambiguity
174  fUseSatCheck = (pMan->nInspLimit == 0 || Fraig_ManReadInspects(pMan) < pMan->nInspLimit);
175  if ( fUseSatCheck && Fraig_NodeIsEquivalent( pMan, pNodeOld, pNodeNew, pMan->nBTLimit, 1000000 ) )
176  {
177  // set the node to be equivalent with this node
178  // to prevent loops, only set if the old node is not in the TFI of the new node
179  // the loop may happen in the following case: suppose
180  // NodeC = AND(NodeA, NodeB) and at the same time NodeA => NodeB
181  // in this case, NodeA and NodeC are functionally equivalent
182  // however, NodeA is a fanin of node NodeC (this leads to the loop)
183  // add the node to the list of equivalent nodes or dereference it
184  if ( pMan->fChoicing && !Fraig_CheckTfi( pMan, pNodeOld, pNodeNew ) )
185  {
186  // if the old node is not in the TFI of the new node and choicing
187  // is enabled, add the new node to the list of equivalent ones
188  pNodeNew->pNextE = pNodeOld->pNextE;
189  pNodeOld->pNextE = pNodeNew;
190  }
191  // set the canonical representative of this node
192  pNodeNew->pRepr = pNodeOld;
193  // return the equivalent node
194  return Fraig_NotCond( pNodeOld, Fraig_NodeComparePhase(pNodeOld, pNodeNew) );
195  }
196 
197  // now we add another member to this simulation class
198  if ( pNodeNew->nOnes == 0 || pNodeNew->nOnes == (unsigned)pMan->nWordsRand * 32 )
199  {
200  Fraig_Node_t * pNodeTemp;
201  assert( pMan->fDoSparse );
202  pNodeTemp = Fraig_HashTableLookupF0( pMan, pNodeNew );
203 // assert( pNodeTemp == NULL );
204 // Fraig_HashTableInsertF0( pMan, pNodeNew );
205  }
206  else
207  {
208  pNodeNew->pNextD = pNodeOld->pNextD;
209  pNodeOld->pNextD = pNodeNew;
210  }
211  // return the new node
212  assert( pNodeNew->pRepr == 0 );
213  return pNodeNew;
214 }
int Fraig_NodeIsEquivalent(Fraig_Man_t *p, Fraig_Node_t *pOld, Fraig_Node_t *pNew, int nBTLimit, int nTimeLimit)
Definition: fraigSat.c:302
int Fraig_NodeComparePhase(Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:154
int Fraig_CheckTfi(Fraig_Man_t *pMan, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
Definition: fraigUtil.c:173
Fraig_Node_t * pNextD
Definition: fraigInt.h:240
int Fraig_HashTableLookupS(Fraig_Man_t *pMan, Fraig_Node_t *p1, Fraig_Node_t *p2, Fraig_Node_t **ppNodeRes)
Definition: fraigTable.c:90
int Fraig_ManReadInspects(Fraig_Man_t *p)
Definition: fraigApi.c:75
#define Fraig_Not(p)
Definition: fraig.h:109
Fraig_Node_t * pNextE
Definition: fraigInt.h:241
Fraig_Node_t * Fraig_HashTableLookupF0(Fraig_Man_t *pMan, Fraig_Node_t *pNode)
Definition: fraigTable.c:193
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
Fraig_Node_t * pRepr
Definition: fraigInt.h:242
int Fraig_NodeIsConst(Fraig_Node_t *p)
Definition: fraigApi.c:151
Fraig_Node_t * Fraig_HashTableLookupF(Fraig_Man_t *pMan, Fraig_Node_t *pNode)
Definition: fraigTable.c:136
#define Fraig_Regular(p)
Definition: fraig.h:108
#define Fraig_NotCond(p, c)
Definition: fraig.h:110
#define assert(ex)
Definition: util_old.h:213
int Fraig_NodeAndSimpleCase_rec ( Fraig_Node_t pOld,
Fraig_Node_t pNew 
)
int Fraig_NodeCountPis ( Msat_IntVec_t vVars,
int  nVarsPi 
)
int Fraig_NodeCountSuppVars ( Fraig_Man_t p,
Fraig_Node_t pNode,
int  fSuppStr 
)
Fraig_Node_t* Fraig_NodeCreate ( Fraig_Man_t p,
Fraig_Node_t p1,
Fraig_Node_t p2 
)

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

Synopsis [Creates a new node.]

Description [This procedure should be called to create the constant node and the PI nodes first.]

SideEffects []

SeeAlso []

Definition at line 160 of file fraigNode.c.

161 {
162  Fraig_Node_t * pNode;
163  abctime clk;
164 
165  // create the node
166  pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
167  memset( pNode, 0, sizeof(Fraig_Node_t) );
168 
169  // assign the children
170  pNode->p1 = p1; Fraig_Ref(p1); Fraig_Regular(p1)->nRefs++;
171  pNode->p2 = p2; Fraig_Ref(p2); Fraig_Regular(p2)->nRefs++;
172 
173  // assign the number and add to the array of nodes
174  pNode->Num = p->vNodes->nSize;
175  Fraig_NodeVecPush( p->vNodes, pNode );
176 
177  // assign the PI number
178  pNode->NumPi = -1;
179 
180  // compute the level of this node
181  pNode->Level = 1 + Abc_MaxInt(Fraig_Regular(p1)->Level, Fraig_Regular(p2)->Level);
183  pNode->fFailTfo = Fraig_Regular(p1)->fFailTfo | Fraig_Regular(p2)->fFailTfo;
184 
185  // derive the simulation info
186 clk = Abc_Clock();
187  // allocate memory for the simulation info
188  pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
189  pNode->puSimD = pNode->puSimR + p->nWordsRand;
190  // derive random simulation info
191  pNode->uHashR = 0;
192  Fraig_NodeSimulate( pNode, 0, p->nWordsRand, 1 );
193  // derive dynamic simulation info
194  pNode->uHashD = 0;
195  Fraig_NodeSimulate( pNode, 0, p->iWordStart, 0 );
196  // count the number of ones in the random simulation info
197  pNode->nOnes = Fraig_BitStringCountOnes( pNode->puSimR, p->nWordsRand );
198  if ( pNode->fInv )
199  pNode->nOnes = p->nWordsRand * 32 - pNode->nOnes;
200  // add to the runtime of simulation
201 p->timeSims += Abc_Clock() - clk;
202 
203 #ifdef FRAIG_ENABLE_FANOUTS
204  // create the fanout info
207 #endif
208  return pNode;
209 }
char * memset()
void Fraig_NodeVecPush(Fraig_NodeVec_t *p, Fraig_Node_t *Entry)
Definition: fraigVec.c:189
ABC_NAMESPACE_IMPL_START void Fraig_NodeAddFaninFanout(Fraig_Node_t *pFanin, Fraig_Node_t *pFanout)
DECLARATIONS ///.
Definition: fraigFanout.c:45
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Fraig_NodeSimulate(Fraig_Node_t *pNode, int iWordStart, int iWordStop, int fUseRand)
Definition: fraigNode.c:226
unsigned * puSimD
Definition: fraigInt.h:248
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
Fraig_Node_t * p2
Definition: fraigInt.h:233
#define Fraig_Ref(p)
Definition: fraig.h:113
unsigned * puSimR
Definition: fraigInt.h:247
Fraig_Node_t * p1
Definition: fraigInt.h:232
#define Fraig_NodeIsSimComplement(p)
DECLARATIONS ///.
Definition: fraigNode.c:29
int Fraig_BitStringCountOnes(unsigned *pString, int nWords)
Definition: fraigUtil.c:288
unsigned fFailTfo
Definition: fraigInt.h:227
#define Fraig_Regular(p)
Definition: fraig.h:108
char * Fraig_MemFixedEntryFetch(Fraig_MemFixed_t *p)
Definition: fraigMem.c:131
ABC_INT64_T abctime
Definition: abc_global.h:278
Fraig_Node_t* Fraig_NodeCreateConst ( Fraig_Man_t p)

FUNCTION DEFINITIONS ///.

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

Synopsis [Creates the constant 1 node.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file fraigNode.c.

47 {
48  Fraig_Node_t * pNode;
49 
50  // create the node
51  pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
52  memset( pNode, 0, sizeof(Fraig_Node_t) );
53 
54  // assign the number and add to the array of nodes
55  pNode->Num = p->vNodes->nSize;
56  Fraig_NodeVecPush( p->vNodes, pNode );
57  pNode->NumPi = -1; // this is not a PI, so its number is -1
58  pNode->Level = 0; // just like a PI, it has 0 level
59  pNode->nRefs = 1; // it is a persistent node, which comes referenced
60  pNode->fInv = 1; // the simulation info is complemented
61 
62  // create the simulation info
63  pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
64  pNode->puSimD = pNode->puSimR + p->nWordsRand;
65  memset( pNode->puSimR, 0, sizeof(unsigned) * p->nWordsRand );
66  memset( pNode->puSimD, 0, sizeof(unsigned) * p->nWordsDyna );
67 
68  // count the number of ones in the simulation vector
69  pNode->nOnes = p->nWordsRand * sizeof(unsigned) * 8;
70 
71  // insert it into the hash table
72  Fraig_HashTableLookupF0( p, pNode );
73  return pNode;
74 }
char * memset()
void Fraig_NodeVecPush(Fraig_NodeVec_t *p, Fraig_Node_t *Entry)
Definition: fraigVec.c:189
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
Fraig_Node_t * Fraig_HashTableLookupF0(Fraig_Man_t *pMan, Fraig_Node_t *pNode)
Definition: fraigTable.c:193
char * Fraig_MemFixedEntryFetch(Fraig_MemFixed_t *p)
Definition: fraigMem.c:131
Fraig_Node_t* Fraig_NodeCreatePi ( Fraig_Man_t p)

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

Synopsis [Creates a primary input node.]

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file fraigNode.c.

88 {
89  Fraig_Node_t * pNode, * pNodeRes;
90  int i;
91  abctime clk;
92 
93  // create the node
94  pNode = (Fraig_Node_t *)Fraig_MemFixedEntryFetch( p->mmNodes );
95  memset( pNode, 0, sizeof(Fraig_Node_t) );
96  pNode->puSimR = (unsigned *)Fraig_MemFixedEntryFetch( p->mmSims );
97  pNode->puSimD = pNode->puSimR + p->nWordsRand;
98  memset( pNode->puSimD, 0, sizeof(unsigned) * p->nWordsDyna );
99 
100  // assign the number and add to the array of nodes
101  pNode->Num = p->vNodes->nSize;
102  Fraig_NodeVecPush( p->vNodes, pNode );
103 
104  // assign the PI number and add to the array of primary inputs
105  pNode->NumPi = p->vInputs->nSize;
106  Fraig_NodeVecPush( p->vInputs, pNode );
107 
108  pNode->Level = 0; // PI has 0 level
109  pNode->nRefs = 1; // it is a persistent node, which comes referenced
110  pNode->fInv = 0; // the simulation info of the PI is not complemented
111 
112  // derive the simulation info for the new node
113 clk = Abc_Clock();
114  // set the random simulation info for the primary input
115  pNode->uHashR = 0;
116  for ( i = 0; i < p->nWordsRand; i++ )
117  {
118  // generate the simulation info
119  pNode->puSimR[i] = FRAIG_RANDOM_UNSIGNED;
120  // for reasons that take very long to explain, it makes sense to have (0000000...)
121  // pattern in the set (this helps if we need to return the counter-examples)
122  if ( i == 0 )
123  pNode->puSimR[i] <<= 1;
124  // compute the hash key
125  pNode->uHashR ^= pNode->puSimR[i] * s_FraigPrimes[i];
126  }
127  // count the number of ones in the simulation vector
128  pNode->nOnes = Fraig_BitStringCountOnes( pNode->puSimR, p->nWordsRand );
129 
130  // set the systematic simulation info for the primary input
131  pNode->uHashD = 0;
132  for ( i = 0; i < p->iWordStart; i++ )
133  {
134  // generate the simulation info
135  pNode->puSimD[i] = FRAIG_RANDOM_UNSIGNED;
136  // compute the hash key
137  pNode->uHashD ^= pNode->puSimD[i] * s_FraigPrimes[i];
138  }
139 p->timeSims += Abc_Clock() - clk;
140 
141  // insert it into the hash table
142  pNodeRes = Fraig_HashTableLookupF( p, pNode );
143  assert( pNodeRes == NULL );
144  // add to the runtime of simulation
145  return pNode;
146 }
char * memset()
void Fraig_NodeVecPush(Fraig_NodeVec_t *p, Fraig_Node_t *Entry)
Definition: fraigVec.c:189
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned * puSimD
Definition: fraigInt.h:248
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned * puSimR
Definition: fraigInt.h:247
#define FRAIG_RANDOM_UNSIGNED
Definition: fraigInt.h:76
int Fraig_BitStringCountOnes(unsigned *pString, int nWords)
Definition: fraigUtil.c:288
Fraig_Node_t * Fraig_HashTableLookupF(Fraig_Man_t *pMan, Fraig_Node_t *pNode)
Definition: fraigTable.c:136
char * Fraig_MemFixedEntryFetch(Fraig_MemFixed_t *p)
Definition: fraigMem.c:131
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
int s_FraigPrimes[FRAIG_MAX_PRIMES]
DECLARATIONS ///.
Definition: fraigPrime.c:30
int Fraig_NodeGetFanoutNum ( Fraig_Node_t pNode)

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

Synopsis [Returns the number of fanouts of a node.]

Description []

SideEffects []

SeeAlso []

Definition at line 164 of file fraigFanout.c.

165 {
166  Fraig_Node_t * pFanout;
167  int Counter = 0;
168  Fraig_NodeForEachFanout( pNode, pFanout )
169  Counter++;
170  return Counter;
171 }
#define Fraig_NodeForEachFanout(pNode, pFanout)
Definition: fraigInt.h:288
static int Counter
int Fraig_NodeIsExor ( Fraig_Node_t pNode)

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

Synopsis [Returns 1 if the node is EXOR, 0 if it is NEXOR.]

Description [The node should be EXOR type and not complemented.]

SideEffects []

SeeAlso []

Definition at line 633 of file fraigUtil.c.

634 {
635  Fraig_Node_t * pNode1;
636  assert( !Fraig_IsComplement(pNode) );
637  assert( Fraig_NodeIsExorType(pNode) );
638  assert( Fraig_IsComplement(pNode->p1) );
639  // get children
640  pNode1 = Fraig_Regular(pNode->p1);
641  return Fraig_IsComplement(pNode1->p1) == Fraig_IsComplement(pNode1->p2);
642 }
int Fraig_NodeIsExorType(Fraig_Node_t *pNode)
Definition: fraigUtil.c:558
Fraig_Node_t * p2
Definition: fraigInt.h:233
Fraig_Node_t * p1
Definition: fraigInt.h:232
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
int Fraig_NodeIsExorType ( Fraig_Node_t pNode)

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

Synopsis [Returns 1 if the node is the root of EXOR/NEXOR gate.]

Description [The node can be complemented.]

SideEffects []

SeeAlso []

Definition at line 558 of file fraigUtil.c.

559 {
560  Fraig_Node_t * pNode1, * pNode2;
561  // make the node regular (it does not matter for EXOR/NEXOR)
562  pNode = Fraig_Regular(pNode);
563  // if the node or its children are not ANDs or not compl, this cannot be EXOR type
564  if ( !Fraig_NodeIsAnd(pNode) )
565  return 0;
566  if ( !Fraig_NodeIsAnd(pNode->p1) || !Fraig_IsComplement(pNode->p1) )
567  return 0;
568  if ( !Fraig_NodeIsAnd(pNode->p2) || !Fraig_IsComplement(pNode->p2) )
569  return 0;
570 
571  // get children
572  pNode1 = Fraig_Regular(pNode->p1);
573  pNode2 = Fraig_Regular(pNode->p2);
574  assert( pNode1->Num < pNode2->Num );
575 
576  // compare grandchildren
577  return pNode1->p1 == Fraig_Not(pNode2->p1) && pNode1->p2 == Fraig_Not(pNode2->p2);
578 }
Fraig_Node_t * p2
Definition: fraigInt.h:233
#define Fraig_Not(p)
Definition: fraig.h:109
Fraig_Node_t * p1
Definition: fraigInt.h:232
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
int Fraig_NodeIsImplication ( Fraig_Man_t p,
Fraig_Node_t pOld,
Fraig_Node_t pNew,
int  nBTLimit 
)

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

Synopsis [Checks whether pOld => pNew.]

Description []

SideEffects []

SeeAlso []

Definition at line 551 of file fraigSat.c.

552 {
553  int RetValue, RetValue1, i, fComp;
554  abctime clk;
555  int fVerbose = 0;
556 
557  // make sure the nodes are not complemented
558  assert( !Fraig_IsComplement(pNew) );
559  assert( !Fraig_IsComplement(pOld) );
560  assert( pNew != pOld );
561 
562  p->nSatCallsImp++;
563 
564  // make sure the solver is allocated and has enough variables
565  if ( p->pSat == NULL )
567  // make sure the SAT solver has enough variables
568  for ( i = Msat_SolverReadVarNum(p->pSat); i < p->vNodes->nSize; i++ )
569  Msat_SolverAddVar( p->pSat, p->vNodes->pArray[i]->Level );
570 
571  // get the logic cone
572 clk = Abc_Clock();
573  Fraig_OrderVariables( p, pOld, pNew );
574 // Fraig_PrepareCones( p, pOld, pNew );
575 p->timeTrav += Abc_Clock() - clk;
576 
577 if ( fVerbose )
578  printf( "%d(%d) - ", Fraig_CountPis(p,p->vVarsInt), Msat_IntVecReadSize(p->vVarsInt) );
579 
580 
581  // get the complemented attribute
582  fComp = Fraig_NodeComparePhase( pOld, pNew );
583 //Msat_SolverPrintClauses( p->pSat );
584 
585  ////////////////////////////////////////////
586  // prepare the solver to run incrementally on these variables
587 //clk = Abc_Clock();
588  Msat_SolverPrepare( p->pSat, p->vVarsInt );
589 //p->time3 += Abc_Clock() - clk;
590 
591  // solve under assumptions
592  // A = 1; B = 0 OR A = 1; B = 1
593  Msat_IntVecClear( p->vProj );
594  Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pOld->Num, 0) );
595  Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNew->Num, !fComp) );
596  // run the solver
597 clk = Abc_Clock();
598  RetValue1 = Msat_SolverSolve( p->pSat, p->vProj, nBTLimit, 1000000 );
599 p->timeSat += Abc_Clock() - clk;
600 
601  if ( RetValue1 == MSAT_FALSE )
602  {
603 //p->time1 += Abc_Clock() - clk;
604 
605 if ( fVerbose )
606 {
607 // printf( "unsat %d ", Msat_SolverReadBackTracks(p->pSat) );
608 //ABC_PRT( "time", Abc_Clock() - clk );
609 }
610 
611  // add the clause
612  Msat_IntVecClear( p->vProj );
613  Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pOld->Num, 1) );
614  Msat_IntVecPush( p->vProj, MSAT_VAR2LIT(pNew->Num, fComp) );
615  RetValue = Msat_SolverAddClause( p->pSat, p->vProj );
616  assert( RetValue );
617 // p->nSatProofImp++;
618  return 1;
619  }
620  else if ( RetValue1 == MSAT_TRUE )
621  {
622 //p->time2 += Abc_Clock() - clk;
623 
624 if ( fVerbose )
625 {
626 // printf( "sat %d ", Msat_SolverReadBackTracks(p->pSat) );
627 //ABC_PRT( "time", Abc_Clock() - clk );
628 }
629  // record the counter example
630  Fraig_FeedBack( p, Msat_SolverReadModelArray(p->pSat), p->vVarsInt, pOld, pNew );
631  p->nSatCounterImp++;
632  return 0;
633  }
634  else // if ( RetValue1 == MSAT_UNKNOWN )
635  {
636 p->time3 += Abc_Clock() - clk;
637  p->nSatFailsImp++;
638  return 0;
639  }
640 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int * Msat_SolverReadModelArray(Msat_Solver_t *p)
Definition: msatSolverApi.c:57
int Msat_SolverAddClause(Msat_Solver_t *p, Msat_IntVec_t *pLits)
int Fraig_NodeComparePhase(Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:154
void Msat_IntVecClear(Msat_IntVec_t *p)
Definition: msatVec.c:335
Definition: msat.h:50
static abctime Abc_Clock()
Definition: abc_global.h:279
int Fraig_CountPis(Fraig_Man_t *p, Msat_IntVec_t *vVarNums)
Definition: fraigUtil.c:817
int Msat_SolverAddVar(Msat_Solver_t *p, int Level)
DECLARATIONS ///.
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition: msatVec.c:233
void Msat_IntVecPush(Msat_IntVec_t *p, int Entry)
Definition: msatVec.c:351
void Msat_SolverPrepare(Msat_Solver_t *pSat, Msat_IntVec_t *vVars)
void Fraig_ManCreateSolver(Fraig_Man_t *p)
Definition: fraigMan.c:325
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
int Msat_SolverReadVarNum(Msat_Solver_t *p)
FUNCTION DEFINITIONS ///.
Definition: msatSolverApi.c:47
#define MSAT_VAR2LIT(v, s)
Definition: msat.h:56
#define assert(ex)
Definition: util_old.h:213
static ABC_NAMESPACE_IMPL_START void Fraig_OrderVariables(Fraig_Man_t *pMan, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
DECLARATIONS ///.
Definition: fraigSat.c:875
void Fraig_FeedBack(Fraig_Man_t *p, int *pModel, Msat_IntVec_t *vVars, Fraig_Node_t *pOld, Fraig_Node_t *pNew)
Definition: fraigFeed.c:80
ABC_INT64_T abctime
Definition: abc_global.h:278
int Msat_SolverSolve(Msat_Solver_t *p, Msat_IntVec_t *pVecAssumps, int nBackTrackLimit, int nTimeLimit)
int Fraig_NodeIsInSupergate ( Fraig_Node_t pOld,
Fraig_Node_t pNew 
)

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

Synopsis [Checks if pNew exists among the implication fanins of pOld.]

Description [If pNew is an implication fanin of pOld, returns 1. If Fraig_Not(pNew) is an implication fanin of pOld, return -1. Otherwise returns 0.]

SideEffects []

SeeAlso []

Definition at line 905 of file fraigUtil.c.

906 {
907  int RetValue1, RetValue2;
908  if ( Fraig_Regular(pOld) == Fraig_Regular(pNew) )
909  return (pOld == pNew)? 1 : -1;
910  if ( Fraig_IsComplement(pOld) || Fraig_NodeIsVar(pOld) )
911  return 0;
912  RetValue1 = Fraig_NodeIsInSupergate( pOld->p1, pNew );
913  RetValue2 = Fraig_NodeIsInSupergate( pOld->p2, pNew );
914  if ( RetValue1 == -1 || RetValue2 == -1 )
915  return -1;
916  if ( RetValue1 == 1 || RetValue2 == 1 )
917  return 1;
918  return 0;
919 }
Fraig_Node_t * p2
Definition: fraigInt.h:233
Fraig_Node_t * p1
Definition: fraigInt.h:232
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
int Fraig_NodeIsInSupergate(Fraig_Node_t *pOld, Fraig_Node_t *pNew)
Definition: fraigUtil.c:905
#define Fraig_Regular(p)
Definition: fraig.h:108
int Fraig_NodeIsVar(Fraig_Node_t *p)
Definition: fraigApi.c:152
int Fraig_NodeIsMuxType ( Fraig_Node_t pNode)

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

Synopsis [Returns 1 if the node is the root of MUX or EXOR/NEXOR.]

Description [The node can be complemented.]

SideEffects []

SeeAlso []

Definition at line 591 of file fraigUtil.c.

592 {
593  Fraig_Node_t * pNode1, * pNode2;
594 
595  // make the node regular (it does not matter for EXOR/NEXOR)
596  pNode = Fraig_Regular(pNode);
597  // if the node or its children are not ANDs or not compl, this cannot be EXOR type
598  if ( !Fraig_NodeIsAnd(pNode) )
599  return 0;
600  if ( !Fraig_NodeIsAnd(pNode->p1) || !Fraig_IsComplement(pNode->p1) )
601  return 0;
602  if ( !Fraig_NodeIsAnd(pNode->p2) || !Fraig_IsComplement(pNode->p2) )
603  return 0;
604 
605  // get children
606  pNode1 = Fraig_Regular(pNode->p1);
607  pNode2 = Fraig_Regular(pNode->p2);
608  assert( pNode1->Num < pNode2->Num );
609 
610  // compare grandchildren
611  // node is an EXOR/NEXOR
612  if ( pNode1->p1 == Fraig_Not(pNode2->p1) && pNode1->p2 == Fraig_Not(pNode2->p2) )
613  return 1;
614 
615  // otherwise the node is MUX iff it has a pair of equal grandchildren
616  return pNode1->p1 == Fraig_Not(pNode2->p1) ||
617  pNode1->p1 == Fraig_Not(pNode2->p2) ||
618  pNode1->p2 == Fraig_Not(pNode2->p1) ||
619  pNode1->p2 == Fraig_Not(pNode2->p2);
620 }
Fraig_Node_t * p2
Definition: fraigInt.h:233
#define Fraig_Not(p)
Definition: fraig.h:109
Fraig_Node_t * p1
Definition: fraigInt.h:232
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
int Fraig_NodeIsTravIdCurrent ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 1012 of file fraigUtil.c.

1013 {
1014  return pNode->TravId2 == pMan->nTravIds2;
1015 }
int Fraig_NodeIsTravIdPrevious ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 1028 of file fraigUtil.c.

1029 {
1030  return pNode->TravId2 == pMan->nTravIds2 - 1;
1031 }
Fraig_Node_t* Fraig_NodeRecognizeMux ( Fraig_Node_t pNode,
Fraig_Node_t **  ppNodeT,
Fraig_Node_t **  ppNodeE 
)

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

Synopsis [Recognizes what nodes are control and data inputs of a MUX.]

Description [If the node is a MUX, returns the control variable C. Assigns nodes T and E to be the then and else variables of the MUX. Node C is never complemented. Nodes T and E can be complemented. This function also recognizes EXOR/NEXOR gates as MUXes.]

SideEffects []

SeeAlso []

Definition at line 658 of file fraigUtil.c.

659 {
660  Fraig_Node_t * pNode1, * pNode2;
661  assert( !Fraig_IsComplement(pNode) );
662  assert( Fraig_NodeIsMuxType(pNode) );
663  // get children
664  pNode1 = Fraig_Regular(pNode->p1);
665  pNode2 = Fraig_Regular(pNode->p2);
666  // find the control variable
667  if ( pNode1->p1 == Fraig_Not(pNode2->p1) )
668  {
669  if ( Fraig_IsComplement(pNode1->p1) )
670  { // pNode2->p1 is positive phase of C
671  *ppNodeT = Fraig_Not(pNode2->p2);
672  *ppNodeE = Fraig_Not(pNode1->p2);
673  return pNode2->p1;
674  }
675  else
676  { // pNode1->p1 is positive phase of C
677  *ppNodeT = Fraig_Not(pNode1->p2);
678  *ppNodeE = Fraig_Not(pNode2->p2);
679  return pNode1->p1;
680  }
681  }
682  else if ( pNode1->p1 == Fraig_Not(pNode2->p2) )
683  {
684  if ( Fraig_IsComplement(pNode1->p1) )
685  { // pNode2->p2 is positive phase of C
686  *ppNodeT = Fraig_Not(pNode2->p1);
687  *ppNodeE = Fraig_Not(pNode1->p2);
688  return pNode2->p2;
689  }
690  else
691  { // pNode1->p1 is positive phase of C
692  *ppNodeT = Fraig_Not(pNode1->p2);
693  *ppNodeE = Fraig_Not(pNode2->p1);
694  return pNode1->p1;
695  }
696  }
697  else if ( pNode1->p2 == Fraig_Not(pNode2->p1) )
698  {
699  if ( Fraig_IsComplement(pNode1->p2) )
700  { // pNode2->p1 is positive phase of C
701  *ppNodeT = Fraig_Not(pNode2->p2);
702  *ppNodeE = Fraig_Not(pNode1->p1);
703  return pNode2->p1;
704  }
705  else
706  { // pNode1->p2 is positive phase of C
707  *ppNodeT = Fraig_Not(pNode1->p1);
708  *ppNodeE = Fraig_Not(pNode2->p2);
709  return pNode1->p2;
710  }
711  }
712  else if ( pNode1->p2 == Fraig_Not(pNode2->p2) )
713  {
714  if ( Fraig_IsComplement(pNode1->p2) )
715  { // pNode2->p2 is positive phase of C
716  *ppNodeT = Fraig_Not(pNode2->p1);
717  *ppNodeE = Fraig_Not(pNode1->p1);
718  return pNode2->p2;
719  }
720  else
721  { // pNode1->p2 is positive phase of C
722  *ppNodeT = Fraig_Not(pNode1->p1);
723  *ppNodeE = Fraig_Not(pNode2->p1);
724  return pNode1->p2;
725  }
726  }
727  assert( 0 ); // this is not MUX
728  return NULL;
729 }
Fraig_Node_t * p2
Definition: fraigInt.h:233
#define Fraig_Not(p)
Definition: fraig.h:109
int Fraig_NodeIsMuxType(Fraig_Node_t *pNode)
Definition: fraigUtil.c:591
Fraig_Node_t * p1
Definition: fraigInt.h:232
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
void Fraig_NodeRemoveFaninFanout ( Fraig_Node_t pFanin,
Fraig_Node_t pFanoutToRemove 
)

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

Synopsis [Add the fanout to the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 101 of file fraigFanout.c.

102 {
103  Fraig_Node_t * pFanout, * pFanout2, ** ppFanList;
104  // start the linked list of fanouts
105  ppFanList = &pFanin->pFanPivot;
106  // go through the fanouts
107  Fraig_NodeForEachFanoutSafe( pFanin, pFanout, pFanout2 )
108  {
109  // skip the fanout-to-remove
110  if ( pFanout == pFanoutToRemove )
111  continue;
112  // add useful fanouts to the list
113  *ppFanList = pFanout;
114  ppFanList = Fraig_NodeReadNextFanoutPlace( pFanin, pFanout );
115  }
116  *ppFanList = NULL;
117 }
#define Fraig_NodeReadNextFanoutPlace(pNode, pFanout)
Definition: fraigInt.h:284
#define Fraig_NodeForEachFanoutSafe(pNode, pFanout, pFanout2)
Definition: fraigInt.h:292
Fraig_Node_t * pFanPivot
Definition: fraigInt.h:256
int Fraig_NodesCompareSupps ( Fraig_Man_t p,
Fraig_Node_t pOld,
Fraig_Node_t pNew 
)
void Fraig_NodeSetTravIdCurrent ( Fraig_Man_t pMan,
Fraig_Node_t pNode 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 996 of file fraigUtil.c.

997 {
998  pNode->TravId2 = pMan->nTravIds2;
999 }
int Fraig_NodeSimsContained ( Fraig_Man_t pMan,
Fraig_Node_t pNode1,
Fraig_Node_t pNode2 
)

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

Synopsis [Returns 1 if siminfo of Node1 is contained in siminfo of Node2.]

Description []

SideEffects []

SeeAlso []

Definition at line 784 of file fraigUtil.c.

785 {
786  unsigned * pUnsigned1, * pUnsigned2;
787  int i;
788 
789  // compare random siminfo
790  pUnsigned1 = pNode1->puSimR;
791  pUnsigned2 = pNode2->puSimR;
792  for ( i = 0; i < pMan->nWordsRand; i++ )
793  if ( pUnsigned1[i] & ~pUnsigned2[i] )
794  return 0;
795 
796  // compare systematic siminfo
797  pUnsigned1 = pNode1->puSimD;
798  pUnsigned2 = pNode2->puSimD;
799  for ( i = 0; i < pMan->iWordStart; i++ )
800  if ( pUnsigned1[i] & ~pUnsigned2[i] )
801  return 0;
802 
803  return 1;
804 }
unsigned * puSimD
Definition: fraigInt.h:248
unsigned * puSimR
Definition: fraigInt.h:247
void Fraig_NodeSimulate ( Fraig_Node_t pNode,
int  iWordStart,
int  iWordStop,
int  fUseRand 
)

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

Synopsis [Simulates the node.]

Description [Simulates the random or dynamic simulation info through the node. Uses phases of the children to determine their real simulation info. Uses phase of the node to determine the way its simulation info is stored. The resulting info is guaranteed to be 0 for the first pattern.]

SideEffects [This procedure modified the hash value of the simulation info.]

SeeAlso []

Definition at line 226 of file fraigNode.c.

227 {
228  unsigned * pSims, * pSims1, * pSims2;
229  unsigned uHash;
230  int fCompl, fCompl1, fCompl2, i;
231 
232  assert( !Fraig_IsComplement(pNode) );
233 
234  // get hold of the simulation information
235  pSims = fUseRand? pNode->puSimR : pNode->puSimD;
236  pSims1 = fUseRand? Fraig_Regular(pNode->p1)->puSimR : Fraig_Regular(pNode->p1)->puSimD;
237  pSims2 = fUseRand? Fraig_Regular(pNode->p2)->puSimR : Fraig_Regular(pNode->p2)->puSimD;
238 
239  // get complemented attributes of the children using their random info
240  fCompl = pNode->fInv;
241  fCompl1 = Fraig_NodeIsSimComplement(pNode->p1);
242  fCompl2 = Fraig_NodeIsSimComplement(pNode->p2);
243 
244  // simulate
245  uHash = 0;
246  if ( fCompl1 && fCompl2 )
247  {
248  if ( fCompl )
249  for ( i = iWordStart; i < iWordStop; i++ )
250  {
251  pSims[i] = (pSims1[i] | pSims2[i]);
252  uHash ^= pSims[i] * s_FraigPrimes[i];
253  }
254  else
255  for ( i = iWordStart; i < iWordStop; i++ )
256  {
257  pSims[i] = ~(pSims1[i] | pSims2[i]);
258  uHash ^= pSims[i] * s_FraigPrimes[i];
259  }
260  }
261  else if ( fCompl1 && !fCompl2 )
262  {
263  if ( fCompl )
264  for ( i = iWordStart; i < iWordStop; i++ )
265  {
266  pSims[i] = (pSims1[i] | ~pSims2[i]);
267  uHash ^= pSims[i] * s_FraigPrimes[i];
268  }
269  else
270  for ( i = iWordStart; i < iWordStop; i++ )
271  {
272  pSims[i] = (~pSims1[i] & pSims2[i]);
273  uHash ^= pSims[i] * s_FraigPrimes[i];
274  }
275  }
276  else if ( !fCompl1 && fCompl2 )
277  {
278  if ( fCompl )
279  for ( i = iWordStart; i < iWordStop; i++ )
280  {
281  pSims[i] = (~pSims1[i] | pSims2[i]);
282  uHash ^= pSims[i] * s_FraigPrimes[i];
283  }
284  else
285  for ( i = iWordStart; i < iWordStop; i++ )
286  {
287  pSims[i] = (pSims1[i] & ~pSims2[i]);
288  uHash ^= pSims[i] * s_FraigPrimes[i];
289  }
290  }
291  else // if ( !fCompl1 && !fCompl2 )
292  {
293  if ( fCompl )
294  for ( i = iWordStart; i < iWordStop; i++ )
295  {
296  pSims[i] = ~(pSims1[i] & pSims2[i]);
297  uHash ^= pSims[i] * s_FraigPrimes[i];
298  }
299  else
300  for ( i = iWordStart; i < iWordStop; i++ )
301  {
302  pSims[i] = (pSims1[i] & pSims2[i]);
303  uHash ^= pSims[i] * s_FraigPrimes[i];
304  }
305  }
306 
307  if ( fUseRand )
308  pNode->uHashR ^= uHash;
309  else
310  pNode->uHashD ^= uHash;
311 }
unsigned * puSimD
Definition: fraigInt.h:248
Fraig_Node_t * p2
Definition: fraigInt.h:233
unsigned * puSimR
Definition: fraigInt.h:247
Fraig_Node_t * p1
Definition: fraigInt.h:232
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define Fraig_NodeIsSimComplement(p)
DECLARATIONS ///.
Definition: fraigNode.c:29
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
int s_FraigPrimes[FRAIG_MAX_PRIMES]
DECLARATIONS ///.
Definition: fraigPrime.c:30
void Fraig_NodeVecSortByRefCount ( Fraig_NodeVec_t p)

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

Synopsis [Sorting the entries by their integer value.]

Description []

SideEffects []

SeeAlso []

Definition at line 539 of file fraigVec.c.

540 {
541  qsort( (void *)p->pArray, p->nSize, sizeof(Fraig_Node_t *),
542  (int (*)(const void *, const void *)) Fraig_NodeVecCompareRefCounts );
543 }
Fraig_Node_t ** pArray
Definition: fraigInt.h:267
int Fraig_NodeVecCompareRefCounts(Fraig_Node_t **pp1, Fraig_Node_t **pp2)
Definition: fraigVec.c:470
void Fraig_PrintBinary ( FILE *  pFile,
unsigned *  pSign,
int  nBits 
)

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

Synopsis [Prints the bit string.]

Description []

SideEffects []

SeeAlso []

Definition at line 402 of file fraigUtil.c.

403 {
404  int Remainder, nWords;
405  int w, i;
406 
407  Remainder = (nBits%(sizeof(unsigned)*8));
408  nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
409 
410  for ( w = nWords-1; w >= 0; w-- )
411  for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
412  fprintf( pFile, "%c", '0' + (int)((pSign[w] & (1<<i)) > 0) );
413 
414 // fprintf( pFile, "\n" );
415 }
int nWords
Definition: abcNpn.c:127
void Fraig_TablePrintStatsF ( Fraig_Man_t pMan)

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

Synopsis [Prints stats of the structural table.]

Description []

SideEffects []

SeeAlso []

Definition at line 537 of file fraigTable.c.

538 {
539  Fraig_HashTable_t * pT = pMan->pTableF;
540  Fraig_Node_t * pNode;
541  int i, Counter;
542 
543  printf( "Functional table. Table size = %d. Number of entries = %d.\n", pT->nBins, pT->nEntries );
544  for ( i = 0; i < pT->nBins; i++ )
545  {
546  Counter = 0;
547  Fraig_TableBinForEachEntryF( pT->pBins[i], pNode )
548  Counter++;
549  if ( Counter > 1 )
550  printf( "{%d} ", Counter );
551  }
552  printf( "\n" );
553 }
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
Definition: fraigInt.h:312
if(last==0)
Definition: sparse_int.h:34
static int Counter
void Fraig_TablePrintStatsF0 ( Fraig_Man_t pMan)

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

Synopsis [Prints stats of the structural table.]

Description []

SideEffects []

SeeAlso []

Definition at line 566 of file fraigTable.c.

567 {
568  Fraig_HashTable_t * pT = pMan->pTableF0;
569  Fraig_Node_t * pNode;
570  int i, Counter;
571 
572  printf( "Zero-node table. Table size = %d. Number of entries = %d.\n", pT->nBins, pT->nEntries );
573  for ( i = 0; i < pT->nBins; i++ )
574  {
575  Counter = 0;
576  Fraig_TableBinForEachEntryF( pT->pBins[i], pNode )
577  Counter++;
578  if ( Counter == 0 )
579  continue;
580 /*
581  printf( "\nBin = %4d : Number of entries = %4d\n", i, Counter );
582  Fraig_TableBinForEachEntryF( pT->pBins[i], pNode )
583  printf( "Node %5d. Hash = %10d.\n", pNode->Num, pNode->uHashD );
584 */
585  }
586  printf( "\n" );
587 }
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
Definition: fraigInt.h:312
if(last==0)
Definition: sparse_int.h:34
static int Counter
void Fraig_TablePrintStatsS ( Fraig_Man_t pMan)

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

Synopsis [Prints stats of the structural table.]

Description []

SideEffects []

SeeAlso []

Definition at line 504 of file fraigTable.c.

505 {
506  Fraig_HashTable_t * pT = pMan->pTableS;
507  Fraig_Node_t * pNode;
508  int i, Counter;
509 
510  printf( "Structural table. Table size = %d. Number of entries = %d.\n", pT->nBins, pT->nEntries );
511  for ( i = 0; i < pT->nBins; i++ )
512  {
513  Counter = 0;
514  Fraig_TableBinForEachEntryS( pT->pBins[i], pNode )
515  Counter++;
516  if ( Counter > 1 )
517  {
518  printf( "%d ", Counter );
519  if ( Counter > 50 )
520  printf( "{%d} ", i );
521  }
522  }
523  printf( "\n" );
524 }
#define Fraig_TableBinForEachEntryS(pBin, pEnt)
Definition: fraigInt.h:301
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
if(last==0)
Definition: sparse_int.h:34
static int Counter
int Fraig_TableRehashF0 ( Fraig_Man_t pMan,
int  fLinkEquiv 
)

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

Synopsis [Rehashes the table after the simulation info has changed.]

Description [Assumes that the hash values have been updated after performing additional simulation. Rehashes the table using the new hash values. Uses pNextF to link the entries in the bins. Uses pNextD to link the entries with identical hash values. Returns 1 if the identical entries have been found. Note that identical hash values may mean that the simulation data is different.]

SideEffects []

SeeAlso []

Definition at line 604 of file fraigTable.c.

605 {
606  Fraig_HashTable_t * pT = pMan->pTableF0;
607  Fraig_Node_t ** pBinsNew;
608  Fraig_Node_t * pEntF, * pEntF2, * pEnt, * pEntD2, * pEntN;
609  int ReturnValue, Counter, i;
610  unsigned Key;
611 
612  // allocate a new array of bins
613  pBinsNew = ABC_ALLOC( Fraig_Node_t *, pT->nBins );
614  memset( pBinsNew, 0, sizeof(Fraig_Node_t *) * pT->nBins );
615 
616  // rehash the entries in the table
617  // go through all the nodes in the F-lists (and possible in D-lists, if used)
618  Counter = 0;
619  ReturnValue = 0;
620  for ( i = 0; i < pT->nBins; i++ )
621  Fraig_TableBinForEachEntrySafeF( pT->pBins[i], pEntF, pEntF2 )
622  Fraig_TableBinForEachEntrySafeD( pEntF, pEnt, pEntD2 )
623  {
624  // decide where to put entry pEnt
625  Key = pEnt->uHashD % pT->nBins;
626  if ( fLinkEquiv )
627  {
628  // go through the entries in the new bin
629  Fraig_TableBinForEachEntryF( pBinsNew[Key], pEntN )
630  {
631  // if they have different values skip
632  if ( pEnt->uHashD != pEntN->uHashD )
633  continue;
634  // they have the same hash value, add pEnt to the D-list pEnt3
635  pEnt->pNextD = pEntN->pNextD;
636  pEntN->pNextD = pEnt;
637  ReturnValue = 1;
638  Counter++;
639  break;
640  }
641  if ( pEntN != NULL ) // already linked
642  continue;
643  // we did not find equal entry
644  }
645  // link the new entry
646  pEnt->pNextF = pBinsNew[Key];
647  pBinsNew[Key] = pEnt;
648  pEnt->pNextD = NULL;
649  Counter++;
650  }
651  assert( Counter == pT->nEntries );
652  // replace the table and the parameters
653  ABC_FREE( pT->pBins );
654  pT->pBins = pBinsNew;
655  return ReturnValue;
656 }
char * memset()
#define Fraig_TableBinForEachEntrySafeF(pBin, pEnt, pEnt2)
Definition: fraigInt.h:316
Fraig_Node_t ** pBins
Definition: fraigInt.h:273
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Fraig_Node_t * pNextD
Definition: fraigInt.h:240
Fraig_Node_t * pNextF
Definition: fraigInt.h:239
#define Fraig_TableBinForEachEntryF(pBin, pEnt)
Definition: fraigInt.h:312
#define Fraig_TableBinForEachEntrySafeD(pBin, pEnt, pEnt2)
Definition: fraigInt.h:327
static int Counter
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213

Variable Documentation

int s_FraigPrimes[FRAIG_MAX_PRIMES]

DECLARATIONS ///.

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

FileName [fraigPrime.c]

PackageName [FRAIG: Functionally reduced AND-INV graphs.]

Synopsis [The table of the first 1000 primes.]

Author [Alan Mishchenko alanm.nosp@m.i@ee.nosp@m.cs.be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - October 1, 2004]

Revision [

Id:
fraigPrime.c,v 1.4 2005/07/08 01:01:32 alanmi Exp

]

Definition at line 30 of file fraigPrime.c.