abc/src/proof/pdr/pdrTsim.c
/**Function*************************************************************

  Synopsis    [Shrinks values using ternary simulation.]

  Description [The cube contains the set of flop index literals which,
  when converted into a clause and applied to the combinational outputs, 
  led to a satisfiable SAT run in frame k (values stored in the SAT solver).
  If the cube is NULL, it is assumed that the first property output was
  asserted and failed.
  The resulting array is a set of flop index literals that asserts the COs.
  Priority contains 0 for i-th entry if the i-th FF is desirable to remove.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Shrinks values using ternary simulation.]

Description [The cube contains the set of flop index literals which,
when converted into a clause and applied to the combinational outputs,
led to a satisfiable SAT run in frame k (values stored in the SAT solver).
If the cube is NULL, it is assumed that the first property output was
asserted and failed.
The resulting array is a set of flop index literals that asserts the COs.
Priority contains 0 for i-th entry if the i-th FF is desirable to remove.]




Function Synopsis [ Shrinks values using ternary simulation . ] Description [ The cube contains the set of flop index literals which when converted into a clause and applied to the combinational outputs led to a satisfiable SAT run in frame k ( values stored in the SAT solver ) . If the cube is NULL it is assumed that the first property output was asserted and failed . The resulting array is a set of flop index literals that asserts the COs . Priority contains 0 for i - th entry if the i - th FF is desirable to remove . ]
Pdr_Set_t * Pdr_ManTernarySim( Pdr_Man_t * p, int k, Pdr_Set_t * pCube )
{
    Pdr_Set_t * pRes;
    Vec_Int_t * vPrio   = p->vPrio;    
    Vec_Int_t * vPiLits = p->vLits;    
    Vec_Int_t * vCiObjs = p->vCiObjs;  
    Vec_Int_t * vCoObjs = p->vCoObjs;  
    Vec_Int_t * vCiVals = p->vCiVals;  
    Vec_Int_t * vCoVals = p->vCoVals;  
    Vec_Int_t * vNodes  = p->vNodes;   
    Vec_Int_t * vUndo   = p->vUndo;    
    Vec_Int_t * vVisits = p->vVisits;  
    Vec_Int_t * vCi2Rem = p->vCi2Rem;  
    Vec_Int_t * vRes    = p->vRes;     
    Aig_Obj_t * pObj;
    int i, Entry, RetValue;
    Vec_IntClear( vCoObjs );
    if ( pCube == NULL ) 
    {
        Vec_IntPush( vCoObjs, Aig_ObjId(Aig_ManCo(p->pAig, p->iOutCur)) );
    }
    else 
    {
        for ( i = 0; i < pCube->nLits; i++ )
        {
            if ( pCube->Lits[i] == -1 )
                continue;
            pObj = Saig_ManLi(p->pAig, (pCube->Lits[i] >> 1));
            Vec_IntPush( vCoObjs, Aig_ObjId(pObj) );
        }
    }
if ( p->pPars->fVeryVerbose )
{
Abc_Print( 1, "Trying to justify cube " );
if ( pCube )
    Pdr_SetPrint( stdout, pCube, Aig_ManRegNum(p->pAig), NULL );
else
    Abc_Print( 1, "<prop=fail>" );
Abc_Print( 1, " in frame %d.\n", k );
}
    Pdr_ManCollectCone( p->pAig, vCoObjs, vCiObjs, vNodes );
    Pdr_ManCollectValues( p, k, vCiObjs, vCiVals );
    Pdr_ManCollectValues( p, k, vCoObjs, vCoVals );
if ( p->pPars->fVeryVerbose )
Pdr_ManPrintCex( p->pAig, vCiObjs, vCiVals, NULL );
    RetValue = Pdr_ManSimDataInit( p->pAig, vCiObjs, vCiVals, vNodes, vCoObjs, vCoVals, NULL );
    assert( RetValue );
    if ( p->pPars->fFlopPrio )
    {
        Vec_IntClear( vRes );
        Aig_ManForEachObjVec( vCiObjs, p->pAig, pObj, i )
        {
            if ( !Saig_ObjIsLo( p->pAig, pObj ) )
                continue;
            Entry = Aig_ObjCioId(pObj) - Saig_ManPiNum(p->pAig);
            Vec_IntPush( vRes, Entry );
        }
        Vec_IntSelectSortCost( Vec_IntArray(vRes), Vec_IntSize(vRes), vPrio );
        Vec_IntClear( vCi2Rem );
        Vec_IntForEachEntry( vRes, Entry, i )
        {
            pObj = Aig_ManCi( p->pAig, Saig_ManPiNum(p->pAig) + Entry );
            assert( Saig_ObjIsLo( p->pAig, pObj ) );
            Vec_IntClear( vUndo );
            if ( Pdr_ManExtendOne( p->pAig, pObj, vUndo, vVisits ) )
                Vec_IntPush( vCi2Rem, Aig_ObjId(pObj) );
            else
                Pdr_ManExtendUndo( p->pAig, vUndo );
        }
    }
    else
    {
        Vec_IntClear( vCi2Rem );
        Aig_ManForEachObjVec( vCiObjs, p->pAig, pObj, i )
        {
            if ( !Saig_ObjIsLo( p->pAig, pObj ) )
                continue;
            Entry = Aig_ObjCioId(pObj) - Saig_ManPiNum(p->pAig);
            if ( Vec_IntEntry(vPrio, Entry) )
                continue;
            Vec_IntClear( vUndo );
            if ( Pdr_ManExtendOne( p->pAig, pObj, vUndo, vVisits ) )
                Vec_IntPush( vCi2Rem, Aig_ObjId(pObj) );
            else
                Pdr_ManExtendUndo( p->pAig, vUndo );
        }
        Aig_ManForEachObjVec( vCiObjs, p->pAig, pObj, i )
        {
            if ( !Saig_ObjIsLo( p->pAig, pObj ) )
                continue;
            Entry = Aig_ObjCioId(pObj) - Saig_ManPiNum(p->pAig);
            if ( !Vec_IntEntry(vPrio, Entry) )
                continue;
            Vec_IntClear( vUndo );
            if ( Pdr_ManExtendOne( p->pAig, pObj, vUndo, vVisits ) )
                Vec_IntPush( vCi2Rem, Aig_ObjId(pObj) );
            else
                Pdr_ManExtendUndo( p->pAig, vUndo );
        }
    }
if ( p->pPars->fVeryVerbose )
Pdr_ManPrintCex( p->pAig, vCiObjs, vCiVals, vCi2Rem );
    RetValue = Pdr_ManSimDataInit( p->pAig, vCiObjs, vCiVals, vNodes, vCoObjs, vCoVals, vCi2Rem );
    assert( RetValue );
    Pdr_ManDeriveResult( p->pAig, vCiObjs, vCiVals, vCi2Rem, vRes, vPiLits );
    assert( Vec_IntSize(vRes) > 0 );
    if ( p->pPars->fUseAbs && p->vAbsFlops )
    {
        int i, iLit, k = 0;
        Vec_IntForEachEntry( vRes, iLit, i )
        {
            if ( Vec_IntEntry(p->vAbsFlops, Abc_Lit2Var(iLit)) ) 
                Vec_IntWriteEntry( vRes, k++, iLit );
            else
                Vec_IntPush( vPiLits, 2*Saig_ManPiNum(p->pAig) + iLit );
        }
        Vec_IntShrink( vRes, k );
    }
    pRes = Pdr_SetCreate( vRes, vPiLits );
    return pRes;
}
Pdr_Set_t * Pdr_ManTernarySim ( Pdr_Man_t * p , int k , Pdr_Set_t * pCube ) { Pdr_Set_t * pRes ; Vec_Int_t * vPrio = p -> vPrio ; Vec_Int_t * vPiLits = p -> vLits ; Vec_Int_t * vCiObjs = p -> vCiObjs ; Vec_Int_t * vCoObjs = p -> vCoObjs ; Vec_Int_t * vCiVals = p -> vCiVals ; Vec_Int_t * vCoVals = p -> vCoVals ; Vec_Int_t * vNodes = p -> vNodes ; Vec_Int_t * vUndo = p -> vUndo ; Vec_Int_t * vVisits = p -> vVisits ; Vec_Int_t * vCi2Rem = p -> vCi2Rem ; Vec_Int_t * vRes = p -> vRes ; Aig_Obj_t * pObj ; int i , Entry , RetValue ; Vec_IntClear ( vCoObjs ) ; if ( pCube == NULL ) { Vec_IntPush ( vCoObjs , Aig_ObjId ( Aig_ManCo ( p -> pAig , p -> iOutCur ) ) ) ; } else { for ( i = 0 ; i < pCube -> nLits ; i ++ ) { if ( pCube -> Lits [ i ] == -1 ) continue ; pObj = Saig_ManLi ( p -> pAig , ( pCube -> Lits [ i ] >> 1 ) ) ; Vec_IntPush ( vCoObjs , Aig_ObjId ( pObj ) ) ; } } if ( p -> pPars -> fVeryVerbose ) { Abc_Print ( 1 , " " ) ; if ( pCube ) Pdr_SetPrint ( stdout , pCube , Aig_ManRegNum ( p -> pAig ) , NULL ) ; else Abc_Print ( 1 , " " ) ; Abc_Print ( 1 , " \n " , k ) ; } Pdr_ManCollectCone ( p -> pAig , vCoObjs , vCiObjs , vNodes ) ; Pdr_ManCollectValues ( p , k , vCiObjs , vCiVals ) ; Pdr_ManCollectValues ( p , k , vCoObjs , vCoVals ) ; if ( p -> pPars -> fVeryVerbose ) Pdr_ManPrintCex ( p -> pAig , vCiObjs , vCiVals , NULL ) ; RetValue = Pdr_ManSimDataInit ( p -> pAig , vCiObjs , vCiVals , vNodes , vCoObjs , vCoVals , NULL ) ; assert ( RetValue ) ; if ( p -> pPars -> fFlopPrio ) { Vec_IntClear ( vRes ) ; Aig_ManForEachObjVec ( vCiObjs , p -> pAig , pObj , i ) { if ( ! Saig_ObjIsLo ( p -> pAig , pObj ) ) continue ; Entry = Aig_ObjCioId ( pObj ) - Saig_ManPiNum ( p -> pAig ) ; Vec_IntPush ( vRes , Entry ) ; } Vec_IntSelectSortCost ( Vec_IntArray ( vRes ) , Vec_IntSize ( vRes ) , vPrio ) ; Vec_IntClear ( vCi2Rem ) ; Vec_IntForEachEntry ( vRes , Entry , i ) { pObj = Aig_ManCi ( p -> pAig , Saig_ManPiNum ( p -> pAig ) + Entry ) ; assert ( Saig_ObjIsLo ( p -> pAig , pObj ) ) ; Vec_IntClear ( vUndo ) ; if ( Pdr_ManExtendOne ( p -> pAig , pObj , vUndo , vVisits ) ) Vec_IntPush ( vCi2Rem , Aig_ObjId ( pObj ) ) ; else Pdr_ManExtendUndo ( p -> pAig , vUndo ) ; } } else { Vec_IntClear ( vCi2Rem ) ; Aig_ManForEachObjVec ( vCiObjs , p -> pAig , pObj , i ) { if ( ! Saig_ObjIsLo ( p -> pAig , pObj ) ) continue ; Entry = Aig_ObjCioId ( pObj ) - Saig_ManPiNum ( p -> pAig ) ; if ( Vec_IntEntry ( vPrio , Entry ) ) continue ; Vec_IntClear ( vUndo ) ; if ( Pdr_ManExtendOne ( p -> pAig , pObj , vUndo , vVisits ) ) Vec_IntPush ( vCi2Rem , Aig_ObjId ( pObj ) ) ; else Pdr_ManExtendUndo ( p -> pAig , vUndo ) ; } Aig_ManForEachObjVec ( vCiObjs , p -> pAig , pObj , i ) { if ( ! Saig_ObjIsLo ( p -> pAig , pObj ) ) continue ; Entry = Aig_ObjCioId ( pObj ) - Saig_ManPiNum ( p -> pAig ) ; if ( ! Vec_IntEntry ( vPrio , Entry ) ) continue ; Vec_IntClear ( vUndo ) ; if ( Pdr_ManExtendOne ( p -> pAig , pObj , vUndo , vVisits ) ) Vec_IntPush ( vCi2Rem , Aig_ObjId ( pObj ) ) ; else Pdr_ManExtendUndo ( p -> pAig , vUndo ) ; } } if ( p -> pPars -> fVeryVerbose ) Pdr_ManPrintCex ( p -> pAig , vCiObjs , vCiVals , vCi2Rem ) ; RetValue = Pdr_ManSimDataInit ( p -> pAig , vCiObjs , vCiVals , vNodes , vCoObjs , vCoVals , vCi2Rem ) ; assert ( RetValue ) ; Pdr_ManDeriveResult ( p -> pAig , vCiObjs , vCiVals , vCi2Rem , vRes , vPiLits ) ; assert ( Vec_IntSize ( vRes ) > 0 ) ; if ( p -> pPars -> fUseAbs && p -> vAbsFlops ) { int i , iLit , k = 0 ; Vec_IntForEachEntry ( vRes , iLit , i ) { if ( Vec_IntEntry ( p -> vAbsFlops , Abc_Lit2Var ( iLit ) ) ) Vec_IntWriteEntry ( vRes , k ++ , iLit ) ; else Vec_IntPush ( vPiLits , 2 * Saig_ManPiNum ( p -> pAig ) + iLit ) ; } Vec_IntShrink ( vRes , k ) ; } pRes = Pdr_SetCreate ( vRes , vPiLits ) ; return pRes ; }
Function
Synopsis    [Shrinks values using ternary simulation.]
Function Synopsis [ Shrinks values using ternary simulation . ]
// priority flops (flop indices) // array of literals (0/1 PI values) // cone leaves (CI obj IDs) // cone roots (CO obj IDs) // cone leaf values (0/1 CI values) // cone root values (0/1 CO values) // cone nodes (node obj IDs) // cone undos (node obj IDs) // intermediate (obj IDs) // CIs to be removed (CI obj IDs) // final result (flop literals) //abctime clk = Abc_Clock(); // collect CO objects // the target is the property output //        Vec_IntPush( vCoObjs, Aig_ObjId(Aig_ManCo(p->pAig, (p->pPars->iOutput==-1)?0:p->pPars->iOutput)) ); // the target is the cube // collect CI objects // collect values // simulate for the first time // iteratively remove flops // collect flops and sort them by priority // try removing flops starting from low-priority to high-priority // try removing low-priority flops first // try removing high-priority flops next // derive the set of resulting registers //p->tTsim += Abc_Clock() - clk; // move abstracted literals from flops to inputs // used flop //ZH: Disabled assertion because this invariant doesn't hold with down //because of the join operation which can bring in initial states //assert( k == 0 || !Pdr_SetIsInit(pRes, -1) );