ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
fxuSingle.c
Go to the documentation of this file.
1
18
19#include "fxuInt.h"
20#include "misc/vec/vec.h"
21
23
24
28
29static void Fxu_MatrixComputeSinglesOneCollect( Fxu_Matrix * p, Fxu_Var * pVar, Vec_Ptr_t * vSingles );
30
34
47void Fxu_MatrixComputeSingles( Fxu_Matrix * p, int fUse0, int nSingleMax )
48{
49 Fxu_Var * pVar;
50 Vec_Ptr_t * vSingles;
51 int i, k;
52 // set the weight limit
53 p->nWeightLimit = 1 - fUse0;
54 // iterate through columns in the matrix and collect single-cube divisors
55 vSingles = Vec_PtrAlloc( 10000 );
57 Fxu_MatrixComputeSinglesOneCollect( p, pVar, vSingles );
58 p->nSingleTotal = Vec_PtrSize(vSingles) / 3;
59 // check if divisors should be filtered
60 if ( Vec_PtrSize(vSingles) > nSingleMax )
61 {
62 int * pWeigtCounts, nDivCount, Weight, i, c;;
63 assert( Vec_PtrSize(vSingles) % 3 == 0 );
64 // count how many divisors have the given weight
65 pWeigtCounts = ABC_ALLOC( int, 1000 );
66 memset( pWeigtCounts, 0, sizeof(int) * 1000 );
67 for ( i = 2; i < Vec_PtrSize(vSingles); i += 3 )
68 {
69 Weight = (int)(ABC_PTRUINT_T)Vec_PtrEntry(vSingles, i);
70 if ( Weight >= 999 )
71 pWeigtCounts[999]++;
72 else
73 pWeigtCounts[Weight]++;
74 }
75 // select the bound on the weight (above this bound, singles will be included)
76 nDivCount = 0;
77 for ( c = 999; c >= 0; c-- )
78 {
79 nDivCount += pWeigtCounts[c];
80 if ( nDivCount >= nSingleMax )
81 break;
82 }
83 ABC_FREE( pWeigtCounts );
84 // collect singles with the given costs
85 k = 0;
86 for ( i = 2; i < Vec_PtrSize(vSingles); i += 3 )
87 {
88 Weight = (int)(ABC_PTRUINT_T)Vec_PtrEntry(vSingles, i);
89 if ( Weight < c )
90 continue;
91 Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i-2) );
92 Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i-1) );
93 Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i) );
94 if ( k/3 == nSingleMax )
95 break;
96 }
97 Vec_PtrShrink( vSingles, k );
98 // adjust the weight limit
99 p->nWeightLimit = c;
100 }
101 // collect the selected divisors
102 assert( Vec_PtrSize(vSingles) % 3 == 0 );
103 for ( i = 0; i < Vec_PtrSize(vSingles); i += 3 )
104 {
106 (Fxu_Var *)Vec_PtrEntry(vSingles,i),
107 (Fxu_Var *)Vec_PtrEntry(vSingles,i+1),
108 (int)(ABC_PTRUINT_T)Vec_PtrEntry(vSingles,i+2) );
109 }
110 Vec_PtrFree( vSingles );
111}
112
124void Fxu_MatrixComputeSinglesOneCollect( Fxu_Matrix * p, Fxu_Var * pVar, Vec_Ptr_t * vSingles )
125{
126 Fxu_Lit * pLitV, * pLitH;
127 Fxu_Var * pVar2;
128 int Coin;
129 int WeightCur;
130
131 // start collecting the affected vars
133 // go through all the literals of this variable
134 for ( pLitV = pVar->lLits.pHead; pLitV; pLitV = pLitV->pVNext )
135 // for this literal, go through all the horizontal literals
136 for ( pLitH = pLitV->pHPrev; pLitH; pLitH = pLitH->pHPrev )
137 {
138 // get another variable
139 pVar2 = pLitH->pVar;
140 // skip the var if it is already used
141 if ( pVar2->pOrder )
142 continue;
143 // skip the var if it belongs to the same node
144// if ( pValue2Node[pVar->iVar] == pValue2Node[pVar2->iVar] )
145// continue;
146 // collect the var
147 Fxu_MatrixRingVarsAdd( p, pVar2 );
148 }
149 // stop collecting the selected vars
151
152 // iterate through the selected vars
154 {
155 // count the coincidence
156 Coin = Fxu_SingleCountCoincidence( p, pVar2, pVar );
157 assert( Coin > 0 );
158 // get the new weight
159 WeightCur = Coin - 2;
160 // peformance fix (August 24, 2007)
161 if ( WeightCur >= p->nWeightLimit )
162 {
163 Vec_PtrPush( vSingles, pVar2 );
164 Vec_PtrPush( vSingles, pVar );
165 Vec_PtrPush( vSingles, (void *)(ABC_PTRUINT_T)WeightCur );
166 }
167 }
168
169 // unmark the vars
171}
172
185{
186 Fxu_Lit * pLitV, * pLitH;
187 Fxu_Var * pVar2;
188 int Coin;
189 int WeightCur;
190
191 // start collecting the affected vars
193 // go through all the literals of this variable
194 for ( pLitV = pVar->lLits.pHead; pLitV; pLitV = pLitV->pVNext )
195 // for this literal, go through all the horizontal literals
196 for ( pLitH = pLitV->pHPrev; pLitH; pLitH = pLitH->pHPrev )
197 {
198 // get another variable
199 pVar2 = pLitH->pVar;
200 // skip the var if it is already used
201 if ( pVar2->pOrder )
202 continue;
203 // skip the var if it belongs to the same node
204// if ( pValue2Node[pVar->iVar] == pValue2Node[pVar2->iVar] )
205// continue;
206 // collect the var
207 Fxu_MatrixRingVarsAdd( p, pVar2 );
208 }
209 // stop collecting the selected vars
211
212 // iterate through the selected vars
214 {
215 // count the coincidence
216 Coin = Fxu_SingleCountCoincidence( p, pVar2, pVar );
217 assert( Coin > 0 );
218 // get the new weight
219 WeightCur = Coin - 2;
220 // peformance fix (August 24, 2007)
221// if ( WeightCur >= 0 )
222// Fxu_MatrixAddSingle( p, pVar2, pVar, WeightCur );
223 if ( WeightCur >= p->nWeightLimit )
224 Fxu_MatrixAddSingle( p, pVar2, pVar, WeightCur );
225 }
226 // unmark the vars
228}
229
242{
243 Fxu_Lit * pLit1, * pLit2;
244 int Result;
245
246 // compute the coincidence count
247 Result = 0;
248 pLit1 = pVar1->lLits.pHead;
249 pLit2 = pVar2->lLits.pHead;
250 while ( 1 )
251 {
252 if ( pLit1 && pLit2 )
253 {
254 if ( pLit1->pCube->pVar->iVar == pLit2->pCube->pVar->iVar )
255 { // the variables are the same
256 if ( pLit1->iCube == pLit2->iCube )
257 { // the literals are the same
258 pLit1 = pLit1->pVNext;
259 pLit2 = pLit2->pVNext;
260 // add this literal to the coincidence
261 Result++;
262 }
263 else if ( pLit1->iCube < pLit2->iCube )
264 pLit1 = pLit1->pVNext;
265 else
266 pLit2 = pLit2->pVNext;
267 }
268 else if ( pLit1->pCube->pVar->iVar < pLit2->pCube->pVar->iVar )
269 pLit1 = pLit1->pVNext;
270 else
271 pLit2 = pLit2->pVNext;
272 }
273 else if ( pLit1 && !pLit2 )
274 pLit1 = pLit1->pVNext;
275 else if ( !pLit1 && pLit2 )
276 pLit2 = pLit2->pVNext;
277 else
278 break;
279 }
280 return Result;
281}
282
286
287
289
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
#define Fxu_MatrixForEachVarInRing(Matrix, Var)
Definition fxuInt.h:407
struct FxuVar Fxu_Var
Definition fxuInt.h:67
#define Fxu_MatrixRingVarsStart( Matrix)
Definition fxuInt.h:386
#define Fxu_MatrixRingVarsAdd( Matrix, Var)
Definition fxuInt.h:395
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition fxuInt.h:63
#define Fxu_MatrixRingVarsStop( Matrix)
Definition fxuInt.h:389
#define Fxu_MatrixForEachVariable(Matrix, Var)
Definition fxuInt.h:303
struct FxuLit Fxu_Lit
Definition fxuInt.h:68
void Fxu_MatrixAddSingle(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2, int Weight)
Definition fxuMatrix.c:274
int Fxu_SingleCountCoincidence(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2)
Definition fxuSingle.c:241
void Fxu_MatrixComputeSingles(Fxu_Matrix *p, int fUse0, int nSingleMax)
FUNCTION DEFINITIONS ///.
Definition fxuSingle.c:47
void Fxu_MatrixComputeSinglesOne(Fxu_Matrix *p, Fxu_Var *pVar)
Definition fxuSingle.c:184
void Fxu_MatrixRingVarsUnmark(Fxu_Matrix *p)
Definition fxu.c:206
Fxu_Var * pVar
Definition fxuInt.h:205
Fxu_Lit * pHead
Definition fxuInt.h:109
Fxu_Lit * pVNext
Definition fxuInt.h:235
Fxu_Cube * pCube
Definition fxuInt.h:230
Fxu_Lit * pHPrev
Definition fxuInt.h:232
Fxu_Var * pVar
Definition fxuInt.h:231
int iCube
Definition fxuInt.h:229
Fxu_Var * pOrder
Definition fxuInt.h:222
int iVar
Definition fxuInt.h:215
Fxu_ListLit lLits
Definition fxuInt.h:219
#define assert(ex)
Definition util_old.h:213
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42