23static inline int Abc_TruthGetBit(
word *
p,
int i ) {
return (
int)(
p[i>>6] >> (i & 63)) & 1; }
24static inline void Abc_TruthSetBit(
word *
p,
int i ) {
p[i>>6] |= (((
word)1)<<(i & 63)); }
25static inline void Abc_TruthXorBit(
word *
p,
int i ) {
p[i>>6] ^= (((
word)1)<<(i & 63)); }
28static inline int Abc_TruthGetHex(
word *
p,
int k ) {
return (
int)(
p[k>>4] >> ((k<<2) & 63)) & 15; }
29static inline void Abc_TruthSetHex(
word *
p,
int k,
int d ) {
p[k>>4] |= (((
word)d)<<((k<<2) & 63)); }
30static inline void Abc_TruthXorHex(
word *
p,
int k,
int d ) {
p[k>>4] ^= (((
word)d)<<((k<<2) & 63)); }
33static inline int Abc_TruthReadHexDigit(
char HexChar )
35 if ( HexChar >=
'0' && HexChar <=
'9' )
37 if ( HexChar >=
'A' && HexChar <=
'F' )
38 return HexChar -
'A' + 10;
39 if ( HexChar >=
'a' && HexChar <=
'f' )
40 return HexChar -
'a' + 10;
46static inline void Abc_TruthWriteHexDigit( FILE * pFile,
int HexDigit )
48 assert( HexDigit >= 0 && HexDigit < 16 );
50 fprintf( pFile,
"%d", HexDigit );
52 fprintf( pFile,
"%c",
'A' + HexDigit-10 );
58 int nWords = (nVars < 7)? 1 : (1 << (nVars-6));
59 int k, Digit, nDigits = (nVars < 7) ? (1 << (nVars-2)) : (
nWords << 4);
62 if ( pString[0] ==
'0' && pString[1] ==
'x' )
65 EndSymbol = pString[nDigits];
69 assert( EndSymbol ==
' ' || EndSymbol ==
'\n' || EndSymbol ==
'\r' || EndSymbol ==
'\0' );
72 for ( k = 0; k < nDigits; k++ )
74 Digit = Abc_TruthReadHexDigit( pString[nDigits - 1 - k] );
75 assert( Digit >= 0 && Digit < 16 );
76 Abc_TruthSetHex( pTruth, k, Digit );
83 int nDigits, Digit, k;
86 nDigits = (1 << (nVars-2));
87 for ( k = 0; k < nDigits; k++ )
89 Digit = Abc_TruthGetHex( pTruth, nDigits - 1 - k );
90 assert( Digit >= 0 && Digit < 16 );
91 Abc_TruthWriteHexDigit( pFile, Digit );
102 p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
109 for ( i = 1; i <
p->nFuncs; i++ )
110 p->pFuncs[i] =
p->pFuncs[i-1] +
p->nWords;
117 free(
p->pFuncs[0] );
129 pFile = fopen( pFileName,
"r" );
132 printf(
"Cannot open file \"%s\" for reading.\n", pFileName );
137 nFileSize = ftell( pFile );
141 pBuffer = (
char *)
malloc( nFileSize + 3 );
142 RetValue = fread( pBuffer, nFileSize, 1, pFile );
145 pBuffer[ nFileSize + 0] =
'\n';
146 pBuffer[ nFileSize + 1] =
'\n';
148 pBuffer[ nFileSize + 2] =
'\0';
158 int i, nVars, nLines;
166 if ( pContents == NULL )
170 for ( i = 0; pContents[i]; i++ )
171 if ( pContents[i] ==
' ' || pContents[i] ==
'\n' || pContents[i] ==
'\r' )
173 if ( pContents[i] == 0 )
174 printf(
"Strange, the input file does not have spaces and new-lines...\n" );
177 if ( pContents[0] ==
'0' && pContents[1] ==
'x' )
181 for ( nVars = 0; nVars < 32; nVars++ )
182 if ( 4 * i == (1 << nVars) )
184 if ( nVars < 2 || nVars > 16 )
186 printf(
"Does not look like the input file contains truth tables...\n" );
194 for ( i = 0; pContents[i]; i++ )
195 nLines += (pContents[i] ==
'\n');
215 if ( pContents == NULL )
222 for ( nLines = i = 0; pContents[i] !=
'\n'; )
228 while ( pContents[i++] !=
'\n' );
239static void Abc_TruthStoreWrite(
char * pFileName,
Abc_TtStore_t *
p )
243 pFile = fopen( pFileName,
"wb" );
246 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
249 for ( i = 0; i <
p->nFuncs; i++ )
252 fprintf( pFile,
"\n" );
261 pFile = fopen( pFileName,
"w" );
264 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
267 for ( i = 0; i <
p->nFuncs; i++ )
270 fprintf( pFile,
"\n" );
279 pFile = fopen( pFileName,
"w" );
282 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
285 for ( i = 0; i <
p->nFuncs; i++ )
287 fprintf( pFile,
"0" );
288 fprintf( pFile,
"x" );
289 for ( j=
p->nWords-1; j >= 0; j-- )
291 fprintf( pFile,
"\n" );
293 fprintf( pFile,
"\n" );
300 pFile = fopen( pFileName,
"w" );
303 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
306 for ( i = 0; i <
p->nFuncs; i++ )
308 fprintf( pFile,
"0" );
309 fprintf( pFile,
"x" );
310 for ( j=
p->nWords-1; j >= 0; j-- )
312 fprintf( pFile,
"\n" );
314 fprintf( pFile,
"\n" );
void Abc_TruthWriteHex(FILE *pFile, word *pTruth, int nVars)
void Abc_TruthStoreRead(char *pFileName, Abc_TtStore_t *p)
void Abc_TruthReadHex(word *pTruth, char *pString, int nVars)
void Abc_TruthGetParams(char *pFileName, int *pnVars, int *pnTruths)
Abc_TtStore_t * Abc_TruthStoreAlloc(int nVars, int nFuncs)
char * Abc_FileRead(char *pFileName)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
unsigned __int64 word
DECLARATIONS ///.
void Abc_TruthStoreFree(Abc_TtStore_t *p)
Abc_TtStore_t * setTtStore(char *pFileInput)
for(p=first;p->value< newval;p=p->next)