abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
retCore.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [retCore.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Retiming package.]
8 
9  Synopsis [The core retiming procedures.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - Oct 31, 2006.]
16 
17  Revision [$Id: retCore.c,v 1.00 2006/10/31 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "retInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Implementation of retiming.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 int Abc_NtkRetime( Abc_Ntk_t * pNtk, int Mode, int nDelayLim, int fForwardOnly, int fBackwardOnly, int fOneStep, int fVerbose )
48 {
49  int nLatches = Abc_NtkLatchNum(pNtk);
50  int nLevels = Abc_NtkLevel(pNtk);
51  int RetValue = 0;
52  abctime clkTotal = Abc_Clock();
53  int nNodesOld, nLatchesOld;
54  assert( Mode > 0 && Mode < 7 );
55  assert( !fForwardOnly || !fBackwardOnly );
56 
57  // cleanup the network
58  nNodesOld = Abc_NtkNodeNum(pNtk);
59  nLatchesOld = Abc_NtkLatchNum(pNtk);
60  Abc_NtkCleanupSeq(pNtk, 0, 0, 0);
61  if ( nNodesOld > Abc_NtkNodeNum(pNtk) || nLatchesOld > Abc_NtkLatchNum(pNtk) )
62  printf( "Cleanup before retiming removed %d dangling nodes and %d dangling latches.\n",
63  nNodesOld - Abc_NtkNodeNum(pNtk), nLatchesOld - Abc_NtkLatchNum(pNtk) );
64 
65  // perform retiming
66  switch ( Mode )
67  {
68  case 1: // forward
69  RetValue = Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 0, 0, fVerbose );
70  break;
71  case 2: // backward
72  RetValue = Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 0, 0, fVerbose );
73  break;
74  case 3: // min-area
75  RetValue = Abc_NtkRetimeMinArea( pNtk, fForwardOnly, fBackwardOnly, fVerbose );
76  break;
77  case 4: // min-delay
78  if ( !fBackwardOnly )
79  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 1, fOneStep, fVerbose );
80  if ( !fForwardOnly )
81  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 1, fOneStep, fVerbose );
82  break;
83  case 5: // min-area + min-delay
84  RetValue = Abc_NtkRetimeMinArea( pNtk, fForwardOnly, fBackwardOnly, fVerbose );
85  if ( !fBackwardOnly )
86  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 1, 0, fVerbose );
87  if ( !fForwardOnly )
88  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 1, 0, fVerbose );
89  break;
90  case 6: // Pan's algorithm
91  RetValue = Abc_NtkRetimeLValue( pNtk, 500, fVerbose );
92  break;
93  default:
94  printf( "Unknown retiming option.\n" );
95  break;
96  }
97  if ( fVerbose )
98  {
99  printf( "Reduction in area = %3d. Reduction in delay = %3d. ",
100  nLatches - Abc_NtkLatchNum(pNtk), nLevels - Abc_NtkLevel(pNtk) );
101  ABC_PRT( "Total runtime", Abc_Clock() - clkTotal );
102  }
103  timeRetime = Abc_Clock() - clkTotal;
104  return RetValue;
105 }
106 
107 /**Function*************************************************************
108 
109  Synopsis [Used for automated debugging.]
110 
111  Description []
112 
113  SideEffects []
114 
115  SeeAlso []
116 
117 ***********************************************************************/
119 {
120  extern int Abc_NtkSecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nFrames, int fVerbose );
121  Abc_Ntk_t * pNtkRet;
122  assert( Abc_NtkIsLogic(pNtk) );
123  Abc_NtkToSop( pNtk, 0 );
124 // if ( !Abc_NtkCheck( pNtk ) )
125 // fprintf( stdout, "Abc_NtkRetimeDebug(): Network check has failed.\n" );
126 // Io_WriteBlifLogic( pNtk, "debug_temp.blif", 1 );
127  pNtkRet = Abc_NtkDup( pNtk );
128  Abc_NtkRetime( pNtkRet, 3, 0, 0, 1, 0, 0 ); // debugging backward flow
129  return !Abc_NtkSecFraig( pNtk, pNtkRet, 10000, 3, 0 );
130 }
131 
132 ////////////////////////////////////////////////////////////////////////
133 /// END OF FILE ///
134 ////////////////////////////////////////////////////////////////////////
135 
136 
138 
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
int Abc_NtkRetimeDebug(Abc_Ntk_t *pNtk)
Definition: retCore.c:118
int Abc_NtkRetimeLValue(Abc_Ntk_t *pNtk, int nIterLimit, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retLvalue.c:61
ABC_NAMESPACE_IMPL_START abctime timeRetime
DECLARATIONS ///.
Definition: retCore.c:30
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static abctime Abc_Clock()
Definition: abc_global.h:279
int Abc_NtkRetime(Abc_Ntk_t *pNtk, int Mode, int nDelayLim, int fForwardOnly, int fBackwardOnly, int fOneStep, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retCore.c:47
int Abc_NtkRetimeMinArea(Abc_Ntk_t *pNtk, int fForwardOnly, int fBackwardOnly, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retArea.c:53
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
int Abc_NtkSecFraig(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int nSeconds, int nFrames, int fVerbose)
Definition: abcVerify.c:568
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Abc_NtkRetimeIncremental(Abc_Ntk_t *pNtk, int nDelayLim, int fForward, int fMinDelay, int fOneStep, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retIncrem.c:47
#define assert(ex)
Definition: util_old.h:213
ABC_DLL int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
Definition: abcSweep.c:909
ABC_INT64_T abctime
Definition: abc_global.h:278
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265