sswSemi.c 9.97 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [sswSemi.c]
Alan Mishchenko committed
4 5 6 7 8

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Inductive prover with constraints.]

9
  Synopsis    [Semiformal for equivalence classes.]
Alan Mishchenko committed
10 11 12 13 14 15 16

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - September 1, 2008.]

Alan Mishchenko committed
17
  Revision    [$Id: sswSemi.c,v 1.00 2008/09/01 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20 21 22

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

#include "sswInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
30
typedef struct Ssw_Sem_t_ Ssw_Sem_t; // BMC manager
Alan Mishchenko committed
31

Alan Mishchenko committed
32
struct Ssw_Sem_t_
Alan Mishchenko committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
    // parameters
    int              nConfMaxStart;  // the starting conflict limit
    int              nConfMax;       // the intermediate conflict limit
    int              nFramesSweep;   // the number of frames to sweep
    int              fVerbose;       // prints output statistics
    // equivalences considered
    Ssw_Man_t *      pMan;           // SAT sweeping manager
    Vec_Ptr_t *      vTargets;       // the nodes that are watched
    // storage for patterns
    int              nPatternsAlloc; // the max number of interesting states
    int              nPatterns;      // the number of patterns
    Vec_Ptr_t *      vPatterns;      // storage for the interesting states
    Vec_Int_t *      vHistory;       // what state and how many steps
};

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
64
Ssw_Sem_t * Ssw_SemManStart( Ssw_Man_t * pMan, int nConfMax, int fVerbose )
Alan Mishchenko committed
65
{
Alan Mishchenko committed
66
    Ssw_Sem_t * p;
Alan Mishchenko committed
67 68 69
    Aig_Obj_t * pObj;
    int i;
    // create interpolation manager
70
    p = ABC_ALLOC( Ssw_Sem_t, 1 );
Alan Mishchenko committed
71
    memset( p, 0, sizeof(Ssw_Sem_t) );
Alan Mishchenko committed
72 73
    p->nConfMaxStart  = nConfMax;
    p->nConfMax       = nConfMax;
74
    p->nFramesSweep   = Abc_MaxInt( (1<<21)/Aig_ManNodeNum(pMan->pAig), pMan->nFrames );
Alan Mishchenko committed
75 76 77 78 79 80 81 82 83
    p->fVerbose       = fVerbose;
    // equivalences considered
    p->pMan           = pMan;
    p->vTargets       = Vec_PtrAlloc( Saig_ManPoNum(p->pMan->pAig) );
    Saig_ManForEachPo( p->pMan->pAig, pObj, i )
        Vec_PtrPush( p->vTargets, Aig_ObjFanin0(pObj) );
    // storage for patterns
    p->nPatternsAlloc = 512;
    p->nPatterns      = 1;
84 85
    p->vPatterns      = Vec_PtrAllocSimInfo( Aig_ManRegNum(p->pMan->pAig), Abc_BitWordNum(p->nPatternsAlloc) );
    Vec_PtrCleanSimInfo( p->vPatterns, 0, Abc_BitWordNum(p->nPatternsAlloc) );
Alan Mishchenko committed
86 87 88
    p->vHistory       = Vec_IntAlloc( 100 );
    Vec_IntPush( p->vHistory, 0 );
    // update arrays of the manager
Alan Mishchenko committed
89 90
    assert( 0 );
/*
Alan Mishchenko committed
91
    ABC_FREE( p->pMan->pNodeToFrames );
Alan Mishchenko committed
92
    Vec_IntFree( p->pMan->vSatVars );
Alan Mishchenko committed
93
    p->pMan->pNodeToFrames = ABC_CALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p->pMan->pAig) * p->nFramesSweep );
Alan Mishchenko committed
94
    p->pMan->vSatVars      = Vec_IntStart( Aig_ManObjNumMax(p->pMan->pAig) * (p->nFramesSweep+1) );
Alan Mishchenko committed
95
*/
Alan Mishchenko committed
96 97 98 99 100 101 102 103
    return p;
}

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

  Synopsis    []

  Description []
104

Alan Mishchenko committed
105 106 107 108 109
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
110
void Ssw_SemManStop( Ssw_Sem_t * p )
Alan Mishchenko committed
111 112 113 114
{
    Vec_PtrFree( p->vTargets );
    Vec_PtrFree( p->vPatterns );
    Vec_IntFree( p->vHistory );
Alan Mishchenko committed
115
    ABC_FREE( p );
Alan Mishchenko committed
116 117 118 119 120 121 122
}

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

  Synopsis    []

  Description []
123

Alan Mishchenko committed
124 125 126 127 128
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
129
int Ssw_SemCheckTargets( Ssw_Sem_t * p )
Alan Mishchenko committed
130 131 132
{
    Aig_Obj_t * pObj;
    int i;
133
    Vec_PtrForEachEntry( Aig_Obj_t *, p->vTargets, pObj, i )
Alan Mishchenko committed
134 135 136 137 138 139 140 141 142 143
        if ( !Ssw_ObjIsConst1Cand(p->pMan->pAig, pObj) )
            return 1;
    return 0;
}

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

  Synopsis    []

  Description []
144

Alan Mishchenko committed
145 146 147 148 149
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
150
void Ssw_ManFilterBmcSavePattern( Ssw_Sem_t * p )
Alan Mishchenko committed
151 152 153 154 155 156 157 158
{
    unsigned * pInfo;
    Aig_Obj_t * pObj;
    int i;
    if ( p->nPatterns >= p->nPatternsAlloc )
        return;
    Saig_ManForEachLo( p->pMan->pAig, pObj, i )
    {
159
        pInfo = (unsigned *)Vec_PtrEntry( p->vPatterns, i );
160 161
        if ( Abc_InfoHasBit( p->pMan->pPatWords, Saig_ManPiNum(p->pMan->pAig) + i ) )
            Abc_InfoSetBit( pInfo, p->nPatterns );
Alan Mishchenko committed
162 163 164 165 166 167 168 169 170
    }
    p->nPatterns++;
}

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

  Synopsis    [Performs fraiging for the internal nodes.]

  Description []
171

Alan Mishchenko committed
172 173 174 175 176
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
177
int Ssw_ManFilterBmc( Ssw_Sem_t * pBmc, int iPat, int fCheckTargets )
Alan Mishchenko committed
178 179 180 181
{
    Ssw_Man_t * p = pBmc->pMan;
    Aig_Obj_t * pObj, * pObjNew, * pObjLi, * pObjLo;
    unsigned * pInfo;
182
    int i, f, RetValue, fFirst = 0;
183 184
    abctime clk;
clk = Abc_Clock();
Alan Mishchenko committed
185 186 187 188 189

    // start initialized timeframes
    p->pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * 3 );
    Saig_ManForEachLo( p->pAig, pObj, i )
    {
190
        pInfo = (unsigned *)Vec_PtrEntry( pBmc->vPatterns, i );
191
        pObjNew = Aig_NotCond( Aig_ManConst1(p->pFrames), !Abc_InfoHasBit(pInfo, iPat) );
Alan Mishchenko committed
192 193 194 195 196 197 198 199 200 201
        Ssw_ObjSetFrame( p, pObj, 0, pObjNew );
    }

    // sweep internal nodes
    RetValue = pBmc->nFramesSweep;
    for ( f = 0; f < pBmc->nFramesSweep; f++ )
    {
        // map constants and PIs
        Ssw_ObjSetFrame( p, Aig_ManConst1(p->pAig), f, Aig_ManConst1(p->pFrames) );
        Saig_ManForEachPi( p->pAig, pObj, i )
202
            Ssw_ObjSetFrame( p, pObj, f, Aig_ObjCreateCi(p->pFrames) );
Alan Mishchenko committed
203 204 205 206 207
        // sweep internal nodes
        Aig_ManForEachNode( p->pAig, pObj, i )
        {
            pObjNew = Aig_And( p->pFrames, Ssw_ObjChild0Fra(p, pObj, f), Ssw_ObjChild1Fra(p, pObj, f) );
            Ssw_ObjSetFrame( p, pObj, f, pObjNew );
208
            if ( Ssw_ManSweepNode( p, pObj, f, 1, NULL ) )
Alan Mishchenko committed
209 210 211 212 213 214
            {
                Ssw_ManFilterBmcSavePattern( pBmc );
                if ( fFirst == 0 )
                {
                    fFirst = 1;
                    pBmc->nConfMax *= 10;
215
                }
Alan Mishchenko committed
216
            }
Alan Mishchenko committed
217
            if ( f > 0 && p->pMSat->pSat->stats.conflicts >= pBmc->nConfMax )
Alan Mishchenko committed
218 219 220 221 222 223
            {
                RetValue = -1;
                break;
            }
        }
        // quit if this is the last timeframe
Alan Mishchenko committed
224
        if ( p->pMSat->pSat->stats.conflicts >= pBmc->nConfMax )
Alan Mishchenko committed
225 226 227 228
        {
            RetValue += f + 1;
            break;
        }
Alan Mishchenko committed
229
        if ( fCheckTargets && Ssw_SemCheckTargets( pBmc ) )
Alan Mishchenko committed
230 231 232 233 234 235 236
            break;
        // transfer latch input to the latch outputs 
        // build logic cones for register outputs
        Saig_ManForEachLiLo( p->pAig, pObjLi, pObjLo, i )
        {
            pObjNew = Ssw_ObjChild0Fra(p, pObjLi,f);
            Ssw_ObjSetFrame( p, pObjLo, f+1, pObjNew );
Alan Mishchenko committed
237
            Ssw_CnfNodeAddToSolver( p->pMSat, Aig_Regular(pObjNew) );
Alan Mishchenko committed
238
        }
239
//Abc_Print( 1, "Frame %2d : Conflicts = %6d. \n", f, p->pSat->stats.conflicts );
Alan Mishchenko committed
240 241 242 243 244 245
    }
    if ( fFirst )
        pBmc->nConfMax /= 10;

    // cleanup
    Ssw_ClassesCheck( p->ppClasses );
246
p->timeBmc += Abc_Clock() - clk;
Alan Mishchenko committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260
    return RetValue;
}

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

  Synopsis    [Returns 1 if one of the targets has failed.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
261
int Ssw_FilterUsingSemi( Ssw_Man_t * pMan, int fCheckTargets, int nConfMax, int fVerbose )
Alan Mishchenko committed
262
{
Alan Mishchenko committed
263
    Ssw_Sem_t * p;
264
    int RetValue, Frames, Iter;
265
    abctime clk = Abc_Clock();
Alan Mishchenko committed
266 267
    p = Ssw_SemManStart( pMan, nConfMax, fVerbose );
    if ( fCheckTargets && Ssw_SemCheckTargets( p ) )
Alan Mishchenko committed
268 269
    {
        assert( 0 );
Alan Mishchenko committed
270
        Ssw_SemManStop( p );
Alan Mishchenko committed
271 272 273 274
        return 1;
    }
    if ( fVerbose )
    {
275 276
        Abc_Print( 1, "AIG : C = %6d. Cl = %6d. Nodes = %6d.  ConfMax = %6d. FramesMax = %6d.\n",
            Ssw_ClassesCand1Num(p->pMan->ppClasses), Ssw_ClassesClassNum(p->pMan->ppClasses),
Alan Mishchenko committed
277
            Aig_ManNodeNum(p->pMan->pAig), p->nConfMax, p->nFramesSweep );
278
    }
Alan Mishchenko committed
279 280 281
    RetValue = 0;
    for ( Iter = 0; Iter < p->nPatterns; Iter++ )
    {
282
clk = Abc_Clock();
Alan Mishchenko committed
283
        pMan->pMSat = Ssw_SatStart( 0 );
Alan Mishchenko committed
284 285 286
        Frames = Ssw_ManFilterBmc( p, Iter, fCheckTargets );
        if ( fVerbose )
        {
287 288 289
            Abc_Print( 1, "%3d : C = %6d. Cl = %6d. NR = %6d. F = %3d. C = %5d. P = %3d. %s ",
                Iter, Ssw_ClassesCand1Num(p->pMan->ppClasses), Ssw_ClassesClassNum(p->pMan->ppClasses),
                Aig_ManNodeNum(p->pMan->pFrames), Frames, (int)p->pMan->pMSat->pSat->stats.conflicts, p->nPatterns,
Alan Mishchenko committed
290
                p->pMan->nSatFailsReal? "f" : " " );
291
            ABC_PRT( "T", Abc_Clock() - clk );
292
        }
Alan Mishchenko committed
293
        Ssw_ManCleanup( p->pMan );
Alan Mishchenko committed
294
        if ( fCheckTargets && Ssw_SemCheckTargets( p ) )
Alan Mishchenko committed
295
        {
296
            Abc_Print( 1, "Target is hit!!!\n" );
Alan Mishchenko committed
297 298 299 300 301
            RetValue = 1;
        }
        if ( p->nPatterns >= p->nPatternsAlloc )
            break;
    }
Alan Mishchenko committed
302
    Ssw_SemManStop( p );
Alan Mishchenko committed
303 304 305 306

    pMan->nStrangers = 0;
    pMan->nSatCalls = 0;
    pMan->nSatProof = 0;
307
    pMan->nSatFailsReal = 0;
Alan Mishchenko committed
308
    pMan->nSatCallsUnsat = 0;
309 310 311 312 313 314
    pMan->nSatCallsSat = 0;
    pMan->timeSimSat = 0;
    pMan->timeSat = 0;
    pMan->timeSatSat = 0;
    pMan->timeSatUnsat = 0;
    pMan->timeSatUndec = 0;
Alan Mishchenko committed
315 316 317 318 319 320 321 322
    return RetValue;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


323
ABC_NAMESPACE_IMPL_END