abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lucky.c File Reference
#include "luckyInt.h"

Go to the source code of this file.

Data Structures

struct  cycleCtr
 

Functions

ABC_NAMESPACE_IMPL_START int memCompare (word *x, word *y, int nVars)
 
int compareWords1 (const void *a, const void *b)
 
void sortAndUnique1 (word *a, Abc_TtStore_t *p)
 
int compareWords2 (const void **x, const void **y)
 
int compareWords (const void **a, const void **b)
 
int compareWords3 (const void **x, const void **y)
 
void sortAndUnique (word **a, Abc_TtStore_t *p)
 
cycleCtrsetCycleCtrPtr ()
 
void freeCycleCtr (cycleCtr *x)
 
word ** makeArray (Abc_TtStore_t *p)
 
void freeArray (word **a, Abc_TtStore_t *p)
 
wordmakeArrayB (word **a, int nFuncs)
 
void freeArrayB (word *b)
 
void printCCtrInfo (cycleCtr *cCtr, int nFuncs)
 
int minimalInitialFlip1 (word *pInOut, int nVars)
 
int minimalFlip1 (word *pInOut, word *pMinimal, word *PDuplicat, int nVars)
 
int minimalSwap1 (word *pInOut, word *pMinimal, word *PDuplicat, int nVars)
 
int minimalInitialFlip (word *pInOut, int nVars, unsigned *p_uCanonPhase)
 
int minimalFlip (word *pInOut, word *pMinimal, word *PDuplicat, int nVars, unsigned *p_uCanonPhase)
 
void swapInfoAdjacentVars (int iVar, char *pCanonPerm, unsigned *p_uCanonPhase)
 
int minimalSwap (word *pInOut, word *pMinimal, word *PDuplicat, int nVars, char *pCanonPerm, char *tempArray, unsigned *p_uCanonPhase)
 
void luckyCanonicizer (word *pInOut, word *pAux, word *pAux1, int nVars, char *pCanonPerm, char *tempArray, unsigned *p_uCanonPhase)
 
unsigned luckyCanonicizer1_simple (word *pInOut, word *pAux, word *pAux1, int nVars, char *pCanonPerm, unsigned CanonPhase)
 
void luckyCanonicizer_final (word *pInOut, word *pAux, word *pAux1, int nVars)
 
unsigned Kit_TruthSemiCanonicize_new_internal (word *pInOut, int nVars, char *pCanonPerm)
 
unsigned Kit_TruthSemiCanonicize_new (unsigned *pInOut, unsigned *pAux, int nVars, char *pCanonPerm)
 

Function Documentation

int compareWords ( const void **  a,
const void **  b 
)

Definition at line 73 of file lucky.c.

74 {
75  if( memcmp(*(word**)a,*(word**)b,sizeof(word)*1) > 0 )
76  return 1;
77  else
78  return ( memcmp(*(word**)a,*(word**)b,sizeof(word)*1) < 0 ) ? -1: 0;
79 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
int compareWords1 ( const void *  a,
const void *  b 
)

Definition at line 37 of file lucky.c.

38  {
39  if( *(word*)a > *(word*)b )
40  return 1;
41  else
42  return( *(word*)a < *(word*)b ) ? -1: 0;
43 
44  }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int compareWords2 ( const void **  x,
const void **  y 
)

Definition at line 62 of file lucky.c.

63 {
64 
65  if(**(word**)x > **(word**)y)
66  return 1;
67  else if(**(word**)x < **(word**)y)
68  return -1;
69  else
70  return 0;
71 
72 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int compareWords3 ( const void **  x,
const void **  y 
)

Definition at line 80 of file lucky.c.

81 {
82  return memCompare(*(word**)x, *(word**)y, 16);
83 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
void freeArray ( word **  a,
Abc_TtStore_t p 
)

Definition at line 133 of file lucky.c.

134 {
135  int i;
136  for(i=0;i<p->nFuncs;i++)
137  free(a[i]);
138  free(a);
139 }
VOID_HACK free()
void freeArrayB ( word b)

Definition at line 151 of file lucky.c.

152 {
153  free(b);
154 }
VOID_HACK free()
void freeCycleCtr ( cycleCtr x)

Definition at line 116 of file lucky.c.

117 {
118  free(x);
119 }
VOID_HACK free()
unsigned Kit_TruthSemiCanonicize_new ( unsigned *  pInOut,
unsigned *  pAux,
int  nVars,
char *  pCanonPerm 
)

Definition at line 611 of file lucky.c.

612 {
613  unsigned Result;
614  if ( nVars < 6 )
615  {
616  word Temp = ((word)pInOut[0] << 32) | (word)pInOut[0];
617  Result = Kit_TruthSemiCanonicize_new_internal( &Temp, nVars, pCanonPerm );
618  pInOut[0] = (unsigned)Temp;
619  }
620  else
621  Result = Kit_TruthSemiCanonicize_new_internal( (word *)pInOut, nVars, pCanonPerm );
622  return Result;
623 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
unsigned Kit_TruthSemiCanonicize_new_internal(word *pInOut, int nVars, char *pCanonPerm)
Definition: lucky.c:599
unsigned Kit_TruthSemiCanonicize_new_internal ( word pInOut,
int  nVars,
char *  pCanonPerm 
)

Definition at line 599 of file lucky.c.

600 {
601  word pAux[1024], pAux1[1024];
602  char tempArray[16];
603  unsigned CanonPhase;
604  assert( nVars <= 16 );
605  CanonPhase = Kit_TruthSemiCanonicize_Yasha( pInOut, nVars, pCanonPerm );
606  luckyCanonicizer(pInOut, pAux, pAux1, nVars, pCanonPerm, tempArray, &CanonPhase);
607  return CanonPhase;
608 }
void luckyCanonicizer(word *pInOut, word *pAux, word *pAux1, int nVars, char *pCanonPerm, char *tempArray, unsigned *p_uCanonPhase)
Definition: lucky.c:564
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define assert(ex)
Definition: util_old.h:213
unsigned Kit_TruthSemiCanonicize_Yasha(word *pInOut, int nVars, char *pCanonPerm)
Definition: luckySwap.c:186
void luckyCanonicizer ( word pInOut,
word pAux,
word pAux1,
int  nVars,
char *  pCanonPerm,
char *  tempArray,
unsigned *  p_uCanonPhase 
)

Definition at line 564 of file lucky.c.

565 {
566  int counter=1;
567  assert( nVars <= 16 );
568  while(counter>0 ) // && cycles < 10 if we wanna limit cycles
569  {
570  counter=0;
571  counter += minimalInitialFlip(pInOut, nVars, p_uCanonPhase);
572  counter += minimalFlip(pInOut, pAux, pAux1, nVars, p_uCanonPhase);
573  counter += minimalSwap(pInOut, pAux, pAux1, nVars, pCanonPerm, tempArray, p_uCanonPhase);
574  }
575 }
int minimalFlip(word *pInOut, word *pMinimal, word *PDuplicat, int nVars, unsigned *p_uCanonPhase)
Definition: lucky.c:378
int minimalSwap(word *pInOut, word *pMinimal, word *PDuplicat, int nVars, char *pCanonPerm, char *tempArray, unsigned *p_uCanonPhase)
Definition: lucky.c:475
#define assert(ex)
Definition: util_old.h:213
int minimalInitialFlip(word *pInOut, int nVars, unsigned *p_uCanonPhase)
Definition: lucky.c:362
unsigned luckyCanonicizer1_simple ( word pInOut,
word pAux,
word pAux1,
int  nVars,
char *  pCanonPerm,
unsigned  CanonPhase 
)

Definition at line 577 of file lucky.c.

578 {
579  int counter=1;
580  assert( nVars <= 16 );
581  while(counter>0 ) // && cycles < 10 if we wanna limit cycles
582  {
583  counter=0;
584  counter += minimalInitialFlip1(pInOut, nVars);
585  counter += minimalFlip1(pInOut, pAux, pAux1, nVars);
586  counter += minimalSwap1(pInOut, pAux, pAux1, nVars);
587  }
588  return CanonPhase;
589 }
int minimalFlip1(word *pInOut, word *pMinimal, word *PDuplicat, int nVars)
Definition: lucky.c:301
int minimalSwap1(word *pInOut, word *pMinimal, word *PDuplicat, int nVars)
Definition: lucky.c:332
int minimalInitialFlip1(word *pInOut, int nVars)
Definition: lucky.c:286
#define assert(ex)
Definition: util_old.h:213
void luckyCanonicizer_final ( word pInOut,
word pAux,
word pAux1,
int  nVars 
)

Definition at line 591 of file lucky.c.

592 {
593  Kit_TruthSemiCanonicize_Yasha_simple( pInOut, nVars, NULL );
594  luckyCanonicizer1_simple(pInOut, pAux, pAux1, nVars, NULL, 0);
595 }
unsigned luckyCanonicizer1_simple(word *pInOut, word *pAux, word *pAux1, int nVars, char *pCanonPerm, unsigned CanonPhase)
Definition: lucky.c:577
void Kit_TruthSemiCanonicize_Yasha_simple(word *pInOut, int nVars, int *pStore)
Definition: luckySwap.c:358
word** makeArray ( Abc_TtStore_t p)

Definition at line 120 of file lucky.c.

121 {
122  int i;
123  word** a;
124  a = (word**)malloc(sizeof(word*)*(p->nFuncs));
125  for(i=0;i<p->nFuncs;i++)
126  {
127  a[i] = (word*)malloc(sizeof(word)*(p->nWords));
128  memcpy(a[i],p->pFuncs[i],sizeof(word)*(p->nWords));
129 
130  }
131  return a;
132 }
char * malloc()
word ** pFuncs
Definition: luckyInt.h:70
char * memcpy()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
word* makeArrayB ( word **  a,
int  nFuncs 
)

Definition at line 141 of file lucky.c.

142 {
143  int i;
144  word* b;
145  b = (word*)malloc(sizeof(word)*(nFuncs));
146  for(i=0;i<nFuncs;i++)
147  b[i] = a[i][0];
148 
149  return b;
150 }
char * malloc()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
ABC_NAMESPACE_IMPL_START int memCompare ( word x,
word y,
int  nVars 
)

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

FileName [lucky.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Semi-canonical form computation package.]

Synopsis [Truth table minimization procedures.]

Author [Jake]

Date [Started - August 2012]

Definition at line 22 of file lucky.c.

23 {
24  int i;
25  for(i=Kit_TruthWordNum_64bit( nVars )-1;i>=0;i--)
26  {
27  if(x[i]==y[i])
28  continue;
29  else if(x[i]>y[i])
30  return 1;
31  else
32  return -1;
33  }
34  return 0;
35 }
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
int minimalFlip ( word pInOut,
word pMinimal,
word PDuplicat,
int  nVars,
unsigned *  p_uCanonPhase 
)

Definition at line 378 of file lucky.c.

379 {
380  int i;
381  unsigned minTemp = *p_uCanonPhase;
382  int blockSize = Kit_TruthWordNum_64bit( nVars )*sizeof(word);
383  memcpy(pMinimal, pInOut, blockSize);
384  memcpy(PDuplicat, pInOut, blockSize); //////////////need one more unsigned!!!!!!!!!!!!!
385  Kit_TruthChangePhase_64bit( pInOut, nVars, 0 );
386  *p_uCanonPhase ^= (unsigned)1;
387  for(i=1;i<nVars;i++)
388  {
389  if( memCompare(pMinimal,pInOut,nVars) == 1)
390  {
391  memcpy(pMinimal, pInOut, blockSize);
392  minTemp = *p_uCanonPhase;
393  }
394  else
395  {
396  memcpy(pInOut, pMinimal, blockSize);
397  *p_uCanonPhase = minTemp;
398  }
399  Kit_TruthChangePhase_64bit( pInOut, nVars, i );
400  *p_uCanonPhase ^= (1 << i);
401  }
402  if( memCompare(pMinimal,pInOut,nVars) == -1)
403  {
404  memcpy(pInOut, pMinimal, blockSize);
405  *p_uCanonPhase = minTemp;
406  }
407  if(memcmp(pInOut,PDuplicat,blockSize) == 0)
408  return 0;
409  else
410  return 1;
411 }
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
char * memcpy()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
void Kit_TruthChangePhase_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:100
int minimalFlip1 ( word pInOut,
word pMinimal,
word PDuplicat,
int  nVars 
)

Definition at line 301 of file lucky.c.

302 {
303  int i;
304  int blockSize = Kit_TruthWordNum_64bit( nVars )*sizeof(word);
305  memcpy(pMinimal, pInOut, blockSize);
306  memcpy(PDuplicat, pInOut, blockSize);
307  Kit_TruthChangePhase_64bit( pInOut, nVars, 0 );
308  for(i=1;i<nVars;i++)
309  {
310  if( memCompare(pMinimal,pInOut,nVars) == 1)
311  {
312  memcpy(pMinimal, pInOut, blockSize);
313  Kit_TruthChangePhase_64bit( pInOut, nVars, i );
314  }
315  else
316  {
317  memcpy(pInOut, pMinimal, blockSize);
318  Kit_TruthChangePhase_64bit( pInOut, nVars, i );
319  }
320  }
321  if( memCompare(pMinimal,pInOut,nVars) == -1)
322  memcpy(pInOut, pMinimal, blockSize);
323  if(memcmp(pInOut,PDuplicat,blockSize) == 0)
324  return 0;
325  else
326  return 1;
327 }
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
char * memcpy()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
void Kit_TruthChangePhase_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:100
int minimalInitialFlip ( word pInOut,
int  nVars,
unsigned *  p_uCanonPhase 
)

Definition at line 362 of file lucky.c.

363 {
364  word oneWord=1;
365  if( (pInOut[Kit_TruthWordNum_64bit( nVars ) -1]>>63) & oneWord )
366  {
367  Kit_TruthNot_64bit( pInOut, nVars );
368  *p_uCanonPhase ^= (1 << nVars);
369  return 1;
370  }
371  return 0;
372 }
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Kit_TruthNot_64bit(word *pIn, int nVars)
Definition: luckySwap.c:130
int minimalInitialFlip1 ( word pInOut,
int  nVars 
)

Definition at line 286 of file lucky.c.

287 {
288  word oneWord=1;
289  if( (pInOut[Kit_TruthWordNum_64bit( nVars ) -1]>>63) & oneWord )
290  {
291  Kit_TruthNot_64bit( pInOut, nVars );
292  return 1;
293  }
294  return 0;
295 }
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Kit_TruthNot_64bit(word *pIn, int nVars)
Definition: luckySwap.c:130
int minimalSwap ( word pInOut,
word pMinimal,
word PDuplicat,
int  nVars,
char *  pCanonPerm,
char *  tempArray,
unsigned *  p_uCanonPhase 
)

Definition at line 475 of file lucky.c.

476 {
477  int i;
478  int blockSizeWord = Kit_TruthWordNum_64bit( nVars )*sizeof(word);
479  int blockSizeChar = nVars *sizeof(char);
480  unsigned TempuCanonPhase = *p_uCanonPhase;
481  memcpy(pMinimal, pInOut, blockSizeWord);
482  memcpy(PDuplicat, pInOut, blockSizeWord);
483  memcpy(tempArray, pCanonPerm, blockSizeChar);
484  Kit_TruthSwapAdjacentVars_64bit( pInOut, nVars, 0 );
485  swapInfoAdjacentVars(0, pCanonPerm, p_uCanonPhase);
486  for(i=1;i<nVars-1;i++)
487  {
488  if( memCompare(pMinimal,pInOut,nVars) == 1)
489  {
490  memcpy(pMinimal, pInOut, blockSizeWord);
491  memcpy(tempArray, pCanonPerm, blockSizeChar);
492  TempuCanonPhase = *p_uCanonPhase;
493 
494  }
495  else
496  {
497  memcpy(pInOut, pMinimal, blockSizeWord);
498  memcpy(pCanonPerm, tempArray, blockSizeChar);
499  *p_uCanonPhase = TempuCanonPhase;
500  }
501  Kit_TruthSwapAdjacentVars_64bit( pInOut, nVars, i );
502  swapInfoAdjacentVars(i, pCanonPerm, p_uCanonPhase);
503  }
504  if( memCompare(pMinimal,pInOut,nVars) == -1)
505  {
506  memcpy(pInOut, pMinimal, blockSizeWord);
507  memcpy(pCanonPerm, tempArray, blockSizeChar);
508  *p_uCanonPhase = TempuCanonPhase;
509  }
510  if(memcmp(pInOut,PDuplicat,blockSizeWord) == 0)
511  return 0;
512  else
513  return 1;
514 }
void swapInfoAdjacentVars(int iVar, char *pCanonPerm, unsigned *p_uCanonPhase)
Definition: lucky.c:414
void Kit_TruthSwapAdjacentVars_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:141
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
char * memcpy()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
int minimalSwap1 ( word pInOut,
word pMinimal,
word PDuplicat,
int  nVars 
)

Definition at line 332 of file lucky.c.

333 {
334  int i;
335  int blockSize = Kit_TruthWordNum_64bit( nVars )*sizeof(word);
336  memcpy(pMinimal, pInOut, blockSize);
337  memcpy(PDuplicat, pInOut, blockSize);
338  Kit_TruthSwapAdjacentVars_64bit( pInOut, nVars, 0 );
339  for(i=1;i<nVars-1;i++)
340  {
341  if( memCompare(pMinimal,pInOut,nVars) == 1)
342  {
343  memcpy(pMinimal, pInOut, blockSize);
344  Kit_TruthSwapAdjacentVars_64bit( pInOut, nVars, i );
345  }
346  else
347  {
348  memcpy(pInOut, pMinimal, blockSize);
349  Kit_TruthSwapAdjacentVars_64bit( pInOut, nVars, i );
350  }
351  }
352  if( memCompare(pMinimal,pInOut,nVars) == -1)
353  memcpy(pInOut, pMinimal, blockSize);
354  if(memcmp(pInOut,PDuplicat,blockSize) == 0)
355  return 0;
356  else
357  return 1;
358 }
void Kit_TruthSwapAdjacentVars_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:141
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
char * memcpy()
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
void printCCtrInfo ( cycleCtr cCtr,
int  nFuncs 
)

Definition at line 276 of file lucky.c.

277 {
278  printf("maxNCycles = %d\n",cCtr->maxNCycles);
279  printf("minNCycles = %d\n",cCtr->minNCycles);
280  printf("average NCycles = %.3f\n",cCtr->totalCycles/(double)nFuncs);
281 }
int maxNCycles
Definition: lucky.c:104
int minNCycles
Definition: lucky.c:105
int totalCycles
Definition: lucky.c:103
cycleCtr* setCycleCtrPtr ( )

Definition at line 108 of file lucky.c.

109 {
110  cycleCtr* x = (cycleCtr*) malloc(sizeof(cycleCtr));
111  x->totalCycles=0;
112  x->maxNCycles=0;
113  x->minNCycles=111111111;
114  return x;
115 }
char * malloc()
int maxNCycles
Definition: lucky.c:104
int minNCycles
Definition: lucky.c:105
int totalCycles
Definition: lucky.c:103
void sortAndUnique ( word **  a,
Abc_TtStore_t p 
)

Definition at line 84 of file lucky.c.

85 {
86  int i, count=1, WordsPtrN = p->nFuncs;
87  word* tempWordPtr;
88  qsort(a,WordsPtrN,sizeof(word*),(int(*)(const void *,const void *))compareWords3);
89  tempWordPtr = a[0];
90  for(i=1;i<WordsPtrN;i++)
91  if(memcmp(a[i],tempWordPtr,sizeof(word)*(p->nWords)) != 0)
92  {
93  a[count] = a[i];
94  tempWordPtr = a[i];
95  count++;
96  }
97  p->nFuncs = count;
98 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int memcmp()
int compareWords3(const void **x, const void **y)
Definition: lucky.c:80
void sortAndUnique1 ( word a,
Abc_TtStore_t p 
)

Definition at line 46 of file lucky.c.

47  {
48  int i, count=1, WordsN = p->nFuncs;
49  word tempWord;
50  qsort(a,WordsN,sizeof(word),compareWords1);
51  tempWord = a[0];
52  for(i=1;i<WordsN;i++)
53  if(tempWord != a[i])
54  {
55  a[count] = a[i];
56  tempWord = a[i];
57  count++;
58  }
59  p->nFuncs = count;
60 }
int compareWords1(const void *a, const void *b)
Definition: lucky.c:37
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void swapInfoAdjacentVars ( int  iVar,
char *  pCanonPerm,
unsigned *  p_uCanonPhase 
)

Definition at line 414 of file lucky.c.

415 {
416  char Temp = pCanonPerm[iVar];
417  pCanonPerm[iVar] = pCanonPerm[iVar+1];
418  pCanonPerm[iVar+1] = Temp;
419 
420  // if the polarity of variables is different, swap them
421  if ( ((*p_uCanonPhase & (1 << iVar)) > 0) != ((*p_uCanonPhase & (1 << (iVar+1))) > 0) )
422  {
423  *p_uCanonPhase ^= (1 << iVar);
424  *p_uCanonPhase ^= (1 << (iVar+1));
425  }
426 
427 }