fraSec.c 23.9 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"
Alan Mishchenko committed
22
#include "ioa.h"
Alan Mishchenko committed
23
#include "int.h"
Alan Mishchenko committed
24
#include "ssw.h"
Alan Mishchenko committed
25
#include "saig.h"
26
#include "bbr.h"
27
#include "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;
Alan Mishchenko committed
101
    int nFrames, RetValue, nIter, clk, clkTotal = clock();
Alan Mishchenko committed
102
    int TimeOut = 0;
Alan Mishchenko committed
103
    int fLatchCorr = 0;
Alan Mishchenko committed
104
    float TimeLeft = 0.0;
Alan Mishchenko committed
105
    pParSec->nSMnumber = -1;
Alan Mishchenko committed
106 107

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

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

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

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

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

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

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

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

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

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

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

        pPars2->nFramesK = nFrames;
Alan Mishchenko committed
347 348 349 350 351 352 353 354 355 356 357 358 359
        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
360
        Aig_ManSetRegNum( pNew, pNew->nRegs );
Alan Mishchenko committed
361 362
//        pNew = Ssw_SignalCorrespondence( pTemp = pNew, pPars2 );
        if ( Aig_ManRegNum(pNew) > 0 )
363
            pNew = Ssw_SignalCorrespondence( pTemp = pNew, pPars2 );
Alan Mishchenko committed
364
        else
365
            pNew = Aig_ManDupSimpleDfs( pTemp = pNew );
Alan Mishchenko committed
366

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

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

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

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

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

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

Alan Mishchenko committed
426
        // perform sequential simulation
Alan Mishchenko committed
427 428
        if ( pNew->nRegs )
        {
Alan Mishchenko committed
429
clk = clock();
Alan Mishchenko committed
430
        pSml = Fra_SmlSimulateSeq( pNew, 0, 128 * nFrames, 1 + 16/(1+Aig_ManNodeNum(pNew)/1000), 1  ); 
Alan Mishchenko committed
431
        if ( pParSec->fVerbose )
Alan Mishchenko committed
432 433 434
        {
            printf( "Seq simulation  :     Latches = %5d. Nodes = %6d. ", 
                Aig_ManRegNum(pNew), Aig_ManNodeNum(pNew) );
Alan Mishchenko committed
435
ABC_PRT( "Time", clock() - clk );
Alan Mishchenko committed
436 437 438
        }
        if ( pSml->fNonConstOut )
        {
Alan Mishchenko committed
439 440 441 442 443 444
            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
445
            ABC_FREE( p->pSeqModel );
446
            p->pSeqModel = Abc_CexDup( pNew->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
447
            ABC_FREE( pNew->pSeqModel );
Alan Mishchenko committed
448 449
            }

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

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

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

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

Alan Mishchenko committed
570
    // try reachability analysis
Alan Mishchenko committed
571
    if ( pParSec->fReachability && RetValue == -1 && Aig_ManRegNum(pNew) > 0 && Aig_ManRegNum(pNew) < pParSec->nBddVarsMax )
Alan Mishchenko committed
572
    {
573 574 575 576 577 578 579 580 581 582
        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;
Alan Mishchenko committed
583 584
        pNew->nTruePis = Aig_ManPiNum(pNew) - Aig_ManRegNum(pNew); 
        pNew->nTruePos = Aig_ManPoNum(pNew) - Aig_ManRegNum(pNew); 
585
        RetValue = Aig_ManVerifyUsingBdds( pNew, pPars );
Alan Mishchenko committed
586 587
    }

588 589 590 591 592 593 594 595 596 597 598 599 600
    // try PDR
    if ( pParSec->fUsePdr && RetValue == -1 && Aig_ManRegNum(pNew) > 0 )
    {
        Abc_Cex_t * pCex = NULL;
        Aig_Man_t * pNewOrpos = Saig_ManDupOrpos( pNew );
        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" );
        RetValue = Pdr_ManSolve( pNewOrpos, pPars, &pCex );
        if ( pCex )
601
            pCex->iPo = Saig_ManFindFailedPoCex( pNew, pCex );
602 603 604 605
        Aig_ManStop( pNewOrpos );
        pNew->pSeqModel = pCex;
    }

Alan Mishchenko committed
606
finish:
Alan Mishchenko committed
607 608
    // report the miter
    if ( RetValue == 1 )
Alan Mishchenko committed
609
    {
Alan Mishchenko committed
610 611 612
        if ( !pParSec->fSilent )
        {
            printf( "Networks are equivalent.   " );
Alan Mishchenko committed
613
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
614
        }
Alan Mishchenko committed
615 616 617
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: PASS       " );
Alan Mishchenko committed
618
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
619
        }
Alan Mishchenko committed
620
    }
Alan Mishchenko committed
621
    else if ( RetValue == 0 )
Alan Mishchenko committed
622
    {
623 624 625 626 627 628 629 630 631 632 633
        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++ )
                    Aig_InfoSetBit( pNew->pSeqModel->pData, i );
        }
Alan Mishchenko committed
634 635 636
        if ( !pParSec->fSilent )
        {
            printf( "Networks are NOT EQUIVALENT.   " );
Alan Mishchenko committed
637
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
638
        }
Alan Mishchenko committed
639 640 641
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: FAIL       " );
Alan Mishchenko committed
642
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
643
        }
Alan Mishchenko committed
644
    }
Alan Mishchenko committed
645
    else 
Alan Mishchenko committed
646
    {
Alan Mishchenko committed
647 648 649 650 651
        ///////////////////////////////////
        // save intermediate result
        extern void Abc_FrameSetSave1( void * pAig );
        Abc_FrameSetSave1( Aig_ManDupSimple(pNew) );
        ///////////////////////////////////
Alan Mishchenko committed
652 653 654
        if ( !pParSec->fSilent )
        {
            printf( "Networks are UNDECIDED.   " );
Alan Mishchenko committed
655
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
656
        }
Alan Mishchenko committed
657 658 659
        if ( pParSec->fReportSolution && !pParSec->fRecursive )
        {
        printf( "SOLUTION: UNDECIDED  " );
Alan Mishchenko committed
660
ABC_PRT( "Time", clock() - clkTotal );
Alan Mishchenko committed
661
        }
Alan Mishchenko committed
662
        if ( !TimeOut && !pParSec->fSilent )
Alan Mishchenko committed
663 664 665
        {
            static int Counter = 1;
            char pFileName[1000];
Alan Mishchenko committed
666 667
            pParSec->nSMnumber = Counter;
            sprintf( pFileName, "sm%02d.aig", Counter++ );
Alan Mishchenko committed
668 669 670
            Ioa_WriteAiger( pNew, pFileName, 0, 0 );
            printf( "The unsolved reduced miter is written into file \"%s\".\n", pFileName );
        }
Alan Mishchenko committed
671
    }
Alan Mishchenko committed
672 673 674 675 676 677
    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
678
        ABC_FREE( p->pSeqModel );
679
        p->pSeqModel = Abc_CexDup( pNew->pSeqModel, Aig_ManRegNum(p) );
Alan Mishchenko committed
680
        ABC_FREE( pNew->pSeqModel );
Alan Mishchenko committed
681 682
        }
    }
Alan Mishchenko committed
683 684
    if ( ppResult != NULL )
        *ppResult = Aig_ManDupSimpleDfs( pNew );
Alan Mishchenko committed
685 686
    if ( pNew )
        Aig_ManStop( pNew );
Alan Mishchenko committed
687 688 689
    return RetValue;
}

Alan Mishchenko committed
690 691 692 693 694
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


695 696
ABC_NAMESPACE_IMPL_END