abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cloud.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cloud.h]
4 
5  PackageName [Fast application-specific BDD package.]
6 
7  Synopsis [Interface of the package.]
8 
9  Author [Alan Mishchenko <alanmi@ece.pdx.edu>]
10 
11  Affiliation [ECE Department. Portland State University, Portland, Oregon.]
12 
13  Date [Ver. 1.0. Started - June 10, 2002.]
14 
15  Revision [$Id: cloud.h,v 1.0 2002/06/10 03:00:00 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #ifndef ABC__aig__kit__cloud_h
20 #define ABC__aig__kit__cloud_h
21 
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <assert.h>
26 
27 #include "misc/util/abc_global.h"
28 
29 
30 
32 
33 
34 #ifdef _WIN32
35 #define inline __inline // compatible with MS VS 6.0
36 #endif
37 
38 ////////////////////////////////////////////////////////////////////////
39 // n | 2^n || n | 2^n || n | 2^n || n | 2^n //
40 //====================================================================//
41 // 1 | 2 || 9 | 512 || 17 | 131,072 || 25 | 33,554,432 //
42 // 2 | 4 || 10 | 1,024 || 18 | 262,144 || 26 | 67,108,864 //
43 // 3 | 8 || 11 | 2,048 || 19 | 524,288 || 27 | 134,217,728 //
44 // 4 | 16 || 12 | 4,096 || 20 | 1,048,576 || 28 | 268,435,456 //
45 // 5 | 32 || 13 | 8,192 || 21 | 2,097,152 || 29 | 536,870,912 //
46 // 6 | 64 || 14 | 16,384 || 22 | 4,194,304 || 30 | 1,073,741,824 //
47 // 7 | 128 || 15 | 32,768 || 23 | 8,388,608 || 31 | 2,147,483,648 //
48 // 8 | 256 || 16 | 65,536 || 24 | 16,777,216 || 32 | 4,294,967,296 //
49 ////////////////////////////////////////////////////////////////////////
50 
51 // data structure typedefs
52 typedef struct cloudManager CloudManager;
53 typedef unsigned CloudVar;
54 typedef unsigned CloudSign;
55 typedef struct cloudNode CloudNode;
59 
60 // operation codes used to set up the cache
61 typedef enum {
66 } CloudOper;
67 
68 /*
69 // the number of operators using cache
70 static int CacheOperNum = 4;
71 
72 // the ratio of cache size to the unique table size for each operator
73 static int CacheLogRatioDefault[4] = {
74  4, // CLOUD_OPER_AND,
75  8, // CLOUD_OPER_XOR,
76  8, // CLOUD_OPER_BDIFF,
77  8 // CLOUD_OPER_LEQ
78 };
79 
80 // the ratio of cache size to the unique table size for each operator
81 static int CacheSize[4] = {
82  2, // CLOUD_OPER_AND,
83  2, // CLOUD_OPER_XOR,
84  2, // CLOUD_OPER_BDIFF,
85  2 // CLOUD_OPER_LEQ
86 };
87 */
88 
89 // data structure definitions
90 struct cloudManager // the fast bdd manager
91 {
92  // variables
93  int nVars; // the number of variables allocated
94  // bits
95  int bitsNode; // the number of bits used for the node
96  int bitsCache[4]; // default: bitsNode - CacheSizeRatio[i]
97  // shifts
98  int shiftUnique; // 8*sizeof(unsigned) - (bitsNode + 1)
99  int shiftCache[4]; // 8*sizeof(unsigned) - bitsCache[i]
100  // nodes
101  int nNodesAlloc; // 2 ^ (bitsNode + 1)
102  int nNodesLimit; // 2 ^ bitsNode
103  int nNodesCur; // the current number of nodes (including const1 and vars)
104  // signature
106 
107  // statistics
108  int nMemUsed; // memory usage in bytes
109  // cache stats
110  int nUniqueHits; // hits in the unique table
111  int nUniqueMisses; // misses in the unique table
112  int nCacheHits; // hits in the caches
113  int nCacheMisses; // misses in the caches
114  // the number of steps through the hash table
116 
117  // tables
118  CloudNode * tUnique; // the unique table to store BDD nodes
119 
120  // special nodes
121  CloudNode * pNodeStart; // the pointer to the first node
122  CloudNode * pNodeEnd; // the pointer to the first node out of the table
123 
124  // constants and variables
125  CloudNode * one; // the one function
126  CloudNode * zero; // the zero function
127  CloudNode ** vars; // the elementary variables
128 
129  // temporary storage for nodes
131 
132  // caches
133  CloudCacheEntry2 * tCaches[20]; // caches
134 };
135 
136 struct cloudNode // representation of the node in the unique table
137 {
138  CloudSign s; // signature
139  CloudVar v; // variable
140  CloudNode * e; // negative cofactor
141  CloudNode * t; // positive cofactor
142 };
143 struct cloudCacheEntry1 // one-argument cache
144 {
145  CloudSign s; // signature
146  CloudNode * a; // argument 1
147  CloudNode * r; // result
148 };
149 struct cloudCacheEntry2 // the two-argument cache
150 {
151  CloudSign s; // signature
155 };
156 struct cloudCacheEntry3 // the three-argument cache
157 {
158  CloudSign s; // signature
163 };
164 
165 
166 // parameters
167 #define CLOUD_NODE_BITS 23
168 
169 #define CLOUD_CONST_INDEX ((unsigned)0x0fffffff)
170 #define CLOUD_MARK_ON ((unsigned)0x10000000)
171 #define CLOUD_MARK_OFF ((unsigned)0xefffffff)
172 
173 // hash functions a la Buddy
174 #define cloudHashBuddy2(x,y,s) ((((x)+(y))*((x)+(y)+1)/2) & ((1<<(32-(s)))-1))
175 #define cloudHashBuddy3(x,y,z,s) (cloudHashBuddy2((cloudHashBuddy2((x),(y),(s))),(z),(s)) & ((1<<(32-(s)))-1))
176 // hash functions a la Cudd
177 #define DD_P1 12582917
178 #define DD_P2 4256249
179 #define DD_P3 741457
180 #define DD_P4 1618033999
181 #define cloudHashCudd2(f,g,s) ((((unsigned)(ABC_PTRUINT_T)(f) * DD_P1 + (unsigned)(ABC_PTRUINT_T)(g)) * DD_P2) >> (s))
182 #define cloudHashCudd3(f,g,h,s) (((((unsigned)(ABC_PTRUINT_T)(f) * DD_P1 + (unsigned)(ABC_PTRUINT_T)(g)) * DD_P2 + (unsigned)(ABC_PTRUINT_T)(h)) * DD_P3) >> (s))
183 
184 // node complementation (using node)
185 #define Cloud_Regular(p) ((CloudNode*)(((ABC_PTRUINT_T)(p)) & ~01)) // get the regular node (w/o bubble)
186 #define Cloud_Not(p) ((CloudNode*)(((ABC_PTRUINT_T)(p)) ^ 01)) // complement the node
187 #define Cloud_NotCond(p,c) ((CloudNode*)(((ABC_PTRUINT_T)(p)) ^ (c))) // complement the node conditionally
188 #define Cloud_IsComplement(p) ((int)(((ABC_PTRUINT_T)(p)) & 01)) // check if complemented
189 // checking constants (using node)
190 #define Cloud_IsConstant(p) (((Cloud_Regular(p))->v & CLOUD_MARK_OFF) == CLOUD_CONST_INDEX)
191 #define cloudIsConstant(p) (((p)->v & CLOUD_MARK_OFF) == CLOUD_CONST_INDEX)
192 
193 // retrieving values from the node (using node structure)
194 #define Cloud_V(p) ((Cloud_Regular(p))->v)
195 #define Cloud_E(p) ((Cloud_Regular(p))->e)
196 #define Cloud_T(p) ((Cloud_Regular(p))->t)
197 // retrieving values from the regular node (using node structure)
198 #define cloudV(p) ((p)->v)
199 #define cloudE(p) ((p)->e)
200 #define cloudT(p) ((p)->t)
201 // marking/unmarking (using node structure)
202 #define cloudNodeMark(p) ((p)->v |= CLOUD_MARK_ON)
203 #define cloudNodeUnmark(p) ((p)->v &= CLOUD_MARK_OFF)
204 #define cloudNodeIsMarked(p) ((int)((p)->v & CLOUD_MARK_ON))
205 
206 // cache lookups and inserts (using node)
207 #define cloudCacheLookup1(p,sign,f) (((p)->s == (sign) && (p)->a == (f))? ((p)->r): (0))
208 #define cloudCacheLookup2(p,sign,f,g) (((p)->s == (sign) && (p)->a == (f) && (p)->b == (g))? ((p)->r): (0))
209 #define cloudCacheLookup3(p,sign,f,g,h) (((p)->s == (sign) && (p)->a == (f) && (p)->b == (g) && (p)->c == (h))? ((p)->r): (0))
210 // cache inserts
211 #define cloudCacheInsert1(p,sign,f,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->r = (r)))
212 #define cloudCacheInsert2(p,sign,f,g,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->b = (g)), ((p)->r = (r)))
213 #define cloudCacheInsert3(p,sign,f,g,h,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->b = (g)), ((p)->c = (h)), ((p)->r = (r)))
214 
215 //#define CLOUD_ASSERT(p) (assert((p) >= (dd->pNodeStart-1) && (p) < dd->pNodeEnd))
216 #define CLOUD_ASSERT(p) assert((p) >= dd->tUnique && (p) < dd->tUnique+dd->nNodesAlloc)
217 
218 ////////////////////////////////////////////////////////////////////////
219 /// FUNCTION DECLARATIONS ///
220 ////////////////////////////////////////////////////////////////////////
221 // starting/stopping
222 extern CloudManager * Cloud_Init( int nVars, int nBits );
223 extern void Cloud_Quit( CloudManager * dd );
224 extern void Cloud_Restart( CloudManager * dd );
225 extern void Cloud_CacheAllocate( CloudManager * dd, CloudOper oper, int size );
226 extern CloudNode * Cloud_MakeNode( CloudManager * dd, CloudVar v, CloudNode * t, CloudNode * e );
227 // support and node count
228 extern CloudNode * Cloud_Support( CloudManager * dd, CloudNode * n );
229 extern int Cloud_SupportSize( CloudManager * dd, CloudNode * n );
230 extern int Cloud_DagSize( CloudManager * dd, CloudNode * n );
231 extern int Cloud_DagCollect( CloudManager * dd, CloudNode * n );
232 extern int Cloud_SharingSize( CloudManager * dd, CloudNode * * pn, int nn );
233 // cubes
234 extern CloudNode * Cloud_GetOneCube( CloudManager * dd, CloudNode * n );
235 extern void Cloud_bddPrint( CloudManager * dd, CloudNode * Func );
236 extern void Cloud_bddPrintCube( CloudManager * dd, CloudNode * Cube );
237 // operations
238 extern CloudNode * Cloud_bddAnd( CloudManager * dd, CloudNode * f, CloudNode * g );
239 extern CloudNode * Cloud_bddOr( CloudManager * dd, CloudNode * f, CloudNode * g );
240 // stats
241 extern void Cloud_PrintInfo( CloudManager * dd );
242 extern void Cloud_PrintHashTable( CloudManager * dd );
243 
244 
245 
247 
248 
249 
250 #endif
251 
252 ////////////////////////////////////////////////////////////////////////
253 /// END OF FILE ///
254 ////////////////////////////////////////////////////////////////////////
int nMemUsed
Definition: cloud.h:108
unsigned CloudVar
Definition: cloud.h:53
int nNodesLimit
Definition: cloud.h:102
CloudNode * c
Definition: cloud.h:161
CloudSign s
Definition: cloud.h:151
typedefABC_NAMESPACE_HEADER_START struct cloudManager CloudManager
Definition: cloud.h:52
CloudNode * Cloud_Support(CloudManager *dd, CloudNode *n)
Definition: cloud.c:618
CloudVar v
Definition: cloud.h:139
CloudNode * Cloud_bddAnd(CloudManager *dd, CloudNode *f, CloudNode *g)
Definition: cloud.c:489
CloudNode * pNodeEnd
Definition: cloud.h:122
CloudNode * pNodeStart
Definition: cloud.h:121
int nNodesAlloc
Definition: cloud.h:101
CloudNode * tUnique
Definition: cloud.h:118
CloudNode * e
Definition: cloud.h:140
CloudNode * r
Definition: cloud.h:162
CloudNode * a
Definition: cloud.h:152
CloudOper
Definition: cloud.h:61
void Cloud_bddPrint(CloudManager *dd, CloudNode *Func)
Definition: cloud.c:866
CloudCacheEntry2 * tCaches[20]
Definition: cloud.h:133
CloudNode * one
Definition: cloud.h:125
int shiftUnique
Definition: cloud.h:98
CloudManager * Cloud_Init(int nVars, int nBits)
FUNCTION DECLARATIONS ///.
Definition: cloud.c:70
int nCacheMisses
Definition: cloud.h:113
void Cloud_PrintHashTable(CloudManager *dd)
Definition: cloud.c:975
int Cloud_DagSize(CloudManager *dd, CloudNode *n)
Definition: cloud.c:721
int bitsCache[4]
Definition: cloud.h:96
int nUniqueMisses
Definition: cloud.h:111
CloudSign s
Definition: cloud.h:145
CloudSign s
Definition: cloud.h:138
int Cloud_SupportSize(CloudManager *dd, CloudNode *n)
Definition: cloud.c:658
CloudNode * b
Definition: cloud.h:153
CloudNode * a
Definition: cloud.h:146
int shiftCache[4]
Definition: cloud.h:99
void Cloud_bddPrintCube(CloudManager *dd, CloudNode *Cube)
Definition: cloud.c:900
CloudNode ** vars
Definition: cloud.h:127
void Cloud_Restart(CloudManager *dd)
Definition: cloud.c:166
CloudNode * zero
Definition: cloud.h:126
CloudNode * r
Definition: cloud.h:154
static int size
Definition: cuddSign.c:86
int nUniqueSteps
Definition: cloud.h:115
CloudNode ** ppNodes
Definition: cloud.h:130
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
CloudNode * t
Definition: cloud.h:141
void Cloud_Quit(CloudManager *dd)
Definition: cloud.c:144
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
CloudNode * b
Definition: cloud.h:160
int nNodesCur
Definition: cloud.h:103
unsigned CloudSign
Definition: cloud.h:54
int Cloud_DagCollect(CloudManager *dd, CloudNode *n)
Definition: cloud.c:772
CloudSign s
Definition: cloud.h:158
void Cloud_CacheAllocate(CloudManager *dd, CloudOper oper, int size)
Definition: cloud.c:195
CloudNode * r
Definition: cloud.h:147
int nVars
Definition: cloud.h:93
CloudNode * Cloud_MakeNode(CloudManager *dd, CloudVar v, CloudNode *t, CloudNode *e)
Definition: cloud.c:254
CloudNode * Cloud_bddOr(CloudManager *dd, CloudNode *f, CloudNode *g)
Definition: cloud.c:511
int nUniqueHits
Definition: cloud.h:110
int bitsNode
Definition: cloud.h:95
void Cloud_PrintInfo(CloudManager *dd)
Definition: cloud.c:950
int nCacheHits
Definition: cloud.h:112
CloudNode * Cloud_GetOneCube(CloudManager *dd, CloudNode *n)
Definition: cloud.c:817
CloudSign nSignCur
Definition: cloud.h:105
int Cloud_SharingSize(CloudManager *dd, CloudNode **pn, int nn)
Definition: cloud.c:796
CloudNode * a
Definition: cloud.h:159