abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fxu.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fxu.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [The entrance into the fast extract module.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: fxu.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fxuInt.h"
20 #include "fxu.h"
21 
23 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 /*===== fxuCreate.c ====================================================*/
30 extern Fxu_Matrix * Fxu_CreateMatrix( Fxu_Data_t * pData );
31 extern void Fxu_CreateCovers( Fxu_Matrix * p, Fxu_Data_t * pData );
32 
33 static int s_MemoryTotal;
34 static int s_MemoryPeak;
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Performs fast_extract on a set of covers.]
43 
44  Description [All the covers are given in the array p->vSops.
45  The resulting covers are returned in the array p->vSopsNew.
46  The entries in these arrays correspond to objects in the network.
47  The entries corresponding to the PI and objects with trivial covers are NULL.
48  The number of extracted covers (not exceeding p->nNodesExt) is returned.
49  Two other things are important for the correct operation of this procedure:
50  (1) The input covers do not have duplicated fanins and are SCC-free.
51  (2) The fanins array contains the numbers of the fanin objects.]
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
59 {
60  int fScrollLines = 0;
61  Fxu_Matrix * p;
62  Fxu_Single * pSingle;
63  Fxu_Double * pDouble;
64  int Weight1, Weight2, Weight3;
65  int Counter = 0;
66 
67  s_MemoryTotal = 0;
68  s_MemoryPeak = 0;
69 
70  // create the matrix
71  p = Fxu_CreateMatrix( pData );
72  if ( p == NULL )
73  return -1;
74 // if ( pData->fVerbose )
75 // printf( "Memory usage after construction: Total = %d. Peak = %d.\n", s_MemoryTotal, s_MemoryPeak );
76 //Fxu_MatrixPrint( NULL, p );
77 
78  if ( pData->fOnlyS )
79  {
80  pData->nNodesNew = 0;
81  do
82  {
83  Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
84  if ( pData->fVerbose )
85  printf( "Div %5d : Best single = %5d.%s", Counter++, Weight1, fScrollLines?"\n":"\r" );
86  if ( Weight1 > pData->WeightMin || (Weight1 == 0 && pData->fUse0) )
87  Fxu_UpdateSingle( p );
88  else
89  break;
90  }
91  while ( ++pData->nNodesNew < pData->nNodesExt );
92  }
93  else if ( pData->fOnlyD )
94  {
95  pData->nNodesNew = 0;
96  do
97  {
98  Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
99  if ( pData->fVerbose )
100  printf( "Div %5d : Best double = %5d.%s", Counter++, Weight2, fScrollLines?"\n":"\r" );
101  if ( Weight2 > pData->WeightMin || (Weight2 == 0 && pData->fUse0) )
102  Fxu_UpdateDouble( p );
103  else
104  break;
105  }
106  while ( ++pData->nNodesNew < pData->nNodesExt );
107  }
108  else if ( !pData->fUseCompl )
109  {
110  pData->nNodesNew = 0;
111  do
112  {
113  Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
114  Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
115 
116  if ( pData->fVerbose )
117  printf( "Div %5d : Best double = %5d. Best single = %5d.%s", Counter++, Weight2, Weight1, fScrollLines?"\n":"\r" );
118 //Fxu_Select( p, &pSingle, &pDouble );
119 
120  if ( Weight1 >= Weight2 )
121  {
122  if ( Weight1 > pData->WeightMin || (Weight1 == 0 && pData->fUse0) )
123  Fxu_UpdateSingle( p );
124  else
125  break;
126  }
127  else
128  {
129  if ( Weight2 > pData->WeightMin || (Weight2 == 0 && pData->fUse0) )
130  Fxu_UpdateDouble( p );
131  else
132  break;
133  }
134  }
135  while ( ++pData->nNodesNew < pData->nNodesExt );
136  }
137  else
138  { // use the complement
139  pData->nNodesNew = 0;
140  do
141  {
142  Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
143  Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
144 
145  // select the best single and double
146  Weight3 = Fxu_Select( p, &pSingle, &pDouble );
147  if ( pData->fVerbose )
148  printf( "Div %5d : Best double = %5d. Best single = %5d. Best complement = %5d.%s",
149  Counter++, Weight2, Weight1, Weight3, fScrollLines?"\n":"\r" );
150 
151  if ( Weight3 > pData->WeightMin || (Weight3 == 0 && pData->fUse0) )
152  Fxu_Update( p, pSingle, pDouble );
153  else
154  break;
155  }
156  while ( ++pData->nNodesNew < pData->nNodesExt );
157  }
158 
159  if ( pData->fVerbose )
160  printf( "Total single = %3d. Total double = %3d. Total compl = %3d. \n",
161  p->nDivs1, p->nDivs2, p->nDivs3 );
162 
163  // create the new covers
164  if ( pData->nNodesNew )
165  Fxu_CreateCovers( p, pData );
166  Fxu_MatrixDelete( p );
167 // printf( "Memory usage after deallocation: Total = %d. Peak = %d.\n", s_MemoryTotal, s_MemoryPeak );
168  if ( pData->nNodesNew == pData->nNodesExt )
169  printf( "Warning: The limit on the number of extracted divisors has been reached.\n" );
170  return pData->nNodesNew;
171 }
172 
173 
174 /**Function*************************************************************
175 
176  Synopsis [Unmarks the cubes in the ring.]
177 
178  Description []
179 
180  SideEffects []
181 
182  SeeAlso []
183 
184 ***********************************************************************/
186 {
187  Fxu_Cube * pCube, * pCube2;
188  // unmark the cubes
189  Fxu_MatrixForEachCubeInRingSafe( p, pCube, pCube2 )
190  pCube->pOrder = NULL;
192 }
193 
194 
195 /**Function*************************************************************
196 
197  Synopsis [Unmarks the vars in the ring.]
198 
199  Description []
200 
201  SideEffects []
202 
203  SeeAlso []
204 
205 ***********************************************************************/
207 {
208  Fxu_Var * pVar, * pVar2;
209  // unmark the vars
210  Fxu_MatrixForEachVarInRingSafe( p, pVar, pVar2 )
211  pVar->pOrder = NULL;
213 }
214 
215 
216 /**Function*************************************************************
217 
218  Synopsis []
219 
220  Description []
221 
222  SideEffects []
223 
224  SeeAlso []
225 
226 ***********************************************************************/
227 char * Fxu_MemFetch( Fxu_Matrix * p, int nBytes )
228 {
229  s_MemoryTotal += nBytes;
230  if ( s_MemoryPeak < s_MemoryTotal )
232 // return ABC_ALLOC( char, nBytes );
233  return Extra_MmFixedEntryFetch( p->pMemMan );
234 }
235 
236 /**Function*************************************************************
237 
238  Synopsis []
239 
240  Description []
241 
242  SideEffects []
243 
244  SeeAlso []
245 
246 ***********************************************************************/
247 void Fxu_MemRecycle( Fxu_Matrix * p, char * pItem, int nBytes )
248 {
249  s_MemoryTotal -= nBytes;
250 // ABC_FREE( pItem );
251  Extra_MmFixedEntryRecycle( p->pMemMan, pItem );
252 }
253 
254 ////////////////////////////////////////////////////////////////////////
255 /// END OF FILE ///
256 ////////////////////////////////////////////////////////////////////////
257 
258 
260 
Definition: fxuInt.h:213
#define Fxu_MatrixForEachVarInRingSafe(Matrix, Var, Var2)
Definition: fxuInt.h:412
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Fxu_MatrixRingVarsReset(Matrix)
Definition: fxuInt.h:392
void Fxu_Update(Fxu_Matrix *p, Fxu_Single *pSingle, Fxu_Double *pDouble)
FUNCTION DEFINITIONS ///.
Definition: fxuUpdate.c:57
static int s_MemoryPeak
Definition: fxu.c:34
typedefABC_NAMESPACE_HEADER_START struct FxuDataStruct Fxu_Data_t
INCLUDES ///.
Definition: fxu.h:42
void Fxu_MatrixDelete(Fxu_Matrix *p)
Definition: fxuMatrix.c:96
void Fxu_MemRecycle(Fxu_Matrix *p, char *pItem, int nBytes)
Definition: fxu.c:247
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
void Fxu_UpdateSingle(Fxu_Matrix *p)
Definition: fxuUpdate.c:149
int Fxu_HeapDoubleReadMaxWeight(Fxu_HeapDouble *p)
Definition: fxuHeapD.c:319
void Fxu_CreateCovers(Fxu_Matrix *p, Fxu_Data_t *pData)
Definition: fxuCreate.c:278
#define Fxu_MatrixForEachCubeInRingSafe(Matrix, Cube, Cube2)
Definition: fxuInt.h:402
#define Fxu_MatrixRingCubesReset(Matrix)
Definition: fxuInt.h:391
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Fxu_UpdateDouble(Fxu_Matrix *p)
Definition: fxuUpdate.c:219
void Fxu_MatrixRingVarsUnmark(Fxu_Matrix *p)
Definition: fxu.c:206
static int Counter
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
char * Fxu_MemFetch(Fxu_Matrix *p, int nBytes)
FUNCTION DEFINITIONS ///.
Definition: fxu.c:227
int Fxu_HeapSingleReadMaxWeight(Fxu_HeapSingle *p)
Definition: fxuHeapS.c:321
int Fxu_FastExtract(Fxu_Data_t *pData)
FUNCTION DEFINITIONS ///.
Definition: fxu.c:58
Fxu_Var * pOrder
Definition: fxuInt.h:222
Fxu_Cube * pOrder
Definition: fxuInt.h:209
void Extra_MmFixedEntryRecycle(Extra_MmFixed_t *p, char *pEntry)
typedefABC_NAMESPACE_HEADER_START struct FxuMatrix Fxu_Matrix
INCLUDES ///.
Definition: fxuInt.h:63
ABC_NAMESPACE_IMPL_START Fxu_Matrix * Fxu_CreateMatrix(Fxu_Data_t *pData)
DECLARATIONS ///.
Definition: fxuCreate.c:52
static int s_MemoryTotal
Definition: fxu.c:33
int Fxu_Select(Fxu_Matrix *p, Fxu_Single **ppSingle, Fxu_Double **ppDouble)
FUNCTION DEFINITIONS ///.
Definition: fxuSelect.c:57
void Fxu_MatrixRingCubesUnmark(Fxu_Matrix *p)
Definition: fxu.c:185