ifSat.c 21.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/**CFile****************************************************************

  FileName    [ifSat.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [FPGA mapping based on priority cuts.]

  Synopsis    [SAT-based evaluation.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - November 21, 2006.]

  Revision    [$Id: ifSat.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]

***********************************************************************/

#include "if.h"
#include "sat/bsat/satSolver.h"

ABC_NAMESPACE_IMPL_START

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////
 
/**Function*************************************************************

  Synopsis    [Builds SAT instance for the given structure.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
45
void * If_ManSatBuildXY( int nLutSize )
46 47 48 49 50 51 52 53 54 55
{
    int nMintsL = (1 << nLutSize);
    int nMintsF = (1 << (2 * nLutSize - 1));
    int nVars   = 2 * nMintsL + nMintsF;
    int iVarP0  = 0;           // LUT0 parameters (total nMintsL)
    int iVarP1  = nMintsL;     // LUT1 parameters (total nMintsL)
    int m,iVarM = 2 * nMintsL; // MUX vars        (total nMintsF)
    sat_solver * p = sat_solver_new();
    sat_solver_setnvars( p, nVars );
    for ( m = 0; m < nMintsF; m++ )
56
        sat_solver_add_mux( p, 
57
            iVarM  + m, 
58 59 60
            iVarP0 + m % nMintsL, 
            iVarP1 + 2 * (m / nMintsL) + 1, 
            iVarP1 + 2 * (m / nMintsL), 
61
            0, 0, 0, 0 );
62 63
    return p;
}
64 65 66 67 68 69 70 71 72 73 74 75 76
void * If_ManSatBuildXYZ( int nLutSize )
{
    int nMintsL = (1 << nLutSize);
    int nMintsF = (1 << (3 * nLutSize - 2));
    int nVars   = 3 * nMintsL + nMintsF;
    int iVarP0  = 0;           // LUT0 parameters (total nMintsL)
    int iVarP1  = nMintsL;     // LUT1 parameters (total nMintsL)
    int iVarP2  = 2 * nMintsL; // LUT2 parameters (total nMintsL)
    int m,iVarM = 3 * nMintsL; // MUX vars        (total nMintsF)
    sat_solver * p = sat_solver_new();
    sat_solver_setnvars( p, nVars );
    for ( m = 0; m < nMintsF; m++ )
        sat_solver_add_mux41( p, 
77
            iVarM  + m,
78 79 80 81 82
            iVarP0 + m % nMintsL, 
            iVarP1 + (m >> nLutSize) % nMintsL, 
            iVarP2 + 4 * (m >> (2 * nLutSize)) + 0, 
            iVarP2 + 4 * (m >> (2 * nLutSize)) + 1, 
            iVarP2 + 4 * (m >> (2 * nLutSize)) + 2, 
83
            iVarP2 + 4 * (m >> (2 * nLutSize)) + 3 );
84 85 86 87 88 89 90
    return p;
}
void If_ManSatUnbuild( void * p )
{
    if ( p )
        sat_solver_delete( (sat_solver *)p );
}
91 92 93

/**Function*************************************************************

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  Synopsis    [Verification for 6-input function.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static word If_ManSat6ComposeLut4( int t, word f[4], int k )
{
    int m, v, nMints = (1 << k);
    word c, r = 0;
    assert( k <= 4 );
    for ( m = 0; m < nMints; m++ )
    {
        if ( !((t >> m) & 1) )
            continue;
        c = ~(word)0;
        for ( v = 0; v < k; v++ )
            c &= ((m >> v) & 1) ? f[v] : ~f[v];
        r |= c;
    }
    return r;
}
word If_ManSat6Truth( word uBound, word uFree, int * pBSet, int nBSet, int * pSSet, int nSSet, int * pFSet, int nFSet )
{
    word r, q, f[4];
    int i, k = 0;
    // bound set vars
    for ( i = 0; i < nSSet; i++ )
        f[k++] = s_Truths6[pSSet[i]];
    for ( i = 0; i < nBSet; i++ )
        f[k++] = s_Truths6[pBSet[i]];
    q = If_ManSat6ComposeLut4( (int)(uBound & 0xffff), f, k );
    // free set vars
    k = 0;
    f[k++] = q;
    for ( i = 0; i < nSSet; i++ )
        f[k++] = s_Truths6[pSSet[i]];
    for ( i = 0; i < nFSet; i++ )
        f[k++] = s_Truths6[pFSet[i]];
    r = If_ManSat6ComposeLut4( (int)(uFree & 0xffff), f, k );
    return r;
}

/**Function*************************************************************

142 143 144 145 146 147 148 149 150
  Synopsis    [Returns config string for the given truth table.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
151
int If_ManSatCheckXY( void * pSat, int nLutSize, word * pTruth, int nVars, unsigned uSet, word * pTBound, word * pTFree, Vec_Int_t * vLits )
152
{
153 154 155 156
    sat_solver * p = (sat_solver *)pSat;
    int iBSet, nBSet = 0, pBSet[IF_MAX_FUNC_LUTSIZE];
    int iSSet, nSSet = 0, pSSet[IF_MAX_FUNC_LUTSIZE];
    int iFSet, nFSet = 0, pFSet[IF_MAX_FUNC_LUTSIZE];
157 158 159
    int nMintsL = (1 << nLutSize);
    int nMintsF = (1 << (2 * nLutSize - 1));
    int v, Value, m, mNew, nMintsFNew, nMintsLNew;
160
    word Res;
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    // collect variable sets
    Dau_DecSortSet( uSet, nVars, &nBSet, &nSSet, &nFSet );
    assert( nBSet + nSSet + nFSet == nVars );
    // check variable bounds
    assert( nSSet + nBSet <= nLutSize );
    assert( nLutSize + nSSet + nFSet <= 2*nLutSize - 1 );
    nMintsFNew = (1 << (nLutSize + nSSet + nFSet));
    // remap minterms
    Vec_IntFill( vLits, nMintsF, -1 );
    for ( m = 0; m < (1 << nVars); m++ )
    {
        mNew = iBSet = iSSet = iFSet = 0;
        for ( v = 0; v < nVars; v++ )
        {
            Value = ((uSet >> (v << 1)) & 3);
            if ( Value == 0 ) // FS
            {
                if ( ((m >> v) & 1) )
179
                    mNew |= 1 << (nLutSize + nSSet + iFSet), pFSet[iFSet] = v;
180 181 182 183 184
                iFSet++;
            }
            else if ( Value == 1 ) // BS
            {
                if ( ((m >> v) & 1) )
185
                    mNew |= 1 << (nSSet + iBSet), pBSet[iBSet] = v;
186 187 188 189 190 191 192 193
                iBSet++;
            }
            else if ( Value == 3 ) // SS
            {
                if ( ((m >> v) & 1) )
                {
                    mNew |= 1 << iSSet;
                    mNew |= 1 << (nLutSize + iSSet);
194
                    pSSet[iSSet] = v;
195 196 197 198 199 200 201 202 203 204 205 206 207
                }
                iSSet++;
            }
            else assert( Value == 0 );
        }
        assert( iBSet == nBSet && iFSet == nFSet );
        assert( Vec_IntEntry(vLits, mNew) == -1 );
        Vec_IntWriteEntry( vLits, mNew, Abc_TtGetBit(pTruth, m) );
    }
    // find assumptions
    v = 0;
    Vec_IntForEachEntry( vLits, Value, m )
    {
208
//        printf( "%d", (Value >= 0) ? Value : 2 );
209 210 211 212
        if ( Value >= 0 )
            Vec_IntWriteEntry( vLits, v++, Abc_Var2Lit(2 * nMintsL + m, !Value) );
    }
    Vec_IntShrink( vLits, v );
213
//    printf( " %d\n", Vec_IntSize(vLits) );
214 215 216 217
    // run SAT solver
    Value = sat_solver_solve( p, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits), 0, 0, 0, 0 );
    if ( Value != l_True )
        return 0;
218
    if ( pTBound && pTFree )
219
    {
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        // collect config
        assert( nSSet + nBSet <= nLutSize );
        *pTBound = 0;
        nMintsLNew = (1 << (nSSet + nBSet));
        for ( m = 0; m < nMintsLNew; m++ )
            if ( sat_solver_var_value(p, m) )
                Abc_TtSetBit( pTBound, m );
        *pTBound = Abc_Tt6Stretch( *pTBound, nSSet + nBSet );
        // collect configs
        assert( nSSet + nFSet + 1 <= nLutSize );
        *pTFree = 0;
        nMintsLNew = (1 << (1 + nSSet + nFSet));
        for ( m = 0; m < nMintsLNew; m++ )
            if ( sat_solver_var_value(p, nMintsL+m) )
                Abc_TtSetBit( pTFree, m );
        *pTFree = Abc_Tt6Stretch( *pTFree, 1 + nSSet + nFSet );
        if ( nVars != 6 || nLutSize != 4 )
            return 1;
        // verify the result
        Res = If_ManSat6Truth( *pTBound, *pTFree, pBSet, nBSet, pSSet, nSSet, pFSet, nFSet );
        if ( pTruth[0] != Res )
        {
            Dau_DsdPrintFromTruth( pTruth,  nVars );
            Dau_DsdPrintFromTruth( &Res,    nVars );
            Dau_DsdPrintFromTruth( pTBound, nSSet+nBSet );
            Dau_DsdPrintFromTruth( pTFree,  nSSet+nFSet+1 );
            printf( "Verification failed!\n" );
        }
248
    }
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    return 1;
}

/**Function*************************************************************

  Synopsis    [Returns config string for the given truth table.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
unsigned If_ManSatCheckXYall_int( void * pSat, int nLutSize, word * pTruth, int nVars, Vec_Int_t * vLits )
{
    unsigned uSet = 0;
    int nTotal = 2 * nLutSize - 1;
    int nShared = nTotal - nVars;
    int i[6], s[4];
    assert( nLutSize >= 2 && nLutSize <= 6 );
    assert( nLutSize < nVars && nVars <= nTotal );
    assert( nShared >= 0 && nShared < nLutSize - 1 );
    if ( nLutSize == 2 )
273
    {
274 275 276 277 278 279 280 281
        assert( nShared == 0 );
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1]));
            if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet, NULL, NULL, vLits) )
                return uSet;
        }
282
    }
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
    else if ( nLutSize == 3 )
    {
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2]));
            if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet, NULL, NULL, vLits) )
                return uSet;
        }
        if ( nShared < 1 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2]));
            for ( s[0] = 0; s[0] < nLutSize; s[0]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]]));
        }
    }
    else if ( nLutSize == 4 )
    {
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3]));
            if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet, NULL, NULL, vLits) )
                return uSet;
        }
        if ( nShared < 1 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3]));
            for ( s[0] = 0; s[0] < nLutSize; s[0]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]]));
        }
        if ( nShared < 2 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3]));
            {
                for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
                for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
                    if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])), NULL, NULL, vLits) )
                        return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]]));
            }
        }
    }
    else if ( nLutSize == 5 )
    {
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4]));
            if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet, NULL, NULL, vLits) )
                return uSet;
        }
        if ( nShared < 1 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4]));
            for ( s[0] = 0; s[0] < nLutSize; s[0]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]]));
        }
        if ( nShared < 2 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4]));
            for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
            for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]]));
        }
        if ( nShared < 3 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        {
391
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4]));
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
            for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
            for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
            for ( s[2] = s[1]+1; s[2] < nLutSize; s[2]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]]));
        }
    }
    else if ( nLutSize == 6 )
    {
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        for ( i[5] = i[4]+1; i[5] < nVars; i[5]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4])) | (1 << (2*i[5]));
            if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet, NULL, NULL, vLits) )
                return uSet;
        }
        if ( nShared < 1 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        for ( i[5] = i[4]+1; i[5] < nVars; i[5]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4])) | (1 << (2*i[5]));
            for ( s[0] = 0; s[0] < nLutSize; s[0]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]]));
        }
        if ( nShared < 2 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        for ( i[5] = i[4]+1; i[5] < nVars; i[5]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4])) | (1 << (2*i[5]));
            for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
            for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]]));
        }
        if ( nShared < 3 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        for ( i[5] = i[4]+1; i[5] < nVars; i[5]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4])) | (1 << (2*i[5]));
            for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
            for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
            for ( s[2] = s[1]+1; s[2] < nLutSize; s[2]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]]));
        }
        if ( nShared < 4 )
            return 0;
        for ( i[0] = 0;      i[0] < nVars; i[0]++ )
        for ( i[1] = i[0]+1; i[1] < nVars; i[1]++ )
        for ( i[2] = i[1]+1; i[2] < nVars; i[2]++ )
        for ( i[3] = i[2]+1; i[3] < nVars; i[3]++ )
        for ( i[4] = i[3]+1; i[4] < nVars; i[4]++ )
        for ( i[5] = i[4]+1; i[5] < nVars; i[5]++ )
        {
            uSet = (1 << (2*i[0])) | (1 << (2*i[1])) | (1 << (2*i[2])) | (1 << (2*i[3])) | (1 << (2*i[4])) | (1 << (2*i[5]));
            for ( s[0] = 0;      s[0] < nLutSize; s[0]++ )
            for ( s[1] = s[0]+1; s[1] < nLutSize; s[1]++ )
            for ( s[2] = s[1]+1; s[2] < nLutSize; s[2]++ )
            for ( s[3] = s[1]+1; s[3] < nLutSize; s[3]++ )
                if ( If_ManSatCheckXY(pSat, nLutSize, pTruth, nVars, uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]])) | (3 << (2*i[s[3]])), NULL, NULL, vLits) )
                    return uSet | (3 << (2*i[s[0]])) | (3 << (2*i[s[1]])) | (3 << (2*i[s[2]])) | (3 << (2*i[s[3]]));
        }
    }
    return 0;
}
unsigned If_ManSatCheckXYall( void * pSat, int nLutSize, word * pTruth, int nVars, Vec_Int_t * vLits )
{
    unsigned uSet = If_ManSatCheckXYall_int( pSat, nLutSize, pTruth, nVars, vLits );
//    Dau_DecPrintSet( uSet, nVars, 1 );
    return uSet;
482 483 484 485 486 487 488 489 490 491 492 493 494
}

/**Function*************************************************************

  Synopsis    [Test procedure.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
495
void If_ManSatTest2()
496 497 498
{
    int nVars = 6;
    int nLutSize = 4;
499
    sat_solver * p = (sat_solver *)If_ManSatBuildXY( nLutSize );
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
//    char * pDsd = "(abcdefg)";
//    char * pDsd = "([a!bc]d!e)";
    char * pDsd = "0123456789ABCDEF{abcdef}";
    word * pTruth = Dau_DsdToTruth( pDsd, nVars );
    word uBound, uFree;
    Vec_Int_t * vLits = Vec_IntAlloc( 100 );
//    unsigned uSet = (1 << 0) | (1 << 2) | (1 << 4) | (1 << 6);
//    unsigned uSet = (3 << 0) | (1 << 2) | (1 << 8) | (1 << 4);
    unsigned uSet = (1 << 0) | (3 << 2) | (1 << 4) | (1 << 6);
    int RetValue = If_ManSatCheckXY( p, nLutSize, pTruth, nVars, uSet, &uBound, &uFree, vLits );
    assert( RetValue );
    
//    Abc_TtPrintBinary( pTruth, nVars );
//    Abc_TtPrintBinary( &uBound, nLutSize );
//    Abc_TtPrintBinary( &uFree, nLutSize );

    Dau_DsdPrintFromTruth( pTruth, nVars );
    Dau_DsdPrintFromTruth( &uBound, nLutSize );
    Dau_DsdPrintFromTruth( &uFree, nLutSize );
    sat_solver_delete(p);
    Vec_IntFree( vLits );
}
522
void If_ManSatTest3()
523
{
524 525
    int nVars = 6;
    int nLutSize = 4;
526
    sat_solver * p = (sat_solver *)If_ManSatBuildXY( nLutSize );
527 528 529 530
//    char * pDsd = "(abcdefg)";
//    char * pDsd = "([a!bc]d!e)";
    char * pDsd = "0123456789ABCDEF{abcdef}";
    word * pTruth = Dau_DsdToTruth( pDsd, nVars );
531
    Vec_Int_t * vLits = Vec_IntAlloc( 100 );
532 533 534 535 536
//    unsigned uSet = (1 << 0) | (1 << 2) | (1 << 4) | (1 << 6);
//    unsigned uSet = (3 << 0) | (1 << 2) | (1 << 8) | (1 << 4);
    unsigned uSet = (1 << 0) | (3 << 2) | (1 << 4) | (1 << 6);
    uSet = If_ManSatCheckXYall( p, nLutSize, pTruth, nVars, vLits );
    Dau_DecPrintSet( uSet, nVars, 1 );
537 538 539 540 541

    sat_solver_delete(p);
    Vec_IntFree( vLits );
}

542 543 544 545 546 547 548
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END