abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fxuSingle.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fxuSingle.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [Procedures to compute the set of single-cube divisors.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: fxuSingle.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fxuInt.h"
20 #include "misc/vec/vec.h"
21 
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 static void Fxu_MatrixComputeSinglesOneCollect( Fxu_Matrix * p, Fxu_Var * pVar, Vec_Ptr_t * vSingles );
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// FUNCTION DEFINITIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37  Synopsis [Computes and adds all single-cube divisors to storage.]
38 
39  Description [This procedure should be called once when the matrix is
40  already contructed before the process of logic extraction begins..]
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 void 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 );
56  Fxu_MatrixForEachVariable( p, pVar )
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 
113 /**Function*************************************************************
114 
115  Synopsis [Adds the single-cube divisors associated with a new column.]
116 
117  Description []
118 
119  SideEffects []
120 
121  SeeAlso []
122 
123 ***********************************************************************/
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
153  Fxu_MatrixForEachVarInRing( p, pVar2 )
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 
173 /**Function*************************************************************
174 
175  Synopsis [Adds the single-cube divisors associated with a new column.]
176 
177  Description []
178 
179  SideEffects []
180 
181  SeeAlso []
182 
183 ***********************************************************************/
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
213  Fxu_MatrixForEachVarInRing( p, pVar2 )
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 
230 /**Function*************************************************************
231 
232  Synopsis [Computes the coincidence count of two columns.]
233 
234  Description []
235 
236  SideEffects []
237 
238  SeeAlso []
239 
240 ***********************************************************************/
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 
283 ////////////////////////////////////////////////////////////////////////
284 /// END OF FILE ///
285 ////////////////////////////////////////////////////////////////////////
286 
287 
289 
char * memset()
Definition: fxuInt.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Fxu_ListLit lLits
Definition: fxuInt.h:219
void Fxu_MatrixComputeSingles(Fxu_Matrix *p, int fUse0, int nSingleMax)
FUNCTION DEFINITIONS ///.
Definition: fxuSingle.c:47
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int iVar
Definition: fxuInt.h:215
Fxu_Lit * pHead
Definition: fxuInt.h:109
#define Fxu_MatrixForEachVarInRing(Matrix, Var)
Definition: fxuInt.h:407
int iCube
Definition: fxuInt.h:229
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Fxu_SingleCountCoincidence(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2)
Definition: fxuSingle.c:241
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Fxu_Lit * pVNext
Definition: fxuInt.h:235
void Fxu_MatrixComputeSinglesOne(Fxu_Matrix *p, Fxu_Var *pVar)
Definition: fxuSingle.c:184
#define Fxu_MatrixForEachVariable(Matrix, Var)
Definition: fxuInt.h:303
#define Fxu_MatrixRingVarsStart(Matrix)
Definition: fxuInt.h:386
Fxu_Var * pVar
Definition: fxuInt.h:205
static ABC_NAMESPACE_IMPL_START void Fxu_MatrixComputeSinglesOneCollect(Fxu_Matrix *p, Fxu_Var *pVar, Vec_Ptr_t *vSingles)
DECLARATIONS ///.
Definition: fxuSingle.c:124
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Fxu_Cube * pCube
Definition: fxuInt.h:230
void Fxu_MatrixRingVarsUnmark(Fxu_Matrix *p)
Definition: fxu.c:206
#define Fxu_MatrixRingVarsAdd(Matrix, Var)
Definition: fxuInt.h:395
void Fxu_MatrixAddSingle(Fxu_Matrix *p, Fxu_Var *pVar1, Fxu_Var *pVar2, int Weight)
Definition: fxuMatrix.c:274
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
Fxu_Var * pVar
Definition: fxuInt.h:231
Fxu_Var * pOrder
Definition: fxuInt.h:222
#define Fxu_MatrixRingVarsStop(Matrix)
Definition: fxuInt.h:389
#define assert(ex)
Definition: util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition: fxuInt.h:63
Definition: fxuInt.h:226
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
Fxu_Lit * pHPrev
Definition: fxuInt.h:232
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223