1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/**CFile****************************************************************
FileName [abcFxu.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Interface with the fast extract package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: abcFxu.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "src/base/abc/abc.h"
#include "src/opt/fxu/fxu.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk );
static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Performs fast_extract on the current network.]
Description [Takes the network and the maximum number of nodes to extract.
Uses the concurrent double-cube and single cube divisor extraction procedure.
Modifies the network in the end, after extracting all nodes. Note that
Ntk_NetworkSweep() may increase the performance of this procedure because
the single-literal nodes will not be created in the sparse matrix. Returns 1
if the network has been changed.]
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_NtkFastExtract( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
{
assert( Abc_NtkIsLogic(pNtk) );
// if the network is already in the SOP form, it may come from BLIF file
// and it may not be SCC-ABC_FREE, in which case FXU will not work correctly
if ( Abc_NtkIsSopLogic(pNtk) )
{ // to make sure the SOPs are SCC-ABC_FREE
// Abc_NtkSopToBdd(pNtk);
// Abc_NtkBddToSop(pNtk);
}
// get the network in the SOP form
if ( !Abc_NtkToSop(pNtk, 0) )
{
printf( "Abc_NtkFastExtract(): Converting to SOPs has failed.\n" );
return 0;
}
// check if the network meets the requirements
if ( !Abc_NtkFxuCheck(pNtk) )
{
printf( "Abc_NtkFastExtract: Nodes have duplicated or complemented fanins. FXU is not performed.\n" );
return 0;
}
// sweep removes useless nodes
Abc_NtkCleanup( pNtk, 0 );
// collect information about the covers
Abc_NtkFxuCollectInfo( pNtk, p );
// call the fast extract procedure
if ( Fxu_FastExtract(p) > 0 )
{
// update the network
Abc_NtkFxuReconstruct( pNtk, p );
// make sure everything is okay
if ( !Abc_NtkCheck( pNtk ) )
printf( "Abc_NtkFastExtract: The network check has failed.\n" );
return 1;
}
else
printf( "Warning: The network has not been changed by \"fx\".\n" );
return 0;
}
/**Function*************************************************************
Synopsis [Makes sure the nodes do not have complemented and duplicated fanins.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk )
{
Abc_Obj_t * pNode, * pFanin1, * pFanin2;
int n, i, k;
Abc_NtkForEachNode( pNtk, pNode, n )
{
Abc_ObjForEachFanin( pNode, pFanin1, i )
{
if ( i < 2 && Abc_ObjFaninC(pNode, i) )
return 0;
Abc_ObjForEachFanin( pNode, pFanin2, k )
{
if ( i == k )
continue;
if ( pFanin1 == pFanin2 )
return 0;
}
}
}
return 1;
}
/**Function*************************************************************
Synopsis [Collect information about the network for fast_extract.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
{
Abc_Obj_t * pNode;
int i;
// add information to the manager
p->pManSop = (Mem_Flex_t *)pNtk->pManFunc;
p->vSops = Vec_PtrAlloc(0);
p->vFanins = Vec_PtrAlloc(0);
p->vSopsNew = Vec_PtrAlloc(0);
p->vFaninsNew = Vec_PtrAlloc(0);
Vec_PtrFill( p->vSops, Abc_NtkObjNumMax(pNtk), NULL );
Vec_PtrFill( p->vFanins, Abc_NtkObjNumMax(pNtk), NULL );
Vec_PtrFill( p->vSopsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
Vec_PtrFill( p->vFaninsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
// add SOPs and fanin array
Abc_NtkForEachNode( pNtk, pNode, i )
{
if ( Abc_SopGetVarNum((char *)pNode->pData) < 2 )
continue;
if ( Abc_SopGetCubeNum((char *)pNode->pData) < 1 )
continue;
p->vSops->pArray[i] = pNode->pData;
p->vFanins->pArray[i] = &pNode->vFanins;
}
p->nNodesOld = Abc_NtkObjNumMax(pNtk);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkFxuFreeInfo( Fxu_Data_t * p )
{
int i;
// free the arrays of new fanins
if ( p->vFaninsNew )
for ( i = 0; i < p->vFaninsNew->nSize; i++ )
if ( p->vFaninsNew->pArray[i] )
Vec_IntFree( (Vec_Int_t *)p->vFaninsNew->pArray[i] );
// free the arrays
if ( p->vSops ) Vec_PtrFree( p->vSops );
if ( p->vSopsNew ) Vec_PtrFree( p->vSopsNew );
if ( p->vFanins ) Vec_PtrFree( p->vFanins );
if ( p->vFaninsNew ) Vec_PtrFree( p->vFaninsNew );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Reconstructs the network after FX.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
{
Vec_Int_t * vFanins;
Abc_Obj_t * pNode, * pFanin;
int i, k;
assert( p->vFanins->nSize < p->vFaninsNew->nSize );
// create the new nodes
for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
{
// start the node
pNode = Abc_NtkCreateNode( pNtk );
assert( i == (int)pNode->Id );
}
// update the old nodes
for ( i = 0; i < p->vFanins->nSize; i++ )
{
// the new array of fanins
vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
if ( vFanins == NULL )
continue;
// remove old fanins
pNode = Abc_NtkObj( pNtk, i );
Abc_ObjRemoveFanins( pNode );
// add new fanins
vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
for ( k = 0; k < vFanins->nSize; k++ )
{
pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
Abc_ObjAddFanin( pNode, pFanin );
}
pNode->pData = p->vSopsNew->pArray[i];
assert( pNode->pData != NULL );
}
// set up the new nodes
for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
{
// get the new node
pNode = Abc_NtkObj( pNtk, i );
// add the fanins
vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
for ( k = 0; k < vFanins->nSize; k++ )
{
pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
Abc_ObjAddFanin( pNode, pFanin );
}
pNode->pData = p->vSopsNew->pArray[i];
assert( pNode->pData != NULL );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|