181 int nSizeLog = (1<<nVars) -2;
182 int nSizeW = 1 << nSizeLog;
187 int i, v, u, g, k, m, n, Res, Entry;
188 unsigned Inv = (unsigned)Abc_Tt6Mask(1 << (nVars-1));
189 sprintf( pFileName,
"tableW%d.data", nSizeLog );
192 pTable[0] |= (1 << 31);
193 pTable[Inv] |= (1 << 31);
194 Vec_IntPushTwo( Vec_WecEntry(vNpns, 0), 0, Inv );
195 Vec_IntPushTwo( Vec_WecEntry(vNpns_, 0), 0, Inv );
196 printf(
"Nodes = %2d. New = %6d. Total = %6d. New = %6d. Total = %6d. ",
197 0, Vec_IntSize(Vec_WecEntry(vNpns, 0)), Vec_WecSizeSize(vNpns),
198 Vec_IntSize(Vec_WecEntry(vNpns_, 0)), Vec_WecSizeSize(vNpns_) );
199 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
201 for ( n = 1; n < 32; n++ )
203 Vec_Int_t * vFuncsN2 = n > 1 ? Vec_WecEntry( vNpns, n-2 ) : NULL;
204 Vec_Int_t * vFuncsN1 = Vec_WecEntry( vNpns, n-1 );
205 Vec_Int_t * vFuncsN = Vec_WecEntry( vNpns, n );
206 Vec_Int_t * vFuncsN_ = Vec_WecEntry( vNpns_,n );
210 int nSupp = Abc_TtSupportSize( &uTruth, nVars );
211 assert( nSupp == 6 || !Abc_Tt6HasVar(uTruth, nVars-1-nSupp) );
215 for ( v = 0; v < nSupp; v++ )
218 word Cof0 = Abc_Tt6Cofactor0( uTruth, nVars-1-v );
219 word Cof1 = Abc_Tt6Cofactor1( uTruth, nVars-1-v );
220 for ( g = 0; g < Limit; g++ )
226 tGate = s_Truths6[nVars-1-v] & s_Truths6[nVars-1-nSupp];
227 tCur = (tGate & Cof1) | (~tGate & Cof0);
230 tCur = (tGate & Cof0) | (~tGate & Cof1);
235 tGate = s_Truths6[nVars-1-v] ^ s_Truths6[nVars-1-nSupp];
236 tCur = (tGate & Cof1) | (~tGate & Cof0);
241 for ( g = 0; g < Limit; g++ )
244 for ( k = 0; k < nSupp; k++ )
if ( k != v )
248 tGate = s_Truths6[nVars-1-v] & s_Truths6[nVars-1-k];
249 tCur = (tGate & Cof1) | (~tGate & Cof0);
252 tCur = (tGate & Cof0) | (~tGate & Cof1);
255 tGate = s_Truths6[nVars-1-v] & ~s_Truths6[nVars-1-k];
256 tCur = (tGate & Cof1) | (~tGate & Cof0);
259 tCur = (tGate & Cof0) | (~tGate & Cof1);
264 tGate = s_Truths6[nVars-1-v] ^ s_Truths6[nVars-1-k];
265 tCur = (tGate & Cof1) | (~tGate & Cof0);
270 for ( g = 0; g < Limit; g++ )
273 for ( k = 0; k < nSupp; k++ )
if ( k != v )
274 for ( m = k+1; m < nSupp; m++ )
if ( m != v )
278 tGate = s_Truths6[nVars-1-m] & s_Truths6[nVars-1-k];
279 tCur = (tGate & Cof1) | (~tGate & Cof0);
282 tCur = (tGate & Cof0) | (~tGate & Cof1);
285 tGate = s_Truths6[nVars-1-m] & ~s_Truths6[nVars-1-k];
286 tCur = (tGate & Cof1) | (~tGate & Cof0);
289 tCur = (tGate & Cof0) | (~tGate & Cof1);
292 tGate = ~s_Truths6[nVars-1-m] & s_Truths6[nVars-1-k];
293 tCur = (tGate & Cof1) | (~tGate & Cof0);
296 tCur = (tGate & Cof0) | (~tGate & Cof1);
299 tGate = ~s_Truths6[nVars-1-m] & ~s_Truths6[nVars-1-k];
300 tCur = (tGate & Cof1) | (~tGate & Cof0);
303 tCur = (tGate & Cof0) | (~tGate & Cof1);
308 tGate = s_Truths6[nVars-1-m] ^ s_Truths6[nVars-1-k];
309 tCur = (tGate & Cof1) | (~tGate & Cof0);
316 if ( UseTwo && vFuncsN2 )
320 int nSupp = Abc_TtSupportSize( &uTruth, nVars );
321 assert( nSupp == 6 || !Abc_Tt6HasVar(uTruth, nVars-1-nSupp) );
325 for ( v = 0; v < nSupp; v++ )
327 for ( u = 0; u < nSupp; u++ )
if ( u != v )
329 word tGate1, tGate2, tCur;
330 word Cof0 = Abc_Tt6Cofactor0( uTruth, nVars-1-v );
331 word Cof1 = Abc_Tt6Cofactor1( uTruth, nVars-1-v );
333 word Cof00 = Abc_Tt6Cofactor0( Cof0, nVars-1-u );
334 word Cof01 = Abc_Tt6Cofactor1( Cof0, nVars-1-u );
335 word Cof10 = Abc_Tt6Cofactor0( Cof1, nVars-1-u );
336 word Cof11 = Abc_Tt6Cofactor1( Cof1, nVars-1-u );
338 tGate1 = s_Truths6[nVars-1-v] & s_Truths6[nVars-1-u];
339 tGate2 = s_Truths6[nVars-1-v] ^ s_Truths6[nVars-1-u];
341 Cof0 = (tGate2 & Cof00) | (~tGate2 & Cof01);
342 Cof1 = (tGate2 & Cof10) | (~tGate2 & Cof11);
344 tCur = (tGate1 & Cof1) | (~tGate1 & Cof0);
347 printf(
"Found function %d\n", Res );
349 tCur = (tGate1 & Cof0) | (~tGate1 & Cof1);
352 printf(
"Found function %d\n", Res );
355 printf(
"Nodes = %2d. New = %6d. Total = %6d. New = %6d. Total = %6d. ",
356 n, Vec_IntSize(vFuncsN), Vec_WecSizeSize(vNpns), Vec_IntSize(vFuncsN_), Vec_WecSizeSize(vNpns_) );
357 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
359 if ( Vec_IntSize(vFuncsN) == 0 )
367 Vec_WecFree( vNpns );
368 Vec_WecFree( vNpns_ );
370 Abc_PrintTime( 1,
"Total time", Abc_Clock() - clk );
622void Dau_FunctionEnum(
int nInputs,
int nVars,
int nNodeMax,
int fUseTwo,
int fReduce,
int fVerbose )
625 int nWords = Abc_TtWordNum(nInputs);
word nSteps = 0;
628 Vec_Int_t * vNodSup = Vec_IntAlloc( 1 << 16 );
629 int v, u, k, m, n, Entry, nNew, Limit[32] = {1, 2};
631 assert( nVars >= 3 && nVars <= nInputs && nInputs <= 6 );
632 Vec_MemHashAlloc( vTtMem, 1<<16 );
634 Vec_MemHashInsert( vTtMem, Truth );
635 Vec_IntPush( vNodSup, 0 );
637 Abc_TtIthVar( Truth, 0, nInputs );
638 Abc_TtNot( Truth,
nWords );
639 Vec_MemHashInsert( vTtMem, Truth );
640 Vec_IntPush( vNodSup, 1 );
641 Dau_PrintStats( 0, nInputs, nVars, vNodSup, 0, 2, nSteps, 0, clk );
643 for ( n = 1; n <= nNodeMax; n++ )
646 int fExpand = !(fReduce && n == nNodeMax);
647 for ( Entry = Limit[n-1]; Entry < Limit[n]; Entry++ )
649 word * pTruth = Vec_MemReadEntry( vTtMem, Entry );
650 int NodSup = Vec_IntEntry(vNodSup, Entry);
651 int nSupp = 0xF & NodSup;
653 assert( n-1 == (NodSup >> 16) );
654 assert( !Abc_Tt6HasVar(*pTruth, nSupp) );
658 for ( v = 0; v < nSupp; v++ )
if ( (SymVars & (1 << v)) == 0 )
661 word Cof0 = Abc_Tt6Cofactor0( *pTruth, v );
662 word Cof1 = Abc_Tt6Cofactor1( *pTruth, v );
664 if ( nSupp < nInputs && fExpand )
666 tGate = s_Truths6[v] & s_Truths6[nSupp];
667 tCur = (tGate & Cof1) | (~tGate & Cof0);
668 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp+1, vTtMem, vNodSup, Entry, clk );
670 tCur = (tGate & Cof0) | (~tGate & Cof1);
671 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp+1, vTtMem, vNodSup, Entry, clk );
674 tGate = s_Truths6[v] ^ s_Truths6[nSupp];
675 tCur = (tGate & Cof1) | (~tGate & Cof0);
676 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp+1, vTtMem, vNodSup, Entry, clk );
682 for ( k = 0; k < nSupp; k++ )
if ( k != v && ((SymVars & (1 << k)) == 0 || k == v+1) )
684 tGate = s_Truths6[v] & s_Truths6[k];
685 tCur = (tGate & Cof1) | (~tGate & Cof0);
686 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
688 tCur = (tGate & Cof0) | (~tGate & Cof1);
689 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
691 tGate = s_Truths6[v] & ~s_Truths6[k];
692 tCur = (tGate & Cof1) | (~tGate & Cof0);
693 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
695 tCur = (tGate & Cof0) | (~tGate & Cof1);
696 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
699 tGate = s_Truths6[v] ^ s_Truths6[k];
700 tCur = (tGate & Cof1) | (~tGate & Cof0);
701 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
706 for ( k = 0; k < nSupp; k++ )
if ( k != v )
707 for ( m = k+1; m < nSupp; m++ )
if ( m != v )
709 tGate = s_Truths6[m] & s_Truths6[k];
710 tCur = (tGate & Cof1) | (~tGate & Cof0);
711 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
713 tCur = (tGate & Cof0) | (~tGate & Cof1);
714 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
716 tGate = s_Truths6[m] & ~s_Truths6[k];
717 tCur = (tGate & Cof1) | (~tGate & Cof0);
718 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
720 tCur = (tGate & Cof0) | (~tGate & Cof1);
721 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
723 tGate = ~s_Truths6[m] & s_Truths6[k];
724 tCur = (tGate & Cof1) | (~tGate & Cof0);
725 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
727 tCur = (tGate & Cof0) | (~tGate & Cof1);
728 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
730 tGate = ~s_Truths6[m] & ~s_Truths6[k];
731 tCur = (tGate & Cof1) | (~tGate & Cof0);
732 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
734 tCur = (tGate & Cof0) | (~tGate & Cof1);
735 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
738 tGate = s_Truths6[m] ^ s_Truths6[k];
739 tCur = (tGate & Cof1) | (~tGate & Cof0);
740 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
742 tGate = s_Truths6[m] ^ s_Truths6[k];
743 tCur = (tGate & Cof0) | (~tGate & Cof1);
744 Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
750 if ( fUseTwo && n > 2 && fExpand )
751 for ( Entry = Limit[n-2]; Entry < Limit[n-1]; Entry++ )
753 word * pTruth = Vec_MemReadEntry( vTtMem, Entry );
754 int NodSup = Vec_IntEntry(vNodSup, Entry);
755 int nSupp = 0xF & NodSup;
int g1, g2;
756 assert( n-2 == (NodSup >> 16) );
757 assert( !Abc_Tt6HasVar(*pTruth, nSupp) );
758 for ( v = 0; v < nSupp; v++ )
759 for ( u = 0; u < nSupp; u++ )
if ( u != v )
761 word Cof0 = Abc_Tt6Cofactor0( *pTruth, v );
762 word Cof1 = Abc_Tt6Cofactor1( *pTruth, v );
764 word Cof00 = Abc_Tt6Cofactor0( Cof0, u );
765 word Cof01 = Abc_Tt6Cofactor1( Cof0, u );
766 word Cof10 = Abc_Tt6Cofactor0( Cof1, u );
767 word Cof11 = Abc_Tt6Cofactor1( Cof1, u );
769 word tGates[5], tCur;
770 tGates[0] = s_Truths6[v] & s_Truths6[u];
771 tGates[1] = s_Truths6[v] & ~s_Truths6[u];
772 tGates[2] = ~s_Truths6[v] & s_Truths6[u];
773 tGates[3] = s_Truths6[v] | s_Truths6[u];
774 tGates[4] = s_Truths6[v] ^ s_Truths6[u];
776 for ( g1 = 0; g1 < 5; g1++ )
777 for ( g2 = g1+1; g2 < 5; g2++ )
779 Cof0 = (tGates[g1] & Cof01) | (~tGates[g1] & Cof00);
780 Cof1 = (tGates[g1] & Cof11) | (~tGates[g1] & Cof10);
782 tCur = (tGates[g2] & Cof1) | (~tGates[g2] & Cof0);
783 Count2 +=
Dau_InsertFunction( pMan, &tCur, n, nInputs, nVars, nSupp, vTtMem, vNodSup, Entry, clk );
787 Limit[n+1] = Vec_IntSize(vNodSup);
788 nNew =
Dau_PrintStats( n, nInputs, nVars, vNodSup, Limit[n], Limit[n+1], nSteps, Count2, clk );
792 Dau_TablesSave( nInputs, nVars, vTtMem, vNodSup, Vec_IntSize(vNodSup), clk );
793 Abc_PrintTime( 1,
"Total time", Abc_Clock() - clk );
797 Vec_MemHashFree( vTtMem );
798 Vec_MemFreeP( &vTtMem );
799 Vec_IntFree( vNodSup );