ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
vecSet.h
Go to the documentation of this file.
1
20
21#ifndef ABC__sat__bsat__vecSet_h
22#define ABC__sat__bsat__vecSet_h
23
24
28
29#include <stdio.h>
30
32
33
37
41
42// data-structure for logging entries
43// memory is allocated in 2^nPageSize word-sized pages
44// the first two 'words' of each page are used for bookkeeping
45// the first 'word' of bookkeeping data stores the word limit
46// the second 'word' of bookkeeping data stores the shadow word limit
47// (the shadow word limit is only used during garbage collection)
48
49typedef struct Vec_Set_t_ Vec_Set_t;
51{
52 int nPageSize; // page size
53 unsigned uPageMask; // page mask
54 int nEntries; // entry count
55 int iPage; // current page
56 int iPageS; // shadow page
57 int nPagesAlloc; // page count allocated
58 word ** pPages; // page pointers
59};
60
64
65static inline int Vec_SetHandPage( Vec_Set_t * p, int h ) { return h >> p->nPageSize; }
66static inline int Vec_SetHandShift( Vec_Set_t * p, int h ) { return h & p->uPageMask; }
67static inline int Vec_SetWordNum( int nSize ) { return (nSize + 1) >> 1; }
68
69//static inline word * Vec_SetEntry( Vec_Set_t * p, int h ) { assert(Vec_SetHandPage(p, h) >= 0 && Vec_SetHandPage(p, h) <= p->iPage); assert(Vec_SetHandShift(p, h) >= 2 && Vec_SetHandShift(p, h) < (1 << p->nPageSize)); return p->pPages[Vec_SetHandPage(p, h)] + Vec_SetHandShift(p, h); }
70static inline word * Vec_SetEntry( Vec_Set_t * p, int h ) { return p->pPages[Vec_SetHandPage(p, h)] + Vec_SetHandShift(p, h); }
71static inline int Vec_SetEntryNum( Vec_Set_t * p ) { return p->nEntries; }
72static inline void Vec_SetWriteEntryNum( Vec_Set_t * p, int i){ p->nEntries = i; }
73
74static inline int Vec_SetLimit( word * p ) { return p[0]; }
75static inline int Vec_SetLimitS( word * p ) { return p[1]; }
76
77static inline int Vec_SetIncLimit( word * p, int nWords ) { return p[0] += nWords; }
78static inline int Vec_SetIncLimitS( word * p, int nWords ) { return p[1] += nWords; }
79
80static inline void Vec_SetWriteLimit( word * p, int nWords ) { p[0] = nWords; }
81static inline void Vec_SetWriteLimitS( word * p, int nWords ) { p[1] = nWords; }
82
83static inline int Vec_SetHandCurrent( Vec_Set_t * p ) { return (p->iPage << p->nPageSize) + Vec_SetLimit(p->pPages[p->iPage]); }
84static inline int Vec_SetHandCurrentS( Vec_Set_t * p ) { return (p->iPageS << p->nPageSize) + Vec_SetLimitS(p->pPages[p->iPageS]); }
85
86static inline int Vec_SetHandMemory( Vec_Set_t * p, int h ) { return Vec_SetHandPage(p, h) * (1 << (p->nPageSize+3)) + Vec_SetHandShift(p, h) * 8; }
87static inline int Vec_SetMemory( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrent(p)); }
88static inline int Vec_SetMemoryS( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrentS(p)); }
89static inline int Vec_SetMemoryAll( Vec_Set_t * p ) { return (p->iPage+1) * (1 << (p->nPageSize+3)); }
90
91// Type is the Set type
92// pVec is vector of set
93// nSize should be given by the user
94// pSet is the pointer to the set
95// p (page) and s (shift) are variables used here
96#define Vec_SetForEachEntry( Type, pVec, nSize, pSet, p, s ) \
97 for ( p = 0; p <= pVec->iPage; p++ ) \
98 for ( s = 2; s < Vec_SetLimit(pVec->pPages[p]) && ((pSet) = (Type)(pVec->pPages[p] + (s))); s += nSize )
99
103
115static inline void Vec_SetAlloc_( Vec_Set_t * p, int nPageSize )
116{
117 assert( nPageSize > 8 );
118 memset( p, 0, sizeof(Vec_Set_t) );
119 p->nPageSize = nPageSize;
120 p->uPageMask = (unsigned)((1 << nPageSize) - 1);
121 p->nPagesAlloc = 256;
122 p->pPages = ABC_CALLOC( word *, p->nPagesAlloc );
123 p->pPages[0] = ABC_ALLOC( word, (int)(((word)1) << p->nPageSize) );
124 p->pPages[0][0] = ~0;
125 p->pPages[0][1] = ~0;
126 Vec_SetWriteLimit( p->pPages[0], 2 );
127}
128static inline Vec_Set_t * Vec_SetAlloc( int nPageSize )
129{
130 Vec_Set_t * p;
131 p = ABC_CALLOC( Vec_Set_t, 1 );
132 Vec_SetAlloc_( p, nPageSize );
133 return p;
134}
135
147static inline void Vec_SetRestart( Vec_Set_t * p )
148{
149 p->nEntries = 0;
150 p->iPage = 0;
151 p->iPageS = 0;
152 p->pPages[0][0] = ~0;
153 p->pPages[0][1] = ~0;
154 Vec_SetWriteLimit( p->pPages[0], 2 );
155}
156
168static inline void Vec_SetFree_( Vec_Set_t * p )
169{
170 int i;
171 if ( p == NULL ) return;
172 for ( i = 0; i < p->nPagesAlloc; i++ )
173 ABC_FREE( p->pPages[i] );
174 ABC_FREE( p->pPages );
175}
176static inline void Vec_SetFree( Vec_Set_t * p )
177{
178 if ( p == NULL ) return;
179 Vec_SetFree_( p );
180 ABC_FREE( p );
181}
182
194static inline double Vec_ReportMemory( Vec_Set_t * p )
195{
196 double Mem = sizeof(Vec_Set_t);
197 Mem += p->nPagesAlloc * sizeof(void *);
198 Mem += sizeof(word) * (size_t)(((word)1) << p->nPageSize) * (size_t)(1 + p->iPage);
199 return Mem;
200}
201
213static inline int Vec_SetAppend( Vec_Set_t * p, int * pArray, int nSize )
214{
215 int nWords = Vec_SetWordNum( nSize );
216 assert( nWords < (1 << p->nPageSize) );
217 p->nEntries++;
218 if ( Vec_SetLimit( p->pPages[p->iPage] ) + nWords >= (1 << p->nPageSize) )
219 {
220 if ( ++p->iPage == p->nPagesAlloc )
221 {
222 p->pPages = ABC_REALLOC( word *, p->pPages, p->nPagesAlloc * 2 );
223 memset( p->pPages + p->nPagesAlloc, 0, sizeof(word *) * (size_t)p->nPagesAlloc );
224 p->nPagesAlloc *= 2;
225 }
226 if ( p->pPages[p->iPage] == NULL )
227 p->pPages[p->iPage] = ABC_ALLOC( word, (int)(((word)1) << p->nPageSize) );
228 Vec_SetWriteLimit( p->pPages[p->iPage], 2 );
229 p->pPages[p->iPage][1] = ~0;
230 }
231 if ( pArray )
232 memcpy( p->pPages[p->iPage] + Vec_SetLimit(p->pPages[p->iPage]), pArray, sizeof(int) * (size_t)nSize );
233 Vec_SetIncLimit( p->pPages[p->iPage], nWords );
234 return Vec_SetHandCurrent(p) - nWords;
235}
236static inline int Vec_SetAppendS( Vec_Set_t * p, int nSize )
237{
238 int nWords = Vec_SetWordNum( nSize );
239 assert( nWords < (1 << p->nPageSize) );
240 if ( Vec_SetLimitS( p->pPages[p->iPageS] ) + nWords >= (1 << p->nPageSize) )
241 Vec_SetWriteLimitS( p->pPages[++p->iPageS], 2 );
242 Vec_SetIncLimitS( p->pPages[p->iPageS], nWords );
243 return Vec_SetHandCurrentS(p) - nWords;
244}
245static inline int Vec_SetFetchH( Vec_Set_t * p, int nBytes )
246{
247 return Vec_SetAppend(p, NULL, (nBytes + 3) >> 2);
248}
249static inline void * Vec_SetFetch( Vec_Set_t * p, int nBytes )
250{
251 return (void *)Vec_SetEntry( p, Vec_SetFetchH(p, nBytes) );
252}
253static inline char * Vec_SetStrsav( Vec_Set_t * p, char * pName )
254{
255 char * pStr = (char *)Vec_SetFetch( p, (int)strlen(pName) + 1 );
256 strcpy( pStr, pName );
257 return pStr;
258}
259
271static inline void Vec_SetShrink( Vec_Set_t * p, int h )
272{
273 assert( h <= Vec_SetHandCurrent(p) );
274 p->iPage = Vec_SetHandPage(p, h);
275 Vec_SetWriteLimit( p->pPages[p->iPage], Vec_SetHandShift(p, h) );
276}
277static inline void Vec_SetShrinkS( Vec_Set_t * p, int h )
278{
279 assert( h <= Vec_SetHandCurrent(p) );
280 p->iPageS = Vec_SetHandPage(p, h);
281 Vec_SetWriteLimitS( p->pPages[p->iPageS], Vec_SetHandShift(p, h) );
282}
283
284static inline void Vec_SetShrinkLimits( Vec_Set_t * p )
285{
286 int i;
287 for ( i = 0; i <= p->iPage; i++ )
288 Vec_SetWriteLimit( p->pPages[i], Vec_SetLimitS(p->pPages[i]) );
289}
290
291
293
294#endif
295
299
int nWords
Definition abcNpn.c:127
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Cube * p
Definition exorList.c:222
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int nPagesAlloc
Definition vecSet.h:57
int nPageSize
Definition vecSet.h:52
int iPageS
Definition vecSet.h:56
word ** pPages
Definition vecSet.h:58
int nEntries
Definition vecSet.h:54
int iPage
Definition vecSet.h:55
unsigned uPageMask
Definition vecSet.h:53
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * memset()
int strlen()
char * strcpy()
typedefABC_NAMESPACE_HEADER_START struct Vec_Set_t_ Vec_Set_t
INCLUDES ///.
Definition vecSet.h:49