sswUnique.c 6.12 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 22
/**CFile****************************************************************

  FileName    [sswSat.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Inductive prover with constraints.]

  Synopsis    [On-demand uniqueness constraints.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: sswSat.c,v 1.00 2008/09/01 00:00:00 alanmi Exp $]

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

#include "sswInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

Alan Mishchenko committed
36
  Synopsis    [Performs computation of signal correspondence with constraints.]
Alan Mishchenko committed
37

Alan Mishchenko committed
38
  Description []
Alan Mishchenko committed
39 40 41 42 43 44
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
45
void Ssw_UniqueRegisterPairInfo( Ssw_Man_t * p )
Alan Mishchenko committed
46
{
Alan Mishchenko committed
47
    Aig_Obj_t * pObjLo, * pObj0, * pObj1;
Alan Mishchenko committed
48
    int i, RetValue, Counter;
Alan Mishchenko committed
49 50 51 52
    if ( p->vDiffPairs == NULL )
        p->vDiffPairs = Vec_IntAlloc( Saig_ManRegNum(p->pAig) );
    Vec_IntClear( p->vDiffPairs );
    Saig_ManForEachLo( p->pAig, pObjLo, i )
Alan Mishchenko committed
53
    {
Alan Mishchenko committed
54 55 56 57 58 59
        pObj0 = Ssw_ObjFrame( p, pObjLo, 0 );
        pObj1 = Ssw_ObjFrame( p, pObjLo, 1 );
        if ( pObj0 == pObj1 )
            Vec_IntPush( p->vDiffPairs, 0 );
        else if ( pObj0 == Aig_Not(pObj1) )
            Vec_IntPush( p->vDiffPairs, 1 );
Alan Mishchenko committed
60 61 62 63
//        else
//            Vec_IntPush( p->vDiffPairs, 1 );
        else if ( Aig_ObjPhaseReal(pObj0) != Aig_ObjPhaseReal(pObj1) )
            Vec_IntPush( p->vDiffPairs, 1 );
64
        else
Alan Mishchenko committed
65
        {
Alan Mishchenko committed
66 67
            RetValue = Ssw_NodesAreEquiv( p, Aig_Regular(pObj0), Aig_Regular(pObj1) );
            Vec_IntPush( p->vDiffPairs, RetValue!=1 );
Alan Mishchenko committed
68
        }
Alan Mishchenko committed
69
    }
Alan Mishchenko committed
70 71 72 73 74
    assert( Vec_IntSize(p->vDiffPairs) == Saig_ManRegNum(p->pAig) );
    // count the number of ones
    Counter = 0;
    Vec_IntForEachEntry( p->vDiffPairs, RetValue, i )
        Counter += RetValue;
75
//    Abc_Print( 1, "The number of different register pairs = %d.\n", Counter );
Alan Mishchenko committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89
}


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

  Synopsis    [Returns 1 if uniqueness constraints can be added.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
90
int Ssw_ManUniqueOne( Ssw_Man_t * p, Aig_Obj_t * pRepr, Aig_Obj_t * pObj, int fVerbose )
Alan Mishchenko committed
91 92
{
    Aig_Obj_t * ppObjs[2], * pTemp;
Alan Mishchenko committed
93
    int i, k, Value0, Value1, RetValue, fFeasible;
Alan Mishchenko committed
94

Alan Mishchenko committed
95 96
    assert( p->pPars->nFramesK > 1 );
    assert( p->vDiffPairs && Vec_IntSize(p->vDiffPairs) == Saig_ManRegNum(p->pAig) );
Alan Mishchenko committed
97 98

    // compute the first support in terms of LOs
99
    ppObjs[0] = pRepr;
Alan Mishchenko committed
100
    ppObjs[1] = pObj;
Alan Mishchenko committed
101 102 103 104
    Aig_SupportNodes( p->pAig, ppObjs, 2, p->vCommon );
    // keep only LOs
    RetValue = Vec_PtrSize( p->vCommon );
    fFeasible = 0;
Alan Mishchenko committed
105
    k = 0;
106
    Vec_PtrForEachEntry( Aig_Obj_t *, p->vCommon, pTemp, i )
Alan Mishchenko committed
107
    {
108
        assert( Aig_ObjIsCi(pTemp) );
Alan Mishchenko committed
109 110
        if ( !Saig_ObjIsLo(p->pAig, pTemp) )
            continue;
111
        assert( Aig_ObjCioId(pTemp) > 0 );
Alan Mishchenko committed
112
        Vec_PtrWriteEntry( p->vCommon, k++, pTemp );
113
        if ( Vec_IntEntry(p->vDiffPairs, Aig_ObjCioId(pTemp) - Saig_ManPiNum(p->pAig)) )
Alan Mishchenko committed
114 115
            fFeasible = 1;
    }
Alan Mishchenko committed
116 117
    Vec_PtrShrink( p->vCommon, k );

Alan Mishchenko committed
118
    if ( fVerbose )
119
        Abc_Print( 1, "Node = %5d : Supp = %3d. Regs = %3d. Feasible = %s. ",
Alan Mishchenko committed
120 121
            Aig_ObjId(pObj), RetValue, Vec_PtrSize(p->vCommon),
            fFeasible? "yes": "no " );
Alan Mishchenko committed
122 123 124

    // check the current values
    RetValue = 1;
125
    Vec_PtrForEachEntry( Aig_Obj_t *, p->vCommon, pTemp, i )
Alan Mishchenko committed
126 127 128 129 130 131
    {
        Value0 = Ssw_ManGetSatVarValue( p, pTemp, 0 );
        Value1 = Ssw_ManGetSatVarValue( p, pTemp, 1 );
        if ( Value0 != Value1 )
            RetValue = 0;
        if ( fVerbose )
132
            Abc_Print( 1, "%d", Value0 ^ Value1 );
Alan Mishchenko committed
133 134
    }
    if ( fVerbose )
135
        Abc_Print( 1, "\n" );
Alan Mishchenko committed
136

Alan Mishchenko committed
137
    return RetValue && fFeasible;
Alan Mishchenko committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
}

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

  Synopsis    [Returns the output of the uniqueness constraint.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Ssw_ManUniqueAddConstraint( Ssw_Man_t * p, Vec_Ptr_t * vCommon, int f1, int f2 )
{
    Aig_Obj_t * pObj, * pObj1New, * pObj2New, * pMiter, * pTotal;
    int i, pLits[2];
//    int RetValue;
    assert( Vec_PtrSize(vCommon) > 0 );
    // generate the constraint
    pTotal = Aig_ManConst0(p->pFrames);
159
    Vec_PtrForEachEntry( Aig_Obj_t *, vCommon, pObj, i )
Alan Mishchenko committed
160 161 162 163 164 165 166 167 168
    {
        assert( Saig_ObjIsLo(p->pAig, pObj) );
        pObj1New = Ssw_ObjFrame( p, pObj, f1 );
        pObj2New = Ssw_ObjFrame( p, pObj, f2 );
        pMiter = Aig_Exor( p->pFrames, pObj1New, pObj2New );
        pTotal = Aig_Or( p->pFrames, pTotal, pMiter );
    }
    if ( Aig_ObjIsConst1(Aig_Regular(pTotal)) )
    {
169
//        Abc_Print( 1, "Skipped\n" );
Alan Mishchenko committed
170 171 172
        return 0;
    }
    // create CNF
Alan Mishchenko committed
173
    Ssw_CnfNodeAddToSolver( p->pMSat, Aig_Regular(pTotal) );
Alan Mishchenko committed
174
    // add output constraint
Alan Mishchenko committed
175
    pLits[0] = toLitCond( Ssw_ObjSatNum(p->pMSat,Aig_Regular(pTotal)), Aig_IsComplement(pTotal) );
Alan Mishchenko committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
/*
    RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 1 );
    assert( RetValue );
    // simplify the solver
    if ( p->pSat->qtail != p->pSat->qhead )
    {
        RetValue = sat_solver_simplify(p->pSat);
        assert( RetValue != 0 );
    }
*/
    assert( p->iOutputLit == -1 );
    p->iOutputLit = pLits[0];
    return 1;
}

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


196
ABC_NAMESPACE_IMPL_END