blob: 79de38048e7b062f6c1f5bc845f853c9df5a423a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/**CFile****************************************************************
FileName [hopMem.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Minimalistic And-Inverter Graph package.]
Synopsis [Memory management for the AIG nodes.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - May 11, 2006.]
Revision [$Id: hopMem.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
***********************************************************************/
#include "hop.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// 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 []
***********************************************************************/
void Hop_ManStartMemory( Hop_Man_t * p )
{
p->vChunks = Vec_PtrAlloc( 128 );
p->vPages = Vec_PtrAlloc( 128 );
}
/**Function*************************************************************
Synopsis [Stops the internal memory manager.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ManStopMemory( Hop_Man_t * p )
{
void * pMemory;
int i;
Vec_PtrForEachEntry( void *, p->vChunks, pMemory, i )
ABC_FREE( pMemory );
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 []
***********************************************************************/
void Hop_ManAddMemory( Hop_Man_t * p )
{
char * pMemory;
int i, nBytes;
assert( sizeof(Hop_Obj_t) <= 64 );
assert( p->pListFree == NULL );
// assert( (Hop_ManObjNum(p) & IVY_PAGE_MASK) == 0 );
// allocate new memory page
nBytes = sizeof(Hop_Obj_t) * (1<<IVY_PAGE_SIZE) + 64;
pMemory = ABC_ALLOC( char, nBytes );
Vec_PtrPush( p->vChunks, pMemory );
// align memory at the 32-byte boundary
pMemory = pMemory + 64 - (((int)(ABC_PTRUINT_T)pMemory) & 63);
// remember the manager in the first entry
Vec_PtrPush( p->vPages, pMemory );
// break the memory down into nodes
p->pListFree = (Hop_Obj_t *)pMemory;
for ( i = 1; i <= IVY_PAGE_MASK; i++ )
{
*((char **)pMemory) = pMemory + sizeof(Hop_Obj_t);
pMemory += sizeof(Hop_Obj_t);
}
*((char **)pMemory) = NULL;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|