abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcDec.c File Reference
#include "misc/extra/extra.h"
#include "misc/vec/vec.h"
#include "bool/bdc/bdc.h"
#include "bool/dec/dec.h"
#include "bool/kit/kit.h"
#include "opt/dau/dau.h"
#include "misc/util/utilTruth.h"

Go to the source code of this file.

Data Structures

struct  Abc_TtStore_t_
 

Typedefs

typedef
typedefABC_NAMESPACE_IMPL_START
struct Abc_TtStore_t_ 
Abc_TtStore_t
 DECLARATIONS ///. More...
 

Functions

static int Abc_TruthGetBit (word *p, int i)
 
static void Abc_TruthSetBit (word *p, int i)
 
static void Abc_TruthXorBit (word *p, int i)
 
static int Abc_TruthGetHex (word *p, int k)
 
static void Abc_TruthSetHex (word *p, int k, int d)
 
static void Abc_TruthXorHex (word *p, int k, int d)
 
static int Abc_TruthReadHexDigit (char HexChar)
 FUNCTION DEFINITIONS ///. More...
 
static void Abc_TruthWriteHexDigit (FILE *pFile, int HexDigit)
 
void Abc_TruthReadHex (word *pTruth, char *pString, int nVars)
 
void Abc_TruthWriteHex (FILE *pFile, word *pTruth, int nVars)
 
Abc_TtStore_tAbc_TruthStoreAlloc (int nVars, int nFuncs)
 
Abc_TtStore_tAbc_TruthStoreAlloc2 (int nVars, int nFuncs, word *pBuffer)
 
void Abc_TtStoreFree (Abc_TtStore_t *p, int nVarNum)
 
int Abc_FileSize (char *pFileName)
 
char * Abc_FileRead (char *pFileName)
 
void Abc_TruthGetParams (char *pFileName, int *pnVars, int *pnTruths)
 
void Abc_TruthStoreRead (char *pFileName, Abc_TtStore_t *p)
 
void Abc_TtStoreWrite (char *pFileName, Abc_TtStore_t *p, int fBinary)
 
Abc_TtStore_tAbc_TtStoreLoad (char *pFileName, int nVarNum)
 
void Abc_TtStoreTest (char *pFileName)
 
void Abc_TruthDecPerform (Abc_TtStore_t *p, int DecType, int fVerbose)
 
void Abc_TruthDecTest (char *pFileName, int DecType, int nVarNum, int fVerbose)
 
int Abc_DecTest (char *pFileName, int DecType, int nVarNum, int fVerbose)
 

Typedef Documentation

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_TtStore_t_ Abc_TtStore_t

DECLARATIONS ///.

CFile****************************************************************

FileName [abcDec.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Procedures for testing and comparing decomposition algorithms.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abcDec.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 44 of file abcDec.c.

Function Documentation

int Abc_DecTest ( char *  pFileName,
int  DecType,
int  nVarNum,
int  fVerbose 
)

Function*************************************************************

Synopsis [Testbench for decomposition algorithms.]

Description []

SideEffects []

SeeAlso []

Definition at line 626 of file abcDec.c.

627 {
628  if ( fVerbose )
629  printf( "Using truth tables from file \"%s\"...\n", pFileName );
630  if ( DecType == 0 )
631  { if ( nVarNum < 0 ) Abc_TtStoreTest( pFileName ); }
632  else if ( DecType >= 1 && DecType <= 5 )
633  Abc_TruthDecTest( pFileName, DecType, nVarNum, fVerbose );
634  else
635  printf( "Unknown decomposition type value (%d).\n", DecType );
636  fflush( stdout );
637  return 0;
638 }
void Abc_TtStoreTest(char *pFileName)
Definition: abcDec.c:441
void Abc_TruthDecTest(char *pFileName, int DecType, int nVarNum, int fVerbose)
Definition: abcDec.c:598
char* Abc_FileRead ( char *  pFileName)

Function*************************************************************

Synopsis [Read file contents.]

Description []

SideEffects []

SeeAlso []

Definition at line 222 of file abcDec.c.

223 {
224  FILE * pFile;
225  char * pBuffer;
226  int nFileSize, RetValue;
227  pFile = fopen( pFileName, "rb" );
228  if ( pFile == NULL )
229  {
230  printf( "Cannot open file \"%s\" for reading.\n", pFileName );
231  return NULL;
232  }
233  // get the file size, in bytes
234  fseek( pFile, 0, SEEK_END );
235  nFileSize = ftell( pFile );
236  // move the file current reading position to the beginning
237  rewind( pFile );
238  // load the contents of the file into memory
239  pBuffer = (char *)malloc( nFileSize + 3 );
240  RetValue = fread( pBuffer, nFileSize, 1, pFile );
241  // add several empty lines at the end
242  // (these will be used to signal the end of parsing)
243  pBuffer[ nFileSize + 0] = '\n';
244  pBuffer[ nFileSize + 1] = '\n';
245  // terminate the string with '\0'
246  pBuffer[ nFileSize + 2] = '\0';
247  fclose( pFile );
248  return pBuffer;
249 }
char * malloc()
#define SEEK_END
Definition: zconf.h:392
VOID_HACK rewind()
int Abc_FileSize ( char *  pFileName)

Function*************************************************************

Synopsis [Read file contents.]

Description []

SideEffects []

SeeAlso []

Definition at line 194 of file abcDec.c.

195 {
196  FILE * pFile;
197  int nFileSize;
198  pFile = fopen( pFileName, "rb" );
199  if ( pFile == NULL )
200  {
201  printf( "Cannot open file \"%s\" for reading.\n", pFileName );
202  return -1;
203  }
204  // get the file size, in bytes
205  fseek( pFile, 0, SEEK_END );
206  nFileSize = ftell( pFile );
207  fclose( pFile );
208  return nFileSize;
209 }
#define SEEK_END
Definition: zconf.h:392
void Abc_TruthDecPerform ( Abc_TtStore_t p,
int  DecType,
int  fVerbose 
)

Function*************************************************************

Synopsis [Apply decomposition to the truth table.]

Description [Returns the number of AIG nodes.]

SideEffects []

SeeAlso []

Definition at line 471 of file abcDec.c.

472 {
473  abctime clk = Abc_Clock();
474  int i, nNodes = 0;
475 
476  char * pAlgoName = NULL;
477  if ( DecType == 1 )
478  pAlgoName = "factoring";
479  else if ( DecType == 2 )
480  pAlgoName = "bi-decomp";
481  else if ( DecType == 3 )
482  pAlgoName = "DSD";
483  else if ( DecType == 4 )
484  pAlgoName = "fast DSD";
485  else if ( DecType == 5 )
486  pAlgoName = "analysis";
487 
488  if ( pAlgoName )
489  printf( "Applying %-10s to %8d func%s of %2d vars... ",
490  pAlgoName, p->nFuncs, (p->nFuncs == 1 ? "":"s"), p->nVars );
491  if ( fVerbose )
492  printf( "\n" );
493 
494  if ( DecType == 1 )
495  {
496  // perform algebraic factoring and count AIG nodes
497  Dec_Graph_t * pFForm;
498  Vec_Int_t * vCover;
499  Vec_Str_t * vStr;
500  char * pSopStr;
501  vStr = Vec_StrAlloc( 10000 );
502  vCover = Vec_IntAlloc( 1 << 16 );
503  for ( i = 0; i < p->nFuncs; i++ )
504  {
505 // extern int Abc_IsopTest( word * pFunc, int nVars, Vec_Int_t * vCover );
506 // if ( i == 0 ) printf( "\n" );
507 // Abc_IsopTest( p->pFuncs[i], p->nVars, vCover );
508 // continue;
509  if ( fVerbose )
510  printf( "%7d : ", i );
511  pSopStr = Kit_PlaFromTruthNew( (unsigned *)p->pFuncs[i], p->nVars, vCover, vStr );
512  pFForm = Dec_Factor( pSopStr );
513  nNodes += Dec_GraphNodeNum( pFForm );
514  if ( fVerbose )
515  Dec_GraphPrint( stdout, pFForm, NULL, NULL );
516  Dec_GraphFree( pFForm );
517  }
518  Vec_IntFree( vCover );
519  Vec_StrFree( vStr );
520  }
521  else if ( DecType == 2 )
522  {
523  // perform bi-decomposition and count AIG nodes
524  Bdc_Man_t * pManDec;
525  Bdc_Par_t Pars = {0}, * pPars = &Pars;
526  pPars->nVarsMax = p->nVars;
527  pManDec = Bdc_ManAlloc( pPars );
528  for ( i = 0; i < p->nFuncs; i++ )
529  {
530  if ( fVerbose )
531  printf( "%7d : ", i );
532  Bdc_ManDecompose( pManDec, (unsigned *)p->pFuncs[i], NULL, p->nVars, NULL, 1000 );
533  nNodes += Bdc_ManAndNum( pManDec );
534  if ( fVerbose )
535  Bdc_ManDecPrint( pManDec );
536  }
537  Bdc_ManFree( pManDec );
538  }
539  else if ( DecType == 3 )
540  {
541  // perform disjoint-support decomposition and count AIG nodes
542  // (non-DSD blocks are decomposed into 2:1 MUXes, each counting as 3 AIG nodes)
543  Kit_DsdNtk_t * pNtk;
544  for ( i = 0; i < p->nFuncs; i++ )
545  {
546  if ( fVerbose )
547  printf( "%7d : ", i );
548  pNtk = Kit_DsdDecomposeMux( (unsigned *)p->pFuncs[i], p->nVars, 3 );
549  if ( fVerbose )
550  Kit_DsdPrintExpanded( pNtk ), printf( "\n" );
551  nNodes += Kit_DsdCountAigNodes( pNtk );
552  Kit_DsdNtkFree( pNtk );
553  }
554  }
555  else if ( DecType == 4 )
556  {
557  char pDsd[DAU_MAX_STR];
558  for ( i = 0; i < p->nFuncs; i++ )
559  {
560  if ( fVerbose )
561  printf( "%7d : ", i );
562  Dau_DsdDecompose( p->pFuncs[i], p->nVars, 0, 1, pDsd );
563  if ( fVerbose )
564  printf( "%s\n", pDsd );
565  nNodes += Dau_DsdCountAnds( pDsd );
566  }
567  }
568  else if ( DecType == 5 )
569  {
570  for ( i = 0; i < p->nFuncs; i++ )
571  {
572  extern void Dau_DecTrySets( word * pInit, int nVars, int fVerbose );
573  int nSuppSize = Abc_TtSupportSize( p->pFuncs[i], p->nVars );
574  if ( fVerbose )
575  printf( "%7d : ", i );
576  Dau_DecTrySets( p->pFuncs[i], nSuppSize, fVerbose );
577  if ( fVerbose )
578  printf( "\n" );
579  }
580  }
581  else assert( 0 );
582 
583  printf( "AIG nodes =%9d ", nNodes );
584  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
585 }
void Bdc_ManDecPrint(Bdc_Man_t *p)
Definition: bdcCore.c:260
static int Dec_GraphNodeNum(Dec_Graph_t *pGraph)
Definition: dec.h:421
int nVarsMax
Definition: bdc.h:48
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
char * Kit_PlaFromTruthNew(unsigned *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vStr)
Definition: kitPla.c:406
word ** pFuncs
Definition: luckyInt.h:70
Kit_DsdNtk_t * Kit_DsdDecomposeMux(unsigned *pTruth, int nVars, int nDecMux)
Definition: kitDsd.c:2350
Bdc_Man_t * Bdc_ManAlloc(Bdc_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition: bdcCore.c:68
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
Definition: dauDsd.c:1912
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition: decFactor.c:55
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
int Bdc_ManDecompose(Bdc_Man_t *p, unsigned *puFunc, unsigned *puCare, int nVars, Vec_Ptr_t *vDivs, int nNodesMax)
Definition: bdcCore.c:291
static abctime Abc_Clock()
Definition: abc_global.h:279
int Kit_DsdCountAigNodes(Kit_DsdNtk_t *pNtk)
Definition: kitDsd.c:1895
void Dau_DecTrySets(word *pInit, int nVars, int fVerbose)
Definition: dauNonDsd.c:831
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
#define DAU_MAX_STR
Definition: dau.h:43
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition: decPrint.c:49
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int Bdc_ManAndNum(Bdc_Man_t *p)
Definition: bdcCore.c:49
Definition: bdc.h:45
static int Abc_TtSupportSize(word *t, int nVars)
Definition: utilTruth.h:986
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
void Kit_DsdNtkFree(Kit_DsdNtk_t *pNtk)
Definition: kitDsd.c:163
#define assert(ex)
Definition: util_old.h:213
void Bdc_ManFree(Bdc_Man_t *p)
Definition: bdcCore.c:113
int Dau_DsdCountAnds(char *pDsd)
Definition: dauDsd.c:316
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
void Kit_DsdPrintExpanded(Kit_DsdNtk_t *pNtk)
Definition: kitDsd.c:471
void Abc_TruthDecTest ( char *  pFileName,
int  DecType,
int  nVarNum,
int  fVerbose 
)

Function*************************************************************

Synopsis [Apply decomposition to truth tables.]

Description []

SideEffects []

SeeAlso []

Definition at line 598 of file abcDec.c.

599 {
600  Abc_TtStore_t * p;
601 
602  // allocate data-structure
603  p = Abc_TtStoreLoad( pFileName, nVarNum );
604  if ( p == NULL ) return;
605 
606  // consider functions from the file
607  Abc_TruthDecPerform( p, DecType, fVerbose );
608 
609  // delete data-structure
610  Abc_TtStoreFree( p, nVarNum );
611 // printf( "Finished decomposing truth tables from file \"%s\".\n", pFileName );
612 }
void Abc_TtStoreFree(Abc_TtStore_t *p, int nVarNum)
Definition: abcDec.c:175
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Abc_TtStore_t * Abc_TtStoreLoad(char *pFileName, int nVarNum)
Definition: abcDec.c:395
void Abc_TruthDecPerform(Abc_TtStore_t *p, int DecType, int fVerbose)
Definition: abcDec.c:471
static int Abc_TruthGetBit ( word p,
int  i 
)
inlinestatic

Definition at line 54 of file abcDec.c.

54 { return (int)(p[i>>6] >> (i & 63)) & 1; }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Abc_TruthGetHex ( word p,
int  k 
)
inlinestatic

Definition at line 59 of file abcDec.c.

59 { return (int)(p[k>>4] >> ((k<<2) & 63)) & 15; }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Abc_TruthGetParams ( char *  pFileName,
int *  pnVars,
int *  pnTruths 
)

Function*************************************************************

Synopsis [Determine the number of variables by reading the first line.]

Description [Determine the number of functions by counting the lines.]

SideEffects []

SeeAlso []

Definition at line 262 of file abcDec.c.

263 {
264  char * pContents;
265  int i, nVars, nLines;
266  // prepare the output
267  if ( pnVars )
268  *pnVars = 0;
269  if ( pnTruths )
270  *pnTruths = 0;
271  // read data from file
272  pContents = Abc_FileRead( pFileName );
273  if ( pContents == NULL )
274  return;
275  // count the number of symbols before the first space or new-line
276  // (note that on Windows symbols '\r' can be inserted before each '\n')
277  for ( i = 0; pContents[i]; i++ )
278  if ( pContents[i] == ' ' || pContents[i] == '\n' || pContents[i] == '\r' )
279  break;
280  if ( pContents[i] == 0 )
281  printf( "Strange, the input file does not have spaces and new-lines...\n" );
282 
283  // acount for the fact that truth tables may have "0x" at the beginning of each line
284  if ( pContents[0] == '0' && pContents[1] == 'x' )
285  i = i - 2;
286 
287  // determine the number of variables
288  for ( nVars = 0; nVars < 32; nVars++ )
289  if ( 4 * i == (1 << nVars) ) // the number of bits equal to the size of truth table
290  break;
291  if ( nVars < 2 || nVars > 16 )
292  {
293  printf( "Does not look like the input file contains truth tables...\n" );
294  return;
295  }
296  if ( pnVars )
297  *pnVars = nVars;
298 
299  // determine the number of functions by counting the lines
300  nLines = 0;
301  for ( i = 0; pContents[i]; i++ )
302  nLines += (pContents[i] == '\n');
303  if ( pnTruths )
304  *pnTruths = nLines;
305  ABC_FREE( pContents );
306 }
char * Abc_FileRead(char *pFileName)
Definition: abcDec.c:222
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Abc_TruthReadHex ( word pTruth,
char *  pString,
int  nVars 
)

Definition at line 91 of file abcDec.c.

92 {
93  int nWords = (nVars < 7)? 1 : (1 << (nVars-6));
94  int k, Digit, nDigits = (nWords << 4);
95  char EndSymbol;
96  // skip the first 2 symbols if they are "0x"
97  if ( pString[0] == '0' && pString[1] == 'x' )
98  pString += 2;
99  // get the last symbol
100  EndSymbol = pString[nDigits];
101  // the end symbol of the TT (the one immediately following hex digits)
102  // should be one of the following: space, a new-line, or a zero-terminator
103  // (note that on Windows symbols '\r' can be inserted before each '\n')
104  assert( EndSymbol == ' ' || EndSymbol == '\n' || EndSymbol == '\r' || EndSymbol == '\0' );
105  // read hexadecimal digits in the reverse order
106  // (the last symbol in the string is the least significant digit)
107  for ( k = 0; k < nDigits; k++ )
108  {
109  Digit = Abc_TruthReadHexDigit( pString[nDigits - 1 - k] );
110  assert( Digit >= 0 && Digit < 16 );
111  Abc_TruthSetHex( pTruth, k, Digit );
112  }
113 }
static int Abc_TruthReadHexDigit(char HexChar)
FUNCTION DEFINITIONS ///.
Definition: abcDec.c:68
int nWords
Definition: abcNpn.c:127
static void Abc_TruthSetHex(word *p, int k, int d)
Definition: abcDec.c:60
#define assert(ex)
Definition: util_old.h:213
static int Abc_TruthReadHexDigit ( char  HexChar)
inlinestatic

FUNCTION DEFINITIONS ///.

Definition at line 68 of file abcDec.c.

69 {
70  if ( HexChar >= '0' && HexChar <= '9' )
71  return HexChar - '0';
72  if ( HexChar >= 'A' && HexChar <= 'F' )
73  return HexChar - 'A' + 10;
74  if ( HexChar >= 'a' && HexChar <= 'f' )
75  return HexChar - 'a' + 10;
76  assert( 0 ); // not a hexadecimal symbol
77  return -1; // return value which makes no sense
78 }
#define assert(ex)
Definition: util_old.h:213
static void Abc_TruthSetBit ( word p,
int  i 
)
inlinestatic

Definition at line 55 of file abcDec.c.

55 { p[i>>6] |= (((word)1)<<(i & 63)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Abc_TruthSetHex ( word p,
int  k,
int  d 
)
inlinestatic

Definition at line 60 of file abcDec.c.

60 { p[k>>4] |= (((word)d)<<((k<<2) & 63)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
Abc_TtStore_t* Abc_TruthStoreAlloc ( int  nVars,
int  nFuncs 
)

Function*************************************************************

Synopsis [Allocate/Deallocate storage for truth tables..]

Description []

SideEffects []

SeeAlso []

Definition at line 140 of file abcDec.c.

141 {
142  Abc_TtStore_t * p;
143  int i;
144  p = (Abc_TtStore_t *)malloc( sizeof(Abc_TtStore_t) );
145  p->nVars = nVars;
146  p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
147  p->nFuncs = nFuncs;
148  // alloc storage for 'nFuncs' truth tables as one chunk of memory
149  p->pFuncs = (word **)malloc( (sizeof(word *) + sizeof(word) * p->nWords) * p->nFuncs );
150  // assign and clean the truth table storage
151  p->pFuncs[0] = (word *)(p->pFuncs + p->nFuncs);
152  memset( p->pFuncs[0], 0, sizeof(word) * p->nWords * p->nFuncs );
153  // split it up into individual truth tables
154  for ( i = 1; i < p->nFuncs; i++ )
155  p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
156  return p;
157 }
char * memset()
char * malloc()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
word ** pFuncs
Definition: luckyInt.h:70
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
Abc_TtStore_t* Abc_TruthStoreAlloc2 ( int  nVars,
int  nFuncs,
word pBuffer 
)

Definition at line 158 of file abcDec.c.

159 {
160  Abc_TtStore_t * p;
161  int i;
162  p = (Abc_TtStore_t *)malloc( sizeof(Abc_TtStore_t) );
163  p->nVars = nVars;
164  p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
165  p->nFuncs = nFuncs;
166  // alloc storage for 'nFuncs' truth tables as one chunk of memory
167  p->pFuncs = (word **)malloc( sizeof(word *) * p->nFuncs );
168  // assign and clean the truth table storage
169  p->pFuncs[0] = pBuffer;
170  // split it up into individual truth tables
171  for ( i = 1; i < p->nFuncs; i++ )
172  p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
173  return p;
174 }
char * malloc()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
word ** pFuncs
Definition: luckyInt.h:70
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Abc_TruthStoreRead ( char *  pFileName,
Abc_TtStore_t p 
)

Function*************************************************************

Synopsis [Read truth tables from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file abcDec.c.

321 {
322  char * pContents;
323  int i, nLines;
324  pContents = Abc_FileRead( pFileName );
325  if ( pContents == NULL )
326  return;
327  // here it is assumed (without checking!) that each line of the file
328  // begins with a string of hexadecimal chars followed by space
329 
330  // the file will be read till the first empty line (pContents[i] == '\n')
331  // (note that Abc_FileRead() added several empty lines at the end of the file contents)
332  for ( nLines = i = 0; pContents[i] != '\n'; )
333  {
334  // read one line
335  Abc_TruthReadHex( p->pFuncs[nLines++], &pContents[i], p->nVars );
336  // skip till after the end-of-line symbol
337  // (note that end-of-line symbol is also skipped)
338  while ( pContents[i++] != '\n' );
339  }
340  // adjust the number of functions read
341  // (we may have allocated more storage because some lines in the file were empty)
342  assert( p->nFuncs >= nLines );
343  p->nFuncs = nLines;
344  ABC_FREE( pContents );
345 }
word ** pFuncs
Definition: luckyInt.h:70
char * Abc_FileRead(char *pFileName)
Definition: abcDec.c:222
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
void Abc_TruthReadHex(word *pTruth, char *pString, int nVars)
Definition: abcDec.c:91
void Abc_TruthWriteHex ( FILE *  pFile,
word pTruth,
int  nVars 
)

Definition at line 116 of file abcDec.c.

117 {
118  int nDigits, Digit, k;
119  nDigits = (1 << (nVars-2));
120  for ( k = 0; k < nDigits; k++ )
121  {
122  Digit = Abc_TruthGetHex( pTruth, k );
123  assert( Digit >= 0 && Digit < 16 );
124  Abc_TruthWriteHexDigit( pFile, Digit );
125  }
126 }
static void Abc_TruthWriteHexDigit(FILE *pFile, int HexDigit)
Definition: abcDec.c:81
#define assert(ex)
Definition: util_old.h:213
static int Abc_TruthGetHex(word *p, int k)
Definition: abcDec.c:59
static void Abc_TruthWriteHexDigit ( FILE *  pFile,
int  HexDigit 
)
inlinestatic

Definition at line 81 of file abcDec.c.

82 {
83  assert( HexDigit >= 0 && HexDigit < 16 );
84  if ( HexDigit < 10 )
85  fprintf( pFile, "%d", HexDigit );
86  else
87  fprintf( pFile, "%c", 'A' + HexDigit-10 );
88 }
#define assert(ex)
Definition: util_old.h:213
static void Abc_TruthXorBit ( word p,
int  i 
)
inlinestatic

Definition at line 56 of file abcDec.c.

56 { p[i>>6] ^= (((word)1)<<(i & 63)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Abc_TruthXorHex ( word p,
int  k,
int  d 
)
inlinestatic

Definition at line 61 of file abcDec.c.

61 { p[k>>4] ^= (((word)d)<<((k<<2) & 63)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Abc_TtStoreFree ( Abc_TtStore_t p,
int  nVarNum 
)

Definition at line 175 of file abcDec.c.

176 {
177  if ( nVarNum >= 0 )
178  ABC_FREE( p->pFuncs[0] );
179  ABC_FREE( p->pFuncs );
180  ABC_FREE( p );
181 }
word ** pFuncs
Definition: luckyInt.h:70
#define ABC_FREE(obj)
Definition: abc_global.h:232
Abc_TtStore_t* Abc_TtStoreLoad ( char *  pFileName,
int  nVarNum 
)

Function*************************************************************

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 395 of file abcDec.c.

396 {
397  Abc_TtStore_t * p;
398  if ( nVarNum < 0 )
399  {
400  int nVars, nTruths;
401  // figure out how many truth table and how many variables
402  Abc_TruthGetParams( pFileName, &nVars, &nTruths );
403  if ( nVars < 2 || nVars > 16 || nTruths == 0 )
404  return NULL;
405  // allocate data-structure
406  p = Abc_TruthStoreAlloc( nVars, nTruths );
407  // read info from file
408  Abc_TruthStoreRead( pFileName, p );
409  }
410  else
411  {
412  char * pBuffer;
413  int nFileSize = Abc_FileSize( pFileName );
414  int nBytes = (1 << (nVarNum-3));
415  int nTruths = nFileSize / nBytes;
416  if ( nFileSize == -1 )
417  return NULL;
418  assert( nVarNum >= 6 );
419  if ( nFileSize % nBytes != 0 )
420  Abc_Print( 0, "The file size (%d) is divided by the truth table size (%d) with remainder (%d).\n",
421  nFileSize, nBytes, nFileSize % nBytes );
422  // read file contents
423  pBuffer = Abc_FileRead( pFileName );
424  // allocate data-structure
425  p = Abc_TruthStoreAlloc2( nVarNum, nTruths, (word *)pBuffer );
426  }
427  return p;
428 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Abc_TtStore_t * Abc_TruthStoreAlloc2(int nVars, int nFuncs, word *pBuffer)
Definition: abcDec.c:158
void Abc_TruthGetParams(char *pFileName, int *pnVars, int *pnTruths)
Definition: abcDec.c:262
Abc_TtStore_t * Abc_TruthStoreAlloc(int nVars, int nFuncs)
Definition: abcDec.c:140
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
char * Abc_FileRead(char *pFileName)
Definition: abcDec.c:222
void Abc_TruthStoreRead(char *pFileName, Abc_TtStore_t *p)
Definition: abcDec.c:320
int Abc_FileSize(char *pFileName)
Definition: abcDec.c:194
#define assert(ex)
Definition: util_old.h:213
void Abc_TtStoreTest ( char *  pFileName)

Function*************************************************************

Synopsis [Read truth tables from input file and write them into output file.]

Description []

SideEffects []

SeeAlso []

Definition at line 441 of file abcDec.c.

442 {
443  Abc_TtStore_t * p;
444  char * pFileInput = pFileName;
445  char * pFileOutput = "out.txt";
446 
447  // read info from file
448  p = Abc_TtStoreLoad( pFileInput, -1 );
449  if ( p == NULL )
450  return;
451 
452  // write into another file
453  Abc_TtStoreWrite( pFileOutput, p, 0 );
454 
455  // delete data-structure
456  Abc_TtStoreFree( p, -1 );
457  printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
458 }
void Abc_TtStoreWrite(char *pFileName, Abc_TtStore_t *p, int fBinary)
Definition: abcDec.c:358
void Abc_TtStoreFree(Abc_TtStore_t *p, int nVarNum)
Definition: abcDec.c:175
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Abc_TtStore_t * Abc_TtStoreLoad(char *pFileName, int nVarNum)
Definition: abcDec.c:395
void Abc_TtStoreWrite ( char *  pFileName,
Abc_TtStore_t p,
int  fBinary 
)

Function*************************************************************

Synopsis [Write truth tables into file.]

Description []

SideEffects []

SeeAlso []

Definition at line 358 of file abcDec.c.

359 {
360  FILE * pFile;
361  char pBuffer[1000];
362  int i, nBytes = 8 * Abc_Truth6WordNum( p->nVars );
363  pFile = fopen( pFileName, "wb" );
364  if ( pFile == NULL )
365  {
366  printf( "Cannot open file \"%s\" for writing.\n", pFileName );
367  return;
368  }
369  for ( i = 0; i < p->nFuncs; i++ )
370  {
371  if ( fBinary )
372  fwrite( p->pFuncs[i], nBytes, 1, pFile );
373  else
374  {
375  Abc_TruthWriteHex( pFile, p->pFuncs[i], p->nVars ), fprintf( pFile, " " );
376  Dau_DsdDecompose( p->pFuncs[i], p->nVars, 0, (int)(p->nVars <= 10), pBuffer );
377  fprintf( pFile, "%s\n", pBuffer );
378  }
379  }
380  fclose( pFile );
381 }
word ** pFuncs
Definition: luckyInt.h:70
static int Abc_Truth6WordNum(int nVars)
Definition: abc_global.h:257
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
Definition: dauDsd.c:1912
void Abc_TruthWriteHex(FILE *pFile, word *pTruth, int nVars)
Definition: abcDec.c:116