ivyMem.c 3.56 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [ivyMem.c]
Alan Mishchenko committed
4 5 6

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [And-Inverter Graph package.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16

  Synopsis    [Memory management for the AIG nodes.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - May 11, 2006.]

Alan Mishchenko committed
17
  Revision    [$Id: ivyMem.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20

***********************************************************************/

Alan Mishchenko committed
21
#include "ivy.h"
Alan Mishchenko committed
22

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

// memory management
#define IVY_PAGE_SIZE      12        // page size containing 2^IVY_PAGE_SIZE nodes
#define IVY_PAGE_MASK    4095        // page bitmask (2^IVY_PAGE_SIZE)-1

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Starts the internal memory manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
49
void Ivy_ManStartMemory( Ivy_Man_t * p )
Alan Mishchenko committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
{
    p->vChunks = Vec_PtrAlloc( 128 );
    p->vPages = Vec_PtrAlloc( 128 );
}

/**Function*************************************************************

  Synopsis    [Stops the internal memory manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
66
void Ivy_ManStopMemory( Ivy_Man_t * p )
Alan Mishchenko committed
67 68 69
{
    void * pMemory;
    int i;
70
    Vec_PtrForEachEntry( void *, p->vChunks, pMemory, i )
Alan Mishchenko committed
71
        ABC_FREE( pMemory );
Alan Mishchenko committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    Vec_PtrFree( p->vChunks );
    Vec_PtrFree( p->vPages );
    p->pListFree = NULL;
}

/**Function*************************************************************

  Synopsis    [Allocates additional memory for the nodes.]

  Description [Allocates IVY_PAGE_SIZE nodes. Aligns memory by 32 bytes. 
  Records the pointer to the AIG manager in the -1 entry.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
89
void Ivy_ManAddMemory( Ivy_Man_t * p )
Alan Mishchenko committed
90 91 92
{
    char * pMemory;
    int i, nBytes;
Alan Mishchenko committed
93 94
    int EntrySizeMax = 128;
    assert( sizeof(Ivy_Obj_t) <= EntrySizeMax );
Alan Mishchenko committed
95
    assert( p->pListFree == NULL );
Alan Mishchenko committed
96
//    assert( (Ivy_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
Alan Mishchenko committed
97
    // allocate new memory page
Alan Mishchenko committed
98
    nBytes = sizeof(Ivy_Obj_t) * (1<<IVY_PAGE_SIZE) + EntrySizeMax;
Alan Mishchenko committed
99
    pMemory = ABC_ALLOC( char, nBytes );
Alan Mishchenko committed
100 101
    Vec_PtrPush( p->vChunks, pMemory );
    // align memory at the 32-byte boundary
Alan Mishchenko committed
102
    pMemory = pMemory + EntrySizeMax - (((int)(ABC_PTRUINT_T)pMemory) & (EntrySizeMax-1));
Alan Mishchenko committed
103 104 105
    // remember the manager in the first entry
    Vec_PtrPush( p->vPages, pMemory );
    // break the memory down into nodes
Alan Mishchenko committed
106
    p->pListFree = (Ivy_Obj_t *)pMemory;
Alan Mishchenko committed
107 108
    for ( i = 1; i <= IVY_PAGE_MASK; i++ )
    {
Alan Mishchenko committed
109 110
        *((char **)pMemory) = pMemory + sizeof(Ivy_Obj_t);
        pMemory += sizeof(Ivy_Obj_t);
Alan Mishchenko committed
111 112 113 114 115 116 117 118 119
    }
    *((char **)pMemory) = NULL;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


120 121
ABC_NAMESPACE_IMPL_END