ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
msatMem.c File Reference
#include "msatInt.h"
Include dependency graph for msatMem.c:

Go to the source code of this file.

Classes

struct  Msat_MmFixed_t_
 DECLARATIONS ///. More...
 
struct  Msat_MmFlex_t_
 
struct  Msat_MmStep_t_
 

Functions

Msat_MmFixed_tMsat_MmFixedStart (int nEntrySize)
 FUNCTION DEFINITIONS ///.
 
void Msat_MmFixedStop (Msat_MmFixed_t *p, int fVerbose)
 
char * Msat_MmFixedEntryFetch (Msat_MmFixed_t *p)
 
void Msat_MmFixedEntryRecycle (Msat_MmFixed_t *p, char *pEntry)
 
void Msat_MmFixedRestart (Msat_MmFixed_t *p)
 
int Msat_MmFixedReadMemUsage (Msat_MmFixed_t *p)
 
Msat_MmFlex_tMsat_MmFlexStart ()
 
void Msat_MmFlexStop (Msat_MmFlex_t *p, int fVerbose)
 
char * Msat_MmFlexEntryFetch (Msat_MmFlex_t *p, int nBytes)
 
int Msat_MmFlexReadMemUsage (Msat_MmFlex_t *p)
 
Msat_MmStep_tMsat_MmStepStart (int nSteps)
 
void Msat_MmStepStop (Msat_MmStep_t *p, int fVerbose)
 
char * Msat_MmStepEntryFetch (Msat_MmStep_t *p, int nBytes)
 
void Msat_MmStepEntryRecycle (Msat_MmStep_t *p, char *pEntry, int nBytes)
 
int Msat_MmStepReadMemUsage (Msat_MmStep_t *p)
 

Function Documentation

◆ Msat_MmFixedEntryFetch()

char * Msat_MmFixedEntryFetch ( Msat_MmFixed_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 161 of file msatMem.c.

162{
163 char * pTemp;
164 int i;
165
166 // check if there are still free entries
167 if ( p->nEntriesUsed == p->nEntriesAlloc )
168 { // need to allocate more entries
169 assert( p->pEntriesFree == NULL );
170 if ( p->nChunks == p->nChunksAlloc )
171 {
172 p->nChunksAlloc *= 2;
173 p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
174 }
175 p->pEntriesFree = ABC_ALLOC( char, p->nEntrySize * p->nChunkSize );
176 p->nMemoryAlloc += p->nEntrySize * p->nChunkSize;
177 // transform these entries into a linked list
178 pTemp = p->pEntriesFree;
179 for ( i = 1; i < p->nChunkSize; i++ )
180 {
181 *((char **)pTemp) = pTemp + p->nEntrySize;
182 pTemp += p->nEntrySize;
183 }
184 // set the last link
185 *((char **)pTemp) = NULL;
186 // add the chunk to the chunk storage
187 p->pChunks[ p->nChunks++ ] = p->pEntriesFree;
188 // add to the number of entries allocated
189 p->nEntriesAlloc += p->nChunkSize;
190 }
191 // incrememt the counter of used entries
192 p->nEntriesUsed++;
193 if ( p->nEntriesMax < p->nEntriesUsed )
194 p->nEntriesMax = p->nEntriesUsed;
195 // return the first entry in the free entry list
196 pTemp = p->pEntriesFree;
197 p->pEntriesFree = *((char **)pTemp);
198 return pTemp;
199}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
Cube * p
Definition exorList.c:222
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Msat_MmFixedEntryRecycle()

void Msat_MmFixedEntryRecycle ( Msat_MmFixed_t * p,
char * pEntry )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 212 of file msatMem.c.

213{
214 // decrement the counter of used entries
215 p->nEntriesUsed--;
216 // add the entry to the linked list of free entries
217 *((char **)pEntry) = p->pEntriesFree;
218 p->pEntriesFree = pEntry;
219}
Here is the caller graph for this function:

◆ Msat_MmFixedReadMemUsage()

int Msat_MmFixedReadMemUsage ( Msat_MmFixed_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 270 of file msatMem.c.

271{
272 return p->nMemoryAlloc;
273}

◆ Msat_MmFixedRestart()

void Msat_MmFixedRestart ( Msat_MmFixed_t * p)

Function*************************************************************

Synopsis []

Description [Relocates all the memory except the first chunk.]

SideEffects []

SeeAlso []

Definition at line 232 of file msatMem.c.

233{
234 int i;
235 char * pTemp;
236
237 // deallocate all chunks except the first one
238 for ( i = 1; i < p->nChunks; i++ )
239 ABC_FREE( p->pChunks[i] );
240 p->nChunks = 1;
241 // transform these entries into a linked list
242 pTemp = p->pChunks[0];
243 for ( i = 1; i < p->nChunkSize; i++ )
244 {
245 *((char **)pTemp) = pTemp + p->nEntrySize;
246 pTemp += p->nEntrySize;
247 }
248 // set the last link
249 *((char **)pTemp) = NULL;
250 // set the free entry list
251 p->pEntriesFree = p->pChunks[0];
252 // set the correct statistics
253 p->nMemoryAlloc = p->nEntrySize * p->nChunkSize;
254 p->nMemoryUsed = 0;
255 p->nEntriesAlloc = p->nChunkSize;
256 p->nEntriesUsed = 0;
257}
#define ABC_FREE(obj)
Definition abc_global.h:267

◆ Msat_MmFixedStart()

Msat_MmFixed_t * Msat_MmFixedStart ( int nEntrySize)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Allocates memory pieces of fixed size.]

Description [The size of the chunk is computed as the minimum of 1024 entries and 64K. Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 93 of file msatMem.c.

94{
96
98 memset( p, 0, sizeof(Msat_MmFixed_t) );
99
100 p->nEntrySize = nEntrySize;
101 p->nEntriesAlloc = 0;
102 p->nEntriesUsed = 0;
103 p->pEntriesFree = NULL;
104
105 if ( nEntrySize * (1 << 10) < (1<<16) )
106 p->nChunkSize = (1 << 10);
107 else
108 p->nChunkSize = (1<<16) / nEntrySize;
109 if ( p->nChunkSize < 8 )
110 p->nChunkSize = 8;
111
112 p->nChunksAlloc = 64;
113 p->nChunks = 0;
114 p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
115
116 p->nMemoryUsed = 0;
117 p->nMemoryAlloc = 0;
118 return p;
119}
struct Msat_MmFixed_t_ Msat_MmFixed_t
Definition msatInt.h:61
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_MmFixedStop()

void Msat_MmFixedStop ( Msat_MmFixed_t * p,
int fVerbose )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 132 of file msatMem.c.

133{
134 int i;
135 if ( p == NULL )
136 return;
137 if ( fVerbose )
138 {
139 printf( "Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n",
140 p->nEntrySize, p->nChunkSize, p->nChunks );
141 printf( " Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n",
142 p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc );
143 }
144 for ( i = 0; i < p->nChunks; i++ )
145 ABC_FREE( p->pChunks[i] );
146 ABC_FREE( p->pChunks );
147 ABC_FREE( p );
148}
Here is the caller graph for this function:

◆ Msat_MmFlexEntryFetch()

char * Msat_MmFlexEntryFetch ( Msat_MmFlex_t * p,
int nBytes )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 349 of file msatMem.c.

350{
351 char * pTemp;
352 // check if there are still free entries
353 if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd )
354 { // need to allocate more entries
355 if ( p->nChunks == p->nChunksAlloc )
356 {
357 p->nChunksAlloc *= 2;
358 p->pChunks = ABC_REALLOC( char *, p->pChunks, p->nChunksAlloc );
359 }
360 if ( nBytes > p->nChunkSize )
361 {
362 // resize the chunk size if more memory is requested than it can give
363 // (ideally, this should never happen)
364 p->nChunkSize = 2 * nBytes;
365 }
366 p->pCurrent = ABC_ALLOC( char, p->nChunkSize );
367 p->pEnd = p->pCurrent + p->nChunkSize;
368 p->nMemoryAlloc += p->nChunkSize;
369 // add the chunk to the chunk storage
370 p->pChunks[ p->nChunks++ ] = p->pCurrent;
371 }
372 assert( p->pCurrent + nBytes <= p->pEnd );
373 // increment the counter of used entries
374 p->nEntriesUsed++;
375 // keep track of the memory used
376 p->nMemoryUsed += nBytes;
377 // return the next entry
378 pTemp = p->pCurrent;
379 p->pCurrent += nBytes;
380 return pTemp;
381}

◆ Msat_MmFlexReadMemUsage()

int Msat_MmFlexReadMemUsage ( Msat_MmFlex_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 394 of file msatMem.c.

395{
396 return p->nMemoryAlloc;
397}

◆ Msat_MmFlexStart()

Msat_MmFlex_t * Msat_MmFlexStart ( )

Function*************************************************************

Synopsis [Allocates entries of flexible size.]

Description [Can only work with entry size at least 4 byte long.]

SideEffects []

SeeAlso []

Definition at line 288 of file msatMem.c.

289{
291
292 p = ABC_ALLOC( Msat_MmFlex_t, 1 );
293 memset( p, 0, sizeof(Msat_MmFlex_t) );
294
295 p->nEntriesUsed = 0;
296 p->pCurrent = NULL;
297 p->pEnd = NULL;
298
299 p->nChunkSize = (1 << 12);
300 p->nChunksAlloc = 64;
301 p->nChunks = 0;
302 p->pChunks = ABC_ALLOC( char *, p->nChunksAlloc );
303
304 p->nMemoryUsed = 0;
305 p->nMemoryAlloc = 0;
306 return p;
307}
struct Msat_MmFlex_t_ Msat_MmFlex_t
Definition msatInt.h:62
Here is the call graph for this function:

◆ Msat_MmFlexStop()

void Msat_MmFlexStop ( Msat_MmFlex_t * p,
int fVerbose )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file msatMem.c.

321{
322 int i;
323 if ( p == NULL )
324 return;
325 if ( fVerbose )
326 {
327 printf( "Flexible memory manager: Chunk size = %d. Chunks used = %d.\n",
328 p->nChunkSize, p->nChunks );
329 printf( " Entries used = %d. Memory used = %d. Memory alloc = %d.\n",
330 p->nEntriesUsed, p->nMemoryUsed, p->nMemoryAlloc );
331 }
332 for ( i = 0; i < p->nChunks; i++ )
333 ABC_FREE( p->pChunks[i] );
334 ABC_FREE( p->pChunks );
335 ABC_FREE( p );
336}

◆ Msat_MmStepEntryFetch()

char * Msat_MmStepEntryFetch ( Msat_MmStep_t * p,
int nBytes )

Function*************************************************************

Synopsis [Creates the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 479 of file msatMem.c.

480{
481 if ( nBytes == 0 )
482 return NULL;
483 if ( nBytes > p->nMapSize )
484 {
485// printf( "Allocating %d bytes.\n", nBytes );
486 return ABC_ALLOC( char, nBytes );
487 }
488 return Msat_MmFixedEntryFetch( p->pMap[nBytes] );
489}
char * Msat_MmFixedEntryFetch(Msat_MmFixed_t *p)
Definition msatMem.c:161
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_MmStepEntryRecycle()

void Msat_MmStepEntryRecycle ( Msat_MmStep_t * p,
char * pEntry,
int nBytes )

Function*************************************************************

Synopsis [Recycles the entry.]

Description []

SideEffects []

SeeAlso []

Definition at line 503 of file msatMem.c.

504{
505 if ( nBytes == 0 )
506 return;
507 if ( nBytes > p->nMapSize )
508 {
509 ABC_FREE( pEntry );
510 return;
511 }
512 Msat_MmFixedEntryRecycle( p->pMap[nBytes], pEntry );
513}
void Msat_MmFixedEntryRecycle(Msat_MmFixed_t *p, char *pEntry)
Definition msatMem.c:212
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_MmStepReadMemUsage()

int Msat_MmStepReadMemUsage ( Msat_MmStep_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 526 of file msatMem.c.

527{
528 int i, nMemTotal = 0;
529 for ( i = 0; i < p->nMems; i++ )
530 nMemTotal += p->pMems[i]->nMemoryAlloc;
531 return nMemTotal;
532}

◆ Msat_MmStepStart()

Msat_MmStep_t * Msat_MmStepStart ( int nSteps)

Function*************************************************************

Synopsis [Starts the hierarchical memory manager.]

Description [This manager can allocate entries of any size. Iternally they are mapped into the entries with the number of bytes equal to the power of 2. The smallest entry size is 8 bytes. The next one is 16 bytes etc. So, if the user requests 6 bytes, he gets 8 byte entry. If we asks for 25 bytes, he gets 32 byte entry etc. The input parameters "nSteps" says how many fixed memory managers are employed internally. Calling this procedure with nSteps equal to 10 results in 10 hierarchically arranged internal memory managers, which can allocate up to 4096 (1Kb) entries. Requests for larger entries are handed over to malloc() and then ABC_FREE()ed.]

SideEffects []

SeeAlso []

Definition at line 423 of file msatMem.c.

424{
426 int i, k;
427 p = ABC_ALLOC( Msat_MmStep_t, 1 );
428 p->nMems = nSteps;
429 // start the fixed memory managers
430 p->pMems = ABC_ALLOC( Msat_MmFixed_t *, p->nMems );
431 for ( i = 0; i < p->nMems; i++ )
432 p->pMems[i] = Msat_MmFixedStart( (8<<i) );
433 // set up the mapping of the required memory size into the corresponding manager
434 p->nMapSize = (4<<p->nMems);
435 p->pMap = ABC_ALLOC( Msat_MmFixed_t *, p->nMapSize+1 );
436 p->pMap[0] = NULL;
437 for ( k = 1; k <= 4; k++ )
438 p->pMap[k] = p->pMems[0];
439 for ( i = 0; i < p->nMems; i++ )
440 for ( k = (4<<i)+1; k <= (8<<i); k++ )
441 p->pMap[k] = p->pMems[i];
442//for ( i = 1; i < 100; i ++ )
443//printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize );
444 return p;
445}
Msat_MmFixed_t * Msat_MmFixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Definition msatMem.c:93
struct Msat_MmStep_t_ Msat_MmStep_t
Definition msatInt.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_MmStepStop()

void Msat_MmStepStop ( Msat_MmStep_t * p,
int fVerbose )

Function*************************************************************

Synopsis [Stops the memory manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 458 of file msatMem.c.

459{
460 int i;
461 for ( i = 0; i < p->nMems; i++ )
462 Msat_MmFixedStop( p->pMems[i], fVerbose );
463 ABC_FREE( p->pMems );
464 ABC_FREE( p->pMap );
465 ABC_FREE( p );
466}
void Msat_MmFixedStop(Msat_MmFixed_t *p, int fVerbose)
Definition msatMem.c:132
Here is the call graph for this function:
Here is the caller graph for this function: