abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mvcCover.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mvcCover.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [Basic procedures to manipulate unate cube covers.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: mvcCover.c,v 1.5 2003/04/09 18:02:05 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mvc.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis []
35 
36  Description []
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
44 {
45  Mvc_Cover_t * p;
46  int nBitsInUnsigned;
47 
48  nBitsInUnsigned = 8 * sizeof(Mvc_CubeWord_t);
49 #ifdef USE_SYSTEM_MEMORY_MANAGEMENT
50  p = (Mvc_Cover_t *)ABC_ALLOC( char, sizeof(Mvc_Cover_t) );
51 #else
53 #endif
54  p->pMem = pMem;
55  p->nBits = nBits;
56  p->nWords = nBits / nBitsInUnsigned + (int)(nBits % nBitsInUnsigned > 0);
57  p->nUnused = p->nWords * nBitsInUnsigned - p->nBits;
58  p->lCubes.nItems = 0;
59  p->lCubes.pHead = NULL;
60  p->lCubes.pTail = NULL;
61  p->nCubesAlloc = 0;
62  p->pCubes = NULL;
63  p->pMask = NULL;
64  p->pLits = NULL;
65  return p;
66 }
67 
68 /**Function*************************************************************
69 
70  Synopsis []
71 
72  Description []
73 
74  SideEffects []
75 
76  SeeAlso []
77 
78 ***********************************************************************/
80 {
81  Mvc_Cover_t * pCover;
82 #ifdef USE_SYSTEM_MEMORY_MANAGEMENT
83  pCover = (Mvc_Cover_t *)ABC_ALLOC( char, sizeof(Mvc_Cover_t) );
84 #else
85  pCover = (Mvc_Cover_t *)Extra_MmFixedEntryFetch( p->pMem->pManC );
86 #endif
87  pCover->pMem = p->pMem;
88  pCover->nBits = p->nBits;
89  pCover->nWords = p->nWords;
90  pCover->nUnused = p->nUnused;
91  pCover->lCubes.nItems = 0;
92  pCover->lCubes.pHead = NULL;
93  pCover->lCubes.pTail = NULL;
94  pCover->nCubesAlloc = 0;
95  pCover->pCubes = NULL;
96  pCover->pMask = NULL;
97  pCover->pLits = NULL;
98  return pCover;
99 }
100 
101 /**Function*************************************************************
102 
103  Synopsis []
104 
105  Description []
106 
107  SideEffects []
108 
109  SeeAlso []
110 
111 ***********************************************************************/
113 {
114  Mvc_Cover_t * pCover;
115  Mvc_Cube_t * pCube, * pCubeCopy;
116  // clone the cover
117  pCover = Mvc_CoverClone( p );
118  // copy the cube list
119  Mvc_CoverForEachCube( p, pCube )
120  {
121  pCubeCopy = Mvc_CubeDup( p, pCube );
122  Mvc_CoverAddCubeTail( pCover, pCubeCopy );
123  }
124  return pCover;
125 }
126 
127 /**Function*************************************************************
128 
129  Synopsis []
130 
131  Description []
132 
133  SideEffects []
134 
135  SeeAlso []
136 
137 ***********************************************************************/
139 {
140  Mvc_Cube_t * pCube, * pCube2;
141  // recycle cube list
142  Mvc_CoverForEachCubeSafe( p, pCube, pCube2 )
143  Mvc_CubeFree( p, pCube );
144  // recycle other pointers
145  Mvc_CubeFree( p, p->pMask );
146  MEM_FREE( p->pMem, Mvc_Cube_t *, p->nCubesAlloc, p->pCubes );
147  MEM_FREE( p->pMem, int, p->nBits, p->pLits );
148 
149 #ifdef USE_SYSTEM_MEMORY_MANAGEMENT
150  ABC_FREE( p );
151 #else
152  Extra_MmFixedEntryRecycle( p->pMem->pManC, (char *)p );
153 #endif
154 }
155 
156 
157 /**Function*************************************************************
158 
159  Synopsis []
160 
161  Description []
162 
163  SideEffects []
164 
165  SeeAlso []
166 
167 ***********************************************************************/
169 {
170  if ( pCover->pMask == NULL )
171  pCover->pMask = Mvc_CubeAlloc( pCover );
172 }
173 
174 /**Function*************************************************************
175 
176  Synopsis []
177 
178  Description []
179 
180  SideEffects []
181 
182  SeeAlso []
183 
184 ***********************************************************************/
186 {
187  if ( pCover->pLits == NULL )
188  pCover->pLits = MEM_ALLOC( pCover->pMem, int, pCover->nBits );
189 }
190 
191 /**Function*************************************************************
192 
193  Synopsis []
194 
195  Description []
196 
197  SideEffects []
198 
199  SeeAlso []
200 
201 ***********************************************************************/
203 {
204  if ( pCover->nCubesAlloc < pCover->lCubes.nItems )
205  {
206  if ( pCover->nCubesAlloc > 0 )
207  MEM_FREE( pCover->pMem, Mvc_Cube_t *, pCover->nCubesAlloc, pCover->pCubes );
208  pCover->nCubesAlloc = pCover->lCubes.nItems;
209  pCover->pCubes = MEM_ALLOC( pCover->pMem, Mvc_Cube_t *, pCover->nCubesAlloc );
210  }
211 }
212 
213 /**Function*************************************************************
214 
215  Synopsis []
216 
217  Description []
218 
219  SideEffects []
220 
221  SeeAlso []
222 
223 ***********************************************************************/
225 {
226  Mvc_CubeFree( pCover, pCover->pMask );
227  pCover->pMask = NULL;
228 }
229 
230 /**Function*************************************************************
231 
232  Synopsis []
233 
234  Description []
235 
236  SideEffects []
237 
238  SeeAlso []
239 
240 ***********************************************************************/
242 {
243  if ( pCover->pLits )
244  {
245  MEM_FREE( pCover->pMem, int, pCover->nBits, pCover->pLits );
246  pCover->pLits = NULL;
247  }
248 }
249 
250 ////////////////////////////////////////////////////////////////////////
251 /// END OF FILE ///
252 ////////////////////////////////////////////////////////////////////////
253 
254 
256 
#define Mvc_CoverAddCubeTail(pCover, pCube)
Definition: mvc.h:501
Mvc_Cube_t ** pCubes
Definition: mvc.h:89
Mvc_Cube_t * Mvc_CubeDup(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcCube.c:94
int nWords
Definition: mvc.h:85
unsigned int Mvc_CubeWord_t
STRUCTURE DEFINITIONS ///.
Definition: mvc.h:55
ABC_NAMESPACE_IMPL_START Mvc_Cover_t * Mvc_CoverAlloc(Mvc_Manager_t *pMem, int nBits)
DECLARATIONS ///.
Definition: mvcCover.c:43
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Mvc_Cover_t * Mvc_CoverClone(Mvc_Cover_t *p)
Definition: mvcCover.c:79
void Mvc_CoverDeallocateMask(Mvc_Cover_t *pCover)
Definition: mvcCover.c:224
int nItems
Definition: mvc.h:79
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
int * pLits
Definition: mvc.h:91
void Mvc_CoverAllocateArrayCubes(Mvc_Cover_t *pCover)
Definition: mvcCover.c:202
#define MEM_FREE(Manager, Type, Size, Pointer)
Definition: mvc.h:568
Mvc_Cube_t * Mvc_CubeAlloc(Mvc_Cover_t *pCover)
DECLARATIONS ///.
Definition: mvcCube.c:43
int nUnused
Definition: mvc.h:86
Mvc_Cube_t * pMask
Definition: mvc.h:92
Mvc_List_t lCubes
Definition: mvc.h:88
#define Mvc_CoverForEachCubeSafe(Cover, Cube, Cube2)
Definition: mvc.h:536
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Mvc_Cover_t * Mvc_CoverDup(Mvc_Cover_t *p)
Definition: mvcCover.c:112
void Mvc_CoverAllocateArrayLits(Mvc_Cover_t *pCover)
Definition: mvcCover.c:185
Mvc_Cube_t * pTail
Definition: mvc.h:78
#define Mvc_CoverForEachCube(Cover, Cube)
Definition: mvc.h:528
#define MEM_ALLOC(Manager, Type, Size)
Definition: mvc.h:567
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Mvc_Cube_t * pHead
Definition: mvc.h:77
void Mvc_CoverFree(Mvc_Cover_t *p)
Definition: mvcCover.c:138
void Mvc_CoverDeallocateArrayLits(Mvc_Cover_t *pCover)
Definition: mvcCover.c:241
#define ABC_FREE(obj)
Definition: abc_global.h:232
int nCubesAlloc
Definition: mvc.h:90
int nBits
Definition: mvc.h:87
void Mvc_CoverAllocateMask(Mvc_Cover_t *pCover)
Definition: mvcCover.c:168
void Extra_MmFixedEntryRecycle(Extra_MmFixed_t *p, char *pEntry)
Extra_MmFixed_t * pManC
Definition: mvc.h:110
void Mvc_CubeFree(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcCube.c:114
Mvc_Manager_t * pMem
Definition: mvc.h:93