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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
/**CFile****************************************************************
FileName [acbPush.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Hierarchical word-level netlist.]
Synopsis [Implementation of logic pushing.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - July 21, 2015.]
Revision [$Id: acbPush.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
***********************************************************************/
#include "acb.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Pushing logic to the fanout.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Acb_ObjPushToFanout( Acb_Ntk_t * p, int iObj, int iFaninIndex, int iFanout )
{
word c0, uTruthObjNew, uTruthObj = Acb_ObjTruth( p, iObj ), Gate;
word c1, uTruthFanNew, uTruthFan = Acb_ObjTruth( p, iFanout );
int DecType = Abc_TtCheckOutAnd( uTruthObj, iFaninIndex, &uTruthObjNew );
int iFanin = Acb_ObjFanin( p, iObj, iFaninIndex );
int iFanoutObjIndex = Acb_ObjWhatFanin( p, iFanout, iObj );
int iFanoutFaninIndex = Acb_ObjWhatFanin( p, iFanout, iFanin );
if ( iFanoutFaninIndex == -1 )
iFanoutFaninIndex = Acb_ObjFaninNum(p, iFanout);
assert( !Acb_ObjIsCio(p, iObj) );
assert( !Acb_ObjIsCio(p, iFanout) );
assert( iFanoutFaninIndex >= 0 );
assert( iFaninIndex < Acb_ObjFaninNum(p, iObj) );
assert( Acb_ObjFanoutNum(p, iObj) == 1 );
// compute new function of the fanout
c0 = Abc_Tt6Cofactor0( uTruthFan, iFanoutObjIndex );
c1 = Abc_Tt6Cofactor1( uTruthFan, iFanoutObjIndex );
if ( DecType == 0 ) // F = i * G
Gate = s_Truths6[iFanoutFaninIndex] & s_Truths6[iFanoutObjIndex];
else if ( DecType == 1 ) // F = ~i * G
Gate = ~s_Truths6[iFanoutFaninIndex] & s_Truths6[iFanoutObjIndex];
else if ( DecType == 2 ) // F = ~i + G
Gate = ~s_Truths6[iFanoutFaninIndex] | s_Truths6[iFanoutObjIndex];
else if ( DecType == 3 ) // F = i + G
Gate = s_Truths6[iFanoutFaninIndex] | s_Truths6[iFanoutObjIndex];
else if ( DecType == 4 ) // F = i # G
Gate = s_Truths6[iFanoutFaninIndex] ^ s_Truths6[iFanoutObjIndex];
else assert( 0 );
uTruthFanNew = (~Gate & c0) | (Gate & c1);
// update functions
Vec_WrdWriteEntry( &p->vObjTruth, iObj, Abc_Tt6RemoveVar(uTruthObjNew, iFaninIndex) );
Vec_WrdWriteEntry( &p->vObjTruth, iFanout, uTruthFanNew );
// update fanins
Acb_ObjRemoveFaninFanoutOne( p, iObj, iFanin );
if ( iFanoutFaninIndex == Acb_ObjFaninNum(p, iFanout) ) // adding new
Acb_ObjAddFaninFanoutOne( p, iFanout, iFanin );
}
/**Function*************************************************************
Synopsis [Pushing logic to the fanin.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Acb_ObjPushToFanin( Acb_Ntk_t * p, int iObj, int iFaninIndex2, int iFanin )
{
word uTruthObjNew, uTruthObj = Acb_ObjTruth( p, iObj );
word uTruthFanNew, uTruthFan = Acb_ObjTruth( p, iFanin );
int iFaninIndex = Acb_ObjWhatFanin( p, iObj, iFanin );
int DecType = Abc_TtCheckDsdAnd( uTruthObj, iFaninIndex, iFaninIndex2, &uTruthObjNew );
int iFanin2 = Acb_ObjFanin( p, iObj, iFaninIndex2 );
int iFaninFaninIndex = Acb_ObjWhatFanin( p, iFanin, iFanin2 );
if ( iFaninFaninIndex == -1 )
iFaninFaninIndex = Acb_ObjFaninNum(p, iFanin);
assert( !Acb_ObjIsCio(p, iObj) );
assert( !Acb_ObjIsCio(p, iFanin) );
assert( iFaninIndex < Acb_ObjFaninNum(p, iObj) );
assert( iFaninIndex2 < Acb_ObjFaninNum(p, iObj) );
assert( iFaninIndex != iFaninIndex2 );
assert( Acb_ObjFanoutNum(p, iFanin) == 1 );
// compute new function of the fanout
if ( DecType == 0 ) // i * j
uTruthFanNew = uTruthFan & s_Truths6[iFaninFaninIndex];
else if ( DecType == 1 ) // i * !j
uTruthFanNew = ~uTruthFan & s_Truths6[iFaninFaninIndex];
else if ( DecType == 2 ) // !i * j
uTruthFanNew = uTruthFan & ~s_Truths6[iFaninFaninIndex];
else if ( DecType == 3 ) // !i * !j
uTruthFanNew = ~uTruthFan & ~s_Truths6[iFaninFaninIndex];
else if ( DecType == 4 ) // i # j
uTruthFanNew = uTruthFan ^ s_Truths6[iFaninFaninIndex];
else assert( 0 );
// update functions
Vec_WrdWriteEntry( &p->vObjTruth, iObj, Abc_Tt6RemoveVar(uTruthObjNew, iFaninIndex2) );
Vec_WrdWriteEntry( &p->vObjTruth, iFanin, uTruthFanNew );
// update fanins
Acb_ObjRemoveFaninFanoutOne( p, iObj, iFanin2 );
if ( iFaninFaninIndex == Acb_ObjFaninNum(p, iFanin) ) // adding new
Acb_ObjAddFaninFanoutOne( p, iFanin, iFanin2 );
}
/**Function*************************************************************
Synopsis [Removing constants, buffers, duplicated fanins.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Acb_ObjFindNodeFanout( Acb_Ntk_t * p, int iObj )
{
int i, iFanout;
Acb_ObjForEachFanout( p, iObj, iFanout, i )
if ( !Acb_ObjIsCio(p, iFanout) )
return iFanout;
return -1;
}
int Acb_ObjSuppMin_int( Acb_Ntk_t * p, int iObj )
{
int k, iFanin, * pFanins;
word uTruth = Acb_ObjTruth( p, iObj );
Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
{
if ( Abc_Tt6HasVar(uTruth, k) )
continue;
Acb_ObjDeleteFaninIndex( p, iObj, k );
Vec_IntRemove( Vec_WecEntry(&p->vFanouts, iFanin), iObj );
Vec_WrdWriteEntry( &p->vObjTruth, iObj, Abc_Tt6RemoveVar(uTruth, k) );
return 1;
}
return 0;
}
void Acb_ObjSuppMin( Acb_Ntk_t * p, int iObj )
{
while ( Acb_ObjSuppMin_int(p, iObj) );
}
void Acb_ObjRemoveDup( Acb_Ntk_t * p, int iObj, int i, int j )
{
word c00, c11, uTruthNew, uTruth = Acb_ObjTruth( p, iObj );
assert( !Acb_ObjIsCio(p, iObj) );
assert( Acb_ObjFanin(p, iObj, i) == Acb_ObjFanin(p, iObj, j) );
c00 = Abc_Tt6Cofactor0( Abc_Tt6Cofactor0(uTruth, i), j );
c11 = Abc_Tt6Cofactor1( Abc_Tt6Cofactor1(uTruth, i), j );
uTruthNew = (~s_Truths6[i] & c00) | (s_Truths6[i] & c11);
Vec_WrdWriteEntry( &p->vObjTruth, iObj, Abc_Tt6RemoveVar(uTruthNew, j) );
Acb_ObjDeleteFaninIndex( p, iObj, j );
Vec_IntRemove( Vec_WecEntry(&p->vFanouts, iObj), Acb_ObjFanin(p, iObj, j) );
Acb_ObjSuppMin( p, iObj );
}
int Acb_ObjRemoveDupFanins_int( Acb_Ntk_t * p, int iObj )
{
int i, k, * pFanins = Acb_ObjFanins( p, iObj );
for ( i = 0; i < pFanins[0]; i++ )
for ( k = i+1; k < pFanins[0]; k++ )
{
if ( pFanins[1+i] != pFanins[1+k] )
continue;
Acb_ObjRemoveDup( p, iObj, i, k );
return 1;
}
return 0;
}
void Acb_ObjRemoveDupFanins( Acb_Ntk_t * p, int iObj )
{
assert( !Acb_ObjIsCio(p, iObj) );
while ( Acb_ObjRemoveDupFanins_int(p, iObj) );
}
void Acb_ObjRemoveConst( Acb_Ntk_t * p, int iObj )
{
int iFanout;
word uTruth = Acb_ObjTruth( p, iObj );
assert( !Acb_ObjIsCio(p, iObj) );
assert( Acb_ObjFaninNum(p, iObj) == 0 );
assert( uTruth == 0 || ~uTruth == 0 );
while ( (iFanout = Acb_ObjFindNodeFanout(p, iObj)) >= 0 )
{
int iObjIndex = Acb_ObjWhatFanin( p, iFanout, iObj );
word uTruthF = Acb_ObjTruth( p, iFanout );
Acb_ObjRemoveFaninFanoutOne( p, iFanout, iObj );
uTruthF = (uTruth & 1) ? Abc_Tt6Cofactor1(uTruthF, iObjIndex) : Abc_Tt6Cofactor0(uTruthF, iObjIndex);
Vec_WrdWriteEntry( &p->vObjTruth, iFanout, Abc_Tt6RemoveVar(uTruthF, iObjIndex) );
Acb_ObjSuppMin( p, iFanout );
}
if ( Acb_ObjFanoutNum(p, iObj) == 0 )
Acb_ObjCleanType( p, iObj );
}
void Acb_ObjRemoveBufInv( Acb_Ntk_t * p, int iObj )
{
int iFanout;
word uTruth = Acb_ObjTruth( p, iObj );
assert( !Acb_ObjIsCio(p, iObj) );
assert( Acb_ObjFaninNum(p, iObj) == 1 );
assert( uTruth == s_Truths6[0] || ~uTruth == s_Truths6[0] );
while ( (iFanout = Acb_ObjFindNodeFanout(p, iObj)) >= 0 )
{
int iFanin = Acb_ObjFanin( p, iObj, 0 );
int iObjIndex = Acb_ObjWhatFanin( p, iFanout, iObj );
Acb_ObjPatchFanin( p, iFanout, iObj, iFanin );
if ( uTruth & 1 ) // inv
{
word uTruthF = Acb_ObjTruth( p, iFanout );
Vec_WrdWriteEntry( &p->vObjTruth, iFanout, Abc_Tt6Flip(uTruthF, iObjIndex) );
}
Acb_ObjRemoveDupFanins( p, iFanout );
}
while ( (uTruth & 1) == 0 && Acb_ObjFanoutNum(p, iObj) > 0 )
{
int iFanin = Acb_ObjFanin( p, iObj, 0 );
int iFanout = Acb_ObjFanout( p, iObj, 0 );
assert( Acb_ObjIsCo(p, iFanout) );
Acb_ObjPatchFanin( p, iFanout, iObj, iFanin );
}
if ( Acb_ObjFanoutNum(p, iObj) == 0 )
{
Acb_ObjRemoveFaninFanout( p, iObj );
Acb_ObjRemoveFanins( p, iObj );
Acb_ObjCleanType( p, iObj );
}
}
/**Function*************************************************************
Synopsis [Check if the node can have its logic pushed.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Acb_ObjFindPushableIndex( Acb_Ntk_t * p, int iObj, int iFanIndex )
{
int k, iFanin, * pFanins;
Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
if ( k != iFanIndex && Abc_TtCheckDsdAnd(Acb_ObjTruth(p, iObj), k, iFanIndex, NULL) >= 0 )
return k;
return -1;
}
int Acb_ObjPushToFanins( Acb_Ntk_t * p, int iObj, int nLutSize )
{
int k, k2, iFanin, * pFanins;
if ( Acb_ObjFaninNum(p, iObj) < 2 )
return 0;
Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
{
if ( Acb_ObjIsCi(p, iFanin) )
continue;
if ( Acb_ObjFanoutNum(p, iFanin) > 1 )
continue;
if ( Acb_ObjFaninNum(p, iFanin) == nLutSize )
continue;
if ( (k2 = Acb_ObjFindPushableIndex(p, iObj, k)) == -1 )
continue;
Acb_ObjPushToFanin( p, iObj, k2, iFanin );
return 1;
}
return 0;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Acb_NtkPushLogic( Acb_Ntk_t * p, int nLutSize, int fVerbose )
{
int n = 0, iObj, nNodes = Acb_NtkNodeNum(p), nPushes = 0;
Acb_NtkCreateFanout( p ); // fanout data structure
Acb_NtkForEachNodeSupp( p, iObj, 0 )
Acb_ObjRemoveConst( p, iObj );
Acb_NtkForEachNodeSupp( p, iObj, 1 )
Acb_ObjRemoveBufInv( p, iObj );
for ( n = 2; n <= nLutSize; n++ )
Acb_NtkForEachNodeSupp( p, iObj, n )
{
while ( Acb_ObjPushToFanins(p, iObj, nLutSize) )
nPushes++;
if ( Acb_ObjFaninNum(p, iObj) == 1 )
Acb_ObjRemoveBufInv( p, iObj );
}
printf( "Saved %d nodes after %d pushes.\n", nNodes - Acb_NtkNodeNum(p), nPushes );
}
/**Function*************************************************************
Synopsis [Pushing logic to the fanin.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Acb_NtkPushLogic2( Acb_Ntk_t * p, int nLutSize, int fVerbose )
{
int iObj;
Acb_NtkCreateFanout( p ); // fanout data structure
Acb_NtkForEachObj( p, iObj )
if ( !Acb_ObjIsCio(p, iObj) )
break;
Acb_ObjPushToFanout( p, iObj, Acb_ObjFaninNum(p, iObj)-1, Acb_ObjFanout(p, iObj, 0) );
// Acb_ObjPushToFanin( p, Acb_ObjFanout(p, iObj, 0), Acb_ObjFaninNum(p, iObj)-1, iObj );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|