59 if ( pName == NULL )
return NULL;
78 char * pSopCover, * pCube;
81 Length = nCubes * (nVars + 3);
83 memset( pSopCover,
'-', Length );
84 pSopCover[Length] = 0;
86 for ( i = 0; i < nCubes; i++ )
88 pCube = pSopCover + i * (nVars + 3);
89 pCube[nVars + 0] =
' ';
90 pCube[nVars + 1] =
'1';
91 pCube[nVars + 2] =
'\n';
142 Buffer[0] =
'1' - fCompl0;
143 Buffer[1] =
'1' - fCompl1;
167 for ( i = 0; i < nVars; i++ )
168 pSop[i] =
'1' - (pfCompl? pfCompl[i] : 0);
169 pSop[nVars + 1] =
'1';
189 for ( i = 0; i < nVars; i++ )
191 pSop[nVars + 1] =
'0';
211 for ( i = 0; i < nVars; i++ )
212 pSop[i] =
'0' + (pfCompl? pfCompl[i] : 0);
213 pSop[nVars + 1] =
'0';
230 char * pSop, * pCube;
236 pCube[i] =
'1' - (pfCompl? pfCompl[i] : 0);
258 for ( i = 0; i < nVars; i++ )
296 assert( pSop[nVars+2] ==
'\n' );
379 char * pSop, * pCube;
383 nMints = (1 << nVars);
384 for ( i = 0; i < nMints; i++ )
385 Counter += ((pTruth[i>>5] & (1 << (i&31))) > 0);
394 for ( i = 0; i < nMints; i++ )
395 if ( (pTruth[i>>5] & (1 << (i&31))) > 0 )
397 pCube = pSop + Counter * (nVars + 3);
398 for ( k = 0; k < nVars; k++ )
399 pCube[k] =
'0' + ((i & (1 << k)) > 0);
418 char * pSop, * pCube;
419 int i, k, Entry, Literal;
428 pCube = pSop + i * (nVars + 3);
429 for ( k = 0; k < nVars; k++ )
431 Literal = 3 & (Entry >> (k << 1));
434 else if ( Literal == 2 )
436 else if ( Literal != 0 )
462 for ( pCube = pSop; *pCube; pCube += nVars + 3 )
465 for ( k = nVars - 1; k >= 0; k-- )
466 if ( pCube[k] ==
'0' )
467 Entry = (Entry << 2) | 1;
468 else if ( pCube[k] ==
'1' )
469 Entry = (Entry << 2) | 2;
470 else if ( pCube[k] ==
'-' )
471 Entry = (Entry << 2);
495 for ( pCur = pSop; *pCur; pCur++ )
496 nCubes += (*pCur ==
'\n');
517 for ( pCur = pSop; *pCur; pCur++ )
519 nLits -= (*pCur ==
'\n');
520 nLits += (*pCur ==
'0' || *pCur ==
'1');
539 for ( pCur = pSop; *pCur !=
'\n'; pCur++ )
542 return pCur - pSop - 2;
559 if ( pSop[nVars+1] ==
'0' || pSop[nVars+1] ==
'n' )
561 if ( pSop[nVars+1] ==
'1' || pSop[nVars+1] ==
'x' )
584 if ( pCube[i] !=
'-' )
585 return pCube[i] -
'0';
603 for ( pCur = pSop; *pCur; pCur++ )
606 if ( *(pCur - 1) ==
'0' )
608 else if ( *(pCur - 1) ==
'1' )
610 else if ( *(pCur - 1) ==
'x' )
612 else if ( *(pCur - 1) ==
'n' )
637 if ( pCube[iVar] ==
'0' )
639 else if ( pCube[iVar] ==
'1' )
658 for ( pCur = pSop; *pCur; pCur++ )
660 return (
int)(*(pCur - 1) ==
'0' || *(pCur - 1) ==
'n');
678 return pSop[0] ==
' ' && pSop[1] ==
'0';
694 return pSop[0] ==
' ' && pSop[1] ==
'1';
712 if ( (pSop[0] ==
'1' && pSop[2] ==
'1') || (pSop[0] ==
'0' && pSop[2] ==
'0') )
732 if ( (pSop[0] ==
'0' && pSop[2] ==
'1') || (pSop[0] ==
'1' && pSop[2] ==
'0') )
753 for ( pCur = pSop; *pCur !=
' '; pCur++ )
756 if ( pCur[1] !=
'1' )
774 char * pCube, * pCur;
783 for ( pCur = pCube; *pCur !=
' '; pCur++ )
784 nLits += ( *pCur !=
'-' );
805 for ( pCur = pSop; *pCur; pCur++ )
807 return (
int)(*(pCur - 1) ==
'x' || *(pCur - 1) ==
'n');
825 char * pCubes, * pCubesOld;
826 int fFound0 = 0, fFound1 = 0;
829 for ( pCubes = pSop; *pCubes; pCubes++ )
832 for ( pCubesOld = pCubes; *pCubes !=
' '; pCubes++ );
834 if ( pCubes - pCubesOld != nFanins )
836 fprintf( stdout,
"Abc_SopCheck: SOP has a mismatch between its cover size (%d) and its fanin number (%d).\n",
837 (
int)(ABC_PTRDIFF_T)(pCubes - pCubesOld), nFanins );
842 if ( *pCubes ==
'0' )
844 else if ( *pCubes ==
'1' )
846 else if ( *pCubes !=
'x' && *pCubes !=
'n' )
848 fprintf( stdout,
"Abc_SopCheck: SOP has a strange character (%c) in the output part of its cube.\n", *pCubes );
853 if ( *pCubes !=
'\n' )
855 fprintf( stdout,
"Abc_SopCheck: SOP has a cube without new line in the end.\n" );
859 if ( fFound0 && fFound1 )
861 fprintf( stdout,
"Abc_SopCheck: SOP has cubes in both phases.\n" );
881 char * pSopCover, * pCube;
882 int nTruthSize, nVars, Digit, Length, Mint, i, b;
886 nTruthSize =
strlen(pTruth);
888 if ( nTruthSize != (1 << (nVars)) )
890 printf(
"String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
896 for ( i = 0; i < nTruthSize; i++ )
898 if ( pTruth[i] >=
'0' && pTruth[i] <=
'1' )
899 Digit = pTruth[i] -
'0';
903 printf(
"String %s does not look like a binary representation of the truth table.\n", pTruth );
912 printf(
"Cannot create constant function.\n" );
918 pSopCover =
ABC_ALLOC(
char, Length + 1 );
919 pSopCover[Length] = 0;
922 pCube = pSopCover + i * (nVars + 3);
923 for ( b = 0; b < nVars; b++ )
924 if ( Mint & (1 << (nVars-1-b)) )
929 pCube[nVars + 0] =
' ';
930 pCube[nVars + 1] =
'1';
931 pCube[nVars + 2] =
'\n';
950 char * pSopCover, * pCube;
951 int nTruthSize, nVars, Digit, Length, Mint, i, b;
955 nTruthSize =
strlen(pTruth);
956 nVars = (nTruthSize < 2) ? 2 :
Abc_Base2Log(nTruthSize) + 2;
957 if ( nTruthSize != (1 << (nVars-2)) )
959 printf(
"String %s does not look like a truth table of a %d-variable function.\n", pTruth, nVars );
965 for ( i = 0; i < nTruthSize; i++ )
967 if ( pTruth[i] >=
'0' && pTruth[i] <=
'9' )
968 Digit = pTruth[i] -
'0';
969 else if ( pTruth[i] >=
'a' && pTruth[i] <=
'f' )
970 Digit = 10 + pTruth[i] -
'a';
971 else if ( pTruth[i] >=
'A' && pTruth[i] <=
'F' )
972 Digit = 10 + pTruth[i] -
'A';
975 printf(
"String %s does not look like a hexadecimal representation of the truth table.\n", pTruth );
978 for ( b = 0; b < 4; b++ )
979 if ( Digit & (1 << b) )
985 pSopCover =
ABC_ALLOC(
char, Length + 1 );
986 pSopCover[Length] = 0;
989 pCube = pSopCover + i * (nVars + 3);
990 for ( b = 0; b < nVars; b++ )
992 if ( Mint & (1 << b) )
996 pCube[nVars + 0] =
' ';
997 pCube[nVars + 1] =
'1';
998 pCube[nVars + 2] =
'\n';
1033 assert( iValue < nValues );
1034 sprintf( Buffer,
"d0\n%d 1\n", iValue );
1057 for ( v = 0; v < nValues; v++ )
1058 Counter += ( (v & (1 << iBit)) > 0 );
1064 for ( v = 0; v < nValues; v++ )
1065 if ( v & (1 << iBit) )
1100 for ( i = 0; i < nValues; i++ )
1102 for ( k = 0; k < nValues; k++ )
1134 assert( nValues > 1 && nValues <= (1<<nBits) );
1136 for ( i = 0; i < nValues; i++ )
1138 for ( b = 0; b < nBits; b++ )
1175 word Cube, Result = 0;
1178 assert( nVars >= 0 && nVars <= 6 );
1179 assert( nVars == nInputs );
1182 for ( v = 0; v < nVars; v++, lit++ )
1184 if ( pSop[lit] ==
'1' )
1186 else if ( pSop[lit] ==
'0' )
1188 else if ( pSop[lit] !=
'-' )
1192 assert( pSop[lit] ==
' ' );
1195 assert( pSop[lit] ==
'\n' );
1197 }
while ( pSop[lit] );
1228 assert( nVars >= 0 && nVars <= 7 );
1229 assert( nVars == nInputs );
1232 Cube[0] = Cube[1] = ~(
word)0;
1233 for ( v = 0; v < nVars; v++, lit++ )
1235 if ( pSop[lit] ==
'1' )
1237 Cube[0] &= Truth[v][0];
1238 Cube[1] &= Truth[v][1];
1240 else if ( pSop[lit] ==
'0' )
1242 Cube[0] &= ~Truth[v][0];
1243 Cube[1] &= ~Truth[v][1];
1245 else if ( pSop[lit] !=
'-' )
1250 assert( pSop[lit] ==
' ' );
1253 assert( pSop[lit] ==
'\n' );
1255 }
while ( pSop[lit] );
1277 int nWords = nVars <= 6 ? 1 : 1 << (nVars-6);
1279 assert( nVars >= 0 && nVars <= 16 );
1280 assert( nVars == nInputs );
1281 for ( i = 0; i <
nWords; i++ )
1284 for ( i = 0; i <
nWords; i++ )
1285 pCube[i] = ~(
word)0;
1286 for ( v = 0; v < nVars; v++, lit++ )
1288 if ( pSop[lit] ==
'1' )
1290 for ( i = 0; i <
nWords; i++ )
1291 pCube[i] &= pVars[v][i];
1293 else if ( pSop[lit] ==
'0' )
1295 for ( i = 0; i <
nWords; i++ )
1296 pCube[i] &= ~pVars[v][i];
1298 else if ( pSop[lit] !=
'-' )
1301 for ( i = 0; i <
nWords; i++ )
1302 pRes[i] |= pCube[i];
1303 assert( pSop[lit] ==
' ' );
1306 assert( pSop[lit] ==
'\n' );
1308 }
while ( pSop[lit] );
1311 for ( i = 0; i <
nWords; i++ )
word Abc_SopToTruth(char *pSop, int nInputs)
char * Abc_SopCreateOrMultiCube(Mem_Flex_t *pMan, int nVars, int *pfCompl)
void Abc_SopComplement(char *pSop)
int Abc_SopIsAndType(char *pSop)
char * Abc_SopCreateNxor(Mem_Flex_t *pMan, int nVars)
char * Abc_SopCreateNor(Mem_Flex_t *pMan, int nVars)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
static char * Vec_StrArray(Vec_Str_t *p)
char * Abc_SopEncoderPos(Mem_Flex_t *pMan, int iValue, int nValues)
void Abc_SopToIsop(char *pSop, Vec_Int_t *vCover)
char * Abc_SopCreateAnd2(Mem_Flex_t *pMan, int fCompl0, int fCompl1)
#define Abc_SopForEachCube(pSop, nFanins, pCube)
void Abc_SopToTruth7(char *pSop, int nInputs, word r[2])
static void Vec_StrPrintNum(Vec_Str_t *p, int Num)
#define ABC_ALLOC(type, num)
char * Abc_SopCreateOr(Mem_Flex_t *pMan, int nVars, int *pfCompl)
ABC_NAMESPACE_IMPL_START char * Abc_SopRegister(Mem_Flex_t *pMan, char *pName)
DECLARATIONS ///.
static Vec_Str_t * Vec_StrAlloc(int nCap)
static void Vec_StrPush(Vec_Str_t *p, char Entry)
char * Abc_SopCreateMux(Mem_Flex_t *pMan)
void Abc_SopComplementVar(char *pSop, int iVar)
int Abc_SopIsConst1(char *pSop)
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
int Abc_SopGetIthCareLit(char *pSop, int i)
char * Abc_SopCreateXor(Mem_Flex_t *pMan, int nVars)
char * Abc_SopCreateBuf(Mem_Flex_t *pMan)
int Abc_SopGetVarNum(char *pSop)
char * Abc_SopCreateXorSpecial(Mem_Flex_t *pMan, int nVars)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
static void Vec_StrFree(Vec_Str_t *p)
char * Abc_SopCreateConst1(Mem_Flex_t *pMan)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
char * Abc_SopFromTruthBin(char *pTruth)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
int Abc_SopIsExorType(char *pSop)
int Abc_SopGetPhase(char *pSop)
char * Abc_SopFromTruthHex(char *pTruth)
#define ABC_NAMESPACE_IMPL_START
int Abc_SopIsConst0(char *pSop)
int Abc_SopIsBuf(char *pSop)
char * Abc_SopEncoderLog(Mem_Flex_t *pMan, int iBit, int nValues)
int Abc_SopIsComplement(char *pSop)
char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
char * Abc_SopCreateAnd(Mem_Flex_t *pMan, int nVars, int *pfCompl)
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
static int Vec_IntSize(Vec_Int_t *p)
char * Abc_SopCreateInv(Mem_Flex_t *pMan)
char * Abc_SopCreateFromIsop(Mem_Flex_t *pMan, int nVars, Vec_Int_t *vCover)
int Abc_SopCheck(char *pSop, int nFanins)
#define ABC_CONST(number)
PARAMETERS ///.
char * Abc_SopStart(Mem_Flex_t *pMan, int nCubes, int nVars)
char * Abc_SopCreateConst0(Mem_Flex_t *pMan)
char * Abc_SopDecoderPos(Mem_Flex_t *pMan, int nValues)
char * Abc_SopCreateNand(Mem_Flex_t *pMan, int nVars)
static int Abc_Base2Log(unsigned n)
void Abc_SopToTruthBig(char *pSop, int nInputs, word **pVars, word *pCube, word *pRes)
static void Vec_StrPrintStr(Vec_Str_t *p, const char *pStr)
int Abc_SopGetCubeNum(char *pSop)
static void Vec_IntFree(Vec_Int_t *p)
int Abc_SopIsInv(char *pSop)
static void Vec_IntClear(Vec_Int_t *p)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
int Abc_SopIsOrType(char *pSop)
int Abc_SopGetLitNum(char *pSop)
char * Abc_SopDecoderLog(Mem_Flex_t *pMan, int nValues)