abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mem2.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mem2.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Memory management.]
8 
9  Synopsis [External declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: mem2.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__aig__mem__mem2_h
22 #define ABC__aig__mem__mem2_h
23 
24 #include "misc/vec/vec.h"
25 
27 
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// DECLARATIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 typedef struct Mmr_Flex_t_ Mmr_Flex_t;
34 typedef struct Mmr_Fixed_t_ Mmr_Fixed_t;
35 typedef struct Mmr_Step_t_ Mmr_Step_t;
36 
38 {
39  int nPageBase; // log2 page size in words
40  int PageMask; // page mask
41  int nEntries; // entries allocated
42  int nEntriesMax; // max number of enries used
43  int iNext; // next word to be used
44  Vec_Ptr_t vPages; // memory pages
45 };
46 
48 {
49  int nPageBase; // log2 page size in words
50  int PageMask; // page mask
51  int nEntryWords; // entry size in words
52  int nEntries; // entries allocated
53  int nEntriesMax; // max number of enries used
54  Vec_Ptr_t vPages; // memory pages
55  Vec_Int_t vFrees; // free entries
56 };
57 
59 {
60  int nBits; // the number of bits
61  int uMask; // the number of managers minus 1
62  int nEntries; // the number of entries
63  int nEntriesMax; // the max number of entries
64  int nEntriesAll; // the total number of entries
65  Mmr_Fixed_t pMems[0]; // memory managers: 2^0 words, 2^1 words, etc
66 };
67 
68 ////////////////////////////////////////////////////////////////////////
69 /// FUNCTION DEFINITIONS ///
70 ////////////////////////////////////////////////////////////////////////
71 
72 /**Function*************************************************************
73 
74  Synopsis []
75 
76  Description []
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
83 static inline Mmr_Flex_t * Mmr_FlexStart( int nPageBase )
84 {
85  Mmr_Flex_t * p;
86  p = ABC_CALLOC( Mmr_Flex_t, 1 );
87  p->nPageBase = nPageBase;
88  p->PageMask = (1 << nPageBase) - 1;
89  p->iNext = (1 << nPageBase);
90  return p;
91 }
92 static inline void Mmr_FlexStop( Mmr_Flex_t * p )
93 {
94  word * pPage;
95  int i;
96  if ( 0 && Vec_PtrSize(&p->vPages) )
97  printf( "Using %3d pages of %6d words each with %6d entries (max = %6d). Total memory = %5.2f MB.\n",
98  Vec_PtrSize(&p->vPages), p->nPageBase ? 1 << p->nPageBase : 0, p->nEntries, p->nEntriesMax,
99  1.0 * Vec_PtrSize(&p->vPages) * (1 << p->nPageBase) * 8 / (1 << 20) );
100  Vec_PtrForEachEntry( word *, &p->vPages, pPage, i )
101  ABC_FREE( pPage );
102  ABC_FREE( p->vPages.pArray );
103  ABC_FREE( p );
104 }
105 static inline word * Mmr_FlexEntry( Mmr_Flex_t * p, int h )
106 {
107  assert( h > 0 && h < p->iNext );
108  return (word *)Vec_PtrEntry(&p->vPages, (h >> p->nPageBase)) + (h & p->PageMask);
109 }
110 static inline int Mmr_FlexFetch( Mmr_Flex_t * p, int nWords )
111 {
112  int hEntry;
113  assert( nWords > 0 && nWords < p->PageMask );
114  if ( p->iNext + nWords >= p->PageMask )
115  {
116  Vec_PtrPush( &p->vPages, ABC_FALLOC( word, p->PageMask + 1 ) );
117  p->iNext = 1;
118  }
119  hEntry = ((Vec_PtrSize(&p->vPages) - 1) << p->nPageBase) | p->iNext;
120  p->iNext += nWords;
121  p->nEntries++;
122  p->nEntriesMax = Abc_MaxInt( p->nEntriesMax, p->nEntries );
123  return hEntry;
124 }
125 static inline void Mmr_FlexRelease( Mmr_Flex_t * p, int h )
126 {
127  assert( h > 0 && h < p->iNext );
128  if ( (h >> p->nPageBase) && Vec_PtrEntry(&p->vPages, (h >> p->nPageBase) - 1) )
129  {
130  word * pPage = (word *)Vec_PtrEntry(&p->vPages, (h >> p->nPageBase) - 1);
131  Vec_PtrWriteEntry( &p->vPages, (h >> p->nPageBase) - 1, NULL );
132  ABC_FREE( pPage );
133  }
134 }
135 
136 
137 /**Function*************************************************************
138 
139  Synopsis []
140 
141  Description []
142 
143  SideEffects []
144 
145  SeeAlso []
146 
147 ***********************************************************************/
148 static inline void Mmr_FixedCreate( Mmr_Fixed_t * p, int nPageBase, int nEntryWords )
149 {
150  assert( nEntryWords > 0 && nEntryWords < (1 << nPageBase) );
151  p->nPageBase = nPageBase;
152  p->PageMask = (1 << nPageBase) - 1;
153  p->nEntryWords = nEntryWords;
154 }
155 static inline Mmr_Fixed_t * Mmr_FixedStart( int nPageBase, int nEntryWords )
156 {
158  Mmr_FixedCreate( p, nPageBase, nEntryWords );
159  return p;
160 }
161 static inline void Mmr_FixedStop( Mmr_Fixed_t * p, int fFreeLast )
162 {
163  word * pPage;
164  int i;
165  if ( 0 && Vec_PtrSize(&p->vPages) )
166  printf( "Using %3d pages of %6d words each with %6d entries (max = %6d) of size %d. Total memory = %5.2f MB.\n",
167  Vec_PtrSize(&p->vPages), p->nPageBase ? 1 << p->nPageBase : 0, p->nEntries, p->nEntriesMax, p->nEntryWords,
168  1.0 * Vec_PtrSize(&p->vPages) * (1 << p->nPageBase) * 8 / (1 << 20) );
169  Vec_PtrForEachEntry( word *, &p->vPages, pPage, i )
170  ABC_FREE( pPage );
171  ABC_FREE( p->vPages.pArray );
172  ABC_FREE( p->vFrees.pArray );
173  if ( fFreeLast )
174  ABC_FREE( p );
175 }
176 static inline word * Mmr_FixedEntry( Mmr_Fixed_t * p, int h )
177 {
178  assert( h > 0 && h < (Vec_PtrSize(&p->vPages) << p->nPageBase) );
179  return (word *)Vec_PtrEntry(&p->vPages, (h >> p->nPageBase)) + (h & p->PageMask);
180 }
181 static inline int Mmr_FixedFetch( Mmr_Fixed_t * p )
182 {
183  if ( Vec_IntSize(&p->vFrees) == 0 )
184  {
185  int i, hEntry = Vec_PtrSize(&p->vPages) << p->nPageBase;
186  Vec_PtrPush( &p->vPages, ABC_FALLOC( word, p->PageMask + 1 ) );
187  for ( i = 1; i + p->nEntryWords <= p->PageMask; i += p->nEntryWords )
188  Vec_IntPush( &p->vFrees, hEntry | i );
190  }
191  p->nEntries++;
193  return Vec_IntPop( &p->vFrees );
194 }
195 static inline void Mmr_FixedRecycle( Mmr_Fixed_t * p, int h )
196 {
197  p->nEntries--;
198  memset( Mmr_FixedEntry(p, h), 0xFF, sizeof(word) * p->nEntryWords );
199  Vec_IntPush( &p->vFrees, h );
200 }
201 static inline int Mmr_FixedMemory( Mmr_Fixed_t * p )
202 {
203  return Vec_PtrSize(&p->vPages) * (p->PageMask + 1);
204 }
205 
206 
207 /**Function*************************************************************
208 
209  Synopsis []
210 
211  Description []
212 
213  SideEffects []
214 
215  SeeAlso []
216 
217 ***********************************************************************/
218 static inline Mmr_Step_t * Mmr_StepStart( int nPageBase, int nWordBase )
219 {
220  char * pMemory = ABC_CALLOC( char, sizeof(Mmr_Step_t) + sizeof(Mmr_Fixed_t) * (1 << nWordBase) );
221  Mmr_Step_t * p = (Mmr_Step_t *)pMemory;
222  int i;
223  p->nBits = nWordBase;
224  p->uMask = (1 << nWordBase) - 1;
225  for ( i = 1; i <= p->uMask; i++ )
226  Mmr_FixedCreate( p->pMems + i, nPageBase, i );
227  return p;
228 }
229 static inline void Mmr_StepStop( Mmr_Step_t * p )
230 {
231  int i;
232  for ( i = 0; i <= p->uMask; i++ )
233  Mmr_FixedStop( p->pMems + i, 0 );
234  ABC_FREE( p );
235 }
236 static inline word * Mmr_StepEntry( Mmr_Step_t * p, int h )
237 {
238  assert( (h & p->uMask) > 0 );
239  return Mmr_FixedEntry( p->pMems + (h & p->uMask), (h >> p->nBits) );
240 }
241 static inline int Mmr_StepFetch( Mmr_Step_t * p, int nWords )
242 {
243  assert( nWords > 0 && nWords <= p->uMask );
244  p->nEntries++;
245  p->nEntriesAll++;
247  return (Mmr_FixedFetch(p->pMems + nWords) << p->nBits) | nWords;
248 }
249 static inline void Mmr_StepRecycle( Mmr_Step_t * p, int h )
250 {
251  p->nEntries--;
252  Mmr_FixedRecycle( p->pMems + (h & p->uMask), (h >> p->nBits) );
253 }
254 static inline int Mmr_StepMemory( Mmr_Step_t * p )
255 {
256  int i, Mem = 0;
257  for ( i = 1; i <= p->uMask; i++ )
258  Mem += Mmr_FixedMemory( p->pMems + i );
259  return Mem;
260 }
261 
262 
264 
265 #endif
266 
267 ////////////////////////////////////////////////////////////////////////
268 /// END OF FILE ///
269 ////////////////////////////////////////////////////////////////////////
270 
271 
char * memset()
int nPageBase
Definition: mem2.h:49
static void Mmr_FixedStop(Mmr_Fixed_t *p, int fFreeLast)
Definition: mem2.h:161
static Mmr_Flex_t * Mmr_FlexStart(int nPageBase)
FUNCTION DEFINITIONS ///.
Definition: mem2.h:83
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Mmr_StepMemory(Mmr_Step_t *p)
Definition: mem2.h:254
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int nEntriesMax
Definition: mem2.h:53
int nEntriesMax
Definition: mem2.h:42
static Mmr_Step_t * Mmr_StepStart(int nPageBase, int nWordBase)
Definition: mem2.h:218
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static word * Mmr_FlexEntry(Mmr_Flex_t *p, int h)
Definition: mem2.h:105
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int nWords
Definition: abcNpn.c:127
static void Vec_IntReverseOrder(Vec_Int_t *p)
Definition: vecInt.h:1042
static void Mmr_FlexRelease(Mmr_Flex_t *p, int h)
Definition: mem2.h:125
int PageMask
Definition: mem2.h:40
static void Mmr_FixedCreate(Mmr_Fixed_t *p, int nPageBase, int nEntryWords)
Definition: mem2.h:148
static word * Mmr_FixedEntry(Mmr_Fixed_t *p, int h)
Definition: mem2.h:176
int nEntries
Definition: mem2.h:62
Vec_Int_t vFrees
Definition: mem2.h:55
int iNext
Definition: mem2.h:43
static int Mmr_StepFetch(Mmr_Step_t *p, int nWords)
Definition: mem2.h:241
Mmr_Fixed_t pMems[0]
Definition: mem2.h:65
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Mmr_FixedMemory(Mmr_Fixed_t *p)
Definition: mem2.h:201
static int Vec_IntPop(Vec_Int_t *p)
static word * Mmr_StepEntry(Mmr_Step_t *p, int h)
Definition: mem2.h:236
int nEntries
Definition: mem2.h:41
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static void Mmr_FlexStop(Mmr_Flex_t *p)
Definition: mem2.h:92
static int Mmr_FixedFetch(Mmr_Fixed_t *p)
Definition: mem2.h:181
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static void Mmr_StepRecycle(Mmr_Step_t *p, int h)
Definition: mem2.h:249
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
typedefABC_NAMESPACE_HEADER_START struct Mmr_Flex_t_ Mmr_Flex_t
DECLARATIONS ///.
Definition: mem2.h:33
int nBits
Definition: mem2.h:60
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Mmr_Fixed_t * Mmr_FixedStart(int nPageBase, int nEntryWords)
Definition: mem2.h:155
Vec_Ptr_t vPages
Definition: mem2.h:44
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
int nEntryWords
Definition: mem2.h:51
static int Mmr_FlexFetch(Mmr_Flex_t *p, int nWords)
Definition: mem2.h:110
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int nPageBase
Definition: mem2.h:39
#define assert(ex)
Definition: util_old.h:213
Vec_Ptr_t vPages
Definition: mem2.h:54
static void Mmr_StepStop(Mmr_Step_t *p)
Definition: mem2.h:229
static void Mmr_FixedRecycle(Mmr_Fixed_t *p, int h)
Definition: mem2.h:195
int PageMask
Definition: mem2.h:50
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int nEntriesAll
Definition: mem2.h:64
int uMask
Definition: mem2.h:61
int nEntriesMax
Definition: mem2.h:63
int nEntries
Definition: mem2.h:52
#define ABC_FALLOC(type, num)
Definition: abc_global.h:231