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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
|
/**CFile****************************************************************
FileName [rsbDec6.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Truth-table-based resubstitution.]
Synopsis [Implementation of the algorithm.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rsbDec6.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rsbInt.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline unsigned Rsb_DecTry0( word c )
{
return (unsigned)(c != 0);
}
static inline unsigned Rsb_DecTry1( word c, word f1 )
{
return (Rsb_DecTry0(c&f1) << 1) | Rsb_DecTry0(c&~f1);
}
static inline unsigned Rsb_DecTry2( word c, word f1, word f2 )
{
return (Rsb_DecTry1(c&f2, f1) << 2) | Rsb_DecTry1(c&~f2, f1);
}
static inline unsigned Rsb_DecTry3( word c, word f1, word f2, word f3 )
{
return (Rsb_DecTry2(c&f3, f1, f2) << 4) | Rsb_DecTry2(c&~f3, f1, f2);
}
static inline unsigned Rsb_DecTry4( word c, word f1, word f2, word f3, word f4 )
{
return (Rsb_DecTry3(c&f4, f1, f2, f3) << 8) | Rsb_DecTry3(c&~f4, f1, f2, f3);
}
static inline unsigned Rsb_DecTry5( word c, word f1, word f2, word f3, word f4, word f5 )
{
return (Rsb_DecTry4(c&f5, f1, f2, f3, f4) << 16) | Rsb_DecTry4(c&~f5, f1, f2, f3, f4);
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Rsb_DecTryCex( word * g, int iCexA, int iCexB )
{
return Abc_TtGetBit(g, iCexA) == Abc_TtGetBit(g, iCexB);
}
static inline void Rsb_DecVerifyCex( word * f, word ** g, int nGs, int iCexA, int iCexB )
{
int i;
// f distinquished it
if ( Rsb_DecTryCex( f, iCexA, iCexB ) )
printf( "Verification of CEX has failed: f(A) == f(B)!!!\n" );
// g do not distinguish it
for ( i = 0; i < nGs; i++ )
if ( !Rsb_DecTryCex( g[i], iCexA, iCexB ) )
printf( "Verification of CEX has failed: g[%d](A) != g[%d](B)!!!\n", i, i );
}
static inline void Rsb_DecRecordCex( word ** g, int nGs, int iCexA, int iCexB, word * pCexes, int nCexes )
{
int i;
assert( nCexes < 64 );
for ( i = 0; i < nGs; i++ )
if ( Rsb_DecTryCex(g[i], iCexA, iCexB) )
Abc_TtSetBit( pCexes + i, nCexes );
}
/**Function*************************************************************
Synopsis [Checks decomposability of f with divisors g.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline word Rsb_DecCofactor( word ** g, int nGs, int w, int iMint )
{
int i;
word Cof = ~(word)0;
for ( i = 0; i < nGs; i++ )
Cof &= ((iMint >> i) & 1) ? g[i][w] : ~g[i][w];
return Cof;
}
unsigned Rsb_DecCheck( int nVars, word * f, word ** g, int nGs, unsigned * pPat, int * pCexA, int * pCexB )
{
word CofA, CofB;
int nWords = Abc_TtWordNum( nVars );
int w, k, iMint, iShift = ( 1 << nGs );
unsigned uMask = (~(unsigned)0) >> (32-iShift);
unsigned uTotal = 0;
assert( nGs > 0 && nGs < 5 );
for ( w = 0; w < nWords; w++ )
{
// generate decomposition pattern
if ( nGs == 1 )
pPat[w] = Rsb_DecTry2( ~(word)0, g[0][w], f[w] );
else if ( nGs == 2 )
pPat[w] = Rsb_DecTry3( ~(word)0, g[0][w], g[1][w], f[w] );
else if ( nGs == 3 )
pPat[w] = Rsb_DecTry4( ~(word)0, g[0][w], g[1][w], g[2][w], f[w] );
else if ( nGs == 4 )
pPat[w] = Rsb_DecTry5( ~(word)0, g[0][w], g[1][w], g[2][w], g[3][w], f[w] );
// check if it is consistent
iMint = Abc_Tt6FirstBit( (pPat[w] >> iShift) & pPat[w] & uMask );
if ( iMint >= 0 )
{ // generate a cex
CofA = Rsb_DecCofactor( g, nGs, w, iMint );
assert( (~f[w] & CofA) && (f[w] & CofA) );
*pCexA = w * 64 + Abc_Tt6FirstBit( ~f[w] & CofA );
*pCexB = w * 64 + Abc_Tt6FirstBit( f[w] & CofA );
return 0;
}
uTotal |= pPat[w];
if ( w == 0 )
continue;
// check if it is consistent with other patterns seen so far
iMint = Abc_Tt6FirstBit( (uTotal >> iShift) & uTotal & uMask );
if ( iMint == -1 )
continue;
// find an overlap and generate a cex
for ( k = 0; k < w; k++ )
{
iMint = Abc_Tt6FirstBit( ((pPat[k] | pPat[w]) >> iShift) & (pPat[k] | pPat[w]) & uMask );
if ( iMint == -1 )
continue;
CofA = Rsb_DecCofactor( g, nGs, k, iMint );
CofB = Rsb_DecCofactor( g, nGs, w, iMint );
if ( (~f[k] & CofA) && (f[w] & CofB) )
{
*pCexA = k * 64 + Abc_Tt6FirstBit( ~f[k] & CofA );
*pCexB = w * 64 + Abc_Tt6FirstBit( f[w] & CofB );
}
else
{
assert( (f[k] & CofA) && (~f[w] & CofB) );
*pCexA = k * 64 + Abc_Tt6FirstBit( f[k] & CofA );
*pCexB = w * 64 + Abc_Tt6FirstBit( ~f[w] & CofB );
}
return 0;
}
}
return uTotal;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rsb_DecPrintTable( word * pCexes, int nGs, int nGsAll, Vec_Int_t * vTries )
{
int pCands[16], nCands;
int i, c, Cand, iStart = 0;
if ( Vec_IntSize(vTries) == 0 )
return;
// printf( "\n" );
for ( i = 0; i < 4; i++ )
printf( " " );
printf( " " );
for ( i = 0; i < nGs; i++ )
printf( "%d", (i % 100) / 10 );
printf( "|" );
for ( ; i < nGsAll; i++ )
printf( "%d", (i % 100) / 10 );
printf( "\n" );
for ( i = 0; i < 4; i++ )
printf( " " );
printf( " " );
for ( i = 0; i < nGs; i++ )
printf( "%d", i % 10 );
printf( "|" );
for ( ; i < nGsAll; i++ )
printf( "%d", i % 10 );
printf( "\n" );
printf( "\n" );
for ( c = 0; iStart < Vec_IntSize(vTries); c++ )
{
// collect candidates
for ( i = 0; i < 4; i++ )
pCands[i] = -1;
nCands = 0;
Vec_IntForEachEntryStart( vTries, Cand, i, iStart )
if ( Cand == -1 )
{
iStart = i + 1;
break;
}
else
pCands[nCands++] = Cand;
assert( nCands <= 4 );
// print them
for ( i = 0; i < 4; i++ )
if ( pCands[i] >= 0 )
printf( "%4d", pCands[i] );
else
printf( " " );
// print the bit-string
printf( " " );
for ( i = 0; i < nGs; i++ )
printf( "%c", Abc_TtGetBit( pCexes + i, c ) ? '.' : '+' );
printf( "|" );
for ( ; i < nGsAll; i++ )
printf( "%c", Abc_TtGetBit( pCexes + i, c ) ? '.' : '+' );
printf( " %3d\n", c );
}
printf( "\n" );
// write the number of ones
for ( i = 0; i < 4; i++ )
printf( " " );
printf( " " );
for ( i = 0; i < nGs; i++ )
printf( "%d", Abc_TtCountOnes(pCexes[i]) / 10 );
printf( "|" );
for ( ; i < nGsAll; i++ )
printf( "%d", Abc_TtCountOnes(pCexes[i]) / 10 );
printf( "\n" );
for ( i = 0; i < 4; i++ )
printf( " " );
printf( " " );
for ( i = 0; i < nGs; i++ )
printf( "%d", Abc_TtCountOnes(pCexes[i]) % 10 );
printf( "|" );
for ( ; i < nGsAll; i++ )
printf( "%d", Abc_TtCountOnes(pCexes[i]) % 10 );
printf( "\n" );
printf( "\n" );
}
/**Function*************************************************************
Synopsis [Init ]
Description [Returns the numbers of the decomposition functions and
the truth table of a function up to 4 variables.]
SideEffects []
SeeAlso []
***********************************************************************/
int Rsb_DecInitCexes( int nVars, word * f, word ** g, int nGs, int nGsAll, word * pCexes, Vec_Int_t * vTries )
{
int nWords = Abc_TtWordNum( nVars );
int ValueB = Abc_TtGetBit( f, 0 );
int ValueE = Abc_TtGetBit( f, 64*nWords-1 );
int iCexT0, iCexT1, iCexF0, iCexF1;
iCexT0 = ValueB ? 0 : Abc_TtFindFirstBit( f, nVars );
iCexT1 = ValueE ? 64*nWords-1 : Abc_TtFindLastBit( f, nVars );
iCexF0 = !ValueB ? 0 : Abc_TtFindFirstZero( f, nVars );
iCexF1 = !ValueE ? 64*nWords-1 : Abc_TtFindLastZero( f, nVars );
assert( !Rsb_DecTryCex( f, iCexT0, iCexF0 ) );
assert( !Rsb_DecTryCex( f, iCexT0, iCexF1 ) );
assert( !Rsb_DecTryCex( f, iCexT1, iCexF0 ) );
assert( !Rsb_DecTryCex( f, iCexT1, iCexF1 ) );
Rsb_DecRecordCex( g, nGsAll, iCexT0, iCexF0, pCexes, 0 );
Rsb_DecRecordCex( g, nGsAll, iCexT0, iCexF1, pCexes, 1 );
Rsb_DecRecordCex( g, nGsAll, iCexT1, iCexF0, pCexes, 2 );
Rsb_DecRecordCex( g, nGsAll, iCexT1, iCexF1, pCexes, 3 );
if ( vTries )
{
Vec_IntPush( vTries, -1 );
Vec_IntPush( vTries, -1 );
Vec_IntPush( vTries, -1 );
Vec_IntPush( vTries, -1 );
}
return 4;
}
/**Function*************************************************************
Synopsis [Finds a setset of gs to decompose f.]
Description [Returns the numbers of the decomposition functions and
the truth table of a function up to 4 variables.]
SideEffects []
SeeAlso []
***********************************************************************/
unsigned Rsb_DecPerformInt( Rsb_Man_t * p, int nVars, word * f, word ** g, int nGs, int nGsAll, int fFindAll )
{
word * pCexes = Vec_WrdArray(p->vCexes);
unsigned * pPat = (unsigned *)Vec_IntArray(p->vDecPats);
/*
The following filtering hueristic can be used:
after the first round (if there is more than 5 cexes,
remove all the divisors, except fanins of the node
This should lead to a speadup without sacrifying quality.
Another idea is to precompute several counter-examples
like the first and last 0 and 1 mints of the function
which yields 4 cexes.
*/
word * pDivs[16];
unsigned uTruth = 0;
int i, k, j, n, iCexA, iCexB, nCexes = 0;
memset( pCexes, 0, sizeof(word) * nGsAll );
Vec_IntClear( p->vTries );
// populate the counter-examples with the three most obvious
// nCexes = Rsb_DecInitCexes( nVars, f, g, nGs, nGsAll, pCexes, vTries );
// start by checking each function
p->vFanins->nSize = 1;
for ( i = 0; i < nGs; i++ )
{
if ( pCexes[i] )
continue;
pDivs[0] = g[i]; p->vFanins->pArray[0] = i;
uTruth = Rsb_DecCheck( nVars, f, pDivs, Vec_IntSize(p->vFanins), pPat, &iCexA, &iCexB );
if ( uTruth )
{
if ( fFindAll )
{
uTruth = (unsigned)Abc_Tt6Stretch( (word)uTruth, 1 );
Kit_DsdPrintFromTruth( &uTruth, 1 ); printf( " " );
Vec_IntPrint(p->vFanins);
continue;
}
else
return uTruth;
}
if ( nCexes == 64 )
return 0;
Rsb_DecVerifyCex( f, pDivs, Vec_IntSize(p->vFanins), iCexA, iCexB );
Rsb_DecRecordCex( g, nGsAll, iCexA, iCexB, pCexes, nCexes++ );
if ( !p->fVerbose )
continue;
Vec_IntPush( p->vTries, i );
Vec_IntPush( p->vTries, -1 );
}
if ( p->nDecMax == 1 )
return 0;
// continue by checking pairs
p->vFanins->nSize = 2;
for ( i = 1; i < nGs; i++ )
for ( k = 0; k < i; k++ )
{
if ( pCexes[i] & pCexes[k] )
continue;
pDivs[0] = g[i]; p->vFanins->pArray[0] = i;
pDivs[1] = g[k]; p->vFanins->pArray[1] = k;
uTruth = Rsb_DecCheck( nVars, f, pDivs, Vec_IntSize(p->vFanins), pPat, &iCexA, &iCexB );
if ( uTruth )
{
if ( fFindAll )
{
uTruth = (unsigned)Abc_Tt6Stretch( (word)uTruth, 2 );
Kit_DsdPrintFromTruth( &uTruth, 2 ); printf( " " );
Vec_IntPrint(p->vFanins);
continue;
}
else
return uTruth;
}
if ( nCexes == 64 )
return 0;
Rsb_DecVerifyCex( f, pDivs, Vec_IntSize(p->vFanins), iCexA, iCexB );
Rsb_DecRecordCex( g, nGsAll, iCexA, iCexB, pCexes, nCexes++ );
if ( !p->fVerbose )
continue;
Vec_IntPush( p->vTries, i );
Vec_IntPush( p->vTries, k );
Vec_IntPush( p->vTries, -1 );
}
if ( p->nDecMax == 2 )
return 0;
// continue by checking triples
p->vFanins->nSize = 3;
for ( i = 2; i < nGs; i++ )
for ( k = 1; k < i; k++ )
for ( j = 0; j < k; j++ )
{
if ( pCexes[i] & pCexes[k] & pCexes[j] )
continue;
pDivs[0] = g[i]; p->vFanins->pArray[0] = i;
pDivs[1] = g[k]; p->vFanins->pArray[1] = k;
pDivs[2] = g[j]; p->vFanins->pArray[2] = j;
uTruth = Rsb_DecCheck( nVars, f, pDivs, Vec_IntSize(p->vFanins), pPat, &iCexA, &iCexB );
if ( uTruth )
{
if ( fFindAll )
{
uTruth = (unsigned)Abc_Tt6Stretch( (word)uTruth, 3 );
Kit_DsdPrintFromTruth( &uTruth, 3 ); printf( " " );
Vec_IntPrint(p->vFanins);
continue;
}
else
return uTruth;
}
if ( nCexes == 64 )
return 0;
Rsb_DecVerifyCex( f, pDivs, Vec_IntSize(p->vFanins), iCexA, iCexB );
Rsb_DecRecordCex( g, nGsAll, iCexA, iCexB, pCexes, nCexes++ );
if ( !p->fVerbose )
continue;
Vec_IntPush( p->vTries, i );
Vec_IntPush( p->vTries, k );
Vec_IntPush( p->vTries, j );
Vec_IntPush( p->vTries, -1 );
}
if ( p->nDecMax == 3 )
return 0;
// continue by checking quadras
p->vFanins->nSize = 4;
for ( i = 3; i < nGs; i++ )
for ( k = 2; k < i; k++ )
for ( j = 1; j < k; j++ )
for ( n = 0; n < j; n++ )
{
if ( pCexes[i] & pCexes[k] & pCexes[j] & pCexes[n] )
continue;
pDivs[0] = g[i]; p->vFanins->pArray[0] = i;
pDivs[1] = g[k]; p->vFanins->pArray[1] = k;
pDivs[2] = g[j]; p->vFanins->pArray[2] = j;
pDivs[3] = g[n]; p->vFanins->pArray[3] = n;
uTruth = Rsb_DecCheck( nVars, f, pDivs, Vec_IntSize(p->vFanins), pPat, &iCexA, &iCexB );
if ( uTruth )
{
if ( fFindAll )
{
uTruth = (unsigned)Abc_Tt6Stretch( (word)uTruth, 4 );
Kit_DsdPrintFromTruth( &uTruth, 4 ); printf( " " );
Vec_IntPrint(p->vFanins);
continue;
}
else
return uTruth;
}
if ( nCexes == 64 )
return 0;
Rsb_DecVerifyCex( f, pDivs, Vec_IntSize(p->vFanins), iCexA, iCexB );
Rsb_DecRecordCex( g, nGsAll, iCexA, iCexB, pCexes, nCexes++ );
if ( !p->fVerbose )
continue;
Vec_IntPush( p->vTries, i );
Vec_IntPush( p->vTries, k );
Vec_IntPush( p->vTries, j );
Vec_IntPush( p->vTries, n );
Vec_IntPush( p->vTries, -1 );
}
// printf( "%d ", nCexes );
if ( p->nDecMax == 4 )
return 0;
return 0;
}
/**Function*************************************************************
Synopsis [Verifies 4-input decomposition.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rsb_DecPrintFunc( Rsb_Man_t * p, unsigned Truth4, word * f, word ** ppGs, int nGs, int nVarsAll )
{
int nVars = Vec_IntSize(p->vFanins);
word Copy = Truth4;
word wOn = Abc_Tt6Stretch( Copy >> (1 << nVars), nVars );
word wOnDc = ~Abc_Tt6Stretch( Copy, nVars );
word wIsop = Abc_Tt6Isop( wOn, wOnDc, nVars );
int i;
printf( "Offset : " );
Abc_TtPrintBinary( &Copy, nVars ); //printf( "\n" );
Copy >>= ((word)1 << nVars);
printf( "Onset : " );
Abc_TtPrintBinary( &Copy, nVars ); //printf( "\n" );
printf( "Result : " );
Abc_TtPrintBinary( &wIsop, nVars ); //printf( "\n" );
Kit_DsdPrintFromTruth( (unsigned *)&wIsop, nVars ); printf( "\n" );
// print functions
printf( "Func : " );
Abc_TtPrintBinary( f, nVarsAll ); //printf( "\n" );
Kit_DsdPrintFromTruth( (unsigned *)f, nVarsAll ); printf( "\n" );
for ( i = 0; i < nGs; i++ )
{
printf( "Div%3d : ", i );
Kit_DsdPrintFromTruth( (unsigned *)ppGs[i], nVarsAll ); printf( "\n" );
}
printf( "Solution : " );
for ( i = 0; i < Vec_IntSize(p->vFanins); i++ )
printf( "%d ", Vec_IntEntry(p->vFanins, i) );
printf( "\n" );
}
/**Function*************************************************************
Synopsis [Verifies 4-input decomposition.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Rsb_DecVerify( Rsb_Man_t * p, int nVars, word * f, word ** g, int nGs, unsigned Truth4, word * pTemp1, word * pTemp2 )
{
word * pFanins[16];
int b, m, Num, nSuppSize;
int nWords = Abc_TtWordNum(nVars);
Truth4 >>= (1 << Vec_IntSize(p->vFanins));
Truth4 = (unsigned)Abc_Tt6Stretch( (word)Truth4, Vec_IntSize(p->vFanins) );
//Kit_DsdPrintFromTruth( (unsigned *)&Truth4, Vec_IntSize(p->vFanins) );
//printf( "\n" );
// nSuppSize = Rsb_Word6SupportSize( Truth4 );
// assert( nSuppSize == Vec_IntSize(p->vFanins) );
nSuppSize = Vec_IntSize(p->vFanins);
// collect the fanins
Vec_IntForEachEntry( p->vFanins, Num, b )
{
assert( Num < nGs );
pFanins[b] = g[Num];
}
// create the or of ands
Abc_TtClear( pTemp1, nWords );
for ( m = 0; m < (1<<nSuppSize); m++ )
{
if ( ((Truth4 >> m) & 1) == 0 )
continue;
Abc_TtFill( pTemp2, nWords );
for ( b = 0; b < nSuppSize; b++ )
if ( (m >> b) & 1 )
Abc_TtAnd( pTemp2, pTemp2, pFanins[b], nWords, 0 );
else
Abc_TtSharp( pTemp2, pTemp2, pFanins[b], nWords );
Abc_TtOr( pTemp1, pTemp1, pTemp2, nWords );
}
// check the function
if ( !Abc_TtEqual( pTemp1, f, nWords ) )
printf( "Verification failed.\n" );
// else
// printf( "Verification passed.\n" );
return 1;
}
/**Function*************************************************************
Synopsis [Finds a setset of gs to decompose f.]
Description [Returns the numbers of the decomposition functions and
the truth table of a function up to 4 variables.]
SideEffects []
SeeAlso []
***********************************************************************/
unsigned Rsb_ManPerform( Rsb_Man_t * p, int nVars, word * f, word ** g, int nGs, int nGsAll, int fVerbose0 )
{
word * pCexes = Vec_WrdArray(p->vCexes);
unsigned * pPat = (unsigned *)Vec_IntArray(p->vDecPats);
int fVerbose = 0;//(nGs > 40);
Vec_Int_t * vTries = NULL;
unsigned uTruth;
// verify original decomposition
if ( Vec_IntSize(p->vFaninsOld) && Vec_IntSize(p->vFaninsOld) <= 4 )
{
word * pDivs[8];
int i, Entry, iCexA, iCexB;
Vec_IntForEachEntry( p->vFaninsOld, Entry, i )
pDivs[i] = g[Entry];
uTruth = Rsb_DecCheck( nVars, f, pDivs, Vec_IntSize(p->vFaninsOld), pPat, &iCexA, &iCexB );
// assert( uTruth != 0 );
if ( fVerbose )
{
printf( "Verified orig decomp with %d vars {", Vec_IntSize(p->vFaninsOld) );
Vec_IntForEachEntry( p->vFaninsOld, Entry, i )
printf( " %d", Entry );
printf( " }\n" );
}
if ( uTruth )
{
// if ( fVerbose )
// Rsb_DecPrintFunc( p, uTruth );
}
else
{
printf( "Verified orig decomp with %d vars {", Vec_IntSize(p->vFaninsOld) );
Vec_IntForEachEntry( p->vFaninsOld, Entry, i )
printf( " %d", Entry );
printf( " }\n" );
printf( "Verification FAILED.\n" );
}
}
// start tries
if ( fVerbose )
vTries = Vec_IntAlloc( 100 );
assert( nGs < nGsAll );
uTruth = Rsb_DecPerformInt( p, nVars, f, g, nGs, nGsAll, 0 );
if ( uTruth )
{
if ( fVerbose )
{
int i, Entry;
printf( "Found decomp with %d vars {", Vec_IntSize(p->vFanins) );
Vec_IntForEachEntry( p->vFanins, Entry, i )
printf( " %d", Entry );
printf( " }\n" );
// Rsb_DecPrintFunc( p, uTruth );
// Rsb_DecVerify( nVars, f, g, nGs, p->vFanins, uTruth, g[nGsAll], g[nGsAll+1] );
}
}
else
{
Vec_IntShrink( p->vFanins, 0 );
if ( fVerbose )
printf( "Did not find decomposition with 4 variables.\n" );
}
if ( fVerbose )
Rsb_DecPrintTable( pCexes, nGs, nGsAll, vTries );
if ( fVerbose )
Vec_IntFree( vTries );
return uTruth;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Rsb_ManPerformResub6( Rsb_Man_t * p, int nVarsAll, word uTruth, Vec_Wrd_t * vDivTruths, word * puTruth0, word * puTruth1, int fVerbose )
{
word * pGs[200];
unsigned uTruthRes;
int i, nVars, nGs = Vec_WrdSize(vDivTruths);
assert( nGs < 200 );
for ( i = 0; i < nGs; i++ )
pGs[i] = Vec_WrdEntryP(vDivTruths,i);
uTruthRes = Rsb_DecPerformInt( p, nVarsAll, &uTruth, pGs, nGs, nGs, 0 );
if ( uTruthRes == 0 )
return 0;
if ( fVerbose )
Rsb_DecPrintFunc( p, uTruthRes, &uTruth, pGs, nGs, nVarsAll );
if ( fVerbose )
Rsb_DecPrintTable( Vec_WrdArray(p->vCexes), nGs, nGs, p->vTries );
nVars = Vec_IntSize(p->vFanins);
*puTruth0 = Abc_Tt6Stretch( uTruthRes, nVars );
*puTruth1 = Abc_Tt6Stretch( uTruthRes >> (1 << nVars), nVars );
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rsb_ManPerformResub6Test()
{
Rsb_Man_t * p;
Vec_Wrd_t * vDivTruths;
int RetValue;
word a = s_Truths6[0];
word b = s_Truths6[1];
word c = s_Truths6[2];
word d = s_Truths6[3];
word e = s_Truths6[4];
word f = s_Truths6[5];
word ab = a & b;
word cd = c & d;
word ef = e & f;
word F = ab | cd | ef;
word uTruth0, uTruth1;
vDivTruths = Vec_WrdAlloc( 100 );
Vec_WrdPush( vDivTruths, a );
Vec_WrdPush( vDivTruths, b );
Vec_WrdPush( vDivTruths, c );
Vec_WrdPush( vDivTruths, d );
Vec_WrdPush( vDivTruths, e );
Vec_WrdPush( vDivTruths, f );
Vec_WrdPush( vDivTruths, ab );
Vec_WrdPush( vDivTruths, cd );
Vec_WrdPush( vDivTruths, ef );
p = Rsb_ManAlloc( 6, 64, 4, 1 );
RetValue = Rsb_ManPerformResub6( p, 6, F, vDivTruths, &uTruth0, &uTruth1, 1 );
Rsb_ManFree( p );
Vec_WrdFree( vDivTruths );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|