darInt.h 7.39 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    [darInt.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [DAG-aware AIG rewriting.]

  Synopsis    [Internal declarations.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - April 28, 2007.]

  Revision    [$Id: darInt.h,v 1.00 2007/04/28 00:00:00 alanmi Exp $]

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

21 22
#ifndef ABC__aig__dar__darInt_h
#define ABC__aig__dar__darInt_h
Alan Mishchenko committed
23

24

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

34 35
#include "misc/vec/vec.h"
#include "aig/aig/aig.h"
Alan Mishchenko committed
36 37 38 39 40 41
#include "dar.h"

////////////////////////////////////////////////////////////////////////
///                         PARAMETERS                               ///
////////////////////////////////////////////////////////////////////////

42 43 44 45


ABC_NAMESPACE_HEADER_START
 
Alan Mishchenko committed
46

Alan Mishchenko committed
47 48 49 50 51 52 53 54 55 56 57 58
////////////////////////////////////////////////////////////////////////
///                         BASIC TYPES                              ///
////////////////////////////////////////////////////////////////////////

typedef struct Dar_Man_t_            Dar_Man_t;
typedef struct Dar_Cut_t_            Dar_Cut_t;

// the AIG 4-cut
struct Dar_Cut_t_  // 6 words
{
    unsigned         uSign;          // cut signature
    unsigned         uTruth  : 16;   // the truth table of the cut function
Alan Mishchenko committed
59 60
    unsigned         Value   : 11;   // the value of the cut 
    unsigned         fBest   :  1;   // marks the best cut
Alan Mishchenko committed
61 62 63 64 65 66 67 68
    unsigned         fUsed   :  1;   // marks the cut currently in use
    unsigned         nLeaves :  3;   // the number of leaves
    int              pLeaves[4];     // the array of leaves
};

// the AIG manager
struct Dar_Man_t_
{
Alan Mishchenko committed
69 70
    // input data
    Dar_RwrPar_t *   pPars;          // rewriting parameters
Alan Mishchenko committed
71 72 73 74
    Aig_Man_t *      pAig;           // AIG manager 
    // various data members
    Aig_MmFixed_t *  pMemCuts;       // memory manager for cuts
    void *           pManCnf;        // CNF managers
Alan Mishchenko committed
75
    Vec_Ptr_t *      vCutNodes;      // the nodes with cuts allocated
Alan Mishchenko committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    // current rewriting step
    Vec_Ptr_t *      vLeavesBest;    // the best set of leaves
    int              OutBest;        // the best output (in the library)
    int              OutNumBest;     // the best number of the output
    int              GainBest;       // the best gain
    int              LevelBest;      // the level of node with the best gain
    int              ClassBest;      // the equivalence class of the best replacement
    // function statistics
    int              nTotalSubgs;    // the total number of subgraphs tried
    int              ClassTimes[222];// the runtimes for each class
    int              ClassGains[222];// the gains for each class
    int              ClassSubgs[222];// the graphs for each class
    int              nCutMemUsed;    // memory used for cuts
    // rewriting statistics
    int              nNodesInit;     // the original number of nodes
Alan Mishchenko committed
91
    int              nNodesTried;    // the number of nodes attempted
Alan Mishchenko committed
92 93 94 95 96 97 98
    int              nCutsAll;       // all cut pairs
    int              nCutsTried;     // computed cuts
    int              nCutsUsed;      // used cuts
    int              nCutsBad;       // bad cuts due to absent fanin
    int              nCutsGood;      // good cuts
    int              nCutsSkipped;   // skipped bad cuts
    // timing statistics
99 100 101 102 103 104
    abctime          timeCuts;
    abctime          timeEval;
    abctime          timeOther;
    abctime          timeTotal;
    abctime          time1;
    abctime          time2;
Alan Mishchenko committed
105 106
};

107
static inline Dar_Cut_t *  Dar_ObjCuts( Aig_Obj_t * pObj )                         { return (Dar_Cut_t *)pObj->pData;    }
Alan Mishchenko committed
108
static inline void         Dar_ObjSetCuts( Aig_Obj_t * pObj, Dar_Cut_t * pCuts )   { assert( !Aig_ObjIsNone(pObj) ); pObj->pData = pCuts;   }
Alan Mishchenko committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

////////////////////////////////////////////////////////////////////////
///                      MACRO DEFINITIONS                           ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                          ITERATORS                               ///
////////////////////////////////////////////////////////////////////////

// iterator over all cuts of the node
#define Dar_ObjForEachCutAll( pObj, pCut, i )                                   \
    for ( (pCut) = Dar_ObjCuts(pObj), i = 0; i < (int)(pObj)->nCuts; i++, pCut++ ) 
#define Dar_ObjForEachCut( pObj, pCut, i )                                      \
    for ( (pCut) = Dar_ObjCuts(pObj), i = 0; i < (int)(pObj)->nCuts; i++, pCut++ ) if ( (pCut)->fUsed==0 ) {} else
// iterator over leaves of the cut
#define Dar_CutForEachLeaf( p, pCut, pLeaf, i )                                 \
    for ( i = 0; (i < (int)(pCut)->nLeaves) && (((pLeaf) = Aig_ManObj(p, (pCut)->pLeaves[i])), 1); i++ )

////////////////////////////////////////////////////////////////////////
///                    FUNCTION DECLARATIONS                         ///
////////////////////////////////////////////////////////////////////////

/*=== darBalance.c ========================================================*/
Alan Mishchenko committed
132 133
/*=== darCore.c ===========================================================*/
/*=== darCut.c ============================================================*/
Alan Mishchenko committed
134
extern void            Dar_ManCutsRestart( Dar_Man_t * p, Aig_Obj_t * pRoot );
Alan Mishchenko committed
135
extern void            Dar_ManCutsFree( Dar_Man_t * p );
Alan Mishchenko committed
136
extern Dar_Cut_t *     Dar_ObjPrepareCuts( Dar_Man_t * p, Aig_Obj_t * pObj );
Alan Mishchenko committed
137
extern Dar_Cut_t *     Dar_ObjComputeCuts_rec( Dar_Man_t * p, Aig_Obj_t * pObj );
138
extern Dar_Cut_t *     Dar_ObjComputeCuts( Dar_Man_t * p, Aig_Obj_t * pObj, int fSkipTtMin );
Alan Mishchenko committed
139
extern void            Dar_ObjCutPrint( Aig_Man_t * p, Aig_Obj_t * pObj );
Alan Mishchenko committed
140
/*=== darData.c ===========================================================*/
Alan Mishchenko committed
141 142 143
extern Vec_Int_t *     Dar_LibReadNodes();
extern Vec_Int_t *     Dar_LibReadOuts();
extern Vec_Int_t *     Dar_LibReadPrios();
Alan Mishchenko committed
144
/*=== darLib.c ============================================================*/
Alan Mishchenko committed
145 146
extern void            Dar_LibStart();
extern void            Dar_LibStop();
Alan Mishchenko committed
147
extern void            Dar_LibReturnCanonicals( unsigned * pCanons );
148
extern void            Dar_LibEval( Dar_Man_t * p, Aig_Obj_t * pRoot, Dar_Cut_t * pCut, int Required, int * pnMffcSize );
Alan Mishchenko committed
149
extern Aig_Obj_t *     Dar_LibBuildBest( Dar_Man_t * p );
Alan Mishchenko committed
150
/*=== darMan.c ============================================================*/
Alan Mishchenko committed
151
extern Dar_Man_t *     Dar_ManStart( Aig_Man_t * pAig, Dar_RwrPar_t * pPars );
Alan Mishchenko committed
152 153
extern void            Dar_ManStop( Dar_Man_t * p );
extern void            Dar_ManPrintStats( Dar_Man_t * p );
Alan Mishchenko committed
154 155 156
/*=== darPrec.c ============================================================*/
extern char **         Dar_Permutations( int n );
extern void            Dar_Truth4VarNPN( unsigned short ** puCanons, char ** puPhases, char ** puPerms, unsigned char ** puMap );
Alan Mishchenko committed
157

158 159 160 161 162


ABC_NAMESPACE_HEADER_END


Alan Mishchenko committed
163 164 165 166 167 168 169

#endif

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