abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
superAnd.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [superAnd.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Pre-computation of supergates.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - September 8, 2003.]
14 
15  Revision [$Id: superAnd.c,v 1.3 2004/06/28 14:20:25 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "superInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 // the bit masks
29 #define SUPER_MASK(n) ((~((unsigned)0)) >> (32-n))
30 #define SUPER_FULL (~((unsigned)0))
31 
32 // data structure for AND2 subgraph precomputation
33 typedef struct Super2_ManStruct_t_ Super2_Man_t; // manager
34 typedef struct Super2_LibStruct_t_ Super2_Lib_t; // library
35 typedef struct Super2_GateStruct_t_ Super2_Gate_t; // supergate
36 
38 {
39  Extra_MmFixed_t * pMem; // memory manager for all supergates
40  stmm_table * tTable; // mapping of truth tables into gates
41  int nTried; // the total number of tried
42 };
43 
45 {
46  int i; // used to iterate through the table
47  int k; // used to iterate through the table
48  int nInputs; // the number of inputs
49  int nMints; // the number of minterms
50  int nLevels; // the number of logic levels
51  int nGates; // the number of gates in the library
52  int nGatesAlloc; // the number of allocated places
53  Super2_Gate_t ** pGates; // the gates themselves
54  unsigned uMaskBit; // the mask used to determine the compl bit
55 };
56 
58 {
59  unsigned uTruth; // the truth table of this supergate
60  Super2_Gate_t * pOne; // the left wing
61  Super2_Gate_t * pTwo; // the right wing
62  Super2_Gate_t * pNext; // the next gate in the table
63 };
64 
65 
66 // manipulation of complemented attributes
67 #define Super2_IsComplement(p) (((int)((ABC_PTRUINT_T) (p) & 01)))
68 #define Super2_Regular(p) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) & ~01))
69 #define Super2_Not(p) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ 01))
70 #define Super2_NotCond(p,c) ((Super2_Gate_t *)((ABC_PTRUINT_T)(p) ^ (c)))
71 
72 // iterating through the gates in the library
73 #define Super2_LibForEachGate( Lib, Gate ) \
74  for ( Lib->i = 0; \
75  Lib->i < Lib->nGates && (Gate = Lib->pGates[Lib->i]); \
76  Lib->i++ )
77 #define Super2_LibForEachGate2( Lib, Gate2 ) \
78  for ( Lib->k = 0; \
79  Lib->k < Lib->i && (Gate2 = Lib->pGates[Lib->k]); \
80  Lib->k++ )
81 
82 // static functions
83 static Super2_Man_t * Super2_ManStart();
84 static void Super2_ManStop( Super2_Man_t * pMan );
85 static Super2_Lib_t * Super2_LibStart();
86 static Super2_Lib_t * Super2_LibDup( Super2_Lib_t * pLib );
87 static void Super2_LibStop( Super2_Lib_t * pLib );
88 static void Super2_LibAddGate( Super2_Lib_t * pLib, Super2_Gate_t * pGate );
89 static Super2_Lib_t * Super2_LibFirst( Super2_Man_t * pMan, int nInputs );
90 static Super2_Lib_t * Super2_LibCompute( Super2_Man_t * pMan, Super2_Lib_t * pLib );
91 
92 static void Super2_LibWrite( Super2_Lib_t * pLib );
93 static void Super2_LibWriteGate( FILE * pFile, Super2_Lib_t * pLib, Super2_Gate_t * pGate );
94 static char * Super2_LibWriteGate_rec( Super2_Gate_t * pGate, int fInv, int Level );
95 static int Super2_LibWriteCompare( char * pStr1, char * pStr2 );
96 static int Super2_LibCompareGates( Super2_Gate_t ** ppG1, Super2_Gate_t ** ppG2 );
97 
98 ////////////////////////////////////////////////////////////////////////
99 /// FUNCTION DEFINITIONS ///
100 ////////////////////////////////////////////////////////////////////////
101 
102 /**Function*************************************************************
103 
104  Synopsis [Precomputes the library of AND2 gates.]
105 
106  Description []
107 
108  SideEffects []
109 
110  SeeAlso []
111 
112 ***********************************************************************/
113 void Super2_Precompute( int nInputs, int nLevels, int fVerbose )
114 {
115  Super2_Man_t * pMan;
116  Super2_Lib_t * pLibCur, * pLibNext;
117  int Level;
118  abctime clk;
119 
120  assert( nInputs < 6 );
121 
122  // start the manager
123  pMan = Super2_ManStart();
124 
125  // get the starting supergates
126  pLibCur = Super2_LibFirst( pMan, nInputs );
127 
128  // perform the computation of supergates
129 printf( "Computing supergates for %d inputs and %d levels:\n", nInputs, nLevels );
130  for ( Level = 1; Level <= nLevels; Level++ )
131  {
132 clk = Abc_Clock();
133  pLibNext = Super2_LibCompute( pMan, pLibCur );
134  pLibNext->nLevels = Level;
135  Super2_LibStop( pLibCur );
136  pLibCur = pLibNext;
137 printf( "Level %d: Tried = %7d. Computed = %7d. ", Level, pMan->nTried, pLibCur->nGates );
138 ABC_PRT( "Runtime", Abc_Clock() - clk );
139 fflush( stdout );
140  }
141 
142 printf( "Writing the output file...\n" );
143 fflush( stdout );
144  // write them into a file
145  Super2_LibWrite( pLibCur );
146  Super2_LibStop( pLibCur );
147 
148  // stop the manager
149  Super2_ManStop( pMan );
150 }
151 
152 
153 
154 
155 /**Function*************************************************************
156 
157  Synopsis [Starts the manager.]
158 
159  Description []
160 
161  SideEffects []
162 
163  SeeAlso []
164 
165 ***********************************************************************/
167 {
168  Super2_Man_t * pMan;
169  pMan = ABC_ALLOC( Super2_Man_t, 1 );
170  memset( pMan, 0, sizeof(Super2_Man_t) );
171  pMan->pMem = Extra_MmFixedStart( sizeof(Super2_Gate_t) );
173  return pMan;
174 }
175 
176 /**Function*************************************************************
177 
178  Synopsis [Stops the manager.]
179 
180  Description []
181 
182  SideEffects []
183 
184  SeeAlso []
185 
186 ***********************************************************************/
188 {
189  Extra_MmFixedStop( pMan->pMem );
190  stmm_free_table( pMan->tTable );
191  ABC_FREE( pMan );
192 }
193 
194 /**Function*************************************************************
195 
196  Synopsis [Starts the library.]
197 
198  Description []
199 
200  SideEffects []
201 
202  SeeAlso []
203 
204 ***********************************************************************/
206 {
207  Super2_Lib_t * pLib;
208  pLib = ABC_ALLOC( Super2_Lib_t, 1 );
209  memset( pLib, 0, sizeof(Super2_Lib_t) );
210  return pLib;
211 }
212 
213 /**Function*************************************************************
214 
215  Synopsis [Duplicates the library.]
216 
217  Description []
218 
219  SideEffects []
220 
221  SeeAlso []
222 
223 ***********************************************************************/
225 {
226  Super2_Lib_t * pLibNew;
227  pLibNew = Super2_LibStart();
228  pLibNew->nInputs = pLib->nInputs;
229  pLibNew->nMints = pLib->nMints;
230  pLibNew->nLevels = pLib->nLevels;
231  pLibNew->nGates = pLib->nGates;
232  pLibNew->uMaskBit = pLib->uMaskBit;
233  pLibNew->nGatesAlloc = 1000 + pLib->nGatesAlloc;
234  pLibNew->pGates = ABC_ALLOC( Super2_Gate_t *, pLibNew->nGatesAlloc );
235  memcpy( pLibNew->pGates, pLib->pGates, pLibNew->nGates * sizeof(Super2_Gate_t *) );
236  return pLibNew;
237 }
238 
239 /**Function*************************************************************
240 
241  Synopsis [Add gate to the library.]
242 
243  Description []
244 
245  SideEffects []
246 
247  SeeAlso []
248 
249 ***********************************************************************/
251 {
252  if ( pLib->nGates == pLib->nGatesAlloc )
253  {
254  pLib->pGates = ABC_REALLOC( Super2_Gate_t *, pLib->pGates, 3 * pLib->nGatesAlloc );
255  pLib->nGatesAlloc *= 3;
256  }
257  pLib->pGates[ pLib->nGates++ ] = pGate;
258 }
259 
260 /**Function*************************************************************
261 
262  Synopsis [Stops the library.]
263 
264  Description []
265 
266  SideEffects []
267 
268  SeeAlso []
269 
270 ***********************************************************************/
272 {
273  ABC_FREE( pLib->pGates );
274  ABC_FREE( pLib );
275 }
276 
277 /**Function*************************************************************
278 
279  Synopsis [Derives the starting supergates.]
280 
281  Description []
282 
283  SideEffects []
284 
285  SeeAlso []
286 
287 ***********************************************************************/
288 Super2_Lib_t * Super2_LibFirst( Super2_Man_t * pMan, int nInputs )
289 {
290  Super2_Lib_t * pLib;
291  int v, m;
292 
293  // start the library
294  pLib = Super2_LibStart();
295 
296  // create the starting supergates
297  pLib->nInputs = nInputs;
298  pLib->nMints = (1 << nInputs);
299  pLib->nLevels = 0;
300  pLib->nGates = nInputs + 1;
301  pLib->nGatesAlloc = nInputs + 1;
302  pLib->uMaskBit = (1 << (pLib->nMints-1));
303  pLib->pGates = ABC_ALLOC( Super2_Gate_t *, nInputs + 1 );
304  // add the constant 0
305  pLib->pGates[0] = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
306  memset( pLib->pGates[0], 0, sizeof(Super2_Gate_t) );
307  // add the elementary gates
308  for ( v = 0; v < nInputs; v++ )
309  {
310  pLib->pGates[v+1] = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
311  memset( pLib->pGates[v+1], 0, sizeof(Super2_Gate_t) );
312  pLib->pGates[v+1]->pTwo = (Super2_Gate_t *)(ABC_PTRUINT_T)v;
313  }
314 
315  // set up their truth tables
316  for ( m = 0; m < pLib->nMints; m++ )
317  for ( v = 0; v < nInputs; v++ )
318  if ( m & (1 << v) )
319  pLib->pGates[v+1]->uTruth |= (1 << m);
320  return pLib;
321 }
322 
323 /**Function*************************************************************
324 
325  Synopsis [Precomputes one level of supergates.]
326 
327  Description []
328 
329  SideEffects []
330 
331  SeeAlso []
332 
333 ***********************************************************************/
335 {
336  Super2_Lib_t * pLibNew;
337  Super2_Gate_t * pGate1, * pGate2, * pGateNew;
338  Super2_Gate_t ** ppGate;
339  unsigned Mask = SUPER_MASK(pLib->nMints);
340  unsigned uTruth, uTruthR, uTruth1, uTruth2, uTruth1c, uTruth2c;
341 
342  // start the new library
343  pLibNew = Super2_LibDup( pLib );
344 
345  // reset the hash table
346  stmm_free_table( pMan->tTable );
348  // set the starting things into the hash table
349  Super2_LibForEachGate( pLibNew, pGate1 )
350  {
351  uTruthR = ((pGate1->uTruth & pLibNew->uMaskBit)? Mask & ~pGate1->uTruth : pGate1->uTruth);
352 
353  if ( stmm_lookup( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char **)&pGate2 ) )
354  {
355  printf( "New gate:\n" );
356  Super2_LibWriteGate( stdout, pLibNew, pGate1 );
357  printf( "Gate in the table:\n" );
358  Super2_LibWriteGate( stdout, pLibNew, pGate2 );
359  assert( 0 );
360  }
361  stmm_insert( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char *)(ABC_PTRUINT_T)pGate1 );
362  }
363 
364 
365  // set the number of gates tried
366  pMan->nTried = pLibNew->nGates;
367 
368  // go through the gate pairs
369  Super2_LibForEachGate( pLib, pGate1 )
370  {
371  if ( pLib->i && pLib->i % 300 == 0 )
372  {
373  printf( "Tried %5d first gates...\n", pLib->i );
374  fflush( stdout );
375  }
376 
377  Super2_LibForEachGate2( pLib, pGate2 )
378  {
379  uTruth1 = pGate1->uTruth;
380  uTruth2 = pGate2->uTruth;
381  uTruth1c = Mask & ~uTruth1;
382  uTruth2c = Mask & ~uTruth2;
383 
384  // none complemented
385  uTruth = uTruth1 & uTruth2;
386  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
387 
388  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
389  {
390  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
391  pGateNew->pOne = pGate1;
392  pGateNew->pTwo = pGate2;
393  pGateNew->uTruth = uTruth;
394  *ppGate = pGateNew;
395  Super2_LibAddGate( pLibNew, pGateNew );
396  }
397 
398  // one complemented
399  uTruth = uTruth1c & uTruth2;
400  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
401 
402  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
403  {
404  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
405  pGateNew->pOne = Super2_Not(pGate1);
406  pGateNew->pTwo = pGate2;
407  pGateNew->uTruth = uTruth;
408  *ppGate = pGateNew;
409  Super2_LibAddGate( pLibNew, pGateNew );
410  }
411 
412  // another complemented
413  uTruth = uTruth1 & uTruth2c;
414  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
415 
416  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
417  {
418  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
419  pGateNew->pOne = pGate1;
420  pGateNew->pTwo = Super2_Not(pGate2);
421  pGateNew->uTruth = uTruth;
422  *ppGate = pGateNew;
423  Super2_LibAddGate( pLibNew, pGateNew );
424  }
425 
426  // both complemented
427  uTruth = uTruth1c & uTruth2c;
428  uTruthR = ((uTruth & pLibNew->uMaskBit)? Mask & ~uTruth : uTruth);
429 
430  if ( !stmm_find_or_add( pMan->tTable, (char *)(ABC_PTRUINT_T)uTruthR, (char ***)&ppGate ) )
431  {
432  pGateNew = (Super2_Gate_t *)Extra_MmFixedEntryFetch( pMan->pMem );
433  pGateNew->pOne = Super2_Not(pGate1);
434  pGateNew->pTwo = Super2_Not(pGate2);
435  pGateNew->uTruth = uTruth;
436  *ppGate = pGateNew;
437  Super2_LibAddGate( pLibNew, pGateNew );
438  }
439 
440  pMan->nTried += 4;
441  }
442  }
443  return pLibNew;
444 }
445 
446 
447 static unsigned s_uMaskBit;
448 static unsigned s_uMaskAll;
449 
450 /**Function*************************************************************
451 
452  Synopsis [Writes the library into the file.]
453 
454  Description []
455 
456  SideEffects []
457 
458  SeeAlso []
459 
460 ***********************************************************************/
462 {
463  Super2_Gate_t * pGate;
464  FILE * pFile;
465  char FileName[100];
466  abctime clk;
467 
468  if ( pLib->nLevels > 5 )
469  {
470  printf( "Cannot write file for %d levels.\n", pLib->nLevels );
471  return;
472  }
473 
474 clk = Abc_Clock();
475  // sort the supergates by truth table
476  s_uMaskBit = pLib->uMaskBit;
477  s_uMaskAll = SUPER_MASK(pLib->nMints);
478  qsort( (void *)pLib->pGates, pLib->nGates, sizeof(Super2_Gate_t *),
479  (int (*)(const void *, const void *)) Super2_LibCompareGates );
480  assert( Super2_LibCompareGates( pLib->pGates, pLib->pGates + pLib->nGates - 1 ) < 0 );
481 ABC_PRT( "Sorting", Abc_Clock() - clk );
482 
483 
484  // start the file
485  sprintf( FileName, "superI%dL%d", pLib->nInputs, pLib->nLevels );
486  pFile = fopen( FileName, "w" );
487  fprintf( pFile, "# AND2/INV supergates derived on %s.\n", Extra_TimeStamp() );
488  fprintf( pFile, "# Command line: \"super2 -i %d -l %d\".\n", pLib->nInputs, pLib->nLevels );
489  fprintf( pFile, "# The number of inputs = %6d.\n", pLib->nInputs );
490  fprintf( pFile, "# The number of levels = %6d.\n", pLib->nLevels );
491  fprintf( pFile, "# The number of supergates = %6d.\n", pLib->nGates );
492  fprintf( pFile, "# The total functions = %6d.\n", (1<<(pLib->nMints-1)) );
493  fprintf( pFile, "\n" );
494  fprintf( pFile, "%6d\n", pLib->nGates );
495 
496  // print the gates
497  Super2_LibForEachGate( pLib, pGate )
498  Super2_LibWriteGate( pFile, pLib, pGate );
499  fclose( pFile );
500 
501  printf( "The supergates are written into file \"%s\" ", FileName );
502  printf( "(%0.2f MB).\n", ((double)Extra_FileSize(FileName))/(1<<20) );
503 }
504 
505 /**Function*************************************************************
506 
507  Synopsis [Writes the gate into the file.]
508 
509  Description []
510 
511  SideEffects []
512 
513  SeeAlso []
514 
515 ***********************************************************************/
517 {
518  Super2_Gate_t * pG1 = *ppG1;
519  Super2_Gate_t * pG2 = *ppG2;
520  unsigned uTruth1, uTruth2;
521 
522  uTruth1 = (pG1->uTruth & s_uMaskBit)? s_uMaskAll & ~pG1->uTruth : pG1->uTruth;
523  uTruth2 = (pG2->uTruth & s_uMaskBit)? s_uMaskAll & ~pG2->uTruth : pG2->uTruth;
524 
525  if ( uTruth1 < uTruth2 )
526  return -1;
527  return 1;
528 }
529 
530 /**Function*************************************************************
531 
532  Synopsis [Writes the gate into the file.]
533 
534  Description []
535 
536  SideEffects []
537 
538  SeeAlso []
539 
540 ***********************************************************************/
541 void Super2_LibWriteGate( FILE * pFile, Super2_Lib_t * pLib, Super2_Gate_t * pGate )
542 {
543 // unsigned uTruthR;
544  unsigned uTruth;
545  int fInv;
546 
547  // check whether the gate need complementation
548  fInv = (int)(pGate->uTruth & pLib->uMaskBit);
549  uTruth = (fInv? ~pGate->uTruth : pGate->uTruth);
550 /*
551  // reverse the truth table
552  uTruthR = 0;
553  for ( m = 0; m < pLib->nMints; m++ )
554  if ( uTruth & (1 << m) )
555  uTruthR |= (1 << (pLib->nMints-1-m));
556 */
557  // write the truth table
558  Extra_PrintBinary( pFile, &uTruth, pLib->nMints );
559  fprintf( pFile, " " );
560  // write the symbolic expression
561  fprintf( pFile, "%s", Super2_LibWriteGate_rec( pGate, fInv, pLib->nLevels ) );
562  fprintf( pFile, "\n" );
563 }
564 
565 
566 /**Function*************************************************************
567 
568  Synopsis [Recursively writes the gate into the file.]
569 
570  Description []
571 
572  SideEffects []
573 
574  SeeAlso []
575 
576 ***********************************************************************/
577 char * Super2_LibWriteGate_rec( Super2_Gate_t * pGate, int fInv, int Level )
578 {
579  static char Buff01[ 3], Buff02[ 3]; // Max0 = 1
580  static char Buff11[ 6], Buff12[ 6]; // Max1 = 2*Max0 + 2 = 4
581  static char Buff21[ 12], Buff22[ 12]; // Max2 = 2*Max1 + 2 = 10
582  static char Buff31[ 25], Buff32[ 25]; // Max3 = 2*Max2 + 2 = 22
583  static char Buff41[ 50], Buff42[ 50]; // Max4 = 2*Max3 + 2 = 46
584  static char Buff51[100], Buff52[100]; // Max5 = 2*Max4 + 2 = 94
585  static char * pBuffs1[6] = { Buff01, Buff11, Buff21, Buff31, Buff41, Buff51 };
586  static char * pBuffs2[6] = { Buff02, Buff12, Buff22, Buff32, Buff42, Buff52 };
587  char * pBranch;
588  char * pBuffer1 = pBuffs1[Level];
589  char * pBuffer2 = pBuffs2[Level];
590  Super2_Gate_t * pGateNext1, * pGateNext2;
591  int fInvNext1, fInvNext2;
592  int RetValue;
593 
594  // consider the last level
595  assert( Level >= 0 );
596  if ( pGate->pOne == NULL )
597  {
598  if ( pGate->uTruth == 0 )
599  {
600  pBuffer1[0] = (fInv? '1': '0');
601  pBuffer1[1] = '$';
602  pBuffer1[2] = 0;
603  }
604  else
605  {
606  pBuffer1[0] = (fInv? 'A' + ((int)(ABC_PTRUINT_T)pGate->pTwo): 'a' + ((int)(ABC_PTRUINT_T)pGate->pTwo));
607  pBuffer1[1] = 0;
608  }
609  return pBuffer1;
610  }
611  assert( Level > 0 );
612 
613 
614  // get the left branch
615  pGateNext1 = Super2_Regular(pGate->pOne);
616  fInvNext1 = Super2_IsComplement(pGate->pOne);
617  pBranch = Super2_LibWriteGate_rec(pGateNext1, fInvNext1, Level - 1);
618  // copy into Buffer1
619  strcpy( pBuffer1, pBranch );
620 
621  // get the right branch
622  pGateNext2 = Super2_Regular(pGate->pTwo);
623  fInvNext2 = Super2_IsComplement(pGate->pTwo);
624  pBranch = Super2_LibWriteGate_rec(pGateNext2, fInvNext2, Level - 1);
625 
626  // consider the case when comparison is not necessary
627  if ( fInvNext1 ^ fInvNext2 )
628  {
629  if ( fInvNext1 > fInvNext2 )
630  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBuffer1, pBranch, (fInv? '>': ')') );
631  else
632  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBranch, pBuffer1, (fInv? '>': ')') );
633  }
634  else
635  {
636  // compare the two branches
637  RetValue = Super2_LibWriteCompare( pBuffer1, pBranch );
638  if ( RetValue == 1 )
639  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBuffer1, pBranch, (fInv? '>': ')') );
640  else // if ( RetValue == -1 )
641  {
642  sprintf( pBuffer2, "%c%s%s%c", (fInv? '<': '('), pBranch, pBuffer1, (fInv? '>': ')') );
643  if ( RetValue == 0 )
644  printf( "Strange!\n" );
645  }
646  }
647  return pBuffer2;
648 }
649 
650 /**Function*************************************************************
651 
652  Synopsis [Compares the two branches of the tree.]
653 
654  Description []
655 
656  SideEffects []
657 
658  SeeAlso []
659 
660 ***********************************************************************/
661 int Super2_LibWriteCompare( char * pStr1, char * pStr2 )
662 {
663  while ( 1 )
664  {
665  // skip extra symbols
666  while ( *pStr1 && *pStr1 < 'A' )
667  pStr1++;
668  while ( *pStr2 && *pStr2 < 'A' )
669  pStr2++;
670 
671  // check if any one is finished
672  if ( *pStr1 == 0 || *pStr2 == 0 )
673  {
674  if ( *pStr2 )
675  return 1;
676  return -1;
677  }
678 
679  // compare
680  if ( *pStr1 == *pStr2 )
681  {
682  pStr1++;
683  pStr2++;
684  }
685  else
686  {
687  if ( *pStr1 < *pStr2 )
688  return 1;
689  return -1;
690  }
691  }
692  return 0;
693 }
694 
695 ////////////////////////////////////////////////////////////////////////
696 /// END OF FILE ///
697 ////////////////////////////////////////////////////////////////////////
698 
699 
701 
char * memset()
static unsigned s_uMaskAll
Definition: superAnd.c:448
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
#define SUPER_MASK(n)
DECLARATIONS ///.
Definition: superAnd.c:29
int stmm_insert(stmm_table *table, char *key, char *value)
Definition: stmm.c:200
void Extra_MmFixedStop(Extra_MmFixed_t *p)
void Super2_Precompute(int nInputs, int nLevels, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: superAnd.c:113
#define Super2_LibForEachGate2(Lib, Gate2)
Definition: superAnd.c:77
static unsigned s_uMaskBit
Definition: superAnd.c:447
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static Super2_Lib_t * Super2_LibDup(Super2_Lib_t *pLib)
Definition: superAnd.c:224
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned uMaskBit
Definition: superAnd.c:54
char * Extra_MmFixedEntryFetch(Extra_MmFixed_t *p)
Extra_MmFixed_t * pMem
Definition: superAnd.c:39
static char * Super2_LibWriteGate_rec(Super2_Gate_t *pGate, int fInv, int Level)
Definition: superAnd.c:577
static void Super2_LibWriteGate(FILE *pFile, Super2_Lib_t *pLib, Super2_Gate_t *pGate)
Definition: superAnd.c:541
static void Super2_LibWrite(Super2_Lib_t *pLib)
Definition: superAnd.c:461
int Extra_FileSize(char *pFileName)
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition: stmm.c:134
static Super2_Lib_t * Super2_LibCompute(Super2_Man_t *pMan, Super2_Lib_t *pLib)
Definition: superAnd.c:334
static Super2_Man_t * Super2_ManStart()
Definition: superAnd.c:166
static int Super2_LibCompareGates(Super2_Gate_t **ppG1, Super2_Gate_t **ppG2)
Definition: superAnd.c:516
static void Super2_LibAddGate(Super2_Lib_t *pLib, Super2_Gate_t *pGate)
Definition: superAnd.c:250
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Super2_Not(p)
Definition: superAnd.c:69
char * sprintf()
static void Super2_LibStop(Super2_Lib_t *pLib)
Definition: superAnd.c:271
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition: stmm.c:266
char * strcpy()
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
#define Super2_LibForEachGate(Lib, Gate)
Definition: superAnd.c:73
Super2_Gate_t * pTwo
Definition: superAnd.c:61
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
static Super2_Lib_t * Super2_LibFirst(Super2_Man_t *pMan, int nInputs)
Definition: superAnd.c:288
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
char * Extra_TimeStamp()
#define Super2_IsComplement(p)
Definition: superAnd.c:67
static void Super2_ManStop(Super2_Man_t *pMan)
Definition: superAnd.c:187
#define assert(ex)
Definition: util_old.h:213
#define Super2_Regular(p)
Definition: superAnd.c:68
static Super2_Lib_t * Super2_LibStart()
Definition: superAnd.c:205
stmm_table * tTable
Definition: superAnd.c:40
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Super2_LibWriteCompare(char *pStr1, char *pStr2)
Definition: superAnd.c:661
Super2_Gate_t ** pGates
Definition: superAnd.c:53
Super2_Gate_t * pOne
Definition: superAnd.c:60
int st__ptrhash(const char *, int)
Definition: st.c:468
Super2_Gate_t * pNext
Definition: superAnd.c:62