Commit fe40fd5c by Alan Mishchenko

Updating new mapper.

parent 8c7ca72e
......@@ -39,6 +39,7 @@ struct Mmr_Flex_t_
int nPageBase; // log2 page size in words
int PageMask; // page mask
int nEntries; // entries allocated
int nEntriesMax; // max number of enries used
int iNext; // next word to be used
Vec_Ptr_t vPages; // memory pages
};
......@@ -49,15 +50,19 @@ struct Mmr_Fixed_t_
int PageMask; // page mask
int nEntryWords; // entry size in words
int nEntries; // entries allocated
int nEntriesMax; // max number of enries used
Vec_Ptr_t vPages; // memory pages
Vec_Int_t vFrees; // free entries
};
struct Mmr_Step_t_
{
Vec_Ptr_t vLarge; // memory pages
int nMems; // the number of fixed memory managers employed
Mmr_Fixed_t * pMems[0]; // memory managers: 2^1 words, 2^2 words, etc
int nBits; // the number of bits
int uMask; // the number of managers minus 1
int nEntries; // the number of entries
int nEntriesMax; // the max number of entries
int nEntriesAll; // the total number of entries
Mmr_Fixed_t pMems[0]; // memory managers: 2^0 words, 2^1 words, etc
};
////////////////////////////////////////////////////////////////////////
......@@ -88,9 +93,9 @@ static inline void Mmr_FlexStop( Mmr_Flex_t * p )
{
word * pPage;
int i;
if ( 1 )
printf( "Using %d pages of %d words each. Total memory %.2f MB.\n",
Vec_PtrSize(&p->vPages), 1 << p->nPageBase,
if ( 1 && Vec_PtrSize(&p->vPages) )
printf( "Using %3d pages of %6d words each with %6d entries (max = %6d). Total memory %5.2f MB.\n",
Vec_PtrSize(&p->vPages), p->nPageBase ? 1 << p->nPageBase : 0, p->nEntries, p->nEntriesMax,
1.0 * Vec_PtrSize(&p->vPages) * (1 << p->nPageBase) * 8 / (1 << 20) );
Vec_PtrForEachEntry( word *, &p->vPages, pPage, i )
ABC_FREE( pPage );
......@@ -114,6 +119,7 @@ static inline int Mmr_FlexFetch( Mmr_Flex_t * p, int nWords )
hEntry = ((Vec_PtrSize(&p->vPages) - 1) << p->nPageBase) | p->iNext;
p->iNext += nWords;
p->nEntries++;
p->nEntriesMax = Abc_MaxInt( p->nEntriesMax, p->nEntries );
return hEntry;
}
static inline void Mmr_FlexRelease( Mmr_Flex_t * p, int h )
......@@ -139,33 +145,37 @@ static inline void Mmr_FlexRelease( Mmr_Flex_t * p, int h )
SeeAlso []
***********************************************************************/
static inline Mmr_Fixed_t * Mmr_FixedStart( int nPageBase, int nEntryWords )
static inline void Mmr_FixedCreate( Mmr_Fixed_t * p, int nPageBase, int nEntryWords )
{
Mmr_Fixed_t * p;
assert( nEntryWords > 0 && nEntryWords < (1 << nPageBase) );
p = ABC_CALLOC( Mmr_Fixed_t, 1 );
p->nPageBase = nPageBase;
p->PageMask = (1 << nPageBase) - 1;
p->nEntryWords = nEntryWords;
}
static inline Mmr_Fixed_t * Mmr_FixedStart( int nPageBase, int nEntryWords )
{
Mmr_Fixed_t * p = ABC_CALLOC( Mmr_Fixed_t, 1 );
Mmr_FixedCreate( p, nPageBase, nEntryWords );
return p;
}
static inline void Mmr_FixedStop( Mmr_Fixed_t * p )
static inline void Mmr_FixedStop( Mmr_Fixed_t * p, int fFreeLast )
{
word * pPage;
int i;
if ( 1 )
printf( "Using %d pages of %d words each. Total memory %.2f MB.\n",
Vec_PtrSize(&p->vPages), 1 << p->nPageBase,
if ( 1 && Vec_PtrSize(&p->vPages) )
printf( "Using %3d pages of %6d words each with %6d entries (max = %6d) of size %d. Total memory %5.2f MB.\n",
Vec_PtrSize(&p->vPages), p->nPageBase ? 1 << p->nPageBase : 0, p->nEntries, p->nEntriesMax, p->nEntryWords,
1.0 * Vec_PtrSize(&p->vPages) * (1 << p->nPageBase) * 8 / (1 << 20) );
Vec_PtrForEachEntry( word *, &p->vPages, pPage, i )
ABC_FREE( pPage );
ABC_FREE( p->vPages.pArray );
ABC_FREE( p->vFrees.pArray );
ABC_FREE( p );
if ( fFreeLast )
ABC_FREE( p );
}
static inline word * Mmr_FixedEntry( Mmr_Fixed_t * p, int h )
{
assert( h > 0 && h < ((Vec_PtrSize(&p->vPages) - 1) << p->nPageBase) );
assert( h > 0 && h < (Vec_PtrSize(&p->vPages) << p->nPageBase) );
return (word *)Vec_PtrEntry(&p->vPages, (h >> p->nPageBase)) + (h & p->PageMask);
}
static inline int Mmr_FixedFetch( Mmr_Fixed_t * p )
......@@ -179,10 +189,12 @@ static inline int Mmr_FixedFetch( Mmr_Fixed_t * p )
Vec_IntReverseOrder( &p->vFrees );
}
p->nEntries++;
p->nEntriesMax = Abc_MaxInt( p->nEntriesMax, p->nEntries );
return Vec_IntPop( &p->vFrees );
}
static inline void Mmr_FixedRecycle( Mmr_Fixed_t * p, int h )
{
p->nEntries--;
memset( Mmr_FixedEntry(p, h), 0xFF, sizeof(word) * p->nEntryWords );
Vec_IntPush( &p->vFrees, h );
}
......@@ -199,46 +211,41 @@ static inline void Mmr_FixedRecycle( Mmr_Fixed_t * p, int h )
SeeAlso []
***********************************************************************/
static inline Mmr_Step_t * Mmr_StepStart( int nWordsMax )
static inline Mmr_Step_t * Mmr_StepStart( int nPageBase, int nWordBase )
{
char * pMemory = ABC_CALLOC( char, sizeof(Mmr_Step_t) + sizeof(void *) * (nWordsMax + 1) );
char * pMemory = ABC_CALLOC( char, sizeof(Mmr_Step_t) + sizeof(Mmr_Fixed_t) * (1 << nWordBase) );
Mmr_Step_t * p = (Mmr_Step_t *)pMemory;
p->nMems = nWordsMax + 1;
int i;
p->nBits = nWordBase;
p->uMask = (1 << nWordBase) - 1;
for ( i = 1; i <= p->uMask; i++ )
Mmr_FixedCreate( p->pMems + i, nPageBase, i );
return p;
}
static inline void Mmr_StepStop( Mmr_Step_t * p )
{
word * pPage;
int i;
Vec_PtrForEachEntry( word *, &p->vLarge, pPage, i )
ABC_FREE( pPage );
ABC_FREE( p->vLarge.pArray );
for ( i = 0; i <= p->uMask; i++ )
Mmr_FixedStop( p->pMems + i, 0 );
ABC_FREE( p );
}
static inline word * Mmr_StepEntry( Mmr_Step_t * p, int nWords, int h )
static inline word * Mmr_StepEntry( Mmr_Step_t * p, int h )
{
if ( nWords < p->nMems )
return Mmr_FixedEntry( p->pMems[nWords], h );
return (word *)Vec_PtrEntry(&p->vLarge, h);
assert( (h & p->uMask) > 0 );
return Mmr_FixedEntry( p->pMems + (h & p->uMask), (h >> p->nBits) );
}
static inline int Mmr_StepFetch( Mmr_Step_t * p, int nWords )
{
if ( nWords < p->nMems )
return Mmr_FixedFetch( p->pMems[nWords] );
Vec_PtrPush( &p->vLarge, ABC_FALLOC( word, nWords ) );
return Vec_PtrSize( &p->vLarge ) - 1;
assert( nWords > 0 && nWords <= p->uMask );
p->nEntries++;
p->nEntriesAll++;
p->nEntriesMax = Abc_MaxInt( p->nEntriesMax, p->nEntries );
return (Mmr_FixedFetch(p->pMems + nWords) << p->nBits) | nWords;
}
static inline void Mmr_StepRecycle( Mmr_Step_t * p, int nWords, int h )
static inline void Mmr_StepRecycle( Mmr_Step_t * p, int h )
{
void * pPage;
if ( nWords < p->nMems )
{
Mmr_FixedRecycle( p->pMems[nWords], h );
return;
}
pPage = Vec_PtrEntry( &p->vLarge, h );
ABC_FREE( pPage );
Vec_PtrWriteEntry( &p->vLarge, h, NULL );
p->nEntries--;
Mmr_FixedRecycle( p->pMems + (h & p->uMask), (h >> p->nBits) );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment