1 /**CFile**************************************************************** 2 3 FileName [ivyMem.c] 4 5 SystemName [ABC: Logic synthesis and verification system.] 6 7 PackageName [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: ivyMem.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $] 18 19 ***********************************************************************/ 20 21 #include "ivy.h" 22 23 ABC_NAMESPACE_IMPL_START 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 ***********************************************************************/ Ivy_ManStartMemory(Ivy_Man_t * p)49void Ivy_ManStartMemory( Ivy_Man_t * p ) 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 ***********************************************************************/ Ivy_ManStopMemory(Ivy_Man_t * p)66void Ivy_ManStopMemory( Ivy_Man_t * p ) 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 ***********************************************************************/ Ivy_ManAddMemory(Ivy_Man_t * p)89void Ivy_ManAddMemory( Ivy_Man_t * p ) 90 { 91 char * pMemory; 92 int i, nBytes; 93 int EntrySizeMax = 128; 94 assert( sizeof(Ivy_Obj_t) <= EntrySizeMax ); 95 assert( p->pListFree == NULL ); 96 // assert( (Ivy_ManObjNum(p) & IVY_PAGE_MASK) == 0 ); 97 // allocate new memory page 98 nBytes = sizeof(Ivy_Obj_t) * (1<<IVY_PAGE_SIZE) + EntrySizeMax; 99 pMemory = ABC_ALLOC( char, nBytes ); 100 Vec_PtrPush( p->vChunks, pMemory ); 101 // align memory at the 32-byte boundary 102 pMemory = pMemory + EntrySizeMax - (((int)(ABC_PTRUINT_T)pMemory) & (EntrySizeMax-1)); 103 // remember the manager in the first entry 104 Vec_PtrPush( p->vPages, pMemory ); 105 // break the memory down into nodes 106 p->pListFree = (Ivy_Obj_t *)pMemory; 107 for ( i = 1; i <= IVY_PAGE_MASK; i++ ) 108 { 109 *((char **)pMemory) = pMemory + sizeof(Ivy_Obj_t); 110 pMemory += sizeof(Ivy_Obj_t); 111 } 112 *((char **)pMemory) = NULL; 113 } 114 115 //////////////////////////////////////////////////////////////////////// 116 /// END OF FILE /// 117 //////////////////////////////////////////////////////////////////////// 118 119 120 ABC_NAMESPACE_IMPL_END 121 122