abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
exp.h
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [exp.h]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Boolean expression.]
8 
9  Synopsis [External declarations.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: exp.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__map__mio__exp_h
22 #define ABC__map__mio__exp_h
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// INCLUDES ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// PARAMETERS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// BASIC TYPES ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 ////////////////////////////////////////////////////////////////////////
40 /// MACRO DEFINITIONS ///
41 ////////////////////////////////////////////////////////////////////////
42 
43 #define EXP_CONST0 -1
44 #define EXP_CONST1 -2
45 
46 static inline Vec_Int_t * Exp_Const0()
47 {
48  Vec_Int_t * vExp;
49  vExp = Vec_IntAlloc( 1 );
50  Vec_IntPush( vExp, EXP_CONST0 );
51  return vExp;
52 }
53 static inline Vec_Int_t * Exp_Const1()
54 {
55  Vec_Int_t * vExp;
56  vExp = Vec_IntAlloc( 1 );
57  Vec_IntPush( vExp, EXP_CONST1 );
58  return vExp;
59 }
60 static inline int Exp_IsConst( Vec_Int_t * p )
61 {
62  return Vec_IntEntry(p,0) == EXP_CONST0 || Vec_IntEntry(p,0) == EXP_CONST1;
63 }
64 static inline int Exp_IsConst0( Vec_Int_t * p )
65 {
66  return Vec_IntEntry(p,0) == EXP_CONST0;
67 }
68 static inline int Exp_IsConst1( Vec_Int_t * p )
69 {
70  return Vec_IntEntry(p,0) == EXP_CONST1;
71 }
72 static inline Vec_Int_t * Exp_Var( int iVar )
73 {
74  Vec_Int_t * vExp;
75  vExp = Vec_IntAlloc( 1 );
76  Vec_IntPush( vExp, 2 * iVar );
77  return vExp;
78 }
79 static inline int Exp_LitShift( int nVars, int Lit, int Shift )
80 {
81  if ( Lit < 2 * nVars )
82  return Lit;
83  return Lit + 2 * Shift;
84 }
85 static inline int Exp_IsLit( Vec_Int_t * p )
86 {
87  return Vec_IntSize(p) == 1 && !Exp_IsConst(p);
88 }
89 static inline int Exp_NodeNum( Vec_Int_t * p )
90 {
91  return Vec_IntSize(p)/2;
92 }
93 static inline Vec_Int_t * Exp_Not( Vec_Int_t * p )
94 {
95  Vec_IntWriteEntry( p, 0, Vec_IntEntry(p,0) ^ 1 );
96  return p;
97 }
98 static inline void Exp_PrintLit( int nVars, int Lit )
99 {
100  if ( Lit == EXP_CONST0 )
101  Abc_Print( 1, "Const0" );
102  else if ( Lit == EXP_CONST1 )
103  Abc_Print( 1, "Const1" );
104  else if ( Lit < 2 * nVars )
105  Abc_Print( 1, "%s%c", (Lit&1) ? "!" : " ", 'a' + Lit/2 );
106  else
107  Abc_Print( 1, "%s%d", (Lit&1) ? "!" : " ", Lit/2 );
108 }
109 static inline void Exp_Print( int nVars, Vec_Int_t * p )
110 {
111  int i;
112  for ( i = 0; i < Exp_NodeNum(p); i++ )
113  {
114  Abc_Print( 1, "%2d = ", nVars + i );
115  Exp_PrintLit( nVars, Vec_IntEntry(p, 2*i+0) );
116  Abc_Print( 1, " & " );
117  Exp_PrintLit( nVars, Vec_IntEntry(p, 2*i+1) );
118  Abc_Print( 1, "\n" );
119  }
120  Abc_Print( 1, " F = " );
121  Exp_PrintLit( nVars, Vec_IntEntryLast(p) );
122  Abc_Print( 1, "\n" );
123 }
124 static inline Vec_Int_t * Exp_Reverse( Vec_Int_t * p )
125 {
126  Vec_IntReverseOrder( p );
127  return p;
128 }
129 static inline void Exp_PrintReverse( int nVars, Vec_Int_t * p )
130 {
131  Exp_Reverse( p );
132  Exp_Print( nVars, p );
133  Exp_Reverse( p );
134 }
135 static inline Vec_Int_t * Exp_And( int * pMan, int nVars, Vec_Int_t * p0, Vec_Int_t * p1, int fCompl0, int fCompl1 )
136 {
137  int i, Len0 = Vec_IntSize(p0), Len1 = Vec_IntSize(p1);
138  Vec_Int_t * r = Vec_IntAlloc( Len0 + Len1 + 1 );
139  assert( (Len0 & 1) && (Len1 & 1) );
140  Vec_IntPush( r, 2 * (nVars + Len0/2 + Len1/2) );
141  Vec_IntPush( r, Exp_LitShift( nVars, Vec_IntEntry(p0, 0) ^ fCompl0, Len1/2 ) );
142  Vec_IntPush( r, Vec_IntEntry(p1, 0) ^ fCompl1 );
143  for ( i = 1; i < Len0; i++ )
144  Vec_IntPush( r, Exp_LitShift( nVars, Vec_IntEntry(p0, i), Len1/2 ) );
145  for ( i = 1; i < Len1; i++ )
146  Vec_IntPush( r, Vec_IntEntry(p1, i) );
147  assert( Vec_IntSize(r) == Len0 + Len1 + 1 );
148  return r;
149 }
150 static inline Vec_Int_t * Exp_Or( int * pMan, int nVars, Vec_Int_t * p0, Vec_Int_t * p1 )
151 {
152  return Exp_Not( Exp_And(pMan, nVars, p0, p1, 1, 1) );
153 }
154 static inline Vec_Int_t * Exp_Xor( int * pMan, int nVars, Vec_Int_t * p0, Vec_Int_t * p1 )
155 {
156  int i, Len0 = Vec_IntSize(p0), Len1 = Vec_IntSize(p1);
157  Vec_Int_t * r = Vec_IntAlloc( Len0 + Len1 + 5 );
158  assert( (Len0 & 1) && (Len1 & 1) );
159  Vec_IntPush( r, 2 * (nVars + Len0/2 + Len1/2 + 2) );
160  Vec_IntPush( r, 2 * (nVars + Len0/2 + Len1/2 + 1) + 1 );
161  Vec_IntPush( r, 2 * (nVars + Len0/2 + Len1/2 + 0) + 1 );
162  Vec_IntPush( r, Exp_LitShift( nVars, Vec_IntEntry(p0, 0) ^ 1, Len1/2 ) );
163  Vec_IntPush( r, Vec_IntEntry(p1, 0) );
164  Vec_IntPush( r, Exp_LitShift( nVars, Vec_IntEntry(p0, 0), Len1/2 ) );
165  Vec_IntPush( r, Vec_IntEntry(p1, 0) ^ 1 );
166  for ( i = 1; i < Len0; i++ )
167  Vec_IntPush( r, Exp_LitShift( nVars, Vec_IntEntry(p0, i), Len1/2 ) );
168  for ( i = 1; i < Len1; i++ )
169  Vec_IntPush( r, Vec_IntEntry(p1, i) );
170  assert( Vec_IntSize(r) == Len0 + Len1 + 5 );
171  return Exp_Not( r );
172 }
173 static inline word Exp_Truth6Lit( int nVars, int Lit, word * puFanins, word * puNodes )
174 {
175  if ( Lit == EXP_CONST0 )
176  return 0;
177  if ( Lit == EXP_CONST1 )
178  return ~(word)0;
179  if ( Lit < 2 * nVars )
180  return (Lit&1) ? ~puFanins[Lit/2] : puFanins[Lit/2];
181  return (Lit&1) ? ~puNodes[Lit/2-nVars] : puNodes[Lit/2-nVars];
182 }
183 static inline word Exp_Truth6( int nVars, Vec_Int_t * p, word * puFanins )
184 {
185  static word Truth6[6] = {
186  ABC_CONST(0xAAAAAAAAAAAAAAAA),
187  ABC_CONST(0xCCCCCCCCCCCCCCCC),
188  ABC_CONST(0xF0F0F0F0F0F0F0F0),
189  ABC_CONST(0xFF00FF00FF00FF00),
190  ABC_CONST(0xFFFF0000FFFF0000),
191  ABC_CONST(0xFFFFFFFF00000000)
192  };
193  word * puNodes, Res;
194  int i;
195  if ( puFanins == NULL )
196  puFanins = (word *)Truth6;
197  puNodes = ABC_CALLOC( word, Exp_NodeNum(p) );
198  for ( i = 0; i < Exp_NodeNum(p); i++ )
199  puNodes[i] = Exp_Truth6Lit( nVars, Vec_IntEntry(p, 2*i+0), puFanins, puNodes ) &
200  Exp_Truth6Lit( nVars, Vec_IntEntry(p, 2*i+1), puFanins, puNodes );
201  Res = Exp_Truth6Lit( nVars, Vec_IntEntryLast(p), puFanins, puNodes );
202  ABC_FREE( puNodes );
203  return Res;
204 }
205 static inline void Exp_TruthLit( int nVars, int Lit, word ** puFanins, word ** puNodes, word * pRes, int nWords )
206 {
207  int w;
208  if ( Lit == EXP_CONST0 )
209  for ( w = 0; w < nWords; w++ )
210  pRes[w] = 0;
211  else if ( Lit == EXP_CONST1 )
212  for ( w = 0; w < nWords; w++ )
213  pRes[w] = ~(word)0;
214  else if ( Lit < 2 * nVars )
215  for ( w = 0; w < nWords; w++ )
216  pRes[w] = (Lit&1) ? ~puFanins[Lit/2][w] : puFanins[Lit/2][w];
217  else
218  for ( w = 0; w < nWords; w++ )
219  pRes[w] = (Lit&1) ? ~puNodes[Lit/2-nVars][w] : puNodes[Lit/2-nVars][w];
220 }
221 static inline void Exp_Truth( int nVars, Vec_Int_t * p, word * pRes )
222 {
223  static word Truth6[6] = {
224  ABC_CONST(0xAAAAAAAAAAAAAAAA),
225  ABC_CONST(0xCCCCCCCCCCCCCCCC),
226  ABC_CONST(0xF0F0F0F0F0F0F0F0),
227  ABC_CONST(0xFF00FF00FF00FF00),
228  ABC_CONST(0xFFFF0000FFFF0000),
229  ABC_CONST(0xFFFFFFFF00000000)
230  };
231  word ** puFanins, ** puNodes, * pTemp0, * pTemp1;
232  int i, w, nWords = (nVars <= 6 ? 1 : 1 << (nVars-6));
233  // create elementary variables
234  puFanins = ABC_ALLOC( word *, nVars );
235  for ( i = 0; i < nVars; i++ )
236  puFanins[i] = ABC_ALLOC( word, nWords );
237  // assign elementary truth tables
238  for ( i = 0; i < nVars; i++ )
239  if ( i < 6 )
240  for ( w = 0; w < nWords; w++ )
241  puFanins[i][w] = Truth6[i];
242  else
243  for ( w = 0; w < nWords; w++ )
244  puFanins[i][w] = (w & (1 << (i-6))) ? ~(word)0 : 0;
245  // create intermediate nodes
246  puNodes = ABC_ALLOC( word *, Exp_NodeNum(p) );
247  for ( i = 0; i < Exp_NodeNum(p); i++ )
248  puNodes[i] = ABC_ALLOC( word, nWords );
249  // evaluate the expression
250  pTemp0 = ABC_ALLOC( word, nWords );
251  pTemp1 = ABC_ALLOC( word, nWords );
252  for ( i = 0; i < Exp_NodeNum(p); i++ )
253  {
254  Exp_TruthLit( nVars, Vec_IntEntry(p, 2*i+0), puFanins, puNodes, pTemp0, nWords );
255  Exp_TruthLit( nVars, Vec_IntEntry(p, 2*i+1), puFanins, puNodes, pTemp1, nWords );
256  for ( w = 0; w < nWords; w++ )
257  puNodes[i][w] = pTemp0[w] & pTemp1[w];
258  }
259  ABC_FREE( pTemp0 );
260  ABC_FREE( pTemp1 );
261  // copy the final result
262  Exp_TruthLit( nVars, Vec_IntEntryLast(p), puFanins, puNodes, pRes, nWords );
263  // cleanup
264  for ( i = 0; i < nVars; i++ )
265  ABC_FREE( puFanins[i] );
266  ABC_FREE( puFanins );
267  for ( i = 0; i < Exp_NodeNum(p); i++ )
268  ABC_FREE( puNodes[i] );
269  ABC_FREE( puNodes );
270 }
271 
272 ////////////////////////////////////////////////////////////////////////
273 /// FUNCTION DECLARATIONS ///
274 ////////////////////////////////////////////////////////////////////////
275 
277 
278 
279 #endif
280 
281 ////////////////////////////////////////////////////////////////////////
282 /// END OF FILE ///
283 ////////////////////////////////////////////////////////////////////////
284 
static int Exp_IsConst0(Vec_Int_t *p)
Definition: exp.h:64
static void Exp_Print(int nVars, Vec_Int_t *p)
Definition: exp.h:109
static Vec_Int_t * Exp_Var(int iVar)
Definition: exp.h:72
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Exp_PrintReverse(int nVars, Vec_Int_t *p)
Definition: exp.h:129
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static void Exp_PrintLit(int nVars, int Lit)
Definition: exp.h:98
static int Exp_LitShift(int nVars, int Lit, int Shift)
Definition: exp.h:79
#define EXP_CONST0
INCLUDES ///.
Definition: exp.h:43
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static void Exp_TruthLit(int nVars, int Lit, word **puFanins, word **puNodes, word *pRes, int nWords)
Definition: exp.h:205
int nWords
Definition: abcNpn.c:127
static void Vec_IntReverseOrder(Vec_Int_t *p)
Definition: vecInt.h:1042
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static Vec_Int_t * Exp_Or(int *pMan, int nVars, Vec_Int_t *p0, Vec_Int_t *p1)
Definition: exp.h:150
static word Exp_Truth6(int nVars, Vec_Int_t *p, word *puFanins)
Definition: exp.h:183
static Vec_Int_t * Exp_And(int *pMan, int nVars, Vec_Int_t *p0, Vec_Int_t *p1, int fCompl0, int fCompl1)
Definition: exp.h:135
static Vec_Int_t * Exp_Const0()
Definition: exp.h:46
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static Vec_Int_t * Exp_Xor(int *pMan, int nVars, Vec_Int_t *p0, Vec_Int_t *p1)
Definition: exp.h:154
static word Truth6[6]
Definition: ifDec07.c:52
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static word Exp_Truth6Lit(int nVars, int Lit, word *puFanins, word *puNodes)
Definition: exp.h:173
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
static int Exp_NodeNum(Vec_Int_t *p)
Definition: exp.h:89
static void Exp_Truth(int nVars, Vec_Int_t *p, word *pRes)
Definition: exp.h:221
static Vec_Int_t * Exp_Reverse(Vec_Int_t *p)
Definition: exp.h:124
static int Vec_IntEntryLast(Vec_Int_t *p)
Definition: bblif.c:319
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static int Exp_IsLit(Vec_Int_t *p)
Definition: exp.h:85
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Exp_IsConst1(Vec_Int_t *p)
Definition: exp.h:68
#define assert(ex)
Definition: util_old.h:213
static int Exp_IsConst(Vec_Int_t *p)
Definition: exp.h:60
static Vec_Int_t * Exp_Not(Vec_Int_t *p)
Definition: exp.h:93
static Vec_Int_t * Exp_Const1()
Definition: exp.h:53
#define EXP_CONST1
Definition: exp.h:44