abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hopMem.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [hopMem.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Minimalistic And-Inverter Graph package.]
8 
9  Synopsis [Memory management for the AIG nodes.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - May 11, 2006.]
16 
17  Revision [$Id: hopMem.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "hop.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // memory management
31 #define IVY_PAGE_SIZE 12 // page size containing 2^IVY_PAGE_SIZE nodes
32 #define IVY_PAGE_MASK 4095 // page bitmask (2^IVY_PAGE_SIZE)-1
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Starts the internal memory manager.]
41 
42  Description []
43 
44  SideEffects []
45 
46  SeeAlso []
47 
48 ***********************************************************************/
50 {
51  p->vChunks = Vec_PtrAlloc( 128 );
52  p->vPages = Vec_PtrAlloc( 128 );
53 }
54 
55 /**Function*************************************************************
56 
57  Synopsis [Stops the internal memory manager.]
58 
59  Description []
60 
61  SideEffects []
62 
63  SeeAlso []
64 
65 ***********************************************************************/
67 {
68  void * pMemory;
69  int i;
70  Vec_PtrForEachEntry( void *, p->vChunks, pMemory, i )
71  ABC_FREE( pMemory );
72  Vec_PtrFree( p->vChunks );
73  Vec_PtrFree( p->vPages );
74  p->pListFree = NULL;
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Allocates additional memory for the nodes.]
80 
81  Description [Allocates IVY_PAGE_SIZE nodes. Aligns memory by 32 bytes.
82  Records the pointer to the AIG manager in the -1 entry.]
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
90 {
91  char * pMemory;
92  int i, nBytes;
93  assert( sizeof(Hop_Obj_t) <= 64 );
94  assert( p->pListFree == NULL );
95 // assert( (Hop_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
96  // allocate new memory page
97  nBytes = sizeof(Hop_Obj_t) * (1<<IVY_PAGE_SIZE) + 64;
98  pMemory = ABC_ALLOC( char, nBytes );
99  Vec_PtrPush( p->vChunks, pMemory );
100  // align memory at the 32-byte boundary
101  pMemory = pMemory + 64 - (((int)(ABC_PTRUINT_T)pMemory) & 63);
102  // remember the manager in the first entry
103  Vec_PtrPush( p->vPages, pMemory );
104  // break the memory down into nodes
105  p->pListFree = (Hop_Obj_t *)pMemory;
106  for ( i = 1; i <= IVY_PAGE_MASK; i++ )
107  {
108  *((char **)pMemory) = pMemory + sizeof(Hop_Obj_t);
109  pMemory += sizeof(Hop_Obj_t);
110  }
111  *((char **)pMemory) = NULL;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////
115 /// END OF FILE ///
116 ////////////////////////////////////////////////////////////////////////
117 
118 
120 
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Hop_ManStartMemory(Hop_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: hopMem.c:49
void Hop_ManAddMemory(Hop_Man_t *p)
MACRO DEFINITIONS ///.
Definition: hopMem.c:89
Definition: hop.h:65
void Hop_ManStopMemory(Hop_Man_t *p)
Definition: hopMem.c:66
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define IVY_PAGE_MASK
Definition: hopMem.c:32
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
#define IVY_PAGE_SIZE
DECLARATIONS ///.
Definition: hopMem.c:31
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
struct Hop_Obj_t_ Hop_Obj_t
Definition: hop.h:50
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223