abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cnf.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/vec/vec.h"
#include "aig/aig/aig.h"
#include "opt/dar/darInt.h"

Go to the source code of this file.

Data Structures

struct  Cnf_Dat_t_
 
struct  Cnf_Cut_t_
 
struct  Cnf_Man_t_
 

Macros

#define Cnf_CnfForClause(p, pBeg, pEnd, i)   for ( i = 0; i < p->nClauses && (pBeg = p->pClauses[i]) && (pEnd = p->pClauses[i+1]); i++ )
 MACRO DEFINITIONS ///. More...
 
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)   for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ )
 

Typedefs

typedef
typedefABC_NAMESPACE_HEADER_START
struct Cnf_Man_t_ 
Cnf_Man_t
 INCLUDES ///. More...
 
typedef struct Cnf_Dat_t_ Cnf_Dat_t
 
typedef struct Cnf_Cut_t_ Cnf_Cut_t
 

Functions

static Dar_Cut_tDar_ObjBestCut (Aig_Obj_t *pObj)
 
static int Cnf_CutSopCost (Cnf_Man_t *p, Dar_Cut_t *pCut)
 
static int Cnf_CutLeaveNum (Cnf_Cut_t *pCut)
 
static int * Cnf_CutLeaves (Cnf_Cut_t *pCut)
 
static unsigned * Cnf_CutTruth (Cnf_Cut_t *pCut)
 
static Cnf_Cut_tCnf_ObjBestCut (Aig_Obj_t *pObj)
 
static void Cnf_ObjSetBestCut (Aig_Obj_t *pObj, Cnf_Cut_t *pCut)
 
Vec_Int_tCnf_DeriveMappingArray (Aig_Man_t *pAig)
 FUNCTION DECLARATIONS ///. More...
 
Cnf_Dat_tCnf_Derive (Aig_Man_t *pAig, int nOutputs)
 
Cnf_Dat_tCnf_DeriveWithMan (Cnf_Man_t *p, Aig_Man_t *pAig, int nOutputs)
 
Cnf_Dat_tCnf_DeriveOther (Aig_Man_t *pAig, int fSkipTtMin)
 
Cnf_Dat_tCnf_DeriveOtherWithMan (Cnf_Man_t *p, Aig_Man_t *pAig, int fSkipTtMin)
 
void Cnf_ManPrepare ()
 FUNCTION DEFINITIONS ///. More...
 
Cnf_Man_tCnf_ManRead ()
 
void Cnf_ManFree ()
 
Cnf_Cut_tCnf_CutCreate (Cnf_Man_t *p, Aig_Obj_t *pObj)
 
void Cnf_CutPrint (Cnf_Cut_t *pCut)
 
void Cnf_CutFree (Cnf_Cut_t *pCut)
 
void Cnf_CutUpdateRefs (Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, Cnf_Cut_t *pCutRes)
 
Cnf_Cut_tCnf_CutCompose (Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, int iFan)
 
void Cnf_ReadMsops (char **ppSopSizes, char ***ppSops)
 FUNCTION DEFINITIONS ///. More...
 
void Cnf_CollectLeaves (Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
 
void Cnf_ComputeClauses (Aig_Man_t *p, Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes, Vec_Int_t *vMap, Vec_Int_t *vCover, Vec_Int_t *vClauses)
 
void Cnf_DeriveFastMark (Aig_Man_t *p)
 
Cnf_Dat_tCnf_DeriveFast (Aig_Man_t *p, int nOutputs)
 
Cnf_Man_tCnf_ManStart ()
 FUNCTION DEFINITIONS ///. More...
 
void Cnf_ManStop (Cnf_Man_t *p)
 
Vec_Int_tCnf_DataCollectPiSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
Cnf_Dat_tCnf_DataAlloc (Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
 
Cnf_Dat_tCnf_DataDup (Cnf_Dat_t *p)
 
void Cnf_DataFree (Cnf_Dat_t *p)
 
void Cnf_DataLift (Cnf_Dat_t *p, int nVarsPlus)
 
void Cnf_DataFlipLastLiteral (Cnf_Dat_t *p)
 
void Cnf_DataPrint (Cnf_Dat_t *p, int fReadable)
 
void Cnf_DataWriteIntoFile (Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
 
void * Cnf_DataWriteIntoSolver (Cnf_Dat_t *p, int nFrames, int fInit)
 
void * Cnf_DataWriteIntoSolverInt (void *pSat, Cnf_Dat_t *p, int nFrames, int fInit)
 
int Cnf_DataWriteOrClause (void *pSat, Cnf_Dat_t *pCnf)
 
int Cnf_DataWriteAndClauses (void *p, Cnf_Dat_t *pCnf)
 
void Cnf_DataTranformPolarity (Cnf_Dat_t *pCnf, int fTransformPos)
 
int Cnf_DataAddXorClause (void *pSat, int iVarA, int iVarB, int iVarC)
 
void Cnf_DeriveMapping (Cnf_Man_t *p)
 
int Cnf_ManMapForCnf (Cnf_Man_t *p)
 
void Cnf_ManTransferCuts (Cnf_Man_t *p)
 
void Cnf_ManFreeCuts (Cnf_Man_t *p)
 
void Cnf_ManPostprocess (Cnf_Man_t *p)
 
Vec_Ptr_tAig_ManScanMapping (Cnf_Man_t *p, int fCollect)
 
Vec_Ptr_tCnf_ManScanMapping (Cnf_Man_t *p, int fCollect, int fPreorder)
 
Vec_Int_tCnf_DataCollectCiSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
Vec_Int_tCnf_DataCollectCoSatNums (Cnf_Dat_t *pCnf, Aig_Man_t *p)
 
unsigned char * Cnf_DataDeriveLitPolarities (Cnf_Dat_t *p)
 
Cnf_Dat_tCnf_DataReadFromFile (char *pFileName)
 
Vec_Int_tCnf_ManWriteCnfMapping (Cnf_Man_t *p, Vec_Ptr_t *vMapped)
 DECLARATIONS ///. More...
 
void Cnf_SopConvertToVector (char *pSop, int nCubes, Vec_Int_t *vCover)
 
Cnf_Dat_tCnf_ManWriteCnf (Cnf_Man_t *p, Vec_Ptr_t *vMapped, int nOutputs)
 
Cnf_Dat_tCnf_ManWriteCnfOther (Cnf_Man_t *p, Vec_Ptr_t *vMapped)
 
Cnf_Dat_tCnf_DeriveSimple (Aig_Man_t *p, int nOutputs)
 
Cnf_Dat_tCnf_DeriveSimpleForRetiming (Aig_Man_t *p)
 

Macro Definition Documentation

#define Cnf_CnfForClause (   p,
  pBeg,
  pEnd,
 
)    for ( i = 0; i < p->nClauses && (pBeg = p->pClauses[i]) && (pEnd = p->pClauses[i+1]); i++ )

MACRO DEFINITIONS ///.

ITERATORS ///

Definition at line 117 of file cnf.h.

#define Cnf_CutForEachLeaf (   p,
  pCut,
  pLeaf,
 
)    for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ )

Definition at line 121 of file cnf.h.

Typedef Documentation

typedef struct Cnf_Cut_t_ Cnf_Cut_t

Definition at line 53 of file cnf.h.

typedef struct Cnf_Dat_t_ Cnf_Dat_t

Definition at line 52 of file cnf.h.

typedef typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t

INCLUDES ///.

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

FileName [cnf.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [DAG-aware AIG rewriting.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
cnf.h,v 1.00 2007/04/28 00:00:00 alanmi Exp

]PARAMETERS ///BASIC TYPES ///

Definition at line 51 of file cnf.h.

Function Documentation

Vec_Ptr_t* Aig_ManScanMapping ( Cnf_Man_t p,
int  fCollect 
)

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order.]

SideEffects []

SeeAlso []

Definition at line 90 of file cnfUtil.c.

91 {
92  Vec_Ptr_t * vMapped = NULL;
93  Aig_Obj_t * pObj;
94  int i;
95  // clean all references
96  Aig_ManForEachObj( p->pManAig, pObj, i )
97  pObj->nRefs = 0;
98  // allocate the array
99  if ( fCollect )
100  vMapped = Vec_PtrAlloc( 1000 );
101  // collect nodes reachable from POs in the DFS order through the best cuts
102  p->aArea = 0;
103  Aig_ManForEachCo( p->pManAig, pObj, i )
104  p->aArea += Aig_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped );
105 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
106  return vMapped;
107 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
ABC_NAMESPACE_IMPL_START int Aig_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfUtil.c:46
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
void Cnf_CollectLeaves ( Aig_Obj_t pRoot,
Vec_Ptr_t vSuper,
int  fStopCompl 
)

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

Synopsis [Detects multi-input gate rooted at this node.]

Description []

SideEffects []

SeeAlso []

Definition at line 76 of file cnfFast.c.

77 {
78  assert( !Aig_IsComplement(pRoot) );
79  Vec_PtrClear( vSuper );
80  Cnf_CollectLeaves_rec( pRoot, pRoot, vSuper, fStopCompl );
81 }
ABC_NAMESPACE_IMPL_START void Cnf_CollectLeaves_rec(Aig_Obj_t *pRoot, Aig_Obj_t *pObj, Vec_Ptr_t *vSuper, int fStopCompl)
DECLARATIONS ///.
Definition: cnfFast.c:45
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Cnf_ComputeClauses ( Aig_Man_t p,
Aig_Obj_t pRoot,
Vec_Ptr_t vLeaves,
Vec_Ptr_t vNodes,
Vec_Int_t vMap,
Vec_Int_t vCover,
Vec_Int_t vClauses 
)

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

Synopsis [Collects nodes inside the cone.]

Description []

SideEffects []

SeeAlso []

Definition at line 198 of file cnfFast.c.

200 {
201  Aig_Obj_t * pLeaf;
202  int c, k, Cube, OutLit, RetValue;
203  word Truth;
204  assert( pRoot->fMarkA );
205 
206  Vec_IntClear( vClauses );
207 
208  OutLit = Cnf_ObjGetLit( vMap, pRoot, 0 );
209  // detect cone
210  Cnf_CollectLeaves( pRoot, vLeaves, 0 );
211  Cnf_CollectVolume( p, pRoot, vLeaves, vNodes );
212  assert( pRoot == Vec_PtrEntryLast(vNodes) );
213  // check if this is an AND-gate
214  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pLeaf, k )
215  {
216  if ( Aig_ObjFaninC0(pLeaf) && !Aig_ObjFanin0(pLeaf)->fMarkA )
217  break;
218  if ( Aig_ObjFaninC1(pLeaf) && !Aig_ObjFanin1(pLeaf)->fMarkA )
219  break;
220  }
221  if ( k == Vec_PtrSize(vNodes) )
222  {
223  Cnf_CollectLeaves( pRoot, vLeaves, 1 );
224  // write big clause
225  Vec_IntPush( vClauses, 0 );
226  Vec_IntPush( vClauses, OutLit );
227  Vec_PtrForEachEntry( Aig_Obj_t *, vLeaves, pLeaf, k )
228  Vec_IntPush( vClauses, Cnf_ObjGetLit(vMap, Aig_Regular(pLeaf), !Aig_IsComplement(pLeaf)) );
229  // write small clauses
230  Vec_PtrForEachEntry( Aig_Obj_t *, vLeaves, pLeaf, k )
231  {
232  Vec_IntPush( vClauses, 0 );
233  Vec_IntPush( vClauses, OutLit ^ 1 );
234  Vec_IntPush( vClauses, Cnf_ObjGetLit(vMap, Aig_Regular(pLeaf), Aig_IsComplement(pLeaf)) );
235  }
236  return;
237  }
238  if ( Vec_PtrSize(vLeaves) > 6 )
239  printf( "FastCnfGeneration: Internal error!!!\n" );
240  assert( Vec_PtrSize(vLeaves) <= 6 );
241 
242  Truth = Cnf_CutDeriveTruth( p, vLeaves, vNodes );
243  if ( Truth == 0 || Truth == ~(word)0 )
244  {
245  Vec_IntPush( vClauses, 0 );
246  Vec_IntPush( vClauses, (Truth == 0) ? (OutLit ^ 1) : OutLit );
247  return;
248  }
249 
250  RetValue = Kit_TruthIsop( (unsigned *)&Truth, Vec_PtrSize(vLeaves), vCover, 0 );
251  assert( RetValue >= 0 );
252 
253  Vec_IntForEachEntry( vCover, Cube, c )
254  {
255  Vec_IntPush( vClauses, 0 );
256  Vec_IntPush( vClauses, OutLit );
257  for ( k = 0; k < Vec_PtrSize(vLeaves); k++, Cube >>= 2 )
258  {
259  if ( (Cube & 3) == 0 )
260  continue;
261  assert( (Cube & 3) != 3 );
262  Vec_IntPush( vClauses, Cnf_ObjGetLit(vMap, (Aig_Obj_t *)Vec_PtrEntry(vLeaves,k), (Cube&3)!=1) );
263  }
264  }
265 
266  Truth = ~Truth;
267 
268  RetValue = Kit_TruthIsop( (unsigned *)&Truth, Vec_PtrSize(vLeaves), vCover, 0 );
269  assert( RetValue >= 0 );
270  Vec_IntForEachEntry( vCover, Cube, c )
271  {
272  Vec_IntPush( vClauses, 0 );
273  Vec_IntPush( vClauses, OutLit ^ 1 );
274  for ( k = 0; k < Vec_PtrSize(vLeaves); k++, Cube >>= 2 )
275  {
276  if ( (Cube & 3) == 0 )
277  continue;
278  assert( (Cube & 3) != 3 );
279  Vec_IntPush( vClauses, Cnf_ObjGetLit(vMap, (Aig_Obj_t *)Vec_PtrEntry(vLeaves,k), (Cube&3)!=1) );
280  }
281  }
282 }
static int Cnf_ObjGetLit(Vec_Int_t *vMap, Aig_Obj_t *pObj, int fCompl)
Definition: cnfFast.c:180
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Cnf_CollectVolume(Aig_Man_t *p, Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes)
Definition: cnfFast.c:116
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
unsigned int fMarkA
Definition: aig.h:79
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
FUNCTION DEFINITIONS ///.
Definition: kitIsop.c:55
void Cnf_CollectLeaves(Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
Definition: cnfFast.c:76
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
word Cnf_CutDeriveTruth(Aig_Man_t *p, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes)
Definition: cnfFast.c:138
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
Cnf_Cut_t* Cnf_CutCompose ( Cnf_Man_t p,
Cnf_Cut_t pCut,
Cnf_Cut_t pCutFan,
int  iFan 
)

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

Synopsis [Merges two cuts.]

Description [Returns NULL of the cuts cannot be merged.]

SideEffects []

SeeAlso []

Definition at line 294 of file cnfCut.c.

295 {
296  Cnf_Cut_t * pCutRes;
297  static int pFanins[32];
298  unsigned * pTruth, * pTruthFan, * pTruthRes;
299  unsigned * pTop = p->pTruths[0], * pFan = p->pTruths[2], * pTemp = p->pTruths[3];
300  unsigned uPhase, uPhaseFan;
301  int i, iVar, nFanins, RetValue;
302 
303  // make sure the second cut is the fanin of the first
304  for ( iVar = 0; iVar < pCut->nFanins; iVar++ )
305  if ( pCut->pFanins[iVar] == iFan )
306  break;
307  assert( iVar < pCut->nFanins );
308  // remove this variable
309  Cnf_CutRemoveIthVar( pCut, iVar, iFan );
310  // merge leaves of the cuts
311  nFanins = Cnf_CutMergeLeaves( pCut, pCutFan, pFanins );
312  if ( nFanins+1 > p->nMergeLimit )
313  {
314  Cnf_CutInsertIthVar( pCut, iVar, iFan );
315  return NULL;
316  }
317  // create new cut
318  pCutRes = Cnf_CutAlloc( p, nFanins );
319  memcpy( pCutRes->pFanins, pFanins, sizeof(int) * nFanins );
320  assert( pCutRes->nFanins <= pCut->nFanins + pCutFan->nFanins );
321 
322  // derive its truth table
323  // get the truth tables in the composition space
324  pTruth = Cnf_CutTruth(pCut);
325  pTruthFan = Cnf_CutTruth(pCutFan);
326  pTruthRes = Cnf_CutTruth(pCutRes);
327  for ( i = 0; i < 2*pCutRes->nWords; i++ )
328  pTop[i] = pTruth[i % pCut->nWords];
329  for ( i = 0; i < pCutRes->nWords; i++ )
330  pFan[i] = pTruthFan[i % pCutFan->nWords];
331  // move the variable to the end
332  uPhase = Kit_BitMask( pCutRes->nFanins+1 ) & ~(1 << iVar);
333  Kit_TruthShrink( pTemp, pTop, pCutRes->nFanins, pCutRes->nFanins+1, uPhase, 1 );
334  // compute the phases
335  uPhase = Cnf_TruthPhase( pCutRes, pCut ) | (1 << pCutRes->nFanins);
336  uPhaseFan = Cnf_TruthPhase( pCutRes, pCutFan );
337  // permute truth-tables to the common support
338  Kit_TruthStretch( pTemp, pTop, pCut->nFanins+1, pCutRes->nFanins+1, uPhase, 1 );
339  Kit_TruthStretch( pTemp, pFan, pCutFan->nFanins, pCutRes->nFanins, uPhaseFan, 1 );
340  // perform Boolean operation
341  Kit_TruthMux( pTruthRes, pTop, pTop+pCutRes->nWords, pFan, pCutRes->nFanins );
342  // return the cut to its original condition
343  Cnf_CutInsertIthVar( pCut, iVar, iFan );
344  // consider the simple case
345  if ( pCutRes->nFanins < 5 )
346  {
347  pCutRes->Cost = p->pSopSizes[0xFFFF & *pTruthRes] + p->pSopSizes[0xFFFF & ~*pTruthRes];
348  return pCutRes;
349  }
350 
351  // derive ISOP for positive phase
352  RetValue = Kit_TruthIsop( pTruthRes, pCutRes->nFanins, p->vMemory, 0 );
353  pCutRes->vIsop[1] = (RetValue == -1)? NULL : Vec_IntDup( p->vMemory );
354  // derive ISOP for negative phase
355  Kit_TruthNot( pTruthRes, pTruthRes, pCutRes->nFanins );
356  RetValue = Kit_TruthIsop( pTruthRes, pCutRes->nFanins, p->vMemory, 0 );
357  pCutRes->vIsop[0] = (RetValue == -1)? NULL : Vec_IntDup( p->vMemory );
358  Kit_TruthNot( pTruthRes, pTruthRes, pCutRes->nFanins );
359 
360  // compute the cut cost
361  if ( pCutRes->vIsop[0] == NULL || pCutRes->vIsop[1] == NULL )
362  pCutRes->Cost = 127;
363  else if ( Vec_IntSize(pCutRes->vIsop[0]) + Vec_IntSize(pCutRes->vIsop[1]) > 127 )
364  pCutRes->Cost = 127;
365  else
366  pCutRes->Cost = Vec_IntSize(pCutRes->vIsop[0]) + Vec_IntSize(pCutRes->vIsop[1]);
367  return pCutRes;
368 }
void Cnf_CutInsertIthVar(Cnf_Cut_t *pCut, int iVar, int iFan)
Definition: cnfCut.c:274
static Vec_Int_t * Vec_IntDup(Vec_Int_t *pVec)
Definition: vecInt.h:214
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * memcpy()
void Kit_TruthStretch(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn)
Definition: kitTruth.c:166
short nWords
Definition: cnf.h:75
for(p=first;p->value< newval;p=p->next)
char Cost
Definition: cnf.h:74
Vec_Int_t * vIsop[2]
Definition: cnf.h:76
static void Kit_TruthMux(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, unsigned *pCtrl, int nVars)
Definition: kit.h:457
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
Definition: cnf.h:71
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
FUNCTION DEFINITIONS ///.
Definition: kitIsop.c:55
int pFanins[0]
Definition: cnf.h:77
static void Kit_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:373
ABC_NAMESPACE_IMPL_START Cnf_Cut_t * Cnf_CutAlloc(Cnf_Man_t *p, int nLeaves)
DECLARATIONS ///.
Definition: cnfCut.c:46
void Kit_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn)
Definition: kitTruth.c:200
static int Cnf_CutMergeLeaves(Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, int *pFanins)
Definition: cnfCut.c:196
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define assert(ex)
Definition: util_old.h:213
void Cnf_CutRemoveIthVar(Cnf_Cut_t *pCut, int iVar, int iFan)
Definition: cnfCut.c:254
char nFanins
Definition: cnf.h:73
static unsigned Cnf_TruthPhase(Cnf_Cut_t *pCut, Cnf_Cut_t *pCut1)
Definition: cnfCut.c:226
static unsigned Kit_BitMask(int nBits)
Definition: kit.h:225
Cnf_Cut_t* Cnf_CutCreate ( Cnf_Man_t p,
Aig_Obj_t pObj 
)

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

Synopsis [Creates cut for the given node.]

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file cnfCut.c.

88 {
89  Dar_Cut_t * pCutBest;
90  Cnf_Cut_t * pCut;
91  unsigned * pTruth;
92  assert( Aig_ObjIsNode(pObj) );
93  pCutBest = Dar_ObjBestCut( pObj );
94  assert( pCutBest != NULL );
95  assert( pCutBest->nLeaves <= 4 );
96  pCut = Cnf_CutAlloc( p, pCutBest->nLeaves );
97  memcpy( pCut->pFanins, pCutBest->pLeaves, sizeof(int) * pCutBest->nLeaves );
98  pTruth = Cnf_CutTruth(pCut);
99  *pTruth = (pCutBest->uTruth << 16) | pCutBest->uTruth;
100  pCut->Cost = Cnf_CutSopCost( p, pCutBest );
101  return pCut;
102 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Cnf_CutSopCost(Cnf_Man_t *p, Dar_Cut_t *pCut)
Definition: cnf.h:99
unsigned uTruth
Definition: darInt.h:58
char * memcpy()
char Cost
Definition: cnf.h:74
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
int pLeaves[4]
Definition: darInt.h:63
Definition: cnf.h:71
int pFanins[0]
Definition: cnf.h:77
static Dar_Cut_t * Dar_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:97
unsigned nLeaves
Definition: darInt.h:62
ABC_NAMESPACE_IMPL_START Cnf_Cut_t * Cnf_CutAlloc(Cnf_Man_t *p, int nLeaves)
DECLARATIONS ///.
Definition: cnfCut.c:46
#define assert(ex)
Definition: util_old.h:213
void Cnf_CutFree ( Cnf_Cut_t pCut)

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

Synopsis [Deallocates cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 68 of file cnfCut.c.

69 {
70  if ( pCut->vIsop[0] )
71  Vec_IntFree( pCut->vIsop[0] );
72  if ( pCut->vIsop[1] )
73  Vec_IntFree( pCut->vIsop[1] );
74 }
Vec_Int_t * vIsop[2]
Definition: cnf.h:76
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Cnf_CutLeaveNum ( Cnf_Cut_t pCut)
inlinestatic

Definition at line 101 of file cnf.h.

101 { return pCut->nFanins; }
char nFanins
Definition: cnf.h:73
static int* Cnf_CutLeaves ( Cnf_Cut_t pCut)
inlinestatic

Definition at line 102 of file cnf.h.

102 { return pCut->pFanins; }
int pFanins[0]
Definition: cnf.h:77
void Cnf_CutPrint ( Cnf_Cut_t pCut)

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

Synopsis [Deallocates cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 115 of file cnfCut.c.

116 {
117  int i;
118  printf( "{" );
119  for ( i = 0; i < pCut->nFanins; i++ )
120  printf( "%d ", pCut->pFanins[i] );
121  printf( " } " );
122 }
int pFanins[0]
Definition: cnf.h:77
char nFanins
Definition: cnf.h:73
static int Cnf_CutSopCost ( Cnf_Man_t p,
Dar_Cut_t pCut 
)
inlinestatic

Definition at line 99 of file cnf.h.

99 { return p->pSopSizes[pCut->uTruth] + p->pSopSizes[0xFFFF & ~pCut->uTruth]; }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned uTruth
Definition: darInt.h:58
static unsigned* Cnf_CutTruth ( Cnf_Cut_t pCut)
inlinestatic

Definition at line 103 of file cnf.h.

103 { return (unsigned *)(pCut->pFanins + pCut->nFanins); }
int pFanins[0]
Definition: cnf.h:77
char nFanins
Definition: cnf.h:73
void Cnf_CutUpdateRefs ( Cnf_Man_t p,
Cnf_Cut_t pCut,
Cnf_Cut_t pCutFan,
Cnf_Cut_t pCutRes 
)

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

Synopsis [Allocates cut of the given size.]

Description []

SideEffects []

SeeAlso []

Definition at line 178 of file cnfCut.c.

179 {
180  Cnf_CutDeref( p, pCut );
181  Cnf_CutDeref( p, pCutFan );
182  Cnf_CutRef( p, pCutRes );
183 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Cnf_CutDeref(Cnf_Man_t *p, Cnf_Cut_t *pCut)
Definition: cnfCut.c:135
void Cnf_CutRef(Cnf_Man_t *p, Cnf_Cut_t *pCut)
Definition: cnfCut.c:157
int Cnf_DataAddXorClause ( void *  pSat,
int  iVarA,
int  iVarB,
int  iVarC 
)

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

Synopsis [Adds constraints for the two-input AND-gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 688 of file cnfMan.c.

689 {
690  lit Lits[3];
691  assert( iVarA > 0 && iVarB > 0 && iVarC > 0 );
692 
693  Lits[0] = toLitCond( iVarA, 1 );
694  Lits[1] = toLitCond( iVarB, 1 );
695  Lits[2] = toLitCond( iVarC, 1 );
696  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
697  return 0;
698 
699  Lits[0] = toLitCond( iVarA, 1 );
700  Lits[1] = toLitCond( iVarB, 0 );
701  Lits[2] = toLitCond( iVarC, 0 );
702  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
703  return 0;
704 
705  Lits[0] = toLitCond( iVarA, 0 );
706  Lits[1] = toLitCond( iVarB, 1 );
707  Lits[2] = toLitCond( iVarC, 0 );
708  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
709  return 0;
710 
711  Lits[0] = toLitCond( iVarA, 0 );
712  Lits[1] = toLitCond( iVarB, 0 );
713  Lits[2] = toLitCond( iVarC, 1 );
714  if ( !sat_solver_addclause( (sat_solver *)pSat, Lits, Lits + 3 ) )
715  return 0;
716 
717  return 1;
718 }
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int lit
Definition: satVec.h:130
static lit toLitCond(int v, int c)
Definition: satVec.h:143
#define assert(ex)
Definition: util_old.h:213
Cnf_Dat_t* Cnf_DataAlloc ( Aig_Man_t pAig,
int  nVars,
int  nClauses,
int  nLiterals 
)

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

Synopsis [Allocates the new CNF.]

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file cnfMan.c.

127 {
128  Cnf_Dat_t * pCnf;
129  int i;
130  pCnf = ABC_ALLOC( Cnf_Dat_t, 1 );
131  memset( pCnf, 0, sizeof(Cnf_Dat_t) );
132  pCnf->pMan = pAig;
133  pCnf->nVars = nVars;
134  pCnf->nClauses = nClauses;
135  pCnf->nLiterals = nLiterals;
136  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
137  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
138  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
139  pCnf->pVarNums = ABC_ALLOC( int, Aig_ManObjNumMax(pAig) );
140 // memset( pCnf->pVarNums, 0xff, sizeof(int) * Aig_ManObjNumMax(pAig) );
141  for ( i = 0; i < Aig_ManObjNumMax(pAig); i++ )
142  pCnf->pVarNums[i] = -1;
143  return pCnf;
144 }
char * memset()
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
int nLiterals
Definition: cnf.h:60
Vec_Int_t* Cnf_DataCollectCiSatNums ( Cnf_Dat_t pCnf,
Aig_Man_t p 
)

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 200 of file cnfUtil.c.

201 {
202  Vec_Int_t * vCiIds;
203  Aig_Obj_t * pObj;
204  int i;
205  vCiIds = Vec_IntAlloc( Aig_ManCiNum(p) );
206  Aig_ManForEachCi( p, pObj, i )
207  Vec_IntPush( vCiIds, pCnf->pVarNums[pObj->Id] );
208  return vCiIds;
209 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Vec_Int_t* Cnf_DataCollectCoSatNums ( Cnf_Dat_t pCnf,
Aig_Man_t p 
)

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 222 of file cnfUtil.c.

223 {
224  Vec_Int_t * vCoIds;
225  Aig_Obj_t * pObj;
226  int i;
227  vCoIds = Vec_IntAlloc( Aig_ManCoNum(p) );
228  Aig_ManForEachCo( p, pObj, i )
229  Vec_IntPush( vCoIds, pCnf->pVarNums[pObj->Id] );
230  return vCoIds;
231 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
Vec_Int_t* Cnf_DataCollectPiSatNums ( Cnf_Dat_t pCnf,
Aig_Man_t p 
)

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file cnfMan.c.

105 {
106  Vec_Int_t * vCiIds;
107  Aig_Obj_t * pObj;
108  int i;
109  vCiIds = Vec_IntAlloc( Aig_ManCiNum(p) );
110  Aig_ManForEachCi( p, pObj, i )
111  Vec_IntPush( vCiIds, pCnf->pVarNums[pObj->Id] );
112  return vCiIds;
113 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Aig_ManCiNum(Aig_Man_t *p)
Definition: aig.h:251
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
unsigned char* Cnf_DataDeriveLitPolarities ( Cnf_Dat_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 244 of file cnfUtil.c.

245 {
246  int i, c, iClaBeg, iClaEnd, * pLit;
247  unsigned * pPols0 = ABC_CALLOC( unsigned, Aig_ManObjNumMax(p->pMan) );
248  unsigned * pPols1 = ABC_CALLOC( unsigned, Aig_ManObjNumMax(p->pMan) );
249  unsigned char * pPres = ABC_CALLOC( unsigned char, p->nClauses );
250  for ( i = 0; i < Aig_ManObjNumMax(p->pMan); i++ )
251  {
252  if ( p->pObj2Count[i] == 0 )
253  continue;
254  iClaBeg = p->pObj2Clause[i];
255  iClaEnd = p->pObj2Clause[i] + p->pObj2Count[i];
256  // go through the negative polarity clauses
257  for ( c = iClaBeg; c < iClaEnd; c++ )
258  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
259  if ( Abc_LitIsCompl(p->pClauses[c][0]) )
260  pPols0[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
261  else
262  pPols1[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
263  // record these clauses
264  for ( c = iClaBeg; c < iClaEnd; c++ )
265  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
266  if ( Abc_LitIsCompl(p->pClauses[c][0]) )
267  pPres[c] = (unsigned char)( (unsigned)pPres[c] | (pPols0[Abc_Lit2Var(*pLit)] << (2*(pLit-p->pClauses[c]-1))) );
268  else
269  pPres[c] = (unsigned char)( (unsigned)pPres[c] | (pPols1[Abc_Lit2Var(*pLit)] << (2*(pLit-p->pClauses[c]-1))) );
270  // clean negative polarity
271  for ( c = iClaBeg; c < iClaEnd; c++ )
272  for ( pLit = p->pClauses[c]+1; pLit < p->pClauses[c+1]; pLit++ )
273  pPols0[Abc_Lit2Var(*pLit)] = pPols1[Abc_Lit2Var(*pLit)] = 0;
274  }
275  ABC_FREE( pPols0 );
276  ABC_FREE( pPols1 );
277 /*
278 // for ( c = 0; c < p->nClauses; c++ )
279  for ( c = 0; c < 100; c++ )
280  {
281  printf( "Clause %6d : ", c );
282  for ( i = 0; i < 4; i++ )
283  printf( "%d ", ((unsigned)pPres[c] >> (2*i)) & 3 );
284  printf( " " );
285  for ( pLit = p->pClauses[c]; pLit < p->pClauses[c+1]; pLit++ )
286  printf( "%6d ", *pLit );
287  printf( "\n" );
288  }
289 */
290  return pPres;
291 }
int nClauses
Definition: cnf.h:61
Aig_Man_t * pMan
Definition: cnf.h:58
int * pObj2Clause
Definition: cnf.h:64
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int * pObj2Count
Definition: cnf.h:65
Cnf_Dat_t* Cnf_DataDup ( Cnf_Dat_t p)

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

Synopsis [Allocates the new CNF.]

Description []

SideEffects []

SeeAlso []

Definition at line 157 of file cnfMan.c.

158 {
159  Cnf_Dat_t * pCnf;
160  int i;
161  pCnf = Cnf_DataAlloc( p->pMan, p->nVars, p->nClauses, p->nLiterals );
162  memcpy( pCnf->pClauses[0], p->pClauses[0], sizeof(int) * p->nLiterals );
163  memcpy( pCnf->pVarNums, p->pVarNums, sizeof(int) * Aig_ManObjNumMax(p->pMan) );
164  for ( i = 1; i < p->nClauses; i++ )
165  pCnf->pClauses[i] = pCnf->pClauses[0] + (p->pClauses[i] - p->pClauses[0]);
166  return pCnf;
167 }
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
char * memcpy()
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
int ** pClauses
Definition: cnf.h:62
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
Cnf_Dat_t * Cnf_DataAlloc(Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
Definition: cnfMan.c:126
int nLiterals
Definition: cnf.h:60
void Cnf_DataFlipLastLiteral ( Cnf_Dat_t p)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file cnfMan.c.

231 {
232  p->pClauses[0][p->nLiterals-1] = lit_neg( p->pClauses[0][p->nLiterals-1] );
233 }
static lit lit_neg(lit l)
Definition: satVec.h:144
int ** pClauses
Definition: cnf.h:62
int nLiterals
Definition: cnf.h:60
void Cnf_DataFree ( Cnf_Dat_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file cnfMan.c.

181 {
182  if ( p == NULL )
183  return;
184  Vec_IntFreeP( &p->vMapping );
185  ABC_FREE( p->pClaPols );
186  ABC_FREE( p->pObj2Clause );
187  ABC_FREE( p->pObj2Count );
188  ABC_FREE( p->pClauses[0] );
189  ABC_FREE( p->pClauses );
190  ABC_FREE( p->pVarNums );
191  ABC_FREE( p );
192 }
Vec_Int_t * vMapping
Definition: cnf.h:67
unsigned char * pClaPols
Definition: cnf.h:66
int * pVarNums
Definition: cnf.h:63
int * pObj2Clause
Definition: cnf.h:64
int ** pClauses
Definition: cnf.h:62
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
#define ABC_FREE(obj)
Definition: abc_global.h:232
int * pObj2Count
Definition: cnf.h:65
void Cnf_DataLift ( Cnf_Dat_t p,
int  nVarsPlus 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file cnfMan.c.

206 {
207  Aig_Obj_t * pObj;
208  int v;
209  if ( p->pMan )
210  {
211  Aig_ManForEachObj( p->pMan, pObj, v )
212  if ( p->pVarNums[pObj->Id] >= 0 )
213  p->pVarNums[pObj->Id] += nVarsPlus;
214  }
215  for ( v = 0; v < p->nLiterals; v++ )
216  p->pClauses[0][v] += 2*nVarsPlus;
217 }
Aig_Man_t * pMan
Definition: cnf.h:58
for(p=first;p->value< newval;p=p->next)
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
void Cnf_DataPrint ( Cnf_Dat_t p,
int  fReadable 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 246 of file cnfMan.c.

247 {
248  FILE * pFile = stdout;
249  int * pLit, * pStop, i;
250  fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
251  for ( i = 0; i < p->nClauses; i++ )
252  {
253  for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
254  fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
255  fprintf( pFile, "\n" );
256  }
257  fprintf( pFile, "\n" );
258 }
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var(int Lit)
DECLARATIONS ///.
Definition: cnfMan.c:33
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
int ** pClauses
Definition: cnf.h:62
static int Cnf_Lit2Var2(int Lit)
Definition: cnfMan.c:34
Cnf_Dat_t* Cnf_DataReadFromFile ( char *  pFileName)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 304 of file cnfUtil.c.

305 {
306  int MaxLine = 1000000;
307  int Var, Lit, nVars = -1, nClas = -1, i, Entry, iLine = 0;
308  Cnf_Dat_t * pCnf = NULL;
309  Vec_Int_t * vClas = NULL;
310  Vec_Int_t * vLits = NULL;
311  char * pBuffer, * pToken;
312  FILE * pFile = fopen( pFileName, "rb" );
313  if ( pFile == NULL )
314  {
315  printf( "Cannot open file \"%s\" for writing.\n", pFileName );
316  return NULL;
317  }
318  pBuffer = ABC_ALLOC( char, MaxLine );
319  while ( fgets(pBuffer, MaxLine, pFile) != NULL )
320  {
321  iLine++;
322  if ( pBuffer[0] == 'c' )
323  continue;
324  if ( pBuffer[0] == 'p' )
325  {
326  pToken = strtok( pBuffer+1, " \t" );
327  if ( strcmp(pToken, "cnf") )
328  {
329  printf( "Incorrect input file.\n" );
330  goto finish;
331  }
332  pToken = strtok( NULL, " \t" );
333  nVars = atoi( pToken );
334  pToken = strtok( NULL, " \t" );
335  nClas = atoi( pToken );
336  if ( nVars <= 0 || nClas <= 0 )
337  {
338  printf( "Incorrect parameters.\n" );
339  goto finish;
340  }
341  // temp storage
342  vClas = Vec_IntAlloc( nClas+1 );
343  vLits = Vec_IntAlloc( nClas*8 );
344  continue;
345  }
346  pToken = strtok( pBuffer, " \t\r\n" );
347  if ( pToken == NULL )
348  continue;
349  Vec_IntPush( vClas, Vec_IntSize(vLits) );
350  while ( pToken )
351  {
352  Var = atoi( pToken );
353  if ( Var == 0 )
354  break;
355  Lit = (Var > 0) ? Abc_Var2Lit(Var-1, 0) : Abc_Var2Lit(-Var-1, 1);
356  if ( Lit >= 2*nVars )
357  {
358  printf( "Literal %d is out-of-bound for %d variables.\n", Lit, nVars );
359  goto finish;
360  }
361  Vec_IntPush( vLits, Lit );
362  pToken = strtok( NULL, " \t\r\n" );
363  }
364  if ( Var != 0 )
365  {
366  printf( "There is no zero-terminator in line %d.\n", iLine );
367  goto finish;
368  }
369  }
370  // finalize
371  if ( Vec_IntSize(vClas) != nClas )
372  printf( "Warning! The number of clauses (%d) is different from declaration (%d).\n", Vec_IntSize(vClas), nClas );
373  Vec_IntPush( vClas, Vec_IntSize(vLits) );
374  // create
375  pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
376  pCnf->nVars = nVars;
377  pCnf->nClauses = nClas;
378  pCnf->nLiterals = Vec_IntSize(vLits);
379  pCnf->pClauses = ABC_ALLOC( int *, Vec_IntSize(vClas) );
380  pCnf->pClauses[0] = Vec_IntReleaseArray(vLits);
381  Vec_IntForEachEntry( vClas, Entry, i )
382  pCnf->pClauses[i] = pCnf->pClauses[0] + Entry;
383 finish:
384  fclose( pFile );
385  Vec_IntFreeP( &vClas );
386  Vec_IntFreeP( &vLits );
387  ABC_FREE( pBuffer );
388  return pCnf;
389 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
char * strtok()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Definition: cnf.h:56
int strcmp()
int ** pClauses
Definition: cnf.h:62
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntFreeP(Vec_Int_t **p)
Definition: vecInt.h:289
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int Var
Definition: SolverTypes.h:42
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int nLiterals
Definition: cnf.h:60
static int * Vec_IntReleaseArray(Vec_Int_t *p)
Definition: extraZddTrunc.c:89
void Cnf_DataTranformPolarity ( Cnf_Dat_t pCnf,
int  fTransformPos 
)

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

Synopsis [Transforms polarity of the internal veriables.]

Description []

SideEffects []

SeeAlso []

Definition at line 652 of file cnfMan.c.

653 {
654  Aig_Obj_t * pObj;
655  int * pVarToPol;
656  int i, iVar;
657  // create map from the variable number to its polarity
658  pVarToPol = ABC_CALLOC( int, pCnf->nVars );
659  Aig_ManForEachObj( pCnf->pMan, pObj, i )
660  {
661  if ( !fTransformPos && Aig_ObjIsCo(pObj) )
662  continue;
663  if ( pCnf->pVarNums[pObj->Id] >= 0 )
664  pVarToPol[ pCnf->pVarNums[pObj->Id] ] = pObj->fPhase;
665  }
666  // transform literals
667  for ( i = 0; i < pCnf->nLiterals; i++ )
668  {
669  iVar = lit_var(pCnf->pClauses[0][i]);
670  assert( iVar < pCnf->nVars );
671  if ( pVarToPol[iVar] )
672  pCnf->pClauses[0][i] = lit_neg( pCnf->pClauses[0][i] );
673  }
674  ABC_FREE( pVarToPol );
675 }
static int lit_var(lit l)
Definition: satVec.h:145
int nVars
Definition: cnf.h:59
int * pVarNums
Definition: cnf.h:63
Aig_Man_t * pMan
Definition: cnf.h:58
static lit lit_neg(lit l)
Definition: satVec.h:144
int ** pClauses
Definition: cnf.h:62
Definition: aig.h:69
unsigned int fPhase
Definition: aig.h:78
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
static int Aig_ObjIsCo(Aig_Obj_t *pObj)
Definition: aig.h:276
int Cnf_DataWriteAndClauses ( void *  p,
Cnf_Dat_t pCnf 
)

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 627 of file cnfMan.c.

628 {
629  sat_solver * pSat = (sat_solver *)p;
630  Aig_Obj_t * pObj;
631  int i, Lit;
632  Aig_ManForEachCo( pCnf->pMan, pObj, i )
633  {
634  Lit = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
635  if ( !sat_solver_addclause( pSat, &Lit, &Lit+1 ) )
636  return 0;
637  }
638  return 1;
639 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int * pVarNums
Definition: cnf.h:63
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
Aig_Man_t * pMan
Definition: cnf.h:58
static lit toLitCond(int v, int c)
Definition: satVec.h:143
Definition: aig.h:69
int Id
Definition: aig.h:85
void Cnf_DataWriteIntoFile ( Cnf_Dat_t p,
char *  pFileName,
int  fReadable,
Vec_Int_t vForAlls,
Vec_Int_t vExists 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 318 of file cnfMan.c.

319 {
320  FILE * pFile;
321  int * pLit, * pStop, i, VarId;
322  if ( !strncmp(pFileName+strlen(pFileName)-3,".gz",3) )
323  {
324  Cnf_DataWriteIntoFileGz( p, pFileName, fReadable, vForAlls, vExists );
325  return;
326  }
327  pFile = fopen( pFileName, "w" );
328  if ( pFile == NULL )
329  {
330  printf( "Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
331  return;
332  }
333  fprintf( pFile, "c Result of efficient AIG-to-CNF conversion using package CNF\n" );
334  fprintf( pFile, "p cnf %d %d\n", p->nVars, p->nClauses );
335  if ( vForAlls )
336  {
337  fprintf( pFile, "a " );
338  Vec_IntForEachEntry( vForAlls, VarId, i )
339  fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
340  fprintf( pFile, "0\n" );
341  }
342  if ( vExists )
343  {
344  fprintf( pFile, "e " );
345  Vec_IntForEachEntry( vExists, VarId, i )
346  fprintf( pFile, "%d ", fReadable? VarId : VarId+1 );
347  fprintf( pFile, "0\n" );
348  }
349  for ( i = 0; i < p->nClauses; i++ )
350  {
351  for ( pLit = p->pClauses[i], pStop = p->pClauses[i+1]; pLit < pStop; pLit++ )
352  fprintf( pFile, "%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
353  fprintf( pFile, "0\n" );
354  }
355  fprintf( pFile, "\n" );
356  fclose( pFile );
357 }
static ABC_NAMESPACE_IMPL_START int Cnf_Lit2Var(int Lit)
DECLARATIONS ///.
Definition: cnfMan.c:33
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
for(p=first;p->value< newval;p=p->next)
int ** pClauses
Definition: cnf.h:62
static int Cnf_Lit2Var2(int Lit)
Definition: cnfMan.c:34
if(last==0)
Definition: sparse_int.h:34
void Cnf_DataWriteIntoFileGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition: cnfMan.c:271
int strncmp()
int strlen()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
void* Cnf_DataWriteIntoSolver ( Cnf_Dat_t p,
int  nFrames,
int  fInit 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 463 of file cnfMan.c.

464 {
465  return Cnf_DataWriteIntoSolverInt( sat_solver_new(), p, nFrames, fInit );
466 }
void * Cnf_DataWriteIntoSolverInt(void *pSolver, Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:370
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
void* Cnf_DataWriteIntoSolverInt ( void *  pSolver,
Cnf_Dat_t p,
int  nFrames,
int  fInit 
)

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

Synopsis [Writes CNF into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 370 of file cnfMan.c.

371 {
372  sat_solver * pSat = (sat_solver *)pSolver;
373  int i, f, status;
374  assert( nFrames > 0 );
375  assert( pSat );
376 // pSat = sat_solver_new();
377  sat_solver_setnvars( pSat, p->nVars * nFrames );
378  for ( i = 0; i < p->nClauses; i++ )
379  {
380  if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
381  {
382  sat_solver_delete( pSat );
383  return NULL;
384  }
385  }
386  if ( nFrames > 1 )
387  {
388  Aig_Obj_t * pObjLo, * pObjLi;
389  int nLitsAll, * pLits, Lits[2];
390  nLitsAll = 2 * p->nVars;
391  pLits = p->pClauses[0];
392  for ( f = 1; f < nFrames; f++ )
393  {
394  // add equality of register inputs/outputs for different timeframes
395  Aig_ManForEachLiLoSeq( p->pMan, pObjLi, pObjLo, i )
396  {
397  Lits[0] = (f-1)*nLitsAll + toLitCond( p->pVarNums[pObjLi->Id], 0 );
398  Lits[1] = f *nLitsAll + toLitCond( p->pVarNums[pObjLo->Id], 1 );
399  if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
400  {
401  sat_solver_delete( pSat );
402  return NULL;
403  }
404  Lits[0]++;
405  Lits[1]--;
406  if ( !sat_solver_addclause( pSat, Lits, Lits + 2 ) )
407  {
408  sat_solver_delete( pSat );
409  return NULL;
410  }
411  }
412  // add clauses for the next timeframe
413  for ( i = 0; i < p->nLiterals; i++ )
414  pLits[i] += nLitsAll;
415  for ( i = 0; i < p->nClauses; i++ )
416  {
417  if ( !sat_solver_addclause( pSat, p->pClauses[i], p->pClauses[i+1] ) )
418  {
419  sat_solver_delete( pSat );
420  return NULL;
421  }
422  }
423  }
424  // return literals to their original state
425  nLitsAll = (f-1) * nLitsAll;
426  for ( i = 0; i < p->nLiterals; i++ )
427  pLits[i] -= nLitsAll;
428  }
429  if ( fInit )
430  {
431  Aig_Obj_t * pObjLo;
432  int Lits[1];
433  Aig_ManForEachLoSeq( p->pMan, pObjLo, i )
434  {
435  Lits[0] = toLitCond( p->pVarNums[pObjLo->Id], 1 );
436  if ( !sat_solver_addclause( pSat, Lits, Lits + 1 ) )
437  {
438  sat_solver_delete( pSat );
439  return NULL;
440  }
441  }
442  }
443  status = sat_solver_simplify(pSat);
444  if ( status == 0 )
445  {
446  sat_solver_delete( pSat );
447  return NULL;
448  }
449  return pSat;
450 }
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
int * pVarNums
Definition: cnf.h:63
Aig_Man_t * pMan
Definition: cnf.h:58
int ** pClauses
Definition: cnf.h:62
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
Definition: aig.h:450
static lit toLitCond(int v, int c)
Definition: satVec.h:143
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
Definition: aig.h:69
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
#define Aig_ManForEachLoSeq(p, pObj, i)
Definition: aig.h:441
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
int Cnf_DataWriteOrClause ( void *  p,
Cnf_Dat_t pCnf 
)

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

Synopsis [Adds the OR-clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 571 of file cnfMan.c.

572 {
573  sat_solver * pSat = (sat_solver *)p;
574  Aig_Obj_t * pObj;
575  int i, * pLits;
576  pLits = ABC_ALLOC( int, Aig_ManCoNum(pCnf->pMan) );
577  Aig_ManForEachCo( pCnf->pMan, pObj, i )
578  pLits[i] = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
579  if ( !sat_solver_addclause( pSat, pLits, pLits + Aig_ManCoNum(pCnf->pMan) ) )
580  {
581  ABC_FREE( pLits );
582  return 0;
583  }
584  ABC_FREE( pLits );
585  return 1;
586 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static lit toLitCond(int v, int c)
Definition: satVec.h:143
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define ABC_FREE(obj)
Definition: abc_global.h:232
Cnf_Dat_t* Cnf_Derive ( Aig_Man_t pAig,
int  nOutputs 
)

Definition at line 165 of file cnfCore.c.

166 {
167  Cnf_ManPrepare();
168  return Cnf_DeriveWithMan( s_pManCnf, pAig, nOutputs );
169 }
Cnf_Dat_t * Cnf_DeriveWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:129
void Cnf_ManPrepare()
FUNCTION DEFINITIONS ///.
Definition: cnfCore.c:46
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
Cnf_Dat_t* Cnf_DeriveFast ( Aig_Man_t p,
int  nOutputs 
)

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

Synopsis [Fast CNF computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 666 of file cnfFast.c.

667 {
668  Cnf_Dat_t * pCnf = NULL;
669  abctime clk;//, clkTotal = Abc_Clock();
670 // printf( "\n" );
672  // create initial marking
673  clk = Abc_Clock();
675 // Abc_PrintTime( 1, "Marking", Abc_Clock() - clk );
676  // compute CNF size
677  clk = Abc_Clock();
678  pCnf = Cnf_DeriveFastClauses( p, nOutputs );
679 // Abc_PrintTime( 1, "Clauses", Abc_Clock() - clk );
680  // derive the resulting CNF
681  Aig_ManCleanMarkA( p );
682 // Abc_PrintTime( 1, "TOTAL ", Abc_Clock() - clkTotal );
683 
684 // printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. \n", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
685 
686 // Cnf_DataFree( pCnf );
687 // pCnf = NULL;
688  return pCnf;
689 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Cnf_Dat_t * Cnf_DeriveFastClauses(Aig_Man_t *p, int nOutputs)
Definition: cnfFast.c:545
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
void Aig_ManCleanMarkAB(Aig_Man_t *p)
Definition: aigUtil.c:186
void Aig_ManCleanMarkA(Aig_Man_t *p)
Definition: aigUtil.c:148
ABC_INT64_T abctime
Definition: abc_global.h:278
void Cnf_DeriveFastMark(Aig_Man_t *p)
Definition: cnfFast.c:297
void Cnf_DeriveFastMark ( Aig_Man_t p)

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

Synopsis [Marks AIG for CNF computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 297 of file cnfFast.c.

298 {
299  Vec_Int_t * vSupps;
300  Vec_Ptr_t * vLeaves, * vNodes;
301  Aig_Obj_t * pObj, * pTemp, * pObjC, * pObj0, * pObj1;
302  int i, k, nFans, Counter;
303 
304  vLeaves = Vec_PtrAlloc( 100 );
305  vNodes = Vec_PtrAlloc( 100 );
306  vSupps = Vec_IntStart( Aig_ManObjNumMax(p) );
307 
308  // mark CIs
309  Aig_ManForEachCi( p, pObj, i )
310  pObj->fMarkA = 1;
311 
312  // mark CO drivers
313  Aig_ManForEachCo( p, pObj, i )
314  Aig_ObjFanin0(pObj)->fMarkA = 1;
315 
316  // mark MUX/XOR nodes
317  Aig_ManForEachNode( p, pObj, i )
318  {
319  assert( !pObj->fMarkB );
320  if ( !Aig_ObjIsMuxType(pObj) )
321  continue;
322  pObj0 = Aig_ObjFanin0(pObj);
323  if ( pObj0->fMarkB || Aig_ObjRefs(pObj0) > 1 )
324  continue;
325  pObj1 = Aig_ObjFanin1(pObj);
326  if ( pObj1->fMarkB || Aig_ObjRefs(pObj1) > 1 )
327  continue;
328  // mark nodes
329  pObj->fMarkB = 1;
330  pObj0->fMarkB = 1;
331  pObj1->fMarkB = 1;
332  // mark inputs and outputs
333  pObj->fMarkA = 1;
334  Aig_ObjFanin0(pObj0)->fMarkA = 1;
335  Aig_ObjFanin1(pObj0)->fMarkA = 1;
336  Aig_ObjFanin0(pObj1)->fMarkA = 1;
337  Aig_ObjFanin1(pObj1)->fMarkA = 1;
338  }
339 
340  // mark nodes with multiple fanouts and pointed to by complemented edges
341  Aig_ManForEachNode( p, pObj, i )
342  {
343  // mark nodes with many fanouts
344  if ( Aig_ObjRefs(pObj) > 1 )
345  pObj->fMarkA = 1;
346  // mark nodes pointed to by a complemented edge
347  if ( Aig_ObjFaninC0(pObj) && !Aig_ObjFanin0(pObj)->fMarkB )
348  Aig_ObjFanin0(pObj)->fMarkA = 1;
349  if ( Aig_ObjFaninC1(pObj) && !Aig_ObjFanin1(pObj)->fMarkB )
350  Aig_ObjFanin1(pObj)->fMarkA = 1;
351  }
352 
353  // compute supergate size for internal marked nodes
354  Aig_ManForEachNode( p, pObj, i )
355  {
356  if ( !pObj->fMarkA )
357  continue;
358  if ( pObj->fMarkB )
359  {
360  if ( !Aig_ObjIsMuxType(pObj) )
361  continue;
362  pObjC = Aig_ObjRecognizeMux( pObj, &pObj1, &pObj0 );
363  pObj0 = Aig_Regular(pObj0);
364  pObj1 = Aig_Regular(pObj1);
365  assert( pObj0->fMarkA );
366  assert( pObj1->fMarkA );
367 // if ( pObj0 == pObj1 )
368 // continue;
369  nFans = 1 + (pObj0 == pObj1);
370  if ( !pObj0->fMarkB && !Aig_ObjIsCi(pObj0) && Aig_ObjRefs(pObj0) == nFans && Vec_IntEntry(vSupps, Aig_ObjId(pObj0)) < 3 )
371  {
372  pObj0->fMarkA = 0;
373  continue;
374  }
375  if ( !pObj1->fMarkB && !Aig_ObjIsCi(pObj1) && Aig_ObjRefs(pObj1) == nFans && Vec_IntEntry(vSupps, Aig_ObjId(pObj1)) < 3 )
376  {
377  pObj1->fMarkA = 0;
378  continue;
379  }
380  continue;
381  }
382 
383  Cnf_CollectLeaves( pObj, vLeaves, 1 );
384  Vec_IntWriteEntry( vSupps, Aig_ObjId(pObj), Vec_PtrSize(vLeaves) );
385  if ( Vec_PtrSize(vLeaves) >= 6 )
386  continue;
387  Vec_PtrForEachEntry( Aig_Obj_t *, vLeaves, pTemp, k )
388  {
389  pTemp = Aig_Regular(pTemp);
390  assert( pTemp->fMarkA );
391  if ( pTemp->fMarkB || Aig_ObjIsCi(pTemp) || Aig_ObjRefs(pTemp) > 1 )
392  continue;
393  assert( Vec_IntEntry(vSupps, Aig_ObjId(pTemp)) > 0 );
394  if ( Vec_PtrSize(vLeaves) - 1 + Vec_IntEntry(vSupps, Aig_ObjId(pTemp)) > 6 )
395  continue;
396  pTemp->fMarkA = 0;
397  Vec_IntWriteEntry( vSupps, Aig_ObjId(pObj), 6 );
398 //printf( "%d %d ", Vec_PtrSize(vLeaves), Vec_IntEntry(vSupps, Aig_ObjId(pTemp)) );
399  break;
400  }
401  }
402  Aig_ManCleanMarkB( p );
403 
404  // check CO drivers
405  Counter = 0;
406  Aig_ManForEachCo( p, pObj, i )
407  Counter += !Aig_ObjFanin0(pObj)->fMarkA;
408  if ( Counter )
409  printf( "PO-driver rule is violated %d times.\n", Counter );
410 
411  // check that the AND-gates are fine
412  Counter = 0;
413  Aig_ManForEachNode( p, pObj, i )
414  {
415  assert( pObj->fMarkB == 0 );
416  if ( !pObj->fMarkA )
417  continue;
418  Cnf_CollectLeaves( pObj, vLeaves, 0 );
419  if ( Vec_PtrSize(vLeaves) <= 6 )
420  continue;
421  Cnf_CollectVolume( p, pObj, vLeaves, vNodes );
422  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pTemp, k )
423  {
424  if ( Aig_ObjFaninC0(pTemp) && !Aig_ObjFanin0(pTemp)->fMarkA )
425  Counter++;
426  if ( Aig_ObjFaninC1(pTemp) && !Aig_ObjFanin1(pTemp)->fMarkA )
427  Counter++;
428  }
429  }
430  if ( Counter )
431  printf( "AND-gate rule is violated %d times.\n", Counter );
432 
433  Vec_PtrFree( vLeaves );
434  Vec_PtrFree( vNodes );
435  Vec_IntFree( vSupps );
436 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
unsigned int fMarkB
Definition: aig.h:80
void Cnf_CollectVolume(Aig_Man_t *p, Aig_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vNodes)
Definition: cnfFast.c:116
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
void Aig_ManCleanMarkB(Aig_Man_t *p)
Definition: aigUtil.c:167
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
unsigned int fMarkA
Definition: aig.h:79
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Aig_Obj_t * Aig_ObjRecognizeMux(Aig_Obj_t *pObj, Aig_Obj_t **ppObjT, Aig_Obj_t **ppObjE)
Definition: aigUtil.c:387
void Cnf_CollectLeaves(Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
Definition: cnfFast.c:76
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static int Counter
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Aig_ObjIsMuxType(Aig_Obj_t *pObj)
Definition: aigUtil.c:307
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
#define assert(ex)
Definition: util_old.h:213
static int Aig_ObjRefs(Aig_Obj_t *pObj)
Definition: aig.h:300
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Cnf_DeriveMapping ( Cnf_Man_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file cnfMap.c.

101 {
102  Vec_Ptr_t * vSuper;
103  Aig_Obj_t * pObj;
104  Dar_Cut_t * pCut, * pCutBest;
105  int i, k, AreaFlow, * pAreaFlows;
106  // allocate area flows
107  pAreaFlows = ABC_ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
108  memset( pAreaFlows, 0, sizeof(int) * Aig_ManObjNumMax(p->pManAig) );
109  // visit the nodes in the topological order and update their best cuts
110  vSuper = Vec_PtrAlloc( 100 );
111  Aig_ManForEachNode( p->pManAig, pObj, i )
112  {
113  // go through the cuts
114  pCutBest = NULL;
115  Dar_ObjForEachCut( pObj, pCut, k )
116  {
117  pCut->fBest = 0;
118  if ( k == 0 )
119  continue;
120  Cnf_CutAssignAreaFlow( p, pCut, pAreaFlows );
121  if ( pCutBest == NULL || pCutBest->uSign > pCut->uSign ||
122  (pCutBest->uSign == pCut->uSign && pCutBest->Value < pCut->Value) )
123  pCutBest = pCut;
124  }
125  // check the big cut
126 // Aig_ObjCollectSuper( pObj, vSuper );
127  // get the area flow of this cut
128 // AreaFlow = Cnf_CutSuperAreaFlow( vSuper, pAreaFlows );
129  AreaFlow = ABC_INFINITY;
130  if ( AreaFlow >= (int)pCutBest->uSign )
131  {
132  pAreaFlows[pObj->Id] = pCutBest->uSign;
133  pCutBest->fBest = 1;
134  }
135  else
136  {
137  pAreaFlows[pObj->Id] = AreaFlow;
138  pObj->fMarkB = 1; // mark the special node
139  }
140  }
141  Vec_PtrFree( vSuper );
142  ABC_FREE( pAreaFlows );
143 
144 /*
145  // compute the area of mapping
146  AreaFlow = 0;
147  Aig_ManForEachCo( p->pManAig, pObj, i )
148  AreaFlow += Dar_ObjBestCut(Aig_ObjFanin0(pObj))->uSign / 100 / Aig_ObjFanin0(pObj)->nRefs;
149  printf( "Area of the network = %d.\n", AreaFlow );
150 */
151 }
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned int fMarkB
Definition: aig.h:80
unsigned fBest
Definition: darInt.h:60
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Dar_ObjForEachCut(pObj, pCut, i)
Definition: darInt.h:121
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
ABC_NAMESPACE_IMPL_START void Cnf_CutAssignAreaFlow(Cnf_Man_t *p, Dar_Cut_t *pCut, int *pAreaFlows)
DECLARATIONS ///.
Definition: cnfMap.c:45
Definition: aig.h:69
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition: abc_global.h:216
unsigned uSign
Definition: darInt.h:57
unsigned Value
Definition: darInt.h:59
int Id
Definition: aig.h:85
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Vec_Int_t* Cnf_DeriveMappingArray ( Aig_Man_t pAig)

FUNCTION DECLARATIONS ///.

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

Synopsis [Converts AIG into the SAT solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 78 of file cnfCore.c.

79 {
80  Vec_Int_t * vResult;
81  Cnf_Man_t * p;
82  Vec_Ptr_t * vMapped;
83  Aig_MmFixed_t * pMemCuts;
84  abctime clk;
85  // allocate the CNF manager
86  p = Cnf_ManStart();
87  p->pManAig = pAig;
88 
89  // generate cuts for all nodes, assign cost, and find best cuts
90 clk = Abc_Clock();
91  pMemCuts = Dar_ManComputeCuts( pAig, 10, 0, 0 );
92 p->timeCuts = Abc_Clock() - clk;
93 
94  // find the mapping
95 clk = Abc_Clock();
96  Cnf_DeriveMapping( p );
97 p->timeMap = Abc_Clock() - clk;
98 // Aig_ManScanMapping( p, 1 );
99 
100  // convert it into CNF
101 clk = Abc_Clock();
102  Cnf_ManTransferCuts( p );
103  vMapped = Cnf_ManScanMapping( p, 1, 0 );
104  vResult = Cnf_ManWriteCnfMapping( p, vMapped );
105  Vec_PtrFree( vMapped );
106  Aig_MmFixedStop( pMemCuts, 0 );
107 p->timeSave = Abc_Clock() - clk;
108 
109  // reset reference counters
110  Aig_ManResetRefs( pAig );
111 //ABC_PRT( "Cuts ", p->timeCuts );
112 //ABC_PRT( "Map ", p->timeMap );
113 //ABC_PRT( "Saving ", p->timeSave );
114  Cnf_ManStop( p );
115  return vResult;
116 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition: cnfUtil.c:170
void Cnf_ManStop(Cnf_Man_t *p)
Definition: cnfMan.c:82
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
static abctime Abc_Clock()
Definition: abc_global.h:279
DECLARATIONS ///.
Definition: aigMem.c:30
Aig_MmFixed_t * Dar_ManComputeCuts(Aig_Man_t *pAig, int nCutsMax, int fSkipTtMin, int fVerbose)
Definition: darCore.c:287
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition: cnfMap.c:100
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117
Vec_Int_t * Cnf_ManWriteCnfMapping(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfWrite.c:45
Cnf_Man_t * Cnf_ManStart()
FUNCTION DEFINITIONS ///.
Definition: cnfMan.c:51
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition: cnf.h:51
ABC_INT64_T abctime
Definition: abc_global.h:278
void Aig_ManResetRefs(Aig_Man_t *p)
Definition: aigUtil.c:122
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Cnf_Dat_t* Cnf_DeriveOther ( Aig_Man_t pAig,
int  fSkipTtMin 
)

Definition at line 219 of file cnfCore.c.

220 {
221  Cnf_ManPrepare();
222  return Cnf_DeriveOtherWithMan( s_pManCnf, pAig, fSkipTtMin );
223 }
void Cnf_ManPrepare()
FUNCTION DEFINITIONS ///.
Definition: cnfCore.c:46
Cnf_Dat_t * Cnf_DeriveOtherWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int fSkipTtMin)
Definition: cnfCore.c:182
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
Cnf_Dat_t* Cnf_DeriveOtherWithMan ( Cnf_Man_t p,
Aig_Man_t pAig,
int  fSkipTtMin 
)

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

Synopsis [Converts AIG into the SAT solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file cnfCore.c.

183 {
184  Cnf_Dat_t * pCnf;
185  Vec_Ptr_t * vMapped;
186  Aig_MmFixed_t * pMemCuts;
187  abctime clk;
188  // connect the managers
189  p->pManAig = pAig;
190 
191  // generate cuts for all nodes, assign cost, and find best cuts
192 clk = Abc_Clock();
193  pMemCuts = Dar_ManComputeCuts( pAig, 10, fSkipTtMin, 0 );
194 p->timeCuts = Abc_Clock() - clk;
195 
196  // find the mapping
197 clk = Abc_Clock();
198  Cnf_DeriveMapping( p );
199 p->timeMap = Abc_Clock() - clk;
200 // Aig_ManScanMapping( p, 1 );
201 
202  // convert it into CNF
203 clk = Abc_Clock();
205  vMapped = Cnf_ManScanMapping( p, 1, 1 );
206  pCnf = Cnf_ManWriteCnfOther( p, vMapped );
207  pCnf->vMapping = Cnf_ManWriteCnfMapping( p, vMapped );
208  Vec_PtrFree( vMapped );
209  Aig_MmFixedStop( pMemCuts, 0 );
210 p->timeSave = Abc_Clock() - clk;
211 
212  // reset reference counters
213  Aig_ManResetRefs( pAig );
214 //ABC_PRT( "Cuts ", p->timeCuts );
215 //ABC_PRT( "Map ", p->timeMap );
216 //ABC_PRT( "Saving ", p->timeSave );
217  return pCnf;
218 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition: cnfUtil.c:170
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
Vec_Int_t * vMapping
Definition: cnf.h:67
Cnf_Dat_t * Cnf_ManWriteCnfOther(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
Definition: cnfWrite.c:419
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
DECLARATIONS ///.
Definition: aigMem.c:30
Aig_MmFixed_t * Dar_ManComputeCuts(Aig_Man_t *pAig, int nCutsMax, int fSkipTtMin, int fVerbose)
Definition: darCore.c:287
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition: cnfMap.c:100
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117
Vec_Int_t * Cnf_ManWriteCnfMapping(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfWrite.c:45
ABC_INT64_T abctime
Definition: abc_global.h:278
void Aig_ManResetRefs(Aig_Man_t *p)
Definition: aigUtil.c:122
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Cnf_Dat_t* Cnf_DeriveSimple ( Aig_Man_t p,
int  nOutputs 
)

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

Synopsis [Derives a simple CNF for the AIG.]

Description [The last argument lists the number of last outputs of the manager, which will not be converted into clauses. New variables will be introduced for these outputs.]

SideEffects []

SeeAlso []

Definition at line 587 of file cnfWrite.c.

588 {
589  Aig_Obj_t * pObj;
590  Cnf_Dat_t * pCnf;
591  int OutVar, PoVar, pVars[32], * pLits, ** pClas;
592  int i, nLiterals, nClauses, Number;
593 
594  // count the number of literals and clauses
595  nLiterals = 1 + 7 * Aig_ManNodeNum(p) + Aig_ManCoNum( p ) + 3 * nOutputs;
596  nClauses = 1 + 3 * Aig_ManNodeNum(p) + Aig_ManCoNum( p ) + nOutputs;
597 
598  // allocate CNF
599  pCnf = ABC_ALLOC( Cnf_Dat_t, 1 );
600  memset( pCnf, 0, sizeof(Cnf_Dat_t) );
601  pCnf->pMan = p;
602  pCnf->nLiterals = nLiterals;
603  pCnf->nClauses = nClauses;
604  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
605  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
606  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
607 
608  // create room for variable numbers
609  pCnf->pVarNums = ABC_ALLOC( int, Aig_ManObjNumMax(p) );
610 // memset( pCnf->pVarNums, 0xff, sizeof(int) * Aig_ManObjNumMax(p) );
611  for ( i = 0; i < Aig_ManObjNumMax(p); i++ )
612  pCnf->pVarNums[i] = -1;
613  // assign variables to the last (nOutputs) POs
614  Number = 1;
615  if ( nOutputs )
616  {
617 // assert( nOutputs == Aig_ManRegNum(p) );
618 // Aig_ManForEachLiSeq( p, pObj, i )
619 // pCnf->pVarNums[pObj->Id] = Number++;
620  Aig_ManForEachCo( p, pObj, i )
621  pCnf->pVarNums[pObj->Id] = Number++;
622  }
623  // assign variables to the internal nodes
624  Aig_ManForEachNode( p, pObj, i )
625  pCnf->pVarNums[pObj->Id] = Number++;
626  // assign variables to the PIs and constant node
627  Aig_ManForEachCi( p, pObj, i )
628  pCnf->pVarNums[pObj->Id] = Number++;
629  pCnf->pVarNums[Aig_ManConst1(p)->Id] = Number++;
630  pCnf->nVars = Number;
631 /*
632  // print CNF numbers
633  printf( "SAT numbers of each node:\n" );
634  Aig_ManForEachObj( p, pObj, i )
635  printf( "%d=%d ", pObj->Id, pCnf->pVarNums[pObj->Id] );
636  printf( "\n" );
637 */
638  // assign the clauses
639  pLits = pCnf->pClauses[0];
640  pClas = pCnf->pClauses;
641  Aig_ManForEachNode( p, pObj, i )
642  {
643  OutVar = pCnf->pVarNums[ pObj->Id ];
644  pVars[0] = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
645  pVars[1] = pCnf->pVarNums[ Aig_ObjFanin1(pObj)->Id ];
646 
647  // positive phase
648  *pClas++ = pLits;
649  *pLits++ = 2 * OutVar;
650  *pLits++ = 2 * pVars[0] + !Aig_ObjFaninC0(pObj);
651  *pLits++ = 2 * pVars[1] + !Aig_ObjFaninC1(pObj);
652  // negative phase
653  *pClas++ = pLits;
654  *pLits++ = 2 * OutVar + 1;
655  *pLits++ = 2 * pVars[0] + Aig_ObjFaninC0(pObj);
656  *pClas++ = pLits;
657  *pLits++ = 2 * OutVar + 1;
658  *pLits++ = 2 * pVars[1] + Aig_ObjFaninC1(pObj);
659  }
660 
661  // write the constant literal
662  OutVar = pCnf->pVarNums[ Aig_ManConst1(p)->Id ];
663  assert( OutVar <= Aig_ManObjNumMax(p) );
664  *pClas++ = pLits;
665  *pLits++ = 2 * OutVar;
666 
667  // write the output literals
668  Aig_ManForEachCo( p, pObj, i )
669  {
670  OutVar = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
671  if ( i < Aig_ManCoNum(p) - nOutputs )
672  {
673  *pClas++ = pLits;
674  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
675  }
676  else
677  {
678  PoVar = pCnf->pVarNums[ pObj->Id ];
679  // first clause
680  *pClas++ = pLits;
681  *pLits++ = 2 * PoVar;
682  *pLits++ = 2 * OutVar + !Aig_ObjFaninC0(pObj);
683  // second clause
684  *pClas++ = pLits;
685  *pLits++ = 2 * PoVar + 1;
686  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
687  }
688  }
689 
690  // verify that the correct number of literals and clauses was written
691  assert( pLits - pCnf->pClauses[0] == nLiterals );
692  assert( pClas - pCnf->pClauses == nClauses );
693  return pCnf;
694 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nClauses
Definition: cnf.h:61
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int ** pClauses
Definition: cnf.h:62
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
Cnf_Dat_t* Cnf_DeriveSimpleForRetiming ( Aig_Man_t p)

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

Synopsis [Derives a simple CNF for backward retiming computation.]

Description [The last argument shows the number of last outputs of the manager, which will not be converted into clauses. New variables will be introduced for these outputs.]

SideEffects []

SeeAlso []

Definition at line 709 of file cnfWrite.c.

710 {
711  Aig_Obj_t * pObj;
712  Cnf_Dat_t * pCnf;
713  int OutVar, PoVar, pVars[32], * pLits, ** pClas;
714  int i, nLiterals, nClauses, Number;
715 
716  // count the number of literals and clauses
717  nLiterals = 1 + 7 * Aig_ManNodeNum(p) + 5 * Aig_ManCoNum(p);
718  nClauses = 1 + 3 * Aig_ManNodeNum(p) + 3 * Aig_ManCoNum(p);
719 
720  // allocate CNF
721  pCnf = ABC_ALLOC( Cnf_Dat_t, 1 );
722  memset( pCnf, 0, sizeof(Cnf_Dat_t) );
723  pCnf->pMan = p;
724  pCnf->nLiterals = nLiterals;
725  pCnf->nClauses = nClauses;
726  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
727  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
728  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
729 
730  // create room for variable numbers
731  pCnf->pVarNums = ABC_ALLOC( int, Aig_ManObjNumMax(p) );
732 // memset( pCnf->pVarNums, 0xff, sizeof(int) * Aig_ManObjNumMax(p) );
733  for ( i = 0; i < Aig_ManObjNumMax(p); i++ )
734  pCnf->pVarNums[i] = -1;
735  // assign variables to the last (nOutputs) POs
736  Number = 1;
737  Aig_ManForEachCo( p, pObj, i )
738  pCnf->pVarNums[pObj->Id] = Number++;
739  // assign variables to the internal nodes
740  Aig_ManForEachNode( p, pObj, i )
741  pCnf->pVarNums[pObj->Id] = Number++;
742  // assign variables to the PIs and constant node
743  Aig_ManForEachCi( p, pObj, i )
744  pCnf->pVarNums[pObj->Id] = Number++;
745  pCnf->pVarNums[Aig_ManConst1(p)->Id] = Number++;
746  pCnf->nVars = Number;
747  // assign the clauses
748  pLits = pCnf->pClauses[0];
749  pClas = pCnf->pClauses;
750  Aig_ManForEachNode( p, pObj, i )
751  {
752  OutVar = pCnf->pVarNums[ pObj->Id ];
753  pVars[0] = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
754  pVars[1] = pCnf->pVarNums[ Aig_ObjFanin1(pObj)->Id ];
755 
756  // positive phase
757  *pClas++ = pLits;
758  *pLits++ = 2 * OutVar;
759  *pLits++ = 2 * pVars[0] + !Aig_ObjFaninC0(pObj);
760  *pLits++ = 2 * pVars[1] + !Aig_ObjFaninC1(pObj);
761  // negative phase
762  *pClas++ = pLits;
763  *pLits++ = 2 * OutVar + 1;
764  *pLits++ = 2 * pVars[0] + Aig_ObjFaninC0(pObj);
765  *pClas++ = pLits;
766  *pLits++ = 2 * OutVar + 1;
767  *pLits++ = 2 * pVars[1] + Aig_ObjFaninC1(pObj);
768  }
769 
770  // write the constant literal
771  OutVar = pCnf->pVarNums[ Aig_ManConst1(p)->Id ];
772  assert( OutVar <= Aig_ManObjNumMax(p) );
773  *pClas++ = pLits;
774  *pLits++ = 2 * OutVar;
775 
776  // write the output literals
777  Aig_ManForEachCo( p, pObj, i )
778  {
779  OutVar = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
780  PoVar = pCnf->pVarNums[ pObj->Id ];
781  // first clause
782  *pClas++ = pLits;
783  *pLits++ = 2 * PoVar;
784  *pLits++ = 2 * OutVar + !Aig_ObjFaninC0(pObj);
785  // second clause
786  *pClas++ = pLits;
787  *pLits++ = 2 * PoVar + 1;
788  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
789  // final clause (init-state is always 0 -> set the output to 0)
790  *pClas++ = pLits;
791  *pLits++ = 2 * PoVar + 1;
792  }
793 
794  // verify that the correct number of literals and clauses was written
795  assert( pLits - pCnf->pClauses[0] == nLiterals );
796  assert( pClas - pCnf->pClauses == nClauses );
797  return pCnf;
798 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nClauses
Definition: cnf.h:61
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int ** pClauses
Definition: cnf.h:62
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Definition: aig.h:69
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
#define assert(ex)
Definition: util_old.h:213
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
Cnf_Dat_t* Cnf_DeriveWithMan ( Cnf_Man_t p,
Aig_Man_t pAig,
int  nOutputs 
)

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

Synopsis [Converts AIG into the SAT solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 129 of file cnfCore.c.

130 {
131  Cnf_Dat_t * pCnf;
132  Vec_Ptr_t * vMapped;
133  Aig_MmFixed_t * pMemCuts;
134  abctime clk;
135  // connect the managers
136  p->pManAig = pAig;
137 
138  // generate cuts for all nodes, assign cost, and find best cuts
139 clk = Abc_Clock();
140  pMemCuts = Dar_ManComputeCuts( pAig, 10, 0, 0 );
141 p->timeCuts = Abc_Clock() - clk;
142 
143  // find the mapping
144 clk = Abc_Clock();
145  Cnf_DeriveMapping( p );
146 p->timeMap = Abc_Clock() - clk;
147 // Aig_ManScanMapping( p, 1 );
148 
149  // convert it into CNF
150 clk = Abc_Clock();
152  vMapped = Cnf_ManScanMapping( p, 1, 1 );
153  pCnf = Cnf_ManWriteCnf( p, vMapped, nOutputs );
154  Vec_PtrFree( vMapped );
155  Aig_MmFixedStop( pMemCuts, 0 );
156 p->timeSave = Abc_Clock() - clk;
157 
158  // reset reference counters
159  Aig_ManResetRefs( pAig );
160 //ABC_PRT( "Cuts ", p->timeCuts );
161 //ABC_PRT( "Map ", p->timeMap );
162 //ABC_PRT( "Saving ", p->timeSave );
163  return pCnf;
164 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition: cnfUtil.c:170
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
DECLARATIONS ///.
Definition: aigMem.c:30
Cnf_Dat_t * Cnf_ManWriteCnf(Cnf_Man_t *p, Vec_Ptr_t *vMapped, int nOutputs)
Definition: cnfWrite.c:199
Aig_MmFixed_t * Dar_ManComputeCuts(Aig_Man_t *pAig, int nCutsMax, int fSkipTtMin, int fVerbose)
Definition: darCore.c:287
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition: cnfMap.c:100
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117
ABC_INT64_T abctime
Definition: abc_global.h:278
void Aig_ManResetRefs(Aig_Man_t *p)
Definition: aigUtil.c:122
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Cnf_ManFree ( )

Definition at line 58 of file cnfCore.c.

59 {
60  if ( s_pManCnf == NULL )
61  return;
63  s_pManCnf = NULL;
64 }
void Cnf_ManStop(Cnf_Man_t *p)
Definition: cnfMan.c:82
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
void Cnf_ManFreeCuts ( Cnf_Man_t p)

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

Synopsis [Transfers cuts of the mapped nodes into internal representation.]

Description []

SideEffects []

SeeAlso []

Definition at line 142 of file cnfPost.c.

143 {
144  Aig_Obj_t * pObj;
145  int i;
146  Aig_ManForEachObj( p->pManAig, pObj, i )
147  if ( pObj->pData )
148  {
149  Cnf_CutFree( (Cnf_Cut_t *)pObj->pData );
150  pObj->pData = NULL;
151  }
152 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * pData
Definition: aig.h:87
Definition: cnf.h:71
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
int Cnf_ManMapForCnf ( Cnf_Man_t p)
void Cnf_ManPostprocess ( Cnf_Man_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file cnfPost.c.

166 {
167  Cnf_Cut_t * pCut, * pCutFan, * pCutRes;
168  Aig_Obj_t * pObj, * pFan;
169  int Order[16], Costs[16];
170  int i, k, fChanges;
171  Aig_ManForEachNode( p->pManAig, pObj, i )
172  {
173  if ( pObj->nRefs == 0 )
174  continue;
175  pCut = Cnf_ObjBestCut(pObj);
176 
177  // sort fanins according to their size
178  Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k )
179  {
180  Order[k] = k;
181  Costs[k] = Aig_ObjIsNode(pFan)? Cnf_ObjBestCut(pFan)->Cost : 0;
182  }
183  // sort the cuts by Weight
184  do {
185  int Temp;
186  fChanges = 0;
187  for ( k = 0; k < pCut->nFanins - 1; k++ )
188  {
189  if ( Costs[Order[k]] <= Costs[Order[k+1]] )
190  continue;
191  Temp = Order[k];
192  Order[k] = Order[k+1];
193  Order[k+1] = Temp;
194  fChanges = 1;
195  }
196  } while ( fChanges );
197 
198 
199 // Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k )
200  for ( k = 0; (k < (int)(pCut)->nFanins) && ((pFan) = Aig_ManObj(p->pManAig, (pCut)->pFanins[Order[k]])); k++ )
201  {
202  if ( !Aig_ObjIsNode(pFan) )
203  continue;
204  assert( pFan->nRefs != 0 );
205  if ( pFan->nRefs != 1 )
206  continue;
207  pCutFan = Cnf_ObjBestCut(pFan);
208  // try composing these two cuts
209 // Cnf_CutPrint( pCut );
210  pCutRes = Cnf_CutCompose( p, pCut, pCutFan, pFan->Id );
211 // Cnf_CutPrint( pCut );
212 // printf( "\n" );
213  // check if the cost if reduced
214  if ( pCutRes == NULL || pCutRes->Cost == 127 || pCutRes->Cost > pCut->Cost + pCutFan->Cost )
215  {
216  if ( pCutRes )
217  Cnf_CutFree( pCutRes );
218  continue;
219  }
220  // update the cut
221  Cnf_ObjSetBestCut( pObj, pCutRes );
222  Cnf_ObjSetBestCut( pFan, NULL );
223  Cnf_CutUpdateRefs( p, pCut, pCutFan, pCutRes );
224  assert( pFan->nRefs == 0 );
225  Cnf_CutFree( pCut );
226  Cnf_CutFree( pCutFan );
227  break;
228  }
229  }
230 }
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
Definition: aig.h:270
static void Cnf_ObjSetBestCut(Aig_Obj_t *pObj, Cnf_Cut_t *pCut)
Definition: cnf.h:106
char Cost
Definition: cnf.h:74
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
Cnf_Cut_t * Cnf_CutCompose(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, int iFan)
Definition: cnfCut.c:294
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Definition: cnf.h:71
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: cnf.h:121
Definition: aig.h:69
void Cnf_CutUpdateRefs(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, Cnf_Cut_t *pCutRes)
Definition: cnfCut.c:178
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
#define assert(ex)
Definition: util_old.h:213
char nFanins
Definition: cnf.h:73
int Id
Definition: aig.h:85
unsigned int nRefs
Definition: aig.h:81
void Cnf_ManPrepare ( )

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file cnfCore.c.

47 {
48  if ( s_pManCnf == NULL )
49  {
50 // printf( "\n\nCreating CNF manager!!!!!\n\n" );
52  }
53 }
Cnf_Man_t * Cnf_ManStart()
FUNCTION DEFINITIONS ///.
Definition: cnfMan.c:51
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
Cnf_Man_t* Cnf_ManRead ( )

Definition at line 54 of file cnfCore.c.

55 {
56  return s_pManCnf;
57 }
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
Vec_Ptr_t* Cnf_ManScanMapping ( Cnf_Man_t p,
int  fCollect,
int  fPreorder 
)

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

Synopsis [Computes area, references, and nodes used in the mapping.]

Description [Collects the nodes in reverse topological order.]

SideEffects []

SeeAlso []

Definition at line 170 of file cnfUtil.c.

171 {
172  Vec_Ptr_t * vMapped = NULL;
173  Aig_Obj_t * pObj;
174  int i;
175  // clean all references
176  Aig_ManForEachObj( p->pManAig, pObj, i )
177  pObj->nRefs = 0;
178  // allocate the array
179  if ( fCollect )
180  vMapped = Vec_PtrAlloc( 1000 );
181  // collect nodes reachable from POs in the DFS order through the best cuts
182  p->aArea = 0;
183  Aig_ManForEachCo( p->pManAig, pObj, i )
184  p->aArea += Cnf_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped, fPreorder );
185 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
186  return vMapped;
187 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int Cnf_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
Definition: cnfUtil.c:120
Cnf_Man_t* Cnf_ManStart ( )

FUNCTION DEFINITIONS ///.

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

Synopsis [Starts the fraiging manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file cnfMan.c.

52 {
53  Cnf_Man_t * p;
54  int i;
55  // allocate the manager
56  p = ABC_ALLOC( Cnf_Man_t, 1 );
57  memset( p, 0, sizeof(Cnf_Man_t) );
58  // derive internal data structures
59  Cnf_ReadMsops( &p->pSopSizes, &p->pSops );
60  // allocate memory manager for cuts
61  p->pMemCuts = Aig_MmFlexStart();
62  p->nMergeLimit = 10;
63  // allocate temporary truth tables
64  p->pTruths[0] = ABC_ALLOC( unsigned, 4 * Abc_TruthWordNum(p->nMergeLimit) );
65  for ( i = 1; i < 4; i++ )
66  p->pTruths[i] = p->pTruths[i-1] + Abc_TruthWordNum(p->nMergeLimit);
67  p->vMemory = Vec_IntAlloc( 1 << 18 );
68  return p;
69 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static int Abc_TruthWordNum(int nVars)
Definition: abc_global.h:256
void Cnf_ReadMsops(char **ppSopSizes, char ***ppSops)
FUNCTION DEFINITIONS ///.
Definition: cnfData.c:4537
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition: cnf.h:51
void Cnf_ManStop ( Cnf_Man_t p)

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

Synopsis [Stops the fraiging manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file cnfMan.c.

83 {
84  Vec_IntFree( p->vMemory );
85  ABC_FREE( p->pTruths[0] );
86  Aig_MmFlexStop( p->pMemCuts, 0 );
87  ABC_FREE( p->pSopSizes );
88  ABC_FREE( p->pSops[1] );
89  ABC_FREE( p->pSops );
90  ABC_FREE( p );
91 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
void Cnf_ManTransferCuts ( Cnf_Man_t p)

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

Synopsis [Transfers cuts of the mapped nodes into internal representation.]

Description []

SideEffects []

SeeAlso []

Definition at line 117 of file cnfPost.c.

118 {
119  Aig_Obj_t * pObj;
120  int i;
121  Aig_MmFlexRestart( p->pMemCuts );
122  Aig_ManForEachObj( p->pManAig, pObj, i )
123  {
124  if ( Aig_ObjIsNode(pObj) && pObj->nRefs > 0 )
125  pObj->pData = Cnf_CutCreate( p, pObj );
126  else
127  pObj->pData = NULL;
128  }
129 }
void Aig_MmFlexRestart(Aig_MmFlex_t *p)
Definition: aigMem.c:411
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * pData
Definition: aig.h:87
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
Definition: aig.h:69
Cnf_Cut_t * Cnf_CutCreate(Cnf_Man_t *p, Aig_Obj_t *pObj)
Definition: cnfCut.c:87
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
unsigned int nRefs
Definition: aig.h:81
Cnf_Dat_t* Cnf_ManWriteCnf ( Cnf_Man_t p,
Vec_Ptr_t vMapped,
int  nOutputs 
)

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

Synopsis [Derives CNF for the mapping.]

Description [The last argument shows the number of last outputs of the manager, which will not be converted into clauses but the new variables for which will be introduced.]

SideEffects []

SeeAlso []

Definition at line 199 of file cnfWrite.c.

200 {
201  int fChangeVariableOrder = 0; // should be set to 0 to improve performance
202  Aig_Obj_t * pObj;
203  Cnf_Dat_t * pCnf;
204  Cnf_Cut_t * pCut;
205  Vec_Int_t * vCover, * vSopTemp;
206  int OutVar, PoVar, pVars[32], * pLits, ** pClas;
207  unsigned uTruth;
208  int i, k, nLiterals, nClauses, Cube, Number;
209 
210  // count the number of literals and clauses
211  nLiterals = 1 + Aig_ManCoNum( p->pManAig ) + 3 * nOutputs;
212  nClauses = 1 + Aig_ManCoNum( p->pManAig ) + nOutputs;
213  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
214  {
215  assert( Aig_ObjIsNode(pObj) );
216  pCut = Cnf_ObjBestCut( pObj );
217 
218  // positive polarity of the cut
219  if ( pCut->nFanins < 5 )
220  {
221  uTruth = 0xFFFF & *Cnf_CutTruth(pCut);
222  nLiterals += Cnf_SopCountLiterals( p->pSops[uTruth], p->pSopSizes[uTruth] ) + p->pSopSizes[uTruth];
223  assert( p->pSopSizes[uTruth] >= 0 );
224  nClauses += p->pSopSizes[uTruth];
225  }
226  else
227  {
228  nLiterals += Cnf_IsopCountLiterals( pCut->vIsop[1], pCut->nFanins ) + Vec_IntSize(pCut->vIsop[1]);
229  nClauses += Vec_IntSize(pCut->vIsop[1]);
230  }
231  // negative polarity of the cut
232  if ( pCut->nFanins < 5 )
233  {
234  uTruth = 0xFFFF & ~*Cnf_CutTruth(pCut);
235  nLiterals += Cnf_SopCountLiterals( p->pSops[uTruth], p->pSopSizes[uTruth] ) + p->pSopSizes[uTruth];
236  assert( p->pSopSizes[uTruth] >= 0 );
237  nClauses += p->pSopSizes[uTruth];
238  }
239  else
240  {
241  nLiterals += Cnf_IsopCountLiterals( pCut->vIsop[0], pCut->nFanins ) + Vec_IntSize(pCut->vIsop[0]);
242  nClauses += Vec_IntSize(pCut->vIsop[0]);
243  }
244 //printf( "%d ", nClauses-(1 + Aig_ManCoNum( p->pManAig )) );
245  }
246 //printf( "\n" );
247 
248  // allocate CNF
249  pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
250  pCnf->pMan = p->pManAig;
251  pCnf->nLiterals = nLiterals;
252  pCnf->nClauses = nClauses;
253  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
254  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
255  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
256  // create room for variable numbers
257  pCnf->pVarNums = ABC_ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
258 // memset( pCnf->pVarNums, 0xff, sizeof(int) * Aig_ManObjNumMax(p->pManAig) );
259  for ( i = 0; i < Aig_ManObjNumMax(p->pManAig); i++ )
260  pCnf->pVarNums[i] = -1;
261 
262  if ( !fChangeVariableOrder )
263  {
264  // assign variables to the last (nOutputs) POs
265  Number = 1;
266  if ( nOutputs )
267  {
268  if ( Aig_ManRegNum(p->pManAig) == 0 )
269  {
270  assert( nOutputs == Aig_ManCoNum(p->pManAig) );
271  Aig_ManForEachCo( p->pManAig, pObj, i )
272  pCnf->pVarNums[pObj->Id] = Number++;
273  }
274  else
275  {
276  assert( nOutputs == Aig_ManRegNum(p->pManAig) );
277  Aig_ManForEachLiSeq( p->pManAig, pObj, i )
278  pCnf->pVarNums[pObj->Id] = Number++;
279  }
280  }
281  // assign variables to the internal nodes
282  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
283  pCnf->pVarNums[pObj->Id] = Number++;
284  // assign variables to the PIs and constant node
285  Aig_ManForEachCi( p->pManAig, pObj, i )
286  pCnf->pVarNums[pObj->Id] = Number++;
287  pCnf->pVarNums[Aig_ManConst1(p->pManAig)->Id] = Number++;
288  pCnf->nVars = Number;
289  }
290  else
291  {
292  // assign variables to the last (nOutputs) POs
293  Number = Aig_ManObjNumMax(p->pManAig) + 1;
294  pCnf->nVars = Number + 1;
295  if ( nOutputs )
296  {
297  if ( Aig_ManRegNum(p->pManAig) == 0 )
298  {
299  assert( nOutputs == Aig_ManCoNum(p->pManAig) );
300  Aig_ManForEachCo( p->pManAig, pObj, i )
301  pCnf->pVarNums[pObj->Id] = Number--;
302  }
303  else
304  {
305  assert( nOutputs == Aig_ManRegNum(p->pManAig) );
306  Aig_ManForEachLiSeq( p->pManAig, pObj, i )
307  pCnf->pVarNums[pObj->Id] = Number--;
308  }
309  }
310  // assign variables to the internal nodes
311  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
312  pCnf->pVarNums[pObj->Id] = Number--;
313  // assign variables to the PIs and constant node
314  Aig_ManForEachCi( p->pManAig, pObj, i )
315  pCnf->pVarNums[pObj->Id] = Number--;
316  pCnf->pVarNums[Aig_ManConst1(p->pManAig)->Id] = Number--;
317  assert( Number >= 0 );
318  }
319 
320  // assign the clauses
321  vSopTemp = Vec_IntAlloc( 1 << 16 );
322  pLits = pCnf->pClauses[0];
323  pClas = pCnf->pClauses;
324  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
325  {
326  pCut = Cnf_ObjBestCut( pObj );
327 
328  // save variables of this cut
329  OutVar = pCnf->pVarNums[ pObj->Id ];
330  for ( k = 0; k < (int)pCut->nFanins; k++ )
331  {
332  pVars[k] = pCnf->pVarNums[ pCut->pFanins[k] ];
333  assert( pVars[k] <= Aig_ManObjNumMax(p->pManAig) );
334  }
335 
336  // positive polarity of the cut
337  if ( pCut->nFanins < 5 )
338  {
339  uTruth = 0xFFFF & *Cnf_CutTruth(pCut);
340  Cnf_SopConvertToVector( p->pSops[uTruth], p->pSopSizes[uTruth], vSopTemp );
341  vCover = vSopTemp;
342  }
343  else
344  vCover = pCut->vIsop[1];
345  Vec_IntForEachEntry( vCover, Cube, k )
346  {
347  *pClas++ = pLits;
348  *pLits++ = 2 * OutVar;
349  pLits += Cnf_IsopWriteCube( Cube, pCut->nFanins, pVars, pLits );
350  }
351 
352  // negative polarity of the cut
353  if ( pCut->nFanins < 5 )
354  {
355  uTruth = 0xFFFF & ~*Cnf_CutTruth(pCut);
356  Cnf_SopConvertToVector( p->pSops[uTruth], p->pSopSizes[uTruth], vSopTemp );
357  vCover = vSopTemp;
358  }
359  else
360  vCover = pCut->vIsop[0];
361  Vec_IntForEachEntry( vCover, Cube, k )
362  {
363  *pClas++ = pLits;
364  *pLits++ = 2 * OutVar + 1;
365  pLits += Cnf_IsopWriteCube( Cube, pCut->nFanins, pVars, pLits );
366  }
367  }
368  Vec_IntFree( vSopTemp );
369 
370  // write the constant literal
371  OutVar = pCnf->pVarNums[ Aig_ManConst1(p->pManAig)->Id ];
372  assert( OutVar <= Aig_ManObjNumMax(p->pManAig) );
373  *pClas++ = pLits;
374  *pLits++ = 2 * OutVar;
375 
376  // write the output literals
377  Aig_ManForEachCo( p->pManAig, pObj, i )
378  {
379  OutVar = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
380  if ( i < Aig_ManCoNum(p->pManAig) - nOutputs )
381  {
382  *pClas++ = pLits;
383  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
384  }
385  else
386  {
387  PoVar = pCnf->pVarNums[ pObj->Id ];
388  // first clause
389  *pClas++ = pLits;
390  *pLits++ = 2 * PoVar;
391  *pLits++ = 2 * OutVar + !Aig_ObjFaninC0(pObj);
392  // second clause
393  *pClas++ = pLits;
394  *pLits++ = 2 * PoVar + 1;
395  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
396  }
397  }
398 
399  // verify that the correct number of literals and clauses was written
400  assert( pLits - pCnf->pClauses[0] == nLiterals );
401  assert( pClas - pCnf->pClauses == nClauses );
402 //Cnf_DataPrint( pCnf, 1 );
403  return pCnf;
404 }
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
int * pVarNums
Definition: cnf.h:63
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
Vec_Int_t * vIsop[2]
Definition: cnf.h:76
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int ** pClauses
Definition: cnf.h:62
Definition: cnf.h:71
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int pFanins[0]
Definition: cnf.h:77
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
Definition: aig.h:69
int Cnf_IsopWriteCube(int Cube, int nVars, int *pVars, int *pLiterals)
Definition: cnfWrite.c:170
void Cnf_SopConvertToVector(char *pSop, int nCubes, Vec_Int_t *vCover)
Definition: cnfWrite.c:82
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static int Aig_ManRegNum(Aig_Man_t *p)
Definition: aig.h:260
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
#define Aig_ManForEachLiSeq(p, pObj, i)
Definition: aig.h:447
int Cnf_IsopCountLiterals(Vec_Int_t *vIsop, int nVars)
Definition: cnfWrite.c:144
char nFanins
Definition: cnf.h:73
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int Cnf_SopCountLiterals(char *pSop, int nCubes)
Definition: cnfWrite.c:117
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
Vec_Int_t* Cnf_ManWriteCnfMapping ( Cnf_Man_t p,
Vec_Ptr_t vMapped 
)

DECLARATIONS ///.

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

FileName [cnfWrite.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [AIG-to-CNF conversion.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
cnfWrite.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

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

Synopsis [Derives CNF mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file cnfWrite.c.

46 {
47  Vec_Int_t * vResult;
48  Aig_Obj_t * pObj;
49  Cnf_Cut_t * pCut;
50  int i, k, nOffset;
51  nOffset = Aig_ManObjNumMax(p->pManAig);
52  vResult = Vec_IntStart( nOffset );
53  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
54  {
55  assert( Aig_ObjIsNode(pObj) );
56  pCut = Cnf_ObjBestCut( pObj );
57  assert( pCut->nFanins < 5 );
58  Vec_IntWriteEntry( vResult, Aig_ObjId(pObj), nOffset );
59  Vec_IntPush( vResult, *Cnf_CutTruth(pCut) );
60  for ( k = 0; k < pCut->nFanins; k++ )
61  Vec_IntPush( vResult, pCut->pFanins[k] );
62  for ( ; k < 4; k++ )
63  Vec_IntPush( vResult, -1 );
64  nOffset += 5;
65  }
66  return vResult;
67 }
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
Definition: cnf.h:71
int pFanins[0]
Definition: cnf.h:77
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
#define assert(ex)
Definition: util_old.h:213
char nFanins
Definition: cnf.h:73
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Cnf_Dat_t* Cnf_ManWriteCnfOther ( Cnf_Man_t p,
Vec_Ptr_t vMapped 
)

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

Synopsis [Derives CNF for the mapping.]

Description [Derives CNF with obj IDs as SAT vars and mapping of objects into clauses (pObj2Clause and pObj2Count).]

SideEffects []

SeeAlso []

Definition at line 419 of file cnfWrite.c.

420 {
421  Aig_Obj_t * pObj;
422  Cnf_Dat_t * pCnf;
423  Cnf_Cut_t * pCut;
424  Vec_Int_t * vCover, * vSopTemp;
425  int OutVar, PoVar, pVars[32], * pLits, ** pClas;
426  unsigned uTruth;
427  int i, k, nLiterals, nClauses, Cube;
428 
429  // count the number of literals and clauses
430  nLiterals = 1 + 4 * Aig_ManCoNum( p->pManAig );
431  nClauses = 1 + 2 * Aig_ManCoNum( p->pManAig );
432  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
433  {
434  assert( Aig_ObjIsNode(pObj) );
435  pCut = Cnf_ObjBestCut( pObj );
436  // positive polarity of the cut
437  if ( pCut->nFanins < 5 )
438  {
439  uTruth = 0xFFFF & *Cnf_CutTruth(pCut);
440  nLiterals += Cnf_SopCountLiterals( p->pSops[uTruth], p->pSopSizes[uTruth] ) + p->pSopSizes[uTruth];
441  assert( p->pSopSizes[uTruth] >= 0 );
442  nClauses += p->pSopSizes[uTruth];
443  }
444  else
445  {
446  nLiterals += Cnf_IsopCountLiterals( pCut->vIsop[1], pCut->nFanins ) + Vec_IntSize(pCut->vIsop[1]);
447  nClauses += Vec_IntSize(pCut->vIsop[1]);
448  }
449  // negative polarity of the cut
450  if ( pCut->nFanins < 5 )
451  {
452  uTruth = 0xFFFF & ~*Cnf_CutTruth(pCut);
453  nLiterals += Cnf_SopCountLiterals( p->pSops[uTruth], p->pSopSizes[uTruth] ) + p->pSopSizes[uTruth];
454  assert( p->pSopSizes[uTruth] >= 0 );
455  nClauses += p->pSopSizes[uTruth];
456  }
457  else
458  {
459  nLiterals += Cnf_IsopCountLiterals( pCut->vIsop[0], pCut->nFanins ) + Vec_IntSize(pCut->vIsop[0]);
460  nClauses += Vec_IntSize(pCut->vIsop[0]);
461  }
462  }
463 
464  // allocate CNF
465  pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
466  pCnf->pMan = p->pManAig;
467  pCnf->nLiterals = nLiterals;
468  pCnf->nClauses = nClauses;
469  pCnf->pClauses = ABC_ALLOC( int *, nClauses + 1 );
470  pCnf->pClauses[0] = ABC_ALLOC( int, nLiterals );
471  pCnf->pClauses[nClauses] = pCnf->pClauses[0] + nLiterals;
472  // create room for variable numbers
473  pCnf->pObj2Clause = ABC_ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
474  pCnf->pObj2Count = ABC_ALLOC( int, Aig_ManObjNumMax(p->pManAig) );
475  for ( i = 0; i < Aig_ManObjNumMax(p->pManAig); i++ )
476  pCnf->pObj2Clause[i] = pCnf->pObj2Count[i] = -1;
477  pCnf->nVars = Aig_ManObjNumMax(p->pManAig);
478 
479  // clear the PI counters
480  Aig_ManForEachCi( p->pManAig, pObj, i )
481  pCnf->pObj2Count[pObj->Id] = 0;
482 
483  // assign the clauses
484  vSopTemp = Vec_IntAlloc( 1 << 16 );
485  pLits = pCnf->pClauses[0];
486  pClas = pCnf->pClauses;
487  Vec_PtrForEachEntry( Aig_Obj_t *, vMapped, pObj, i )
488  {
489  // remember the starting clause
490  pCnf->pObj2Clause[pObj->Id] = pClas - pCnf->pClauses;
491  pCnf->pObj2Count[pObj->Id] = 0;
492 
493  // get the best cut
494  pCut = Cnf_ObjBestCut( pObj );
495  // save variables of this cut
496  OutVar = pObj->Id;
497  for ( k = 0; k < (int)pCut->nFanins; k++ )
498  {
499  pVars[k] = pCut->pFanins[k];
500  assert( pVars[k] <= Aig_ManObjNumMax(p->pManAig) );
501  }
502 
503  // positive polarity of the cut
504  if ( pCut->nFanins < 5 )
505  {
506  uTruth = 0xFFFF & *Cnf_CutTruth(pCut);
507  Cnf_SopConvertToVector( p->pSops[uTruth], p->pSopSizes[uTruth], vSopTemp );
508  vCover = vSopTemp;
509  }
510  else
511  vCover = pCut->vIsop[1];
512  Vec_IntForEachEntry( vCover, Cube, k )
513  {
514  *pClas++ = pLits;
515  *pLits++ = 2 * OutVar;
516  pLits += Cnf_IsopWriteCube( Cube, pCut->nFanins, pVars, pLits );
517  }
518  pCnf->pObj2Count[pObj->Id] += Vec_IntSize(vCover);
519 
520  // negative polarity of the cut
521  if ( pCut->nFanins < 5 )
522  {
523  uTruth = 0xFFFF & ~*Cnf_CutTruth(pCut);
524  Cnf_SopConvertToVector( p->pSops[uTruth], p->pSopSizes[uTruth], vSopTemp );
525  vCover = vSopTemp;
526  }
527  else
528  vCover = pCut->vIsop[0];
529  Vec_IntForEachEntry( vCover, Cube, k )
530  {
531  *pClas++ = pLits;
532  *pLits++ = 2 * OutVar + 1;
533  pLits += Cnf_IsopWriteCube( Cube, pCut->nFanins, pVars, pLits );
534  }
535  pCnf->pObj2Count[pObj->Id] += Vec_IntSize(vCover);
536  }
537  Vec_IntFree( vSopTemp );
538 
539  // write the output literals
540  Aig_ManForEachCo( p->pManAig, pObj, i )
541  {
542  // remember the starting clause
543  pCnf->pObj2Clause[pObj->Id] = pClas - pCnf->pClauses;
544  pCnf->pObj2Count[pObj->Id] = 2;
545  // get variables
546  OutVar = Aig_ObjFanin0(pObj)->Id;
547  PoVar = pObj->Id;
548  // first clause
549  *pClas++ = pLits;
550  *pLits++ = 2 * PoVar;
551  *pLits++ = 2 * OutVar + !Aig_ObjFaninC0(pObj);
552  // second clause
553  *pClas++ = pLits;
554  *pLits++ = 2 * PoVar + 1;
555  *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
556  }
557 
558  // remember the starting clause
559  pCnf->pObj2Clause[Aig_ManConst1(p->pManAig)->Id] = pClas - pCnf->pClauses;
560  pCnf->pObj2Count[Aig_ManConst1(p->pManAig)->Id] = 1;
561  // write the constant literal
562  OutVar = Aig_ManConst1(p->pManAig)->Id;
563  *pClas++ = pLits;
564  *pLits++ = 2 * OutVar;
565 
566  // verify that the correct number of literals and clauses was written
567  assert( pLits - pCnf->pClauses[0] == nLiterals );
568  assert( pClas - pCnf->pClauses == nClauses );
569 //Cnf_DataPrint( pCnf, 1 );
570  return pCnf;
571 }
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nClauses
Definition: cnf.h:61
int nVars
Definition: cnf.h:59
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: aig.h:393
#define Aig_ManForEachCo(p, pObj, i)
Definition: aig.h:398
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
Vec_Int_t * vIsop[2]
Definition: cnf.h:76
int * pObj2Clause
Definition: cnf.h:64
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
int ** pClauses
Definition: cnf.h:62
Definition: cnf.h:71
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
int pFanins[0]
Definition: cnf.h:77
Definition: aig.h:69
int Cnf_IsopWriteCube(int Cube, int nVars, int *pVars, int *pLiterals)
Definition: cnfWrite.c:170
void Cnf_SopConvertToVector(char *pSop, int nCubes, Vec_Int_t *vCover)
Definition: cnfWrite.c:82
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
int Cnf_IsopCountLiterals(Vec_Int_t *vIsop, int nVars)
Definition: cnfWrite.c:144
char nFanins
Definition: cnf.h:73
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int Cnf_SopCountLiterals(char *pSop, int nCubes)
Definition: cnfWrite.c:117
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int nLiterals
Definition: cnf.h:60
int Id
Definition: aig.h:85
int * pObj2Count
Definition: cnf.h:65
static Cnf_Cut_t* Cnf_ObjBestCut ( Aig_Obj_t pObj)
inlinestatic

Definition at line 105 of file cnf.h.

105 { return (Cnf_Cut_t *)pObj->pData; }
void * pData
Definition: aig.h:87
Definition: cnf.h:71
static void Cnf_ObjSetBestCut ( Aig_Obj_t pObj,
Cnf_Cut_t pCut 
)
inlinestatic

Definition at line 106 of file cnf.h.

106 { pObj->pData = pCut; }
void * pData
Definition: aig.h:87
void Cnf_ReadMsops ( char **  ppSopSizes,
char ***  ppSops 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Prepares the data for MSOPs of 4-variable functions.]

Description []

SideEffects []

SeeAlso []

Definition at line 4537 of file cnfData.c.

4538 {
4539  unsigned uMasks[4][2] = {
4540  { 0x5555, 0xAAAA },
4541  { 0x3333, 0xCCCC },
4542  { 0x0F0F, 0xF0F0 },
4543  { 0x00FF, 0xFF00 }
4544  };
4545  char Map[256], * pPrev, * pMemory;
4546  char * pSopSizes, ** pSops;
4547  int i, k, b, Size;
4548 
4549  // map chars into their numbers
4550  for ( i = 0; i < 256; i++ )
4551  Map[i] = (char)(-1);
4552  for ( i = 0; i < 81; i++ )
4553  Map[(int)s_Data3[i]] = (char)i;
4554 
4555  // count the number of strings
4556  for ( Size = 0; s_Data4[Size] && Size < 100000; Size++ );
4557  assert( Size < 100000 );
4558 
4559  // allocate memory
4560  pMemory = ABC_ALLOC( char, Size * 75 );
4561  // copy the array into memory
4562  for ( i = 0; i < Size; i++ )
4563  for ( k = 0; k < 75; k++ )
4564  if ( s_Data4[i][k] == ' ' )
4565  pMemory[i*75+k] = (char)(-1);
4566  else
4567  pMemory[i*75+k] = Map[(int)s_Data4[i][k]];
4568 
4569  // set pointers and compute SOP sizes
4570  pSopSizes = ABC_ALLOC( char, 65536 );
4571  pSops = ABC_ALLOC( char *, 65536 );
4572  pSopSizes[0] = 0;
4573  pSops[0] = NULL;
4574  pPrev = pMemory;
4575  for ( k = 0, i = 1; i < 65536; k++ )
4576  if ( pMemory[k] == (char)(-1) )
4577  {
4578  pSopSizes[i] = pMemory + k - pPrev;
4579  pSops[i++] = pPrev;
4580  pPrev = pMemory + k + 1;
4581  }
4582  *ppSopSizes = pSopSizes;
4583  *ppSops = pSops;
4584 
4585  // verify the results - derive truth table from SOP
4586  for ( i = 1; i < 65536; i++ )
4587  {
4588  int uTruth = 0, uCube, Lit;
4589  for ( k = 0; k < pSopSizes[i]; k++ )
4590  {
4591  uCube = 0xFFFF;
4592  Lit = pSops[i][k];
4593  for ( b = 3; b >= 0; b-- )
4594  {
4595  if ( Lit % 3 == 0 )
4596  uCube &= uMasks[b][0];
4597  else if ( Lit % 3 == 1 )
4598  uCube &= uMasks[b][1];
4599  Lit = Lit / 3;
4600  }
4601  uTruth |= uCube;
4602  }
4603  assert( uTruth == i );
4604  }
4605 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static ABC_NAMESPACE_IMPL_START const char s_Data3[82]
DECLARATIONS ///.
Definition: cnfData.c:30
static const char * s_Data4[]
Definition: cnfData.c:32
#define assert(ex)
Definition: util_old.h:213
void Cnf_SopConvertToVector ( char *  pSop,
int  nCubes,
Vec_Int_t vCover 
)

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

Synopsis [Writes the cover into the array.]

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file cnfWrite.c.

83 {
84  int Lits[4], Cube, iCube, i, b;
85  Vec_IntClear( vCover );
86  for ( i = 0; i < nCubes; i++ )
87  {
88  Cube = pSop[i];
89  for ( b = 0; b < 4; b++ )
90  {
91  if ( Cube % 3 == 0 )
92  Lits[b] = 1;
93  else if ( Cube % 3 == 1 )
94  Lits[b] = 2;
95  else
96  Lits[b] = 0;
97  Cube = Cube / 3;
98  }
99  iCube = 0;
100  for ( b = 0; b < 4; b++ )
101  iCube = (iCube << 2) | Lits[b];
102  Vec_IntPush( vCover, iCube );
103  }
104 }
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
static Dar_Cut_t* Dar_ObjBestCut ( Aig_Obj_t pObj)
inlinestatic

Definition at line 97 of file cnf.h.

97 { Dar_Cut_t * pCut; int i; Dar_ObjForEachCut( pObj, pCut, i ) if ( pCut->fBest ) return pCut; return NULL; }
#define Dar_ObjForEachCut(pObj, pCut, i)
Definition: darInt.h:121
if(last==0)
Definition: sparse_int.h:34