ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
exorCubes.c
Go to the documentation of this file.
1
20
42
43#include "exor.h"
44
46
50
54
55// information about the cube cover before and after simplification
56extern cinfo g_CoverInfo;
57
61
62// cube cover memory allocation/delocation procedures
63// (called from the ExorMain module)
64int AllocateCover( int nCubes, int nWordsIn, int nWordsOut );
65void DelocateCover();
66
67// manipulation of the free cube list
68// (called from Pseudo-Kronecker, ExorList, and ExorLink modules)
69void AddToFreeCubes( Cube * pC );
71
75
79
80// the pointer to the allocated memory
82
83// the list of free cubes
85
89
90int AllocateCover( int nCubes, int nWordsIn, int nWordsOut )
91// uses the cover parameters nCubes and nWords
92// to allocate-and-clean the cover in one large piece
93{
94 int OneCubeSize;
95 int OneInputSetSize;
96 Cube ** pp;
97 int TotalSize;
98 int i, k;
99
100 // determine the size of one cube WITH storage for bits
101 OneCubeSize = sizeof(Cube) + (nWordsIn+nWordsOut)*sizeof(unsigned);
102 // determine what is the amount of storage for the input part of the cube
103 OneInputSetSize = nWordsIn*sizeof(unsigned);
104
105 // allocate memory for the array of pointers
106 pp = (Cube **)ABC_ALLOC( Cube *, nCubes );
107 if ( pp == NULL )
108 return 0;
109
110 // determine the size of the total cube cover
111 TotalSize = nCubes*OneCubeSize;
112 // allocate and clear memory for the cover in one large piece
113 pp[0] = (Cube *)ABC_ALLOC( char, TotalSize );
114 if ( pp[0] == NULL )
115 return 0;
116 memset( pp[0], 0, (size_t)TotalSize );
117
118 // assign pointers to cubes and bit strings inside this piece
119 pp[0]->pCubeDataIn = (unsigned*)(pp[0] + 1);
120 pp[0]->pCubeDataOut = (unsigned*)((char*)pp[0]->pCubeDataIn + OneInputSetSize);
121 for ( i = 1; i < nCubes; i++ )
122 {
123 pp[i] = (Cube *)((char*)pp[i-1] + OneCubeSize);
124 pp[i]->pCubeDataIn = (unsigned*)(pp[i] + 1);
125 pp[i]->pCubeDataOut = (unsigned*)((char*)pp[i]->pCubeDataIn + OneInputSetSize);
126 }
127
128 // connect the cubes into the list using Next pointers
129 for ( k = 0; k < nCubes-1; k++ )
130 pp[k]->Next = pp[k+1];
131 // the last pointer is already set to NULL
132
133 // assign the head of the free list
134 s_CubesFree = pp[0];
135 // set the counters of the used and free cubes
136 g_CoverInfo.nCubesInUse = 0;
137 g_CoverInfo.nCubesFree = nCubes;
138
139 // save the pointer to the allocated memory
140 s_pCoverMemory = pp;
141
142 assert ( g_CoverInfo.nCubesInUse + g_CoverInfo.nCubesFree == g_CoverInfo.nCubesAlloc );
143
144 return nCubes*sizeof(Cube *) + TotalSize;
145}
146
148{
151}
152
156
158{
159 assert( p );
160 assert( p->Prev == NULL ); // the cube should not be in use
161 assert( p->Next == NULL );
162 assert( p->ID );
163
164 p->Next = s_CubesFree;
165 s_CubesFree = p;
166
167 // set the ID of the cube to 0,
168 // so that cube pair garbage collection could recognize it as different
169 p->ID = 0;
170
171 g_CoverInfo.nCubesFree++;
172}
173
175{
176 Cube * p;
178 p = s_CubesFree;
179 s_CubesFree = s_CubesFree->Next;
180 p->Next = NULL;
181 g_CoverInfo.nCubesFree--;
182 return p;
183}
184
188
189
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void AddToFreeCubes(Cube *pC)
FREE CUBE LIST MANIPULATION FUNCTIONS ///.
Definition exorCubes.c:157
int AllocateCover(int nCubes, int nWordsIn, int nWordsOut)
FUNCTIONS OF THIS MODULE ///.
Definition exorCubes.c:90
Cube * GetFreeCube()
Definition exorCubes.c:174
void DelocateCover()
Definition exorCubes.c:147
Cube ** s_pCoverMemory
EXPORTED VARIABLES ///.
Definition exorCubes.c:81
Cube * s_CubesFree
Definition exorCubes.c:84
Cube * p
Definition exorList.c:222
ABC_NAMESPACE_IMPL_START cinfo g_CoverInfo
GLOBAL VARIABLES ///.
Definition exor.c:58
struct cube Cube
struct cinfo_tag cinfo
drow * pCubeDataOut
Definition exor.h:130
drow * pCubeDataIn
Definition exor.h:129
#define assert(ex)
Definition util_old.h:213
char * memset()