sswSemi.c 9.99 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
Alan Mishchenko committed
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 104 105 106 107 108 109
    return p;
}

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

  Synopsis    []

  Description []
               
  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 123 124 125 126 127 128
}

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

  Synopsis    []

  Description []
               
  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 144 145 146 147 148 149
        if ( !Ssw_ObjIsConst1Cand(p->pMan->pAig, pObj) )
            return 1;
    return 0;
}

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

  Synopsis    []

  Description []
               
  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 171 172 173 174 175 176
    }
    p->nPatterns++;
}

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

  Synopsis    [Performs fraiging for the internal nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

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

    // start initialized timeframes
    p->pFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * 3 );
    Saig_ManForEachLo( p->pAig, pObj, i )
    {
189
        pInfo = (unsigned *)Vec_PtrEntry( pBmc->vPatterns, i );
190
        pObjNew = Aig_NotCond( Aig_ManConst1(p->pFrames), !Abc_InfoHasBit(pInfo, iPat) );
Alan Mishchenko committed
191 192 193 194 195 196 197 198 199 200
        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 )
201
            Ssw_ObjSetFrame( p, pObj, f, Aig_ObjCreateCi(p->pFrames) );
Alan Mishchenko committed
202 203 204 205 206
        // 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 );
207
            if ( Ssw_ManSweepNode( p, pObj, f, 1, NULL ) )
Alan Mishchenko committed
208 209 210 211 212 213 214 215
            {
                Ssw_ManFilterBmcSavePattern( pBmc );
                if ( fFirst == 0 )
                {
                    fFirst = 1;
                    pBmc->nConfMax *= 10;
                } 
            }
Alan Mishchenko committed
216
            if ( f > 0 && p->pMSat->pSat->stats.conflicts >= pBmc->nConfMax )
Alan Mishchenko committed
217 218 219 220 221 222
            {
                RetValue = -1;
                break;
            }
        }
        // quit if this is the last timeframe
Alan Mishchenko committed
223
        if ( p->pMSat->pSat->stats.conflicts >= pBmc->nConfMax )
Alan Mishchenko committed
224 225 226 227
        {
            RetValue += f + 1;
            break;
        }
Alan Mishchenko committed
228
        if ( fCheckTargets && Ssw_SemCheckTargets( pBmc ) )
Alan Mishchenko committed
229 230 231 232 233 234 235
            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
236
            Ssw_CnfNodeAddToSolver( p->pMSat, Aig_Regular(pObjNew) );
Alan Mishchenko committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
        }
//printf( "Frame %2d : Conflicts = %6d. \n", f, p->pSat->stats.conflicts );
    }
    if ( fFirst )
        pBmc->nConfMax /= 10;

    // cleanup
    Ssw_ClassesCheck( p->ppClasses );
p->timeBmc += clock() - clk;
    return RetValue;
}

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

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

  Description []
               
  SideEffects []

  SeeAlso     []

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

    pMan->nStrangers = 0;
    pMan->nSatCalls = 0;
    pMan->nSatProof = 0;
    pMan->nSatFailsReal = 0; 
    pMan->nSatCallsUnsat = 0;
    pMan->nSatCallsSat = 0;  
    pMan->timeSimSat = 0;    
    pMan->timeSat = 0;       
    pMan->timeSatSat = 0;    
    pMan->timeSatUnsat = 0;  
    pMan->timeSatUndec = 0;  
    return RetValue;
}

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


321 322
ABC_NAMESPACE_IMPL_END