00001
00019 #ifndef __MVC_H__
00020 #define __MVC_H__
00021
00025
00026 #include <stdio.h>
00027 #include "extra.h"
00028 #include "extra.h"
00029
00033
00034
00035
00036
00037
00038 #define BITS_PER_WORD 32 // sizeof(Mvc_CubeWord_t) * 8
00039 #define BITS_PER_WORD_MINUS 31 // the same minus 1
00040 #define BITS_PER_WORD_LOG 5 // log2(sizeof(Mvc_CubeWord_t) * 8)
00041 #define BITS_DISJOINT ((Mvc_CubeWord_t)0x55555555) // the mask of the type "01010101"
00042 #define BITS_FULL ((Mvc_CubeWord_t)0xffffffff) // the mask of the type "11111111"
00043
00044
00045
00046
00050
00051
00052 typedef unsigned int Mvc_CubeWord_t;
00053 typedef struct MvcCubeStruct Mvc_Cube_t;
00054 typedef struct MvcListStruct Mvc_List_t;
00055 typedef struct MvcCoverStruct Mvc_Cover_t;
00056 typedef struct MvcDataStruct Mvc_Data_t;
00057 typedef struct MvcManagerStruct Mvc_Manager_t;
00058
00059
00060 struct MvcCubeStruct
00061 {
00062 Mvc_Cube_t * pNext;
00063 unsigned iLast : 8;
00064 unsigned nUnused : 6;
00065 unsigned fPrime : 1;
00066 unsigned fEssen : 1;
00067 unsigned nOnes : 16;
00068 Mvc_CubeWord_t pData[1];
00069 };
00070
00071
00072 struct MvcListStruct
00073 {
00074 Mvc_Cube_t * pHead;
00075 Mvc_Cube_t * pTail;
00076 int nItems;
00077 };
00078
00079
00080 struct MvcCoverStruct
00081 {
00082 char nWords;
00083 char nUnused;
00084 short nBits;
00085 Mvc_List_t lCubes;
00086 Mvc_Cube_t ** pCubes;
00087 int nCubesAlloc;
00088 int * pLits;
00089 Mvc_Cube_t * pMask;
00090 Mvc_Manager_t * pMem;
00091 };
00092
00093
00094 struct MvcDataStruct
00095 {
00096 Mvc_Manager_t * pMan;
00097
00098 int nBinVars;
00099 Mvc_Cube_t * pMaskBin;
00100 Mvc_Cube_t ** ppMasks;
00101 Mvc_Cube_t * ppTemp[3];
00102 };
00103
00104
00105 struct MvcManagerStruct
00106 {
00107 Extra_MmFixed_t * pManC;
00108 Extra_MmFixed_t * pMan1;
00109 Extra_MmFixed_t * pMan2;
00110 Extra_MmFixed_t * pMan4;
00111 };
00112
00116
00117
00118 #define Mvc_CubeReadNext(Cube) ((Cube)->pNext)
00119 #define Mvc_CubeReadNextP(Cube) (&(Cube)->pNext)
00120 #define Mvc_CubeReadLast(Cube) ((Cube)->iLast)
00121 #define Mvc_CubeReadSize(Cube) ((Cube)->nOnes)
00122
00123 #define Mvc_CubeSetNext(Cube,Next) ((Cube)->pNext = (Next))
00124 #define Mvc_CubeSetLast(Cube,Last) ((Cube)->iLast = (Last))
00125 #define Mvc_CubeSetSize(Cube,Size) ((Cube)->nOnes = (Size))
00126
00127
00128 #define Mvc_Cube1Words(Cube) ((Cube)->iLast == 0)
00129 #define Mvc_Cube2Words(Cube) ((Cube)->iLast == 1)
00130 #define Mvc_CubeNWords(Cube) ((Cube)->iLast > 1)
00131
00132 #define Mvc_CubeWhichWord(Bit) ((Bit) >> BITS_PER_WORD_LOG)
00133 #define Mvc_CubeWhichBit(Bit) ((Bit) & BITS_PER_WORD_MINUS)
00134
00135 #define Mvc_CubeBitValue(Cube, Bit) (((Cube)->pData[Mvc_CubeWhichWord(Bit)] & (((Mvc_CubeWord_t)1)<<(Mvc_CubeWhichBit(Bit)))) > 0)
00136 #define Mvc_CubeBitInsert(Cube, Bit) ((Cube)->pData[Mvc_CubeWhichWord(Bit)] |= (((Mvc_CubeWord_t)1)<<(Mvc_CubeWhichBit(Bit))))
00137 #define Mvc_CubeBitRemove(Cube, Bit) ((Cube)->pData[Mvc_CubeWhichWord(Bit)] &= ~(((Mvc_CubeWord_t)1)<<(Mvc_CubeWhichBit(Bit))))
00138
00139 #define Mvc_CubeVarValue(Cube, Var) (((Cube)->pData[Mvc_CubeWhichWord(2*(Var))] >> (Mvc_CubeWhichBit(2*(Var)))) & ((Mvc_CubeWord_t)3))
00140
00141
00142
00143
00144 #define Mvc_Cube1BitClean( Cube )\
00145 ((Cube)->pData[0] = 0)
00146 #define Mvc_Cube2BitClean( Cube )\
00147 (((Cube)->pData[0] = 0),\
00148 ((Cube)->pData[1] = 0))
00149 #define Mvc_CubeNBitClean( Cube )\
00150 {\
00151 int _i_;\
00152 for( _i_ = (Cube)->iLast; _i_ >= 0; _i_--)\
00153 (Cube)->pData[_i_] = 0;\
00154 }
00155
00156
00157 #define Mvc_CubeBitCleanUnused( Cube )\
00158 ((Cube)->pData[(Cube)->iLast] &= (BITS_FULL >> (Cube)->nUnused))
00159
00160
00161 #define Mvc_Cube1BitFill( Cube )\
00162 (Cube)->pData[0] = (BITS_FULL >> (Cube)->nUnused);
00163 #define Mvc_Cube2BitFill( Cube )\
00164 (((Cube)->pData[0] = BITS_FULL),\
00165 ((Cube)->pData[1] = (BITS_FULL >> (Cube)->nUnused)))
00166 #define Mvc_CubeNBitFill( Cube )\
00167 {\
00168 int _i_;\
00169 (Cube)->pData[(Cube)->iLast] = (BITS_FULL >> (Cube)->nUnused);\
00170 for( _i_ = (Cube)->iLast - 1; _i_ >= 0; _i_-- )\
00171 (Cube)->pData[_i_] = BITS_FULL;\
00172 }
00173
00174
00175 #define Mvc_Cube1BitNot( Cube )\
00176 ((Cube)->pData[0] ^= (BITS_FULL >> (Cube)->nUnused))
00177 #define Mvc_Cube2BitNot( Cube )\
00178 (((Cube)->pData[0] ^= BITS_FULL),\
00179 ((Cube)->pData[1] ^= (BITS_FULL >> (Cube)->nUnused)))
00180 #define Mvc_CubeNBitNot( Cube )\
00181 {\
00182 int _i_;\
00183 (Cube)->pData[(Cube)->iLast] ^= (BITS_FULL >> (Cube)->nUnused);\
00184 for( _i_ = (Cube)->iLast - 1; _i_ >= 0; _i_-- )\
00185 (Cube)->pData[_i_] ^= BITS_FULL;\
00186 }
00187
00188 #define Mvc_Cube1BitCopy( Cube1, Cube2 )\
00189 (((Cube1)->pData[0]) = ((Cube2)->pData[0]))
00190 #define Mvc_Cube2BitCopy( Cube1, Cube2 )\
00191 ((((Cube1)->pData[0]) = ((Cube2)->pData[0])),\
00192 (((Cube1)->pData[1])= ((Cube2)->pData[1])))
00193 #define Mvc_CubeNBitCopy( Cube1, Cube2 )\
00194 {\
00195 int _i_;\
00196 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00197 ((Cube1)->pData[_i_]) = ((Cube2)->pData[_i_]);\
00198 }
00199
00200 #define Mvc_Cube1BitOr( CubeR, Cube1, Cube2 )\
00201 (((CubeR)->pData[0]) = ((Cube1)->pData[0] | (Cube2)->pData[0]))
00202 #define Mvc_Cube2BitOr( CubeR, Cube1, Cube2 )\
00203 ((((CubeR)->pData[0]) = ((Cube1)->pData[0] | (Cube2)->pData[0])),\
00204 (((CubeR)->pData[1]) = ((Cube1)->pData[1] | (Cube2)->pData[1])))
00205 #define Mvc_CubeNBitOr( CubeR, Cube1, Cube2 )\
00206 {\
00207 int _i_;\
00208 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00209 (((CubeR)->pData[_i_]) = ((Cube1)->pData[_i_] | (Cube2)->pData[_i_]));\
00210 }
00211
00212 #define Mvc_Cube1BitExor( CubeR, Cube1, Cube2 )\
00213 (((CubeR)->pData[0]) = ((Cube1)->pData[0] ^ (Cube2)->pData[0]))
00214 #define Mvc_Cube2BitExor( CubeR, Cube1, Cube2 )\
00215 ((((CubeR)->pData[0]) = ((Cube1)->pData[0] ^ (Cube2)->pData[0])),\
00216 (((CubeR)->pData[1]) = ((Cube1)->pData[1] ^ (Cube2)->pData[1])))
00217 #define Mvc_CubeNBitExor( CubeR, Cube1, Cube2 )\
00218 {\
00219 int _i_;\
00220 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00221 (((CubeR)->pData[_i_]) = ((Cube1)->pData[_i_] ^ (Cube2)->pData[_i_]));\
00222 }
00223
00224 #define Mvc_Cube1BitAnd( CubeR, Cube1, Cube2 )\
00225 (((CubeR)->pData[0]) = ((Cube1)->pData[0] & (Cube2)->pData[0]))
00226 #define Mvc_Cube2BitAnd( CubeR, Cube1, Cube2 )\
00227 ((((CubeR)->pData[0]) = ((Cube1)->pData[0] & (Cube2)->pData[0])),\
00228 (((CubeR)->pData[1]) = ((Cube1)->pData[1] & (Cube2)->pData[1])))
00229 #define Mvc_CubeNBitAnd( CubeR, Cube1, Cube2 )\
00230 {\
00231 int _i_;\
00232 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00233 (((CubeR)->pData[_i_]) = ((Cube1)->pData[_i_] & (Cube2)->pData[_i_]));\
00234 }
00235
00236 #define Mvc_Cube1BitSharp( CubeR, Cube1, Cube2 )\
00237 (((CubeR)->pData[0]) = ((Cube1)->pData[0] & ~((Cube2)->pData[0])))
00238 #define Mvc_Cube2BitSharp( CubeR, Cube1, Cube2 )\
00239 ((((CubeR)->pData[0]) = ((Cube1)->pData[0] & ~((Cube2)->pData[0]))),\
00240 (((CubeR)->pData[1]) = ((Cube1)->pData[1] & ~((Cube2)->pData[1]))))
00241 #define Mvc_CubeNBitSharp( CubeR, Cube1, Cube2 )\
00242 {\
00243 int _i_;\
00244 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00245 (((CubeR)->pData[_i_]) = ((Cube1)->pData[_i_] & ~(Cube2)->pData[_i_]));\
00246 }
00247
00248 #define Mvc_Cube1BitEmpty( Res, Cube )\
00249 (Res = ((Cube)->pData[0] == 0))
00250 #define Mvc_Cube2BitEmpty( Res, Cube )\
00251 (Res = ((Cube)->pData[0] == 0 && (Cube)->pData[1] == 0))
00252 #define Mvc_CubeNBitEmpty( Res, Cube )\
00253 {\
00254 int _i_; Res = 1;\
00255 for (_i_ = (Cube)->iLast; _i_ >= 0; _i_--)\
00256 if ( (Cube)->pData[_i_] )\
00257 { Res = 0; break; }\
00258 }
00259
00260 #define Mvc_Cube1BitEqual( Res, Cube1, Cube2 )\
00261 (Res = (((Cube1)->pData[0]) == ((Cube2)->pData[0])))
00262 #define Mvc_Cube2BitEqual( Res, Cube1, Cube2 )\
00263 (Res = ((((Cube1)->pData[0]) == ((Cube2)->pData[0])) &&\
00264 (((Cube1)->pData[1]) == ((Cube2)->pData[1]))))
00265 #define Mvc_CubeNBitEqual( Res, Cube1, Cube2 )\
00266 {\
00267 int _i_; Res = 1;\
00268 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00269 if (((Cube1)->pData[_i_]) != ((Cube2)->pData[_i_]))\
00270 { Res = 0; break; }\
00271 }
00272
00273 #define Mvc_Cube1BitLess( Res, Cube1, Cube2 )\
00274 (Res = (((Cube1)->pData[0]) < ((Cube2)->pData[0])))
00275 #define Mvc_Cube2BitLess( Res, Cube1, Cube2 )\
00276 (Res = ((((Cube1)->pData[0]) < ((Cube2)->pData[0])) ||\
00277 ((((Cube1)->pData[0]) == ((Cube2)->pData[0])) && (((Cube1)->pData[1]) < ((Cube2)->pData[1])))))
00278 #define Mvc_CubeNBitLess( Res, Cube1, Cube2 )\
00279 {\
00280 int _i_; Res = 1;\
00281 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00282 if (((Cube1)->pData[_i_]) >= ((Cube2)->pData[_i_]))\
00283 { Res = 0; break; }\
00284 }
00285
00286 #define Mvc_Cube1BitMore( Res, Cube1, Cube2 )\
00287 (Res = (((Cube1)->pData[0]) > ((Cube2)->pData[0])))
00288 #define Mvc_Cube2BitMore( Res, Cube1, Cube2 )\
00289 (Res = ((((Cube1)->pData[0]) > ((Cube2)->pData[0])) ||\
00290 ((((Cube1)->pData[0]) == ((Cube2)->pData[0])) && (((Cube1)->pData[1]) > ((Cube2)->pData[1])))))
00291 #define Mvc_CubeNBitMore( Res, Cube1, Cube2 )\
00292 {\
00293 int _i_; Res = 1;\
00294 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00295 if (((Cube1)->pData[_i_]) <= ((Cube2)->pData[_i_]))\
00296 { Res = 0; break; }\
00297 }
00298
00299 #define Mvc_Cube1BitNotImpl( Res, Cube1, Cube2 )\
00300 (Res = (((Cube1)->pData[0]) & ~((Cube2)->pData[0])))
00301 #define Mvc_Cube2BitNotImpl( Res, Cube1, Cube2 )\
00302 (Res = ((((Cube1)->pData[0]) & ~((Cube2)->pData[0])) ||\
00303 (((Cube1)->pData[1]) & ~((Cube2)->pData[1]))))
00304 #define Mvc_CubeNBitNotImpl( Res, Cube1, Cube2 )\
00305 {\
00306 int _i_; Res = 0;\
00307 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00308 if (((Cube1)->pData[_i_]) & ~((Cube2)->pData[_i_]))\
00309 { Res = 1; break; }\
00310 }
00311
00312 #define Mvc_Cube1BitDisjoint( Res, Cube1, Cube2 )\
00313 (Res = ((((Cube1)->pData[0]) & ((Cube2)->pData[0])) == 0 ))
00314 #define Mvc_Cube2BitDisjoint( Res, Cube1, Cube2 )\
00315 (Res = (((((Cube1)->pData[0]) & ((Cube2)->pData[0])) == 0 ) &&\
00316 ((((Cube1)->pData[1]) & ((Cube2)->pData[1])) == 0 )))
00317 #define Mvc_CubeNBitDisjoint( Res, Cube1, Cube2 )\
00318 {\
00319 int _i_; Res = 1;\
00320 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00321 if (((Cube1)->pData[_i_]) & ((Cube2)->pData[_i_]))\
00322 { Res = 0; break; }\
00323 }
00324
00325 #define Mvc_Cube1BitEqualUnderMask( Res, Cube1, Cube2, Mask )\
00326 (Res = ((((Cube1)->pData[0]) & ((Mask)->pData[0])) == (((Cube2)->pData[0]) & ((Mask)->pData[0]))))
00327 #define Mvc_Cube2BitEqualUnderMask( Res, Cube1, Cube2, Mask )\
00328 (Res = (((((Cube1)->pData[0]) & ((Mask)->pData[0])) == (((Cube2)->pData[0]) & ((Mask)->pData[0]))) &&\
00329 ((((Cube1)->pData[1]) & ((Mask)->pData[1])) == (((Cube2)->pData[1]) & ((Mask)->pData[1])))))
00330 #define Mvc_CubeNBitEqualUnderMask( Res, Cube1, Cube2, Mask )\
00331 {\
00332 int _i_; Res = 1;\
00333 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00334 if ((((Cube1)->pData[_i_]) & ((Mask)->pData[_i_])) != (((Cube2)->pData[_i_]) & ((Mask)->pData[_i_])))\
00335 { Res = 0; break; }\
00336 }
00337
00338 #define Mvc_Cube1BitEqualOutsideMask( Res, Cube1, Cube2, Mask )\
00339 (Res = ((((Cube1)->pData[0]) | ((Mask)->pData[0])) == (((Cube2)->pData[0]) | ((Mask)->pData[0]))))
00340 #define Mvc_Cube2BitEqualOutsideMask( Res, Cube1, Cube2, Mask )\
00341 (Res = (((((Cube1)->pData[0]) | ((Mask)->pData[0])) == (((Cube2)->pData[0]) | ((Mask)->pData[0]))) &&\
00342 ((((Cube1)->pData[1]) | ((Mask)->pData[1])) == (((Cube2)->pData[1]) | ((Mask)->pData[1])))))
00343 #define Mvc_CubeNBitEqualOutsideMask( Res, Cube1, Cube2, Mask )\
00344 {\
00345 int _i_; Res = 1;\
00346 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00347 if ((((Cube1)->pData[_i_]) | ((Mask)->pData[_i_])) != (((Cube2)->pData[_i_]) | ((Mask)->pData[_i_])))\
00348 { Res = 0; break; }\
00349 }
00350
00351 #define Mvc_Cube1BitIntersectUnderMask( Res, Cube1, Cube2, Mask)\
00352 (Res = ((((Cube1)->pData[0]) & ((Cube2)->pData[0]) & ((Mask)->pData[0])) > 0))
00353 #define Mvc_Cube2BitIntersectUnderMask( Res, Cube1, Cube2, Mask)\
00354 (Res = (((((Cube1)->pData[0]) & ((Cube2)->pData[0]) & ((Mask)->pData[0])) > 0) ||\
00355 ((((Cube1)->pData[1]) & ((Cube2)->pData[1]) & ((Mask)->pData[1])) > 0)))
00356 #define Mvc_CubeNBitIntersectUnderMask( Res, Cube1, Cube2, Mask)\
00357 {\
00358 int _i_; Res = 0;\
00359 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00360 if (((Cube1)->pData[_i_]) & ((Cube2)->pData[_i_]) & ((Mask)->pData[_i_]))\
00361 { Res = 1; break; }\
00362 }
00363
00364 #define Mvc_Cube1BitNotImplUnderMask( Res, Cube1, Cube2, Mask )\
00365 (Res = (((Mask)->pData[0]) & ((Cube1)->pData[0]) & ~((Cube2)->pData[0])))
00366 #define Mvc_Cube2BitNotImplUnderMask( Res, Cube1, Cube2, Mask )\
00367 (Res = ((((Mask)->pData[0]) & ((Cube1)->pData[0]) & ~((Cube2)->pData[0])) ||\
00368 (((Mask)->pData[1]) & ((Cube1)->pData[1]) & ~((Cube2)->pData[1]))))
00369 #define Mvc_CubeNBitNotImplUnderMask( Res, Cube1, Cube2, Mask )\
00370 {\
00371 int _i_; Res = 0;\
00372 for (_i_ = (Cube1)->iLast; _i_ >= 0; _i_--)\
00373 if (((Mask)->pData[_i_]) & ((Cube1)->pData[_i_]) & ~((Cube2)->pData[_i_]))\
00374 { Res = 1; break; }\
00375 }
00376
00377
00378 #define Mvc_CubeBitClean( Cube )\
00379 if ( Mvc_Cube1Words(Cube) ) { Mvc_Cube1BitClean( Cube ); }\
00380 else if ( Mvc_Cube2Words(Cube) ) { Mvc_Cube2BitClean( Cube ); }\
00381 else { Mvc_CubeNBitClean( Cube ); }
00382 #define Mvc_CubeBitFill( Cube )\
00383 if ( Mvc_Cube1Words(Cube) ) { Mvc_Cube1BitFill( Cube ); }\
00384 else if ( Mvc_Cube2Words(Cube) ) { Mvc_Cube2BitFill( Cube ); }\
00385 else { Mvc_CubeNBitFill( Cube ); }
00386 #define Mvc_CubeBitNot( Cube )\
00387 if ( Mvc_Cube1Words(Cube) ) { Mvc_Cube1BitNot( Cube ); }\
00388 else if ( Mvc_Cube2Words(Cube) ) { Mvc_Cube2BitNot( Cube ); }\
00389 else { Mvc_CubeNBitNot( Cube ); }
00390 #define Mvc_CubeBitCopy( Cube1, Cube2 )\
00391 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitCopy( Cube1, Cube2 ); }\
00392 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitCopy( Cube1, Cube2 ); }\
00393 else { Mvc_CubeNBitCopy( Cube1, Cube2 ); }
00394 #define Mvc_CubeBitOr( CubeR, Cube1, Cube2 )\
00395 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitOr( CubeR, Cube1, Cube2 ); }\
00396 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitOr( CubeR, Cube1, Cube2 ); }\
00397 else { Mvc_CubeNBitOr( CubeR, Cube1, Cube2 ); }
00398 #define Mvc_CubeBitExor( CubeR, Cube1, Cube2 )\
00399 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitExor( CubeR, Cube1, Cube2 ); }\
00400 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitExor( CubeR, Cube1, Cube2 ); }\
00401 else { Mvc_CubeNBitExor( CubeR, Cube1, Cube2 ); }
00402 #define Mvc_CubeBitAnd( CubeR, Cube1, Cube2 )\
00403 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitAnd( CubeR, Cube1, Cube2 ); }\
00404 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitAnd( CubeR, Cube1, Cube2 ); }\
00405 else { Mvc_CubeNBitAnd( CubeR, Cube1, Cube2 ); }
00406 #define Mvc_CubeBitSharp( CubeR, Cube1, Cube2 )\
00407 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitSharp( CubeR, Cube1, Cube2 ); }\
00408 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitSharp( CubeR, Cube1, Cube2 ); }\
00409 else { Mvc_CubeNBitSharp( CubeR, Cube1, Cube2 ); }
00410 #define Mvc_CubeBitEmpty( Res, Cube )\
00411 if ( Mvc_Cube1Words(Cube) ) { Mvc_Cube1BitEmpty( Res, Cube ); }\
00412 else if ( Mvc_Cube2Words(Cube) ) { Mvc_Cube2BitEmpty( Res, Cube ); }\
00413 else { Mvc_CubeNBitEmpty( Res, Cube ); }
00414 #define Mvc_CubeBitEqual( Res, Cube1, Cube2 )\
00415 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitEqual( Res, Cube1, Cube2 ); }\
00416 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitEqual( Res, Cube1, Cube2 ); }\
00417 else { Mvc_CubeNBitEqual( Res, Cube1, Cube2 ); }
00418 #define Mvc_CubeBitLess( Res, Cube1, Cube2 )\
00419 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitLess( Res, Cube1, Cube2 ); }\
00420 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitLess( Res, Cube1, Cube2 ); }\
00421 else { Mvc_CubeNBitLess( Res, Cube1, Cube2 ); }
00422 #define Mvc_CubeBitMore( Res, Cube1, Cube2 )\
00423 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitMore( Res, Cube1, Cube2 ); }\
00424 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitMore( Res, Cube1, Cube2 ); }\
00425 else { Mvc_CubeNBitMore( Res, Cube1, Cube2 ); }
00426 #define Mvc_CubeBitNotImpl( Res, Cube1, Cube2 )\
00427 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitNotImpl( Res, Cube1, Cube2 ); }\
00428 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitNotImpl( Res, Cube1, Cube2 ); }\
00429 else { Mvc_CubeNBitNotImpl( Res, Cube1, Cube2 ); }
00430 #define Mvc_CubeBitDisjoint( Res, Cube1, Cube2 )\
00431 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitDisjoint( Res, Cube1, Cube2 ); }\
00432 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitDisjoint( Res, Cube1, Cube2 ); }\
00433 else { Mvc_CubeNBitDisjoint( Res, Cube1, Cube2 ); }
00434 #define Mvc_CubeBitEqualUnderMask( Res, Cube1, Cube2, Mask )\
00435 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitEqualUnderMask( Res, Cube1, Cube2, Mask ); }\
00436 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitEqualUnderMask( Res, Cube1, Cube2, Mask ); }\
00437 else { Mvc_CubeNBitEqualUnderMask( Res, Cube1, Cube2, Mask ); }
00438 #define Mvc_CubeBitEqualOutsideMask( Res, Cube1, Cube2, Mask )\
00439 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitEqualOutsideMask( Res, Cube1, Cube2, Mask ); }\
00440 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitEqualOutsideMask( Res, Cube1, Cube2, Mask ); }\
00441 else { Mvc_CubeNBitEqualOutsideMask( Res, Cube1, Cube2, Mask ); }
00442 #define Mvc_CubeBitIntersectUnderMask( Res, Cube1, Cube2, Mask )\
00443 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitIntersectUnderMask( Res, Cube1, Cube2, Mask ); }\
00444 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitIntersectUnderMask( Res, Cube1, Cube2, Mask ); }\
00445 else { Mvc_CubeNBitIntersectUnderMask( Res, Cube1, Cube2, Mask ); }
00446 #define Mvc_CubeBitNotImplUnderMask( Res, Cube1, Cube2, Mask )\
00447 if ( Mvc_Cube1Words(Cube1) ) { Mvc_Cube1BitNotImplUnderMask( Res, Cube1, Cube2, Mask ); }\
00448 else if ( Mvc_Cube2Words(Cube1) ){ Mvc_Cube2BitNotImplUnderMask( Res, Cube1, Cube2, Mask ); }\
00449 else { Mvc_CubeNBitNotImplUnderMask( Res, Cube1, Cube2, Mask ); }
00450
00451
00452
00453 #define Mvc_ListAddCubeHead( pList, pCube )\
00454 {\
00455 if ( pList->pHead == NULL )\
00456 {\
00457 Mvc_CubeSetNext( pCube, NULL );\
00458 pList->pHead = pCube;\
00459 pList->pTail = pCube;\
00460 }\
00461 else\
00462 {\
00463 Mvc_CubeSetNext( pCube, pList->pHead );\
00464 pList->pHead = pCube;\
00465 }\
00466 pList->nItems++;\
00467 }
00468 #define Mvc_ListAddCubeTail( pList, pCube )\
00469 {\
00470 if ( pList->pHead == NULL )\
00471 pList->pHead = pCube;\
00472 else\
00473 Mvc_CubeSetNext( pList->pTail, pCube );\
00474 pList->pTail = pCube;\
00475 Mvc_CubeSetNext( pCube, NULL );\
00476 pList->nItems++;\
00477 }
00478 #define Mvc_ListDeleteCube( pList, pPrev, pCube )\
00479 {\
00480 if ( pPrev == NULL )\
00481 pList->pHead = pCube->pNext;\
00482 else\
00483 pPrev->pNext = pCube->pNext;\
00484 if ( pList->pTail == pCube )\
00485 {\
00486 assert( pCube->pNext == NULL );\
00487 pList->pTail = pPrev;\
00488 }\
00489 pList->nItems--;\
00490 }
00491
00492
00493 #define Mvc_CoverAddCubeHead( pCover, pCube )\
00494 {\
00495 Mvc_List_t * pList = &pCover->lCubes;\
00496 Mvc_ListAddCubeHead( pList, pCube );\
00497 }
00498 #define Mvc_CoverAddCubeTail( pCover, pCube )\
00499 {\
00500 Mvc_List_t * pList = &pCover->lCubes;\
00501 Mvc_ListAddCubeTail( pList, pCube );\
00502 }
00503 #define Mvc_CoverDeleteCube( pCover, pPrev, pCube )\
00504 {\
00505 Mvc_List_t * pList = &pCover->lCubes;\
00506 Mvc_ListDeleteCube( pList, pPrev, pCube );\
00507 }
00508
00509
00510
00511
00512
00513
00514
00515 #define Mvc_ListForEachCube( List, Cube )\
00516 for ( Cube = List->pHead;\
00517 Cube;\
00518 Cube = Cube->pNext )
00519 #define Mvc_ListForEachCubeSafe( List, Cube, Cube2 )\
00520 for ( Cube = List->pHead, Cube2 = (Cube? Cube->pNext: NULL);\
00521 Cube;\
00522 Cube = Cube2, Cube2 = (Cube? Cube->pNext: NULL) )
00523
00524
00525 #define Mvc_CoverForEachCube( Cover, Cube )\
00526 for ( Cube = (Cover)->lCubes.pHead;\
00527 Cube;\
00528 Cube = Cube->pNext )
00529 #define Mvc_CoverForEachCubeWithIndex( Cover, Cube, Index )\
00530 for ( Index = 0, Cube = (Cover)->lCubes.pHead;\
00531 Cube;\
00532 Index++, Cube = Cube->pNext )
00533 #define Mvc_CoverForEachCubeSafe( Cover, Cube, Cube2 )\
00534 for ( Cube = (Cover)->lCubes.pHead, Cube2 = (Cube? Cube->pNext: NULL);\
00535 Cube;\
00536 Cube = Cube2, Cube2 = (Cube? Cube->pNext: NULL) )
00537
00538
00539 #define Mvc_CoverForEachCubeStart( Start, Cube )\
00540 for ( Cube = Start;\
00541 Cube;\
00542 Cube = Cube->pNext )
00543 #define Mvc_CoverForEachCubeStartSafe( Start, Cube, Cube2 )\
00544 for ( Cube = Start, Cube2 = (Cube? Cube->pNext: NULL);\
00545 Cube;\
00546 Cube = Cube2, Cube2 = (Cube? Cube->pNext: NULL) )
00547
00548
00549
00550 #define Mvc_CubeForEachBit( Cover, Cube, iBit, Value )\
00551 for ( iBit = 0;\
00552 iBit < Cover->nBits && ((Value = Mvc_CubeBitValue(Cube,iBit))>=0);\
00553 iBit++ )
00554
00555 #define Mvc_CubeForEachVarValue( Cover, Cube, iVar, Value )\
00556 for ( iVar = 0;\
00557 iVar < Cover->nBits/2 && (Value = Mvc_CubeVarValue(Cube,iVar));\
00558 iVar++ )
00559
00560
00561
00562
00563
00564 #define MEM_ALLOC( Manager, Type, Size ) ((Type *)malloc( (Size) * sizeof(Type) ))
00565 #define MEM_FREE( Manager, Type, Size, Pointer ) if ( Pointer ) { free(Pointer); Pointer = NULL; }
00566
00570
00571
00572 extern int Mvc_CoverReadWordNum( Mvc_Cover_t * pCover );
00573 extern int Mvc_CoverReadBitNum( Mvc_Cover_t * pCover );
00574 extern int Mvc_CoverReadCubeNum( Mvc_Cover_t * pCover );
00575 extern Mvc_Cube_t * Mvc_CoverReadCubeHead( Mvc_Cover_t * pCover );
00576 extern Mvc_Cube_t * Mvc_CoverReadCubeTail( Mvc_Cover_t * pCover );
00577 extern Mvc_List_t * Mvc_CoverReadCubeList( Mvc_Cover_t * pCover );
00578 extern int Mvc_ListReadCubeNum( Mvc_List_t * pList );
00579 extern Mvc_Cube_t * Mvc_ListReadCubeHead( Mvc_List_t * pList );
00580 extern Mvc_Cube_t * Mvc_ListReadCubeTail( Mvc_List_t * pList );
00581 extern void Mvc_CoverSetCubeNum( Mvc_Cover_t * pCover,int nItems );
00582 extern void Mvc_CoverSetCubeHead( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00583 extern void Mvc_CoverSetCubeTail( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00584 extern void Mvc_CoverSetCubeList( Mvc_Cover_t * pCover, Mvc_List_t * pList );
00585 extern int Mvc_CoverIsEmpty( Mvc_Cover_t * pCover );
00586 extern int Mvc_CoverIsTautology( Mvc_Cover_t * pCover );
00587 extern int Mvc_CoverIsBinaryBuffer( Mvc_Cover_t * pCover );
00588 extern void Mvc_CoverMakeEmpty( Mvc_Cover_t * pCover );
00589 extern void Mvc_CoverMakeTautology( Mvc_Cover_t * pCover );
00590 extern Mvc_Cover_t * Mvc_CoverCreateEmpty( Mvc_Cover_t * pCover );
00591 extern Mvc_Cover_t * Mvc_CoverCreateTautology( Mvc_Cover_t * pCover );
00592
00593 extern Mvc_Cover_t * Mvc_CoverAlloc( Mvc_Manager_t * pMem, int nBits );
00594 extern Mvc_Cover_t * Mvc_CoverCreateConst( Mvc_Manager_t * pMem, int nBits, int Phase );
00595 extern Mvc_Cover_t * Mvc_CoverClone( Mvc_Cover_t * pCover );
00596 extern Mvc_Cover_t * Mvc_CoverDup( Mvc_Cover_t * pCover );
00597 extern void Mvc_CoverFree( Mvc_Cover_t * pCover );
00598 extern void Mvc_CoverAllocateMask( Mvc_Cover_t * pCover );
00599 extern void Mvc_CoverAllocateArrayLits( Mvc_Cover_t * pCover );
00600 extern void Mvc_CoverAllocateArrayCubes( Mvc_Cover_t * pCover );
00601 extern void Mvc_CoverDeallocateMask( Mvc_Cover_t * pCover );
00602 extern void Mvc_CoverDeallocateArrayLits( Mvc_Cover_t * pCover );
00603
00604 extern Mvc_Cube_t * Mvc_CubeAlloc( Mvc_Cover_t * pCover );
00605 extern Mvc_Cube_t * Mvc_CubeDup( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00606 extern void Mvc_CubeFree( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00607 extern void Mvc_CubeBitRemoveDcs( Mvc_Cube_t * pCube );
00608
00609 extern int Mvc_CubeCompareInt( Mvc_Cube_t * pC1, Mvc_Cube_t * pC2, Mvc_Cube_t * pMask );
00610 extern int Mvc_CubeCompareSizeAndInt( Mvc_Cube_t * pC1, Mvc_Cube_t * pC2, Mvc_Cube_t * pMask );
00611 extern int Mvc_CubeCompareIntUnderMask( Mvc_Cube_t * pC1, Mvc_Cube_t * pC2, Mvc_Cube_t * pMask );
00612 extern int Mvc_CubeCompareIntOutsideMask( Mvc_Cube_t * pC1, Mvc_Cube_t * pC2, Mvc_Cube_t * pMask );
00613 extern int Mvc_CubeCompareIntOutsideAndUnderMask( Mvc_Cube_t * pC1, Mvc_Cube_t * pC2, Mvc_Cube_t * pMask );
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624 extern Mvc_Cover_t * Mvc_CoverDivisor( Mvc_Cover_t * pCover );
00625
00626 extern void Mvc_CoverDivide( Mvc_Cover_t * pCover, Mvc_Cover_t * pDiv, Mvc_Cover_t ** ppQuo, Mvc_Cover_t ** ppRem );
00627 extern void Mvc_CoverDivideInternal( Mvc_Cover_t * pCover, Mvc_Cover_t * pDiv, Mvc_Cover_t ** ppQuo, Mvc_Cover_t ** ppRem );
00628 extern void Mvc_CoverDivideByLiteral( Mvc_Cover_t * pCover, Mvc_Cover_t * pDiv, Mvc_Cover_t ** ppQuo, Mvc_Cover_t ** ppRem );
00629 extern void Mvc_CoverDivideByCube( Mvc_Cover_t * pCover, Mvc_Cover_t * pDiv, Mvc_Cover_t ** ppQuo, Mvc_Cover_t ** ppRem );
00630 extern void Mvc_CoverDivideByLiteralQuo( Mvc_Cover_t * pCover, int iLit );
00631
00632
00633 extern void Mvc_ListAddCubeHead_( Mvc_List_t * pList, Mvc_Cube_t * pCube );
00634 extern void Mvc_ListAddCubeTail_( Mvc_List_t * pList, Mvc_Cube_t * pCube );
00635 extern void Mvc_ListDeleteCube_( Mvc_List_t * pList, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube );
00636 extern void Mvc_CoverAddCubeHead_( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00637 extern void Mvc_CoverAddCubeTail_( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00638 extern void Mvc_CoverDeleteCube_( Mvc_Cover_t * pCover, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube );
00639 extern void Mvc_CoverAddDupCubeHead( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00640 extern void Mvc_CoverAddDupCubeTail( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00641
00642 extern void Mvc_CoverAddLiteralsOfCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00643 extern void Mvc_CoverDeleteLiteralsOfCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00644 extern void Mvc_CoverList2Array( Mvc_Cover_t * pCover );
00645 extern void Mvc_CoverArray2List( Mvc_Cover_t * pCover );
00646 extern Mvc_Cube_t * Mvc_ListGetTailFromHead( Mvc_Cube_t * pHead );
00647
00648 extern void Mvc_CoverPrint( Mvc_Cover_t * pCover );
00649 extern void Mvc_CubePrint( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00650 extern void Mvc_CoverPrintMv( Mvc_Data_t * pData, Mvc_Cover_t * pCover );
00651 extern void Mvc_CubePrintMv( Mvc_Data_t * pData, Mvc_Cover_t * pCover, Mvc_Cube_t * pCube );
00652
00653 extern void Mvc_CoverSort( Mvc_Cover_t * pCover, Mvc_Cube_t * pMask, int (* pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *) );
00654
00655 extern void Mvc_CoverSupport( Mvc_Cover_t * pCover, Mvc_Cube_t * pSupp );
00656 extern int Mvc_CoverSupportSizeBinary( Mvc_Cover_t * pCover );
00657 extern int Mvc_CoverSupportVarBelongs( Mvc_Cover_t * pCover, int iVar );
00658 extern void Mvc_CoverCommonCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pComCube );
00659 extern int Mvc_CoverIsCubeFree( Mvc_Cover_t * pCover );
00660 extern void Mvc_CoverMakeCubeFree( Mvc_Cover_t * pCover );
00661 extern Mvc_Cover_t * Mvc_CoverCommonCubeCover( Mvc_Cover_t * pCover );
00662 extern int Mvc_CoverCheckSuppContainment( Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00663 extern int Mvc_CoverSetCubeSizes( Mvc_Cover_t * pCover );
00664 extern int Mvc_CoverGetCubeSize( Mvc_Cube_t * pCube );
00665 extern int Mvc_CoverCountCubePairDiffs( Mvc_Cover_t * pCover, unsigned char pDiffs[] );
00666 extern Mvc_Cover_t * Mvc_CoverRemap( Mvc_Cover_t * pCover, int * pVarsRem, int nVarsRem );
00667 extern void Mvc_CoverInverse( Mvc_Cover_t * pCover );
00668 extern Mvc_Cover_t * Mvc_CoverRemoveDontCareLits( Mvc_Cover_t * pCover );
00669 extern Mvc_Cover_t * Mvc_CoverCofactor( Mvc_Cover_t * pCover, int iValue, int iValueOther );
00670 extern Mvc_Cover_t * Mvc_CoverFlipVar( Mvc_Cover_t * pCover, int iValue0, int iValue1 );
00671 extern Mvc_Cover_t * Mvc_CoverUnivQuantify( Mvc_Cover_t * p, int iValueA0, int iValueA1, int iValueB0, int iValueB1 );
00672 extern Mvc_Cover_t ** Mvc_CoverCofactors( Mvc_Data_t * pData, Mvc_Cover_t * pCover, int iVar );
00673 extern int Mvr_CoverCountLitsWithValue( Mvc_Data_t * pData, Mvc_Cover_t * pCover, int iVar, int iValue );
00674
00675 extern Mvc_Cover_t * Mvc_CoverTranspose( Mvc_Cover_t * pCover );
00676 extern int Mvc_UtilsCheckUnusedZeros( Mvc_Cover_t * pCover );
00677
00678 extern int Mvc_CoverAnyLiteral( Mvc_Cover_t * pCover, Mvc_Cube_t * pMask );
00679 extern int Mvc_CoverBestLiteral( Mvc_Cover_t * pCover, Mvc_Cube_t * pMask );
00680 extern int Mvc_CoverWorstLiteral( Mvc_Cover_t * pCover, Mvc_Cube_t * pMask );
00681 extern Mvc_Cover_t * Mvc_CoverBestLiteralCover( Mvc_Cover_t * pCover, Mvc_Cover_t * pSimple );
00682 extern int Mvc_CoverFirstCubeFirstLit( Mvc_Cover_t * pCover );
00683 extern int Mvc_CoverCountLiterals( Mvc_Cover_t * pCover );
00684 extern int Mvc_CoverIsOneLiteral( Mvc_Cover_t * pCover );
00685
00686 extern Mvc_Cover_t * Mvc_CoverAlgebraicMultiply( Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00687 extern Mvc_Cover_t * Mvc_CoverAlgebraicSubtract( Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00688 extern int Mvc_CoverAlgebraicEqual( Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00689
00690 extern Mvc_Cover_t * Mvc_CoverBooleanOr( Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00691 extern Mvc_Cover_t * Mvc_CoverBooleanAnd( Mvc_Data_t * p, Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00692 extern int Mvc_CoverBooleanEqual( Mvc_Data_t * p, Mvc_Cover_t * pCover1, Mvc_Cover_t * pCover2 );
00693
00694
00695 extern int Mvc_CoverContain( Mvc_Cover_t * pCover );
00696
00697 extern int Mvc_CoverTautology( Mvc_Data_t * p, Mvc_Cover_t * pCover );
00698
00699 extern Mvc_Cover_t * Mvc_CoverComplement( Mvc_Data_t * p, Mvc_Cover_t * pCover );
00700
00701 extern Mvc_Cover_t * Mvc_CoverSharp( Mvc_Data_t * p, Mvc_Cover_t * pA, Mvc_Cover_t * pB );
00702 extern int Mvc_CoverDist0Cubes( Mvc_Data_t * pData, Mvc_Cube_t * pA, Mvc_Cube_t * pB );
00703 extern void Mvc_CoverIntersectCubes( Mvc_Data_t * pData, Mvc_Cover_t * pC1, Mvc_Cover_t * pC2 );
00704 extern int Mvc_CoverIsIntersecting( Mvc_Data_t * pData, Mvc_Cover_t * pC1, Mvc_Cover_t * pC2 );
00705 extern void Mvc_CoverAppendCubes( Mvc_Cover_t * pC1, Mvc_Cover_t * pC2 );
00706 extern void Mvc_CoverCopyAndAppendCubes( Mvc_Cover_t * pC1, Mvc_Cover_t * pC2 );
00707 extern void Mvc_CoverRemoveCubes( Mvc_Cover_t * pC );
00708
00709
00710 extern void Mvc_CoverMinimizeByReshape( Mvc_Data_t * pData, Mvc_Cover_t * pCover );
00711
00712
00713 extern void Mvc_CoverDist1Merge( Mvc_Data_t * p, Mvc_Cover_t * pCover );
00714
00715
00716
00717
00718
00719
00720 extern void Mvc_ManagerFree( Mvc_Manager_t * p );
00721 extern Mvc_Manager_t * Mvc_ManagerStart();
00722 extern Mvc_Manager_t * Mvc_ManagerAllocCover();
00723 extern Mvc_Manager_t * Mvc_ManagerAllocCube( int nWords );
00724 extern Mvc_Manager_t * Mvc_ManagerFreeCover( Mvc_Cover_t * pCover );
00725 extern Mvc_Manager_t * Mvc_ManagerFreeCube( Mvc_Cover_t * pCube, int nWords );
00726
00727 #endif
00728
00732