ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cnf.h
Go to the documentation of this file.
1
20
21#ifndef ABC__aig__cnf__cnf_h
22#define ABC__aig__cnf__cnf_h
23
24
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <assert.h>
33
34#include "misc/vec/vec.h"
35#include "aig/aig/aig.h"
36#include "opt/dar/darInt.h"
37
41
42
43
45
46
50
51typedef struct Cnf_Man_t_ Cnf_Man_t;
52typedef struct Cnf_Dat_t_ Cnf_Dat_t;
53typedef struct Cnf_Cut_t_ Cnf_Cut_t;
54
55// the CNF asserting outputs of AIG to be 1
57{
58 Aig_Man_t * pMan; // the AIG manager, for which CNF is computed
59 int nVars; // the number of variables
60 int nLiterals; // the number of CNF literals
61 int nClauses; // the number of CNF clauses
62 int ** pClauses; // the CNF clauses
63 int * pVarNums; // the number of CNF variable for each node ID (-1 if unused)
64 int * pObj2Clause; // the mapping of objects into clauses
65 int * pObj2Count; // the mapping of objects into clause number
66 unsigned char * pClaPols; // polarity of input literals in each clause
67 Vec_Int_t * vMapping; // mapping of internal nodes
68};
69
70// the cut used to represent node in the AIG
72{
73 char nFanins; // the number of leaves
74 char Cost; // the cost of this cut
75 short nWords; // the number of words in truth table
76 Vec_Int_t * vIsop[2]; // neg/pos ISOPs
77 int pFanins[0]; // the fanins (followed by the truth table)
78};
79
80// the CNF computation manager
82{
83 Aig_Man_t * pManAig; // the underlying AIG manager
84 char * pSopSizes; // sizes of SOPs for 4-variable functions
85 char ** pSops; // the SOPs for 4-variable functions
86 int aArea; // the area of the mapping
87 Aig_MmFlex_t * pMemCuts; // memory manager for cuts
88 int nMergeLimit; // the limit on the size of merged cut
89 unsigned * pTruths[4]; // temporary truth tables
90 Vec_Int_t * vMemory; // memory for intermediate ISOP representation
94};
95
96
97static inline Dar_Cut_t * Dar_ObjBestCut( Aig_Obj_t * pObj ) { Dar_Cut_t * pCut; int i; Dar_ObjForEachCut( pObj, pCut, i ) if ( pCut->fBest ) return pCut; return NULL; }
98
99static inline int Cnf_CutSopCost( Cnf_Man_t * p, Dar_Cut_t * pCut ) { return p->pSopSizes[pCut->uTruth] + p->pSopSizes[0xFFFF & ~pCut->uTruth]; }
100
101static inline int Cnf_CutLeaveNum( Cnf_Cut_t * pCut ) { return pCut->nFanins; }
102static inline int * Cnf_CutLeaves( Cnf_Cut_t * pCut ) { return pCut->pFanins; }
103static inline unsigned * Cnf_CutTruth( Cnf_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nFanins); }
104
105static inline Cnf_Cut_t * Cnf_ObjBestCut( Aig_Obj_t * pObj ) { return (Cnf_Cut_t *)pObj->pData; }
106static inline void Cnf_ObjSetBestCut( Aig_Obj_t * pObj, Cnf_Cut_t * pCut ) { pObj->pData = pCut; }
107
111
115
116// iterator over the clauses
117#define Cnf_CnfForClause( p, pBeg, pEnd, i ) \
118 for ( i = 0; i < p->nClauses && (pBeg = p->pClauses[i]) && (pEnd = p->pClauses[i+1]); i++ )
119
120// iterator over leaves of the cut
121#define Cnf_CutForEachLeaf( p, pCut, pLeaf, i ) \
122 for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ )
123
127
128/*=== cnfCore.c ========================================================*/
130extern Cnf_Dat_t * Cnf_Derive( Aig_Man_t * pAig, int nOutputs );
131extern Cnf_Dat_t * Cnf_DeriveWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int nOutputs );
132extern Cnf_Dat_t * Cnf_DeriveOther( Aig_Man_t * pAig, int fSkipTtMin );
133extern Cnf_Dat_t * Cnf_DeriveOtherWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int fSkipTtMin );
134extern void Cnf_ManPrepare();
135extern Cnf_Man_t * Cnf_ManRead();
136extern void Cnf_ManFree();
137/*=== cnfCut.c ========================================================*/
138extern Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Aig_Obj_t * pObj );
139extern void Cnf_CutPrint( Cnf_Cut_t * pCut );
140extern void Cnf_CutFree( Cnf_Cut_t * pCut );
141extern void Cnf_CutUpdateRefs( Cnf_Man_t * p, Cnf_Cut_t * pCut, Cnf_Cut_t * pCutFan, Cnf_Cut_t * pCutRes );
142extern Cnf_Cut_t * Cnf_CutCompose( Cnf_Man_t * p, Cnf_Cut_t * pCut, Cnf_Cut_t * pCutFan, int iFan );
143/*=== cnfData.c ========================================================*/
144extern void Cnf_ReadMsops( char ** ppSopSizes, char *** ppSops );
145/*=== cnfFast.c ========================================================*/
146extern void Cnf_CollectLeaves( Aig_Obj_t * pRoot, Vec_Ptr_t * vSuper, int fStopCompl );
147extern void Cnf_ComputeClauses( Aig_Man_t * p, Aig_Obj_t * pRoot, Vec_Ptr_t * vLeaves,
148 Vec_Ptr_t * vNodes, Vec_Int_t * vMap, Vec_Int_t * vCover, Vec_Int_t * vClauses );
149extern void Cnf_DeriveFastMark( Aig_Man_t * p );
150extern Cnf_Dat_t * Cnf_DeriveFast( Aig_Man_t * p, int nOutputs );
151/*=== cnfMan.c ========================================================*/
152extern Cnf_Man_t * Cnf_ManStart();
153extern void Cnf_ManStop( Cnf_Man_t * p );
155extern Cnf_Dat_t * Cnf_DataAlloc( Aig_Man_t * pAig, int nVars, int nClauses, int nLiterals );
156extern Cnf_Dat_t * Cnf_DataDup( Cnf_Dat_t * p );
157extern Cnf_Dat_t * Cnf_DataDupCof( Cnf_Dat_t * p, int Lit );
158extern Cnf_Dat_t * Cnf_DataDupCofArray( Cnf_Dat_t * p, Vec_Int_t * vLits );
159extern void Cnf_DataFree( Cnf_Dat_t * p );
160extern void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus );
161extern void Cnf_DataCollectFlipLits( Cnf_Dat_t * p, int iFlipVar, Vec_Int_t * vFlips );
162extern void Cnf_DataLiftAndFlipLits( Cnf_Dat_t * p, int nVarsPlus, Vec_Int_t * vLits );
163extern void Cnf_DataPrint( Cnf_Dat_t * p, int fReadable );
164extern void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable, Vec_Int_t * vForAlls, Vec_Int_t * vExists );
165extern void Cnf_DataWriteIntoFileInv( Cnf_Dat_t * p, char * pFileName, int fReadable, Vec_Int_t * vExists1, Vec_Int_t * vForAlls, Vec_Int_t * vExists2 );
166extern void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit );
167extern void * Cnf_DataWriteIntoSolverInt( void * pSat, Cnf_Dat_t * p, int nFrames, int fInit );
168extern int Cnf_DataWriteOrClause( void * pSat, Cnf_Dat_t * pCnf );
169extern int Cnf_DataWriteAndClauses( void * p, Cnf_Dat_t * pCnf );
170extern void Cnf_DataTranformPolarity( Cnf_Dat_t * pCnf, int fTransformPos );
171extern int Cnf_DataAddXorClause( void * pSat, int iVarA, int iVarB, int iVarC );
172/*=== cnfMap.c ========================================================*/
173extern void Cnf_DeriveMapping( Cnf_Man_t * p );
175/*=== cnfPost.c ========================================================*/
176extern void Cnf_ManTransferCuts( Cnf_Man_t * p );
177extern void Cnf_ManFreeCuts( Cnf_Man_t * p );
178extern void Cnf_ManPostprocess( Cnf_Man_t * p );
179/*=== cnfUtil.c ========================================================*/
180extern Vec_Ptr_t * Aig_ManScanMapping( Cnf_Man_t * p, int fCollect );
181extern Vec_Ptr_t * Cnf_ManScanMapping( Cnf_Man_t * p, int fCollect, int fPreorder );
184extern unsigned char * Cnf_DataDeriveLitPolarities( Cnf_Dat_t * p );
185extern Cnf_Dat_t * Cnf_DataReadFromFile( char * pFileName );
186/*=== cnfWrite.c ========================================================*/
187extern Vec_Int_t * Cnf_ManWriteCnfMapping( Cnf_Man_t * p, Vec_Ptr_t * vMapped );
188extern void Cnf_SopConvertToVector( char * pSop, int nCubes, Vec_Int_t * vCover );
189extern Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped, int nOutputs );
190extern Cnf_Dat_t * Cnf_ManWriteCnfOther( Cnf_Man_t * p, Vec_Ptr_t * vMapped );
191extern Cnf_Dat_t * Cnf_DeriveSimple( Aig_Man_t * p, int nOutputs );
193
194
195
197
198
199
200#endif
201
205
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
struct Aig_MmFlex_t_ Aig_MmFlex_t
Definition aig.h:53
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int Cnf_DataAddXorClause(void *pSat, int iVarA, int iVarB, int iVarC)
Definition cnfMan.c:804
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
Cnf_Dat_t * Cnf_DeriveFast(Aig_Man_t *p, int nOutputs)
Definition cnfFast.c:666
void Cnf_DataPrint(Cnf_Dat_t *p, int fReadable)
Definition cnfMan.c:273
Cnf_Dat_t * Cnf_DeriveSimple(Aig_Man_t *p, int nOutputs)
Definition cnfWrite.c:587
Vec_Int_t * Cnf_DeriveMappingArray(Aig_Man_t *pAig)
FUNCTION DECLARATIONS ///.
Definition cnfCore.c:78
Vec_Int_t * Cnf_DataCollectCoSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfUtil.c:429
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:165
Cnf_Dat_t * Cnf_DataDup(Cnf_Dat_t *p)
Definition cnfMan.c:151
Vec_Int_t * Cnf_DataCollectPiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfMan.c:104
Cnf_Dat_t * Cnf_DataReadFromFile(char *pFileName)
Definition cnfUtil.c:511
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition cnfPost.c:117
void Cnf_DataWriteIntoFileInv(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
Definition cnfMan.c:427
Cnf_Dat_t * Cnf_DataDupCofArray(Cnf_Dat_t *p, Vec_Int_t *vLits)
Definition cnfMan.c:178
void Cnf_ManPrepare()
FUNCTION DEFINITIONS ///.
Definition cnfCore.c:46
void Cnf_DataTranformPolarity(Cnf_Dat_t *pCnf, int fTransformPos)
Definition cnfMan.c:768
void Cnf_ReadMsops(char **ppSopSizes, char ***ppSops)
FUNCTION DEFINITIONS ///.
Definition cnfData.c:4537
Cnf_Dat_t * Cnf_DataAlloc(Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
Definition cnfMan.c:124
unsigned char * Cnf_DataDeriveLitPolarities(Cnf_Dat_t *p)
Definition cnfUtil.c:451
void Cnf_ManFreeCuts(Cnf_Man_t *p)
Definition cnfPost.c:142
Cnf_Dat_t * Cnf_ManWriteCnfOther(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
Definition cnfWrite.c:419
int Cnf_DataWriteAndClauses(void *p, Cnf_Dat_t *pCnf)
Definition cnfMan.c:743
int Cnf_ManMapForCnf(Cnf_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition cnf.h:51
void Cnf_SopConvertToVector(char *pSop, int nCubes, Vec_Int_t *vCover)
Definition cnfWrite.c:82
Cnf_Dat_t * Cnf_DeriveOther(Aig_Man_t *pAig, int fSkipTtMin)
Definition cnfCore.c:219
Cnf_Dat_t * Cnf_ManWriteCnf(Cnf_Man_t *p, Vec_Ptr_t *vMapped, int nOutputs)
Definition cnfWrite.c:199
Cnf_Man_t * Cnf_ManStart()
FUNCTION DEFINITIONS ///.
Definition cnfMan.c:51
void * Cnf_DataWriteIntoSolverInt(void *pSat, Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:486
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)
Definition cnfFast.c:198
Cnf_Dat_t * Cnf_DeriveSimpleForRetiming(Aig_Man_t *p)
Definition cnfWrite.c:709
void Cnf_CutUpdateRefs(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, Cnf_Cut_t *pCutRes)
Definition cnfCut.c:178
Cnf_Cut_t * Cnf_CutCompose(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, int iFan)
Definition cnfCut.c:294
void Cnf_ManFree()
Definition cnfCore.c:58
void Cnf_DataCollectFlipLits(Cnf_Dat_t *p, int iFlipVar, Vec_Int_t *vFlips)
Definition cnfMan.c:245
void Cnf_ManPostprocess(Cnf_Man_t *p)
Definition cnfPost.c:165
void Cnf_CollectLeaves(Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
Definition cnfFast.c:76
Cnf_Dat_t * Cnf_DataDupCof(Cnf_Dat_t *p, int Lit)
Definition cnfMan.c:163
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition cnfMap.c:100
Cnf_Cut_t * Cnf_CutCreate(Cnf_Man_t *p, Aig_Obj_t *pObj)
Definition cnfCut.c:87
int Cnf_DataWriteOrClause(void *pSat, Cnf_Dat_t *pCnf)
Definition cnfMan.c:687
Cnf_Dat_t * Cnf_DeriveWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:129
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition cnfUtil.c:377
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataLiftAndFlipLits(Cnf_Dat_t *p, int nVarsPlus, Vec_Int_t *vLits)
Definition cnfMan.c:254
void Cnf_CutPrint(Cnf_Cut_t *pCut)
Definition cnfCut.c:115
Cnf_Man_t * Cnf_ManRead()
Definition cnfCore.c:54
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition cnfCut.c:68
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
struct Cnf_Cut_t_ Cnf_Cut_t
Definition cnf.h:53
void Cnf_ManStop(Cnf_Man_t *p)
Definition cnfMan.c:82
Vec_Int_t * Cnf_ManWriteCnfMapping(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition cnfWrite.c:45
Cnf_Dat_t * Cnf_DeriveOtherWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int fSkipTtMin)
Definition cnfCore.c:182
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition cnfMan.c:387
Vec_Int_t * Cnf_DataCollectCiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfUtil.c:407
Vec_Ptr_t * Aig_ManScanMapping(Cnf_Man_t *p, int fCollect)
Definition cnfUtil.c:297
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Definition cnfMan.c:232
void Cnf_DeriveFastMark(Aig_Man_t *p)
Definition cnfFast.c:297
struct Dar_Cut_t_ Dar_Cut_t
Definition darInt.h:52
#define Dar_ObjForEachCut(pObj, pCut, i)
Definition darInt.h:121
Cube * p
Definition exorList.c:222
void * pData
Definition aig.h:87
Vec_Int_t * vIsop[2]
Definition cnf.h:76
char nFanins
Definition cnf.h:73
int pFanins[0]
Definition cnf.h:77
char Cost
Definition cnf.h:74
short nWords
Definition cnf.h:75
int nVars
Definition cnf.h:59
int * pObj2Count
Definition cnf.h:65
int * pObj2Clause
Definition cnf.h:64
unsigned char * pClaPols
Definition cnf.h:66
int nLiterals
Definition cnf.h:60
int * pVarNums
Definition cnf.h:63
Vec_Int_t * vMapping
Definition cnf.h:67
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
Aig_Man_t * pMan
Definition cnf.h:58
Vec_Int_t * vMemory
Definition cnf.h:90
Aig_Man_t * pManAig
Definition cnf.h:83
Aig_MmFlex_t * pMemCuts
Definition cnf.h:87
abctime timeMap
Definition cnf.h:92
char * pSopSizes
Definition cnf.h:84
unsigned * pTruths[4]
Definition cnf.h:89
abctime timeCuts
Definition cnf.h:91
int nMergeLimit
Definition cnf.h:88
abctime timeSave
Definition cnf.h:93
char ** pSops
Definition cnf.h:85
int aArea
Definition cnf.h:86
unsigned fBest
Definition darInt.h:60
unsigned uTruth
Definition darInt.h:58
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42