fraSec.c 24 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**CFile****************************************************************

  FileName    [fraSec.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [New FRAIG package.]

  Synopsis    [Performs SEC based on seq sweeping.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 30, 2007.]

  Revision    [$Id: fraSec.c,v 1.00 2007/06/30 00:00:00 alanmi Exp $]

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

#include "fra.h"
22 23 24 25
#include "aig/ioa/ioa.h"
#include "proof/int/int.h"
#include "proof/ssw/ssw.h"
#include "aig/saig/saig.h"
26
#include "bdd/bbr/bbr.h"
27
#include "proof/pdr/pdr.h"
28 29 30

ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

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

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
51 52 53
void Fra_SecSetDefaultParams( Fra_Sec_t * p )
{
    memset( p, 0, sizeof(Fra_Sec_t) );
Alan Mishchenko committed
54 55 56 57 58
    p->fTryComb          =       1;  // try CEC call as a preprocessing step
    p->fTryBmc           =       1;  // try BMC call as a preprocessing step 
    p->nFramesMax        =       4;  // the max number of frames used for induction
    p->nBTLimit          =    1000;  // conflict limit at a node during induction 
    p->nBTLimitGlobal    = 5000000;  // global conflict limit during induction
Alan Mishchenko committed
59 60
    p->nBTLimitInter     =   10000;  // conflict limit during interpolation
    p->nBddVarsMax       =     150;  // the limit on the number of registers in BDD reachability
Alan Mishchenko committed
61 62 63 64 65 66 67 68
    p->nBddMax           =   50000;  // the limit on the number of BDD nodes 
    p->nBddIterMax       = 1000000;  // the limit on the number of BDD iterations
    p->fPhaseAbstract    =       0;  // enables phase abstraction
    p->fRetimeFirst      =       1;  // enables most-forward retiming at the beginning
    p->fRetimeRegs       =       1;  // enables min-register retiming at the beginning
    p->fFraiging         =       1;  // enables fraiging at the beginning
    p->fInduction        =       1;  // enables the use of induction (signal correspondence)
    p->fInterpolation    =       1;  // enables interpolation
Alan Mishchenko committed
69
    p->fInterSeparate    =       0;  // enables interpolation for each outputs separately
Alan Mishchenko committed
70
    p->fReachability     =       1;  // enables BDD based reachability
71
    p->fReorderImage     =       1;  // enables variable reordering during image computation
Alan Mishchenko committed
72 73
    p->fStopOnFirstFail  =       1;  // enables stopping after first output of a miter has failed to prove
    p->fUseNewProver     =       0;  // enables new prover
74 75
    p->fUsePdr           =       1;  // enables PDR
    p->nPdrTimeout       =      60;  // enabled PDR timeout
Alan Mishchenko committed
76 77 78 79
    p->fSilent           =       0;  // disables all output
    p->fVerbose          =       0;  // enables verbose reporting of statistics
    p->fVeryVerbose      =       0;  // enables very verbose reporting  
    p->TimeLimit         =       0;  // enables the timeout
Alan Mishchenko committed
80
    // internal parameters
Alan Mishchenko committed
81
    p->fReportSolution   =       0;  // enables specialized format for reporting solution
Alan Mishchenko committed
82 83 84 85 86 87 88 89 90 91 92 93 94
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
95
int Fra_FraigSec( Aig_Man_t * p, Fra_Sec_t * pParSec, Aig_Man_t ** ppResult )
Alan Mishchenko committed
96
{
Alan Mishchenko committed
97
    Ssw_Pars_t Pars2, * pPars2 = &Pars2;
Alan Mishchenko committed
98
    Fra_Ssw_t Pars, * pPars = &Pars;
Alan Mishchenko committed
99
    Fra_Sml_t * pSml;
Alan Mishchenko committed
100
    Aig_Man_t * pNew, * pTemp;
101
    int nFrames, RetValue, nIter;
102
    abctime clk, clkTotal = Abc_Clock();
Alan Mishchenko committed
103
    int TimeOut = 0;
Alan Mishchenko committed
104
    int fLatchCorr = 0;
Alan Mishchenko committed
105
    float TimeLeft = 0.0;
Alan Mishchenko committed
106
    pParSec->nSMnumber = -1;
Alan Mishchenko committed
107 108

    // try the miter before solving
Alan Mishchenko committed
109
    pNew = Aig_ManDupSimple( p );
Alan Mishchenko committed
110 111
    RetValue = Fra_FraigMiterStatus( pNew );
    if ( RetValue >= 0 )
Alan Mishchenko committed
112 113
        goto finish;

Alan Mishchenko committed
114 115 116
    // prepare parameters
    memset( pPars, 0, sizeof(Fra_Ssw_t) );
    pPars->fLatchCorr  = fLatchCorr;
Alan Mishchenko committed
117 118
    pPars->fVerbose = pParSec->fVeryVerbose;
    if ( pParSec->fVerbose )
Alan Mishchenko committed
119 120 121 122
    {
        printf( "Original miter:       Latches = %5d. Nodes = %6d.\n", 
            Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
    }
Alan Mishchenko committed
123
//Aig_ManDumpBlif( pNew, "after.blif", NULL, NULL );
Alan Mishchenko committed
124 125

    // perform sequential cleanup
126
clk = Abc_Clock();
Alan Mishchenko committed
127
    if ( pNew->nRegs )
Alan Mishchenko committed
128
    pNew = Aig_ManReduceLaches( pNew, 0 );
Alan Mishchenko committed
129
    if ( pNew->nRegs )
130
    pNew = Aig_ManConstReduce( pNew, 0, -1, -1, 0, 0 );
Alan Mishchenko committed
131
    if ( pParSec->fVerbose )
Alan Mishchenko committed
132 133 134
    {
        printf( "Sequential cleanup:   Latches = %5d. Nodes = %6d. ", 
            Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
135
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
136
    }
Alan Mishchenko committed
137 138 139
    RetValue = Fra_FraigMiterStatus( pNew );
    if ( RetValue >= 0 )
        goto finish;
Alan Mishchenko committed
140

Alan Mishchenko committed
141
    // perform phase abstraction
142
clk = Abc_Clock();
Alan Mishchenko committed
143
    if ( pParSec->fPhaseAbstract )
Alan Mishchenko committed
144 145
    {
        extern Aig_Man_t * Saig_ManPhaseAbstractAuto( Aig_Man_t * p, int fVerbose );
146 147
        pNew->nTruePis = Aig_ManCiNum(pNew) - Aig_ManRegNum(pNew); 
        pNew->nTruePos = Aig_ManCoNum(pNew) - Aig_ManRegNum(pNew); 
Alan Mishchenko committed
148 149
        pNew = Saig_ManPhaseAbstractAuto( pTemp = pNew, 0 );
        Aig_ManStop( pTemp );
Alan Mishchenko committed
150
        if ( pParSec->fVerbose )
Alan Mishchenko committed
151 152 153
        {
            printf( "Phase abstraction:    Latches = %5d. Nodes = %6d. ", 
                Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
154
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
155 156 157
        }
    }

Alan Mishchenko committed
158
    // perform forward retiming
Alan Mishchenko committed
159
    if ( pParSec->fRetimeFirst && pNew->nRegs )
Alan Mishchenko committed
160
    {
161
clk = Abc_Clock();
Alan Mishchenko committed
162 163
//    pNew = Rtm_ManRetime( pTemp = pNew, 1, 1000, 0 );
    pNew = Saig_ManRetimeForward( pTemp = pNew, 100, 0 );
Alan Mishchenko committed
164
    Aig_ManStop( pTemp );
Alan Mishchenko committed
165
    if ( pParSec->fVerbose )
Alan Mishchenko committed
166 167 168
    {
        printf( "Forward retiming:     Latches = %5d. Nodes = %6d. ", 
            Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
169
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
170 171
    }
    }
Alan Mishchenko committed
172
     
Alan Mishchenko committed
173
    // run latch correspondence
174
clk = Abc_Clock();
Alan Mishchenko committed
175 176
    if ( pNew->nRegs )
    {
Alan Mishchenko committed
177 178
    pNew = Aig_ManDupOrdered( pTemp = pNew );
//    pNew = Aig_ManDupDfs( pTemp = pNew );
Alan Mishchenko committed
179
    Aig_ManStop( pTemp );
Alan Mishchenko committed
180
/*
Alan Mishchenko committed
181
    if ( RetValue == -1 && pParSec->TimeLimit )
Alan Mishchenko committed
182
    {
183
        TimeLeft = (float)pParSec->TimeLimit - ((float)(Abc_Clock()-clkTotal)/(float)(CLOCKS_PER_SEC));
184
        TimeLeft = Abc_MaxInt( TimeLeft, 0.0 );
Alan Mishchenko committed
185 186
        if ( TimeLeft == 0.0 )
        {
Alan Mishchenko committed
187 188
            if ( !pParSec->fSilent )
                printf( "Runtime limit exceeded.\n" );
Alan Mishchenko committed
189
            RetValue = -1;
Alan Mishchenko committed
190
            TimeOut = 1;
Alan Mishchenko committed
191 192 193
            goto finish;
        }
    }
Alan Mishchenko committed
194
*/
Alan Mishchenko committed
195 196 197 198 199 200 201 202 203 204

//    pNew = Fra_FraigLatchCorrespondence( pTemp = pNew, 0, 1000, 1, pParSec->fVeryVerbose, &nIter, TimeLeft );
//Aig_ManDumpBlif( pNew, "ex.blif", NULL, NULL );
    Ssw_ManSetDefaultParamsLcorr( pPars2 );
    pNew = Ssw_LatchCorrespondence( pTemp = pNew, pPars2 );
    nIter = pPars2->nIters;

    // prepare parameters for scorr
    Ssw_ManSetDefaultParams( pPars2 );

Alan Mishchenko committed
205 206
    if ( pTemp->pSeqModel )
    {
207
        if ( !Saig_ManVerifyCex( pTemp, pTemp->pSeqModel ) )
Alan Mishchenko committed
208
            printf( "Fra_FraigSec(): Counter-example verification has FAILED.\n" );
Alan Mishchenko committed
209 210 211 212
        if ( Saig_ManPiNum(p) != Saig_ManPiNum(pTemp) )
            printf( "The counter-example is invalid because of phase abstraction.\n" );
        else
        {
Alan Mishchenko committed
213
        ABC_FREE( p->pSeqModel );
214
        p->pSeqModel = Abc_CexDup( pTemp->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
215
        ABC_FREE( pTemp->pSeqModel );
Alan Mishchenko committed
216 217
        }
    }
Alan Mishchenko committed
218 219
    if ( pNew == NULL )
    {
Alan Mishchenko committed
220 221 222
        if ( p->pSeqModel )
        {
            RetValue = 0;
Alan Mishchenko committed
223 224 225
            if ( !pParSec->fSilent )
            {
                printf( "Networks are NOT EQUIVALENT after simulation.   " );
226
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
227
            }
Alan Mishchenko committed
228 229 230
            if ( pParSec->fReportSolution && !pParSec->fRecursive )
            {
            printf( "SOLUTION: FAIL       " );
231
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
232
            }
Alan Mishchenko committed
233
            Aig_ManStop( pTemp );
Alan Mishchenko committed
234 235
            return RetValue;
        }
Alan Mishchenko committed
236 237
        pNew = pTemp;
        RetValue = -1;
Alan Mishchenko committed
238
        TimeOut = 1;
Alan Mishchenko committed
239 240
        goto finish;
    }
Alan Mishchenko committed
241
    Aig_ManStop( pTemp );
Alan Mishchenko committed
242

Alan Mishchenko committed
243
    if ( pParSec->fVerbose )
Alan Mishchenko committed
244 245 246
    {
        printf( "Latch-corr (I=%3d):   Latches = %5d. Nodes = %6d. ", 
            nIter, Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
247
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
248
    }
Alan Mishchenko committed
249
    }
Alan Mishchenko committed
250
/*
Alan Mishchenko committed
251
    if ( RetValue == -1 && pParSec->TimeLimit )
Alan Mishchenko committed
252
    {
253
        TimeLeft = (float)pParSec->TimeLimit - ((float)(Abc_Clock()-clkTotal)/(float)(CLOCKS_PER_SEC));
254
        TimeLeft = Abc_MaxInt( TimeLeft, 0.0 );
Alan Mishchenko committed
255 256
        if ( TimeLeft == 0.0 )
        {
Alan Mishchenko committed
257 258
            if ( !pParSec->fSilent )
                printf( "Runtime limit exceeded.\n" );
Alan Mishchenko committed
259
            RetValue = -1;
Alan Mishchenko committed
260
            TimeOut = 1;
Alan Mishchenko committed
261 262 263
            goto finish;
        }
    }
Alan Mishchenko committed
264
*/
Alan Mishchenko committed
265
    // perform fraiging
Alan Mishchenko committed
266
    if ( pParSec->fFraiging )
Alan Mishchenko committed
267
    {
268
clk = Abc_Clock();
Alan Mishchenko committed
269
    pNew = Fra_FraigEquivence( pTemp = pNew, 100, 0 );
Alan Mishchenko committed
270
    Aig_ManStop( pTemp );
Alan Mishchenko committed
271
    if ( pParSec->fVerbose )
Alan Mishchenko committed
272 273 274
    {
        printf( "Fraiging:             Latches = %5d. Nodes = %6d. ", 
            Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
275
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
276
    }
Alan Mishchenko committed
277
    }
Alan Mishchenko committed
278

Alan Mishchenko committed
279
    if ( pNew->nRegs == 0 )
Alan Mishchenko committed
280
        RetValue = Fra_FraigCec( &pNew, 100000, 0 );
Alan Mishchenko committed
281 282 283 284

    RetValue = Fra_FraigMiterStatus( pNew );
    if ( RetValue >= 0 )
        goto finish;
Alan Mishchenko committed
285
/*
Alan Mishchenko committed
286
    if ( RetValue == -1 && pParSec->TimeLimit )
Alan Mishchenko committed
287
    {
288
        TimeLeft = (float)pParSec->TimeLimit - ((float)(Abc_Clock()-clkTotal)/(float)(CLOCKS_PER_SEC));
289
        TimeLeft = Abc_MaxInt( TimeLeft, 0.0 );
Alan Mishchenko committed
290 291
        if ( TimeLeft == 0.0 )
        {
Alan Mishchenko committed
292 293
            if ( !pParSec->fSilent )
                printf( "Runtime limit exceeded.\n" );
Alan Mishchenko committed
294
            RetValue = -1;
Alan Mishchenko committed
295
            TimeOut = 1;
Alan Mishchenko committed
296 297 298
            goto finish;
        }
    }
Alan Mishchenko committed
299
*/
Alan Mishchenko committed
300
    // perform min-area retiming
Alan Mishchenko committed
301
    if ( pParSec->fRetimeRegs && pNew->nRegs )
Alan Mishchenko committed
302
    {
303
//    extern Aig_Man_t * Saig_ManRetimeMinArea( Aig_Man_t * p, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose );
304
clk = Abc_Clock();
305 306
    pNew->nTruePis = Aig_ManCiNum(pNew) - Aig_ManRegNum(pNew); 
    pNew->nTruePos = Aig_ManCoNum(pNew) - Aig_ManRegNum(pNew); 
Alan Mishchenko committed
307 308 309 310 311
//        pNew = Rtm_ManRetime( pTemp = pNew, 1, 1000, 0 );
    pNew = Saig_ManRetimeMinArea( pTemp = pNew, 1000, 0, 0, 1, 0 );
    Aig_ManStop( pTemp );
    pNew = Aig_ManDupOrdered( pTemp = pNew );
    Aig_ManStop( pTemp );
Alan Mishchenko committed
312
    if ( pParSec->fVerbose )
Alan Mishchenko committed
313 314 315
    {
    printf( "Min-reg retiming:     Latches = %5d. Nodes = %6d. ", 
        Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
316
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
317 318 319
    }
    }

Alan Mishchenko committed
320 321
    // perform seq sweeping while increasing the number of frames
    RetValue = Fra_FraigMiterStatus( pNew );
Alan Mishchenko committed
322
    if ( RetValue == -1 && pParSec->fInduction )
Alan Mishchenko committed
323
    for ( nFrames = 1; nFrames <= pParSec->nFramesMax; nFrames *= 2 )
Alan Mishchenko committed
324
    {
Alan Mishchenko committed
325
/*
Alan Mishchenko committed
326
        if ( RetValue == -1 && pParSec->TimeLimit )
Alan Mishchenko committed
327
        {
328
            TimeLeft = (float)pParSec->TimeLimit - ((float)(Abc_Clock()-clkTotal)/(float)(CLOCKS_PER_SEC));
329
            TimeLeft = Abc_MaxInt( TimeLeft, 0.0 );
Alan Mishchenko committed
330 331
            if ( TimeLeft == 0.0 )
            {
Alan Mishchenko committed
332 333
                if ( !pParSec->fSilent )
                    printf( "Runtime limit exceeded.\n" );
Alan Mishchenko committed
334
                RetValue = -1;
Alan Mishchenko committed
335
                TimeOut = 1;
Alan Mishchenko committed
336 337 338
                goto finish;
            }
        }
Alan Mishchenko committed
339 340
*/ 

341
clk = Abc_Clock();
Alan Mishchenko committed
342
        pPars->nFramesK = nFrames;
Alan Mishchenko committed
343
        pPars->TimeLimit = TimeLeft;
Alan Mishchenko committed
344
        pPars->fSilent = pParSec->fSilent;
Alan Mishchenko committed
345 346 347
//        pNew = Fra_FraigInduction( pTemp = pNew, pPars );

        pPars2->nFramesK = nFrames;
Alan Mishchenko committed
348 349 350 351 352 353 354 355 356 357 358 359 360
        pPars2->nBTLimit = pParSec->nBTLimit;
        pPars2->nBTLimitGlobal = pParSec->nBTLimitGlobal;
//        pPars2->nBTLimit = 1000 * nFrames;

        if ( RetValue == -1 && pPars2->nConflicts > pPars2->nBTLimitGlobal )
        {
            if ( !pParSec->fSilent )
                printf( "Global conflict limit (%d) exceeded.\n", pPars2->nBTLimitGlobal );
            RetValue = -1;
            TimeOut = 1;
            goto finish;
        }

Alan Mishchenko committed
361
        Aig_ManSetRegNum( pNew, pNew->nRegs );
Alan Mishchenko committed
362 363
//        pNew = Ssw_SignalCorrespondence( pTemp = pNew, pPars2 );
        if ( Aig_ManRegNum(pNew) > 0 )
364
            pNew = Ssw_SignalCorrespondence( pTemp = pNew, pPars2 );
Alan Mishchenko committed
365
        else
366
            pNew = Aig_ManDupSimpleDfs( pTemp = pNew );
Alan Mishchenko committed
367

Alan Mishchenko committed
368 369 370 371
        if ( pNew == NULL )
        {
            pNew = pTemp;
            RetValue = -1;
Alan Mishchenko committed
372
            TimeOut = 1;
Alan Mishchenko committed
373 374
            goto finish;
        }
Alan Mishchenko committed
375 376 377

//        printf( "Total conflicts = %d.\n", pPars2->nConflicts );

Alan Mishchenko committed
378 379
        Aig_ManStop( pTemp );
        RetValue = Fra_FraigMiterStatus( pNew );
Alan Mishchenko committed
380
        if ( pParSec->fVerbose )
Alan Mishchenko committed
381 382
        { 
            printf( "K-step (K=%2d,I=%3d):  Latches = %5d. Nodes = %6d. ", 
Alan Mishchenko committed
383
                nFrames, pPars2->nIters, Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
384
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
385 386 387
        }
        if ( RetValue != -1 )
            break;
Alan Mishchenko committed
388

Alan Mishchenko committed
389
        // perform retiming
Alan Mishchenko committed
390
//        if ( pParSec->fRetimeFirst && pNew->nRegs )
Alan Mishchenko committed
391
        if ( pNew->nRegs )
Alan Mishchenko committed
392
        {
393
//        extern Aig_Man_t * Saig_ManRetimeMinArea( Aig_Man_t * p, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose );
394
clk = Abc_Clock();
395 396
        pNew->nTruePis = Aig_ManCiNum(pNew) - Aig_ManRegNum(pNew); 
        pNew->nTruePos = Aig_ManCoNum(pNew) - Aig_ManRegNum(pNew); 
Alan Mishchenko committed
397 398
//        pNew = Rtm_ManRetime( pTemp = pNew, 1, 1000, 0 );
        pNew = Saig_ManRetimeMinArea( pTemp = pNew, 1000, 0, 0, 1, 0 );
Alan Mishchenko committed
399
        Aig_ManStop( pTemp );
Alan Mishchenko committed
400
        pNew = Aig_ManDupOrdered( pTemp = pNew );
Alan Mishchenko committed
401
        Aig_ManStop( pTemp );
Alan Mishchenko committed
402
        if ( pParSec->fVerbose )
Alan Mishchenko committed
403
        {
Alan Mishchenko committed
404
            printf( "Min-reg retiming:     Latches = %5d. Nodes = %6d. ", 
Alan Mishchenko committed
405
                Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
406
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
407
        }
Alan Mishchenko committed
408
        }  
Alan Mishchenko committed
409

Alan Mishchenko committed
410
        if ( pNew->nRegs )
411
            pNew = Aig_ManConstReduce( pNew, 0, -1, -1, 0, 0 );
Alan Mishchenko committed
412

Alan Mishchenko committed
413
        // perform rewriting
414
clk = Abc_Clock();
Alan Mishchenko committed
415 416 417
        pNew = Aig_ManDupOrdered( pTemp = pNew );
        Aig_ManStop( pTemp );
//        pNew = Dar_ManRewriteDefault( pTemp = pNew );
Alan Mishchenko committed
418
        pNew = Dar_ManCompress2( pTemp = pNew, 1, 0, 1, 0, 0 ); 
Alan Mishchenko committed
419
        Aig_ManStop( pTemp );
Alan Mishchenko committed
420
        if ( pParSec->fVerbose )
Alan Mishchenko committed
421 422 423
        {
            printf( "Rewriting:            Latches = %5d. Nodes = %6d. ", 
                Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
424
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
425 426
        } 

Alan Mishchenko committed
427
        // perform sequential simulation
Alan Mishchenko committed
428 429
        if ( pNew->nRegs )
        {
430
clk = Abc_Clock();
Alan Mishchenko committed
431
        pSml = Fra_SmlSimulateSeq( pNew, 0, 128 * nFrames, 1 + 16/(1+Aig_ManNodeNum(pNew)/1000), 1  ); 
Alan Mishchenko committed
432
        if ( pParSec->fVerbose )
Alan Mishchenko committed
433 434 435
        {
            printf( "Seq simulation  :     Latches = %5d. Nodes = %6d. ", 
                Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
436
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
437 438 439
        }
        if ( pSml->fNonConstOut )
        {
Alan Mishchenko committed
440 441 442 443 444 445
            pNew->pSeqModel = Fra_SmlGetCounterExample( pSml );
            // transfer to the original manager
            if ( Saig_ManPiNum(p) != Saig_ManPiNum(pNew) )
                printf( "The counter-example is invalid because of phase abstraction.\n" );
            else
            {
Alan Mishchenko committed
446
            ABC_FREE( p->pSeqModel );
447
            p->pSeqModel = Abc_CexDup( pNew->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
448
            ABC_FREE( pNew->pSeqModel );
Alan Mishchenko committed
449 450
            }

Alan Mishchenko committed
451 452 453
            Fra_SmlStop( pSml );
            Aig_ManStop( pNew );
            RetValue = 0;
Alan Mishchenko committed
454 455 456
            if ( !pParSec->fSilent )
            {
                printf( "Networks are NOT EQUIVALENT after simulation.   " );
457
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
458
            }
Alan Mishchenko committed
459 460 461
            if ( pParSec->fReportSolution && !pParSec->fRecursive )
            {
            printf( "SOLUTION: FAIL       " );
462
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
463
            }
Alan Mishchenko committed
464 465 466
            return RetValue;
        }
        Fra_SmlStop( pSml );
Alan Mishchenko committed
467
        }
Alan Mishchenko committed
468
    }
Alan Mishchenko committed
469

Alan Mishchenko committed
470 471 472
    // get the miter status
    RetValue = Fra_FraigMiterStatus( pNew );

Alan Mishchenko committed
473
    // try interplation
474
clk = Abc_Clock();
Alan Mishchenko committed
475 476
    Aig_ManSetRegNum( pNew, Aig_ManRegNum(pNew) );
    if ( pParSec->fInterpolation && RetValue == -1 && Aig_ManRegNum(pNew) > 0 )
Alan Mishchenko committed
477
    {
Alan Mishchenko committed
478
        Inter_ManParams_t Pars, * pPars = &Pars;
Alan Mishchenko committed
479
        int Depth;
Alan Mishchenko committed
480
        ABC_FREE( pNew->pSeqModel );
Alan Mishchenko committed
481
        Inter_ManSetDefaultParams( pPars );
Alan Mishchenko committed
482
//        pPars->nBTLimit = 100;
Alan Mishchenko committed
483
        pPars->nBTLimit = pParSec->nBTLimitInter;
Alan Mishchenko committed
484
        pPars->fVerbose = pParSec->fVeryVerbose;
Alan Mishchenko committed
485 486 487 488
        if ( Saig_ManPoNum(pNew) == 1 )
        {
            RetValue = Inter_ManPerformInterpolation( pNew, pPars, &Depth );
        }
Alan Mishchenko committed
489 490
        else if ( pParSec->fInterSeparate )
        {
491
            Abc_Cex_t * pCex = NULL;
Alan Mishchenko committed
492 493 494 495 496 497 498
            Aig_Man_t * pTemp, * pAux;
            Aig_Obj_t * pObjPo;
            int i, Counter = 0;
            Saig_ManForEachPo( pNew, pObjPo, i )
            { 
                if ( Aig_ObjFanin0(pObjPo) == Aig_ManConst1(pNew) )
                    continue;
499 500
                if ( pPars->fVerbose )
                    printf( "Solving output %2d (out of %2d):\n", i, Saig_ManPoNum(pNew) );
Alan Mishchenko committed
501
                pTemp = Aig_ManDupOneOutput( pNew, i, 1 );
502
                pTemp = Aig_ManScl( pAux = pTemp, 1, 1, 0, -1, -1, 0, 0 );
Alan Mishchenko committed
503 504 505 506 507 508
                Aig_ManStop( pAux );
                if ( Saig_ManRegNum(pTemp) > 0 )
                {
                    RetValue = Inter_ManPerformInterpolation( pTemp, pPars, &Depth );
                    if ( pTemp->pSeqModel )
                    {
509
                        pCex = p->pSeqModel = Abc_CexDup( pTemp->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
                        pCex->iPo = i;
                        Aig_ManStop( pTemp );
                        break;
                    }
                    // if solved, remove the output
                    if ( RetValue == 1 )
                    {
                        Aig_ObjPatchFanin0( pNew, pObjPo, Aig_ManConst0(pNew) );
    //                    printf( "Output %3d : Solved ", i );
                    }
                    else
                    {
                        Counter++;
    //                    printf( "Output %3d : Undec  ", i );
                    }
                }
                else
                    Counter++;
//                Aig_ManPrintStats( pTemp );
                Aig_ManStop( pTemp );
                printf( "Solving output %3d (out of %3d) using interpolation.\r", i, Saig_ManPoNum(pNew) );
            }
            Aig_ManCleanup( pNew );
Alan Mishchenko committed
533
            if ( pCex == NULL )
Alan Mishchenko committed
534 535 536 537 538 539 540
            {
                printf( "Interpolation left %d (out of %d) outputs unsolved              \n", Counter, Saig_ManPoNum(pNew) );
                if ( Counter )
                    RetValue = -1;
            }
            pNew = Aig_ManDupUnsolvedOutputs( pTemp = pNew, 1 );
            Aig_ManStop( pTemp );
541
            pNew = Aig_ManScl( pTemp = pNew, 1, 1, 0, -1, -1, 0, 0 );
Alan Mishchenko committed
542 543
            Aig_ManStop( pTemp );
        }
Alan Mishchenko committed
544 545
        else
        {
546
            Aig_Man_t * pNewOrpos = Saig_ManDupOrpos( pNew );
Alan Mishchenko committed
547 548 549
            RetValue = Inter_ManPerformInterpolation( pNewOrpos, pPars, &Depth );
            if ( pNewOrpos->pSeqModel )
            {
550
                Abc_Cex_t * pCex;
Alan Mishchenko committed
551
                pCex = pNew->pSeqModel = pNewOrpos->pSeqModel; pNewOrpos->pSeqModel = NULL;
552
                pCex->iPo = Saig_ManFindFailedPoCex( pNew, pNew->pSeqModel );
Alan Mishchenko committed
553 554 555
            }
            Aig_ManStop( pNewOrpos );
        }
Alan Mishchenko committed
556

Alan Mishchenko committed
557
        if ( pParSec->fVerbose )
Alan Mishchenko committed
558 559 560 561
        {
        if ( RetValue == 1 )
            printf( "Property proved using interpolation.  " );
        else if ( RetValue == 0 )
Alan Mishchenko committed
562
            printf( "Property DISPROVED in frame %d using interpolation.  ", Depth );
Alan Mishchenko committed
563 564 565 566
        else if ( RetValue == -1 )
            printf( "Property UNDECIDED after interpolation.  " );
        else
            assert( 0 ); 
567
ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
568 569 570
        }
    }

Alan Mishchenko committed
571
    // try reachability analysis
Alan Mishchenko committed
572
    if ( pParSec->fReachability && RetValue == -1 && Aig_ManRegNum(pNew) > 0 && Aig_ManRegNum(pNew) < pParSec->nBddVarsMax )
Alan Mishchenko committed
573
    {
574 575 576 577 578 579 580 581 582 583
        Saig_ParBbr_t Pars, * pPars = &Pars;
        Bbr_ManSetDefaultParams( pPars );
        pPars->TimeLimit     = 0;
        pPars->nBddMax       = pParSec->nBddMax;
        pPars->nIterMax      = pParSec->nBddIterMax;
        pPars->fPartition    = 1;
        pPars->fReorder      = 1;
        pPars->fReorderImage = 1;
        pPars->fVerbose      = 0;
        pPars->fSilent       = pParSec->fSilent;
584 585
        pNew->nTruePis = Aig_ManCiNum(pNew) - Aig_ManRegNum(pNew); 
        pNew->nTruePos = Aig_ManCoNum(pNew) - Aig_ManRegNum(pNew); 
586
        RetValue = Aig_ManVerifyUsingBdds( pNew, pPars );
Alan Mishchenko committed
587 588
    }

589 590 591 592 593 594 595 596 597
    // try PDR
    if ( pParSec->fUsePdr && RetValue == -1 && Aig_ManRegNum(pNew) > 0 )
    {
        Pdr_Par_t Pars, * pPars = &Pars;
        Pdr_ManSetDefaultParams( pPars );
        pPars->nTimeOut = pParSec->nPdrTimeout;
        pPars->fVerbose = pParSec->fVerbose;
        if ( pParSec->fVerbose )
            printf( "Running property directed reachability...\n" );
598 599 600
        RetValue = Pdr_ManSolve( pNew, pPars );
        if ( pNew->pSeqModel )
            pNew->pSeqModel->iPo = Saig_ManFindFailedPoCex( pNew, pNew->pSeqModel );
601 602
    }

Alan Mishchenko committed
603
finish:
Alan Mishchenko committed
604 605
    // report the miter
    if ( RetValue == 1 )
Alan Mishchenko committed
606
    {
Alan Mishchenko committed
607 608 609
        if ( !pParSec->fSilent )
        {
            printf( "Networks are equivalent.   " );
610
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
611
        }
Alan Mishchenko committed
612 613 614
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: PASS       " );
615
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
616
        }
Alan Mishchenko committed
617
    }
Alan Mishchenko committed
618
    else if ( RetValue == 0 )
Alan Mishchenko committed
619
    {
620 621 622 623 624 625 626 627 628
        if ( pNew->pSeqModel == NULL )
        {
            int i;
            // if the CEX is not derives, it is because tricial CEX should be assumed
            pNew->pSeqModel = Abc_CexAlloc( Aig_ManRegNum(pNew), pNew->nTruePis, 1 );
            // if the CEX does not work, we need to change PIs to 1 because 
            // the only way it can happen is when a PO is equal to a PI...
            if ( Saig_ManFindFailedPoCex( pNew, pNew->pSeqModel ) == -1 )
                for ( i = 0; i < pNew->nTruePis; i++ )
629
                    Abc_InfoSetBit( pNew->pSeqModel->pData, i );
630
        }
Alan Mishchenko committed
631 632 633
        if ( !pParSec->fSilent )
        {
            printf( "Networks are NOT EQUIVALENT.   " );
634
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
635
        }
Alan Mishchenko committed
636 637 638
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: FAIL       " );
639
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
640
        }
Alan Mishchenko committed
641
    }
Alan Mishchenko committed
642
    else 
Alan Mishchenko committed
643
    {
Alan Mishchenko committed
644 645 646 647 648
        ///////////////////////////////////
        // save intermediate result
        extern void Abc_FrameSetSave1( void * pAig );
        Abc_FrameSetSave1( Aig_ManDupSimple(pNew) );
        ///////////////////////////////////
Alan Mishchenko committed
649 650 651
        if ( !pParSec->fSilent )
        {
            printf( "Networks are UNDECIDED.   " );
652
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
653
        }
Alan Mishchenko committed
654 655 656
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: UNDECIDED  " );
657
ABC_PRT( "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
658
        }
Alan Mishchenko committed
659
        if ( !TimeOut && !pParSec->fSilent )
Alan Mishchenko committed
660 661 662
        {
            static int Counter = 1;
            char pFileName[1000];
Alan Mishchenko committed
663 664
            pParSec->nSMnumber = Counter;
            sprintf( pFileName, "sm%02d.aig", Counter++ );
Alan Mishchenko committed
665 666 667
            Ioa_WriteAiger( pNew, pFileName, 0, 0 );
            printf( "The unsolved reduced miter is written into file \"%s\".\n", pFileName );
        }
Alan Mishchenko committed
668
    }
Alan Mishchenko committed
669 670 671 672 673 674
    if ( pNew->pSeqModel )
    {
        if ( Saig_ManPiNum(p) != Saig_ManPiNum(pNew) )
            printf( "The counter-example is invalid because of phase abstraction.\n" );
        else
        {
Alan Mishchenko committed
675
        ABC_FREE( p->pSeqModel );
676
        p->pSeqModel = Abc_CexDup( pNew->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
677
        ABC_FREE( pNew->pSeqModel );
Alan Mishchenko committed
678 679
        }
    }
Alan Mishchenko committed
680 681
    if ( ppResult != NULL )
        *ppResult = Aig_ManDupSimpleDfs( pNew );
Alan Mishchenko committed
682 683
    if ( pNew )
        Aig_ManStop( pNew );
Alan Mishchenko committed
684 685 686
    return RetValue;
}

Alan Mishchenko committed
687 688 689 690 691
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


692 693
ABC_NAMESPACE_IMPL_END