ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcSop.c
Go to the documentation of this file.
1
20
21#include "abc.h"
22#include "bool/kit/kit.h"
23
24#ifdef _MSC_VER
25# include <intrin.h>
26# define __builtin_popcount __popcnt
27#endif
28
30
31
32/*
33 The SOPs in this package are represented using char * strings.
34 For example, the SOP of the node:
35
36 .names c d0 d1 MUX
37 01- 1
38 1-1 1
39
40 is the string: "01- 1\n1-1 1\n" where '\n' is a single char.
41*/
42
46
50
62char * Abc_SopRegister( Mem_Flex_t * pMan, const char * pName )
63{
64 char * pRegName;
65 if ( pName == NULL ) return NULL;
66 pRegName = Mem_FlexEntryFetch( pMan, strlen(pName) + 1 );
67 strcpy( pRegName, pName );
68 return pRegName;
69}
70
82char * Abc_SopStart( Mem_Flex_t * pMan, int nCubes, int nVars )
83{
84 char * pSopCover, * pCube;
85 int i, Length;
86
87 Length = nCubes * (nVars + 3);
88 pSopCover = Mem_FlexEntryFetch( pMan, Length + 1 );
89 memset( pSopCover, '-', (size_t)Length );
90 pSopCover[Length] = 0;
91
92 for ( i = 0; i < nCubes; i++ )
93 {
94 pCube = pSopCover + i * (nVars + 3);
95 pCube[nVars + 0] = ' ';
96 pCube[nVars + 1] = '1';
97 pCube[nVars + 2] = '\n';
98 }
99 return pSopCover;
100}
101
114{
115 return Abc_SopRegister( pMan, " 1\n" );
116}
117
130{
131 return Abc_SopRegister( pMan, " 0\n" );
132}
133
145char * Abc_SopCreateAnd2( Mem_Flex_t * pMan, int fCompl0, int fCompl1 )
146{
147 char Buffer[6];
148 Buffer[0] = '1' - fCompl0;
149 Buffer[1] = '1' - fCompl1;
150 Buffer[2] = ' ';
151 Buffer[3] = '1';
152 Buffer[4] = '\n';
153 Buffer[5] = 0;
154 return Abc_SopRegister( pMan, Buffer );
155}
156
168char * Abc_SopCreateAnd( Mem_Flex_t * pMan, int nVars, int * pfCompl )
169{
170 char * pSop;
171 int i;
172 pSop = Abc_SopStart( pMan, 1, nVars );
173 for ( i = 0; i < nVars; i++ )
174 pSop[i] = '1' - (pfCompl? pfCompl[i] : 0);
175 pSop[nVars + 1] = '1';
176 return pSop;
177}
178
190char * Abc_SopCreateNand( Mem_Flex_t * pMan, int nVars )
191{
192 char * pSop;
193 int i;
194 pSop = Abc_SopStart( pMan, 1, nVars );
195 for ( i = 0; i < nVars; i++ )
196 pSop[i] = '1';
197 pSop[nVars + 1] = '0';
198 return pSop;
199}
200
212char * Abc_SopCreateOr( Mem_Flex_t * pMan, int nVars, int * pfCompl )
213{
214 char * pSop;
215 int i;
216 pSop = Abc_SopStart( pMan, 1, nVars );
217 for ( i = 0; i < nVars; i++ )
218 pSop[i] = '0' + (pfCompl? pfCompl[i] : 0);
219 pSop[nVars + 1] = '0';
220 return pSop;
221}
222
234char * Abc_SopCreateOrMultiCube( Mem_Flex_t * pMan, int nVars, int * pfCompl )
235{
236 char * pSop, * pCube;
237 int i;
238 pSop = Abc_SopStart( pMan, nVars, nVars );
239 i = 0;
240 Abc_SopForEachCube( pSop, nVars, pCube )
241 {
242 pCube[i] = '1' - (pfCompl? pfCompl[i] : 0);
243 i++;
244 }
245 return pSop;
246}
247
259char * Abc_SopCreateNor( Mem_Flex_t * pMan, int nVars )
260{
261 char * pSop;
262 int i;
263 pSop = Abc_SopStart( pMan, 1, nVars );
264 for ( i = 0; i < nVars; i++ )
265 pSop[i] = '0';
266 return pSop;
267}
268
280char * Abc_SopCreateXor( Mem_Flex_t * pMan, int nVars )
281{
282 assert( nVars == 2 );
283 return Abc_SopRegister(pMan, "01 1\n10 1\n");
284}
285
297char * Abc_SopCreateXorSpecial( Mem_Flex_t * pMan, int nVars )
298{
299 char * pSop;
300 pSop = Abc_SopCreateAnd( pMan, nVars, NULL );
301 pSop[nVars+1] = 'x';
302 assert( pSop[nVars+2] == '\n' );
303 return pSop;
304}
305
317char * Abc_SopCreateNxor( Mem_Flex_t * pMan, int nVars )
318{
319 assert( nVars == 2 );
320 return Abc_SopRegister(pMan, "11 1\n00 1\n");
321}
322
336{
337 return Abc_SopRegister(pMan, "11- 1\n0-1 1\n");
338}
339
352{
353 return Abc_SopRegister(pMan, "0 1\n");
354}
355
368{
369 return Abc_SopRegister(pMan, "1 1\n");
370}
371
383char * Abc_SopCreateFromTruth( Mem_Flex_t * pMan, int nVars, unsigned * pTruth )
384{
385 char * pSop, * pCube;
386 int nMints, Counter, i, k;
387 if ( nVars == 0 )
388 return pTruth[0] ? Abc_SopCreateConst1(pMan) : Abc_SopCreateConst0(pMan);
389 // count the number of true minterms
390 Counter = 0;
391 nMints = (1 << nVars);
392 for ( i = 0; i < nMints; i++ )
393 Counter += ((pTruth[i>>5] & (1 << (i&31))) > 0);
394 // SOP is not well-defined if the truth table is constant 0
395 assert( Counter > 0 );
396 if ( Counter == 0 )
397 return NULL;
398 // start the cover
399 pSop = Abc_SopStart( pMan, Counter, nVars );
400 // create true minterms
401 Counter = 0;
402 for ( i = 0; i < nMints; i++ )
403 if ( (pTruth[i>>5] & (1 << (i&31))) > 0 )
404 {
405 pCube = pSop + Counter * (nVars + 3);
406 for ( k = 0; k < nVars; k++ )
407 pCube[k] = '0' + ((i & (1 << k)) > 0);
408 Counter++;
409 }
410 return pSop;
411}
412
424char * Abc_SopCreateFromIsop( Mem_Flex_t * pMan, int nVars, Vec_Int_t * vCover )
425{
426 char * pSop, * pCube;
427 int i, k, Entry, Literal;
428 assert( Vec_IntSize(vCover) > 0 );
429 if ( Vec_IntSize(vCover) == 0 )
430 return NULL;
431 // start the cover
432 pSop = Abc_SopStart( pMan, Vec_IntSize(vCover), nVars );
433 // create cubes
434 Vec_IntForEachEntry( vCover, Entry, i )
435 {
436 pCube = pSop + i * (nVars + 3);
437 for ( k = 0; k < nVars; k++ )
438 {
439 Literal = 3 & (Entry >> (k << 1));
440 if ( Literal == 1 )
441 pCube[k] = '0';
442 else if ( Literal == 2 )
443 pCube[k] = '1';
444 else if ( Literal != 0 )
445 assert( 0 );
446 }
447 }
448 return pSop;
449}
450
462char * Abc_SopCreateFromTruthIsop( Mem_Flex_t * pMan, int nVars, word * pTruth, Vec_Int_t * vCover )
463{
464 char * pSop = NULL;
465 int w, nWords = Abc_Truth6WordNum( nVars );
466 assert( nVars < 16 );
467
468 for ( w = 0; w < nWords; w++ )
469 if ( pTruth[w] )
470 break;
471 if ( w == nWords )
472 return Abc_SopRegister( pMan, " 0\n" );
473
474 for ( w = 0; w < nWords; w++ )
475 if ( ~pTruth[w] )
476 break;
477 if ( w == nWords )
478 return Abc_SopRegister( pMan, " 1\n" );
479
480 {
481 int RetValue = Kit_TruthIsop( (unsigned *)pTruth, nVars, vCover, 1 );
482 assert( nVars > 0 );
483 assert( RetValue == 0 || RetValue == 1 );
484 pSop = Abc_SopCreateFromIsop( pMan, nVars, vCover );
485 if ( RetValue )
486 Abc_SopComplement( pSop );
487 }
488 return pSop;
489}
490
502void Abc_SopToIsop( char * pSop, Vec_Int_t * vCover )
503{
504 char * pCube;
505 int k, nVars, Entry;
506 nVars = Abc_SopGetVarNum( pSop );
507 assert( nVars > 0 );
508 // create cubes
509 Vec_IntClear( vCover );
510 for ( pCube = pSop; *pCube; pCube += nVars + 3 )
511 {
512 Entry = 0;
513 for ( k = nVars - 1; k >= 0; k-- )
514 if ( pCube[k] == '0' )
515 Entry = (Entry << 2) | 1;
516 else if ( pCube[k] == '1' )
517 Entry = (Entry << 2) | 2;
518 else if ( pCube[k] == '-' )
519 Entry = (Entry << 2);
520 else
521 assert( 0 );
522 Vec_IntPush( vCover, Entry );
523 }
524}
525
537int Abc_SopGetCubeNum( char * pSop )
538{
539 char * pCur;
540 int nCubes = 0;
541 if ( pSop == NULL )
542 return 0;
543 for ( pCur = pSop; *pCur; pCur++ )
544 nCubes += (*pCur == '\n');
545 return nCubes;
546}
547
559int Abc_SopGetLitNum( char * pSop )
560{
561 char * pCur;
562 int nLits = 0;
563 if ( pSop == NULL )
564 return 0;
565 for ( pCur = pSop; *pCur; pCur++ )
566 {
567 nLits -= (*pCur == '\n');
568 nLits += (*pCur == '0' || *pCur == '1');
569 }
570 return nLits;
571}
572
584int Abc_SopGetVarNum( char * pSop )
585{
586 char * pCur;
587 for ( pCur = pSop; *pCur != '\n'; pCur++ )
588 if ( *pCur == 0 )
589 return -1;
590 return pCur - pSop - 2;
591}
592
604int Abc_SopGetPhase( char * pSop )
605{
606 int nVars = Abc_SopGetVarNum( pSop );
607 if ( pSop[nVars+1] == '0' || pSop[nVars+1] == 'n' )
608 return 0;
609 if ( pSop[nVars+1] == '1' || pSop[nVars+1] == 'x' )
610 return 1;
611 assert( 0 );
612 return -1;
613}
614
626int Abc_SopGetIthCareLit( char * pSop, int i )
627{
628 char * pCube;
629 int nVars;
630 nVars = Abc_SopGetVarNum( pSop );
631 Abc_SopForEachCube( pSop, nVars, pCube )
632 if ( pCube[i] != '-' )
633 return pCube[i] - '0';
634 return -1;
635}
636
648void Abc_SopComplement( char * pSop )
649{
650 char * pCur;
651 for ( pCur = pSop; *pCur; pCur++ )
652 if ( *pCur == '\n' )
653 {
654 if ( *(pCur - 1) == '0' )
655 *(pCur - 1) = '1';
656 else if ( *(pCur - 1) == '1' )
657 *(pCur - 1) = '0';
658 else if ( *(pCur - 1) == 'x' )
659 *(pCur - 1) = 'n';
660 else if ( *(pCur - 1) == 'n' )
661 *(pCur - 1) = 'x';
662 else
663 assert( 0 );
664 }
665}
666
678void Abc_SopComplementVar( char * pSop, int iVar )
679{
680 char * pCube;
681 int nVars = Abc_SopGetVarNum(pSop);
682 assert( iVar < nVars );
683 Abc_SopForEachCube( pSop, nVars, pCube )
684 {
685 if ( pCube[iVar] == '0' )
686 pCube[iVar] = '1';
687 else if ( pCube[iVar] == '1' )
688 pCube[iVar] = '0';
689 }
690}
691
703int Abc_SopIsComplement( char * pSop )
704{
705 char * pCur;
706 for ( pCur = pSop; *pCur; pCur++ )
707 if ( *pCur == '\n' )
708 return (int)(*(pCur - 1) == '0' || *(pCur - 1) == 'n');
709 assert( 0 );
710 return 0;
711}
712
724int Abc_SopIsConst0( char * pSop )
725{
726 return pSop[0] == ' ' && pSop[1] == '0';
727}
728
740int Abc_SopIsConst1( char * pSop )
741{
742 return pSop[0] == ' ' && pSop[1] == '1';
743}
744
756int Abc_SopIsBuf( char * pSop )
757{
758 if ( pSop[4] != 0 )
759 return 0;
760 if ( (pSop[0] == '1' && pSop[2] == '1') || (pSop[0] == '0' && pSop[2] == '0') )
761 return 1;
762 return 0;
763}
764
776int Abc_SopIsInv( char * pSop )
777{
778 if ( pSop[4] != 0 )
779 return 0;
780 if ( (pSop[0] == '0' && pSop[2] == '1') || (pSop[0] == '1' && pSop[2] == '0') )
781 return 1;
782 return 0;
783}
784
796int Abc_SopIsAndType( char * pSop )
797{
798 char * pCur;
799 if ( Abc_SopGetCubeNum(pSop) != 1 )
800 return 0;
801 for ( pCur = pSop; *pCur != ' '; pCur++ )
802 if ( *pCur == '-' )
803 return 0;
804 if ( pCur[1] != '1' )
805 return 0;
806 return 1;
807}
808
820int Abc_SopIsOrType( char * pSop )
821{
822 char * pCube, * pCur;
823 int nVars, nLits;
824 nVars = Abc_SopGetVarNum( pSop );
825 if ( nVars != Abc_SopGetCubeNum(pSop) )
826 return 0;
827 Abc_SopForEachCube( pSop, nVars, pCube )
828 {
829 // count the number of literals in the cube
830 nLits = 0;
831 for ( pCur = pCube; *pCur != ' '; pCur++ )
832 nLits += ( *pCur != '-' );
833 if ( nLits != 1 )
834 return 0;
835 }
836 return 1;
837}
838
850int Abc_SopIsExorType( char * pSop )
851{
852 char * pCur;
853 for ( pCur = pSop; *pCur; pCur++ )
854 if ( *pCur == '\n' )
855 return (int)(*(pCur - 1) == 'x' || *(pCur - 1) == 'n');
856 assert( 0 );
857 return 0;
858}
859
871int Abc_SopCheck( char * pSop, int nFanins )
872{
873 char * pCubes, * pCubesOld;
874 int fFound0 = 0, fFound1 = 0;
875
876 // check the logic function of the node
877 for ( pCubes = pSop; *pCubes; pCubes++ )
878 {
879 // get the end of the next cube
880 for ( pCubesOld = pCubes; *pCubes != ' '; pCubes++ );
881 // compare the distance
882 if ( pCubes - pCubesOld != nFanins )
883 {
884 fprintf( stdout, "Abc_SopCheck: SOP has a mismatch between its cover size (%d) and its fanin number (%d).\n",
885 (int)(ABC_PTRDIFF_T)(pCubes - pCubesOld), nFanins );
886 return 0;
887 }
888 // check the output values for this cube
889 pCubes++;
890 if ( *pCubes == '0' )
891 fFound0 = 1;
892 else if ( *pCubes == '1' )
893 fFound1 = 1;
894 else if ( *pCubes != 'x' && *pCubes != 'n' )
895 {
896 fprintf( stdout, "Abc_SopCheck: SOP has a strange character (%c) in the output part of its cube.\n", *pCubes );
897 return 0;
898 }
899 // check the last symbol (new line)
900 pCubes++;
901 if ( *pCubes != '\n' )
902 {
903 fprintf( stdout, "Abc_SopCheck: SOP has a cube without new line in the end.\n" );
904 return 0;
905 }
906 }
907 if ( fFound0 && fFound1 )
908 {
909 fprintf( stdout, "Abc_SopCheck: SOP has cubes in both phases.\n" );
910 return 0;
911 }
912 return 1;
913}
914
926int Abc_SopCheckReadTruth( Vec_Ptr_t * vRes, char * pToken, int fHex )
927{
928 char * pBase; int nVars;
929 int Log2 = Abc_Base2Log( strlen(pToken) );
930 if ( fHex && strlen(pToken) == 1 )
931 Log2 = 0;
932 if ( (1 << Log2) != (int)strlen(pToken) )
933 {
934 printf( "The truth table length (%d) is not power-of-2.\n", (int)strlen(pToken) );
935 Vec_PtrFreeData( vRes );
936 Vec_PtrShrink( vRes, 0 );
937 return 0;
938 }
939 if ( Vec_PtrSize(vRes) == 0 )
940 return 1;
941 pBase = (char *)Vec_PtrEntry( vRes, 0 );
942 nVars = Abc_SopGetVarNum( pBase );
943 if ( nVars != Log2+2*fHex )
944 {
945 printf( "Truth table #1 has %d vars while truth table #%d has %d vars.\n", nVars, Vec_PtrSize(vRes)+1, Log2+2*fHex );
946 Vec_PtrFreeData( vRes );
947 Vec_PtrShrink( vRes, 0 );
948 return 0;
949 }
950 return 1;
951}
952
964char * Abc_SopFromTruthBin( char * pTruth )
965{
966 char * pSopCover, * pCube;
967 int nTruthSize, nVars, Digit, Length, Mint, i, b;
968 Vec_Int_t * vMints;
969
970 // get the number of variables
971 nTruthSize = strlen(pTruth);
972 nVars = Abc_Base2Log( nTruthSize );
973 if ( nTruthSize != (1 << (nVars)) )
974 {
975 printf( "String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
976 return NULL;
977 }
978
979 // collect the on-set minterms
980 vMints = Vec_IntAlloc( 100 );
981 for ( i = 0; i < nTruthSize; i++ )
982 {
983 if ( pTruth[i] >= '0' && pTruth[i] <= '1' )
984 Digit = pTruth[i] - '0';
985 else
986 {
987 Vec_IntFree( vMints );
988 printf( "String %s does not look like a binary representation of the truth table.\n", pTruth );
989 return NULL;
990 }
991 if ( Digit == 1 )
992 Vec_IntPush( vMints, nTruthSize - 1 - i );
993 }
994/*
995 if ( Vec_IntSize( vMints ) == 0 || Vec_IntSize( vMints ) == nTruthSize )
996 {
997 Vec_IntFree( vMints );
998 printf( "Cannot create constant function.\n" );
999 return NULL;
1000 }
1001*/
1002 if ( Vec_IntSize(vMints) == 0 || Vec_IntSize(vMints) == (1 << nVars) )
1003 {
1004 pSopCover = ABC_ALLOC( char, 4 );
1005 pSopCover[0] = ' ';
1006 pSopCover[1] = '0' + (Vec_IntSize(vMints) > 0);
1007 pSopCover[2] = '\n';
1008 pSopCover[3] = 0;
1009 }
1010 else
1011 {
1012 // create the SOP representation of the minterms
1013 Length = Vec_IntSize(vMints) * (nVars + 3);
1014 pSopCover = ABC_ALLOC( char, Length + 1 );
1015 pSopCover[Length] = 0;
1016 Vec_IntForEachEntry( vMints, Mint, i )
1017 {
1018 pCube = pSopCover + i * (nVars + 3);
1019 for ( b = 0; b < nVars; b++ )
1020 // if ( Mint & (1 << (nVars-1-b)) )
1021 if ( Mint & (1 << b) )
1022 pCube[b] = '1';
1023 else
1024 pCube[b] = '0';
1025 pCube[nVars + 0] = ' ';
1026 pCube[nVars + 1] = '1';
1027 pCube[nVars + 2] = '\n';
1028 }
1029 }
1030 Vec_IntFree( vMints );
1031 return pSopCover;
1032}
1034{
1035 Vec_Ptr_t * vRes = Vec_PtrAlloc( 10 );
1036 char * pCopy = Abc_UtilStrsav(pTruth);
1037 char * pToken = strtok( pCopy, " \r\n\t|" );
1038 while ( pToken )
1039 {
1040 if ( !Abc_SopCheckReadTruth( vRes, pToken, 0 ) )
1041 break;
1042 Vec_PtrPush( vRes, Abc_SopFromTruthBin(pToken) );
1043 pToken = strtok( NULL, " \r\n\t|" );
1044 }
1045 ABC_FREE( pCopy );
1046 return vRes;
1047}
1048
1060char * Abc_SopFromTruthHex( char * pTruth )
1061{
1062 char * pSopCover, * pCube;
1063 int nTruthSize, nVars, Digit, Length, Mint, i, b;
1064 Vec_Int_t * vMints;
1065
1066 // get the number of variables
1067 nTruthSize = strlen(pTruth);
1068 nVars = (nTruthSize < 2) ? 2 : Abc_Base2Log(nTruthSize) + 2;
1069 if ( nTruthSize != (1 << (nVars-2)) )
1070 {
1071 printf( "String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
1072 return NULL;
1073 }
1074
1075 // collect the on-set minterms
1076 vMints = Vec_IntAlloc( 100 );
1077 for ( i = 0; i < nTruthSize; i++ )
1078 {
1079 if ( pTruth[i] >= '0' && pTruth[i] <= '9' )
1080 Digit = pTruth[i] - '0';
1081 else if ( pTruth[i] >= 'a' && pTruth[i] <= 'f' )
1082 Digit = 10 + pTruth[i] - 'a';
1083 else if ( pTruth[i] >= 'A' && pTruth[i] <= 'F' )
1084 Digit = 10 + pTruth[i] - 'A';
1085 else
1086 {
1087 printf( "String %s does not look like a hexadecimal representation of the truth table.\n", pTruth );
1088 return NULL;
1089 }
1090 for ( b = 0; b < 4; b++ )
1091 if ( Digit & (1 << b) )
1092 Vec_IntPush( vMints, 4*(nTruthSize-1-i)+b );
1093 }
1094
1095 // create the SOP representation of the minterms
1096 if ( Vec_IntSize(vMints) == 0 || Vec_IntSize(vMints) == (1 << nVars) )
1097 {
1098 pSopCover = ABC_ALLOC( char, 4 );
1099 pSopCover[0] = ' ';
1100 pSopCover[1] = '0' + (Vec_IntSize(vMints) > 0);
1101 pSopCover[2] = '\n';
1102 pSopCover[3] = 0;
1103 }
1104 else
1105 {
1106 Length = Vec_IntSize(vMints) * (nVars + 3);
1107 pSopCover = ABC_ALLOC( char, Length + 1 );
1108 pSopCover[Length] = 0;
1109 Vec_IntForEachEntry( vMints, Mint, i )
1110 {
1111 pCube = pSopCover + i * (nVars + 3);
1112 for ( b = 0; b < nVars; b++ )
1113 // if ( Mint & (1 << (nVars-1-b)) )
1114 if ( Mint & (1 << b) )
1115 pCube[b] = '1';
1116 else
1117 pCube[b] = '0';
1118 pCube[nVars + 0] = ' ';
1119 pCube[nVars + 1] = '1';
1120 pCube[nVars + 2] = '\n';
1121 }
1122 }
1123
1124 Vec_IntFree( vMints );
1125 return pSopCover;
1126}
1128{
1129 Vec_Ptr_t * vRes = Vec_PtrAlloc( 10 );
1130 char * pCopy = Abc_UtilStrsav(pTruth);
1131 char * pToken = strtok( pCopy, " \r\n\t|" );
1132 while ( pToken )
1133 {
1134 if ( pToken[0] == '0' && pToken[1] == 'x' )
1135 pToken += 2;
1136 if ( !Abc_SopCheckReadTruth( vRes, pToken, 1 ) )
1137 break;
1138 Vec_PtrPush( vRes, Abc_SopFromTruthHex(pToken) );
1139 pToken = strtok( NULL, " \r\n\t|" );
1140 }
1141 ABC_FREE( pCopy );
1142 return vRes;
1143}
1144
1146{
1147 int m, i, o, nOuts = Abc_Base2Log( nVars + 1 );
1148 Vec_Ptr_t * vRes = Vec_PtrAlloc( nOuts );
1149 for ( o = 0; o < nOuts; o++ )
1150 {
1151 Vec_Str_t * vStr = Vec_StrAlloc( 1000 );
1152 for ( m = 0; m < (1 << nVars); m++ ) {
1153 int nOnes = __builtin_popcount(m);
1154 if ( !((nOnes >> o) & 1) )
1155 continue;
1156 for ( i = 0; i < nVars; i++ )
1157 Vec_StrPush( vStr, ((m >> i) & 1) ? '1' : '0' );
1158 Vec_StrPush( vStr, ' ' );
1159 Vec_StrPush( vStr, '1' );
1160 Vec_StrPush( vStr, '\n' );
1161 }
1162 Vec_StrPush( vStr, '\0' );
1163 //printf( "%s\n", Vec_StrArray(vStr) );
1164 Vec_PtrPush( vRes, Vec_StrReleaseArray(vStr) );
1165 Vec_StrFree( vStr );
1166 }
1167 return vRes;
1168}
1169
1181char * Abc_SopEncoderPos( Mem_Flex_t * pMan, int iValue, int nValues )
1182{
1183 char Buffer[32];
1184 assert( iValue < nValues );
1185 sprintf( Buffer, "d0\n%d 1\n", iValue );
1186 return Abc_SopRegister( pMan, Buffer );
1187}
1188
1200char * Abc_SopEncoderLog( Mem_Flex_t * pMan, int iBit, int nValues )
1201{
1202 char * pResult;
1203 Vec_Str_t * vSop;
1204 int v, Counter, fFirst = 1, nBits = Abc_Base2Log(nValues);
1205 assert( iBit < nBits );
1206 // count the number of literals
1207 Counter = 0;
1208 for ( v = 0; v < nValues; v++ )
1209 Counter += ( (v & (1 << iBit)) > 0 );
1210 // create the cover
1211 vSop = Vec_StrAlloc( 100 );
1212 Vec_StrPrintStr( vSop, "d0\n" );
1213 if ( Counter > 1 )
1214 Vec_StrPrintStr( vSop, "(" );
1215 for ( v = 0; v < nValues; v++ )
1216 if ( v & (1 << iBit) )
1217 {
1218 if ( fFirst )
1219 fFirst = 0;
1220 else
1221 Vec_StrPush( vSop, ',' );
1222 Vec_StrPrintNum( vSop, v );
1223 }
1224 if ( Counter > 1 )
1225 Vec_StrPrintStr( vSop, ")" );
1226 Vec_StrPrintStr( vSop, " 1\n" );
1227 Vec_StrPush( vSop, 0 );
1228 pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
1229 Vec_StrFree( vSop );
1230 return pResult;
1231}
1232
1244char * Abc_SopDecoderPos( Mem_Flex_t * pMan, int nValues )
1245{
1246 char * pResult;
1247 Vec_Str_t * vSop;
1248 int i, k;
1249 assert( nValues > 1 );
1250 vSop = Vec_StrAlloc( 100 );
1251 for ( i = 0; i < nValues; i++ )
1252 {
1253 for ( k = 0; k < nValues; k++ )
1254 {
1255 if ( k == i )
1256 Vec_StrPrintStr( vSop, "1 " );
1257 else
1258 Vec_StrPrintStr( vSop, "- " );
1259 }
1260 Vec_StrPrintNum( vSop, i );
1261 Vec_StrPush( vSop, '\n' );
1262 }
1263 Vec_StrPush( vSop, 0 );
1264 pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
1265 Vec_StrFree( vSop );
1266 return pResult;
1267}
1268
1280char * Abc_SopDecoderLog( Mem_Flex_t * pMan, int nValues )
1281{
1282 char * pResult;
1283 Vec_Str_t * vSop;
1284 int i, b, nBits = Abc_Base2Log(nValues);
1285 assert( nValues > 1 && nValues <= (1<<nBits) );
1286 vSop = Vec_StrAlloc( 100 );
1287 for ( i = 0; i < nValues; i++ )
1288 {
1289 for ( b = 0; b < nBits; b++ )
1290 {
1291 Vec_StrPrintNum( vSop, (int)((i & (1 << b)) > 0) );
1292 Vec_StrPush( vSop, ' ' );
1293 }
1294 Vec_StrPrintNum( vSop, i );
1295 Vec_StrPush( vSop, '\n' );
1296 }
1297 Vec_StrPush( vSop, 0 );
1298 pResult = Abc_SopRegister( pMan, Vec_StrArray(vSop) );
1299 Vec_StrFree( vSop );
1300 return pResult;
1301}
1302
1314word Abc_SopToTruth( char * pSop, int nInputs )
1315{
1316 static word Truth[8] = {
1317 ABC_CONST(0xAAAAAAAAAAAAAAAA),
1318 ABC_CONST(0xCCCCCCCCCCCCCCCC),
1319 ABC_CONST(0xF0F0F0F0F0F0F0F0),
1320 ABC_CONST(0xFF00FF00FF00FF00),
1321 ABC_CONST(0xFFFF0000FFFF0000),
1322 ABC_CONST(0xFFFFFFFF00000000),
1323 ABC_CONST(0x0000000000000000),
1324 ABC_CONST(0xFFFFFFFFFFFFFFFF)
1325 };
1326 word Cube, Result = 0;
1327 int v, lit = 0;
1328 int nVars = Abc_SopGetVarNum(pSop);
1329 assert( nVars >= 0 && nVars <= 6 );
1330 assert( nVars == nInputs );
1331 do {
1332 Cube = Truth[7];
1333 for ( v = 0; v < nVars; v++, lit++ )
1334 {
1335 if ( pSop[lit] == '1' )
1336 Cube &= Truth[v];
1337 else if ( pSop[lit] == '0' )
1338 Cube &= ~Truth[v];
1339 else if ( pSop[lit] != '-' )
1340 assert( 0 );
1341 }
1342 Result |= Cube;
1343 assert( pSop[lit] == ' ' );
1344 lit++;
1345 lit++;
1346 assert( pSop[lit] == '\n' );
1347 lit++;
1348 } while ( pSop[lit] );
1349 if ( Abc_SopIsComplement(pSop) )
1350 Result = ~Result;
1351 return Result;
1352}
1353
1365void Abc_SopToTruth7( char * pSop, int nInputs, word r[2] )
1366{
1367 static word Truth[7][2] = {
1368 {ABC_CONST(0xAAAAAAAAAAAAAAAA),ABC_CONST(0xAAAAAAAAAAAAAAAA)},
1369 {ABC_CONST(0xCCCCCCCCCCCCCCCC),ABC_CONST(0xCCCCCCCCCCCCCCCC)},
1370 {ABC_CONST(0xF0F0F0F0F0F0F0F0),ABC_CONST(0xF0F0F0F0F0F0F0F0)},
1371 {ABC_CONST(0xFF00FF00FF00FF00),ABC_CONST(0xFF00FF00FF00FF00)},
1372 {ABC_CONST(0xFFFF0000FFFF0000),ABC_CONST(0xFFFF0000FFFF0000)},
1373 {ABC_CONST(0xFFFFFFFF00000000),ABC_CONST(0xFFFFFFFF00000000)},
1374 {ABC_CONST(0x0000000000000000),ABC_CONST(0xFFFFFFFFFFFFFFFF)},
1375 };
1376 word Cube[2];
1377 int v, lit = 0;
1378 int nVars = Abc_SopGetVarNum(pSop);
1379 assert( nVars >= 0 && nVars <= 7 );
1380 assert( nVars == nInputs );
1381 r[0] = r[1] = 0;
1382 do {
1383 Cube[0] = Cube[1] = ~(word)0;
1384 for ( v = 0; v < nVars; v++, lit++ )
1385 {
1386 if ( pSop[lit] == '1' )
1387 {
1388 Cube[0] &= Truth[v][0];
1389 Cube[1] &= Truth[v][1];
1390 }
1391 else if ( pSop[lit] == '0' )
1392 {
1393 Cube[0] &= ~Truth[v][0];
1394 Cube[1] &= ~Truth[v][1];
1395 }
1396 else if ( pSop[lit] != '-' )
1397 assert( 0 );
1398 }
1399 r[0] |= Cube[0];
1400 r[1] |= Cube[1];
1401 assert( pSop[lit] == ' ' );
1402 lit++;
1403 lit++;
1404 assert( pSop[lit] == '\n' );
1405 lit++;
1406 } while ( pSop[lit] );
1407 if ( Abc_SopIsComplement(pSop) )
1408 {
1409 r[0] = ~r[0];
1410 r[1] = ~r[1];
1411 }
1412}
1413
1425void Abc_SopToTruthBig( char * pSop, int nInputs, word ** pVars, word * pCube, word * pRes )
1426{
1427 int nVars = Abc_SopGetVarNum(pSop);
1428 int nWords = nVars <= 6 ? 1 : 1 << (nVars-6);
1429 int v, i, lit = 0;
1430 assert( nVars >= 0 && nVars <= 16 );
1431 assert( nVars == nInputs );
1432 for ( i = 0; i < nWords; i++ )
1433 pRes[i] = 0;
1434 do {
1435 for ( i = 0; i < nWords; i++ )
1436 pCube[i] = ~(word)0;
1437 for ( v = 0; v < nVars; v++, lit++ )
1438 {
1439 if ( pSop[lit] == '1' )
1440 {
1441 for ( i = 0; i < nWords; i++ )
1442 pCube[i] &= pVars[v][i];
1443 }
1444 else if ( pSop[lit] == '0' )
1445 {
1446 for ( i = 0; i < nWords; i++ )
1447 pCube[i] &= ~pVars[v][i];
1448 }
1449 else if ( pSop[lit] != '-' )
1450 assert( 0 );
1451 }
1452 for ( i = 0; i < nWords; i++ )
1453 pRes[i] |= pCube[i];
1454 assert( pSop[lit] == ' ' );
1455 lit++;
1456 lit++;
1457 assert( pSop[lit] == '\n' );
1458 lit++;
1459 } while ( pSop[lit] );
1460 if ( Abc_SopIsComplement(pSop) )
1461 {
1462 for ( i = 0; i < nWords; i++ )
1463 pRes[i] = ~pRes[i];
1464 }
1465}
1466
1470
1471
1473
int nWords
Definition abcNpn.c:127
int Abc_SopIsOrType(char *pSop)
Definition abcSop.c:820
char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
Definition abcSop.c:383
char * Abc_SopCreateNand(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:190
char * Abc_SopCreateNor(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:259
int Abc_SopCheck(char *pSop, int nFanins)
Definition abcSop.c:871
int Abc_SopIsConst0(char *pSop)
Definition abcSop.c:724
int Abc_SopIsBuf(char *pSop)
Definition abcSop.c:756
int Abc_SopIsExorType(char *pSop)
Definition abcSop.c:850
Vec_Ptr_t * Abc_SopFromTruthsHex(char *pTruth)
Definition abcSop.c:1127
char * Abc_SopStart(Mem_Flex_t *pMan, int nCubes, int nVars)
Definition abcSop.c:82
char * Abc_SopCreateOrMultiCube(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition abcSop.c:234
int Abc_SopGetLitNum(char *pSop)
Definition abcSop.c:559
char * Abc_SopCreateConst1(Mem_Flex_t *pMan)
Definition abcSop.c:113
int Abc_SopGetCubeNum(char *pSop)
Definition abcSop.c:537
char * Abc_SopFromTruthHex(char *pTruth)
Definition abcSop.c:1060
char * Abc_SopCreateXor(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:280
int Abc_SopGetIthCareLit(char *pSop, int i)
Definition abcSop.c:626
char * Abc_SopCreateMux(Mem_Flex_t *pMan)
Definition abcSop.c:335
char * Abc_SopCreateNxor(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:317
int Abc_SopIsAndType(char *pSop)
Definition abcSop.c:796
char * Abc_SopCreateOr(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition abcSop.c:212
int Abc_SopIsComplement(char *pSop)
Definition abcSop.c:703
int Abc_SopIsConst1(char *pSop)
Definition abcSop.c:740
int Abc_SopIsInv(char *pSop)
Definition abcSop.c:776
Vec_Ptr_t * Abc_SopFromTruthsBin(char *pTruth)
Definition abcSop.c:1033
char * Abc_SopCreateAnd2(Mem_Flex_t *pMan, int fCompl0, int fCompl1)
Definition abcSop.c:145
ABC_NAMESPACE_IMPL_START char * Abc_SopRegister(Mem_Flex_t *pMan, const char *pName)
DECLARATIONS ///.
Definition abcSop.c:62
char * Abc_SopDecoderPos(Mem_Flex_t *pMan, int nValues)
Definition abcSop.c:1244
char * Abc_SopCreateAnd(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition abcSop.c:168
int Abc_SopGetPhase(char *pSop)
Definition abcSop.c:604
char * Abc_SopEncoderPos(Mem_Flex_t *pMan, int iValue, int nValues)
Definition abcSop.c:1181
word Abc_SopToTruth(char *pSop, int nInputs)
Definition abcSop.c:1314
char * Abc_SopCreateXorSpecial(Mem_Flex_t *pMan, int nVars)
Definition abcSop.c:297
void Abc_SopComplement(char *pSop)
Definition abcSop.c:648
void Abc_SopToIsop(char *pSop, Vec_Int_t *vCover)
Definition abcSop.c:502
int Abc_SopCheckReadTruth(Vec_Ptr_t *vRes, char *pToken, int fHex)
Definition abcSop.c:926
char * Abc_SopDecoderLog(Mem_Flex_t *pMan, int nValues)
Definition abcSop.c:1280
Vec_Ptr_t * Abc_SopGenerateCounters(int nVars)
Definition abcSop.c:1145
void Abc_SopComplementVar(char *pSop, int iVar)
Definition abcSop.c:678
char * Abc_SopCreateFromTruthIsop(Mem_Flex_t *pMan, int nVars, word *pTruth, Vec_Int_t *vCover)
Definition abcSop.c:462
char * Abc_SopCreateFromIsop(Mem_Flex_t *pMan, int nVars, Vec_Int_t *vCover)
Definition abcSop.c:424
char * Abc_SopCreateConst0(Mem_Flex_t *pMan)
Definition abcSop.c:129
char * Abc_SopEncoderLog(Mem_Flex_t *pMan, int iBit, int nValues)
Definition abcSop.c:1200
void Abc_SopToTruthBig(char *pSop, int nInputs, word **pVars, word *pCube, word *pRes)
Definition abcSop.c:1425
char * Abc_SopCreateBuf(Mem_Flex_t *pMan)
Definition abcSop.c:367
void Abc_SopToTruth7(char *pSop, int nInputs, word r[2])
Definition abcSop.c:1365
char * Abc_SopCreateInv(Mem_Flex_t *pMan)
Definition abcSop.c:351
int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
char * Abc_SopFromTruthBin(char *pTruth)
Definition abcSop.c:964
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition abc.h:538
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
struct cube Cube
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Kit_TruthIsop(unsigned *puTruth, int nVars, Vec_Int_t *vMemory, int fTryBoth)
Definition kitIsop.c:134
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
Definition mem.c:388
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
int lit
Definition satVec.h:130
#define assert(ex)
Definition util_old.h:213
char * memset()
int strlen()
char * sprintf()
char * strtok()
char * strcpy()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42