abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sfmInt.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [rsbInt.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT-based optimization using internal don't-cares.]
8 
9  Synopsis [Internal declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: rsbInt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__opt_sfmInt__h
22 #define ABC__opt_sfmInt__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 "sat/bsat/satSolver.h"
36 #include "sfm.h"
37 
38 ////////////////////////////////////////////////////////////////////////
39 /// PARAMETERS ///
40 ////////////////////////////////////////////////////////////////////////
41 
43 
44 #define SFM_FANIN_MAX 6
45 #define SFM_SAT_UNDEC 0x1234567812345678
46 #define SFM_SAT_SAT 0x8765432187654321
47 
48 ////////////////////////////////////////////////////////////////////////
49 /// BASIC TYPES ///
50 ////////////////////////////////////////////////////////////////////////
51 
52 struct Sfm_Ntk_t_
53 {
54  // parameters
55  Sfm_Par_t * pPars; // parameters
56  // objects
57  int nPis; // PI count (PIs should be first objects)
58  int nPos; // PO count (POs should be last objects)
59  int nNodes; // internal nodes
60  int nObjs; // total objects
61  int nLevelMax; // maximum level
62  // user data
63  Vec_Str_t * vFixed; // persistent objects
64  Vec_Str_t * vEmpty; // transparent objects
65  Vec_Wrd_t * vTruths; // truth tables
66  Vec_Wec_t vFanins; // fanins
67  // attributes
68  Vec_Wec_t vFanouts; // fanouts
69  Vec_Int_t vLevels; // logic level
70  Vec_Int_t vLevelsR; // logic level
71  Vec_Int_t vCounts; // fanin counters
72  Vec_Int_t vId2Var; // ObjId -> SatVar
73  Vec_Int_t vVar2Id; // SatVar -> ObjId
74  Vec_Wec_t * vCnfs; // CNFs
75  Vec_Int_t * vCover; // temporary
76  // traversal IDs
77  Vec_Int_t vTravIds; // traversal IDs
78  Vec_Int_t vTravIds2; // traversal IDs
79  int nTravIds; // traversal IDs
80  int nTravIds2; // traversal IDs
81  // window
82  int iPivotNode; // window pivot
83  Vec_Int_t * vNodes; // internal
84  Vec_Int_t * vDivs; // divisors
85  Vec_Int_t * vRoots; // roots
86  Vec_Int_t * vTfo; // TFO (excluding iNode)
87  // SAT solving
88  sat_solver * pSat; // SAT solver
89  int nSatVars; // the number of variables
90  int nTryRemoves; // number of fanin removals
91  int nTryResubs; // number of resubstitutions
92  int nRemoves; // number of fanin removals
93  int nResubs; // number of resubstitutions
94  // counter-examples
95  int nCexes; // number of CEXes
96  Vec_Wrd_t * vDivCexes; // counter-examples
97  // intermediate data
98  Vec_Int_t * vOrder; // object order
99  Vec_Int_t * vDivVars; // divisor SAT variables
100  Vec_Int_t * vDivIds; // divisors indexes
101  Vec_Int_t * vLits; // literals
102  Vec_Int_t * vValues; // SAT variable values
103  Vec_Wec_t * vClauses; // CNF clauses for the node
104  Vec_Int_t * vFaninMap; // mapping fanins into their SAT vars
105  // nodes
114  int nMaxDivs;
115  // runtime
122 // abctime time1;
123 };
124 
125 static inline int Sfm_NtkPiNum( Sfm_Ntk_t * p ) { return p->nPis; }
126 static inline int Sfm_NtkPoNum( Sfm_Ntk_t * p ) { return p->nPos; }
127 static inline int Sfm_NtkNodeNum( Sfm_Ntk_t * p ) { return p->nObjs - p->nPis - p->nPos; }
128 
129 static inline int Sfm_ObjIsPi( Sfm_Ntk_t * p, int i ) { return i < p->nPis; }
130 static inline int Sfm_ObjIsPo( Sfm_Ntk_t * p, int i ) { return i + p->nPos >= p->nObjs; }
131 static inline int Sfm_ObjIsNode( Sfm_Ntk_t * p, int i ) { return i >= p->nPis && i + p->nPos < p->nObjs; }
132 static inline int Sfm_ObjIsFixed( Sfm_Ntk_t * p, int i ) { return Vec_StrEntry(p->vFixed, i); }
133 static inline int Sfm_ObjAddsLevelArray( Vec_Str_t * p, int i ) { return p == NULL || Vec_StrEntry(p, i) == 0; }
134 static inline int Sfm_ObjAddsLevel( Sfm_Ntk_t * p, int i ) { return Sfm_ObjAddsLevelArray(p->vEmpty, i); }
135 
136 static inline Vec_Int_t * Sfm_ObjFiArray( Sfm_Ntk_t * p, int i ) { return Vec_WecEntry(&p->vFanins, i); }
137 static inline Vec_Int_t * Sfm_ObjFoArray( Sfm_Ntk_t * p, int i ) { return Vec_WecEntry(&p->vFanouts, i); }
138 
139 static inline int Sfm_ObjFaninNum( Sfm_Ntk_t * p, int i ) { return Vec_IntSize(Sfm_ObjFiArray(p, i)); }
140 static inline int Sfm_ObjFanoutNum( Sfm_Ntk_t * p, int i ) { return Vec_IntSize(Sfm_ObjFoArray(p, i)); }
141 
142 static inline int Sfm_ObjRefIncrement( Sfm_Ntk_t * p, int iObj ) { return ++Sfm_ObjFoArray(p, iObj)->nSize; }
143 static inline int Sfm_ObjRefDecrement( Sfm_Ntk_t * p, int iObj ) { return --Sfm_ObjFoArray(p, iObj)->nSize; }
144 
145 static inline int Sfm_ObjFanin( Sfm_Ntk_t * p, int i, int k ) { return Vec_IntEntry(Sfm_ObjFiArray(p, i), k); }
146 static inline int Sfm_ObjFanout( Sfm_Ntk_t * p, int i, int k ) { return Vec_IntEntry(Sfm_ObjFoArray(p, i), k); }
147 
148 static inline int Sfm_ObjSatVar( Sfm_Ntk_t * p, int iObj ) { assert(Vec_IntEntry(&p->vId2Var, iObj) > 0); return Vec_IntEntry(&p->vId2Var, iObj); }
149 static inline void Sfm_ObjSetSatVar( Sfm_Ntk_t * p, int iObj, int Num ) { assert(Vec_IntEntry(&p->vId2Var, iObj) == -1); Vec_IntWriteEntry(&p->vId2Var, iObj, Num); Vec_IntWriteEntry(&p->vVar2Id, Num, iObj); }
150 static inline void Sfm_ObjCleanSatVar( Sfm_Ntk_t * p, int Num ) { int iObj = Vec_IntEntry(&p->vVar2Id, Num); assert(Vec_IntEntry(&p->vId2Var, iObj) > 0); Vec_IntWriteEntry(&p->vId2Var, iObj, -1); Vec_IntWriteEntry(&p->vVar2Id, Num, -1); }
151 static inline void Sfm_NtkCleanVars( Sfm_Ntk_t * p ) { int i; for ( i = 1; i < p->nSatVars; i++ ) if ( Vec_IntEntry(&p->vVar2Id, i) != -1 ) Sfm_ObjCleanSatVar( p, i ); }
152 
153 static inline int Sfm_ObjLevel( Sfm_Ntk_t * p, int iObj ) { return Vec_IntEntry( &p->vLevels, iObj ); }
154 static inline void Sfm_ObjSetLevel( Sfm_Ntk_t * p, int iObj, int Lev ) { Vec_IntWriteEntry( &p->vLevels, iObj, Lev ); }
155 
156 static inline int Sfm_ObjLevelR( Sfm_Ntk_t * p, int iObj ) { return Vec_IntEntry( &p->vLevelsR, iObj ); }
157 static inline void Sfm_ObjSetLevelR( Sfm_Ntk_t * p, int iObj, int Lev ) { Vec_IntWriteEntry( &p->vLevelsR, iObj, Lev ); }
158 
159 static inline int Sfm_ObjUpdateFaninCount( Sfm_Ntk_t * p, int iObj ) { return Vec_IntAddToEntry(&p->vCounts, iObj, -1); }
160 static inline void Sfm_ObjResetFaninCount( Sfm_Ntk_t * p, int iObj ) { Vec_IntWriteEntry(&p->vCounts, iObj, Sfm_ObjFaninNum(p, iObj)-1); }
161 
162 extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars );
163 
164 ////////////////////////////////////////////////////////////////////////
165 /// MACRO DEFINITIONS ///
166 ////////////////////////////////////////////////////////////////////////
167 
168 #define Sfm_NtkForEachPi( p, i ) for ( i = 0; i < p->nPis; i++ )
169 #define Sfm_NtkForEachPo( p, i ) for ( i = p->nObjs - p->nPos; i < p->nObjs; i++ )
170 #define Sfm_NtkForEachNode( p, i ) for ( i = p->nPis; i + p->nPos < p->nObjs; i++ )
171 #define Sfm_NtkForEachNodeReverse( p, i ) for ( i = p->nObjs - p->nPos - 1; i >= p->nPis; i-- )
172 #define Sfm_ObjForEachFanin( p, Node, Fan, i ) for ( i = 0; i < Sfm_ObjFaninNum(p, Node) && ((Fan = Sfm_ObjFanin(p, Node, i)), 1); i++ )
173 #define Sfm_ObjForEachFanout( p, Node, Fan, i ) for ( i = 0; i < Sfm_ObjFanoutNum(p, Node) && ((Fan = Sfm_ObjFanout(p, Node, i)), 1); i++ )
174 
175 ////////////////////////////////////////////////////////////////////////
176 /// FUNCTION DECLARATIONS ///
177 ////////////////////////////////////////////////////////////////////////
178 
179 /*=== sfmCnf.c ==========================================================*/
180 extern void Sfm_PrintCnf( Vec_Str_t * vCnf );
181 extern int Sfm_TruthToCnf( word Truth, int nVars, Vec_Int_t * vCover, Vec_Str_t * vCnf );
182 extern Vec_Wec_t * Sfm_CreateCnf( Sfm_Ntk_t * p );
183 extern void Sfm_TranslateCnf( Vec_Wec_t * vRes, Vec_Str_t * vCnf, Vec_Int_t * vFaninMap, int iPivotVar );
184 /*=== sfmCore.c ==========================================================*/
185 /*=== sfmNtk.c ==========================================================*/
186 extern Sfm_Ntk_t * Sfm_ConstructNetwork( Vec_Wec_t * vFanins, int nPis, int nPos );
187 extern void Sfm_NtkPrepare( Sfm_Ntk_t * p );
188 extern void Sfm_NtkUpdate( Sfm_Ntk_t * p, int iNode, int f, int iFaninNew, word uTruth );
189 /*=== sfmSat.c ==========================================================*/
190 extern int Sfm_NtkWindowToSolver( Sfm_Ntk_t * p );
192 /*=== sfmWin.c ==========================================================*/
193 extern int Sfm_ObjMffcSize( Sfm_Ntk_t * p, int iObj );
194 extern int Sfm_NtkCreateWindow( Sfm_Ntk_t * p, int iNode, int fVerbose );
195 
197 
198 #endif
199 
200 ////////////////////////////////////////////////////////////////////////
201 /// END OF FILE ///
202 ////////////////////////////////////////////////////////////////////////
203 
Vec_Int_t * vValues
Definition: sfmInt.h:102
int nTotalNodesEnd
Definition: sfmInt.h:108
static int Sfm_ObjAddsLevel(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:134
Vec_Wec_t * vCnfs
Definition: sfmInt.h:74
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition: vecWec.h:42
int Sfm_NtkWindowToSolver(Sfm_Ntk_t *p)
FUNCTION DEFINITIONS ///.
Definition: sfmSat.c:54
Vec_Int_t * vDivIds
Definition: sfmInt.h:100
Vec_Int_t * vDivVars
Definition: sfmInt.h:99
void Sfm_NtkUpdate(Sfm_Ntk_t *p, int iNode, int f, int iFaninNew, word uTruth)
Definition: sfmNtk.c:314
int nTotalEdgesEnd
Definition: sfmInt.h:109
Vec_Str_t * vEmpty
Definition: sfmInt.h:64
Sfm_Par_t * pPars
Definition: sfmInt.h:55
Sfm_Ntk_t * Sfm_ConstructNetwork(Vec_Wec_t *vFanins, int nPis, int nPos)
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
abctime timeTotal
Definition: sfmInt.h:121
abctime timeOther
Definition: sfmInt.h:120
Vec_Int_t vTravIds
Definition: sfmInt.h:77
Vec_Wrd_t * vDivCexes
Definition: sfmInt.h:96
int Sfm_TruthToCnf(word Truth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vCnf)
Definition: sfmCnf.c:71
int nTimeOuts
Definition: sfmInt.h:113
Vec_Wec_t * vClauses
Definition: sfmInt.h:103
Vec_Int_t * vOrder
Definition: sfmInt.h:98
static int Sfm_ObjFaninNum(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:139
Vec_Int_t * vNodes
Definition: sfmInt.h:83
static void Sfm_NtkCleanVars(Sfm_Ntk_t *p)
Definition: sfmInt.h:151
static int Sfm_ObjUpdateFaninCount(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:159
abctime timeCnf
Definition: sfmInt.h:118
typedefABC_NAMESPACE_HEADER_START struct Sfm_Ntk_t_ Sfm_Ntk_t
INCLUDES ///.
Definition: sfm.h:41
Vec_Wrd_t * vTruths
Definition: sfmInt.h:65
static void Sfm_ObjCleanSatVar(Sfm_Ntk_t *p, int Num)
Definition: sfmInt.h:150
Definition: sfm.h:43
static int Sfm_ObjIsNode(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:131
word Sfm_ComputeInterpolant(Sfm_Ntk_t *p)
Definition: sfmSat.c:162
int nTravIds
Definition: sfmInt.h:79
Vec_Int_t * vTfo
Definition: sfmInt.h:86
Vec_Int_t vCounts
Definition: sfmInt.h:71
static int Sfm_ObjLevel(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:153
Vec_Int_t vVar2Id
Definition: sfmInt.h:73
int Sfm_NtkCreateWindow(Sfm_Ntk_t *p, int iNode, int fVerbose)
Definition: sfmWin.c:334
static int Sfm_ObjFanin(Sfm_Ntk_t *p, int i, int k)
Definition: sfmInt.h:145
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
Vec_Int_t * vRoots
Definition: sfmInt.h:85
static int Sfm_ObjIsPi(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:129
static char Vec_StrEntry(Vec_Str_t *p, int i)
Definition: vecStr.h:336
abctime timeSat
Definition: sfmInt.h:119
int nResubs
Definition: sfmInt.h:93
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static int Sfm_ObjSatVar(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:148
static int Sfm_ObjIsPo(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:130
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static int Sfm_ObjFanout(Sfm_Ntk_t *p, int i, int k)
Definition: sfmInt.h:146
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int nMaxDivs
Definition: sfmInt.h:114
static Vec_Int_t * Sfm_ObjFiArray(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:136
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static int Sfm_ObjLevelR(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:156
void Sfm_PrintCnf(Vec_Str_t *vCnf)
FUNCTION DECLARATIONS ///.
Definition: sfmCnf.c:46
Vec_Int_t vId2Var
Definition: sfmInt.h:72
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static int Sfm_ObjRefDecrement(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:143
abctime timeWin
Definition: sfmInt.h:116
Vec_Wec_t * Sfm_CreateCnf(Sfm_Ntk_t *p)
Definition: sfmCnf.c:122
static Vec_Int_t * Vec_WecEntry(Vec_Wec_t *p, int i)
Definition: vecWec.h:142
static int Sfm_ObjAddsLevelArray(Vec_Str_t *p, int i)
Definition: sfmInt.h:133
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
int nSatVars
Definition: sfmInt.h:89
int nCexes
Definition: sfmInt.h:95
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
BASIC TYPES ///.
Definition: sfmInt.h:52
Vec_Wec_t vFanins
Definition: sfmInt.h:66
int iPivotNode
Definition: sfmInt.h:82
static int Sfm_NtkPoNum(Sfm_Ntk_t *p)
Definition: sfmInt.h:126
static void Sfm_ObjSetSatVar(Sfm_Ntk_t *p, int iObj, int Num)
Definition: sfmInt.h:149
sat_solver * pSat
Definition: sfmInt.h:88
static void Sfm_ObjResetFaninCount(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:160
static int Sfm_ObjFanoutNum(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:140
static void Sfm_ObjSetLevel(Sfm_Ntk_t *p, int iObj, int Lev)
Definition: sfmInt.h:154
static Vec_Int_t * Sfm_ObjFoArray(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:137
void Sfm_NtkPrepare(Sfm_Ntk_t *p)
Definition: sfmNtk.c:195
int nTryRemoves
Definition: sfmInt.h:90
Vec_Int_t vLevelsR
Definition: sfmInt.h:70
abctime timeDiv
Definition: sfmInt.h:117
Vec_Int_t vLevels
Definition: sfmInt.h:69
int nPis
Definition: sfmInt.h:57
int nTotalNodesBeg
Definition: sfmInt.h:106
int nTotalDivs
Definition: sfmInt.h:111
int nPos
Definition: sfmInt.h:58
#define assert(ex)
Definition: util_old.h:213
static int Sfm_ObjIsFixed(Sfm_Ntk_t *p, int i)
Definition: sfmInt.h:132
int nObjs
Definition: sfmInt.h:60
int nTravIds2
Definition: sfmInt.h:80
void Sfm_TranslateCnf(Vec_Wec_t *vRes, Vec_Str_t *vCnf, Vec_Int_t *vFaninMap, int iPivotVar)
Definition: sfmCnf.c:153
Vec_Wec_t vFanouts
Definition: sfmInt.h:68
int nSatCalls
Definition: sfmInt.h:112
ABC_INT64_T abctime
Definition: abc_global.h:278
int nLevelMax
Definition: sfmInt.h:61
Vec_Int_t vTravIds2
Definition: sfmInt.h:78
Vec_Int_t * vDivs
Definition: sfmInt.h:84
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition: vecWrd.h:42
int nNodes
Definition: sfmInt.h:59
static void Sfm_ObjSetLevelR(Sfm_Ntk_t *p, int iObj, int Lev)
Definition: sfmInt.h:157
Vec_Str_t * vFixed
Definition: sfmInt.h:63
Vec_Int_t * vFaninMap
Definition: sfmInt.h:104
static int Sfm_NtkNodeNum(Sfm_Ntk_t *p)
Definition: sfmInt.h:127
static int Sfm_ObjRefIncrement(Sfm_Ntk_t *p, int iObj)
Definition: sfmInt.h:142
Vec_Int_t * vLits
Definition: sfmInt.h:101
int nRemoves
Definition: sfmInt.h:92
static int Sfm_NtkPiNum(Sfm_Ntk_t *p)
Definition: sfmInt.h:125
int nNodesTried
Definition: sfmInt.h:110
int nTotalEdgesBeg
Definition: sfmInt.h:107
Vec_Int_t * vCover
Definition: sfmInt.h:75
int nTryResubs
Definition: sfmInt.h:91
int Sfm_ObjMffcSize(Sfm_Ntk_t *p, int iObj)
Definition: sfmWin.c:89