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

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum (int nVars)
 DECLARATIONS ///. More...
 
static void Hop_ManTruthCopy (unsigned *pOut, unsigned *pIn, int nVars)
 
static void Hop_ManTruthClear (unsigned *pOut, int nVars)
 
static void Hop_ManTruthFill (unsigned *pOut, int nVars)
 
static void Hop_ManTruthNot (unsigned *pOut, unsigned *pIn, int nVars)
 
int Hop_ManConvertAigToTruth_rec1 (Hop_Obj_t *pObj)
 FUNCTION DEFINITIONS ///. More...
 
unsigned * Hop_ManConvertAigToTruth_rec2 (Hop_Obj_t *pObj, Vec_Int_t *vTruth, int nWords)
 
unsigned * Hop_ManConvertAigToTruth (Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
 
word Hop_ManComputeTruth6_rec (Hop_Man_t *p, Hop_Obj_t *pObj)
 
word Hop_ManComputeTruth6 (Hop_Man_t *p, Hop_Obj_t *pObj, int nVars)
 

Variables

static word Truth [8]
 

Function Documentation

word Hop_ManComputeTruth6 ( Hop_Man_t p,
Hop_Obj_t pObj,
int  nVars 
)

Definition at line 256 of file hopTruth.c.

257 {
258  word Truth;
259  int i;
260  if ( Hop_ObjIsConst1( Hop_Regular(pObj) ) )
261  return Hop_IsComplement(pObj) ? 0 : ~(word)0;
262  for ( i = 0; i < nVars; i++ )
263  Hop_ManPi( p, i )->iData = i;
264  Truth = Hop_ManComputeTruth6_rec( p, Hop_Regular(pObj) );
265  return Hop_IsComplement(pObj) ? ~Truth : Truth;
266 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static word Truth[8]
Definition: hopTruth.c:233
int iData
Definition: hop.h:69
static Hop_Obj_t * Hop_ManPi(Hop_Man_t *p, int i)
Definition: hop.h:134
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
word Hop_ManComputeTruth6_rec(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopTruth.c:244
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
word Hop_ManComputeTruth6_rec ( Hop_Man_t p,
Hop_Obj_t pObj 
)

Definition at line 244 of file hopTruth.c.

245 {
246  word Truth0, Truth1;
247  if ( Hop_ObjIsPi(pObj) )
248  return Truth[pObj->iData];
249  assert( Hop_ObjIsNode(pObj) );
250  Truth0 = Hop_ManComputeTruth6_rec( p, Hop_ObjFanin0(pObj) );
251  Truth1 = Hop_ManComputeTruth6_rec( p, Hop_ObjFanin1(pObj) );
252  Truth0 = Hop_ObjFaninC0(pObj) ? ~Truth0 : Truth0;
253  Truth1 = Hop_ObjFaninC1(pObj) ? ~Truth1 : Truth1;
254  return Truth0 & Truth1;
255 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static word Truth[8]
Definition: hopTruth.c:233
static int Hop_ObjIsPi(Hop_Obj_t *pObj)
Definition: hop.h:156
static int Hop_ObjIsNode(Hop_Obj_t *pObj)
Definition: hop.h:160
int iData
Definition: hop.h:69
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
static int Hop_ObjFaninC0(Hop_Obj_t *pObj)
Definition: hop.h:180
word Hop_ManComputeTruth6_rec(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition: hopTruth.c:244
#define assert(ex)
Definition: util_old.h:213
unsigned* Hop_ManConvertAigToTruth ( Hop_Man_t p,
Hop_Obj_t pRoot,
int  nVars,
Vec_Int_t vTruth,
int  fMsbFirst 
)

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

Synopsis [Computes truth table of the node.]

Description [Assumes that the structural support is no more than 8 inputs. Uses array vTruth to store temporary truth tables. The returned pointer should be used immediately.]

SideEffects []

SeeAlso []

Definition at line 143 of file hopTruth.c.

144 {
145  static unsigned uTruths[8][8] = { // elementary truth tables
146  { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA },
147  { 0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC,0xCCCCCCCC },
148  { 0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0,0xF0F0F0F0 },
149  { 0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00,0xFF00FF00 },
150  { 0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000,0xFFFF0000 },
151  { 0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF,0x00000000,0xFFFFFFFF },
152  { 0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF },
153  { 0x00000000,0x00000000,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF }
154  };
155  Hop_Obj_t * pObj;
156  unsigned * pTruth, * pTruth2;
157  int i, nWords, nNodes;
158  Vec_Ptr_t * vTtElems;
159 
160  // if the number of variables is more than 8, allocate truth tables
161  if ( nVars > 8 )
162  vTtElems = Vec_PtrAllocTruthTables( nVars );
163  else
164  vTtElems = NULL;
165 
166  // clear the data fields and set marks
167  nNodes = Hop_ManConvertAigToTruth_rec1( Hop_Regular(pRoot) );
168  // prepare memory
169  nWords = Hop_TruthWordNum( nVars );
170  Vec_IntClear( vTruth );
171  Vec_IntGrow( vTruth, nWords * (nNodes+1) );
172  pTruth = Vec_IntFetch( vTruth, nWords );
173  // check the case of a constant
174  if ( Hop_ObjIsConst1( Hop_Regular(pRoot) ) )
175  {
176  assert( nNodes == 0 );
177  if ( Hop_IsComplement(pRoot) )
178  Hop_ManTruthClear( pTruth, nVars );
179  else
180  Hop_ManTruthFill( pTruth, nVars );
181  return pTruth;
182  }
183  // set elementary truth tables at the leaves
184  assert( nVars <= Hop_ManPiNum(p) );
185 // assert( Hop_ManPiNum(p) <= 8 );
186  if ( fMsbFirst )
187  {
188 // Hop_ManForEachPi( p, pObj, i )
189  for ( i = 0; i < nVars; i++ )
190  {
191  pObj = Hop_ManPi( p, i );
192  if ( vTtElems )
193  pObj->pData = Vec_PtrEntry(vTtElems, nVars-1-i);
194  else
195  pObj->pData = (void *)uTruths[nVars-1-i];
196  }
197  }
198  else
199  {
200 // Hop_ManForEachPi( p, pObj, i )
201  for ( i = 0; i < nVars; i++ )
202  {
203  pObj = Hop_ManPi( p, i );
204  if ( vTtElems )
205  pObj->pData = Vec_PtrEntry(vTtElems, i);
206  else
207  pObj->pData = (void *)uTruths[i];
208  }
209  }
210  // clear the marks and compute the truth table
211  pTruth2 = Hop_ManConvertAigToTruth_rec2( Hop_Regular(pRoot), vTruth, nWords );
212  // copy the result
213  Hop_ManTruthCopy( pTruth, pTruth2, nVars );
214  if ( Hop_IsComplement(pRoot) )
215  Hop_ManTruthNot( pTruth, pTruth, nVars );
216  if ( vTtElems )
217  Vec_PtrFree( vTtElems );
218  return pTruth;
219 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned * Hop_ManConvertAigToTruth_rec2(Hop_Obj_t *pObj, Vec_Int_t *vTruth, int nWords)
Definition: hopTruth.c:97
static unsigned * Vec_IntFetch(Vec_Int_t *p, int nWords)
Definition: vecInt.h:853
int nWords
Definition: abcNpn.c:127
Definition: hop.h:65
static Vec_Ptr_t * Vec_PtrAllocTruthTables(int nVars)
Definition: vecPtr.h:1065
static void Vec_IntGrow(Vec_Int_t *p, int nCapMin)
Definition: bblif.c:336
static Hop_Obj_t * Hop_ManPi(Hop_Man_t *p, int i)
Definition: hop.h:134
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
void * pData
Definition: hop.h:68
static int Hop_ObjIsConst1(Hop_Obj_t *pObj)
Definition: hop.h:155
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static void Hop_ManTruthClear(unsigned *pOut, int nVars)
Definition: hopTruth.c:38
static int Hop_TruthWordNum(int nVars)
Definition: hop.h:119
static void Hop_ManTruthFill(unsigned *pOut, int nVars)
Definition: hopTruth.c:44
static void Hop_ManTruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: hopTruth.c:32
#define assert(ex)
Definition: util_old.h:213
static void Hop_ManTruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: hopTruth.c:50
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static int Hop_ManPiNum(Hop_Man_t *p)
Definition: hop.h:145
int Hop_ManConvertAigToTruth_rec1(Hop_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: hopTruth.c:73
int Hop_ManConvertAigToTruth_rec1 ( Hop_Obj_t pObj)

FUNCTION DEFINITIONS ///.

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

Synopsis [Construct BDDs and mark AIG nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file hopTruth.c.

74 {
75  int Counter = 0;
76  assert( !Hop_IsComplement(pObj) );
77  if ( !Hop_ObjIsNode(pObj) || Hop_ObjIsMarkA(pObj) )
78  return 0;
79  Counter += Hop_ManConvertAigToTruth_rec1( Hop_ObjFanin0(pObj) );
80  Counter += Hop_ManConvertAigToTruth_rec1( Hop_ObjFanin1(pObj) );
81  assert( !Hop_ObjIsMarkA(pObj) ); // loop detection
82  Hop_ObjSetMarkA( pObj );
83  return Counter + 1;
84 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjIsMarkA(Hop_Obj_t *pObj)
Definition: hop.h:164
static void Hop_ObjSetMarkA(Hop_Obj_t *pObj)
Definition: hop.h:165
static int Hop_ObjIsNode(Hop_Obj_t *pObj)
Definition: hop.h:160
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static int Counter
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
#define assert(ex)
Definition: util_old.h:213
int Hop_ManConvertAigToTruth_rec1(Hop_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: hopTruth.c:73
unsigned* Hop_ManConvertAigToTruth_rec2 ( Hop_Obj_t pObj,
Vec_Int_t vTruth,
int  nWords 
)

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

Synopsis [Computes truth table of the cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file hopTruth.c.

98 {
99  unsigned * pTruth, * pTruth0, * pTruth1;
100  int i;
101  assert( !Hop_IsComplement(pObj) );
102  if ( !Hop_ObjIsNode(pObj) || !Hop_ObjIsMarkA(pObj) )
103  return (unsigned *)pObj->pData;
104  // compute the truth tables of the fanins
105  pTruth0 = Hop_ManConvertAigToTruth_rec2( Hop_ObjFanin0(pObj), vTruth, nWords );
106  pTruth1 = Hop_ManConvertAigToTruth_rec2( Hop_ObjFanin1(pObj), vTruth, nWords );
107  // creat the truth table of the node
108  pTruth = Vec_IntFetch( vTruth, nWords );
109  if ( Hop_ObjIsExor(pObj) )
110  for ( i = 0; i < nWords; i++ )
111  pTruth[i] = pTruth0[i] ^ pTruth1[i];
112  else if ( !Hop_ObjFaninC0(pObj) && !Hop_ObjFaninC1(pObj) )
113  for ( i = 0; i < nWords; i++ )
114  pTruth[i] = pTruth0[i] & pTruth1[i];
115  else if ( !Hop_ObjFaninC0(pObj) && Hop_ObjFaninC1(pObj) )
116  for ( i = 0; i < nWords; i++ )
117  pTruth[i] = pTruth0[i] & ~pTruth1[i];
118  else if ( Hop_ObjFaninC0(pObj) && !Hop_ObjFaninC1(pObj) )
119  for ( i = 0; i < nWords; i++ )
120  pTruth[i] = ~pTruth0[i] & pTruth1[i];
121  else // if ( Hop_ObjFaninC0(pObj) && Hop_ObjFaninC1(pObj) )
122  for ( i = 0; i < nWords; i++ )
123  pTruth[i] = ~pTruth0[i] & ~pTruth1[i];
124  assert( Hop_ObjIsMarkA(pObj) ); // loop detection
125  Hop_ObjClearMarkA( pObj );
126  pObj->pData = pTruth;
127  return pTruth;
128 }
static Hop_Obj_t * Hop_ObjFanin1(Hop_Obj_t *pObj)
Definition: hop.h:183
static int Hop_ObjIsMarkA(Hop_Obj_t *pObj)
Definition: hop.h:164
static int Hop_ObjIsNode(Hop_Obj_t *pObj)
Definition: hop.h:160
unsigned * Hop_ManConvertAigToTruth_rec2(Hop_Obj_t *pObj, Vec_Int_t *vTruth, int nWords)
Definition: hopTruth.c:97
static unsigned * Vec_IntFetch(Vec_Int_t *p, int nWords)
Definition: vecInt.h:853
static int Hop_ObjFaninC1(Hop_Obj_t *pObj)
Definition: hop.h:181
int nWords
Definition: abcNpn.c:127
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static void Hop_ObjClearMarkA(Hop_Obj_t *pObj)
Definition: hop.h:166
void * pData
Definition: hop.h:68
static int Hop_ObjIsExor(Hop_Obj_t *pObj)
Definition: hop.h:159
static Hop_Obj_t * Hop_ObjFanin0(Hop_Obj_t *pObj)
Definition: hop.h:182
static int Hop_ObjFaninC0(Hop_Obj_t *pObj)
Definition: hop.h:180
#define assert(ex)
Definition: util_old.h:213
static void Hop_ManTruthClear ( unsigned *  pOut,
int  nVars 
)
inlinestatic

Definition at line 38 of file hopTruth.c.

39 {
40  int w;
41  for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
42  pOut[w] = 0;
43 }
static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum(int nVars)
DECLARATIONS ///.
Definition: hopTruth.c:30
static void Hop_ManTruthCopy ( unsigned *  pOut,
unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 32 of file hopTruth.c.

33 {
34  int w;
35  for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
36  pOut[w] = pIn[w];
37 }
static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum(int nVars)
DECLARATIONS ///.
Definition: hopTruth.c:30
static void Hop_ManTruthFill ( unsigned *  pOut,
int  nVars 
)
inlinestatic

Definition at line 44 of file hopTruth.c.

45 {
46  int w;
47  for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
48  pOut[w] = ~(unsigned)0;
49 }
static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum(int nVars)
DECLARATIONS ///.
Definition: hopTruth.c:30
static void Hop_ManTruthNot ( unsigned *  pOut,
unsigned *  pIn,
int  nVars 
)
inlinestatic

Definition at line 50 of file hopTruth.c.

51 {
52  int w;
53  for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
54  pOut[w] = ~pIn[w];
55 }
static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum(int nVars)
DECLARATIONS ///.
Definition: hopTruth.c:30
static ABC_NAMESPACE_IMPL_START int Hop_ManTruthWordNum ( int  nVars)
inlinestatic

DECLARATIONS ///.

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

FileName [hopTruth.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Minimalistic And-Inverter Graph package.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006.]

Revision [

Id:
hopTruth.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]

Definition at line 30 of file hopTruth.c.

30 { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }

Variable Documentation

word Truth[8]
static
Initial value:
=
{
ABC_CONST(0xAAAAAAAAAAAAAAAA),
ABC_CONST(0xCCCCCCCCCCCCCCCC),
ABC_CONST(0xF0F0F0F0F0F0F0F0),
ABC_CONST(0xFF00FF00FF00FF00),
ABC_CONST(0xFFFF0000FFFF0000),
ABC_CONST(0xFFFFFFFF00000000),
ABC_CONST(0x0000000000000000),
}
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206

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

Synopsis [Compute truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 233 of file hopTruth.c.