diff options
Diffstat (limited to 'src/temp/esop')
-rw-r--r-- | src/temp/esop/esop.h | 49 | ||||
-rw-r--r-- | src/temp/esop/esopMan.c | 16 | ||||
-rw-r--r-- | src/temp/esop/esopMem.c | 274 | ||||
-rw-r--r-- | src/temp/esop/module.make | 1 |
4 files changed, 33 insertions, 307 deletions
diff --git a/src/temp/esop/esop.h b/src/temp/esop/esop.h index d6cdff71..5f95f371 100644 --- a/src/temp/esop/esop.h +++ b/src/temp/esop/esop.h @@ -25,8 +25,9 @@ extern "C" { #endif -#include "stdio.h" +#include <stdio.h> #include "vec.h" +#include "mem.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -34,16 +35,16 @@ extern "C" { typedef struct Esop_Man_t_ Esop_Man_t; typedef struct Esop_Cube_t_ Esop_Cube_t; -typedef struct Esop_MmFixed_t_ Esop_MmFixed_t; +typedef struct Mem_Fixed_t_ Mem_Fixed_t; struct Esop_Man_t_ { int nVars; // the number of vars int nWords; // the number of words - Esop_MmFixed_t * pMemMan1; // memory manager for cubes - Esop_MmFixed_t * pMemMan2; // memory manager for cubes - Esop_MmFixed_t * pMemMan4; // memory manager for cubes - Esop_MmFixed_t * pMemMan8; // memory manager for cubes + Mem_Fixed_t * pMemMan1; // memory manager for cubes + Mem_Fixed_t * pMemMan2; // memory manager for cubes + Mem_Fixed_t * pMemMan4; // memory manager for cubes + Mem_Fixed_t * pMemMan8; // memory manager for cubes // temporary cubes Esop_Cube_t * pOne0; // tautology cube Esop_Cube_t * pOne1; // tautology cube @@ -99,12 +100,12 @@ static inline void Esop_CubeXorVar( Esop_Cube_t * p, int Var, int Value ) { p- static inline int Esop_BitWordNum( int nBits ) { return (nBits>>5) + ((nBits&31) > 0); } /*=== esopMem.c ===========================================================*/ -extern Esop_MmFixed_t * Esop_MmFixedStart( int nEntrySize ); -extern void Esop_MmFixedStop( Esop_MmFixed_t * p, int fVerbose ); -extern char * Esop_MmFixedEntryFetch( Esop_MmFixed_t * p ); -extern void Esop_MmFixedEntryRecycle( Esop_MmFixed_t * p, char * pEntry ); -extern void Esop_MmFixedRestart( Esop_MmFixed_t * p ); -extern int Esop_MmFixedReadMemUsage( Esop_MmFixed_t * p ); +extern Mem_Fixed_t * Mem_FixedStart( int nEntrySize ); +extern void Mem_FixedStop( Mem_Fixed_t * p, int fVerbose ); +extern char * Mem_FixedEntryFetch( Mem_Fixed_t * p ); +extern void Mem_FixedEntryRecycle( Mem_Fixed_t * p, char * pEntry ); +extern void Mem_FixedRestart( Mem_Fixed_t * p ); +extern int Mem_FixedReadMemUsage( Mem_Fixed_t * p ); /*=== esopMin.c ===========================================================*/ extern void Esop_EsopMinimize( Esop_Man_t * p ); extern void Esop_EsopAddCube( Esop_Man_t * p, Esop_Cube_t * pCube ); @@ -142,13 +143,13 @@ static inline Esop_Cube_t * Esop_CubeAlloc( Esop_Man_t * p ) { Esop_Cube_t * pCube; if ( p->nWords <= 1 ) - pCube = (Esop_Cube_t *)Esop_MmFixedEntryFetch( p->pMemMan1 ); + pCube = (Esop_Cube_t *)Mem_FixedEntryFetch( p->pMemMan1 ); else if ( p->nWords <= 2 ) - pCube = (Esop_Cube_t *)Esop_MmFixedEntryFetch( p->pMemMan2 ); + pCube = (Esop_Cube_t *)Mem_FixedEntryFetch( p->pMemMan2 ); else if ( p->nWords <= 4 ) - pCube = (Esop_Cube_t *)Esop_MmFixedEntryFetch( p->pMemMan4 ); + pCube = (Esop_Cube_t *)Mem_FixedEntryFetch( p->pMemMan4 ); else if ( p->nWords <= 8 ) - pCube = (Esop_Cube_t *)Esop_MmFixedEntryFetch( p->pMemMan8 ); + pCube = (Esop_Cube_t *)Mem_FixedEntryFetch( p->pMemMan8 ); pCube->pNext = NULL; pCube->nVars = p->nVars; pCube->nWords = p->nWords; @@ -211,13 +212,13 @@ static inline Esop_Cube_t * Esop_CubeDup( Esop_Man_t * p, Esop_Cube_t * pCopy ) static inline void Esop_CubeRecycle( Esop_Man_t * p, Esop_Cube_t * pCube ) { if ( pCube->nWords <= 1 ) - Esop_MmFixedEntryRecycle( p->pMemMan1, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan1, (char *)pCube ); else if ( pCube->nWords <= 2 ) - Esop_MmFixedEntryRecycle( p->pMemMan2, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan2, (char *)pCube ); else if ( pCube->nWords <= 4 ) - Esop_MmFixedEntryRecycle( p->pMemMan4, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan4, (char *)pCube ); else if ( pCube->nWords <= 8 ) - Esop_MmFixedEntryRecycle( p->pMemMan8, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan8, (char *)pCube ); } /**Function************************************************************* @@ -238,16 +239,16 @@ static inline void Esop_CoverRecycle( Esop_Man_t * p, Esop_Cube_t * pCover ) return; if ( pCover->nWords <= 1 ) Esop_CoverForEachCubeSafe( pCover, pCube, pCube2 ) - Esop_MmFixedEntryRecycle( p->pMemMan1, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan1, (char *)pCube ); else if ( pCover->nWords <= 2 ) Esop_CoverForEachCubeSafe( pCover, pCube, pCube2 ) - Esop_MmFixedEntryRecycle( p->pMemMan2, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan2, (char *)pCube ); else if ( pCover->nWords <= 4 ) Esop_CoverForEachCubeSafe( pCover, pCube, pCube2 ) - Esop_MmFixedEntryRecycle( p->pMemMan4, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan4, (char *)pCube ); else if ( pCover->nWords <= 8 ) Esop_CoverForEachCubeSafe( pCover, pCube, pCube2 ) - Esop_MmFixedEntryRecycle( p->pMemMan8, (char *)pCube ); + Mem_FixedEntryRecycle( p->pMemMan8, (char *)pCube ); } /**Function************************************************************* diff --git a/src/temp/esop/esopMan.c b/src/temp/esop/esopMan.c index e81411f8..5c411349 100644 --- a/src/temp/esop/esopMan.c +++ b/src/temp/esop/esopMan.c @@ -47,10 +47,10 @@ Esop_Man_t * Esop_ManAlloc( int nVars ) memset( pMan, 0, sizeof(Esop_Man_t) ); pMan->nVars = nVars; pMan->nWords = Esop_BitWordNum( nVars * 2 ); - pMan->pMemMan1 = Esop_MmFixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (1 - 1) ); - pMan->pMemMan2 = Esop_MmFixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (2 - 1) ); - pMan->pMemMan4 = Esop_MmFixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (4 - 1) ); - pMan->pMemMan8 = Esop_MmFixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (8 - 1) ); + pMan->pMemMan1 = Mem_FixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (1 - 1) ); + pMan->pMemMan2 = Mem_FixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (2 - 1) ); + pMan->pMemMan4 = Mem_FixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (4 - 1) ); + pMan->pMemMan8 = Mem_FixedStart( sizeof(Esop_Cube_t) + sizeof(unsigned) * (8 - 1) ); // allocate storage for the temporary cover pMan->ppStore = ALLOC( Esop_Cube_t *, pMan->nVars + 1 ); // create tautology cubes @@ -101,10 +101,10 @@ void Esop_ManClean( Esop_Man_t * p, int nSupp ) ***********************************************************************/ void Esop_ManFree( Esop_Man_t * p ) { - Esop_MmFixedStop ( p->pMemMan1, 0 ); - Esop_MmFixedStop ( p->pMemMan2, 0 ); - Esop_MmFixedStop ( p->pMemMan4, 0 ); - Esop_MmFixedStop ( p->pMemMan8, 0 ); + Mem_FixedStop ( p->pMemMan1, 0 ); + Mem_FixedStop ( p->pMemMan2, 0 ); + Mem_FixedStop ( p->pMemMan4, 0 ); + Mem_FixedStop ( p->pMemMan8, 0 ); free( p->ppStore ); free( p ); } diff --git a/src/temp/esop/esopMem.c b/src/temp/esop/esopMem.c deleted file mode 100644 index 9d8e7405..00000000 --- a/src/temp/esop/esopMem.c +++ /dev/null @@ -1,274 +0,0 @@ -/**CFile**************************************************************** - - FileName [esopMem.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Cover manipulation package.] - - Synopsis [Memory managers.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: esopMem.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "esop.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -struct Esop_MmFixed_t_ -{ - // information about individual entries - int nEntrySize; // the size of one entry - int nEntriesAlloc; // the total number of entries allocated - int nEntriesUsed; // the number of entries in use - int nEntriesMax; // the max number of entries in use - char * pEntriesFree; // the linked list of free entries - - // this is where the memory is stored - int nChunkSize; // the size of one chunk - int nChunksAlloc; // the maximum number of memory chunks - int nChunks; // the current number of memory chunks - char ** pChunks; // the allocated memory - - // statistics - int nMemoryUsed; // memory used in the allocated entries - int nMemoryAlloc; // memory allocated -}; - -struct Esop_MmFlex_t_ -{ - // information about individual entries - int nEntriesUsed; // the number of entries allocated - char * pCurrent; // the current pointer to free memory - char * pEnd; // the first entry outside the free memory - - // this is where the memory is stored - int nChunkSize; // the size of one chunk - int nChunksAlloc; // the maximum number of memory chunks - int nChunks; // the current number of memory chunks - char ** pChunks; // the allocated memory - - // statistics - int nMemoryUsed; // memory used in the allocated entries - int nMemoryAlloc; // memory allocated -}; - -struct Esop_MmStep_t_ -{ - int nMems; // the number of fixed memory managers employed - Esop_MmFixed_t ** pMems; // memory managers: 2^1 words, 2^2 words, etc - int nMapSize; // the size of the memory array - Esop_MmFixed_t ** pMap; // maps the number of bytes into its memory manager -}; - -//////////////////////////////////////////////////////////////////////// -/// 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 [] - -***********************************************************************/ -Esop_MmFixed_t * Esop_MmFixedStart( int nEntrySize ) -{ - Esop_MmFixed_t * p; - - p = ALLOC( Esop_MmFixed_t, 1 ); - memset( p, 0, sizeof(Esop_MmFixed_t) ); - - p->nEntrySize = nEntrySize; - p->nEntriesAlloc = 0; - p->nEntriesUsed = 0; - p->pEntriesFree = NULL; - - if ( nEntrySize * (1 << 10) < (1<<16) ) - p->nChunkSize = (1 << 10); - else - p->nChunkSize = (1<<16) / nEntrySize; - if ( p->nChunkSize < 8 ) - p->nChunkSize = 8; - - p->nChunksAlloc = 64; - p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); - - p->nMemoryUsed = 0; - p->nMemoryAlloc = 0; - return p; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Esop_MmFixedStop( Esop_MmFixed_t * p, int fVerbose ) -{ - int i; - if ( p == NULL ) - return; - if ( fVerbose ) - { - printf( "Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n", - p->nEntrySize, p->nChunkSize, p->nChunks ); - printf( " Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n", - p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc ); - } - for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Esop_MmFixedEntryFetch( Esop_MmFixed_t * p ) -{ - char * pTemp; - int i; - - // check if there are still free entries - if ( p->nEntriesUsed == p->nEntriesAlloc ) - { // need to allocate more entries - assert( p->pEntriesFree == NULL ); - if ( p->nChunks == p->nChunksAlloc ) - { - p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); - } - p->pEntriesFree = ALLOC( char, p->nEntrySize * p->nChunkSize ); - p->nMemoryAlloc += p->nEntrySize * p->nChunkSize; - // transform these entries into a linked list - pTemp = p->pEntriesFree; - for ( i = 1; i < p->nChunkSize; i++ ) - { - *((char **)pTemp) = pTemp + p->nEntrySize; - pTemp += p->nEntrySize; - } - // set the last link - *((char **)pTemp) = NULL; - // add the chunk to the chunk storage - p->pChunks[ p->nChunks++ ] = p->pEntriesFree; - // add to the number of entries allocated - p->nEntriesAlloc += p->nChunkSize; - } - // incrememt the counter of used entries - p->nEntriesUsed++; - if ( p->nEntriesMax < p->nEntriesUsed ) - p->nEntriesMax = p->nEntriesUsed; - // return the first entry in the free entry list - pTemp = p->pEntriesFree; - p->pEntriesFree = *((char **)pTemp); - return pTemp; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Esop_MmFixedEntryRecycle( Esop_MmFixed_t * p, char * pEntry ) -{ - // decrement the counter of used entries - p->nEntriesUsed--; - // add the entry to the linked list of free entries - *((char **)pEntry) = p->pEntriesFree; - p->pEntriesFree = pEntry; -} - -/**Function************************************************************* - - Synopsis [] - - Description [Relocates all the memory except the first chunk.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Esop_MmFixedRestart( Esop_MmFixed_t * p ) -{ - int i; - char * pTemp; - - // deallocate all chunks except the first one - for ( i = 1; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - p->nChunks = 1; - // transform these entries into a linked list - pTemp = p->pChunks[0]; - for ( i = 1; i < p->nChunkSize; i++ ) - { - *((char **)pTemp) = pTemp + p->nEntrySize; - pTemp += p->nEntrySize; - } - // set the last link - *((char **)pTemp) = NULL; - // set the free entry list - p->pEntriesFree = p->pChunks[0]; - // set the correct statistics - p->nMemoryAlloc = p->nEntrySize * p->nChunkSize; - p->nMemoryUsed = 0; - p->nEntriesAlloc = p->nChunkSize; - p->nEntriesUsed = 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Esop_MmFixedReadMemUsage( Esop_MmFixed_t * p ) -{ - return p->nMemoryAlloc; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// diff --git a/src/temp/esop/module.make b/src/temp/esop/module.make index cab5e737..1003ccc1 100644 --- a/src/temp/esop/module.make +++ b/src/temp/esop/module.make @@ -1,4 +1,3 @@ SRC += src/temp/esop/esopMan.c \ - src/temp/esop/esopMem.c \ src/temp/esop/esopMin.c \ src/temp/esop/esopUtil.c |