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

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START
swapInfo
setSwapInfoPtr (int varsN)
 
static void freeSwapInfoPtr (swapInfo *x)
 
int nextSwap (swapInfo *x)
 
void fillInSwapArray (permInfo *pi)
 
int oneBitPosition (int x, int size)
 
void fillInFlipArray (permInfo *pi)
 
static int factorial (int n)
 
permInfosetPermInfoPtr (int var)
 
void freePermInfoPtr (permInfo *x)
 
static void minWord (word *a, word *b, word *minimal, int nVars)
 
static void minWord3 (word *a, word *b, word *minimal, int nVars)
 
void simpleMinimal (word *x, word *pAux, word *minimal, permInfo *pi, int nVars)
 

Function Documentation

static int factorial ( int  n)
inlinestatic

Definition at line 106 of file luckySimple.c.

107 {
108  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
109 }
static int factorial(int n)
Definition: luckySimple.c:106
void fillInFlipArray ( permInfo pi)

Definition at line 94 of file luckySimple.c.

95 {
96  int i, temp=0, grayNumber;
97  for(i=1;i<=pi->totalFlips;i++)
98  {
99  grayNumber = i^(i>>1);
100  pi->flipArray[pi->totalFlips-i]=oneBitPosition(temp^grayNumber, pi->varN);
101  temp = grayNumber;
102  }
103 
104 
105 }
int totalFlips
Definition: lucky.h:31
int * flipArray
Definition: lucky.h:29
int oneBitPosition(int x, int size)
Definition: luckySimple.c:86
int varN
Definition: lucky.h:25
void fillInSwapArray ( permInfo pi)

Definition at line 72 of file luckySimple.c.

73 {
74  int counter=pi->totalSwaps-1;
75  swapInfo* x= setSwapInfoPtr(pi->varN);
76  while(nextSwap(x)==1)
77  {
79  pi->swapArray[counter--]=x->positionToSwap1;
80  else
81  pi->swapArray[counter--]=x->positionToSwap2;
82  }
83 
84  freeSwapInfoPtr(x);
85 }
static void freeSwapInfoPtr(swapInfo *x)
Definition: luckySimple.c:40
int totalSwaps
Definition: lucky.h:28
int positionToSwap1
Definition: luckyInt.h:85
int positionToSwap2
Definition: luckyInt.h:86
int * swapArray
Definition: lucky.h:26
static ABC_NAMESPACE_IMPL_START swapInfo * setSwapInfoPtr(int varsN)
Definition: luckySimple.c:21
int varN
Definition: lucky.h:25
int nextSwap(swapInfo *x)
Definition: luckySimple.c:47
void freePermInfoPtr ( permInfo x)

Definition at line 126 of file luckySimple.c.

127 {
128  free(x->flipArray);
129  free(x->swapArray);
130  free(x);
131 }
VOID_HACK free()
int * flipArray
Definition: lucky.h:29
int * swapArray
Definition: lucky.h:26
static void freeSwapInfoPtr ( swapInfo x)
static

Definition at line 40 of file luckySimple.c.

41 {
42  free(x->posArray);
43  free(x->realArray);
44  free(x);
45 }
VOID_HACK free()
varInfo * posArray
Definition: luckyInt.h:82
int * realArray
Definition: luckyInt.h:83
static void minWord ( word a,
word b,
word minimal,
int  nVars 
)
inlinestatic

Definition at line 132 of file luckySimple.c.

133 {
134  if(memCompare(a, b, nVars) == -1)
135  Kit_TruthCopy_64bit( minimal, a, nVars );
136  else
137  Kit_TruthCopy_64bit( minimal, b, nVars );
138 }
void Kit_TruthCopy_64bit(word *pOut, word *pIn, int nVars)
Definition: luckySwap.c:136
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
static void minWord3 ( word a,
word b,
word minimal,
int  nVars 
)
inlinestatic

Definition at line 139 of file luckySimple.c.

140 {
141  if (memCompare(a, b, nVars) <= 0)
142  {
143  if (memCompare(a, minimal, nVars) < 0)
144  Kit_TruthCopy_64bit( minimal, a, nVars );
145  else
146  return ;
147  }
148  if (memCompare(b, minimal, nVars) <= 0)
149  Kit_TruthCopy_64bit( minimal, b, nVars );
150 }
void Kit_TruthCopy_64bit(word *pOut, word *pIn, int nVars)
Definition: luckySwap.c:136
ABC_NAMESPACE_IMPL_START int memCompare(word *x, word *y, int nVars)
Definition: lucky.c:22
int nextSwap ( swapInfo x)

Definition at line 47 of file luckySimple.c.

48 {
49  int i,j,temp;
50  for(i=x->varN;i>1;i--)
51  {
52  if( i > x->realArray[x->posArray[i].position + x->posArray[i].direction] )
53  {
54  x->posArray[i].position = x->posArray[i].position + x->posArray[i].direction;
55  temp = x->realArray[x->posArray[i].position];
56  x->realArray[x->posArray[i].position] = i;
57  x->realArray[x->posArray[i].position - x->posArray[i].direction] = temp;
58  x->posArray[temp].position = x->posArray[i].position - x->posArray[i].direction;
59  for(j=x->varN;j>i;j--)
60  {
61  x->posArray[j].direction = x->posArray[j].direction * -1;
62  }
63  x->positionToSwap1 = x->posArray[temp].position - 1;
64  x->positionToSwap2 = x->posArray[i].position - 1;
65  return 1;
66  }
67 
68  }
69  return 0;
70 }
int positionToSwap1
Definition: luckyInt.h:85
int positionToSwap2
Definition: luckyInt.h:86
varInfo * posArray
Definition: luckyInt.h:82
int position
Definition: luckyInt.h:76
int * realArray
Definition: luckyInt.h:83
int direction
Definition: luckyInt.h:75
int varN
Definition: luckyInt.h:84
int oneBitPosition ( int  x,
int  size 
)

Definition at line 86 of file luckySimple.c.

87 {
88  int i;
89  for(i=0;i<size;i++)
90  if((x>>i)&1)
91  return i;
92  return -1;
93 }
static int size
Definition: cuddSign.c:86
permInfo* setPermInfoPtr ( int  var)

Definition at line 110 of file luckySimple.c.

111 {
112  permInfo* x;
113  x = (permInfo*) malloc(sizeof(permInfo));
114  x->flipCtr=0;
115  x->varN = var;
116  x->totalFlips=(1<<var)-1;
117  x->swapCtr=0;
118  x->totalSwaps=factorial(var)-1;
119  x->flipArray = (int*) malloc(sizeof(int)*x->totalFlips);
120  x->swapArray = (int*) malloc(sizeof(int)*x->totalSwaps);
121  fillInSwapArray(x);
122  fillInFlipArray(x);
123  return x;
124 }
char * malloc()
int totalSwaps
Definition: lucky.h:28
int var(Lit p)
Definition: SolverTypes.h:62
int totalFlips
Definition: lucky.h:31
int flipCtr
Definition: lucky.h:30
int * flipArray
Definition: lucky.h:29
void fillInFlipArray(permInfo *pi)
Definition: luckySimple.c:94
static int factorial(int n)
Definition: luckySimple.c:106
void fillInSwapArray(permInfo *pi)
Definition: luckySimple.c:72
int swapCtr
Definition: lucky.h:27
int * swapArray
Definition: lucky.h:26
int varN
Definition: lucky.h:25
Definition: lucky.h:23
static ABC_NAMESPACE_IMPL_START swapInfo* setSwapInfoPtr ( int  varsN)
static

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

FileName [luckySimple.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 21 of file luckySimple.c.

22 {
23  int i;
24  swapInfo* x = (swapInfo*) malloc(sizeof(swapInfo));
25  x->posArray = (varInfo*) malloc (sizeof(varInfo)*(varsN+2));
26  x->realArray = (int*) malloc (sizeof(int)*(varsN+2));
27  x->varN = varsN;
28  x->realArray[0]=varsN+100;
29  for(i=1;i<=varsN;i++)
30  {
31  x->posArray[i].position=i;
32  x->posArray[i].direction=-1;
33  x->realArray[i]=i;
34  }
35  x->realArray[varsN+1]=varsN+10;
36  return x;
37 }
char * malloc()
varInfo * posArray
Definition: luckyInt.h:82
int position
Definition: luckyInt.h:76
int * realArray
Definition: luckyInt.h:83
int direction
Definition: luckyInt.h:75
int varN
Definition: luckyInt.h:84
void simpleMinimal ( word x,
word pAux,
word minimal,
permInfo pi,
int  nVars 
)

Definition at line 151 of file luckySimple.c.

152 {
153  int i,j=0;
154  Kit_TruthCopy_64bit( pAux, x, nVars );
155  Kit_TruthNot_64bit( x, nVars );
156 
157  minWord(x, pAux, minimal, nVars);
158 
159  for(i=pi->totalSwaps-1;i>=0;i--)
160  {
161  Kit_TruthSwapAdjacentVars_64bit(x, nVars, pi->swapArray[i]);
162  Kit_TruthSwapAdjacentVars_64bit(pAux, nVars, pi->swapArray[i]);
163  minWord3(x, pAux, minimal, nVars);
164  }
165  for(j=pi->totalFlips-1;j>=0;j--)
166  {
167  Kit_TruthSwapAdjacentVars_64bit(x, nVars, 0);
168  Kit_TruthSwapAdjacentVars_64bit(pAux, nVars, 0);
169  Kit_TruthChangePhase_64bit(x, nVars, pi->flipArray[j]);
170  Kit_TruthChangePhase_64bit(pAux, nVars, pi->flipArray[j]);
171  minWord3(x, pAux, minimal, nVars);
172  for(i=pi->totalSwaps-1;i>=0;i--)
173  {
174  Kit_TruthSwapAdjacentVars_64bit(x, nVars, pi->swapArray[i]);
175  Kit_TruthSwapAdjacentVars_64bit(pAux, nVars, pi->swapArray[i]);
176  minWord3(x, pAux, minimal, nVars);
177  }
178  }
179  Kit_TruthCopy_64bit( x, minimal, nVars );
180 }
static void minWord3(word *a, word *b, word *minimal, int nVars)
Definition: luckySimple.c:139
void Kit_TruthCopy_64bit(word *pOut, word *pIn, int nVars)
Definition: luckySwap.c:136
int totalSwaps
Definition: lucky.h:28
void Kit_TruthSwapAdjacentVars_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:141
int totalFlips
Definition: lucky.h:31
int * flipArray
Definition: lucky.h:29
static void minWord(word *a, word *b, word *minimal, int nVars)
Definition: luckySimple.c:132
int * swapArray
Definition: lucky.h:26
void Kit_TruthNot_64bit(word *pIn, int nVars)
Definition: luckySwap.c:130
void Kit_TruthChangePhase_64bit(word *pInOut, int nVars, int iVar)
Definition: luckySwap.c:100