1 /**CFile****************************************************************
2
3 FileName [rwrCut.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [DAG-aware AIG rewriting package.]
8
9 Synopsis [Cut computation.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - June 20, 2005.]
16
17 Revision [$Id: rwrCut.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "rwr.h"
22
23 ABC_NAMESPACE_IMPL_START
24
25
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33
34 /**Function*************************************************************
35
36 Synopsis [Adds one node.]
37
38 Description []
39
40 SideEffects []
41
42 SeeAlso []
43
44 ***********************************************************************/
Rwr_Trav2_rec(Rwr_Man_t * p,Rwr_Node_t * pNode,int * pVolume)45 void Rwr_Trav2_rec( Rwr_Man_t * p, Rwr_Node_t * pNode, int * pVolume )
46 {
47 if ( pNode->fUsed || pNode->TravId == p->nTravIds )
48 return;
49 pNode->TravId = p->nTravIds;
50 (*pVolume)++;
51 Rwr_Trav2_rec( p, Rwr_Regular(pNode->p0), pVolume );
52 Rwr_Trav2_rec( p, Rwr_Regular(pNode->p1), pVolume );
53 }
54
55 /**Function*************************************************************
56
57 Synopsis [Adds the node to the end of the list.]
58
59 Description []
60
61 SideEffects []
62
63 SeeAlso []
64
65 ***********************************************************************/
Rwr_GetBushVolume(Rwr_Man_t * p,int Entry,int * pVolume,int * pnFuncs)66 void Rwr_GetBushVolume( Rwr_Man_t * p, int Entry, int * pVolume, int * pnFuncs )
67 {
68 Rwr_Node_t * pNode;
69 int Volume = 0;
70 int nFuncs = 0;
71 Rwr_ManIncTravId( p );
72 for ( pNode = p->pTable[Entry]; pNode; pNode = pNode->pNext )
73 {
74 if ( pNode->uTruth != p->puCanons[pNode->uTruth] )
75 continue;
76 nFuncs++;
77 Rwr_Trav2_rec( p, pNode, &Volume );
78 }
79 *pVolume = Volume;
80 *pnFuncs = nFuncs;
81 }
82
83 /**Function*************************************************************
84
85 Synopsis [Adds the node to the end of the list.]
86
87 Description []
88
89 SideEffects []
90
91 SeeAlso []
92
93 ***********************************************************************/
Rwr_GetBushSumOfVolumes(Rwr_Man_t * p,int Entry)94 int Rwr_GetBushSumOfVolumes( Rwr_Man_t * p, int Entry )
95 {
96 Rwr_Node_t * pNode;
97 int Volume, VolumeTotal = 0;
98 for ( pNode = p->pTable[Entry]; pNode; pNode = pNode->pNext )
99 {
100 if ( pNode->uTruth != p->puCanons[pNode->uTruth] )
101 continue;
102 Volume = 0;
103 Rwr_ManIncTravId( p );
104 Rwr_Trav2_rec( p, pNode, &Volume );
105 VolumeTotal += Volume;
106 }
107 return VolumeTotal;
108 }
109
110 /**Function*************************************************************
111
112 Synopsis [Prints one rwr node.]
113
114 Description []
115
116 SideEffects []
117
118 SeeAlso []
119
120 ***********************************************************************/
Rwr_NodePrint_rec(FILE * pFile,Rwr_Node_t * pNode)121 void Rwr_NodePrint_rec( FILE * pFile, Rwr_Node_t * pNode )
122 {
123 assert( !Rwr_IsComplement(pNode) );
124
125 if ( pNode->Id == 0 )
126 {
127 fprintf( pFile, "Const1" );
128 return;
129 }
130
131 if ( pNode->Id < 5 )
132 {
133 fprintf( pFile, "%c", 'a' + pNode->Id - 1 );
134 return;
135 }
136
137 if ( Rwr_IsComplement(pNode->p0) )
138 {
139 if ( Rwr_Regular(pNode->p0)->Id < 5 )
140 {
141 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
142 fprintf( pFile, "\'" );
143 }
144 else
145 {
146 fprintf( pFile, "(" );
147 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
148 fprintf( pFile, ")\'" );
149 }
150 }
151 else
152 {
153 if ( Rwr_Regular(pNode->p0)->Id < 5 )
154 {
155 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
156 }
157 else
158 {
159 fprintf( pFile, "(" );
160 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p0) );
161 fprintf( pFile, ")" );
162 }
163 }
164
165 if ( pNode->fExor )
166 fprintf( pFile, "+" );
167
168 if ( Rwr_IsComplement(pNode->p1) )
169 {
170 if ( Rwr_Regular(pNode->p1)->Id < 5 )
171 {
172 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
173 fprintf( pFile, "\'" );
174 }
175 else
176 {
177 fprintf( pFile, "(" );
178 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
179 fprintf( pFile, ")\'" );
180 }
181 }
182 else
183 {
184 if ( Rwr_Regular(pNode->p1)->Id < 5 )
185 {
186 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
187 }
188 else
189 {
190 fprintf( pFile, "(" );
191 Rwr_NodePrint_rec( pFile, Rwr_Regular(pNode->p1) );
192 fprintf( pFile, ")" );
193 }
194 }
195 }
196
197 /**Function*************************************************************
198
199 Synopsis [Prints one rwr node.]
200
201 Description []
202
203 SideEffects []
204
205 SeeAlso []
206
207 ***********************************************************************/
Rwr_NodePrint(FILE * pFile,Rwr_Man_t * p,Rwr_Node_t * pNode)208 void Rwr_NodePrint( FILE * pFile, Rwr_Man_t * p, Rwr_Node_t * pNode )
209 {
210 unsigned uTruth;
211 fprintf( pFile, "%5d : ", pNode->Id );
212 uTruth = pNode->uTruth;
213 Extra_PrintHex( pFile, &uTruth, 4 );
214 fprintf( pFile, " tt=" );
215 Extra_PrintBinary( pFile, &uTruth, 16 );
216 // fprintf( pFile, " cn=", pNode->Id );
217 // uTruth = p->puCanons[pNode->uTruth];
218 // Extra_PrintBinary( pFile, &uTruth, 16 );
219 fprintf( pFile, " lev=%d", pNode->Level );
220 fprintf( pFile, " vol=%d", pNode->Volume );
221 fprintf( pFile, " " );
222 Rwr_NodePrint_rec( pFile, pNode );
223 fprintf( pFile, "\n" );
224 }
225
226 /**Function*************************************************************
227
228 Synopsis [Prints one rwr node.]
229
230 Description []
231
232 SideEffects []
233
234 SeeAlso []
235
236 ***********************************************************************/
Rwr_ManPrint(Rwr_Man_t * p)237 void Rwr_ManPrint( Rwr_Man_t * p )
238 {
239 FILE * pFile;
240 Rwr_Node_t * pNode;
241 unsigned uTruth;
242 int Limit, Counter, Volume, nFuncs, i;
243 pFile = fopen( "graph_lib.txt", "w" );
244 Counter = 0;
245 Limit = (1 << 16);
246 for ( i = 0; i < Limit; i++ )
247 {
248 if ( p->pTable[i] == NULL )
249 continue;
250 if ( i != p->puCanons[i] )
251 continue;
252 fprintf( pFile, "\nClass %3d. Func %6d. ", p->pMap[i], Counter++ );
253 Rwr_GetBushVolume( p, i, &Volume, &nFuncs );
254 fprintf( pFile, "Roots = %3d. Vol = %3d. Sum = %3d. ", nFuncs, Volume, Rwr_GetBushSumOfVolumes(p, i) );
255 uTruth = i;
256 Extra_PrintBinary( pFile, &uTruth, 16 );
257 fprintf( pFile, "\n" );
258 for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
259 if ( pNode->uTruth == p->puCanons[pNode->uTruth] )
260 Rwr_NodePrint( pFile, p, pNode );
261 }
262 fclose( pFile );
263 }
264
265 ////////////////////////////////////////////////////////////////////////
266 /// END OF FILE ///
267 ////////////////////////////////////////////////////////////////////////
268
269
270 ABC_NAMESPACE_IMPL_END
271
272