mfsStrash.c 13.2 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    [mfsStrash.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [The good old minimization with complete don't-cares.]

  Synopsis    [Structural hashing of the window with ODCs.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: mfsStrash.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

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

#include "mfsInt.h"

23 24
ABC_NAMESPACE_IMPL_START

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

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

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

Alan Mishchenko committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  Synopsis    [Recursively converts AIG from Aig_Man_t into Hop_Obj_t.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_MfsConvertAigToHop_rec( Aig_Obj_t * pObj, Hop_Man_t * pHop )
{
    assert( !Aig_IsComplement(pObj) );
    if ( pObj->pData )
        return;
    Abc_MfsConvertAigToHop_rec( Aig_ObjFanin0(pObj), pHop ); 
    Abc_MfsConvertAigToHop_rec( Aig_ObjFanin1(pObj), pHop );
    pObj->pData = Hop_And( pHop, (Hop_Obj_t *)Aig_ObjChild0Copy(pObj), (Hop_Obj_t *)Aig_ObjChild1Copy(pObj) ); 
52
    assert( !Hop_IsComplement((Hop_Obj_t *)pObj->pData) );
Alan Mishchenko committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
}

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

  Synopsis    [Converts AIG from Aig_Man_t into Hop_Obj_t.]

  Description [Assumes that Aig_Man_t has exactly one primary outputs.
  Returns the pointer to the root node (Hop_Obj_t) in Hop_Man_t.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Hop_Obj_t * Abc_MfsConvertAigToHop( Aig_Man_t * pMan, Hop_Man_t * pHop )
{
    Aig_Obj_t * pRoot, * pObj;
    int i;
71 72
    assert( Aig_ManCoNum(pMan) == 1 );
    pRoot = Aig_ManCo( pMan, 0 );
Alan Mishchenko committed
73 74 75 76 77
    // check the case of a constant
    if ( Aig_ObjIsConst1( Aig_ObjFanin0(pRoot) ) )
        return Hop_NotCond( Hop_ManConst1(pHop), Aig_ObjFaninC0(pRoot) );
    // set the PI mapping
    Aig_ManCleanData( pMan );
78
    Aig_ManForEachCi( pMan, pObj, i )
Alan Mishchenko committed
79 80 81
        pObj->pData = Hop_IthVar( pHop, i );
    // construct the AIG
    Abc_MfsConvertAigToHop_rec( Aig_ObjFanin0(pRoot), pHop );
82
    return Hop_NotCond( (Hop_Obj_t *)Aig_ObjFanin0(pRoot)->pData, Aig_ObjFaninC0(pRoot) );
Alan Mishchenko committed
83 84 85 86 87 88
}

// should be called as follows:   pNodeNew->pData = Abc_MfsConvertAigToHop( pAigManInterpol, pNodeNew->pNtk->pManFunc );

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

Alan Mishchenko committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  Synopsis    [Construct BDDs and mark AIG nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_MfsConvertHopToAig_rec( Hop_Obj_t * pObj, Aig_Man_t * pMan )
{
    assert( !Hop_IsComplement(pObj) );
    if ( !Hop_ObjIsNode(pObj) || Hop_ObjIsMarkA(pObj) )
        return;
    Abc_MfsConvertHopToAig_rec( Hop_ObjFanin0(pObj), pMan ); 
    Abc_MfsConvertHopToAig_rec( Hop_ObjFanin1(pObj), pMan );
    pObj->pData = Aig_And( pMan, (Aig_Obj_t *)Hop_ObjChild0Copy(pObj), (Aig_Obj_t *)Hop_ObjChild1Copy(pObj) ); 
    assert( !Hop_ObjIsMarkA(pObj) ); // loop detection
    Hop_ObjSetMarkA( pObj );
}

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

  Synopsis    [Converts the network from AIG to BDD representation.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_MfsConvertHopToAig( Abc_Obj_t * pObjOld, Aig_Man_t * pMan )
{
    Hop_Man_t * pHopMan;
    Hop_Obj_t * pRoot;
    Abc_Obj_t * pFanin;
    int i;
    // get the local AIG
128 129
    pHopMan = (Hop_Man_t *)pObjOld->pNtk->pManFunc;
    pRoot = (Hop_Obj_t *)pObjOld->pData;
Alan Mishchenko committed
130 131 132 133 134 135 136 137 138 139 140 141 142
    // check the case of a constant
    if ( Hop_ObjIsConst1( Hop_Regular(pRoot) ) )
    {
        pObjOld->pCopy = (Abc_Obj_t *)Aig_NotCond( Aig_ManConst1(pMan), Hop_IsComplement(pRoot) );
        pObjOld->pNext = pObjOld->pCopy;
        return;
    }

    // assign the fanin nodes
    Abc_ObjForEachFanin( pObjOld, pFanin, i )
        Hop_ManPi(pHopMan, i)->pData = pFanin->pCopy;
    // construct the AIG
    Abc_MfsConvertHopToAig_rec( Hop_Regular(pRoot), pMan );
143
    pObjOld->pCopy = (Abc_Obj_t *)Aig_NotCond( (Aig_Obj_t *)Hop_Regular(pRoot)->pData, Hop_IsComplement(pRoot) );  
Alan Mishchenko committed
144 145 146 147 148 149 150
    Hop_ConeUnmark_rec( Hop_Regular(pRoot) );

    // assign the fanin nodes
    Abc_ObjForEachFanin( pObjOld, pFanin, i )
        Hop_ManPi(pHopMan, i)->pData = pFanin->pNext;
    // construct the AIG
    Abc_MfsConvertHopToAig_rec( Hop_Regular(pRoot), pMan );
151
    pObjOld->pNext = (Abc_Obj_t *)Aig_NotCond( (Aig_Obj_t *)Hop_Regular(pRoot)->pData, Hop_IsComplement(pRoot) );  
Alan Mishchenko committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    Hop_ConeUnmark_rec( Hop_Regular(pRoot) );
}

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

  Synopsis    [Computes the care set of the node under ODCs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Obj_t * Abc_NtkConstructAig_rec( Mfs_Man_t * p, Abc_Obj_t * pNode, Aig_Man_t * pMan )
{
    Aig_Obj_t * pRoot, * pExor;
    Abc_Obj_t * pObj;
    int i;
    // assign AIG nodes to the leaves
172
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vSupp, pObj, i )
173
        pObj->pCopy = pObj->pNext = (Abc_Obj_t *)Aig_ObjCreateCi( pMan );
Alan Mishchenko committed
174 175
    // strash intermediate nodes
    Abc_NtkIncrementTravId( pNode->pNtk );
176
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vNodes, pObj, i )
Alan Mishchenko committed
177 178 179 180 181 182 183
    {
        Abc_MfsConvertHopToAig( pObj, pMan );
        if ( pObj == pNode )
            pObj->pNext = Abc_ObjNot(pObj->pNext);
    }
    // create the observability condition
    pRoot = Aig_ManConst0(pMan);
184
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vRoots, pObj, i )
Alan Mishchenko committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    {
        pExor = Aig_Exor( pMan, (Aig_Obj_t *)pObj->pCopy, (Aig_Obj_t *)pObj->pNext );
        pRoot = Aig_Or( pMan, pRoot, pExor );
    }
    return pRoot;
}

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

  Synopsis    [Adds relevant constraints.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
203
Aig_Obj_t * Abc_NtkConstructCare_rec( Aig_Man_t * pCare, Aig_Obj_t * pObj, Aig_Man_t * pMan )
Alan Mishchenko committed
204 205
{
    Aig_Obj_t * pObj0, * pObj1;
Alan Mishchenko committed
206
    if ( Aig_ObjIsTravIdCurrent( pCare, pObj ) )
207
        return (Aig_Obj_t *)pObj->pData;
Alan Mishchenko committed
208
    Aig_ObjSetTravIdCurrent( pCare, pObj );
209
    if ( Aig_ObjIsCi(pObj) )
210
        return (Aig_Obj_t *)(pObj->pData = NULL);
Alan Mishchenko committed
211
    pObj0 = Abc_NtkConstructCare_rec( pCare, Aig_ObjFanin0(pObj), pMan );
Alan Mishchenko committed
212
    if ( pObj0 == NULL )
213
        return (Aig_Obj_t *)(pObj->pData = NULL);
Alan Mishchenko committed
214
    pObj1 = Abc_NtkConstructCare_rec( pCare, Aig_ObjFanin1(pObj), pMan );
Alan Mishchenko committed
215
    if ( pObj1 == NULL )
216
        return (Aig_Obj_t *)(pObj->pData = NULL);
Alan Mishchenko committed
217 218
    pObj0 = Aig_NotCond( pObj0, Aig_ObjFaninC0(pObj) );
    pObj1 = Aig_NotCond( pObj1, Aig_ObjFaninC1(pObj) );
219
    return (Aig_Obj_t *)(pObj->pData = Aig_And( pMan, pObj0, pObj1 ));
Alan Mishchenko committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
}

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

  Synopsis    [Creates AIG for the window with constraints.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Abc_NtkConstructAig( Mfs_Man_t * p, Abc_Obj_t * pNode )
{
    Aig_Man_t * pMan;
    Abc_Obj_t * pFanin;
    Aig_Obj_t * pObjAig, * pPi, * pPo;
Alan Mishchenko committed
238 239
    Vec_Int_t * vOuts;
    int i, k, iOut;
Alan Mishchenko committed
240 241 242 243
    // start the new manager
    pMan = Aig_ManStart( 1000 );
    // construct the root node's AIG cone
    pObjAig = Abc_NtkConstructAig_rec( p, pNode, pMan );
Alan Mishchenko committed
244
//    assert( Aig_ManConst1(pMan) == pObjAig );
245
    Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
246 247 248 249
    if ( p->pCare )
    {
        // mark the care set
        Aig_ManIncrementTravId( p->pCare );
250
        Vec_PtrForEachEntry( Abc_Obj_t *, p->vSupp, pFanin, i )
Alan Mishchenko committed
251
        {
252
            pPi = Aig_ManCi( p->pCare, (int)(ABC_PTRUINT_T)pFanin->pData );
Alan Mishchenko committed
253 254 255 256
            Aig_ObjSetTravIdCurrent( p->pCare, pPi );
            pPi->pData = pFanin->pCopy;
        }
        // construct the constraints
257
        Vec_PtrForEachEntry( Abc_Obj_t *, p->vSupp, pFanin, i )
Alan Mishchenko committed
258
        {
259
            vOuts = (Vec_Int_t *)Vec_PtrEntry( p->vSuppsInv, (int)(ABC_PTRUINT_T)pFanin->pData );
Alan Mishchenko committed
260 261
            Vec_IntForEachEntry( vOuts, iOut, k )
            {
262
                pPo = Aig_ManCo( p->pCare, iOut );
Alan Mishchenko committed
263 264 265 266 267 268 269 270 271
                if ( Aig_ObjIsTravIdCurrent( p->pCare, pPo ) )
                    continue;
                Aig_ObjSetTravIdCurrent( p->pCare, pPo );
                if ( Aig_ObjFanin0(pPo) == Aig_ManConst1(p->pCare) )
                    continue;
                pObjAig = Abc_NtkConstructCare_rec( p->pCare, Aig_ObjFanin0(pPo), pMan );
                if ( pObjAig == NULL )
                    continue;
                pObjAig = Aig_NotCond( pObjAig, Aig_ObjFaninC0(pPo) );
272
                Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
273 274 275
            }
        }
/*
276
        Aig_ManForEachCo( p->pCare, pPo, i )
Alan Mishchenko committed
277
        {
Alan Mishchenko committed
278 279 280 281
//            assert( Aig_ObjFanin0(pPo) != Aig_ManConst1(p->pCare) );
            if ( Aig_ObjFanin0(pPo) == Aig_ManConst1(p->pCare) )
                continue;
            pObjAig = Abc_NtkConstructCare_rec( p->pCare, Aig_ObjFanin0(pPo), pMan );
Alan Mishchenko committed
282 283 284
            if ( pObjAig == NULL )
                continue;
            pObjAig = Aig_NotCond( pObjAig, Aig_ObjFaninC0(pPo) );
285
            Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
286
        }
Alan Mishchenko committed
287
*/
Alan Mishchenko committed
288
    }
Alan Mishchenko committed
289
    if ( p->pPars->fResub )
Alan Mishchenko committed
290
    {
Alan Mishchenko committed
291 292
        // construct the node
        pObjAig = (Aig_Obj_t *)pNode->pCopy;
293
        Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
294
        // construct the divisors
295
        Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pFanin, i )
Alan Mishchenko committed
296 297
        {
            pObjAig = (Aig_Obj_t *)pFanin->pCopy;
298
            Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
299 300 301 302 303 304 305 306
        }
    }
    else
    {
        // construct the fanins
        Abc_ObjForEachFanin( pNode, pFanin, i )
        {
            pObjAig = (Aig_Obj_t *)pFanin->pCopy;
307
            Aig_ObjCreateCo( pMan, pObjAig );
Alan Mishchenko committed
308
        }
Alan Mishchenko committed
309 310 311 312 313
    }
    Aig_ManCleanup( pMan );
    return pMan;
}

Alan Mishchenko committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
/**Function*************************************************************

  Synopsis    [Creates AIG for the window with constraints.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Abc_NtkAigForConstraints( Mfs_Man_t * p, Abc_Obj_t * pNode )
{
    Abc_Obj_t * pFanin;
    Aig_Man_t * pMan;
    Aig_Obj_t * pPi, * pPo, * pObjAig, * pObjRoot;
    Vec_Int_t * vOuts;
    int i, k, iOut;
    if ( p->pCare == NULL )
        return NULL;
    pMan = Aig_ManStart( 1000 );
    // mark the care set
    Aig_ManIncrementTravId( p->pCare );
337
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vSupp, pFanin, i )
Alan Mishchenko committed
338
    {
339
        pPi = Aig_ManCi( p->pCare, (int)(ABC_PTRUINT_T)pFanin->pData );
Alan Mishchenko committed
340
        Aig_ObjSetTravIdCurrent( p->pCare, pPi );
341
        pPi->pData = Aig_ObjCreateCi(pMan);
Alan Mishchenko committed
342 343 344
    }
    // construct the constraints
    pObjRoot = Aig_ManConst1(pMan);
345
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vSupp, pFanin, i )
Alan Mishchenko committed
346
    {
347
        vOuts = (Vec_Int_t *)Vec_PtrEntry( p->vSuppsInv, (int)(ABC_PTRUINT_T)pFanin->pData );
Alan Mishchenko committed
348 349
        Vec_IntForEachEntry( vOuts, iOut, k )
        {
350
            pPo = Aig_ManCo( p->pCare, iOut );
Alan Mishchenko committed
351 352 353 354 355 356 357 358 359 360 361 362
            if ( Aig_ObjIsTravIdCurrent( p->pCare, pPo ) )
                continue;
            Aig_ObjSetTravIdCurrent( p->pCare, pPo );
            if ( Aig_ObjFanin0(pPo) == Aig_ManConst1(p->pCare) )
                continue;
            pObjAig = Abc_NtkConstructCare_rec( p->pCare, Aig_ObjFanin0(pPo), pMan );
            if ( pObjAig == NULL )
                continue;
            pObjAig = Aig_NotCond( pObjAig, Aig_ObjFaninC0(pPo) );
            pObjRoot = Aig_And( pMan, pObjRoot, pObjAig );
        }
    }
363
    Aig_ObjCreateCo( pMan, pObjRoot );
Alan Mishchenko committed
364 365 366 367
    Aig_ManCleanup( pMan );
    return pMan;
}

368 369
ABC_NAMESPACE_IMPL_END

370
#include "proof/fra/fra.h"
Alan Mishchenko committed
371

372 373 374
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
/**Function*************************************************************

  Synopsis    [Compute the ratio of don't-cares.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
double Abc_NtkConstraintRatio( Mfs_Man_t * p, Abc_Obj_t * pNode )
{
    int nSimWords = 256;
    Aig_Man_t * pMan;
    Fra_Sml_t * pSim;
    int Counter;
    pMan = Abc_NtkAigForConstraints( p, pNode );
393
    pSim = Fra_SmlSimulateComb( pMan, nSimWords, 0 );
394
    Counter = Fra_SmlNodeCountOnes( pSim, Aig_ManCo(pMan, 0) );
Alan Mishchenko committed
395 396 397 398 399
    Aig_ManStop( pMan );
    Fra_SmlStop( pSim );
    return 1.0 * Counter / (32 * nSimWords);
}

Alan Mishchenko committed
400 401 402 403 404
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


405 406
ABC_NAMESPACE_IMPL_END