ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cloud.h
Go to the documentation of this file.
1
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
28
29
30
32
33
34#ifdef _WIN32
35#define inline __inline // compatible with MS VS 6.0
36#endif
37
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 //
50
51// data structure typedefs
53typedef unsigned CloudVar;
54typedef unsigned CloudSign;
55typedef struct cloudNode CloudNode;
59
60// operation codes used to set up the cache
67
68/*
69// the number of operators using cache
70static int CacheOperNum = 4;
71
72// the ratio of cache size to the unique table size for each operator
73static 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
81static 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
90struct 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
136struct 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};
143struct cloudCacheEntry1 // one-argument cache
144{
145 CloudSign s; // signature
146 CloudNode * a; // argument 1
147 CloudNode * r; // result
148};
149struct cloudCacheEntry2 // the two-argument cache
150{
151 CloudSign s; // signature
155};
156struct 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
221// starting/stopping
222extern CloudManager * Cloud_Init( int nVars, int nBits );
223extern void Cloud_Quit( CloudManager * dd );
224extern void Cloud_Restart( CloudManager * dd );
225extern void Cloud_CacheAllocate( CloudManager * dd, CloudOper oper, int size );
227// support and node count
228extern CloudNode * Cloud_Support( CloudManager * dd, CloudNode * n );
229extern int Cloud_SupportSize( CloudManager * dd, CloudNode * n );
230extern int Cloud_DagSize( CloudManager * dd, CloudNode * n );
231extern int Cloud_DagCollect( CloudManager * dd, CloudNode * n );
232extern int Cloud_SharingSize( CloudManager * dd, CloudNode * * pn, int nn );
233// cubes
235extern void Cloud_bddPrint( CloudManager * dd, CloudNode * Func );
236extern void Cloud_bddPrintCube( CloudManager * dd, CloudNode * Cube );
237// operations
238extern CloudNode * Cloud_bddAnd( CloudManager * dd, CloudNode * f, CloudNode * g );
239extern CloudNode * Cloud_bddOr( CloudManager * dd, CloudNode * f, CloudNode * g );
240// stats
241extern void Cloud_PrintInfo( CloudManager * dd );
242extern void Cloud_PrintHashTable( CloudManager * dd );
243
244
245
247
248
249
250#endif
251
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
int Cloud_SharingSize(CloudManager *dd, CloudNode **pn, int nn)
Definition cloud.c:796
CloudNode * Cloud_bddAnd(CloudManager *dd, CloudNode *f, CloudNode *g)
Definition cloud.c:489
void Cloud_Quit(CloudManager *dd)
Definition cloud.c:144
typedefABC_NAMESPACE_HEADER_START struct cloudManager CloudManager
Definition cloud.h:52
unsigned CloudSign
Definition cloud.h:54
struct cloudNode CloudNode
Definition cloud.h:55
unsigned CloudVar
Definition cloud.h:53
int Cloud_SupportSize(CloudManager *dd, CloudNode *n)
Definition cloud.c:658
void Cloud_PrintHashTable(CloudManager *dd)
Definition cloud.c:975
CloudNode * Cloud_MakeNode(CloudManager *dd, CloudVar v, CloudNode *t, CloudNode *e)
Definition cloud.c:254
void Cloud_bddPrintCube(CloudManager *dd, CloudNode *Cube)
Definition cloud.c:900
CloudOper
Definition cloud.h:61
@ CLOUD_OPER_AND
Definition cloud.h:62
@ CLOUD_OPER_BDIFF
Definition cloud.h:64
@ CLOUD_OPER_XOR
Definition cloud.h:63
@ CLOUD_OPER_LEQ
Definition cloud.h:65
struct cloudCacheEntry3 CloudCacheEntry3
Definition cloud.h:58
struct cloudCacheEntry2 CloudCacheEntry2
Definition cloud.h:57
void Cloud_Restart(CloudManager *dd)
Definition cloud.c:166
struct cloudCacheEntry1 CloudCacheEntry1
Definition cloud.h:56
CloudNode * Cloud_bddOr(CloudManager *dd, CloudNode *f, CloudNode *g)
Definition cloud.c:511
CloudNode * Cloud_GetOneCube(CloudManager *dd, CloudNode *n)
Definition cloud.c:817
void Cloud_PrintInfo(CloudManager *dd)
Definition cloud.c:950
void Cloud_CacheAllocate(CloudManager *dd, CloudOper oper, int size)
Definition cloud.c:195
int Cloud_DagCollect(CloudManager *dd, CloudNode *n)
Definition cloud.c:772
int Cloud_DagSize(CloudManager *dd, CloudNode *n)
Definition cloud.c:721
void Cloud_bddPrint(CloudManager *dd, CloudNode *Func)
Definition cloud.c:866
CloudNode * Cloud_Support(CloudManager *dd, CloudNode *n)
Definition cloud.c:618
CloudManager * Cloud_Init(int nVars, int nBits)
FUNCTION DECLARATIONS ///.
Definition cloud.c:70
struct cube Cube
CloudNode * a
Definition cloud.h:146
CloudNode * r
Definition cloud.h:147
CloudSign s
Definition cloud.h:145
CloudNode * b
Definition cloud.h:153
CloudNode * r
Definition cloud.h:154
CloudSign s
Definition cloud.h:151
CloudNode * a
Definition cloud.h:152
CloudNode * a
Definition cloud.h:159
CloudNode * b
Definition cloud.h:160
CloudNode * r
Definition cloud.h:162
CloudNode * c
Definition cloud.h:161
CloudSign s
Definition cloud.h:158
int nNodesCur
Definition cloud.h:103
int nCacheHits
Definition cloud.h:112
int nUniqueHits
Definition cloud.h:110
CloudSign nSignCur
Definition cloud.h:105
int bitsCache[4]
Definition cloud.h:96
CloudNode * tUnique
Definition cloud.h:118
int nCacheMisses
Definition cloud.h:113
CloudCacheEntry2 * tCaches[20]
Definition cloud.h:133
int shiftCache[4]
Definition cloud.h:99
CloudNode ** vars
Definition cloud.h:127
int nUniqueSteps
Definition cloud.h:115
int nMemUsed
Definition cloud.h:108
CloudNode * pNodeStart
Definition cloud.h:121
int nUniqueMisses
Definition cloud.h:111
CloudNode ** ppNodes
Definition cloud.h:130
int bitsNode
Definition cloud.h:95
CloudNode * pNodeEnd
Definition cloud.h:122
CloudNode * zero
Definition cloud.h:126
int shiftUnique
Definition cloud.h:98
int nVars
Definition cloud.h:93
CloudNode * one
Definition cloud.h:125
int nNodesAlloc
Definition cloud.h:101
int nNodesLimit
Definition cloud.h:102
CloudNode * e
Definition cloud.h:140
CloudNode * t
Definition cloud.h:141
CloudVar v
Definition cloud.h:139
CloudSign s
Definition cloud.h:138