ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
hopTruth.c
Go to the documentation of this file.
1
20
21#include "hop.h"
22
24
25
29
30static inline int Hop_ManTruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
31
32static inline void Hop_ManTruthCopy( unsigned * pOut, unsigned * pIn, int nVars )
33{
34 int w;
35 for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
36 pOut[w] = pIn[w];
37}
38static inline void Hop_ManTruthClear( unsigned * pOut, int nVars )
39{
40 int w;
41 for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
42 pOut[w] = 0;
43}
44static inline void Hop_ManTruthFill( unsigned * pOut, int nVars )
45{
46 int w;
47 for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
48 pOut[w] = ~(unsigned)0;
49}
50static inline void Hop_ManTruthNot( unsigned * pOut, unsigned * pIn, int nVars )
51{
52 int w;
53 for ( w = Hop_ManTruthWordNum(nVars)-1; w >= 0; w-- )
54 pOut[w] = ~pIn[w];
55}
56
60
61
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}
85
97unsigned * Hop_ManConvertAigToTruth_rec2( Hop_Obj_t * pObj, Vec_Int_t * vTruth, int nWords )
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}
129
143unsigned * Hop_ManConvertAigToTruth( Hop_Man_t * p, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, int fMsbFirst )
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}
220
221
233static word Truth[8] =
234{
235 ABC_CONST(0xAAAAAAAAAAAAAAAA),
236 ABC_CONST(0xCCCCCCCCCCCCCCCC),
237 ABC_CONST(0xF0F0F0F0F0F0F0F0),
238 ABC_CONST(0xFF00FF00FF00FF00),
239 ABC_CONST(0xFFFF0000FFFF0000),
240 ABC_CONST(0xFFFFFFFF00000000),
241 ABC_CONST(0x0000000000000000),
242 ABC_CONST(0xFFFFFFFFFFFFFFFF)
243};
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}
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}
267
271
272
274
int nWords
Definition abcNpn.c:127
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
unsigned * Hop_ManConvertAigToTruth_rec2(Hop_Obj_t *pObj, Vec_Int_t *vTruth, int nWords)
Definition hopTruth.c:97
word Hop_ManComputeTruth6_rec(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition hopTruth.c:244
int Hop_ManConvertAigToTruth_rec1(Hop_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition hopTruth.c:73
word Hop_ManComputeTruth6(Hop_Man_t *p, Hop_Obj_t *pObj, int nVars)
Definition hopTruth.c:256
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition hopTruth.c:143
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int iData
Definition hop.h:69
void * pData
Definition hop.h:68
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42