abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cnf.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cnf.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [DAG-aware AIG rewriting.]
8 
9  Synopsis [External declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: cnf.h,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__aig__cnf__cnf_h
22 #define ABC__aig__cnf__cnf_h
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// INCLUDES ///
27 ////////////////////////////////////////////////////////////////////////
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 
38 ////////////////////////////////////////////////////////////////////////
39 /// PARAMETERS ///
40 ////////////////////////////////////////////////////////////////////////
41 
42 
43 
45 
46 
47 ////////////////////////////////////////////////////////////////////////
48 /// BASIC TYPES ///
49 ////////////////////////////////////////////////////////////////////////
50 
51 typedef struct Cnf_Man_t_ Cnf_Man_t;
52 typedef struct Cnf_Dat_t_ Cnf_Dat_t;
53 typedef struct Cnf_Cut_t_ Cnf_Cut_t;
54 
55 // the CNF asserting outputs of AIG to be 1
56 struct Cnf_Dat_t_
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
71 struct Cnf_Cut_t_
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
81 struct Cnf_Man_t_
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 
97 static 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 
99 static inline int Cnf_CutSopCost( Cnf_Man_t * p, Dar_Cut_t * pCut ) { return p->pSopSizes[pCut->uTruth] + p->pSopSizes[0xFFFF & ~pCut->uTruth]; }
100 
101 static inline int Cnf_CutLeaveNum( Cnf_Cut_t * pCut ) { return pCut->nFanins; }
102 static inline int * Cnf_CutLeaves( Cnf_Cut_t * pCut ) { return pCut->pFanins; }
103 static inline unsigned * Cnf_CutTruth( Cnf_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nFanins); }
104 
105 static inline Cnf_Cut_t * Cnf_ObjBestCut( Aig_Obj_t * pObj ) { return (Cnf_Cut_t *)pObj->pData; }
106 static inline void Cnf_ObjSetBestCut( Aig_Obj_t * pObj, Cnf_Cut_t * pCut ) { pObj->pData = pCut; }
107 
108 ////////////////////////////////////////////////////////////////////////
109 /// MACRO DEFINITIONS ///
110 ////////////////////////////////////////////////////////////////////////
111 
112 ////////////////////////////////////////////////////////////////////////
113 /// ITERATORS ///
114 ////////////////////////////////////////////////////////////////////////
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 
124 ////////////////////////////////////////////////////////////////////////
125 /// FUNCTION DECLARATIONS ///
126 ////////////////////////////////////////////////////////////////////////
127 
128 /*=== cnfCore.c ========================================================*/
129 extern Vec_Int_t * Cnf_DeriveMappingArray( Aig_Man_t * pAig );
130 extern Cnf_Dat_t * Cnf_Derive( Aig_Man_t * pAig, int nOutputs );
131 extern Cnf_Dat_t * Cnf_DeriveWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int nOutputs );
132 extern Cnf_Dat_t * Cnf_DeriveOther( Aig_Man_t * pAig, int fSkipTtMin );
133 extern Cnf_Dat_t * Cnf_DeriveOtherWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int fSkipTtMin );
134 extern void Cnf_ManPrepare();
135 extern Cnf_Man_t * Cnf_ManRead();
136 extern void Cnf_ManFree();
137 /*=== cnfCut.c ========================================================*/
138 extern Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Aig_Obj_t * pObj );
139 extern void Cnf_CutPrint( Cnf_Cut_t * pCut );
140 extern void Cnf_CutFree( Cnf_Cut_t * pCut );
141 extern void Cnf_CutUpdateRefs( Cnf_Man_t * p, Cnf_Cut_t * pCut, Cnf_Cut_t * pCutFan, Cnf_Cut_t * pCutRes );
142 extern Cnf_Cut_t * Cnf_CutCompose( Cnf_Man_t * p, Cnf_Cut_t * pCut, Cnf_Cut_t * pCutFan, int iFan );
143 /*=== cnfData.c ========================================================*/
144 extern void Cnf_ReadMsops( char ** ppSopSizes, char *** ppSops );
145 /*=== cnfFast.c ========================================================*/
146 extern void Cnf_CollectLeaves( Aig_Obj_t * pRoot, Vec_Ptr_t * vSuper, int fStopCompl );
147 extern 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 );
149 extern void Cnf_DeriveFastMark( Aig_Man_t * p );
150 extern Cnf_Dat_t * Cnf_DeriveFast( Aig_Man_t * p, int nOutputs );
151 /*=== cnfMan.c ========================================================*/
152 extern Cnf_Man_t * Cnf_ManStart();
153 extern void Cnf_ManStop( Cnf_Man_t * p );
155 extern Cnf_Dat_t * Cnf_DataAlloc( Aig_Man_t * pAig, int nVars, int nClauses, int nLiterals );
156 extern Cnf_Dat_t * Cnf_DataDup( Cnf_Dat_t * p );
157 extern void Cnf_DataFree( Cnf_Dat_t * p );
158 extern void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus );
159 extern void Cnf_DataFlipLastLiteral( Cnf_Dat_t * p );
160 extern void Cnf_DataPrint( Cnf_Dat_t * p, int fReadable );
161 extern void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable, Vec_Int_t * vForAlls, Vec_Int_t * vExists );
162 extern void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit );
163 extern void * Cnf_DataWriteIntoSolverInt( void * pSat, Cnf_Dat_t * p, int nFrames, int fInit );
164 extern int Cnf_DataWriteOrClause( void * pSat, Cnf_Dat_t * pCnf );
165 extern int Cnf_DataWriteAndClauses( void * p, Cnf_Dat_t * pCnf );
166 extern void Cnf_DataTranformPolarity( Cnf_Dat_t * pCnf, int fTransformPos );
167 extern int Cnf_DataAddXorClause( void * pSat, int iVarA, int iVarB, int iVarC );
168 /*=== cnfMap.c ========================================================*/
169 extern void Cnf_DeriveMapping( Cnf_Man_t * p );
170 extern int Cnf_ManMapForCnf( Cnf_Man_t * p );
171 /*=== cnfPost.c ========================================================*/
172 extern void Cnf_ManTransferCuts( Cnf_Man_t * p );
173 extern void Cnf_ManFreeCuts( Cnf_Man_t * p );
174 extern void Cnf_ManPostprocess( Cnf_Man_t * p );
175 /*=== cnfUtil.c ========================================================*/
176 extern Vec_Ptr_t * Aig_ManScanMapping( Cnf_Man_t * p, int fCollect );
177 extern Vec_Ptr_t * Cnf_ManScanMapping( Cnf_Man_t * p, int fCollect, int fPreorder );
180 extern unsigned char * Cnf_DataDeriveLitPolarities( Cnf_Dat_t * p );
181 extern Cnf_Dat_t * Cnf_DataReadFromFile( char * pFileName );
182 /*=== cnfWrite.c ========================================================*/
183 extern Vec_Int_t * Cnf_ManWriteCnfMapping( Cnf_Man_t * p, Vec_Ptr_t * vMapped );
184 extern void Cnf_SopConvertToVector( char * pSop, int nCubes, Vec_Int_t * vCover );
185 extern Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped, int nOutputs );
186 extern Cnf_Dat_t * Cnf_ManWriteCnfOther( Cnf_Man_t * p, Vec_Ptr_t * vMapped );
187 extern Cnf_Dat_t * Cnf_DeriveSimple( Aig_Man_t * p, int nOutputs );
189 
190 
191 
193 
194 
195 
196 #endif
197 
198 ////////////////////////////////////////////////////////////////////////
199 /// END OF FILE ///
200 ////////////////////////////////////////////////////////////////////////
201 
Cnf_Man_t * Cnf_ManRead()
Definition: cnfCore.c:54
static int * Cnf_CutLeaves(Cnf_Cut_t *pCut)
Definition: cnf.h:102
int nMergeLimit
Definition: cnf.h:88
void Cnf_DeriveFastMark(Aig_Man_t *p)
Definition: cnfFast.c:297
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:165
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
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
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Cnf_ManPostprocess(Cnf_Man_t *p)
Definition: cnfPost.c:165
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition: cnfMan.c:318
int Cnf_DataWriteOrClause(void *pSat, Cnf_Dat_t *pCnf)
Definition: cnfMan.c:571
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition: cnfUtil.c:170
int nClauses
Definition: cnf.h:61
Cnf_Dat_t * Cnf_DeriveWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:129
unsigned fBest
Definition: darInt.h:60
void * pData
Definition: aig.h:87
unsigned uTruth
Definition: darInt.h:58
Definition: cnf.h:81
void Cnf_ManStop(Cnf_Man_t *p)
Definition: cnfMan.c:82
int nVars
Definition: cnf.h:59
Vec_Int_t * vMapping
Definition: cnf.h:67
Cnf_Dat_t * Cnf_DeriveOtherWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int fSkipTtMin)
Definition: cnfCore.c:182
unsigned char * pClaPols
Definition: cnf.h:66
Cnf_Dat_t * Cnf_ManWriteCnfOther(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
Definition: cnfWrite.c:419
int * pVarNums
Definition: cnf.h:63
void Cnf_DataTranformPolarity(Cnf_Dat_t *pCnf, int fTransformPos)
Definition: cnfMan.c:652
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
void Cnf_CutPrint(Cnf_Cut_t *pCut)
Definition: cnfCut.c:115
int aArea
Definition: cnf.h:86
short nWords
Definition: cnf.h:75
Cnf_Dat_t * Cnf_DeriveSimpleForRetiming(Aig_Man_t *p)
Definition: cnfWrite.c:709
static void Cnf_ObjSetBestCut(Aig_Obj_t *pObj, Cnf_Cut_t *pCut)
Definition: cnf.h:106
Aig_Man_t * pMan
Definition: cnf.h:58
Definition: cnf.h:56
Cnf_Dat_t * Cnf_DataDup(Cnf_Dat_t *p)
Definition: cnfMan.c:157
abctime timeMap
Definition: cnf.h:92
abctime timeCuts
Definition: cnf.h:91
char Cost
Definition: cnf.h:74
Aig_Man_t * pManAig
Definition: cnf.h:83
Vec_Int_t * vIsop[2]
Definition: cnf.h:76
Cnf_Dat_t * Cnf_ManWriteCnf(Cnf_Man_t *p, Vec_Ptr_t *vMapped, int nOutputs)
Definition: cnfWrite.c:199
int * pObj2Clause
Definition: cnf.h:64
static unsigned * Cnf_CutTruth(Cnf_Cut_t *pCut)
Definition: cnf.h:103
#define Dar_ObjForEachCut(pObj, pCut, i)
Definition: darInt.h:121
Vec_Int_t * Cnf_DeriveMappingArray(Aig_Man_t *pAig)
FUNCTION DECLARATIONS ///.
Definition: cnfCore.c:78
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_DataFlipLastLiteral(Cnf_Dat_t *p)
Definition: cnfMan.c:230
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition: cnfMap.c:100
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:126
int ** pClauses
Definition: cnf.h:62
Definition: cnf.h:71
void Cnf_ManFreeCuts(Cnf_Man_t *p)
Definition: cnfPost.c:142
void Cnf_ManFree()
Definition: cnfCore.c:58
int pFanins[0]
Definition: cnf.h:77
Vec_Int_t * Cnf_DataCollectPiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition: cnfMan.c:104
void Cnf_SopConvertToVector(char *pSop, int nCubes, Vec_Int_t *vCover)
Definition: cnfWrite.c:82
Cnf_Dat_t * Cnf_DeriveFast(Aig_Man_t *p, int nOutputs)
Definition: cnfFast.c:666
void * Cnf_DataWriteIntoSolverInt(void *pSat, Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:370
int Cnf_DataAddXorClause(void *pSat, int iVarA, int iVarB, int iVarC)
Definition: cnfMan.c:688
int Cnf_ManMapForCnf(Cnf_Man_t *p)
Definition: aig.h:69
void Cnf_CollectLeaves(Aig_Obj_t *pRoot, Vec_Ptr_t *vSuper, int fStopCompl)
Definition: cnfFast.c:76
void Cnf_CutUpdateRefs(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, Cnf_Cut_t *pCutRes)
Definition: cnfCut.c:178
Cnf_Dat_t * Cnf_DeriveOther(Aig_Man_t *pAig, int fSkipTtMin)
Definition: cnfCore.c:219
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
unsigned char * Cnf_DataDeriveLitPolarities(Cnf_Dat_t *p)
Definition: cnfUtil.c:244
static Dar_Cut_t * Dar_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:97
Aig_MmFlex_t * pMemCuts
Definition: cnf.h:87
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Definition: cnfMan.c:205
Vec_Int_t * vMemory
Definition: cnf.h:90
int Cnf_DataWriteAndClauses(void *p, Cnf_Dat_t *pCnf)
Definition: cnfMan.c:627
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
Cnf_Cut_t * Cnf_CutCreate(Cnf_Man_t *p, Aig_Obj_t *pObj)
Definition: cnfCut.c:87
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
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:463
Cnf_Dat_t * Cnf_DeriveSimple(Aig_Man_t *p, int nOutputs)
Definition: cnfWrite.c:587
void Cnf_DataPrint(Cnf_Dat_t *p, int fReadable)
Definition: cnfMan.c:246
abctime timeSave
Definition: cnf.h:93
char * pSopSizes
Definition: cnf.h:84
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
Vec_Int_t * Cnf_DataCollectCiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition: cnfUtil.c:200
Cnf_Dat_t * Cnf_DataReadFromFile(char *pFileName)
Definition: cnfUtil.c:304
unsigned * pTruths[4]
Definition: cnf.h:89
Vec_Ptr_t * Aig_ManScanMapping(Cnf_Man_t *p, int fCollect)
Definition: cnfUtil.c:90
static int Cnf_CutLeaveNum(Cnf_Cut_t *pCut)
Definition: cnf.h:101
char nFanins
Definition: cnf.h:73
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
int nLiterals
Definition: cnf.h:60
Vec_Int_t * Cnf_DataCollectCoSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition: cnfUtil.c:222
void Cnf_ManPrepare()
FUNCTION DEFINITIONS ///.
Definition: cnfCore.c:46
char ** pSops
Definition: cnf.h:85
int * pObj2Count
Definition: cnf.h:65