55static inline int Abc_TruthGetBit(
word *
p,
int i ) {
return (
int)(
p[i>>6] >> (i & 63)) & 1; }
56static inline void Abc_TruthSetBit(
word *
p,
int i ) {
p[i>>6] |= (((
word)1)<<(i & 63)); }
57static inline void Abc_TruthXorBit(
word *
p,
int i ) {
p[i>>6] ^= (((
word)1)<<(i & 63)); }
60static inline int Abc_TruthGetHex(
word *
p,
int k ) {
return (
int)(
p[k>>4] >> ((k<<2) & 63)) & 15; }
61static inline void Abc_TruthSetHex(
word *
p,
int k,
int d ) {
p[k>>4] |= (((
word)d)<<((k<<2) & 63)); }
62static inline void Abc_TruthXorHex(
word *
p,
int k,
int d ) {
p[k>>4] ^= (((
word)d)<<((k<<2) & 63)); }
69static inline int Abc_TruthReadHexDigit(
char HexChar )
71 if ( HexChar >=
'0' && HexChar <=
'9' )
73 if ( HexChar >=
'A' && HexChar <=
'F' )
74 return HexChar -
'A' + 10;
75 if ( HexChar >=
'a' && HexChar <=
'f' )
76 return HexChar -
'a' + 10;
82static inline void Abc_TruthWriteHexDigit( FILE * pFile,
int HexDigit )
84 assert( HexDigit >= 0 && HexDigit < 16 );
86 fprintf( pFile,
"%d", HexDigit );
88 fprintf( pFile,
"%c",
'A' + HexDigit-10 );
94 int nWords = (nVars < 7)? 1 : (1 << (nVars-6));
95 int k, Digit, nDigits = (nVars < 7) ? (1 << (nVars-2)) : (
nWords << 4);
98 if ( pString[0] ==
'0' && pString[1] ==
'x' )
101 EndSymbol = pString[nDigits];
105 assert( EndSymbol ==
' ' || EndSymbol ==
'\n' || EndSymbol ==
'\r' || EndSymbol ==
'\0' );
108 for ( k = 0; k < nDigits; k++ )
110 Digit = Abc_TruthReadHexDigit( pString[nDigits - 1 - k] );
111 assert( Digit >= 0 && Digit < 16 );
112 Abc_TruthSetHex( pTruth, k, Digit );
119 int nDigits, Digit, k;
120 nDigits = (1 << (nVars-2));
121 for ( k = 0; k < nDigits; k++ )
123 Digit = Abc_TruthGetHex( pTruth, k );
124 assert( Digit >= 0 && Digit < 16 );
125 Abc_TruthWriteHexDigit( pFile, Digit );
147 p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
152 p->pFuncs[0] = (
word *)(
p->pFuncs +
p->nFuncs);
153 memset(
p->pFuncs[0], 0,
sizeof(
word) *
p->nWords *
p->nFuncs );
155 for ( i = 1; i <
p->nFuncs; i++ )
156 p->pFuncs[i] =
p->pFuncs[i-1] +
p->nWords;
165 p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
170 p->pFuncs[0] = pBuffer;
172 for ( i = 1; i <
p->nFuncs; i++ )
173 p->pFuncs[i] =
p->pFuncs[i-1] +
p->nWords;
199 pFile = fopen( pFileName,
"rb" );
202 printf(
"Cannot open file \"%s\" for reading.\n", pFileName );
207 nFileSize = ftell( pFile );
227 int nFileSize, RetValue;
228 pFile = fopen( pFileName,
"rb" );
231 printf(
"Cannot open file \"%s\" for reading.\n", pFileName );
236 nFileSize = ftell( pFile );
240 pBuffer = (
char *)
malloc( nFileSize + 3 );
241 RetValue = fread( pBuffer, nFileSize, 1, pFile );
244 pBuffer[ nFileSize + 0] =
'\n';
245 pBuffer[ nFileSize + 1] =
'\n';
247 pBuffer[ nFileSize + 2] =
'\0';
266 int i, nVars, nLines;
274 if ( pContents == NULL )
278 for ( i = 0; pContents[i]; i++ )
279 if ( pContents[i] ==
' ' || pContents[i] ==
'\n' || pContents[i] ==
'\r' )
281 if ( pContents[i] == 0 )
282 printf(
"Strange, the input file does not have spaces and new-lines...\n" );
285 if ( pContents[0] ==
'0' && pContents[1] ==
'x' )
289 for ( nVars = 0; nVars < 32; nVars++ )
290 if ( 4 * i == (1 << nVars) )
292 if ( nVars < 2 || nVars > 16 )
294 printf(
"Does not look like the input file contains truth tables...\n" );
302 for ( i = 0; pContents[i]; i++ )
303 nLines += (pContents[i] ==
'\n');
326 if ( pContents == NULL )
333 for ( nLines = i = 0; pContents[i] !=
'\n'; )
339 while ( pContents[i++] !=
'\n' );
363 int i, nBytes = 8 * Abc_Truth6WordNum(
p->nVars );
364 pFile = fopen( pFileName,
"wb" );
367 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
370 for ( i = 0; i <
p->nFuncs; i++ )
373 fwrite(
p->pFuncs[i], nBytes, 1, pFile );
378 fprintf( pFile,
"%s\n", pBuffer );
404 if ( nVars < 2 || nVars > 16 || nTruths == 0 )
415 int nBytes = (1 << (nVarNum-3));
416 int nTruths = nFileSize / nBytes;
417 if ( nFileSize == -1 )
420 if ( nFileSize % nBytes != 0 )
421 Abc_Print( 0,
"The file size (%d) is divided by the truth table size (%d) with remainder (%d).\n",
422 nFileSize, nBytes, nFileSize % nBytes );
445 char * pFileInput = pFileName;
458 printf(
"Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
474 word * pTruth;
int i;
475 FILE * pFile = fopen( pFileName,
"wb" );
478 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
482 fwrite( pTruth, nBytes, 1, pFile );
499 unsigned * pTruth =
ABC_CALLOC(
unsigned, (1 << 11) );
500 char * pBuffer =
ABC_CALLOC(
char, (1 << 16) );
501 char * pFileInput = pFileName;
503 FILE * pFileI = fopen( pFileInput,
"rb" );
504 FILE * pFileO = fopen( pFileOutput,
"wb" );
505 int i, Value, nVarsAll = -1;
506 if ( pFileI == NULL )
508 while ( fgets(pBuffer, (1 << 16), pFileI) )
511 int nVars = Abc_Base2Log(
Len);
512 int nInts = Abc_BitWordNum(
Len);
514 if ( nVarsAll == -1 )
517 assert( nVarsAll == nVars );
518 memset( pTruth, 0,
sizeof(
int)*nInts );
519 for ( i = 0; i <
Len; i++ )
520 if ( pBuffer[i] ==
'1' )
521 Abc_InfoSetBit( pTruth, i );
523 assert( pBuffer[i] ==
'0' );
524 Value = fwrite( pTruth, 1,
sizeof(
int) * nInts, pFileO );
525 assert( Value == (
int)
sizeof(
int) * nInts );
531 printf(
"Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
548 char * pFileInput = pFileName;
549 char * pFileOutput =
"out.txt";
561 printf(
"Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
580 char * pAlgoName = NULL;
582 pAlgoName =
"factoring";
583 else if ( DecType == 2 )
584 pAlgoName =
"bi-decomp";
585 else if ( DecType == 3 )
587 else if ( DecType == 4 )
588 pAlgoName =
"fast DSD";
589 else if ( DecType == 5 )
590 pAlgoName =
"analysis";
591 else if ( DecType == 6 )
592 pAlgoName =
"DSD ICCD'15";
595 printf(
"Applying %-10s to %8d func%s of %2d vars... ",
596 pAlgoName,
p->nFuncs, (
p->nFuncs == 1 ?
"":
"s"),
p->nVars );
607 vStr = Vec_StrAlloc( 10000 );
608 vCover = Vec_IntAlloc( 1 << 16 );
609 for ( i = 0; i <
p->nFuncs; i++ )
616 printf(
"%7d : ", i );
619 nNodes += Dec_GraphNodeNum( pFForm );
622 Dec_GraphFree( pFForm );
624 Vec_IntFree( vCover );
627 else if ( DecType == 2 )
634 for ( i = 0; i <
p->nFuncs; i++ )
637 printf(
"%7d : ", i );
645 else if ( DecType == 3 )
650 for ( i = 0; i <
p->nFuncs; i++ )
653 printf(
"%7d : ", i );
661 else if ( DecType == 4 )
664 for ( i = 0; i <
p->nFuncs; i++ )
667 printf(
"%7d : ", i );
670 printf(
"%s\n", pDsd );
674 else if ( DecType == 5 )
676 for ( i = 0; i <
p->nFuncs; i++ )
679 int nSuppSize = Abc_TtSupportSize(
p->pFuncs[i],
p->nVars );
681 printf(
"%7d : ", i );
686 }
else if ( DecType == 6 )
693 for ( i = 0; i <
p->nFuncs; i++ )
696 printf(
"%7d : ", i );
699 printf(
"%s\n", pDsd[0] ? pDsd :
"NULL");
706 printf(
"AIG nodes =%9d ", nNodes );
707 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
727 if (
p == NULL )
return;
756 if (
p == NULL )
return NULL;
759 Vec_Mem_t * vTtMem = Vec_MemAllocForTTSimple( nVarNum );
760 for ( i = 0; i <
p->nFuncs; i++ )
761 Vec_MemHashInsert( vTtMem, (
word *)
p->pFuncs[i] );
781int Abc_DecTest(
char * pFileName,
int DecType,
int nVarNum,
int fVerbose )
784 printf(
"Using truth tables from file \"%s\"...\n", pFileName );
787 else if ( DecType >= 1 && DecType <= 6 )
790 printf(
"Unknown decomposition type value (%d).\n", DecType );
void Abc_TruthWriteHex(FILE *pFile, word *pTruth, int nVars)
void Abc_TtStoreLoadSaveBin(char *pFileName)
int Abc_DecTest(char *pFileName, int DecType, int nVarNum, int fVerbose)
void Abc_TruthStoreRead(char *pFileName, Abc_TtStore_t *p)
int Abc_FileSize(char *pFileName)
void Abc_TruthReadHex(word *pTruth, char *pString, int nVars)
void Abc_TtStoreLoadSave(char *pFileName)
Abc_TtStore_t * Abc_TruthStoreAlloc2(int nVars, int nFuncs, word *pBuffer)
void Abc_TruthDecTest(char *pFileName, int DecType, int nVarNum, int fVerbose)
void Abc_TruthGetParams(char *pFileName, int *pnVars, int *pnTruths)
Vec_Mem_t * Abc_TruthDecRead(char *pFileName, int nVarNum)
void Abc_TtStoreDump(char *pFileName, Vec_Mem_t *vTtMem, int nBytes)
void Abc_TtStoreWrite(char *pFileName, Abc_TtStore_t *p, int fBinary)
void Abc_TtStoreFree(Abc_TtStore_t *p, int nVarNum)
void Abc_TruthDecPerform(Abc_TtStore_t *p, int DecType, int fVerbose)
Abc_TtStore_t * Abc_TtStoreLoad(char *pFileName, int nVarNum)
Abc_TtStore_t * Abc_TruthStoreAlloc(int nVars, int nFuncs)
void Abc_TtStoreTest(char *pFileName)
char * Abc_FileRead(char *pFileName)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
struct Bdc_Par_t_ Bdc_Par_t
struct Bdc_Man_t_ Bdc_Man_t
void Bdc_ManDecPrint(Bdc_Man_t *p)
void Bdc_ManFree(Bdc_Man_t *p)
int Bdc_ManAndNum(Bdc_Man_t *p)
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
void Dau_DecTrySets(word *pInit, int nVars, int fVerbose)
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
int Dau_DsdCountAnds(char *pDsd)
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
struct Dec_Graph_t_ Dec_Graph_t
int Dsc_CountAnds(char *pDsd)
void Dsc_free_pool(word *pool)
int Dsc_Decompose(word *pTruth, const int nVarsInit, char *const pRes, word *pool)
word * Dsc_alloc_pool(int nVars)
BASIC TYPES ///.
unsigned __int64 word
DECLARATIONS ///.
char * Kit_PlaFromTruthNew(unsigned *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vStr)
void Kit_DsdNtkFree(Kit_DsdNtk_t *pNtk)
int Kit_DsdCountAigNodes(Kit_DsdNtk_t *pNtk)
struct Kit_DsdNtk_t_ Kit_DsdNtk_t
Kit_DsdNtk_t * Kit_DsdDecomposeMux(unsigned *pTruth, int nVars, int nDecMux)
void Kit_DsdPrintExpanded(Kit_DsdNtk_t *pNtk)
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
#define Vec_MemForEachEntry(p, pEntry, i)
MACRO DEFINITIONS ///.