abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcGen.c File Reference
#include "base/abc/abc.h"
#include "aig/aig/aig.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Abc_WriteFullAdder (FILE *pFile)
 DECLARATIONS ///. More...
 
void Abc_WriteAdder (FILE *pFile, int nVars)
 
void Abc_GenAdder (char *pFileName, int nVars)
 
void Abc_WriteMulti (FILE *pFile, int nVars)
 
void Abc_GenMulti (char *pFileName, int nVars)
 
void Abc_WriteComp (FILE *pFile)
 
void Abc_WriteLayer (FILE *pFile, int nVars, int fSkip1)
 
void Abc_GenSorter (char *pFileName, int nVars)
 
void Abc_WriteCell (FILE *pFile)
 
void Abc_GenMesh (char *pFileName, int nVars)
 
void Abc_WriteKLut (FILE *pFile, int nLutSize)
 
void Abc_GenFpga (char *pFileName, int nLutSize, int nLuts, int nVars)
 
void Abc_GenOneHot (char *pFileName, int nVars)
 
void Abc_GenOneHotIntervals (char *pFileName, int nPis, int nRegs, Vec_Ptr_t *vOnehots)
 
ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START void 
Abc_GenRandom (char *pFileName, int nPis)
 
void Abc_GenFsmCond (Vec_Str_t *vCond, int nPis, int Prob)
 
void Abc_GenFsm (char *pFileName, int nPis, int nPos, int nStates, int nLines, int ProbI, int ProbO)
 

Function Documentation

void Abc_GenAdder ( char *  pFileName,
int  nVars 
)

Definition at line 95 of file abcGen.c.

96 {
97  FILE * pFile;
98  assert( nVars > 0 );
99  pFile = fopen( pFileName, "w" );
100  fprintf( pFile, "# %d-bit ripple-carry adder generated by ABC on %s\n", nVars, Extra_TimeStamp() );
101  Abc_WriteAdder( pFile, nVars );
102  fclose( pFile );
103 }
void Abc_WriteAdder(FILE *pFile, int nVars)
Definition: abcGen.c:62
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
void Abc_GenFpga ( char *  pFileName,
int  nLutSize,
int  nLuts,
int  nVars 
)

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

Synopsis [Generates structure of L K-LUTs implementing an N-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 459 of file abcGen.c.

460 {
461  int fGenerateFunc = 1;
462  FILE * pFile;
463  int nVarsLut = (1 << nLutSize); // the number of LUT variables
464  int nVarsLog = Abc_Base2Log( nVars + nLuts - 1 ); // the number of encoding vars
465  int nVarsDeg = (1 << nVarsLog); // the number of LUT variables (total)
466  int nParsLut = nLuts * (1 << nLutSize); // the number of LUT params
467  int nParsVar = nLuts * nLutSize * nVarsLog; // the number of var params
468  int i, j, k;
469 
470  assert( nVars > 0 );
471 
472  pFile = fopen( pFileName, "w" );
473  fprintf( pFile, "# Structure with %d %d-LUTs for %d-var function generated by ABC on %s\n", nLuts, nLutSize, nVars, Extra_TimeStamp() );
474  fprintf( pFile, ".model struct%dx%d_%d\n", nLuts, nLutSize, nVars );
475 
476  fprintf( pFile, ".inputs" );
477  for ( i = 0; i < nParsLut; i++ )
478  {
479 // if ( i % (1 << nLutSize) == 0 && i != (nLuts - 1) * (1 << nLutSize) )
480 // continue;
481  fprintf( pFile, " pl%02d", i );
482  }
483  fprintf( pFile, "\n" );
484 
485  fprintf( pFile, ".inputs" );
486  for ( i = 0; i < nParsVar; i++ )
487  fprintf( pFile, " pv%02d", i );
488  fprintf( pFile, "\n" );
489 
490  fprintf( pFile, ".inputs" );
491  for ( i = 0; i < nVars; i++ )
492  fprintf( pFile, " v%02d", i );
493  fprintf( pFile, "\n" );
494 
495  fprintf( pFile, ".outputs" );
496 // fprintf( pFile, " v%02d", nVars + nLuts - 1 );
497  fprintf( pFile, " out" );
498  fprintf( pFile, "\n" );
499  fprintf( pFile, ".names Gnd\n" );
500  fprintf( pFile, " 0\n" );
501 
502  // generate function
503  if ( fGenerateFunc )
504  {
505  fprintf( pFile, ".names v%02d func out\n", nVars + nLuts - 1 );
506  fprintf( pFile, "00 1\n11 1\n" );
507  fprintf( pFile, ".names" );
508  for ( i = 0; i < nVars; i++ )
509  fprintf( pFile, " v%02d", i );
510  fprintf( pFile, " func\n" );
511  for ( i = 0; i < nVars; i++ )
512  fprintf( pFile, "1" );
513  fprintf( pFile, " 1\n" );
514  }
515  else
516  fprintf( pFile, ".names v%02d out\n1 1\n", nVars + nLuts - 1 );
517 
518  // generate LUTs
519  for ( i = 0; i < nLuts; i++ )
520  {
521  fprintf( pFile, ".subckt lut%d", nLutSize );
522  // generate config parameters
523  for ( k = 0; k < nVarsLut; k++ )
524  fprintf( pFile, " p%02d=pl%02d", k, i * nVarsLut + k );
525  // generate the inputs
526  for ( k = 0; k < nLutSize; k++ )
527  fprintf( pFile, " i%d=s%02d", k, i * nLutSize + k );
528  // generate the output
529  fprintf( pFile, " o=v%02d", nVars + i );
530  fprintf( pFile, "\n" );
531  }
532 
533  // generate LUT inputs
534  for ( i = 0; i < nLuts; i++ )
535  {
536  for ( j = 0; j < nLutSize; j++ )
537  {
538  fprintf( pFile, ".subckt lut%d", nVarsLog );
539  // generate config parameters
540  for ( k = 0; k < nVarsDeg; k++ )
541  {
542  if ( k < nVars + nLuts - 1 && k < nVars + i )
543  fprintf( pFile, " p%02d=v%02d", k, k );
544  else
545  fprintf( pFile, " p%02d=Gnd", k );
546  }
547  // generate the inputs
548  for ( k = 0; k < nVarsLog; k++ )
549  fprintf( pFile, " i%d=pv%02d", k, (i * nLutSize + j) * nVarsLog + k );
550  // generate the output
551  fprintf( pFile, " o=s%02d", i * nLutSize + j );
552  fprintf( pFile, "\n" );
553  }
554  }
555 
556  fprintf( pFile, ".end\n" );
557  fprintf( pFile, "\n" );
558 
559  // generate LUTs
560  Abc_WriteKLut( pFile, nLutSize );
561  if ( nVarsLog != nLutSize )
562  Abc_WriteKLut( pFile, nVarsLog );
563  fclose( pFile );
564 }
void Abc_WriteKLut(FILE *pFile, int nLutSize)
Definition: abcGen.c:411
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
void Abc_GenFsm ( char *  pFileName,
int  nPis,
int  nPos,
int  nStates,
int  nLines,
int  ProbI,
int  ProbO 
)

Definition at line 744 of file abcGen.c.

745 {
746  FILE * pFile;
747  Vec_Wrd_t * vStates;
748  Vec_Str_t * vCond;
749  int i, iState, iState2;
750  int nDigits = Abc_Base10Log( nStates );
751  Aig_ManRandom( 1 );
752  vStates = Vec_WrdAlloc( nLines );
753  vCond = Vec_StrAlloc( 1000 );
754  for ( i = 0; i < nStates; )
755  {
756  iState = Aig_ManRandom( 0 ) % nStates;
757  if ( iState == i )
758  continue;
759  Vec_WrdPush( vStates, ((word)i << 32) | iState );
760  i++;
761  }
762  for ( ; i < nLines; )
763  {
764  iState = Aig_ManRandom( 0 ) % nStates;
765  iState2 = Aig_ManRandom( 0 ) % nStates;
766  if ( iState2 == iState )
767  continue;
768  Vec_WrdPush( vStates, ((word)iState << 32) | iState2 );
769  i++;
770  }
771  Vec_WrdSort( vStates, 0 );
772  // write the file
773  pFile = fopen( pFileName, "w" );
774  fprintf( pFile, "# This random FSM was generated by ABC on %s\n", Extra_TimeStamp() );
775  fprintf( pFile, "# Command line was: \"genfsm -I %d -O %d -S %d -L %d -P %d -Q %d %s\"\n", nPis, nPos, nStates, nLines, ProbI, ProbO, pFileName );
776  fprintf( pFile, "# FSM has %d inputs, %d outputs, %d states, and %d products\n", nPis, nPos, nStates, nLines );
777  fprintf( pFile, ".i %d\n", nPis );
778  fprintf( pFile, ".o %d\n", nPos );
779  fprintf( pFile, ".p %d\n", nLines );
780  fprintf( pFile, ".s %d\n", nStates );
781  for ( i = 0; i < nLines; i++ )
782  {
783  Abc_GenFsmCond( vCond, nPis, ProbI );
784  fprintf( pFile, "%s ", Vec_StrArray(vCond) );
785  fprintf( pFile, "%0*d ", nDigits, (int)(Vec_WrdEntry(vStates, i) >> 32) );
786  fprintf( pFile, "%0*d ", nDigits, (int)(Vec_WrdEntry(vStates, i)) );
787  if ( nPos > 0 )
788  {
789  Abc_GenFsmCond( vCond, nPos, ProbO );
790  fprintf( pFile, "%s", Vec_StrArray(vCond) );
791  }
792  fprintf( pFile, "\n" );
793  }
794  fprintf( pFile, ".e" );
795  fprintf( pFile, "\n" );
796  fclose( pFile );
797  Vec_WrdFree( vStates );
798  Vec_StrFree( vCond );
799 }
void Abc_GenFsmCond(Vec_Str_t *vCond, int nPis, int Prob)
Definition: abcGen.c:728
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
static void Vec_WrdPush(Vec_Wrd_t *p, word Entry)
Definition: vecWrd.h:618
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
static void Vec_WrdFree(Vec_Wrd_t *p)
Definition: vecWrd.h:260
static Vec_Wrd_t * Vec_WrdAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecWrd.h:80
static void Vec_WrdSort(Vec_Wrd_t *p, int fReverse)
Definition: vecWrd.h:1055
char * Extra_TimeStamp()
static word Vec_WrdEntry(Vec_Wrd_t *p, int i)
Definition: vecWrd.h:384
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition: vecWrd.h:42
void Abc_GenFsmCond ( Vec_Str_t vCond,
int  nPis,
int  Prob 
)

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

Synopsis [Generates structure of L K-LUTs implementing an N-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 728 of file abcGen.c.

729 {
730  int i, Rand;
731  Vec_StrClear( vCond );
732  for ( i = 0; i < nPis; i++ )
733  {
734  Rand = Aig_ManRandom( 0 );
735  if ( Rand % 100 > Prob )
736  Vec_StrPush( vCond, '-' );
737  else if ( Rand & 1 )
738  Vec_StrPush( vCond, '1' );
739  else
740  Vec_StrPush( vCond, '0' );
741  }
742  Vec_StrPush( vCond, '\0' );
743 }
static void Vec_StrClear(Vec_Str_t *p)
Definition: vecStr.h:519
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
void Abc_GenMesh ( char *  pFileName,
int  nVars 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 340 of file abcGen.c.

341 {
342  FILE * pFile;
343  int i, k;
344 
345  assert( nVars > 0 );
346 
347  pFile = fopen( pFileName, "w" );
348  fprintf( pFile, "# %dx%d mesh generated by ABC on %s\n", nVars, nVars, Extra_TimeStamp() );
349  fprintf( pFile, ".model mesh%d\n", nVars );
350 
351  for ( i = 0; i < nVars; i++ )
352  for ( k = 0; k < nVars; k++ )
353  {
354  fprintf( pFile, ".inputs" );
355  fprintf( pFile, " p%d%dx1", i, k );
356  fprintf( pFile, " p%d%dx2", i, k );
357  fprintf( pFile, " p%d%dy1", i, k );
358  fprintf( pFile, " p%d%dy2", i, k );
359  fprintf( pFile, "\n" );
360  }
361  fprintf( pFile, ".inputs" );
362  for ( i = 0; i < nVars; i++ )
363  fprintf( pFile, " v%02d v%02d", 2*i, 2*i+1 );
364  fprintf( pFile, "\n" );
365 
366  fprintf( pFile, ".outputs" );
367  fprintf( pFile, " fx00" );
368  fprintf( pFile, "\n" );
369 
370  for ( i = 0; i < nVars; i++ ) // horizontal
371  for ( k = 0; k < nVars; k++ ) // vertical
372  {
373  fprintf( pFile, ".subckt cell" );
374  fprintf( pFile, " px1=p%d%dx1", i, k );
375  fprintf( pFile, " px2=p%d%dx2", i, k );
376  fprintf( pFile, " py1=p%d%dy1", i, k );
377  fprintf( pFile, " py2=p%d%dy2", i, k );
378  if ( k == nVars - 1 )
379  fprintf( pFile, " x=v%02d", i );
380  else
381  fprintf( pFile, " x=fx%d%d", i, k+1 );
382  if ( i == nVars - 1 )
383  fprintf( pFile, " y=v%02d", nVars+k );
384  else
385  fprintf( pFile, " y=fy%d%d", i+1, k );
386  // outputs
387  fprintf( pFile, " fx=fx%d%d", i, k );
388  fprintf( pFile, " fy=fy%d%d", i, k );
389  fprintf( pFile, "\n" );
390  }
391  fprintf( pFile, ".end\n" );
392  fprintf( pFile, "\n" );
393  fprintf( pFile, "\n" );
394 
395  Abc_WriteCell( pFile );
396  fclose( pFile );
397 }
void Abc_WriteCell(FILE *pFile)
Definition: abcGen.c:306
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
void Abc_GenMulti ( char *  pFileName,
int  nVars 
)

Definition at line 159 of file abcGen.c.

160 {
161  FILE * pFile;
162  assert( nVars > 0 );
163  pFile = fopen( pFileName, "w" );
164  fprintf( pFile, "# %d-bit multiplier generated by ABC on %s\n", nVars, Extra_TimeStamp() );
165  Abc_WriteMulti( pFile, nVars );
166  fclose( pFile );
167 }
void Abc_WriteMulti(FILE *pFile, int nVars)
Definition: abcGen.c:116
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
void Abc_GenOneHot ( char *  pFileName,
int  nVars 
)

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

Synopsis [Generates structure of L K-LUTs implementing an N-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 577 of file abcGen.c.

578 {
579  FILE * pFile;
580  int i, k, Counter, nDigitsIn, nDigitsOut;
581  pFile = fopen( pFileName, "w" );
582  fprintf( pFile, "# One-hotness condition for %d vars generated by ABC on %s\n", nVars, Extra_TimeStamp() );
583  fprintf( pFile, ".model 1hot_%dvars\n", nVars );
584  fprintf( pFile, ".inputs" );
585  nDigitsIn = Abc_Base10Log( nVars );
586  for ( i = 0; i < nVars; i++ )
587  fprintf( pFile, " i%0*d", nDigitsIn, i );
588  fprintf( pFile, "\n" );
589  fprintf( pFile, ".outputs" );
590  nDigitsOut = Abc_Base10Log( nVars * (nVars - 1) / 2 );
591  for ( i = 0; i < nVars * (nVars - 1) / 2; i++ )
592  fprintf( pFile, " o%0*d", nDigitsOut, i );
593  fprintf( pFile, "\n" );
594  Counter = 0;
595  for ( i = 0; i < nVars; i++ )
596  for ( k = i+1; k < nVars; k++ )
597  {
598  fprintf( pFile, ".names i%0*d i%0*d o%0*d\n", nDigitsIn, i, nDigitsIn, k, nDigitsOut, Counter );
599  fprintf( pFile, "11 0\n" );
600  Counter++;
601  }
602  fprintf( pFile, ".end\n" );
603  fprintf( pFile, "\n" );
604  fclose( pFile );
605 }
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
static int Counter
char * Extra_TimeStamp()
void Abc_GenOneHotIntervals ( char *  pFileName,
int  nPis,
int  nRegs,
Vec_Ptr_t vOnehots 
)

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

Synopsis [Generates structure of L K-LUTs implementing an N-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 618 of file abcGen.c.

619 {
620  Vec_Int_t * vLine;
621  FILE * pFile;
622  int i, j, k, iReg1, iReg2, Counter, Counter2, nDigitsIn, nDigitsOut;
623  pFile = fopen( pFileName, "w" );
624  fprintf( pFile, "# One-hotness with %d vars and %d regs generated by ABC on %s\n", nPis, nRegs, Extra_TimeStamp() );
625  fprintf( pFile, "# Used %d intervals of 1-hot registers: { ", Vec_PtrSize(vOnehots) );
626  Counter = 0;
627  Vec_PtrForEachEntry( Vec_Int_t *, vOnehots, vLine, k )
628  {
629  fprintf( pFile, "%d ", Vec_IntSize(vLine) );
630  Counter += Vec_IntSize(vLine) * (Vec_IntSize(vLine) - 1) / 2;
631  }
632  fprintf( pFile, "}\n" );
633  fprintf( pFile, ".model 1hot_%dvars_%dregs\n", nPis, nRegs );
634  fprintf( pFile, ".inputs" );
635  nDigitsIn = Abc_Base10Log( nPis+nRegs );
636  for ( i = 0; i < nPis+nRegs; i++ )
637  fprintf( pFile, " i%0*d", nDigitsIn, i );
638  fprintf( pFile, "\n" );
639  fprintf( pFile, ".outputs" );
640  nDigitsOut = Abc_Base10Log( Counter );
641  for ( i = 0; i < Counter; i++ )
642  fprintf( pFile, " o%0*d", nDigitsOut, i );
643  fprintf( pFile, "\n" );
644  Counter2 = 0;
645  Vec_PtrForEachEntry( Vec_Int_t *, vOnehots, vLine, k )
646  {
647  Vec_IntForEachEntry( vLine, iReg1, i )
648  Vec_IntForEachEntryStart( vLine, iReg2, j, i+1 )
649  {
650  fprintf( pFile, ".names i%0*d i%0*d o%0*d\n", nDigitsIn, nPis+iReg1, nDigitsIn, nPis+iReg2, nDigitsOut, Counter2 );
651  fprintf( pFile, "11 0\n" );
652  Counter2++;
653  }
654  }
655  assert( Counter == Counter2 );
656  fprintf( pFile, ".end\n" );
657  fprintf( pFile, "\n" );
658  fclose( pFile );
659 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
static int Counter
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition: vecInt.h:56
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
char * Extra_TimeStamp()
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START void Abc_GenRandom ( char *  pFileName,
int  nPis 
)

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

Synopsis [Generates structure of L K-LUTs implementing an N-var function.]

Description []

SideEffects []

SeeAlso []

Definition at line 679 of file abcGen.c.

680 {
681  FILE * pFile;
682  unsigned * pTruth;
683  int i, b, w, nWords = Abc_TruthWordNum( nPis );
684  int nDigitsIn;
685  Aig_ManRandom( 1 );
686  pTruth = ABC_ALLOC( unsigned, nWords );
687  for ( w = 0; w < nWords; w++ )
688  pTruth[w] = Aig_ManRandom( 0 );
689  pFile = fopen( pFileName, "w" );
690  fprintf( pFile, "# Random function with %d inputs generated by ABC on %s\n", nPis, Extra_TimeStamp() );
691  fprintf( pFile, ".model rand%d\n", nPis );
692  fprintf( pFile, ".inputs" );
693  nDigitsIn = Abc_Base10Log( nPis );
694  for ( i = 0; i < nPis; i++ )
695  fprintf( pFile, " i%0*d", nDigitsIn, i );
696  fprintf( pFile, "\n" );
697  fprintf( pFile, ".outputs f\n" );
698  fprintf( pFile, ".names" );
699  nDigitsIn = Abc_Base10Log( nPis );
700  for ( i = 0; i < nPis; i++ )
701  fprintf( pFile, " i%0*d", nDigitsIn, i );
702  fprintf( pFile, " f\n" );
703  for ( i = 0; i < (1<<nPis); i++ )
704  if ( Abc_InfoHasBit(pTruth, i) )
705  {
706  for ( b = nPis-1; b >= 0; b-- )
707  fprintf( pFile, "%d", (i>>b)&1 );
708  fprintf( pFile, " 1\n" );
709  }
710  fprintf( pFile, ".end\n" );
711  fprintf( pFile, "\n" );
712  fclose( pFile );
713  ABC_FREE( pTruth );
714 }
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
static int Abc_TruthWordNum(int nVars)
Definition: abc_global.h:256
int nWords
Definition: abcNpn.c:127
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
char * Extra_TimeStamp()
void Abc_GenSorter ( char *  pFileName,
int  nVars 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 235 of file abcGen.c.

236 {
237  FILE * pFile;
238  int i, k, Counter, nDigits;
239 
240  assert( nVars > 1 );
241 
242  pFile = fopen( pFileName, "w" );
243  fprintf( pFile, "# %d-bit sorter generated by ABC on %s\n", nVars, Extra_TimeStamp() );
244  fprintf( pFile, ".model Sorter%02d\n", nVars );
245 
246  fprintf( pFile, ".inputs" );
247  for ( i = 0; i < nVars; i++ )
248  fprintf( pFile, " x%02d", i );
249  fprintf( pFile, "\n" );
250 
251  fprintf( pFile, ".outputs" );
252  for ( i = 0; i < nVars; i++ )
253  fprintf( pFile, " y%02d", i );
254  fprintf( pFile, "\n" );
255 
256  Counter = 0;
257  nDigits = Abc_Base10Log( (nVars-2)*nVars );
258  if ( nVars == 2 )
259  fprintf( pFile, ".subckt Comp a=x00 b=x01 x=y00 y=y01\n" );
260  else
261  {
262  fprintf( pFile, ".subckt Layer0" );
263  for ( k = 0; k < nVars; k++ )
264  fprintf( pFile, " x%02d=x%02d", k, k );
265  for ( k = 0; k < nVars; k++ )
266  fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ );
267  fprintf( pFile, "\n" );
268  Counter -= nVars;
269  for ( i = 1; i < 2*nVars-2; i++ )
270  {
271  fprintf( pFile, ".subckt Layer%d", (i&1) );
272  for ( k = 0; k < nVars; k++ )
273  fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ );
274  for ( k = 0; k < nVars; k++ )
275  fprintf( pFile, " y%02d=%0*d", k, nDigits, Counter++ );
276  fprintf( pFile, "\n" );
277  Counter -= nVars;
278  }
279  fprintf( pFile, ".subckt Layer%d", (i&1) );
280  for ( k = 0; k < nVars; k++ )
281  fprintf( pFile, " x%02d=%0*d", k, nDigits, Counter++ );
282  for ( k = 0; k < nVars; k++ )
283  fprintf( pFile, " y%02d=y%02d", k, k );
284  fprintf( pFile, "\n" );
285  }
286  fprintf( pFile, ".end\n" );
287  fprintf( pFile, "\n" );
288 
289  Abc_WriteLayer( pFile, nVars, 0 );
290  Abc_WriteLayer( pFile, nVars, 1 );
291  Abc_WriteComp( pFile );
292  fclose( pFile );
293 }
void Abc_WriteComp(FILE *pFile)
Definition: abcGen.c:180
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
static int Counter
char * Extra_TimeStamp()
void Abc_WriteLayer(FILE *pFile, int nVars, int fSkip1)
Definition: abcGen.c:193
#define assert(ex)
Definition: util_old.h:213
void Abc_WriteAdder ( FILE *  pFile,
int  nVars 
)

Definition at line 62 of file abcGen.c.

63 {
64  int i, nDigits = Abc_Base10Log( nVars );
65 
66  assert( nVars > 0 );
67  fprintf( pFile, ".model ADD%d\n", nVars );
68 
69  fprintf( pFile, ".inputs" );
70  for ( i = 0; i < nVars; i++ )
71  fprintf( pFile, " a%0*d", nDigits, i );
72  for ( i = 0; i < nVars; i++ )
73  fprintf( pFile, " b%0*d", nDigits, i );
74  fprintf( pFile, "\n" );
75 
76  fprintf( pFile, ".outputs" );
77  for ( i = 0; i <= nVars; i++ )
78  fprintf( pFile, " s%0*d", nDigits, i );
79  fprintf( pFile, "\n" );
80 
81  fprintf( pFile, ".names c\n" );
82  if ( nVars == 1 )
83  fprintf( pFile, ".subckt FA a=a0 b=b0 cin=c s=y0 cout=s1\n" );
84  else
85  {
86  fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=c s=s%0*d cout=%0*d\n", nDigits, 0, nDigits, 0, nDigits, 0, nDigits, 0 );
87  for ( i = 1; i < nVars-1; i++ )
88  fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i );
89  fprintf( pFile, ".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=s%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i+1 );
90  }
91  fprintf( pFile, ".end\n" );
92  fprintf( pFile, "\n" );
93  Abc_WriteFullAdder( pFile );
94 }
ABC_NAMESPACE_IMPL_START void Abc_WriteFullAdder(FILE *pFile)
DECLARATIONS ///.
Definition: abcGen.c:44
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
#define assert(ex)
Definition: util_old.h:213
void Abc_WriteCell ( FILE *  pFile)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 306 of file abcGen.c.

307 {
308  fprintf( pFile, ".model cell\n" );
309  fprintf( pFile, ".inputs px1 px2 py1 py2 x y\n" );
310  fprintf( pFile, ".outputs fx fy\n" );
311  fprintf( pFile, ".names x y a\n" );
312  fprintf( pFile, "11 1\n" );
313  fprintf( pFile, ".names px1 a x nx\n" );
314  fprintf( pFile, "11- 1\n" );
315  fprintf( pFile, "0-1 1\n" );
316  fprintf( pFile, ".names py1 a y ny\n" );
317  fprintf( pFile, "11- 1\n" );
318  fprintf( pFile, "0-1 1\n" );
319  fprintf( pFile, ".names px2 nx fx\n" );
320  fprintf( pFile, "10 1\n" );
321  fprintf( pFile, "01 1\n" );
322  fprintf( pFile, ".names py2 ny fy\n" );
323  fprintf( pFile, "10 1\n" );
324  fprintf( pFile, "01 1\n" );
325  fprintf( pFile, ".end\n" );
326  fprintf( pFile, "\n" );
327 }
void Abc_WriteComp ( FILE *  pFile)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file abcGen.c.

181 {
182  fprintf( pFile, ".model Comp\n" );
183  fprintf( pFile, ".inputs a b\n" );
184  fprintf( pFile, ".outputs x y\n" );
185  fprintf( pFile, ".names a b x\n" );
186  fprintf( pFile, "11 1\n" );
187  fprintf( pFile, ".names a b y\n" );
188  fprintf( pFile, "1- 1\n" );
189  fprintf( pFile, "-1 1\n" );
190  fprintf( pFile, ".end\n" );
191  fprintf( pFile, "\n" );
192 }
ABC_NAMESPACE_IMPL_START void Abc_WriteFullAdder ( FILE *  pFile)

DECLARATIONS ///.

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

FileName [abcGen.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Procedures to generate various type of circuits.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 44 of file abcGen.c.

45 {
46  fprintf( pFile, ".model FA\n" );
47  fprintf( pFile, ".inputs a b cin\n" );
48  fprintf( pFile, ".outputs s cout\n" );
49  fprintf( pFile, ".names a b k\n" );
50  fprintf( pFile, "10 1\n" );
51  fprintf( pFile, "01 1\n" );
52  fprintf( pFile, ".names k cin s\n" );
53  fprintf( pFile, "10 1\n" );
54  fprintf( pFile, "01 1\n" );
55  fprintf( pFile, ".names a b cin cout\n" );
56  fprintf( pFile, "11- 1\n" );
57  fprintf( pFile, "1-1 1\n" );
58  fprintf( pFile, "-11 1\n" );
59  fprintf( pFile, ".end\n" );
60  fprintf( pFile, "\n" );
61 }
void Abc_WriteKLut ( FILE *  pFile,
int  nLutSize 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 411 of file abcGen.c.

412 {
413  int i, iVar, iNext, nPars = (1 << nLutSize);
414  fprintf( pFile, "\n" );
415  fprintf( pFile, ".model lut%d\n", nLutSize );
416  fprintf( pFile, ".inputs" );
417  for ( i = 0; i < nPars; i++ )
418  fprintf( pFile, " p%02d", i );
419  fprintf( pFile, "\n" );
420  fprintf( pFile, ".inputs" );
421  for ( i = 0; i < nLutSize; i++ )
422  fprintf( pFile, " i%d", i );
423  fprintf( pFile, "\n" );
424  fprintf( pFile, ".outputs o\n" );
425  fprintf( pFile, ".names n01 o\n" );
426  fprintf( pFile, "1 1\n" );
427  // write internal MUXes
428  iVar = 0;
429  iNext = 2;
430  for ( i = 1; i < nPars; i++ )
431  {
432  if ( i == iNext )
433  {
434  iNext *= 2;
435  iVar++;
436  }
437  if ( iVar == nLutSize - 1 )
438  fprintf( pFile, ".names i%d p%02d p%02d n%02d\n", iVar, 2*(i-nPars/2), 2*(i-nPars/2)+1, i );
439  else
440  fprintf( pFile, ".names i%d n%02d n%02d n%02d\n", iVar, 2*i, 2*i+1, i );
441  fprintf( pFile, "01- 1\n" );
442  fprintf( pFile, "1-1 1\n" );
443  }
444  fprintf( pFile, ".end\n" );
445  fprintf( pFile, "\n" );
446 }
void Abc_WriteLayer ( FILE *  pFile,
int  nVars,
int  fSkip1 
)

Definition at line 193 of file abcGen.c.

194 {
195  int i;
196  fprintf( pFile, ".model Layer%d\n", fSkip1 );
197  fprintf( pFile, ".inputs" );
198  for ( i = 0; i < nVars; i++ )
199  fprintf( pFile, " x%02d", i );
200  fprintf( pFile, "\n" );
201  fprintf( pFile, ".outputs" );
202  for ( i = 0; i < nVars; i++ )
203  fprintf( pFile, " y%02d", i );
204  fprintf( pFile, "\n" );
205  if ( fSkip1 )
206  {
207  fprintf( pFile, ".names x00 y00\n" );
208  fprintf( pFile, "1 1\n" );
209  i = 1;
210  }
211  else
212  i = 0;
213  for ( ; i + 1 < nVars; i += 2 )
214  fprintf( pFile, ".subckt Comp a=x%02d b=x%02d x=y%02d y=y%02d\n", i, i+1, i, i+1 );
215  if ( i < nVars )
216  {
217  fprintf( pFile, ".names x%02d y%02d\n", i, i );
218  fprintf( pFile, "1 1\n" );
219  }
220  fprintf( pFile, ".end\n" );
221  fprintf( pFile, "\n" );
222 }
void Abc_WriteMulti ( FILE *  pFile,
int  nVars 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 116 of file abcGen.c.

117 {
118  int i, k, nDigits = Abc_Base10Log( nVars ), nDigits2 = Abc_Base10Log( 2*nVars );
119 
120  assert( nVars > 0 );
121  fprintf( pFile, ".model Multi%d\n", nVars );
122 
123  fprintf( pFile, ".inputs" );
124  for ( i = 0; i < nVars; i++ )
125  fprintf( pFile, " a%0*d", nDigits, i );
126  for ( i = 0; i < nVars; i++ )
127  fprintf( pFile, " b%0*d", nDigits, i );
128  fprintf( pFile, "\n" );
129 
130  fprintf( pFile, ".outputs" );
131  for ( i = 0; i < 2*nVars; i++ )
132  fprintf( pFile, " m%0*d", nDigits2, i );
133  fprintf( pFile, "\n" );
134 
135  for ( i = 0; i < 2*nVars; i++ )
136  fprintf( pFile, ".names x%0*d_%0*d\n", nDigits, 0, nDigits2, i );
137  for ( k = 0; k < nVars; k++ )
138  {
139  for ( i = 0; i < 2 * nVars; i++ )
140  if ( i >= k && i < k + nVars )
141  fprintf( pFile, ".names b%0*d a%0*d y%0*d_%0*d\n11 1\n", nDigits, k, nDigits, i-k, nDigits, k, nDigits2, i );
142  else
143  fprintf( pFile, ".names y%0*d_%0*d\n", nDigits, k, nDigits2, i );
144  fprintf( pFile, ".subckt ADD%d", 2*nVars );
145  for ( i = 0; i < 2*nVars; i++ )
146  fprintf( pFile, " a%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
147  for ( i = 0; i < 2*nVars; i++ )
148  fprintf( pFile, " b%0*d=y%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
149  for ( i = 0; i <= 2*nVars; i++ )
150  fprintf( pFile, " s%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k+1, nDigits2, i );
151  fprintf( pFile, "\n" );
152  }
153  for ( i = 0; i < 2 * nVars; i++ )
154  fprintf( pFile, ".names x%0*d_%0*d m%0*d\n1 1\n", nDigits, k, nDigits2, i, nDigits2, i );
155  fprintf( pFile, ".end\n" );
156  fprintf( pFile, "\n" );
157  Abc_WriteAdder( pFile, 2*nVars );
158 }
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
void Abc_WriteAdder(FILE *pFile, int nVars)
Definition: abcGen.c:62
#define assert(ex)
Definition: util_old.h:213