00001
00019 #ifndef __CLOUD_H__
00020 #define __CLOUD_H__
00021
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <assert.h>
00029 #include <time.h>
00030
00031 #ifdef _WIN32
00032 #define inline __inline // compatible with MS VS 6.0
00033 #endif
00034
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00047
00048
00049 typedef struct cloudManager CloudManager;
00050 typedef unsigned CloudVar;
00051 typedef unsigned CloudSign;
00052 typedef struct cloudNode CloudNode;
00053 typedef struct cloudCacheEntry1 CloudCacheEntry1;
00054 typedef struct cloudCacheEntry2 CloudCacheEntry2;
00055 typedef struct cloudCacheEntry3 CloudCacheEntry3;
00056
00057
00058 typedef enum {
00059 CLOUD_OPER_AND,
00060 CLOUD_OPER_XOR,
00061 CLOUD_OPER_BDIFF,
00062 CLOUD_OPER_LEQ
00063 } CloudOper;
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 struct cloudManager
00088 {
00089
00090 int nVars;
00091
00092 int bitsNode;
00093 int bitsCache[4];
00094
00095 int shiftUnique;
00096 int shiftCache[4];
00097
00098 int nNodesAlloc;
00099 int nNodesLimit;
00100 int nNodesCur;
00101
00102 CloudSign nSignCur;
00103
00104
00105 int nMemUsed;
00106
00107 int nUniqueHits;
00108 int nUniqueMisses;
00109 int nCacheHits;
00110 int nCacheMisses;
00111
00112 int nUniqueSteps;
00113
00114
00115 CloudNode * tUnique;
00116
00117
00118 CloudNode * pNodeStart;
00119 CloudNode * pNodeEnd;
00120
00121
00122 CloudNode * one;
00123 CloudNode * zero;
00124 CloudNode ** vars;
00125
00126
00127 CloudNode ** ppNodes;
00128
00129
00130 CloudCacheEntry2 * tCaches[20];
00131 };
00132
00133 struct cloudNode
00134 {
00135 CloudSign s;
00136 CloudVar v;
00137 CloudNode * e;
00138 CloudNode * t;
00139 };
00140 struct cloudCacheEntry1
00141 {
00142 CloudSign s;
00143 CloudNode * a;
00144 CloudNode * r;
00145 };
00146 struct cloudCacheEntry2
00147 {
00148 CloudSign s;
00149 CloudNode * a;
00150 CloudNode * b;
00151 CloudNode * r;
00152 };
00153 struct cloudCacheEntry3
00154 {
00155 CloudSign s;
00156 CloudNode * a;
00157 CloudNode * b;
00158 CloudNode * c;
00159 CloudNode * r;
00160 };
00161
00162
00163
00164 #define CLOUD_NODE_BITS 23
00165 #define CLOUD_ONE ((unsigned)0x00000001)
00166 #define CLOUD_NOT_ONE ((unsigned)0xfffffffe)
00167 #define CLOUD_VOID ((unsigned)0x00000000)
00168
00169 #define CLOUD_CONST_INDEX ((unsigned)0x0fffffff)
00170 #define CLOUD_MARK_ON ((unsigned)0x10000000)
00171 #define CLOUD_MARK_OFF ((unsigned)0xefffffff)
00172
00173
00174 #define cloudHashBuddy2(x,y,s) ((((x)+(y))*((x)+(y)+1)/2) & ((1<<(32-(s)))-1))
00175 #define cloudHashBuddy3(x,y,z,s) (cloudHashBuddy2((cloudHashBuddy2((x),(y),(s))),(z),(s)) & ((1<<(32-(s)))-1))
00176
00177 #define DD_P1 12582917
00178 #define DD_P2 4256249
00179 #define DD_P3 741457
00180 #define DD_P4 1618033999
00181 #define cloudHashCudd2(f,g,s) ((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2) >> (s))
00182 #define cloudHashCudd3(f,g,h,s) (((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2 + (unsigned)(h)) * DD_P3) >> (s))
00183
00184
00185 #define Cloud_Regular(p) ((CloudNode*)(((unsigned)(p)) & CLOUD_NOT_ONE)) // get the regular node (w/o bubble)
00186 #define Cloud_Not(p) ((CloudNode*)(((unsigned)(p)) ^ CLOUD_ONE)) // complement the node
00187 #define Cloud_NotCond(p,c) (((int)(c))? Cloud_Not(p):(p)) // complement the node conditionally
00188 #define Cloud_IsComplement(p) ((int)(((unsigned)(p)) & CLOUD_ONE)) // check if complemented
00189
00190 #define Cloud_IsConstant(p) (((Cloud_Regular(p))->v & CLOUD_MARK_OFF) == CLOUD_CONST_INDEX)
00191 #define cloudIsConstant(p) (((p)->v & CLOUD_MARK_OFF) == CLOUD_CONST_INDEX)
00192
00193
00194 #define Cloud_V(p) ((Cloud_Regular(p))->v)
00195 #define Cloud_E(p) ((Cloud_Regular(p))->e)
00196 #define Cloud_T(p) ((Cloud_Regular(p))->t)
00197
00198 #define cloudV(p) ((p)->v)
00199 #define cloudE(p) ((p)->e)
00200 #define cloudT(p) ((p)->t)
00201
00202 #define cloudNodeMark(p) ((p)->v |= CLOUD_MARK_ON)
00203 #define cloudNodeUnmark(p) ((p)->v &= CLOUD_MARK_OFF)
00204 #define cloudNodeIsMarked(p) ((int)((p)->v & CLOUD_MARK_ON))
00205
00206
00207 #define cloudCacheLookup1(p,sign,f) (((p)->s == (sign) && (p)->a == (f))? ((p)->r): (CLOUD_VOID))
00208 #define cloudCacheLookup2(p,sign,f,g) (((p)->s == (sign) && (p)->a == (f) && (p)->b == (g))? ((p)->r): (CLOUD_VOID))
00209 #define cloudCacheLookup3(p,sign,f,g,h) (((p)->s == (sign) && (p)->a == (f) && (p)->b == (g) && (p)->c == (h))? ((p)->r): (CLOUD_VOID))
00210
00211 #define cloudCacheInsert1(p,sign,f,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->r = (r)))
00212 #define cloudCacheInsert2(p,sign,f,g,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->b = (g)), ((p)->r = (r)))
00213 #define cloudCacheInsert3(p,sign,f,g,h,r) (((p)->s = (sign)), ((p)->a = (f)), ((p)->b = (g)), ((p)->c = (h)), ((p)->r = (r)))
00214
00215
00216 #define CLOUD_ASSERT(p) assert((p) >= dd->tUnique && (p) < dd->tUnique+dd->nNodesAlloc)
00217
00218
00219 #ifndef ALLOC
00220 #define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num)))
00221 #endif
00222
00223 #ifndef CALLOC
00224 #define CALLOC(type, num) ((type *) calloc((num), sizeof(type)))
00225 #endif
00226
00227 #ifndef FREE
00228 #define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
00229 #endif
00230
00231 #ifndef PRT
00232 #define PRT(a,t) fprintf( stdout, "%s = ", (a)); printf( "%.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC) )
00233 #endif
00234
00238
00239 extern CloudManager * Cloud_Init( int nVars, int nBits );
00240 extern void Cloud_Quit( CloudManager * dd );
00241 extern void Cloud_Restart( CloudManager * dd );
00242 extern void Cloud_CacheAllocate( CloudManager * dd, CloudOper oper, int size );
00243 extern CloudNode * Cloud_MakeNode( CloudManager * dd, CloudVar v, CloudNode * t, CloudNode * e );
00244
00245 extern CloudNode * Cloud_Support( CloudManager * dd, CloudNode * n );
00246 extern int Cloud_SupportSize( CloudManager * dd, CloudNode * n );
00247 extern int Cloud_DagSize( CloudManager * dd, CloudNode * n );
00248 extern int Cloud_DagCollect( CloudManager * dd, CloudNode * n );
00249 extern int Cloud_SharingSize( CloudManager * dd, CloudNode * * pn, int nn );
00250
00251 extern CloudNode * Cloud_GetOneCube( CloudManager * dd, CloudNode * n );
00252 extern void Cloud_bddPrint( CloudManager * dd, CloudNode * Func );
00253 extern void Cloud_bddPrintCube( CloudManager * dd, CloudNode * Cube );
00254
00255 extern CloudNode * Cloud_bddAnd( CloudManager * dd, CloudNode * f, CloudNode * g );
00256 extern CloudNode * Cloud_bddOr( CloudManager * dd, CloudNode * f, CloudNode * g );
00257
00258 extern void Cloud_PrintInfo( CloudManager * dd );
00259 extern void Cloud_PrintHashTable( CloudManager * dd );
00260
00261 #ifdef __cplusplus
00262 }
00263 #endif
00264
00265 #endif
00266