abcCas.c 3.8 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
/**CFile****************************************************************

  FileName    [abcCas.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Decomposition of shared BDDs into LUT cascade.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21
#include "base/abc/abc.h"
22 23

#ifdef ABC_USE_CUDD
24
#include "bdd/extrab/extraBdd.h"
25
#endif
Alan Mishchenko committed
26

27 28 29
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
30 31 32 33 34 35 36 37 38 39 40
/* 
    This LUT cascade synthesis algorithm is described in the paper:
    A. Mishchenko and T. Sasao, "Encoding of Boolean functions and its 
    application to LUT cascade synthesis", Proc. IWLS '02, pp. 115-120.
    http://www.eecs.berkeley.edu/~alanmi/publications/2002/iwls02_enc.pdf
*/

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

41 42
#ifdef ABC_USE_CUDD

Alan Mishchenko committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
extern int Abc_CascadeExperiment( char * pFileGeneric, DdManager * dd, DdNode ** pOutputs, int nInputs, int nOutputs, int nLutSize, int fCheck, int fVerbose );

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkCascade( Abc_Ntk_t * pNtk, int nLutSize, int fCheck, int fVerbose )
{
    DdManager * dd;
    DdNode ** ppOutputs;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pNode;
    char * pFileGeneric;
    int fBddSizeMax = 500000;
68
    int i, fReorder = 1;
69
    abctime clk = Abc_Clock();
Alan Mishchenko committed
70 71 72

    assert( Abc_NtkIsStrash(pNtk) );
    // compute the global BDDs
73
    if ( Abc_NtkBuildGlobalBdds(pNtk, fBddSizeMax, 1, fReorder, 0, fVerbose) == NULL )
Alan Mishchenko committed
74 75 76 77
        return NULL;

    if ( fVerbose )
    {
78
        DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
Alan Mishchenko committed
79
        printf( "Shared BDD size = %6d nodes.  ", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
80
        ABC_PRT( "BDD construction time", Abc_Clock() - clk );
Alan Mishchenko committed
81 82 83
    }

    // collect global BDDs
84
    dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
Alan Mishchenko committed
85
    ppOutputs = ABC_ALLOC( DdNode *, Abc_NtkCoNum(pNtk) );
Alan Mishchenko committed
86
    Abc_NtkForEachCo( pNtk, pNode, i )
87
        ppOutputs[i] = (DdNode *)Abc_ObjGlobalBdd(pNode);
Alan Mishchenko committed
88 89 90 91 92 93 94 95 96 97 98 99 100

    // call the decomposition
    pFileGeneric = Extra_FileNameGeneric( pNtk->pSpec );
    if ( !Abc_CascadeExperiment( pFileGeneric, dd, ppOutputs, Abc_NtkCiNum(pNtk), Abc_NtkCoNum(pNtk), nLutSize, fCheck, fVerbose ) )
    {
        // the LUT size is too small
    }

    // for now, duplicate the network
    pNtkNew = Abc_NtkDup( pNtk );

    // cleanup
    Abc_NtkFreeGlobalBdds( pNtk, 1 );
Alan Mishchenko committed
101 102
    ABC_FREE( ppOutputs );
    ABC_FREE( pFileGeneric );
Alan Mishchenko committed
103 104 105 106 107 108 109 110 111 112 113 114 115

//    if ( pNtk->pExdc )
//        pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
    // make sure that everything is okay
    if ( !Abc_NtkCheck( pNtkNew ) )
    {
        printf( "Abc_NtkCollapse: The network check has failed.\n" );
        Abc_NtkDelete( pNtkNew );
        return NULL;
    }
    return pNtkNew;
}

116 117 118 119 120 121
#else

Abc_Ntk_t * Abc_NtkCascade( Abc_Ntk_t * pNtk, int nLutSize, int fCheck, int fVerbose ) { return NULL; }

#endif

Alan Mishchenko committed
122 123 124 125 126
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


127 128
ABC_NAMESPACE_IMPL_END