66 Vec_Int_t * vCarryRoots = Vec_IntAlloc( 100 );
67 Vec_Bit_t * vIns = Vec_BitStart( Gia_ManObjNum(
p) );
int i;
69 for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
71 Vec_BitWriteEntry( vIns, Vec_IntEntry(vAdds, 6*i+0), 1 );
72 Vec_BitWriteEntry( vIns, Vec_IntEntry(vAdds, 6*i+1), 1 );
73 Vec_BitWriteEntry( vIns, Vec_IntEntry(vAdds, 6*i+2), 1 );
76 for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
77 if ( !Vec_BitEntry(vIns, Vec_IntEntry(vAdds, 6*i+4)) )
78 Vec_IntPush( vCarryRoots, Vec_IntEntry(vAdds, 6*i+4) );
84 Vec_Int_t * vXorRoots = Vec_IntAlloc( 100 );
85 Vec_Bit_t * vIns = Vec_BitStart( Gia_ManObjNum(
p) );
int i;
87 for ( i = 0; 4*i < Vec_IntSize(vXors); i++ )
89 Vec_BitWriteEntry( vIns, Vec_IntEntry(vXors, 4*i+1), 1 );
90 Vec_BitWriteEntry( vIns, Vec_IntEntry(vXors, 4*i+2), 1 );
91 Vec_BitWriteEntry( vIns, Vec_IntEntry(vXors, 4*i+3), 1 );
94 for ( i = 0; 4*i < Vec_IntSize(vXors); i++ )
95 if ( !Vec_BitEntry(vIns, Vec_IntEntry(vXors, 4*i)) )
96 Vec_IntPush( vXorRoots, Vec_IntEntry(vXors, 4*i) );
103 if ( Node == 0 || Gia_ObjIsTravIdCurrentId(
p, Node) )
105 Gia_ObjSetTravIdCurrentId(
p, Node);
106 iXorBox = Vec_IntEntry( vXorMap, Node );
109 if ( Vec_BitEntry(vIsCarryRoot, Node) )
110 Vec_IntPush( vCarryRootSet, Node );
113 for ( k = 1; k < 4; k++ )
115 Vec_IntPush( vXorSet, Vec_IntEntry(vXors, 4*iXorBox) );
119 Vec_Wec_t * vCarryRootSets = Vec_WecAlloc( 100 );
120 Vec_Int_t * vCarryRootSet = Vec_IntAlloc( 100 );
121 Vec_Bit_t * vIsCarryRoot = Vec_BitStart( Gia_ManObjNum(
p) );
122 Vec_Int_t * vXorSet = Vec_IntAlloc( 100 ), * vLevel;
123 int i, k, XorRoot, CarryRoot;
125 Vec_Int_t * vXorMap = Vec_IntStartFull( Gia_ManObjNum(
p) );
126 for ( i = 0; 4*i < Vec_IntSize(vXors); i++ )
127 Vec_IntWriteEntry( vXorMap, Vec_IntEntry(vXors, 4*i), i );
130 Vec_BitWriteEntry( vIsCarryRoot, CarryRoot, 1 );
134 Vec_IntClear( vXorSet );
135 Vec_IntClear( vCarryRootSet );
142 if ( k == Vec_IntSize(vCarryRootSet) )
144 Vec_IntSort( vCarryRootSet, 0 );
145 vLevel = Vec_WecPushLevel( vCarryRootSets );
146 Vec_IntAppend( vLevel, vXorSet );
147 vLevel = Vec_WecPushLevel( vCarryRootSets );
148 Vec_IntAppend( vLevel, vCarryRootSet );
149 vLevel = Vec_WecPushLevel( vCarryRootSets );
150 vLevel = Vec_WecPushLevel( vCarryRootSets );
151 vLevel = Vec_WecPushLevel( vCarryRootSets );
155 assert( Vec_BitEntry(vIsCarryRoot, CarryRoot) );
156 Vec_BitWriteEntry( vIsCarryRoot, CarryRoot, 0 );
159 Vec_IntFree( vCarryRootSet );
160 Vec_IntFree( vXorSet );
161 Vec_IntFree( vXorMap );
165 if ( !Vec_BitEntry(vIsCarryRoot, CarryRoot) )
169 vLevel = Vec_WecPushLevel( vCarryRootSets );
170 vLevel = Vec_WecPushLevel( vCarryRootSets );
171 Vec_IntFill( vLevel, 1, CarryRoot );
172 vLevel = Vec_WecPushLevel( vCarryRootSets );
173 vLevel = Vec_WecPushLevel( vCarryRootSets );
174 vLevel = Vec_WecPushLevel( vCarryRootSets );
176 Vec_BitFree( vIsCarryRoot );
177 return vCarryRootSets;
187 int i, k, iBox, iObj, Rank, RankMax = 0;
191 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+0), 1 );
192 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+1), 1 );
193 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+2), 1 );
194 Vec_BitWriteEntry( vBoxOuts, Vec_IntEntry(vAdds, 6*iBox+3), 1 );
195 Vec_BitWriteEntry( vBoxOuts, Vec_IntEntry(vAdds, 6*iBox+4), 1 );
200 for ( k = 0; k < 3; k++ )
201 if ( !Vec_BitEntry(vBoxOuts, Vec_IntEntry(vAdds, 6*iBox+k)) )
202 Vec_IntPushTwo( vResIns, Vec_IntEntry(vAdds, 6*iBox+k), Vec_IntEntry(vBoxRanks, iBox) );
203 for ( k = 3; k < 5; k++ )
204 if ( Vec_IntEntry(vAdds, 6*iBox+k) && !Vec_BitEntry(vBoxIns, Vec_IntEntry(vAdds, 6*iBox+k)) )
205 Vec_IntPushTwo( vResOuts, Vec_IntEntry(vAdds, 6*iBox+k), Vec_IntEntry(vBoxRanks, iBox)-(
int)(k==4) );
210 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+0), 0 );
211 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+1), 0 );
212 Vec_BitWriteEntry( vBoxIns, Vec_IntEntry(vAdds, 6*iBox+2), 0 );
213 Vec_BitWriteEntry( vBoxOuts, Vec_IntEntry(vAdds, 6*iBox+3), 0 );
214 Vec_BitWriteEntry( vBoxOuts, Vec_IntEntry(vAdds, 6*iBox+4), 0 );
218 RankMax = Abc_MaxInt( RankMax, Rank );
220 RankMax = Abc_MaxInt( RankMax, Rank );
222 Vec_IntWriteEntry( vResIns, k+1, 1 + RankMax - Rank );
224 Vec_IntWriteEntry( vResOuts, k+1, 1 + RankMax - Rank );
226 qsort( Vec_IntArray(vResIns), (
size_t)(Vec_IntSize(vResIns)/2), 8, (
int (*)(
const void *,
const void *))
Acec_ManCompareTwo );
227 qsort( Vec_IntArray(vResOuts), (
size_t)(Vec_IntSize(vResOuts)/2), 8, (
int (*)(
const void *,
const void *))
Acec_ManCompareTwo );
231 int iBox = Vec_IntEntry( vCarryMap, Carry );
236 if ( Vec_IntEntry(vAdds, 6*iBox+2) )
238 Vec_IntPush( vBoxes, iBox );
239 Vec_IntWriteEntry( vBoxRanks, iBox, iRank );
247 Vec_Int_t * vBoxRanks = Vec_IntStart( Vec_IntSize(vAdds)/6 );
248 Vec_Bit_t * vBoxIns = Vec_BitStart( Gia_ManObjNum(
p) );
249 Vec_Bit_t * vBoxOuts = Vec_BitStart( Gia_ManObjNum(
p) );
int i, k, Root;
250 Vec_IntFree( vCarryRoots );
251 Vec_IntFree( vXorRoots );
253 assert( Vec_WecSize(vBoxSets) % 5 == 0 );
254 for ( i = 0; 5*i < Vec_WecSize(vBoxSets); i++ )
256 Vec_Int_t * vRoots = Vec_WecEntry( vBoxSets, 5*i+1 );
257 Vec_Int_t * vBoxes = Vec_WecEntry( vBoxSets, 5*i+2 );
258 Vec_Int_t * vIns = Vec_WecEntry( vBoxSets, 5*i+3 );
259 Vec_Int_t * vOuts = Vec_WecEntry( vBoxSets, 5*i+4 );
264 Vec_IntFree( vBoxRanks );
265 Vec_BitFree( vBoxIns );
266 Vec_BitFree( vBoxOuts );
267 Vec_IntFree( vCarryMap );
279 int k, iObj, Count, Rank, RankMax = 0;
280 Vec_Int_t * vCounts = Vec_IntStart( 100 );
283 Vec_IntFillExtra( vCounts, Rank+1, 0 );
284 Vec_IntAddToEntry( vCounts, Rank, 1 );
285 RankMax = Abc_MaxInt( RankMax, Rank );
288 printf(
"%2d=%2d ", Rank, Count );
290 Vec_IntFree( vCounts );
311 printf(
"Detected %d full-adders and %d half-adders. Found %d XOR-cuts. ",
Ree_ManCountFadds(vAdds), Vec_IntSize(vAdds)/6-
Ree_ManCountFadds(vAdds), Vec_IntSize(vXors)/4 );
312 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
316 printf(
"Detected %d adder-tree%s. ", Vec_WecSize(vBoxes)/5, Vec_WecSize(vBoxes)/5 > 1 ?
"s":
"" );
317 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
320 for ( i = 0; 5*i < Vec_WecSize(vBoxes); i++ )
322 printf(
"Tree %3d : ", i );
323 printf(
"Xor = %4d ", Vec_IntSize(Vec_WecEntry(vBoxes,5*i+0)) );
324 printf(
"Root = %4d ", Vec_IntSize(Vec_WecEntry(vBoxes,5*i+1)) );
326 printf(
"Adder = %4d ", Vec_IntSize(Vec_WecEntry(vBoxes,5*i+2)) );
327 printf(
"In = %4d ", Vec_IntSize(Vec_WecEntry(vBoxes,5*i+3))/2 );
328 printf(
"Out = %4d ", Vec_IntSize(Vec_WecEntry(vBoxes,5*i+4))/2 );
336 Vec_IntFree( vXors );
337 Vec_IntFree( vAdds );
338 Vec_WecFree( vBoxes );
365 int i, k, iTop, fVerbose = 0;
366 Vec_Int_t * vTops = Vec_IntAlloc( 1000 );
369 for ( i = 0; 6*i < Vec_IntSize(vAdds); i++ )
370 if ( !Vec_BitEntry(vMarks, Vec_IntEntry(vAdds, 6*i+3)) &&
371 !Vec_BitEntry(vMarks, Vec_IntEntry(vAdds, 6*i+4)) )
372 Vec_IntPush( vTops, i );
377 printf(
"%4d : ", iTop );
378 for ( k = 0; k < 3; k++ )
379 printf(
"%4d ", Vec_IntEntry(vAdds, 6*iTop+k) );
381 for ( k = 3; k < 5; k++ )
382 printf(
"%4d ", Vec_IntEntry(vAdds, 6*iTop+k) );
386 Vec_BitFree( vMarks );
void Acec_ManCollectInsOuts(Gia_Man_t *p, Vec_Int_t *vAdds, Vec_Int_t *vBoxes, Vec_Int_t *vBoxRanks, Vec_Bit_t *vBoxIns, Vec_Bit_t *vBoxOuts, Vec_Int_t *vResIns, Vec_Int_t *vResOuts)