1 /**CFile****************************************************************
2
3 FileName [abcBidec.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Network and node package.]
8
9 Synopsis [Interface to bi-decomposition.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - June 20, 2005.]
16
17 Revision [$Id: abcBidec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "base/abc/abc.h"
22 #include "bool/bdc/bdc.h"
23 #include "bool/kit/kit.h"
24
25 ABC_NAMESPACE_IMPL_START
26
27
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31
Bdc_FunCopyHop(Bdc_Fun_t * pObj)32 static inline Hop_Obj_t * Bdc_FunCopyHop( Bdc_Fun_t * pObj ) { return Hop_NotCond( (Hop_Obj_t *)Bdc_FuncCopy(Bdc_Regular(pObj)), Bdc_IsComplement(pObj) ); }
33
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37
38 /**Function*************************************************************
39
40 Synopsis [Resynthesizes nodes using bi-decomposition.]
41
42 Description []
43
44 SideEffects []
45
46 SeeAlso []
47
48 ***********************************************************************/
Abc_NodeIfNodeResyn(Bdc_Man_t * p,Hop_Man_t * pHop,Hop_Obj_t * pRoot,int nVars,Vec_Int_t * vTruth,unsigned * puCare,float dProb)49 Hop_Obj_t * Abc_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb )
50 {
51 unsigned * pTruth;
52 Bdc_Fun_t * pFunc;
53 int nNodes, i;
54 assert( nVars <= 16 );
55 // derive truth table
56 pTruth = Hop_ManConvertAigToTruth( pHop, Hop_Regular(pRoot), nVars, vTruth, 0 );
57 if ( Hop_IsComplement(pRoot) )
58 Extra_TruthNot( pTruth, pTruth, nVars );
59 // perform power-aware decomposition
60 if ( dProb >= 0.0 )
61 {
62 float Prob = (float)2.0 * dProb * (1.0 - dProb);
63 assert( Prob >= 0.0 && Prob <= 0.5 );
64 if ( Prob >= 0.4 )
65 {
66 Extra_TruthNot( puCare, puCare, nVars );
67 if ( dProb > 0.5 ) // more 1s than 0s
68 Extra_TruthOr( pTruth, pTruth, puCare, nVars );
69 else
70 Extra_TruthSharp( pTruth, pTruth, puCare, nVars );
71 Extra_TruthNot( puCare, puCare, nVars );
72 // decompose truth table
73 Bdc_ManDecompose( p, pTruth, NULL, nVars, NULL, 1000 );
74 }
75 else
76 {
77 // decompose truth table
78 Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
79 }
80 }
81 else
82 {
83 // decompose truth table
84 Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
85 }
86 // convert back into HOP
87 Bdc_FuncSetCopy( Bdc_ManFunc( p, 0 ), Hop_ManConst1( pHop ) );
88 for ( i = 0; i < nVars; i++ )
89 Bdc_FuncSetCopy( Bdc_ManFunc( p, i+1 ), Hop_ManPi( pHop, i ) );
90 nNodes = Bdc_ManNodeNum(p);
91 for ( i = nVars + 1; i < nNodes; i++ )
92 {
93 pFunc = Bdc_ManFunc( p, i );
94 Bdc_FuncSetCopy( pFunc, Hop_And( pHop, Bdc_FunCopyHop(Bdc_FuncFanin0(pFunc)), Bdc_FunCopyHop(Bdc_FuncFanin1(pFunc)) ) );
95 }
96 return Bdc_FunCopyHop( Bdc_ManRoot(p) );
97 }
98
99 /**Function*************************************************************
100
101 Synopsis [Resynthesizes nodes using bi-decomposition.]
102
103 Description []
104
105 SideEffects []
106
107 SeeAlso []
108
109 ***********************************************************************/
Abc_NtkBidecResyn(Abc_Ntk_t * pNtk,int fVerbose)110 void Abc_NtkBidecResyn( Abc_Ntk_t * pNtk, int fVerbose )
111 {
112 Bdc_Par_t Pars = {0}, * pPars = &Pars;
113 Bdc_Man_t * p;
114 Abc_Obj_t * pObj;
115 Vec_Int_t * vTruth;
116 int i, nGainTotal = 0, nNodes1, nNodes2;
117 abctime clk = Abc_Clock();
118 assert( Abc_NtkIsLogic(pNtk) );
119 if ( !Abc_NtkToAig(pNtk) )
120 return;
121 pPars->nVarsMax = Abc_NtkGetFaninMax( pNtk );
122 pPars->fVerbose = fVerbose;
123 if ( pPars->nVarsMax > 15 )
124 {
125 if ( fVerbose )
126 printf( "Resynthesis is not performed for nodes with more than 15 inputs.\n" );
127 pPars->nVarsMax = 15;
128 }
129 vTruth = Vec_IntAlloc( 0 );
130 p = Bdc_ManAlloc( pPars );
131 Abc_NtkForEachNode( pNtk, pObj, i )
132 {
133 if ( Abc_ObjFaninNum(pObj) > 15 )
134 continue;
135 nNodes1 = Hop_DagSize((Hop_Obj_t *)pObj->pData);
136 pObj->pData = Abc_NodeIfNodeResyn( p, (Hop_Man_t *)pNtk->pManFunc, (Hop_Obj_t *)pObj->pData, Abc_ObjFaninNum(pObj), vTruth, NULL, -1.0 );
137 nNodes2 = Hop_DagSize((Hop_Obj_t *)pObj->pData);
138 nGainTotal += nNodes1 - nNodes2;
139 }
140 Bdc_ManFree( p );
141 Vec_IntFree( vTruth );
142 if ( fVerbose )
143 {
144 printf( "Total gain in AIG nodes = %d. ", nGainTotal );
145 ABC_PRT( "Total runtime", Abc_Clock() - clk );
146 }
147 }
148
149
150 ////////////////////////////////////////////////////////////////////////
151 /// END OF FILE ///
152 ////////////////////////////////////////////////////////////////////////
153
154
155 ABC_NAMESPACE_IMPL_END
156
157